mirror of
https://github.com/evennia/evennia.git
synced 2026-03-23 08:16:30 +01:00
Added the ability to spawn objects with Tags.
This commit is contained in:
parent
91b84213dd
commit
9dcb97060d
3 changed files with 13 additions and 6 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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_<name> - 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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue