mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
Added alt unpickler hack for backward compatibility with saves.
This commit is contained in:
parent
0a10c72524
commit
a306f65424
1 changed files with 25 additions and 3 deletions
|
@ -267,6 +267,26 @@ def _highlightCards__calc_item(canvas, delta, cw, ch, s, c1, c2, color):
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
class random_dummy:
|
||||||
|
seed = {}
|
||||||
|
|
||||||
|
|
||||||
|
# the _alt_unpickler is an unpickler that contains a few hacks
|
||||||
|
# to ensure backward compatibility of saves.
|
||||||
|
class _alt_unpickler(Unpickler):
|
||||||
|
version = 0
|
||||||
|
|
||||||
|
def set_version(self, version_tuple):
|
||||||
|
if version_tuple < (2, 20, 0):
|
||||||
|
self.version = 1
|
||||||
|
|
||||||
|
def find_class(self, module, name):
|
||||||
|
if self.version == 1 and module == 'pysol_cards.random':
|
||||||
|
return random_dummy
|
||||||
|
else:
|
||||||
|
return super().find_class(module, name)
|
||||||
|
|
||||||
|
|
||||||
@attr.s
|
@attr.s
|
||||||
class StackGroups(NewStruct):
|
class StackGroups(NewStruct):
|
||||||
dropstacks = attr.ib(factory=list)
|
dropstacks = attr.ib(factory=list)
|
||||||
|
@ -906,7 +926,7 @@ class Game(object):
|
||||||
def restoreGameFromBookmark(self, bookmark):
|
def restoreGameFromBookmark(self, bookmark):
|
||||||
old_busy, self.busy = self.busy, 1
|
old_busy, self.busy = self.busy, 1
|
||||||
file = BytesIO(bookmark)
|
file = BytesIO(bookmark)
|
||||||
p = Unpickler(file)
|
p = _alt_unpickler(file)
|
||||||
game = self._undumpGame(p, self.app)
|
game = self._undumpGame(p, self.app)
|
||||||
assert game.id == self.id
|
assert game.id == self.id
|
||||||
self.restoreGame(game, reset=0)
|
self.restoreGame(game, reset=0)
|
||||||
|
@ -3168,7 +3188,7 @@ class Game(object):
|
||||||
s, moves_index = bm
|
s, moves_index = bm
|
||||||
self.setCursor(cursor=CURSOR_WATCH)
|
self.setCursor(cursor=CURSOR_WATCH)
|
||||||
file = BytesIO(s)
|
file = BytesIO(s)
|
||||||
p = Unpickler(file)
|
p = _alt_unpickler(file)
|
||||||
game = self._undumpGame(p, self.app)
|
game = self._undumpGame(p, self.app)
|
||||||
assert game.id == self.id
|
assert game.id == self.id
|
||||||
# save state for undoGotoBookmark
|
# save state for undoGotoBookmark
|
||||||
|
@ -3257,8 +3277,9 @@ class Game(object):
|
||||||
def _loadGame(self, filename, app):
|
def _loadGame(self, filename, app):
|
||||||
game = None
|
game = None
|
||||||
with open(filename, "rb") as f:
|
with open(filename, "rb") as f:
|
||||||
game = self._undumpGame(Unpickler(f), app)
|
game = self._undumpGame(_alt_unpickler(f), app)
|
||||||
game.gstats.loaded += 1
|
game.gstats.loaded += 1
|
||||||
|
|
||||||
return game
|
return game
|
||||||
|
|
||||||
def _undumpGame(self, p, app):
|
def _undumpGame(self, p, app):
|
||||||
|
@ -3292,6 +3313,7 @@ class Game(object):
|
||||||
_('Cannot load games saved with\n%(app)s version %(ver)s') % {
|
_('Cannot load games saved with\n%(app)s version %(ver)s') % {
|
||||||
'app': PACKAGE,
|
'app': PACKAGE,
|
||||||
'ver': version})
|
'ver': version})
|
||||||
|
p.set_version(version_tuple)
|
||||||
game_version = 1
|
game_version = 1
|
||||||
bookmark = pload(int)
|
bookmark = pload(int)
|
||||||
validate(0 <= bookmark <= 2, err_txt)
|
validate(0 <= bookmark <= 2, err_txt)
|
||||||
|
|
Loading…
Add table
Reference in a new issue