Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
parent
f1b834c47e
commit
2a55a16227
@ -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
|
||||
|
||||
@ -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).
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user