diff --git a/evennia/__init__.py b/evennia/__init__.py index 6fdc4aaece..fc916351ad 100644 --- a/evennia/__init__.py +++ b/evennia/__init__.py @@ -174,7 +174,7 @@ def _init(): from .utils import logger from .utils import gametime from .utils import ansi - from .utils.spawner import spawn + from .prototypes.spawner import spawn from . import contrib from .utils.evmenu import EvMenu from .utils.evtable import EvTable diff --git a/evennia/commands/default/building.py b/evennia/commands/default/building.py index 4aabc861b1..692dd2aac6 100644 --- a/evennia/commands/default/building.py +++ b/evennia/commands/default/building.py @@ -13,7 +13,7 @@ from evennia.utils import create, utils, search from evennia.utils.utils import inherits_from, class_from_module, get_all_typeclasses from evennia.utils.eveditor import EvEditor from evennia.utils.evmore import EvMore -from evennia.utils import spawner +from evennia.prototypes import spawner from evennia.utils.ansi import raw COMMAND_DEFAULT_CLASS = class_from_module(settings.COMMAND_DEFAULT_CLASS) diff --git a/evennia/prototypes/prototypes.py b/evennia/prototypes/prototypes.py index 37fd83f846..0020f807c1 100644 --- a/evennia/prototypes/prototypes.py +++ b/evennia/prototypes/prototypes.py @@ -15,7 +15,7 @@ from evennia.utils.utils import ( from evennia.locks.lockhandler import validate_lockstring, check_lockstring from evennia.utils import logger from evennia.utils.evtable import EvTable -from evennia.utils.prototypes.protfuncs import protfunc_parser +from evennia.prototypes.protfuncs import protfunc_parser _MODULE_PROTOTYPE_MODULES = {} diff --git a/evennia/prototypes/spawner.py b/evennia/prototypes/spawner.py index 995cea6e52..8cadd43656 100644 --- a/evennia/prototypes/spawner.py +++ b/evennia/prototypes/spawner.py @@ -129,11 +129,8 @@ import time from django.conf import settings import evennia -from random import randint from evennia.objects.models import ObjectDB -from evennia.utils.utils import ( - make_iter, dbid_to_obj, - is_iter, get_all_typeclasses) +from evennia.utils.utils import make_iter, is_iter from evennia.prototypes import prototypes as protlib from evennia.prototypes.prototypes import value_to_obj, value_to_obj_or_any, init_spawn_value @@ -516,42 +513,3 @@ def spawn(*prototypes, **kwargs): alias_string, nattributes, attributes, tags, execs)) return batch_create_object(*objsparams) - - -# Testing - -if __name__ == "__main__": - protparents = { - "NOBODY": {}, - # "INFINITE" : { - # "prototype":"INFINITE" - # }, - "GOBLIN": { - "key": "goblin grunt", - "health": lambda: randint(20, 30), - "resists": ["cold", "poison"], - "attacks": ["fists"], - "weaknesses": ["fire", "light"] - }, - "GOBLIN_WIZARD": { - "prototype": "GOBLIN", - "key": "goblin wizard", - "spells": ["fire ball", "lighting bolt"] - }, - "GOBLIN_ARCHER": { - "prototype": "GOBLIN", - "key": "goblin archer", - "attacks": ["short bow"] - }, - "ARCHWIZARD": { - "attacks": ["archwizard staff"], - }, - "GOBLIN_ARCHWIZARD": { - "key": "goblin archwizard", - "prototype": ("GOBLIN_WIZARD", "ARCHWIZARD") - } - } - # test - print([o.key for o in spawn(protparents["GOBLIN"], - protparents["GOBLIN_ARCHWIZARD"], - prototype_parents=protparents)]) diff --git a/evennia/utils/tests/test_spawner.py b/evennia/prototypes/tests.py similarity index 74% rename from evennia/utils/tests/test_spawner.py rename to evennia/prototypes/tests.py index 4d680a9e8a..1b8e340377 100644 --- a/evennia/utils/tests/test_spawner.py +++ b/evennia/prototypes/tests.py @@ -1,10 +1,44 @@ """ -Unit test for the spawner +Unit tests for the prototypes and spawner """ +from random import randint from evennia.utils.test_resources import EvenniaTest -from evennia.utils import spawner +from evennia.prototypes import spawner, prototypes as protlib + + +_PROTPARENTS = { + "NOBODY": {}, + "GOBLIN": { + "key": "goblin grunt", + "health": lambda: randint(1, 1), + "resists": ["cold", "poison"], + "attacks": ["fists"], + "weaknesses": ["fire", "light"] + }, + "GOBLIN_WIZARD": { + "prototype": "GOBLIN", + "key": "goblin wizard", + "spells": ["fire ball", "lighting bolt"] + }, + "GOBLIN_ARCHER": { + "prototype": "GOBLIN", + "key": "goblin archer", + "attacks": ["short bow"] + }, + "ARCHWIZARD": { + "attacks": ["archwizard staff"], + }, + "GOBLIN_ARCHWIZARD": { + "key": "goblin archwizard", + "prototype": ("GOBLIN_WIZARD", "ARCHWIZARD") + } +} + + +class TestPrototypes(EvenniaTest): + pass class TestSpawner(EvenniaTest): @@ -17,6 +51,9 @@ class TestSpawner(EvenniaTest): obj1 = spawner.spawn(self.prot1) # check spawned objects have the right tag self.assertEqual(list(spawner.search_objects_with_prototype("testprototype")), obj1) + self.assertEqual([o.key for o in spawner.spawn( + _PROTPARENTS["GOBLIN"], _PROTPARENTS["GOBLIN_ARCHWIZARD"], + prototype_parents=_PROTPARENTS)], []) class TestPrototypeStorage(EvenniaTest):