From 2a55a16227a7ae86b2ff998edff80d217deae5c9 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 29 Dec 2025 13:51:26 -0600 Subject: [PATCH] Signed-off-by: Matt Bruce --- Baccarat/Baccarat/Engine/GameState.swift | 14 +++---- Blackjack/Blackjack/Engine/GameState.swift | 14 ------- .../Models/Session/SessionManager.swift | 38 +++++++++++++++++++ 3 files changed, 43 insertions(+), 23 deletions(-) diff --git a/Baccarat/Baccarat/Engine/GameState.swift b/Baccarat/Baccarat/Engine/GameState.swift index 0662881..65a00ed 100644 --- a/Baccarat/Baccarat/Engine/GameState.swift +++ b/Baccarat/Baccarat/Engine/GameState.swift @@ -929,20 +929,16 @@ final class GameState: SessionManagedGame { } } - // MARK: - Session History Management + // MARK: - Session Cleanup Hooks - /// Deletes a session from history by ID. - func deleteSession(id: UUID) { - sessionHistory.removeAll { $0.id == id } + /// Clean up round history when deleting a session. + func onWillDeleteSession(id: UUID) { sessionRoundHistories.removeValue(forKey: id.uuidString) - saveGameData() } - /// Deletes all session history. - func deleteAllSessionHistory() { - sessionHistory.removeAll() + /// Clean up all round histories when deleting all sessions. + func onWillDeleteAllSessions() { sessionRoundHistories.removeAll() - saveGameData() } // MARK: - Session Round History diff --git a/Blackjack/Blackjack/Engine/GameState.swift b/Blackjack/Blackjack/Engine/GameState.swift index d947347..42bece2 100644 --- a/Blackjack/Blackjack/Engine/GameState.swift +++ b/Blackjack/Blackjack/Engine/GameState.swift @@ -1204,20 +1204,6 @@ final class GameState: SessionManagedGame { allSessions.aggregatedBlackjackStats() } - // MARK: - Session History Management - - /// Deletes a session from history by ID. - func deleteSession(id: UUID) { - sessionHistory.removeAll { $0.id == id } - saveGameData() - } - - /// Deletes all session history. - func deleteAllSessionHistory() { - sessionHistory.removeAll() - saveGameData() - } - // MARK: - Game Reset /// Resets the entire game (keeps statistics). diff --git a/CasinoKit/Sources/CasinoKit/Models/Session/SessionManager.swift b/CasinoKit/Sources/CasinoKit/Models/Session/SessionManager.swift index 59460e8..b3c270d 100644 --- a/CasinoKit/Sources/CasinoKit/Models/Session/SessionManager.swift +++ b/CasinoKit/Sources/CasinoKit/Models/Session/SessionManager.swift @@ -44,11 +44,23 @@ public protocol SessionManagedGame: AnyObject { /// Current game style identifier (e.g., "vegas", "european"). var currentGameStyle: String { get } + /// Whether the end session confirmation dialog should be shown. + /// Games should bind this to their confirmation dialog. + var showEndSessionConfirmation: Bool { get set } + /// Called to persist game data after session changes. func saveGameData() /// Called when starting a new session to reset game-specific state. func resetForNewSession() + + /// Called before a session is deleted. Override to clean up associated data. + /// Default implementation does nothing. + func onWillDeleteSession(id: UUID) + + /// Called before all session history is deleted. Override to clean up associated data. + /// Default implementation does nothing. + func onWillDeleteAllSessions() } // MARK: - Default Session Management Implementation @@ -170,6 +182,32 @@ extension SessionManagedGame { public func aggregatedStats(forStyle style: String) -> AggregatedSessionStats { sessions(forStyle: style).aggregatedStats() } + + // MARK: - Session History Management + + /// Default implementation - does nothing. Override to clean up session-specific data. + public func onWillDeleteSession(id: UUID) { + // Override in game to clean up associated data (e.g., round histories) + } + + /// Default implementation - does nothing. Override to clean up all session data. + public func onWillDeleteAllSessions() { + // Override in game to clean up associated data (e.g., round histories) + } + + /// Deletes a session from history by ID. + public func deleteSession(id: UUID) { + onWillDeleteSession(id: id) + sessionHistory.removeAll { $0.id == id } + saveGameData() + } + + /// Deletes all session history. + public func deleteAllSessionHistory() { + onWillDeleteAllSessions() + sessionHistory.removeAll() + saveGameData() + } } // MARK: - Session Formatter