From 7cb6d9c8b592cc5c8bb168a0a066c9d6103082cd Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Mon, 24 Jun 2019 16:53:57 +0300 Subject: [PATCH] extract a method. --- pysollib/{game.py => game/__init__.py} | 36 ++--------------- pysollib/game/dump.py | 55 ++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 33 deletions(-) rename pysollib/{game.py => game/__init__.py} (99%) create mode 100644 pysollib/game/dump.py diff --git a/pysollib/game.py b/pysollib/game/__init__.py similarity index 99% rename from pysollib/game.py rename to pysollib/game/__init__.py index 257397da..8a7f6e96 100644 --- a/pysollib/game.py +++ b/pysollib/game/__init__.py @@ -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 diff --git a/pysollib/game/dump.py b/pysollib/game/dump.py new file mode 100644 index 00000000..40046a06 --- /dev/null +++ b/pysollib/game/dump.py @@ -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 . +# +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")