From 9dcb97060d18af5d6d306101ac98395ad9e23f69 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 20 Jun 2015 00:31:13 +0200 Subject: [PATCH] Added the ability to spawn objects with Tags. --- evennia/objects/objects.py | 3 +++ evennia/utils/create.py | 5 +++-- evennia/utils/spawner.py | 11 +++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/evennia/objects/objects.py b/evennia/objects/objects.py index 6b076d407c..1a0a283d42 100644 --- a/evennia/objects/objects.py +++ b/evennia/objects/objects.py @@ -857,6 +857,9 @@ class DefaultObject(ObjectDB): if cdict.get("location"): cdict["location"].at_object_receive(self, None) self.at_after_move(None) + if cdict.get("tags"): + # this should be a list of tags + self.tags.add(cdict["tags"]) if cdict.get("attributes"): # this should be a dict of attrname:value keys, values = cdict["attributes"].keys(), cdict["attributes"].values() diff --git a/evennia/utils/create.py b/evennia/utils/create.py index 0590791664..a83f099ad9 100644 --- a/evennia/utils/create.py +++ b/evennia/utils/create.py @@ -54,7 +54,7 @@ _GA = object.__getattribute__ def create_object(typeclass=None, key=None, location=None, home=None, permissions=None, locks=None, - aliases=None, destination=None, report_to=None, nohome=False): + aliases=None, tags=None, destination=None, report_to=None, nohome=False): """ Create a new in-game object. @@ -66,6 +66,7 @@ def create_object(typeclass=None, key=None, location=None, permissions - a comma-separated string of permissions locks - one or more lockstrings, separated by semicolons aliases - a list of alternative keys + tags - a list of tag keys (using no category) destination - obj or #dbref to use as an Exit's target nohome - this allows the creation of objects without a default home location; @@ -103,7 +104,7 @@ def create_object(typeclass=None, key=None, location=None, # store the call signature for the signal new_object._createdict = {"key":key, "location":location, "destination":destination, "home":home, "typeclass":typeclass.path, "permissions":permissions, - "locks":locks, "aliases":aliases, "destination":destination, + "locks":locks, "aliases":aliases, "tags": tags, "destination":destination, "report_to":report_to, "nohome":nohome} # this will trigger the save signal which in turn calls the # at_first_save hook on the typeclass, where the _createdict can be diff --git a/evennia/utils/spawner.py b/evennia/utils/spawner.py index fbd6af6228..2921c7e367 100644 --- a/evennia/utils/spawner.py +++ b/evennia/utils/spawner.py @@ -16,6 +16,7 @@ GOBLIN = { "resists": ["cold", "poison"], "attacks": ["fists"], "weaknesses": ["fire", "light"] + "tags:": ["mob", "evil"] } ``` @@ -30,7 +31,7 @@ Possible keywords are: permissions - string or list of permission strings locks - a lock-string aliases - string or list of strings - + tags - string or list of strings ndb_ - value of a nattribute (ndb_ is stripped) any other keywords are interpreted as Attributes and their values. @@ -154,7 +155,8 @@ def _batch_create_object(*objparams): "locks": objparam[2], "aliases": objparam[3], "nattributes": objparam[4], - "attributes": objparam[5]} + "attributes": objparam[5], + "tags":objparam[6]} # this triggers all hooks obj.save() objs.append(obj) @@ -214,6 +216,7 @@ def spawn(*prototypes, **kwargs): permission_string = prot.pop("permissions", "") lock_string = prot.pop("locks", "") alias_string = prot.pop("aliases", "") + tags = prot.pop("tags", "") # extract ndb assignments nattributes = dict((key.split("_", 1)[1], value if callable(value) else value) @@ -222,11 +225,11 @@ def spawn(*prototypes, **kwargs): # the rest are attributes attributes = dict((key, value() if callable(value) else value) for key, value in prot.items() - if not (key in _CREATE_OBJECT_KWARGS or key in nattributes)) + if not (key in _CREATE_OBJECT_KWARGS or key.startswith("ndb_"))) # pack for call into _batch_create_object objsparams.append( (create_kwargs, permission_string, lock_string, - alias_string, nattributes, attributes) ) + alias_string, nattributes, attributes, tags) ) return _batch_create_object(*objsparams)