Skip to content

Commit

Permalink
Delete game statistics when deleting a game
Browse files Browse the repository at this point in the history
  • Loading branch information
joeraz committed Sep 20, 2024
1 parent 148f189 commit 4a3d6e7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
13 changes: 13 additions & 0 deletions pysollib/app_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ def __resetPrevGames(self, player, games, gameid):
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]
Expand Down
2 changes: 1 addition & 1 deletion pysollib/ui/tktile/menubar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2190,7 +2190,7 @@ def mWizardDelete(self, *event):
% 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)

Expand Down
3 changes: 2 additions & 1 deletion pysollib/wizardutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,9 @@ class MyCustomGame(CustomGame):
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)

Expand Down

0 comments on commit 4a3d6e7

Please sign in to comment.