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

This commit is contained in:
Matt Bruce 2025-12-31 13:44:26 -06:00
parent 3be7fc5884
commit c9b2a9e692
2 changed files with 14 additions and 1 deletions

View File

@ -140,8 +140,10 @@ public extension CasinoGameState {
/// 5. Save data
func performResetGame() {
// 1. End current session FIRST while balance still shows actual state
// Use .brokeOut if balance is 0, otherwise .manualEnd
if currentSession != nil {
endCurrentSession(reason: .manualEnd)
let reason: SessionEndReason = balance <= 0 ? .brokeOut : .manualEnd
endCurrentSession(reason: reason)
}
// 2. Reset balance to starting balance

View File

@ -75,12 +75,23 @@ extension SessionManagedGame {
}
/// Starts a new session.
///
/// This uses the current `balance` as the session's starting balance. If you need to
/// start fresh with the default starting balance from settings, call `endSessionAndStartNew()`
/// instead, which properly resets the balance before creating the new session.
public func startNewSession() {
// End current session if exists
if currentSession != nil {
endCurrentSession(reason: .manualEnd)
}
// If balance is 0 or below minimum bet, reset to starting balance from settings.
// This handles the case where the player went broke and the app was restarted
// before they clicked "Play Again".
if balance <= 0 {
balance = startingBalance
}
// Create new session with current settings
currentSession = GameSession<Stats>(
gameStyle: currentGameStyle,