home · contact · privacy
Make add_line hack unnecessary.
authorChristian Heller <c.heller@plomlompom.de>
Tue, 30 Apr 2019 16:56:05 +0000 (18:56 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Tue, 30 Apr 2019 16:56:05 +0000 (18:56 +0200)
new/example_client.py
new/plomrogue/things.py

index 0ea2db602ff55b91aff63e6f5120d410f169b022..a88c85b3c2d642f2a7a9cce5dc3be95f46b6e010 100755 (executable)
@@ -33,10 +33,12 @@ class ClientMap(Map):
                 cut_end = cut_start + view_width
             map_lines[:] = [line[cut_start:cut_end] for line in map_lines]
 
                 cut_end = cut_start + view_width
             map_lines[:] = [line[cut_start:cut_end] for line in map_lines]
 
-    def format_to_view(self, map_cells, center, size):
+    def format_to_view(self, map_cells, center, size, indent_first_line):
 
         def map_cells_to_lines(map_cells):
 
         def map_cells_to_lines(map_cells):
-            map_view_chars = ['0']
+            map_view_chars = []
+            if indent_first_line:
+                map_view_chars += ['0']
             x = 0
             y = 0
             for cell in map_cells:
             x = 0
             y = 0
             for cell in map_cells:
@@ -49,19 +51,14 @@ class ClientMap(Map):
                     map_view_chars += ['\n']
                     x = 0
                     y += 1
                     map_view_chars += ['\n']
                     x = 0
                     y += 1
-                    if y % 2 == 0:
+                    if y % 2 == int(not indent_first_line):
                         map_view_chars += ['0']
                         map_view_chars += ['0']
-            if y % 2 == 0:
+            if y % 2 == int(not indent_first_line):
                 map_view_chars = map_view_chars[:-1]
             map_view_chars = map_view_chars[:-1]
             return ''.join(map_view_chars).split('\n')
 
         map_lines = map_cells_to_lines(map_cells)
                 map_view_chars = map_view_chars[:-1]
             map_view_chars = map_view_chars[:-1]
             return ''.join(map_view_chars).split('\n')
 
         map_lines = map_cells_to_lines(map_cells)
-        if len(map_lines) % 2 == 0:
-            map_lines = map_lines[1:]
-        else:
-            for i in range(len(map_lines)):
-                map_lines[i] = '0' + map_lines[i]
         self.y_cut(map_lines, center[1].y, size.y)
         map_width = self.size.x * 2 + 1
         self.x_cut(map_lines, center[1].x * 2, size.x, map_width)
         self.y_cut(map_lines, center[1].y, size.y)
         map_width = self.size.x * 2 + 1
         self.x_cut(map_lines, center[1].x * 2, size.x, map_width)
@@ -464,8 +461,10 @@ class MapWidget(Widget):
         center = self.tui.game.world.player.position
         if self.tui.examiner_mode:
             center = self.tui.examiner_position
         center = self.tui.game.world.player.position
         if self.tui.examiner_mode:
             center = self.tui.examiner_position
+        indent_first_line = not bool(self.tui.game.world.offset.y % 2)
         lines = self.tui.game.world.map_.\
         lines = self.tui.game.world.map_.\
-                format_to_view(annotated_terrain, center, self.size)
+                format_to_view(annotated_terrain, center, self.size,
+                               indent_first_line)
         pad_or_cut_x(lines)
         pad_y(lines)
         self.safe_write(lines_to_colored_chars(lines))
         pad_or_cut_x(lines)
         pad_y(lines)
         self.safe_write(lines_to_colored_chars(lines))
index c47e55384c72732469929e0a054468301ad93e79..4f35880b7689644a1e3f1c941f02a93898130077 100644 (file)
@@ -237,24 +237,20 @@ class ThingAnimate(Thing):
         self._surrounding_map = None
         self._surroundings_offset = None
 
         self._surrounding_map = None
         self._surroundings_offset = None
 
-    def must_fix_indentation(self):
-        return self._radius % 2 != self.position[1].y % 2
-
     def get_surroundings_offset(self):
         if self._surroundings_offset is not None:
             return self._surroundings_offset
     def get_surroundings_offset(self):
         if self._surroundings_offset is not None:
             return self._surroundings_offset
-        add_line = self.must_fix_indentation()
-        offset = YX(self.position[0].y * self.world.game.map_size.y + self.position[1].y - self._radius - int(add_line),
-                    self.position[0].x * self.world.game.map_size.x + self.position[1].x - self._radius)
+        offset = YX(self.position[0].y * self.world.game.map_size.y +
+                    self.position[1].y - self._radius,
+                    self.position[0].x * self.world.game.map_size.x +
+                    self.position[1].x - self._radius)
         self._surroundings_offset = offset
         return self._surroundings_offset
 
     def get_surrounding_map(self):
         if self._surrounding_map is not None:
             return self._surrounding_map
         self._surroundings_offset = offset
         return self._surroundings_offset
 
     def get_surrounding_map(self):
         if self._surrounding_map is not None:
             return self._surrounding_map
-        add_line = self.must_fix_indentation()
-        self._surrounding_map = Map(size=YX(self._radius*2+1+int(add_line),
-                                            self._radius*2+1))
+        self._surrounding_map = Map(size=YX(self._radius*2+1, self._radius*2+1))
         offset = self.get_surroundings_offset()
         for pos in self._surrounding_map:
             offset_pos = pos + offset
         offset = self.get_surroundings_offset()
         for pos in self._surrounding_map:
             offset_pos = pos + offset
@@ -273,8 +269,7 @@ class ThingAnimate(Thing):
         for pos in surrounding_map:
             if surrounding_map[pos] in {'.', '~'}:
                 m[pos] = '.'
         for pos in surrounding_map:
             if surrounding_map[pos] in {'.', '~'}:
                 m[pos] = '.'
-        add_line = self.must_fix_indentation()
-        fov_center = YX((add_line + m.size.y) // 2, m.size.x // 2)
+        fov_center = YX((m.size.y) // 2, m.size.x // 2)
         self._stencil = FovMapHex(m, fov_center)
         return self._stencil
 
         self._stencil = FovMapHex(m, fov_center)
         return self._stencil