From fab74e9a4b798d8f9ffb92ec67d672f4d1c420fd Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Sun, 29 Dec 2019 11:37:13 +0200 Subject: [PATCH] Extract a function or class to step away from God Object. See: * https://en.wikipedia.org/wiki/God_object * https://www.c-sharpcorner.com/article/god-object-a-code-smell/ . This is Refactoring / code cleanup. See: * https://refactoring.com/catalog/extractMethod.html * 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 | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pysollib/game/__init__.py b/pysollib/game/__init__.py index 1296efae..dc274c94 100644 --- a/pysollib/game/__init__.py +++ b/pysollib/game/__init__.py @@ -458,6 +458,13 @@ class GameLoadInfo(NewStruct): talon_round = attr.ib(default=1) +# global saveinfo survives a game restart +@attr.s +class GameGlobalSaveInfo(NewStruct): + bookmarks = attr.ib(factory=dict) + comment = attr.ib(default="") + + class Game(object): # for self.gstats.updated U_PLAY = _GLOBAL_U_PLAY @@ -716,11 +723,7 @@ class Game(object): return # global statistics survive a game restart self.gstats = GameGlobalStatsStruct() - # global saveinfo survives a game restart - self.gsaveinfo = Struct( - bookmarks={}, - comment="", - ) + self.gsaveinfo = GameGlobalSaveInfo() # some vars for win animation self.win_animation = GameWinAnimation()