ensured all defaults set with default settings
Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
parent
1c28e43e07
commit
9aa646e89d
@ -191,7 +191,7 @@ final class GameSettings: GameSettingsProtocol {
|
||||
}
|
||||
|
||||
if let balance = defaults.object(forKey: Keys.startingBalance) as? Int {
|
||||
self.startingBalance = balance
|
||||
self.startingBalance = Self.validatedStartingBalance(balance)
|
||||
}
|
||||
|
||||
if defaults.object(forKey: Keys.showAnimations) != nil {
|
||||
@ -199,7 +199,7 @@ final class GameSettings: GameSettingsProtocol {
|
||||
}
|
||||
|
||||
if let speed = defaults.object(forKey: Keys.dealingSpeed) as? Double {
|
||||
self.dealingSpeed = speed
|
||||
self.dealingSpeed = Self.validatedDealingSpeed(speed)
|
||||
}
|
||||
|
||||
if defaults.object(forKey: Keys.showCardsRemaining) != nil {
|
||||
@ -242,7 +242,7 @@ final class GameSettings: GameSettingsProtocol {
|
||||
}
|
||||
|
||||
if let balance = store.object(forKey: Keys.startingBalance) as? Int {
|
||||
self.startingBalance = balance
|
||||
self.startingBalance = Self.validatedStartingBalance(balance)
|
||||
}
|
||||
|
||||
if store.object(forKey: Keys.showAnimations) != nil {
|
||||
@ -250,7 +250,7 @@ final class GameSettings: GameSettingsProtocol {
|
||||
}
|
||||
|
||||
if let speed = store.object(forKey: Keys.dealingSpeed) as? Double {
|
||||
self.dealingSpeed = speed
|
||||
self.dealingSpeed = Self.validatedDealingSpeed(speed)
|
||||
}
|
||||
|
||||
if store.object(forKey: Keys.showCardsRemaining) != nil {
|
||||
@ -311,6 +311,24 @@ final class GameSettings: GameSettingsProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
/// Validates a dealing speed value, returning normal if invalid.
|
||||
/// This handles legacy data that may have been saved with incorrect values.
|
||||
private static func validatedDealingSpeed(_ speed: Double) -> Double {
|
||||
let validSpeeds = [
|
||||
CasinoDesign.DealingSpeed.fast,
|
||||
CasinoDesign.DealingSpeed.normal,
|
||||
CasinoDesign.DealingSpeed.slow
|
||||
]
|
||||
return validSpeeds.contains(speed) ? speed : CasinoDesign.DealingSpeed.normal
|
||||
}
|
||||
|
||||
/// Validates a starting balance value, returning default if invalid.
|
||||
/// This handles legacy data that may have been saved with incorrect values.
|
||||
private static func validatedStartingBalance(_ balance: Int) -> Int {
|
||||
let validBalances = [1_000, 5_000, 10_000, 25_000, 50_000, 100_000]
|
||||
return validBalances.contains(balance) ? balance : 1_000
|
||||
}
|
||||
|
||||
/// Resets all settings to defaults.
|
||||
func resetToDefaults() {
|
||||
deckCount = .eight
|
||||
|
||||
@ -228,7 +228,7 @@ final class GameSettings: GameSettingsProtocol {
|
||||
self.tableLimits = limits
|
||||
}
|
||||
|
||||
self.startingBalance = data.startingBalance
|
||||
self.startingBalance = Self.validatedStartingBalance(data.startingBalance)
|
||||
self.dealerHitsSoft17 = data.dealerHitsSoft17
|
||||
self.doubleAfterSplit = data.doubleAfterSplit
|
||||
self.resplitAces = data.resplitAces
|
||||
@ -238,7 +238,7 @@ final class GameSettings: GameSettingsProtocol {
|
||||
self.insuranceAllowed = data.insuranceAllowed
|
||||
self.neverAskInsurance = data.neverAskInsurance
|
||||
self.showAnimations = data.showAnimations
|
||||
self.dealingSpeed = data.dealingSpeed
|
||||
self.dealingSpeed = Self.validatedDealingSpeed(data.dealingSpeed)
|
||||
self.showCardsRemaining = data.showCardsRemaining
|
||||
self.showHistory = data.showHistory
|
||||
self.showHints = data.showHints
|
||||
@ -276,6 +276,24 @@ final class GameSettings: GameSettingsProtocol {
|
||||
persistence.save(data)
|
||||
}
|
||||
|
||||
/// Validates a dealing speed value, returning normal if invalid.
|
||||
/// This handles legacy data that may have been saved with incorrect values.
|
||||
private static func validatedDealingSpeed(_ speed: Double) -> Double {
|
||||
let validSpeeds = [
|
||||
CasinoDesign.DealingSpeed.fast,
|
||||
CasinoDesign.DealingSpeed.normal,
|
||||
CasinoDesign.DealingSpeed.slow
|
||||
]
|
||||
return validSpeeds.contains(speed) ? speed : CasinoDesign.DealingSpeed.normal
|
||||
}
|
||||
|
||||
/// Validates a starting balance value, returning default if invalid.
|
||||
/// This handles legacy data that may have been saved with incorrect values.
|
||||
private static func validatedStartingBalance(_ balance: Int) -> Int {
|
||||
let validBalances = [1_000, 5_000, 10_000, 25_000, 50_000, 100_000]
|
||||
return validBalances.contains(balance) ? balance : 1_000
|
||||
}
|
||||
|
||||
/// Resets all settings to defaults.
|
||||
func resetToDefaults() {
|
||||
gameStyle = .vegas
|
||||
|
||||
@ -52,12 +52,12 @@ struct BlackjackSettingsData: PersistableGameData {
|
||||
roundsPlayed: 0,
|
||||
gameStyle: "vegas",
|
||||
deckCount: 6,
|
||||
tableLimits: "low",
|
||||
tableLimits: "casual",
|
||||
startingBalance: 1_000,
|
||||
dealerHitsSoft17: false,
|
||||
doubleAfterSplit: true,
|
||||
resplitAces: false,
|
||||
lateSurrender: true,
|
||||
lateSurrender: false,
|
||||
noHoleCard: false,
|
||||
blackjackPayout: 1.5,
|
||||
insuranceAllowed: true,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user