Replace NodeTypeclass (XYZRoom) with specified Typeclass in prototype.

This commit is contained in:
henddher 2022-10-09 22:34:28 -05:00
parent 18138ea3d8
commit f6e6621463
2 changed files with 17 additions and 12 deletions

View file

@ -3,6 +3,8 @@
Tests for the XYZgrid system.
"""
from unittest import mock
from unittest.mock import patch
from random import randint
from parameterized import parameterized
@ -1419,11 +1421,11 @@ class TestBuildExampleGrid(BaseEvenniaTest):
class TestXyzRoom(xyzroom.XYZRoom):
def at_object_creation(self):
breakpoint()
pass
class TestXyzExit(xyzroom.XYZExit):
def at_object_creation(self):
breakpoint()
pass
MAP_DATA = {
"map": """
@ -1469,8 +1471,8 @@ class TestCallbacks(BaseEvenniaTest):
# XYZROOM_PROTOTYPE_OVERRIDE={
# "typeclass": "evennia.contrib.grid.xyzgrid.tests.TestXyzRoom",
# })
# def setUp(self):
# super().setUp()
def setUp(self):
super().setUp()
# self.setup_grid(MAP_DATA)
def setup_grid(self, map_data):
@ -1493,6 +1495,7 @@ class TestCallbacks(BaseEvenniaTest):
self.grid.add_maps(map_data)
def tearDown(self):
super().tearDown()
self.grid.delete()
# @override_settings(
@ -1502,6 +1505,8 @@ class TestCallbacks(BaseEvenniaTest):
# XYZROOM_PROTOTYPE_OVERRIDE={
# "typeclass": "evennia.contrib.grid.xyzgrid.tests.TestXyzRoom",
# })
# @patch('evennia.contrib.grid.xyzgrid.tests.TestXyzRoom')
# def test_dummy(self, MockTestXyzRoom):
def test_dummy(self):
map_data = dict(MAP_DATA)
for prototype_key, prototype_value in map_data["prototypes"].items():

View file

@ -22,6 +22,7 @@ from collections import defaultdict
from django.core import exceptions as django_exceptions
from evennia.prototypes import spawner
from evennia.utils.utils import class_from_module
from .utils import MAPSCAN, REVERSE_DIRECTIONS, MapParserError, BIGVAL
@ -302,7 +303,6 @@ class MapNode:
to their destinations.
"""
# breakpoint()
global NodeTypeclass
if not NodeTypeclass:
from .xyzroom import XYZRoom as NodeTypeclass
@ -317,13 +317,13 @@ class MapNode:
try:
nodeobj = NodeTypeclass.objects.get_xyz(xyz=xyz)
except django_exceptions.ObjectDoesNotExist:
# create a new entity with proper coordinates etc
tclass = self.prototype["typeclass"]
tclass = (
f" ({tclass})" if tclass != "evennia.contrib.grid.xyzgrid.xyzroom.XYZRoom" else ""
)
self.log(f" spawning room at xyz={xyz}{tclass}")
nodeobj, err = NodeTypeclass.create(self.prototype.get("key", "An empty room"), xyz=xyz)
# create a new entity, using the specified typeclass (if there's one) and
# with proper coordinates etc
typeclass = self.prototype.get("typeclass", "")
self.log(f" spawning room at xyz={xyz} ({typeclass})")
Typeclass = class_from_module(typeclass,
fallback="evennia.contrib.grid.xyzgrid.xyzroom.XYZRoom")
nodeobj, err = Typeclass.create(self.prototype.get("key", "An empty room"), xyz=xyz)
if err:
raise RuntimeError(err)
else: