home · contact · privacy
Only save maps that have been modified from default.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 18 Nov 2020 02:53:56 +0000 (03:53 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 18 Nov 2020 02:53:56 +0000 (03:53 +0100)
plomrogue/game.py
plomrogue/mapping.py

index 3a33660da10dcae09b6a82fe95c24ba252e1668e..ccd51dcc1b363e1d6e1cb46428dd96b61ad023cb 100755 (executable)
@@ -34,6 +34,19 @@ class GameBase:
 
 
 
 
 
 
+class SaveableMap(Map):
+    modified = False
+
+    def __setitem__(self, *args, **kwargs):
+        super().__setitem__(*args, **kwargs)
+        self.modified = True
+
+    def set_line(self, *args, **kwargs):
+        super().set_line(*args, **kwargs)
+        self.modified = True
+
+
+
 import os
 class Game(GameBase):
 
 import os
 class Game(GameBase):
 
@@ -219,13 +232,12 @@ class Game(GameBase):
           f.write(msg + '\n')
 
       with open(self.io.save_file, 'w') as f:
           f.write(msg + '\n')
 
       with open(self.io.save_file, 'w') as f:
-          # TODO: save tasks
           write(f, 'TURN %s' % self.turn)
           map_geometry_shape = self.get_map_geometry_shape()
           write(f, 'MAP %s %s' % (map_geometry_shape, self.map_geometry.size,))
           write(f, 'TURN %s' % self.turn)
           map_geometry_shape = self.get_map_geometry_shape()
           write(f, 'MAP %s %s' % (map_geometry_shape, self.map_geometry.size,))
-          for yx in self.maps:
-              for y, line in self.maps[yx].lines():
-                  write(f, 'MAP_LINE %s %5s %s' % (yx, y, quote(line)))
+          for big_yx in [yx for yx in self.maps if self.maps[yx].modified]:
+              for y, line in self.maps[big_yx].lines():
+                  write(f, 'MAP_LINE %s %5s %s' % (big_yx, y, quote(line)))
           for big_yx in self.annotations:
               for little_yx in self.annotations[big_yx]:
                   write(f, 'GOD_ANNOTATE %s %s %s' %
           for big_yx in self.annotations:
               for little_yx in self.annotations[big_yx]:
                   write(f, 'GOD_ANNOTATE %s %s %s' %
@@ -234,9 +246,10 @@ class Game(GameBase):
               for little_yx in self.portals[big_yx]:
                   write(f, 'GOD_PORTAL %s %s %s' % (big_yx, little_yx,
                                                     quote(self.portals[big_yx][little_yx])))
               for little_yx in self.portals[big_yx]:
                   write(f, 'GOD_PORTAL %s %s %s' % (big_yx, little_yx,
                                                     quote(self.portals[big_yx][little_yx])))
-          for yx in self.map_controls:
-              for y, line in self.map_controls[yx].lines():
-                  write(f, 'MAP_CONTROL_LINE %s %5s %s' % (yx, y, quote(line)))
+          for big_yx in [yx for yx in self.map_controls
+                         if self.map_controls[yx].modified]:
+              for y, line in self.map_controls[big_yx].lines():
+                  write(f, 'MAP_CONTROL_LINE %s %5s %s' % (big_yx, y, quote(line)))
           for tile_class in self.map_control_passwords:
               write(f, 'MAP_CONTROL_PW %s %s' % (tile_class,
                                                  self.map_control_passwords[tile_class]))
           for tile_class in self.map_control_passwords:
               write(f, 'MAP_CONTROL_PW %s %s' % (tile_class,
                                                  self.map_control_passwords[tile_class]))
@@ -252,11 +265,11 @@ class Game(GameBase):
         elif type_ == 'control':
             maps = self.map_controls
         if not big_yx in maps:
         elif type_ == 'control':
             maps = self.map_controls
         if not big_yx in maps:
-            maps[big_yx] = Map(self.map_geometry)
+            maps[big_yx] = SaveableMap(self.map_geometry)
         return maps[big_yx]
 
     def new_world(self, map_geometry):
         self.map_geometry = map_geometry
         return maps[big_yx]
 
     def new_world(self, map_geometry):
         self.map_geometry = map_geometry
-        self.maps[YX(0,0)] = Map(self.map_geometry)
-        self.map_controls[YX(0,0)] = Map(self.map_geometry)
+        self.maps[YX(0,0)] = SaveableMap(self.map_geometry)
+        self.map_controls[YX(0,0)] = SaveableMap(self.map_geometry)
         self.annotations = {}
         self.annotations = {}
index 99924bc599bdf396c68115463fafbe4fba23eb99..09845fae1aa219b7421b0cb45ed4868182c248af 100644 (file)
@@ -206,6 +206,7 @@ class Map():
             yield (y, self.terrain[y * width:(y + 1) * width])
 
 
             yield (y, self.terrain[y * width:(y + 1) * width])
 
 
+
 class SourcedMap(Map):
 
     def __init__(self, source_maps, source_center, radius, get_map):
 class SourcedMap(Map):
 
     def __init__(self, source_maps, source_center, radius, get_map):