home · contact · privacy
More refactoring.
authorChristian Heller <c.heller@plomlompom.de>
Tue, 30 Apr 2019 20:22:03 +0000 (22:22 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Tue, 30 Apr 2019 20:22:03 +0000 (22:22 +0200)
new/plomrogue/mapping.py
new/plomrogue/things.py

index e6ae9871b13fabaeb24f7e6bc76892c03a1e8099..33a8aa95f0978a17f743d919017d20adf3cf05ad 100644 (file)
@@ -97,6 +97,20 @@ class MapGeometry():
     def pos_in_view(self, pos, offset, maps_size):
         return self.undouble_coordinate(maps_size, pos) - offset
 
+    def get_view(self, maps_size, get_map, radius, view_offset):
+        m = Map(size=YX(radius*2+1, radius*2+1)
+        for pos in m:
+            seen_pos = self.correct_double_coordinate(maps_size, (0,0),
+                                                      pos + view_offset)
+            seen_map = get_map(seen_pos[0], False)
+            if seen_map is None:
+                seen_map = Map(size=maps_size)
+            m[pos] = seen_map[seen_pos[1]]
+        return m
+
+    def get_correcting_map_size(self, size, offset):
+        return size
+
     def correct_double_coordinate(self, map_size, big_yx, little_yx):
 
         def adapt_axis(axis):
@@ -169,7 +183,6 @@ class MapGeometryHex(MapGeometryWithLeftRightMoves):
             return YX(start_pos.y + 1, start_pos.x + 1)
 
 
-
 class FovMap(Map):
 
     def __init__(self, source_map, center):
index db37a04bd11e09d14c912ae79e4aee0f5b05623e..aded05c60d777918d975023968c8dd1959111d56 100644 (file)
@@ -246,7 +246,7 @@ class ThingAnimate(Thing):
 
     def unset_surroundings(self):
         self._stencil = None
-        self._surrounding_map = None
+        self._surroundings = None
 
     @property
     def view_offset(self):
@@ -254,27 +254,22 @@ class ThingAnimate(Thing):
                                                       self.position,
                                                       self._radius)
 
-    def get_surrounding_map(self):
-        if self._surrounding_map is not None:
-            return self._surrounding_map
-        self._surrounding_map = Map(size=YX(self._radius*2+1, self._radius*2+1))
-        for pos in self._surrounding_map:
-            correct = self.game.map_geometry.correct_double_coordinate
-            big_yx, small_yx = correct(self.game.map_size, (0,0),
-                                       pos + self.view_offset)
-            map_ = self.game.get_map(big_yx, False)
-            if map_ is None:
-                map_ = Map(size=self.game.map_size)
-            self._surrounding_map[pos] = map_[small_yx]
-        return self._surrounding_map
+    @property
+    def surroundings(self):
+        if self._surroundings is not None:
+            return self._surroundings
+        s = self.game.map_geometry.get_view(self.game.map_size,
+                                            self.game.get_map,
+                                            self._radius, self.view_offset)
+        self._surroundings = s
+        return self._surroundings
 
     def get_stencil(self):
         if self._stencil is not None:
             return self._stencil
-        surrounding_map = self.get_surrounding_map()
-        m = Map(surrounding_map.size, ' ')
-        for pos in surrounding_map:
-            if surrounding_map[pos] in {'.', '~'}:
+        m = Map(self.surroundings.size, ' ')
+        for pos in self.surroundings:
+            if self.surroundings[pos] in {'.', '~'}:
                 m[pos] = '.'
         fov_center = YX((m.size.y) // 2, m.size.x // 2)
         self._stencil = FovMapHex(m, fov_center)
@@ -282,10 +277,10 @@ class ThingAnimate(Thing):
 
     def get_visible_map(self):
         stencil = self.get_stencil()
-        m = Map(self.get_surrounding_map().size, ' ')
+        m = Map(self.surroundings.size, ' ')
         for pos in m:
             if stencil[pos] == '.':
-                m[pos] = self._surrounding_map[pos]
+                m[pos] = self.surroundings[pos]
         return m
 
     def get_visible_things(self):