82 lines
2.3 KiB
Swift
82 lines
2.3 KiB
Swift
//
|
|
// HiLoCountBadge.swift
|
|
// Blackjack
|
|
//
|
|
// Badge showing the Hi-Lo counting value of a card.
|
|
//
|
|
|
|
import SwiftUI
|
|
import CasinoKit
|
|
|
|
/// A small badge showing the Hi-Lo counting value of a card.
|
|
struct HiLoCountBadge: View {
|
|
let card: Card
|
|
|
|
var body: some View {
|
|
Text(card.hiLoDisplayText)
|
|
.font(.system(size: Design.Size.countBadgeFontSize, weight: .bold, design: .rounded))
|
|
.foregroundStyle(badgeTextColor)
|
|
.padding(.horizontal, Design.Size.countBadgePaddingH)
|
|
.padding(.vertical, Design.Size.countBadgePaddingV)
|
|
.background(
|
|
Capsule()
|
|
.fill(badgeBackgroundColor)
|
|
)
|
|
.offset(x: -Design.Size.countBadgeOffset, y: Design.Size.countBadgeOffset)
|
|
}
|
|
|
|
private var badgeBackgroundColor: Color {
|
|
switch card.hiLoValue {
|
|
case 1: return .green // Low cards = positive for player
|
|
case -1: return .red // High cards = negative for player
|
|
default: return .gray // Neutral
|
|
}
|
|
}
|
|
|
|
private var badgeTextColor: Color {
|
|
.white
|
|
}
|
|
}
|
|
|
|
// MARK: - Card Accessibility Extension
|
|
|
|
extension Card {
|
|
/// Accessibility description for VoiceOver.
|
|
var accessibilityDescription: String {
|
|
"\(rank.accessibilityName) of \(suit.accessibilityName)"
|
|
}
|
|
}
|
|
|
|
// MARK: - Previews
|
|
|
|
#Preview("Low Card (+1)") {
|
|
ZStack {
|
|
Color.Table.felt.ignoresSafeArea()
|
|
CardView(card: Card(suit: .hearts, rank: .five), isFaceUp: true, cardWidth: 70)
|
|
.overlay(alignment: .bottomLeading) {
|
|
HiLoCountBadge(card: Card(suit: .hearts, rank: .five))
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview("High Card (-1)") {
|
|
ZStack {
|
|
Color.Table.felt.ignoresSafeArea()
|
|
CardView(card: Card(suit: .spades, rank: .king), isFaceUp: true, cardWidth: 70)
|
|
.overlay(alignment: .bottomLeading) {
|
|
HiLoCountBadge(card: Card(suit: .spades, rank: .king))
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview("Neutral Card (0)") {
|
|
ZStack {
|
|
Color.Table.felt.ignoresSafeArea()
|
|
CardView(card: Card(suit: .diamonds, rank: .seven), isFaceUp: true, cardWidth: 70)
|
|
.overlay(alignment: .bottomLeading) {
|
|
HiLoCountBadge(card: Card(suit: .diamonds, rank: .seven))
|
|
}
|
|
}
|
|
}
|
|
|