diff --git a/evennia/commands/default/building.py b/evennia/commands/default/building.py index 692dd2aac6..301bd03761 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.prototypes import spawner +from evennia.prototypes import spawner, prototypes as protlib from evennia.utils.ansi import raw COMMAND_DEFAULT_CLASS = class_from_module(settings.COMMAND_DEFAULT_CLASS) @@ -2887,7 +2887,7 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS): "use the 'exec' prototype key.") return None try: - spawner.validate_prototype(prototype) + protlib.validate_prototype(prototype) except RuntimeError as err: self.caller.msg(str(err)) return @@ -2929,7 +2929,7 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS): if ';' in self.args: key, tags = (part.strip().lower() for part in self.args.split(";", 1)) tags = [tag.strip() for tag in tags.split(",")] if tags else None - EvMore(caller, unicode(spawner.list_prototypes(caller, key=key, tags=tags)), + EvMore(caller, unicode(protlib.list_prototypes(caller, key=key, tags=tags)), exit_on_lastpage=True) return @@ -2947,7 +2947,7 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS): if 'list' in self.switches: # for list, all optional arguments are tags - EvMore(caller, unicode(spawner.list_prototypes(caller, + EvMore(caller, unicode(protlib.list_prototypes(caller, tags=self.lhslist)), exit_on_lastpage=True) return @@ -3049,7 +3049,7 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS): return if not self.args: - ncount = len(spawner.search_prototype()) + ncount = len(protlib.search_prototype()) caller.msg("Usage: @spawn or {{key: value, ...}}" "\n ({} existing prototypes. Use /list to inspect)".format(ncount)) return @@ -3065,7 +3065,7 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS): caller.msg("|rDeletion cancelled.|n") return try: - success = spawner.delete_db_prototype(caller, self.args) + success = protlib.delete_db_prototype(caller, self.args) except PermissionError as err: caller.msg("|rError deleting:|R {}|n".format(err)) caller.msg("Deletion {}.".format( @@ -3077,7 +3077,7 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS): if 'update' in self.switches: # update existing prototypes key = self.args.strip().lower() - existing_objects = spawner.search_objects_with_prototype(key) + existing_objects = protlib.search_objects_with_prototype(key) if existing_objects: n_existing = len(existing_objects) slow = " (note that this may be slow)" if n_existing > 10 else "" @@ -3103,7 +3103,7 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS): if isinstance(prototype, basestring): # A prototype key we are looking to apply key = prototype - prototypes = spawner.search_prototype(prototype) + prototypes = protlib.search_prototype(prototype) nprots = len(prototypes) if not prototypes: caller.msg("No prototype named '%s'." % prototype) @@ -3115,7 +3115,7 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS): return # we have a prototype, check access prototype = prototypes[0] - if not caller.locks.check_lockstring(caller, prototype.get('prototype_locks', ''), access_type='use'): + if not caller.locks.check_lockstring(caller, prototype.get('prototype_locks', ''), access_type='spawn'): caller.msg("You don't have access to use this prototype.") return diff --git a/evennia/commands/default/tests.py b/evennia/commands/default/tests.py index ffb877c3e3..e1688cdb48 100644 --- a/evennia/commands/default/tests.py +++ b/evennia/commands/default/tests.py @@ -28,7 +28,7 @@ from evennia.utils import ansi, utils, gametime from evennia.server.sessionhandler import SESSIONS from evennia import search_object from evennia import DefaultObject, DefaultCharacter -from evennia.utils import spawner +from evennia.prototypes import spawner, prototypes as protlib # set up signal here since we are not starting the server @@ -389,16 +389,16 @@ class TestBuilding(CommandTest): spawnLoc = self.room1 self.call(building.CmdSpawn(), - "{'prototype':'GOBLIN', 'key':'goblin', 'location':'%s'}" + "{'prototype_key':'GOBLIN', 'key':'goblin', 'location':'%s'}" % spawnLoc.dbref, "Spawned goblin") goblin = getObject(self, "goblin") self.assertEqual(goblin.location, spawnLoc) goblin.delete() - spawner.save_db_prototype(self.char1, {'key': 'Ball', 'prototype': 'GOBLIN'}, 'ball') + protlib.create_prototype(**{'key': 'Ball', 'prototype': 'GOBLIN', 'prototype_key': 'testball'}) # Tests "@spawn " - self.call(building.CmdSpawn(), "ball", "Spawned Ball") + self.call(building.CmdSpawn(), "testball", "Spawned Ball") ball = getObject(self, "Ball") self.assertEqual(ball.location, self.char1.location) self.assertIsInstance(ball, DefaultObject) @@ -414,7 +414,7 @@ class TestBuilding(CommandTest): # Tests "@spawn/noloc ...", but DO specify a location. # Location should be the specified location. self.call(building.CmdSpawn(), - "/noloc {'prototype':'BALL', 'location':'%s'}" + "/noloc {'prototype':'TESTBALL', 'location':'%s'}" % spawnLoc.dbref, "Spawned Ball") ball = getObject(self, "Ball") self.assertEqual(ball.location, spawnLoc) diff --git a/evennia/contrib/tutorial_world/objects.py b/evennia/contrib/tutorial_world/objects.py index b260770577..807b4d5e09 100644 --- a/evennia/contrib/tutorial_world/objects.py +++ b/evennia/contrib/tutorial_world/objects.py @@ -24,7 +24,7 @@ import random from evennia import DefaultObject, DefaultExit, Command, CmdSet from evennia.utils import search, delay -from evennia.utils.spawner import spawn +from evennia.prototypes.spawner import spawn # ------------------------------------------------------------- # diff --git a/evennia/prototypes/spawner.py b/evennia/prototypes/spawner.py index 22add7830a..da4d69eeb4 100644 --- a/evennia/prototypes/spawner.py +++ b/evennia/prototypes/spawner.py @@ -132,13 +132,13 @@ import evennia from evennia.objects.models import ObjectDB 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 +from evennia.prototypes.prototypes import ( + value_to_obj, value_to_obj_or_any, init_spawn_value, _PROTOTYPE_TAG_CATEGORY) _CREATE_OBJECT_KWARGS = ("key", "location", "home", "destination") _PROTOTYPE_META_NAMES = ("prototype_key", "prototype_desc", "prototype_tags", "prototype_locks") _NON_CREATE_KWARGS = _CREATE_OBJECT_KWARGS + _PROTOTYPE_META_NAMES -_PROTOTYPE_TAG_CATEGORY = "spawned_by_prototype" # Helper diff --git a/evennia/prototypes/tests.py b/evennia/prototypes/tests.py index 88650caa7b..94bce1f946 100644 --- a/evennia/prototypes/tests.py +++ b/evennia/prototypes/tests.py @@ -83,6 +83,7 @@ class TestUtils(EvenniaTest): 'prototype_desc': 'Built from Obj', 'prototype_key': Something, 'prototype_locks': 'spawn:all();edit:all()', + 'prototype_tags': [], 'tags': [(u'foo', None, None)], 'typeclass': 'evennia.objects.objects.DefaultObject'}, new_prot) @@ -121,6 +122,7 @@ class TestUtils(EvenniaTest): 'prototype_desc': 'UPDATE', 'prototype_key': 'UPDATE', 'prototype_locks': 'KEEP', + 'prototype_tags': 'KEEP', 'test': 'UPDATE', 'typeclass': 'KEEP'}) @@ -148,6 +150,7 @@ class TestUtils(EvenniaTest): 'prototype_desc': 'Built from Obj', 'prototype_key': Something, 'prototype_locks': 'spawn:all();edit:all()', + 'prototype_tags': [], 'typeclass': 'evennia.objects.objects.DefaultObject'}, new_prot)