home · contact · privacy
Add alternate map control preset.
authorChristian Heller <c.heller@plomlompom.de>
Sun, 27 Dec 2020 03:34:31 +0000 (04:34 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sun, 27 Dec 2020 03:34:31 +0000 (04:34 +0100)
plomrogue/commands.py
plomrogue/game.py

index ec31b12ff724774aabe11b9bb0c329f6c2a4b785..909d5bea68de4d2a50d669066343b79662847d02 100644 (file)
@@ -448,7 +448,7 @@ cmd_THING_CRATE_ITEM.argtypes = 'int:pos int:pos'
 
 def cmd_MAP_CONTROL_PRESETS(game, draw_control_presets):
     game.draw_control_presets = draw_control_presets
 
 def cmd_MAP_CONTROL_PRESETS(game, draw_control_presets):
     game.draw_control_presets = draw_control_presets
-cmd_MAP_CONTROL_PRESETS.argtypes = 'bool'
+cmd_MAP_CONTROL_PRESETS.argtypes = 'int:nonneg'
 
 def cmd_THING_SPAWNPOINT_CREATED(game, spawnpoint_id, timestamp):
     import datetime
 
 def cmd_THING_SPAWNPOINT_CREATED(game, spawnpoint_id, timestamp):
     import datetime
index 8784007d8ddeed69e8611a7510e24266c7954dd9..d51c832fd36dc2e9d353969bee079f751c62ce40 100755 (executable)
@@ -50,7 +50,14 @@ class SaveableMap(Map):
             return False
         return True
 
             return False
         return True
 
-    def draw_presets(self, alternate_hex=0):
+    def draw_presets(self, big_yx, type_):
+        if type_ == 1:
+            if big_yx.y < 0:
+                self.terrain = 'X' * self.size_i
+        elif type_ == 2:
+            self.draw_presets_grid(big_yx)
+
+    def draw_presets_grid(self, big_yx):
         old_modified = self.modified
         if type(self.geometry) == MapGeometrySquare:
             self.set_line(0, 'X' * self.geometry.size.x)
         old_modified = self.modified
         if type(self.geometry) == MapGeometrySquare:
             self.set_line(0, 'X' * self.geometry.size.x)
@@ -88,6 +95,7 @@ class SaveableMap(Map):
                                 if self.inside(yx):
                                     self[yx] = 'X'
 
                                 if self.inside(yx):
                                     self[yx] = 'X'
 
+                alternate_hex = big_yx.y % 2
                 if alternate_hex:
                     draw_snake(offset + YX(0, 0))
                 draw_snake(offset + YX((0 + alternate_hex) * distance,
                 if alternate_hex:
                     draw_snake(offset + YX(0, 0))
                 draw_snake(offset + YX((0 + alternate_hex) * distance,
@@ -147,7 +155,7 @@ class Game(GameBase):
             '=': Terrain('=', 'glass', blocks_sound=True, blocks_movement=True),
             'T': Terrain('T', 'table', blocks_movement=True),
         }
             '=': Terrain('=', 'glass', blocks_sound=True, blocks_movement=True),
             'T': Terrain('T', 'table', blocks_movement=True),
         }
-        self.draw_control_presets = True
+        self.draw_control_presets = 1
         if os.path.exists(self.io.save_file):
             if not os.path.isfile(self.io.save_file):
                 raise GameError('save file path refers to non-file')
         if os.path.exists(self.io.save_file):
             if not os.path.isfile(self.io.save_file):
                 raise GameError('save file path refers to non-file')
@@ -519,7 +527,7 @@ class Game(GameBase):
             map_geometry_shape = self.get_map_geometry_shape()
             # must come before MAP, otherwise first get_map uses the default
             # TODO: refactor into MAP
             map_geometry_shape = self.get_map_geometry_shape()
             # must come before MAP, otherwise first get_map uses the default
             # TODO: refactor into MAP
-            write(f, 'MAP_CONTROL_PRESETS %s' % int(self.draw_control_presets))
+            write(f, 'MAP_CONTROL_PRESETS %s' % self.draw_control_presets)
             write(f, 'MAP %s %s' % (map_geometry_shape, self.map_geometry.size,))
             for terrain in self.terrains.values():
                 write(f, 'TERRAIN %s %s %s %s %s' % (quote(terrain.character),
             write(f, 'MAP %s %s' % (map_geometry_shape, self.map_geometry.size,))
             for terrain in self.terrains.values():
                 write(f, 'TERRAIN %s %s %s %s %s' % (quote(terrain.character),
@@ -616,8 +624,8 @@ class Game(GameBase):
             maps = self.map_controls
         if big_yx not in maps:
             maps[big_yx] = SaveableMap(self.map_geometry)
             maps = self.map_controls
         if big_yx not in maps:
             maps[big_yx] = SaveableMap(self.map_geometry)
-            if self.draw_control_presets and type_ == 'control':
-                maps[big_yx].draw_presets(big_yx.y % 2)
+            if type_ == 'control':
+                maps[big_yx].draw_presets(big_yx, self.draw_control_presets)
         return maps[big_yx]
 
     def new_world(self, map_geometry):
         return maps[big_yx]
 
     def new_world(self, map_geometry):