From 3c93a1950802967656e1cbebcaf870ca94c92820 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Fri, 26 Jul 2019 16:21:07 +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 | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/pysollib/game/__init__.py b/pysollib/game/__init__.py index 903ac41d..acbb8f72 100644 --- a/pysollib/game/__init__.py +++ b/pysollib/game/__init__.py @@ -350,6 +350,16 @@ class GameDrag(NewStruct): shadows = attr.ib(factory=list) +@attr.s +class GameTexts(NewStruct): + info = attr.ib(default=None) + help = attr.ib(default=None) + misc = attr.ib(default=None) + score = attr.ib(default=None) + base_rank = attr.ib(default=None) + list = attr.ib(factory=list) + + class Game(object): # for self.gstats.updated U_PLAY = 0 @@ -555,14 +565,7 @@ class Game(object): if self.gstats.start_player is None: self.gstats.start_player = self.app.opt.player # optional MfxCanvasText items - self.texts = Struct( - info=None, # misc info text - help=None, # a static help text - misc=None, # - score=None, # for displaying the score - base_rank=None, # for displaying the base_rank - list=[], # list of texts (if we use many text) - ) + self.texts = GameTexts() # initial position of the texts self.init_texts = Struct( info=None, # misc info text