X-Git-Url: https://plomlompom.com/repos/?p=plomrogue2-experiments;a=blobdiff_plain;f=game_common.py;h=1119ce1b4f8b694a6f8a7f5da6b8686d07434752;hp=2277f13c36ab99469dfdaf62cde8d25ac0046fcd;hb=8ddccb6e5601f8df54f9cbc4c376ad76aee2fe78;hpb=64bf1873a6686c1bc974321c13d3c9f7800db0d6 diff --git a/game_common.py b/game_common.py index 2277f13..1119ce1 100644 --- a/game_common.py +++ b/game_common.py @@ -1,6 +1,27 @@ from parser import ArgError +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 get_map_geometries(self): + geometries = [] + for map_class in self.map_classes: + geometries += [map_class.__name__[3:]] + return geometries + + def get_map_class(self, geometry): + for map_class in self.map_classes: + if map_class.__name__[3:] == geometry: + return map_class + + class Map: def __init__(self, size=(0, 0)): @@ -42,7 +63,7 @@ class World: return t def new_map(self, geometry, yx): - map_type = self.get_map_class(geometry) + map_type = self.game.map_manager.get_map_class(geometry) self.map_ = map_type(yx) @@ -59,12 +80,12 @@ class CommonCommandsMixin: def cmd_MAP(self, geometry, yx): """Create new map of grid geometry, size yx and only '?' cells.""" - legal_grids = {'Hex', 'Square'} + legal_grids = self.map_manager.get_map_geometries() if geometry not in legal_grids: raise ArgError('First map argument must be one of: ' + ', '.join(legal_grids)) self.world.new_map(geometry, yx) - cmd_MAP.argtypes = 'string yx_tuple:nonneg' + cmd_MAP.argtypes = 'string yx_tuple:pos' def cmd_THING_TYPE(self, i, type_): t = self.world.get_thing(i)