1
0
Fork 0
mirror of https://github.com/shlomif/PySolFC.git synced 2025-04-05 00:02:29 -04:00

Refactoring

This commit is contained in:
Shlomi Fish 2018-03-13 15:18:36 +02:00
parent a28001d44b
commit 48cd6abcd5

View file

@ -648,14 +648,13 @@ class Game(object):
def nextGameFlags(self, id, random=None): def nextGameFlags(self, id, random=None):
f = 0 f = 0
if id != self.id: if id != self.id:
f = f | 1 f |= 1
if self.app.nextgame.cardset is not self.app.cardset: if self.app.nextgame.cardset is not self.app.cardset:
f = f | 2 f |= 2
if random is not None: if random is not None:
if random.__class__ is not self.random.__class__: if ((random.__class__ is not self.random.__class__) or
f = f | 16 random.initial_seed != self.random.initial_seed):
elif random.initial_seed != self.random.initial_seed: f |= 16
f = f | 16
return f return f
# quit to outer mainloop in class App, possibly restarting # quit to outer mainloop in class App, possibly restarting
@ -665,10 +664,9 @@ class Game(object):
self.updateTime() self.updateTime()
if bookmark: if bookmark:
id, random = self.id, self.random id, random = self.id, self.random
file = BytesIO() f = BytesIO()
p = Pickler(file, 1) self._dumpGame(Pickler(f, 1), bookmark=1)
self._dumpGame(p, bookmark=1) self.app.nextgame.bookmark = f.getvalue()
self.app.nextgame.bookmark = file.getvalue()
if id > 0: if id > 0:
self.setCursor(cursor=CURSOR_WATCH) self.setCursor(cursor=CURSOR_WATCH)
self.app.nextgame.id = id self.app.nextgame.id = id
@ -3059,11 +3057,10 @@ Congratulations, you did it !
_("Set bookmark"), _("Set bookmark"),
_("Replace existing bookmark %d ?") % (n+1)): _("Replace existing bookmark %d ?") % (n+1)):
return 0 return 0
file = BytesIO() f = BytesIO()
p = Pickler(file, 1)
try: try:
self._dumpGame(p, bookmark=2) self._dumpGame(Pickler(f, 1), bookmark=2)
bm = (file.getvalue(), self.moves.index) bm = (f.getvalue(), self.moves.index)
except Exception: except Exception:
pass pass
else: else:
@ -3182,8 +3179,7 @@ Please report this bug."""))
f = None f = None
try: try:
f = open(filename, "rb") f = open(filename, "rb")
p = Unpickler(f) game = self._undumpGame(Unpickler(f), app)
game = self._undumpGame(p, app)
game.gstats.loaded = game.gstats.loaded + 1 game.gstats.loaded = game.gstats.loaded + 1
finally: finally:
if f: if f:
@ -3289,8 +3285,7 @@ in the current implementation.''') % version)
if not self.canSaveGame(): if not self.canSaveGame():
raise Exception("Cannot save this game.") raise Exception("Cannot save this game.")
f = open(filename, "wb") f = open(filename, "wb")
p = Pickler(f, protocol) self._dumpGame(Pickler(f, protocol))
self._dumpGame(p)
finally: finally:
if f: if f:
f.close() f.close()