Replace NodeTypeclass (XYZRoom) with specified Typeclass in prototype.
This commit is contained in:
parent
18138ea3d8
commit
f6e6621463
2 changed files with 17 additions and 12 deletions
|
|
@ -3,6 +3,8 @@
|
||||||
Tests for the XYZgrid system.
|
Tests for the XYZgrid system.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
from unittest import mock
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
from random import randint
|
from random import randint
|
||||||
from parameterized import parameterized
|
from parameterized import parameterized
|
||||||
|
|
@ -1419,11 +1421,11 @@ class TestBuildExampleGrid(BaseEvenniaTest):
|
||||||
|
|
||||||
class TestXyzRoom(xyzroom.XYZRoom):
|
class TestXyzRoom(xyzroom.XYZRoom):
|
||||||
def at_object_creation(self):
|
def at_object_creation(self):
|
||||||
breakpoint()
|
pass
|
||||||
|
|
||||||
class TestXyzExit(xyzroom.XYZExit):
|
class TestXyzExit(xyzroom.XYZExit):
|
||||||
def at_object_creation(self):
|
def at_object_creation(self):
|
||||||
breakpoint()
|
pass
|
||||||
|
|
||||||
MAP_DATA = {
|
MAP_DATA = {
|
||||||
"map": """
|
"map": """
|
||||||
|
|
@ -1469,8 +1471,8 @@ class TestCallbacks(BaseEvenniaTest):
|
||||||
# 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)
|
# self.setup_grid(MAP_DATA)
|
||||||
|
|
||||||
def setup_grid(self, map_data):
|
def setup_grid(self, map_data):
|
||||||
|
|
@ -1493,6 +1495,7 @@ class TestCallbacks(BaseEvenniaTest):
|
||||||
self.grid.add_maps(map_data)
|
self.grid.add_maps(map_data)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
|
super().tearDown()
|
||||||
self.grid.delete()
|
self.grid.delete()
|
||||||
|
|
||||||
# @override_settings(
|
# @override_settings(
|
||||||
|
|
@ -1502,6 +1505,8 @@ class TestCallbacks(BaseEvenniaTest):
|
||||||
# XYZROOM_PROTOTYPE_OVERRIDE={
|
# XYZROOM_PROTOTYPE_OVERRIDE={
|
||||||
# "typeclass": "evennia.contrib.grid.xyzgrid.tests.TestXyzRoom",
|
# "typeclass": "evennia.contrib.grid.xyzgrid.tests.TestXyzRoom",
|
||||||
# })
|
# })
|
||||||
|
# @patch('evennia.contrib.grid.xyzgrid.tests.TestXyzRoom')
|
||||||
|
# def test_dummy(self, MockTestXyzRoom):
|
||||||
def test_dummy(self):
|
def test_dummy(self):
|
||||||
map_data = dict(MAP_DATA)
|
map_data = dict(MAP_DATA)
|
||||||
for prototype_key, prototype_value in map_data["prototypes"].items():
|
for prototype_key, prototype_value in map_data["prototypes"].items():
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ from collections import defaultdict
|
||||||
|
|
||||||
from django.core import exceptions as django_exceptions
|
from django.core import exceptions as django_exceptions
|
||||||
from evennia.prototypes import spawner
|
from evennia.prototypes import spawner
|
||||||
|
from evennia.utils.utils import class_from_module
|
||||||
|
|
||||||
from .utils import MAPSCAN, REVERSE_DIRECTIONS, MapParserError, BIGVAL
|
from .utils import MAPSCAN, REVERSE_DIRECTIONS, MapParserError, BIGVAL
|
||||||
|
|
||||||
|
|
@ -302,7 +303,6 @@ class MapNode:
|
||||||
to their destinations.
|
to their destinations.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# breakpoint()
|
|
||||||
global NodeTypeclass
|
global NodeTypeclass
|
||||||
if not NodeTypeclass:
|
if not NodeTypeclass:
|
||||||
from .xyzroom import XYZRoom as NodeTypeclass
|
from .xyzroom import XYZRoom as NodeTypeclass
|
||||||
|
|
@ -317,13 +317,13 @@ class MapNode:
|
||||||
try:
|
try:
|
||||||
nodeobj = NodeTypeclass.objects.get_xyz(xyz=xyz)
|
nodeobj = NodeTypeclass.objects.get_xyz(xyz=xyz)
|
||||||
except django_exceptions.ObjectDoesNotExist:
|
except django_exceptions.ObjectDoesNotExist:
|
||||||
# create a new entity with proper coordinates etc
|
# create a new entity, using the specified typeclass (if there's one) and
|
||||||
tclass = self.prototype["typeclass"]
|
# with proper coordinates etc
|
||||||
tclass = (
|
typeclass = self.prototype.get("typeclass", "")
|
||||||
f" ({tclass})" if tclass != "evennia.contrib.grid.xyzgrid.xyzroom.XYZRoom" else ""
|
self.log(f" spawning room at xyz={xyz} ({typeclass})")
|
||||||
)
|
Typeclass = class_from_module(typeclass,
|
||||||
self.log(f" spawning room at xyz={xyz}{tclass}")
|
fallback="evennia.contrib.grid.xyzgrid.xyzroom.XYZRoom")
|
||||||
nodeobj, err = NodeTypeclass.create(self.prototype.get("key", "An empty room"), xyz=xyz)
|
nodeobj, err = Typeclass.create(self.prototype.get("key", "An empty room"), xyz=xyz)
|
||||||
if err:
|
if err:
|
||||||
raise RuntimeError(err)
|
raise RuntimeError(err)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue