Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
parent
163f261e15
commit
ad1999f351
@ -714,6 +714,8 @@ final class GameState: CasinoGameState {
|
|||||||
func deal() async {
|
func deal() async {
|
||||||
guard canDeal else { return }
|
guard canDeal else { return }
|
||||||
|
|
||||||
|
let bottomIsPlayer = bettedOnPlayer ?? true
|
||||||
|
|
||||||
isAnimating = true
|
isAnimating = true
|
||||||
engine.prepareNewRound()
|
engine.prepareNewRound()
|
||||||
|
|
||||||
@ -744,14 +746,23 @@ final class GameState: CasinoGameState {
|
|||||||
// Brief extra delay before the very first card deal starts
|
// Brief extra delay before the very first card deal starts
|
||||||
try? await Task.sleep(for: .milliseconds(250))
|
try? await Task.sleep(for: .milliseconds(250))
|
||||||
|
|
||||||
// Animate dealing: P1, B1, P2, B2
|
// Animate dealing: B1 (Bottom 1), T1 (Top 1), B2 (Bottom 2), T2 (Top 2)
|
||||||
for (index, card) in initialCards.enumerated() {
|
|
||||||
|
// Map slots to roles: (isPlayerRole, engineCardIndex)
|
||||||
|
// engineCardIndex: 0=P1, 1=B1, 2=P2, 3=B2
|
||||||
|
let dealSequence: [(isPlayer: Bool, cardIndex: Int)] = [
|
||||||
|
(bottomIsPlayer, bottomIsPlayer ? 0 : 1), // B1
|
||||||
|
(!bottomIsPlayer, bottomIsPlayer ? 1 : 0), // T1
|
||||||
|
(bottomIsPlayer, bottomIsPlayer ? 2 : 3), // B2
|
||||||
|
(!bottomIsPlayer, bottomIsPlayer ? 3 : 2) // T2
|
||||||
|
]
|
||||||
|
|
||||||
|
for (stepIndex, step) in dealSequence.enumerated() {
|
||||||
try? await Task.sleep(for: dealDelay)
|
try? await Task.sleep(for: dealDelay)
|
||||||
|
|
||||||
// Play card deal sound
|
|
||||||
sound.playCardDeal()
|
sound.playCardDeal()
|
||||||
|
|
||||||
if index % 2 == 0 {
|
let card = initialCards[step.cardIndex]
|
||||||
|
if step.isPlayer {
|
||||||
visiblePlayerCards.append(card)
|
visiblePlayerCards.append(card)
|
||||||
playerCardsFaceUp.append(false)
|
playerCardsFaceUp.append(false)
|
||||||
} else {
|
} else {
|
||||||
@ -763,19 +774,20 @@ final class GameState: CasinoGameState {
|
|||||||
// Reveal according to selected style
|
// Reveal according to selected style
|
||||||
switch settings.revealStyle {
|
switch settings.revealStyle {
|
||||||
case .auto, .tap, .squeeze:
|
case .auto, .tap, .squeeze:
|
||||||
// Sequential reveal: P1, B1, P2, B2
|
// Sequential reveal: B1 -> T1 -> B2 -> T2
|
||||||
for i in 0..<playerCardsFaceUp.count {
|
for i in 0..<4 {
|
||||||
// Flip player card
|
await waitForReveal(index: i)
|
||||||
await waitForReveal(index: i * 2)
|
|
||||||
sound.playCardFlip()
|
sound.playCardFlip()
|
||||||
playerCardsFaceUp[i] = true
|
|
||||||
|
|
||||||
// Flip banker card
|
let slotIndex = i / 2 // 0 for B1/T1, 1 for B2/T2
|
||||||
await waitForReveal(index: i * 2 + 1)
|
let isBottom = i % 2 == 0
|
||||||
sound.playCardFlip()
|
|
||||||
bankerCardsFaceUp[i] = true
|
if (isBottom && bottomIsPlayer) || (!isBottom && !bottomIsPlayer) {
|
||||||
|
playerCardsFaceUp[slotIndex] = true
|
||||||
|
} else {
|
||||||
|
bankerCardsFaceUp[slotIndex] = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pause to let user see initial totals
|
// Pause to let user see initial totals
|
||||||
@ -805,47 +817,89 @@ final class GameState: CasinoGameState {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Player third card
|
// --- THIRD CARD HANDLING ---
|
||||||
currentPhase = .playerThirdCard
|
// Slots: index 4 = B3, index 5 = T3
|
||||||
if let playerThird = engine.drawPlayerThirdCard() {
|
let playerThird = engine.drawPlayerThirdCard()
|
||||||
|
let bankerThird = engine.drawBankerThirdCard()
|
||||||
|
|
||||||
|
// Slot B3
|
||||||
|
let b3Card = bottomIsPlayer ? playerThird : bankerThird
|
||||||
|
if let card = b3Card {
|
||||||
if settings.showAnimations {
|
if settings.showAnimations {
|
||||||
try? await Task.sleep(for: dealDelay)
|
try? await Task.sleep(for: dealDelay)
|
||||||
sound.playCardDeal()
|
sound.playCardDeal()
|
||||||
visiblePlayerCards.append(playerThird)
|
if bottomIsPlayer {
|
||||||
playerCardsFaceUp.append(false)
|
visiblePlayerCards.append(card)
|
||||||
|
playerCardsFaceUp.append(false)
|
||||||
await waitForReveal(index: 4) // Player 3rd card
|
} else {
|
||||||
sound.playCardFlip()
|
visibleBankerCards.append(card)
|
||||||
playerCardsFaceUp[2] = true
|
bankerCardsFaceUp.append(false)
|
||||||
|
|
||||||
if settings.revealStyle == .auto {
|
|
||||||
try? await Task.sleep(for: resultDelay)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
visiblePlayerCards.append(playerThird)
|
if bottomIsPlayer {
|
||||||
playerCardsFaceUp.append(true)
|
visiblePlayerCards.append(card)
|
||||||
|
playerCardsFaceUp.append(true)
|
||||||
|
} else {
|
||||||
|
visibleBankerCards.append(card)
|
||||||
|
bankerCardsFaceUp.append(true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Banker third card
|
// Slot T3
|
||||||
currentPhase = .bankerThirdCard
|
let t3Card = bottomIsPlayer ? bankerThird : playerThird
|
||||||
if let bankerThird = engine.drawBankerThirdCard() {
|
if let card = t3Card {
|
||||||
if settings.showAnimations {
|
if settings.showAnimations {
|
||||||
try? await Task.sleep(for: dealDelay)
|
try? await Task.sleep(for: dealDelay)
|
||||||
sound.playCardDeal()
|
sound.playCardDeal()
|
||||||
visibleBankerCards.append(bankerThird)
|
if bottomIsPlayer {
|
||||||
bankerCardsFaceUp.append(false)
|
visibleBankerCards.append(card)
|
||||||
|
bankerCardsFaceUp.append(false)
|
||||||
await waitForReveal(index: 5) // Banker 3rd card
|
} else {
|
||||||
|
visiblePlayerCards.append(card)
|
||||||
|
playerCardsFaceUp.append(false)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if bottomIsPlayer {
|
||||||
|
visibleBankerCards.append(card)
|
||||||
|
bankerCardsFaceUp.append(true)
|
||||||
|
} else {
|
||||||
|
visiblePlayerCards.append(card)
|
||||||
|
playerCardsFaceUp.append(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reveal 3rd cards in Slot order: B3 then T3
|
||||||
|
if settings.showAnimations {
|
||||||
|
// Reveal B3 (Reveal Index 4)
|
||||||
|
if b3Card != nil {
|
||||||
|
await waitForReveal(index: 4)
|
||||||
sound.playCardFlip()
|
sound.playCardFlip()
|
||||||
bankerCardsFaceUp[2] = true
|
if bottomIsPlayer {
|
||||||
|
playerCardsFaceUp[2] = true
|
||||||
|
} else {
|
||||||
|
bankerCardsFaceUp[2] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if settings.revealStyle == .auto {
|
||||||
|
try? await Task.sleep(for: resultDelay)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reveal T3 (Reveal Index 5)
|
||||||
|
if t3Card != nil {
|
||||||
|
await waitForReveal(index: 5)
|
||||||
|
sound.playCardFlip()
|
||||||
|
if bottomIsPlayer {
|
||||||
|
bankerCardsFaceUp[2] = true
|
||||||
|
} else {
|
||||||
|
playerCardsFaceUp[2] = true
|
||||||
|
}
|
||||||
|
|
||||||
if settings.revealStyle == .auto {
|
if settings.revealStyle == .auto {
|
||||||
try? await Task.sleep(for: resultDelay)
|
try? await Task.sleep(for: resultDelay)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
visibleBankerCards.append(bankerThird)
|
|
||||||
bankerCardsFaceUp.append(true)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -250,6 +250,7 @@ struct CardsDisplayArea: View {
|
|||||||
currentRevealIndex: currentRevealIndex,
|
currentRevealIndex: currentRevealIndex,
|
||||||
revealProgress: revealProgress,
|
revealProgress: revealProgress,
|
||||||
isPlayerHand: true,
|
isPlayerHand: true,
|
||||||
|
isBottom: playerOnBottom,
|
||||||
onReveal: onReveal,
|
onReveal: onReveal,
|
||||||
onUpdateProgress: onUpdateProgress
|
onUpdateProgress: onUpdateProgress
|
||||||
)
|
)
|
||||||
@ -299,6 +300,7 @@ struct CardsDisplayArea: View {
|
|||||||
currentRevealIndex: currentRevealIndex,
|
currentRevealIndex: currentRevealIndex,
|
||||||
revealProgress: revealProgress,
|
revealProgress: revealProgress,
|
||||||
isPlayerHand: false,
|
isPlayerHand: false,
|
||||||
|
isBottom: !playerOnBottom,
|
||||||
onReveal: onReveal,
|
onReveal: onReveal,
|
||||||
onUpdateProgress: onUpdateProgress
|
onUpdateProgress: onUpdateProgress
|
||||||
)
|
)
|
||||||
|
|||||||
@ -23,6 +23,8 @@ struct CompactHandView: View {
|
|||||||
let revealProgress: Double
|
let revealProgress: Double
|
||||||
/// Whether this is the player hand (used to calculate reveal index)
|
/// Whether this is the player hand (used to calculate reveal index)
|
||||||
let isPlayerHand: Bool
|
let isPlayerHand: Bool
|
||||||
|
/// Whether this hand is currently displayed at the bottom of the screen (Home hand)
|
||||||
|
let isBottom: Bool
|
||||||
let onReveal: () -> Void
|
let onReveal: () -> Void
|
||||||
let onUpdateProgress: (Double) -> Void
|
let onUpdateProgress: (Double) -> Void
|
||||||
|
|
||||||
@ -120,7 +122,7 @@ struct CompactHandView: View {
|
|||||||
.onChange(of: cards.count) { _, newCount in
|
.onChange(of: cards.count) { _, newCount in
|
||||||
// When 3rd card is dealt, wait for animation then scroll
|
// When 3rd card is dealt, wait for animation then scroll
|
||||||
if newCount == 3 {
|
if newCount == 3 {
|
||||||
let lastIndex = isPlayerHand ? 4 : 5
|
let lastIndex = isBottom ? 4 : 5
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.8) {
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.8) {
|
||||||
withAnimation(.spring(duration: 0.5)) {
|
withAnimation(.spring(duration: 0.5)) {
|
||||||
proxy.scrollTo(lastIndex, anchor: .center)
|
proxy.scrollTo(lastIndex, anchor: .center)
|
||||||
@ -166,12 +168,12 @@ struct CompactHandView: View {
|
|||||||
let isFaceUp = index < cardsFaceUp.count ? cardsFaceUp[index] : false
|
let isFaceUp = index < cardsFaceUp.count ? cardsFaceUp[index] : false
|
||||||
|
|
||||||
// Reveal Index logic:
|
// Reveal Index logic:
|
||||||
// P1=0, B1=1, P2=2, B2=3, P3=4, B3=5
|
// Generic Slot-Based: B1=0, T1=1, B2=2, T2=3, B3=4, T3=5
|
||||||
let revealIndex: Int = {
|
let revealIndex: Int = {
|
||||||
if index < 2 {
|
if index < 2 {
|
||||||
return isPlayerHand ? index * 2 : index * 2 + 1
|
return isBottom ? index * 2 : index * 2 + 1
|
||||||
} else {
|
} else {
|
||||||
return isPlayerHand ? 4 : 5
|
return isBottom ? 4 : 5
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -250,6 +252,7 @@ struct CompactHandView: View {
|
|||||||
currentRevealIndex: 0,
|
currentRevealIndex: 0,
|
||||||
revealProgress: 0,
|
revealProgress: 0,
|
||||||
isPlayerHand: true,
|
isPlayerHand: true,
|
||||||
|
isBottom: true,
|
||||||
onReveal: {},
|
onReveal: {},
|
||||||
onUpdateProgress: { _ in }
|
onUpdateProgress: { _ in }
|
||||||
)
|
)
|
||||||
@ -274,6 +277,7 @@ struct CompactHandView: View {
|
|||||||
currentRevealIndex: 0,
|
currentRevealIndex: 0,
|
||||||
revealProgress: 0,
|
revealProgress: 0,
|
||||||
isPlayerHand: true,
|
isPlayerHand: true,
|
||||||
|
isBottom: true,
|
||||||
onReveal: {},
|
onReveal: {},
|
||||||
onUpdateProgress: { _ in }
|
onUpdateProgress: { _ in }
|
||||||
)
|
)
|
||||||
@ -299,6 +303,7 @@ struct CompactHandView: View {
|
|||||||
currentRevealIndex: 0,
|
currentRevealIndex: 0,
|
||||||
revealProgress: 0,
|
revealProgress: 0,
|
||||||
isPlayerHand: true,
|
isPlayerHand: true,
|
||||||
|
isBottom: true,
|
||||||
onReveal: {},
|
onReveal: {},
|
||||||
onUpdateProgress: { _ in }
|
onUpdateProgress: { _ in }
|
||||||
)
|
)
|
||||||
@ -323,6 +328,7 @@ struct CompactHandView: View {
|
|||||||
currentRevealIndex: 0,
|
currentRevealIndex: 0,
|
||||||
revealProgress: 0,
|
revealProgress: 0,
|
||||||
isPlayerHand: true,
|
isPlayerHand: true,
|
||||||
|
isBottom: true,
|
||||||
onReveal: {},
|
onReveal: {},
|
||||||
onUpdateProgress: { _ in }
|
onUpdateProgress: { _ in }
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user