Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>

This commit is contained in:
Matt Bruce 2026-01-21 16:10:18 -06:00
parent 163f261e15
commit ad1999f351
3 changed files with 106 additions and 44 deletions

View File

@ -714,6 +714,8 @@ final class GameState: CasinoGameState {
func deal() async {
guard canDeal else { return }
let bottomIsPlayer = bettedOnPlayer ?? true
isAnimating = true
engine.prepareNewRound()
@ -744,14 +746,23 @@ final class GameState: CasinoGameState {
// Brief extra delay before the very first card deal starts
try? await Task.sleep(for: .milliseconds(250))
// Animate dealing: P1, B1, P2, B2
for (index, card) in initialCards.enumerated() {
// Animate dealing: B1 (Bottom 1), T1 (Top 1), B2 (Bottom 2), T2 (Top 2)
// 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)
// Play card deal sound
sound.playCardDeal()
if index % 2 == 0 {
let card = initialCards[step.cardIndex]
if step.isPlayer {
visiblePlayerCards.append(card)
playerCardsFaceUp.append(false)
} else {
@ -763,19 +774,20 @@ final class GameState: CasinoGameState {
// Reveal according to selected style
switch settings.revealStyle {
case .auto, .tap, .squeeze:
// Sequential reveal: P1, B1, P2, B2
for i in 0..<playerCardsFaceUp.count {
// Flip player card
await waitForReveal(index: i * 2)
// Sequential reveal: B1 -> T1 -> B2 -> T2
for i in 0..<4 {
await waitForReveal(index: i)
sound.playCardFlip()
playerCardsFaceUp[i] = true
// Flip banker card
await waitForReveal(index: i * 2 + 1)
sound.playCardFlip()
bankerCardsFaceUp[i] = true
let slotIndex = i / 2 // 0 for B1/T1, 1 for B2/T2
let isBottom = i % 2 == 0
if (isBottom && bottomIsPlayer) || (!isBottom && !bottomIsPlayer) {
playerCardsFaceUp[slotIndex] = true
} else {
bankerCardsFaceUp[slotIndex] = true
}
}
}
// Pause to let user see initial totals
@ -805,47 +817,89 @@ final class GameState: CasinoGameState {
return
}
// Player third card
currentPhase = .playerThirdCard
if let playerThird = engine.drawPlayerThirdCard() {
// --- THIRD CARD HANDLING ---
// Slots: index 4 = B3, index 5 = T3
let playerThird = engine.drawPlayerThirdCard()
let bankerThird = engine.drawBankerThirdCard()
// Slot B3
let b3Card = bottomIsPlayer ? playerThird : bankerThird
if let card = b3Card {
if settings.showAnimations {
try? await Task.sleep(for: dealDelay)
sound.playCardDeal()
visiblePlayerCards.append(playerThird)
playerCardsFaceUp.append(false)
await waitForReveal(index: 4) // Player 3rd card
sound.playCardFlip()
playerCardsFaceUp[2] = true
if settings.revealStyle == .auto {
try? await Task.sleep(for: resultDelay)
if bottomIsPlayer {
visiblePlayerCards.append(card)
playerCardsFaceUp.append(false)
} else {
visibleBankerCards.append(card)
bankerCardsFaceUp.append(false)
}
} else {
visiblePlayerCards.append(playerThird)
playerCardsFaceUp.append(true)
if bottomIsPlayer {
visiblePlayerCards.append(card)
playerCardsFaceUp.append(true)
} else {
visibleBankerCards.append(card)
bankerCardsFaceUp.append(true)
}
}
}
// Banker third card
currentPhase = .bankerThirdCard
if let bankerThird = engine.drawBankerThirdCard() {
// Slot T3
let t3Card = bottomIsPlayer ? bankerThird : playerThird
if let card = t3Card {
if settings.showAnimations {
try? await Task.sleep(for: dealDelay)
sound.playCardDeal()
visibleBankerCards.append(bankerThird)
bankerCardsFaceUp.append(false)
await waitForReveal(index: 5) // Banker 3rd card
if bottomIsPlayer {
visibleBankerCards.append(card)
bankerCardsFaceUp.append(false)
} 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()
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 {
try? await Task.sleep(for: resultDelay)
}
} else {
visibleBankerCards.append(bankerThird)
bankerCardsFaceUp.append(true)
}
}

View File

@ -250,6 +250,7 @@ struct CardsDisplayArea: View {
currentRevealIndex: currentRevealIndex,
revealProgress: revealProgress,
isPlayerHand: true,
isBottom: playerOnBottom,
onReveal: onReveal,
onUpdateProgress: onUpdateProgress
)
@ -299,6 +300,7 @@ struct CardsDisplayArea: View {
currentRevealIndex: currentRevealIndex,
revealProgress: revealProgress,
isPlayerHand: false,
isBottom: !playerOnBottom,
onReveal: onReveal,
onUpdateProgress: onUpdateProgress
)

View File

@ -23,6 +23,8 @@ struct CompactHandView: View {
let revealProgress: Double
/// Whether this is the player hand (used to calculate reveal index)
let isPlayerHand: Bool
/// Whether this hand is currently displayed at the bottom of the screen (Home hand)
let isBottom: Bool
let onReveal: () -> Void
let onUpdateProgress: (Double) -> Void
@ -120,7 +122,7 @@ struct CompactHandView: View {
.onChange(of: cards.count) { _, newCount in
// When 3rd card is dealt, wait for animation then scroll
if newCount == 3 {
let lastIndex = isPlayerHand ? 4 : 5
let lastIndex = isBottom ? 4 : 5
DispatchQueue.main.asyncAfter(deadline: .now() + 0.8) {
withAnimation(.spring(duration: 0.5)) {
proxy.scrollTo(lastIndex, anchor: .center)
@ -166,12 +168,12 @@ struct CompactHandView: View {
let isFaceUp = index < cardsFaceUp.count ? cardsFaceUp[index] : false
// 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 = {
if index < 2 {
return isPlayerHand ? index * 2 : index * 2 + 1
return isBottom ? index * 2 : index * 2 + 1
} else {
return isPlayerHand ? 4 : 5
return isBottom ? 4 : 5
}
}()
@ -250,6 +252,7 @@ struct CompactHandView: View {
currentRevealIndex: 0,
revealProgress: 0,
isPlayerHand: true,
isBottom: true,
onReveal: {},
onUpdateProgress: { _ in }
)
@ -274,6 +277,7 @@ struct CompactHandView: View {
currentRevealIndex: 0,
revealProgress: 0,
isPlayerHand: true,
isBottom: true,
onReveal: {},
onUpdateProgress: { _ in }
)
@ -299,6 +303,7 @@ struct CompactHandView: View {
currentRevealIndex: 0,
revealProgress: 0,
isPlayerHand: true,
isBottom: true,
onReveal: {},
onUpdateProgress: { _ in }
)
@ -323,6 +328,7 @@ struct CompactHandView: View {
currentRevealIndex: 0,
revealProgress: 0,
isPlayerHand: true,
isBottom: true,
onReveal: {},
onUpdateProgress: { _ in }
)