Allow changing the typeclass of xyzroom and xyzexit during test prep.

This commit is contained in:
henddher 2022-10-08 08:54:41 -05:00
parent 38768d137d
commit 18138ea3d8

View file

@ -1425,6 +1425,34 @@ class TestXyzExit(xyzroom.XYZExit):
def at_object_creation(self): def at_object_creation(self):
breakpoint() breakpoint()
MAP_DATA = {
"map": """
+ 0 1
0 #-#
+ 0 1
""",
"zcoord": "map1",
"prototypes": {
("*", "*"): {
"key": "room",
"desc": "A room.",
"prototype_parent": "xyz_room",
},
("*", "*", "*"): {
"desc": "A passage.",
"prototype_parent": "xyz_exit",
}
},
"options": {
"map_visual_range": 1,
"map_mode": "scan",
}
}
# @override_settings( # @override_settings(
# XYZEXIT_PROTOTYPE_OVERRIDE= { # XYZEXIT_PROTOTYPE_OVERRIDE= {
# "typeclass": "evennia.contrib.grid.xyzgrid.tests.TestXyzExit", # "typeclass": "evennia.contrib.grid.xyzgrid.tests.TestXyzExit",
@ -1434,62 +1462,54 @@ class TestXyzExit(xyzroom.XYZExit):
# } # }
# ) # )
class TestCallbacks(BaseEvenniaTest): class TestCallbacks(BaseEvenniaTest):
@override_settings( # @override_settings(
XYZEXIT_PROTOTYPE_OVERRIDE={ # XYZEXIT_PROTOTYPE_OVERRIDE={
"typeclass": "evennia.contrib.grid.xyzgrid.tests.TestXyzExit", # "typeclass": "evennia.contrib.grid.xyzgrid.tests.TestXyzExit",
}, # },
XYZROOM_PROTOTYPE_OVERRIDE={ # XYZROOM_PROTOTYPE_OVERRIDE={
"typeclass": "evennia.contrib.grid.xyzgrid.tests.TestXyzRoom", # "typeclass": "evennia.contrib.grid.xyzgrid.tests.TestXyzRoom",
}) # })
def setUp(self): # def setUp(self):
super().setUp() # super().setUp()
# self.setup_grid(MAP_DATA)
from evennia.prototypes import prototypes as protlib def setup_grid(self, map_data):
for prototype_key in ('xyz_room', 'xyz_exit', 'xyzroom', 'xyzexit'): # from evennia.prototypes import prototypes as protlib
proto = protlib.search_prototype( # for prototype_key in ('xyz_room', 'xyz_exit', 'xyzroom', 'xyzexit'):
prototype_key, # proto = protlib.search_prototype(
# require_single=True, # prototype_key,
# no_db=True # # require_single=True,
) # # no_db=True
print(prototype_key, 'found?', proto) # )
# print(prototype_key, 'found?', proto)
self.map_data = {
"map": """
+ 0 1
0 #-#
+ 0 1
""",
"zcoord": "map1",
"prototypes": {
("*", "*"): {
"key": "room",
"desc": "A room.",
"prototype_parent": "xyz_room",
},
("*", "*", "*"): {
"desc": "A passage.",
"prototype_parent": "xyz_exit",
}
},
"options": {
"map_visual_range": 1,
"map_mode": "scan",
}
}
self.grid, err = xyzgrid.XYZGrid.create("testgrid") self.grid, err = xyzgrid.XYZGrid.create("testgrid")
def _log(msg): def _log(msg):
print(msg) print(msg)
self.grid.log = _log self.grid.log = _log
self.grid.add_maps(self.map_data) self.map_data = map_data
self.grid.add_maps(map_data)
def tearDown(self): def tearDown(self):
self.grid.delete() self.grid.delete()
# @override_settings(
# XYZEXIT_PROTOTYPE_OVERRIDE={
# "typeclass": "evennia.contrib.grid.xyzgrid.tests.TestXyzExit",
# },
# XYZROOM_PROTOTYPE_OVERRIDE={
# "typeclass": "evennia.contrib.grid.xyzgrid.tests.TestXyzRoom",
# })
def test_dummy(self): def test_dummy(self):
map_data = dict(MAP_DATA)
for prototype_key, prototype_value in map_data["prototypes"].items():
if len(prototype_key) == 2:
prototype_value["typeclass"] = "evennia.contrib.grid.xyzgrid.tests.TestXyzRoom"
if len(prototype_key) == 3:
prototype_value["typeclass"] = "evennia.contrib.grid.xyzgrid.tests.TestXyzExit"
print(map_data)
self.setup_grid(map_data)
self.grid.spawn() self.grid.spawn()