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

extract a method.

This commit is contained in:
Shlomi Fish 2019-06-24 16:53:57 +03:00
parent fd797ffbf5
commit 7cb6d9c8b5
2 changed files with 58 additions and 33 deletions

View file

@ -29,6 +29,7 @@ from pickle import Pickler, Unpickler, UnpicklingError
from pysol_cards.cards import ms_rearrange
from pysollib.game.dump import pysolDumpGame
from pysollib.gamedb import GI
from pysollib.help import help_about
from pysollib.hint import DefaultHint
@ -51,7 +52,7 @@ from pysollib.move import AUpdateStackMove
from pysollib.mygettext import _
from pysollib.mygettext import ungettext
from pysollib.pysolrandom import LCRandom31, PysolRandom, constructRandom, \
random__long2str, random__str2long
random__long2str
from pysollib.pysoltk import CURSOR_WATCH
from pysollib.pysoltk import Card
from pysollib.pysoltk import EVENT_HANDLED, EVENT_PROPAGATE
@ -3271,38 +3272,7 @@ in the current implementation.''') % version)
self._dumpGame(Pickler(f, protocol))
def _dumpGame(self, p, bookmark=0):
self.updateTime()
assert 0 <= bookmark <= 2
p.dump(PACKAGE)
p.dump(VERSION)
p.dump(VERSION_TUPLE)
p.dump(bookmark)
p.dump(self.GAME_VERSION)
p.dump(self.id)
#
p.dump(random__str2long(self.random.getSeedStr()))
p.dump(self.random.getstate())
#
p.dump(len(self.allstacks))
for stack in self.allstacks:
p.dump(len(stack.cards))
for card in stack.cards:
p.dump(card.id)
p.dump(card.face_up)
p.dump(self.s.talon.round)
p.dump(self.finished)
if 0 <= bookmark <= 1:
p.dump(self.saveinfo)
p.dump(self.gsaveinfo)
p.dump(self.moves)
p.dump(self.snapshots)
if 0 <= bookmark <= 1:
if bookmark == 0:
self.gstats.saved = self.gstats.saved + 1
p.dump(self.gstats)
p.dump(self.stats)
self._saveGameHook(p)
p.dump("EOF")
return pysolDumpGame(self, p, bookmark)
#
# Playing time

55
pysollib/game/dump.py Normal file
View file

@ -0,0 +1,55 @@
# Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer
# Copyright (C) 2003 Mt. Hood Playing Card Co.
# Copyright (C) 2005-2009 Skomoroh
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from pysollib.pysolrandom import random__str2long
from pysollib.settings import PACKAGE
from pysollib.settings import VERSION, VERSION_TUPLE
def pysolDumpGame(game_, p, bookmark=0):
game_.updateTime()
assert 0 <= bookmark <= 2
p.dump(PACKAGE)
p.dump(VERSION)
p.dump(VERSION_TUPLE)
p.dump(bookmark)
p.dump(game_.GAME_VERSION)
p.dump(game_.id)
#
p.dump(random__str2long(game_.random.getSeedStr()))
p.dump(game_.random.getstate())
#
p.dump(len(game_.allstacks))
for stack in game_.allstacks:
p.dump(len(stack.cards))
for card in stack.cards:
p.dump(card.id)
p.dump(card.face_up)
p.dump(game_.s.talon.round)
p.dump(game_.finished)
if 0 <= bookmark <= 1:
p.dump(game_.saveinfo)
p.dump(game_.gsaveinfo)
p.dump(game_.moves)
p.dump(game_.snapshots)
if 0 <= bookmark <= 1:
if bookmark == 0:
game_.gstats.saved += 1
p.dump(game_.gstats)
p.dump(game_.stats)
game_._saveGameHook(p)
p.dump("EOF")