From a472160ca71aecb12356cbeffeee9b151cf4ba3f Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Tue, 27 Aug 2019 21:32:20 +0300 Subject: [PATCH] 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. --- pysollib/game/__init__.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/pysollib/game/__init__.py b/pysollib/game/__init__.py index aa5a3eea..9f0e8c2b 100644 --- a/pysollib/game/__init__.py +++ b/pysollib/game/__init__.py @@ -430,6 +430,18 @@ class GameGlobalStatsStruct(NewStruct): start_player = attr.ib(default=None) +@attr.s +class GameWinAnimation(NewStruct): + timer = attr.ib(default=None) + images = attr.ib(factory=list) + tk_images = attr.ib(factory=list) # saved tk images + saved_images = attr.ib(factory=dict) # saved resampled images + canvas_images = attr.ib(factory=list) # ids of canvas images + frame_num = attr.ib(default=0) # number of the current frame + width = attr.ib(default=0) + height = attr.ib(default=0) + + class Game(object): # for self.gstats.updated U_PLAY = _GLOBAL_U_PLAY @@ -698,16 +710,7 @@ class Game(object): comment="", ) # some vars for win animation - self.win_animation = Struct( - timer=None, - images=[], - tk_images=[], # saved tk images - saved_images={}, # saved resampled images - canvas_images=[], # ids of canvas images - frame_num=0, # number of the current frame - width=0, - height=0, - ) + self.win_animation = GameWinAnimation() def getTitleName(self): return self.app.getGameTitleName(self.id)