home · contact · privacy
Fix MAP command geometries returning invalid classes.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 30 Jan 2019 22:23:54 +0000 (23:23 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 30 Jan 2019 22:23:54 +0000 (23:23 +0100)
client-curses.py
game_common.py
server_/map_.py

index ea5dcf32f8ad34d9281de174566fe64f3a20601f..a8add972df17428ae24e9ae87be7699353c6cc13 100755 (executable)
@@ -77,7 +77,7 @@ class MapHex(Map):
         return map_lines
 
 
         return map_lines
 
 
-map_manager = game_common.MapManager(globals())
+map_manager = game_common.MapManager((MapHex, MapSquare))
 
 
 class World(game_common.World):
 
 
 class World(game_common.World):
index c0fb98b3fa9138a5766c3b6be70d47b12ad28240..7731c61eebe782e8c8e07187e9925a1d20343539 100644 (file)
@@ -3,12 +3,9 @@ from parser import ArgError
 
 class MapManager:
 
 
 class MapManager:
 
-    def __init__(self, globs):
-        """With globs a globals() call, collect caller's Map classes."""
-        self.map_classes = []
-        for name in globs:
-            if name[:3] == 'Map':
-                self.map_classes += [globs[name]]
+    def __init__(self, map_classes):
+        """Collects tuple of basic Map[Geometry] classes."""
+        self.map_classes = map_classes
 
     def get_map_geometries(self):
         geometries = []
 
     def get_map_geometries(self):
         geometries = []
index 2e87fc59b0c0ed04db0268d132b96bd89434f646..b59eceeee6174761ed8e6ffef87c84f53614f189 100644 (file)
@@ -33,9 +33,9 @@ class Map(game_common.Map):
             yield (y, self.terrain[y * width:(y + 1) * width])
 
     def get_fov_map(self, yx):
             yield (y, self.terrain[y * width:(y + 1) * width])
 
     def get_fov_map(self, yx):
-        # TODO: Currently only have MapFovHex. Provide MapFovSquare.
-        fov_map_class = map_manager.get_map_class('Fov' + self.geometry)
-        return fov_map_class(self, yx)
+        fov_class_name = 'Fov' + self.__class__.__name__
+        fov_class = globals()[fov_class_name]
+        return fov_class(self, yx)
 
     # The following is used nowhere, so not implemented.
     #def items(self):
 
     # The following is used nowhere, so not implemented.
     #def items(self):
@@ -139,7 +139,7 @@ class MapHex(Map):
         return neighbors
 
 
         return neighbors
 
 
-class MapFovHex(MapHex):
+class FovMapHex(MapHex):
 
     def __init__(self, source_map, yx):
         self.source_map = source_map
 
     def __init__(self, source_map, yx):
         self.source_map = source_map
@@ -276,7 +276,7 @@ class MapSquare(Map):
         return neighbors
 
 
         return neighbors
 
 
-class MapFovSquare(MapSquare):
+class FovMapSquare(MapSquare):
     """Just a marginally and unsatisfyingly adapted variant of MapFovHex."""
 
     def __init__(self, source_map, yx):
     """Just a marginally and unsatisfyingly adapted variant of MapFovHex."""
 
     def __init__(self, source_map, yx):
@@ -376,4 +376,4 @@ class MapFovSquare(MapSquare):
             distance += 1
 
 
             distance += 1
 
 
-map_manager = game_common.MapManager(globals())
+map_manager = game_common.MapManager((MapHex, MapSquare))