mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-15 02:54:09 -04:00
Extract a common class/struct.
This is Refactoring / code cleanup. See: * https://en.wikipedia.org/wiki/God_object * https://en.wikipedia.org/wiki/Extract_class * https://en.wikipedia.org/wiki/Code_refactoring * https://www.refactoring.com/ * https://www.joelonsoftware.com/2002/01/23/rub-a-dub-dub/ Some small optimisations may have slipped in as well.
This commit is contained in:
parent
9b0b862406
commit
0ffcc12afc
1 changed files with 27 additions and 15 deletions
|
@ -397,9 +397,32 @@ class GameStatsStruct(NewStruct):
|
||||||
pause_start_time = attr.ib(default=0.0)
|
pause_start_time = attr.ib(default=0.0)
|
||||||
|
|
||||||
|
|
||||||
|
_GLOBAL_U_PLAY = 0
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s
|
||||||
|
class GameGlobalStatsStruct(NewStruct):
|
||||||
|
holded = attr.ib(default=0) # is this a holded game
|
||||||
|
# number of times this game was loaded
|
||||||
|
loaded = attr.ib(default=0)
|
||||||
|
# number of times this game was saved
|
||||||
|
saved = attr.ib(default=0)
|
||||||
|
# number of times this game was restarted
|
||||||
|
restarted = attr.ib(default=0)
|
||||||
|
goto_bookmark_moves = attr.ib(default=0) # number of goto bookmark
|
||||||
|
# did this game already update the player stats ?
|
||||||
|
updated = attr.ib(default=_GLOBAL_U_PLAY)
|
||||||
|
start_time = attr.ib()
|
||||||
|
@start_time.default
|
||||||
|
def _foofoo(self):
|
||||||
|
return time.time() # for updateTime()
|
||||||
|
total_elapsed_time = attr.ib(default=0.0)
|
||||||
|
start_player = attr.ib(default=None)
|
||||||
|
|
||||||
|
|
||||||
class Game(object):
|
class Game(object):
|
||||||
# for self.gstats.updated
|
# for self.gstats.updated
|
||||||
U_PLAY = 0
|
U_PLAY = _GLOBAL_U_PLAY
|
||||||
U_WON = -2
|
U_WON = -2
|
||||||
U_LOST = -3
|
U_LOST = -3
|
||||||
U_PERFECT = -4
|
U_PERFECT = -4
|
||||||
|
@ -658,18 +681,7 @@ class Game(object):
|
||||||
if restart:
|
if restart:
|
||||||
return
|
return
|
||||||
# global statistics survive a game restart
|
# global statistics survive a game restart
|
||||||
self.gstats = Struct(
|
self.gstats = GameGlobalStatsStruct()
|
||||||
holded=0, # is this a holded game
|
|
||||||
loaded=0, # number of times this game was loaded
|
|
||||||
saved=0, # number of times this game was saved
|
|
||||||
restarted=0, # number of times this game was restarted
|
|
||||||
goto_bookmark_moves=0, # number of goto bookmark
|
|
||||||
# did this game already update the player stats ?
|
|
||||||
updated=self.U_PLAY,
|
|
||||||
start_time=time.time(), # game start time
|
|
||||||
total_elapsed_time=0.0,
|
|
||||||
start_player=None,
|
|
||||||
)
|
|
||||||
# global saveinfo survives a game restart
|
# global saveinfo survives a game restart
|
||||||
self.gsaveinfo = Struct(
|
self.gsaveinfo = Struct(
|
||||||
bookmarks={},
|
bookmarks={},
|
||||||
|
@ -900,7 +912,7 @@ class Game(object):
|
||||||
return
|
return
|
||||||
if restart:
|
if restart:
|
||||||
if self.moves.index > 0 and self.getPlayerMoves() > 0:
|
if self.moves.index > 0 and self.getPlayerMoves() > 0:
|
||||||
self.gstats.restarted = self.gstats.restarted + 1
|
self.gstats.restarted += 1
|
||||||
return
|
return
|
||||||
self.updateStats()
|
self.updateStats()
|
||||||
stats = self.app.stats
|
stats = self.app.stats
|
||||||
|
@ -3095,7 +3107,7 @@ class Game(object):
|
||||||
game = None
|
game = None
|
||||||
with open(filename, "rb") as f:
|
with open(filename, "rb") as f:
|
||||||
game = self._undumpGame(Unpickler(f), app)
|
game = self._undumpGame(Unpickler(f), app)
|
||||||
game.gstats.loaded = game.gstats.loaded + 1
|
game.gstats.loaded += 1
|
||||||
return game
|
return game
|
||||||
|
|
||||||
def _undumpGame(self, p, app):
|
def _undumpGame(self, p, app):
|
||||||
|
|
Loading…
Add table
Reference in a new issue