home · contact · privacy
Turn game saving from command to happening every new turn.
authorChristian Heller <c.heller@plomlompom.de>
Sun, 25 Oct 2020 04:03:45 +0000 (05:03 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 25 Oct 2020 04:03:45 +0000 (05:03 +0100)
new2/plomrogue/commands.py
new2/plomrogue/game.py

index df347289f64459ce4718df6aefb6a87a6ec920d2..397dbe45f332aae29d22e6fba8671786496a4316 100644 (file)
@@ -39,17 +39,6 @@ def cmd_PING(game, connection_id):
     game.io.send('PONG')
 cmd_PING.argtypes = ''
 
-def cmd_SAVE(game):
-
-    def write(f, msg):
-        f.write(msg + '\n')
-
-    with open(game.io.save_file, 'w') as f:
-        write(f, 'TURN %s' % game.turn)
-        for y, line in game.map.lines():
-            write(f, 'MAP_LINE %5s %s' % (y, quote(line)))
-cmd_SAVE.argtypes = ''
-
 def cmd_TURN(game, n):
     game.turn = n
 cmd_TURN.argtypes = 'int:nonneg'
index 6325fd0d0849dc9ef37df9612046fcf92f54ba1d..4a4f2972756832a647582cdc5503a60e7d329b42 100755 (executable)
@@ -1,7 +1,7 @@
 from plomrogue.tasks import Task_WAIT, Task_MOVE, Task_WRITE
 from plomrogue.errors import GameError
 from plomrogue.commands import (cmd_ALL, cmd_LOGIN, cmd_QUERY, cmd_PING,
-                                cmd_SAVE, cmd_TURN, cmd_MAP_LINE)
+                                cmd_TURN, cmd_MAP_LINE)
 from plomrogue.io import GameIO
 from plomrogue.misc import quote
 from plomrogue.things import Thing, ThingPlayer 
@@ -44,7 +44,6 @@ class Game(GameBase):
         self.commands = {'QUERY': cmd_QUERY,
                          'ALL': cmd_ALL,
                          'LOGIN': cmd_LOGIN,
-                         'SAVE': cmd_SAVE,
                          'TURN': cmd_TURN,
                          'MAP_LINE': cmd_MAP_LINE,
                          'PING': cmd_PING}
@@ -106,6 +105,7 @@ class Game(GameBase):
             self.turn += 1
             self.send_gamestate()
             self.changed = False
+            self.save()
 
     def get_command(self, command_name):
 
@@ -149,3 +149,13 @@ class Game(GameBase):
         # the more obvious indicators that it does – that's why there's
         # no safeguard here against this.
         return self.things[-1].id_ + 1
+
+    def save(self):
+
+      def write(f, msg):
+          f.write(msg + '\n')
+
+      with open(self.io.save_file, 'w') as f:
+          write(f, 'TURN %s' % self.turn)
+          for y, line in self.map.lines():
+              write(f, 'MAP_LINE %5s %s' % (y, quote(line)))