mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
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.
This commit is contained in:
parent
198038b1c9
commit
6dd98f5984
2 changed files with 39 additions and 17 deletions
|
@ -65,6 +65,7 @@ from pysollib.pysoltk import bind, wm_map
|
||||||
from pysollib.settings import DEBUG
|
from pysollib.settings import DEBUG
|
||||||
from pysollib.settings import PACKAGE, TITLE, TOOLKIT, TOP_TITLE
|
from pysollib.settings import PACKAGE, TITLE, TOOLKIT, TOP_TITLE
|
||||||
from pysollib.settings import VERSION, VERSION_TUPLE
|
from pysollib.settings import VERSION, VERSION_TUPLE
|
||||||
|
from pysollib.struct_new import NewStruct
|
||||||
|
|
||||||
import six
|
import six
|
||||||
from six import BytesIO
|
from six import BytesIO
|
||||||
|
@ -259,7 +260,7 @@ def _highlightCards__calc_item(canvas, delta, cw, ch, s, c1, c2, color):
|
||||||
|
|
||||||
|
|
||||||
@attr.s
|
@attr.s
|
||||||
class StackGroups(object):
|
class StackGroups(NewStruct):
|
||||||
dropstacks = attr.ib(factory=list)
|
dropstacks = attr.ib(factory=list)
|
||||||
hp_stacks = attr.ib(factory=list) # for getHightlightPilesStacks()
|
hp_stacks = attr.ib(factory=list) # for getHightlightPilesStacks()
|
||||||
openstacks = attr.ib(factory=list)
|
openstacks = attr.ib(factory=list)
|
||||||
|
@ -280,7 +281,7 @@ class StackGroups(object):
|
||||||
|
|
||||||
|
|
||||||
@attr.s
|
@attr.s
|
||||||
class StackRegions(object):
|
class StackRegions(NewStruct):
|
||||||
# list of tuples(stacks, rect)
|
# list of tuples(stacks, rect)
|
||||||
info = attr.ib(factory=list)
|
info = attr.ib(factory=list)
|
||||||
# list of stacks in no region
|
# list of stacks in no region
|
||||||
|
@ -318,7 +319,7 @@ class StackRegions(object):
|
||||||
|
|
||||||
|
|
||||||
@attr.s
|
@attr.s
|
||||||
class GameStacks(object):
|
class GameStacks(NewStruct):
|
||||||
talon = attr.ib(default=None)
|
talon = attr.ib(default=None)
|
||||||
waste = attr.ib(default=None)
|
waste = attr.ib(default=None)
|
||||||
foundations = attr.ib(factory=list)
|
foundations = attr.ib(factory=list)
|
||||||
|
@ -333,6 +334,21 @@ class GameStacks(object):
|
||||||
self.internals = tuple(self.internals)
|
self.internals = tuple(self.internals)
|
||||||
|
|
||||||
|
|
||||||
|
@attr.s
|
||||||
|
class GameDrag(NewStruct):
|
||||||
|
event = attr.ib(default=None)
|
||||||
|
timer = attr.ib(default=None)
|
||||||
|
start_x = attr.ib(default=0)
|
||||||
|
start_y = attr.ib(default=0)
|
||||||
|
index = attr.ib(default=-1)
|
||||||
|
stack = attr.ib(default=None)
|
||||||
|
shade_stack = attr.ib(default=None)
|
||||||
|
shade_img = attr.ib(default=None)
|
||||||
|
cards = attr.ib(factory=list)
|
||||||
|
canshade_stacks = attr.ib(factory=list)
|
||||||
|
noshade_stacks = attr.ib(factory=list)
|
||||||
|
|
||||||
|
|
||||||
class Game(object):
|
class Game(object):
|
||||||
# for self.gstats.updated
|
# for self.gstats.updated
|
||||||
U_PLAY = 0
|
U_PLAY = 0
|
||||||
|
@ -534,20 +550,7 @@ class Game(object):
|
||||||
self.top = app.top
|
self.top = app.top
|
||||||
self.canvas = app.canvas
|
self.canvas = app.canvas
|
||||||
self.filename = ""
|
self.filename = ""
|
||||||
self.drag = Struct(
|
self.drag = GameDrag()
|
||||||
event=None, # current event
|
|
||||||
timer=None, # current event timer
|
|
||||||
start_x=0, # X coord of initial drag event
|
|
||||||
start_y=0, # Y coord of initial drag event
|
|
||||||
stack=None, #
|
|
||||||
cards=[], #
|
|
||||||
index=-1, #
|
|
||||||
shadows=[], # list of canvas images
|
|
||||||
shade_stack=None, # stack currently shaded
|
|
||||||
shade_img=None, # canvas image
|
|
||||||
canshade_stacks=[], # list of stacks already tested
|
|
||||||
noshade_stacks=[], # for this drag
|
|
||||||
)
|
|
||||||
if self.gstats.start_player is None:
|
if self.gstats.start_player is None:
|
||||||
self.gstats.start_player = self.app.opt.player
|
self.gstats.start_player = self.app.opt.player
|
||||||
# optional MfxCanvasText items
|
# optional MfxCanvasText items
|
||||||
|
|
19
pysollib/struct_new.py
Normal file
19
pysollib/struct_new.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#! /usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# vim:fenc=utf-8
|
||||||
|
#
|
||||||
|
# Copyright © 2019 Shlomi Fish <shlomif@cpan.org>
|
||||||
|
#
|
||||||
|
# Distributed under terms of the MIT license.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class NewStruct(object):
|
||||||
|
"""docstring for NewStruct"""
|
||||||
|
def copy(self):
|
||||||
|
ret = self.__class__()
|
||||||
|
ret.__dict__.update(self.__dict__)
|
||||||
|
return ret
|
Loading…
Add table
Reference in a new issue