Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
parent
3be7fc5884
commit
c9b2a9e692
@ -140,8 +140,10 @@ public extension CasinoGameState {
|
|||||||
/// 5. Save data
|
/// 5. Save data
|
||||||
func performResetGame() {
|
func performResetGame() {
|
||||||
// 1. End current session FIRST while balance still shows actual state
|
// 1. End current session FIRST while balance still shows actual state
|
||||||
|
// Use .brokeOut if balance is 0, otherwise .manualEnd
|
||||||
if currentSession != nil {
|
if currentSession != nil {
|
||||||
endCurrentSession(reason: .manualEnd)
|
let reason: SessionEndReason = balance <= 0 ? .brokeOut : .manualEnd
|
||||||
|
endCurrentSession(reason: reason)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Reset balance to starting balance
|
// 2. Reset balance to starting balance
|
||||||
|
|||||||
@ -75,12 +75,23 @@ extension SessionManagedGame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Starts a new session.
|
/// 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() {
|
public func startNewSession() {
|
||||||
// End current session if exists
|
// End current session if exists
|
||||||
if currentSession != nil {
|
if currentSession != nil {
|
||||||
endCurrentSession(reason: .manualEnd)
|
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
|
// Create new session with current settings
|
||||||
currentSession = GameSession<Stats>(
|
currentSession = GameSession<Stats>(
|
||||||
gameStyle: currentGameStyle,
|
gameStyle: currentGameStyle,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user