From 4a3d6e7383451c2b28732c4a88c67b6047b6fe9f Mon Sep 17 00:00:00 2001 From: Joe R Date: Thu, 19 Sep 2024 21:41:56 -0400 Subject: [PATCH] Delete game statistics when deleting a game --- pysollib/app_statistics.py | 13 +++++++++++++ pysollib/ui/tktile/menubar.py | 2 +- pysollib/wizardutil.py | 3 ++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/pysollib/app_statistics.py b/pysollib/app_statistics.py index c2117ffc..ba839b05 100644 --- a/pysollib/app_statistics.py +++ b/pysollib/app_statistics.py @@ -72,6 +72,19 @@ class Statistics: else: games[player] = [g for g in games[player] if g[0] != gameid] + def deleteGameStats(self, gameid): + for player in self.games_stats: + try: + del self.games_stats[player][gameid] + except KeyError: + pass + for player in self.prev_games: + self.prev_games[player] = \ + [g for g in self.prev_games[player] if g[0] != gameid] + for player in self.session_games: + self.session_games[player] = \ + [g for g in self.session_games[player] if g[0] != gameid] + def getStats(self, player, gameid): # returned (won, lost) return self.getFullStats(player, gameid)[:2] diff --git a/pysollib/ui/tktile/menubar.py b/pysollib/ui/tktile/menubar.py index 7cc9fb36..36fed857 100644 --- a/pysollib/ui/tktile/menubar.py +++ b/pysollib/ui/tktile/menubar.py @@ -2190,7 +2190,7 @@ Error while saving game. % self.game.gameinfo.name): return from pysollib.wizardutil import delete_game - delete_game(self.game) + delete_game(self.app, self.game) self.game.endGame() self.game.quitGame(2) diff --git a/pysollib/wizardutil.py b/pysollib/wizardutil.py index a8de420e..532cf594 100644 --- a/pysollib/wizardutil.py +++ b/pysollib/wizardutil.py @@ -471,8 +471,9 @@ registerCustomGame(MyCustomGame) return gameid -def delete_game(game): +def delete_game(app, game): hideGame(game) + app.stats.deleteGameStats(game.id) fn = game.MODULE_FILENAME os.remove(fn)