Fix merge conflicts
This commit is contained in:
commit
90b42ca6fb
47 changed files with 1682 additions and 201 deletions
|
|
@ -76,7 +76,7 @@ from evennia import prototypes
|
|||
|
||||
goblin = {"prototype_key": "goblin:, ... }
|
||||
|
||||
prototype = prototypes.save_prototype(caller, **goblin)
|
||||
prototype = prototypes.save_prototype(goblin)
|
||||
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -2139,7 +2139,7 @@ def node_prototype_save(caller, **kwargs):
|
|||
# we already validated and accepted the save, so this node acts as a goto callback and
|
||||
# should now only return the next node
|
||||
prototype_key = prototype.get("prototype_key")
|
||||
protlib.save_prototype(**prototype)
|
||||
protlib.save_prototype(prototype)
|
||||
|
||||
spawned_objects = protlib.search_objects_with_prototype(prototype_key)
|
||||
nspawned = spawned_objects.count()
|
||||
|
|
|
|||
|
|
@ -333,7 +333,7 @@ def objlist(*args, **kwargs):
|
|||
def dbref(*args, **kwargs):
|
||||
"""
|
||||
Usage $dbref(<#dbref>)
|
||||
Returns one Object searched globally by #dbref. Error if #dbref is invalid.
|
||||
Validate that a #dbref input is valid.
|
||||
"""
|
||||
if not args or len(args) < 1 or _RE_DBREF.match(args[0]) is None:
|
||||
raise ValueError('$dbref requires a valid #dbref argument.')
|
||||
|
|
|
|||
|
|
@ -147,13 +147,13 @@ class DbPrototype(DefaultScript):
|
|||
# Prototype manager functions
|
||||
|
||||
|
||||
def save_prototype(**kwargs):
|
||||
def save_prototype(prototype):
|
||||
"""
|
||||
Create/Store a prototype persistently.
|
||||
|
||||
Kwargs:
|
||||
prototype_key (str): This is required for any storage.
|
||||
All other kwargs are considered part of the new prototype dict.
|
||||
Args:
|
||||
prototype (dict): The prototype to save. A `prototype_key` key is
|
||||
required.
|
||||
|
||||
Returns:
|
||||
prototype (dict or None): The prototype stored using the given kwargs, None if deleting.
|
||||
|
|
@ -166,8 +166,8 @@ def save_prototype(**kwargs):
|
|||
is expected to have valid permissions.
|
||||
|
||||
"""
|
||||
|
||||
kwargs = homogenize_prototype(kwargs)
|
||||
in_prototype = prototype
|
||||
in_prototype = homogenize_prototype(in_prototype)
|
||||
|
||||
def _to_batchtuple(inp, *args):
|
||||
"build tuple suitable for batch-creation"
|
||||
|
|
@ -176,7 +176,7 @@ def save_prototype(**kwargs):
|
|||
return inp
|
||||
return (inp, ) + args
|
||||
|
||||
prototype_key = kwargs.get("prototype_key")
|
||||
prototype_key = in_prototype.get("prototype_key")
|
||||
if not prototype_key:
|
||||
raise ValidationError("Prototype requires a prototype_key")
|
||||
|
||||
|
|
@ -192,21 +192,21 @@ def save_prototype(**kwargs):
|
|||
stored_prototype = DbPrototype.objects.filter(db_key=prototype_key)
|
||||
prototype = stored_prototype[0].prototype if stored_prototype else {}
|
||||
|
||||
kwargs['prototype_desc'] = kwargs.get("prototype_desc", prototype.get("prototype_desc", ""))
|
||||
prototype_locks = kwargs.get(
|
||||
in_prototype['prototype_desc'] = in_prototype.get("prototype_desc", prototype.get("prototype_desc", ""))
|
||||
prototype_locks = in_prototype.get(
|
||||
"prototype_locks", prototype.get('prototype_locks', "spawn:all();edit:perm(Admin)"))
|
||||
is_valid, err = validate_lockstring(prototype_locks)
|
||||
if not is_valid:
|
||||
raise ValidationError("Lock error: {}".format(err))
|
||||
kwargs['prototype_locks'] = prototype_locks
|
||||
in_prototype['prototype_locks'] = prototype_locks
|
||||
|
||||
prototype_tags = [
|
||||
_to_batchtuple(tag, _PROTOTYPE_TAG_META_CATEGORY)
|
||||
for tag in make_iter(kwargs.get("prototype_tags",
|
||||
for tag in make_iter(in_prototype.get("prototype_tags",
|
||||
prototype.get('prototype_tags', [])))]
|
||||
kwargs["prototype_tags"] = prototype_tags
|
||||
in_prototype["prototype_tags"] = prototype_tags
|
||||
|
||||
prototype.update(kwargs)
|
||||
prototype.update(in_prototype)
|
||||
|
||||
if stored_prototype:
|
||||
# edit existing prototype
|
||||
|
|
@ -261,19 +261,25 @@ def delete_prototype(prototype_key, caller=None):
|
|||
return True
|
||||
|
||||
|
||||
def search_prototype(key=None, tags=None):
|
||||
def search_prototype(key=None, tags=None, require_single=False):
|
||||
"""
|
||||
Find prototypes based on key and/or tags, or all prototypes.
|
||||
|
||||
Kwargs:
|
||||
key (str): An exact or partial key to query for.
|
||||
tags (str or list): Tag key or keys to query for. These
|
||||
tags (str or list): Tag key or keys to query for. These
|
||||
will always be applied with the 'db_protototype'
|
||||
tag category.
|
||||
require_single (bool): If set, raise KeyError if the result
|
||||
was not found or if there are multiple matches.
|
||||
|
||||
Return:
|
||||
matches (list): All found prototype dicts. If no keys
|
||||
or tags are given, all available prototypes will be returned.
|
||||
matches (list): All found prototype dicts. Empty list if
|
||||
no match was found. Note that if neither `key` nor `tags`
|
||||
were given, *all* available prototypes will be returned.
|
||||
|
||||
Raises:
|
||||
KeyError: If `require_single` is True and there are 0 or >1 matches.
|
||||
|
||||
Note:
|
||||
The available prototypes is a combination of those supplied in
|
||||
|
|
@ -329,6 +335,10 @@ def search_prototype(key=None, tags=None):
|
|||
if mta.get('prototype_key') and mta['prototype_key'] == key]
|
||||
if filter_matches and len(filter_matches) < nmatches:
|
||||
matches = filter_matches
|
||||
|
||||
nmatches = len(matches)
|
||||
if nmatches != 1 and require_single:
|
||||
raise KeyError("Found {} matching prototypes.".format(nmatches))
|
||||
|
||||
return matches
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ prot = {
|
|||
"attrs": [("weapon", "sword")]
|
||||
}
|
||||
|
||||
prot = prototypes.create_prototype(**prot)
|
||||
prot = prototypes.create_prototype(prot)
|
||||
|
||||
```
|
||||
|
||||
|
|
@ -662,8 +662,9 @@ def spawn(*prototypes, **kwargs):
|
|||
Spawn a number of prototyped objects.
|
||||
|
||||
Args:
|
||||
prototypes (dict): Each argument should be a prototype
|
||||
dictionary.
|
||||
prototypes (str or dict): Each argument should either be a
|
||||
prototype_key (will be used to find the prototype) or a full prototype
|
||||
dictionary. These will be batched-spawned as one object each.
|
||||
Kwargs:
|
||||
prototype_modules (str or list): A python-path to a prototype
|
||||
module, or a list of such paths. These will be used to build
|
||||
|
|
@ -673,8 +674,10 @@ def spawn(*prototypes, **kwargs):
|
|||
prototype_parents (dict): A dictionary holding a custom
|
||||
prototype-parent dictionary. Will overload same-named
|
||||
prototypes from prototype_modules.
|
||||
return_parents (bool): Only return a dict of the
|
||||
prototype-parents (no object creation happens)
|
||||
return_parents (bool): Return a dict of the entire prototype-parent tree
|
||||
available to this prototype (no object creation happens). This is a
|
||||
merged result between the globally found protparents and whatever
|
||||
custom `prototype_parents` are given to this function.
|
||||
only_validate (bool): Only run validation of prototype/parents
|
||||
(no object creation) and return the create-kwargs.
|
||||
|
||||
|
|
@ -684,6 +687,11 @@ def spawn(*prototypes, **kwargs):
|
|||
`return_parents` is set, instead return dict of prototype parents.
|
||||
|
||||
"""
|
||||
# search string (=prototype_key) from input
|
||||
prototypes = [protlib.search_prototype(prot, require_single=True)[0]
|
||||
if isinstance(prot, basestring) else prot
|
||||
for prot in prototypes]
|
||||
|
||||
# get available protparents
|
||||
protparents = {prot['prototype_key'].lower(): prot for prot in protlib.search_prototype()}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ class TestSpawner(EvenniaTest):
|
|||
self.prot1 = {"prototype_key": "testprototype",
|
||||
"typeclass": "evennia.objects.objects.DefaultObject"}
|
||||
|
||||
def test_spawn(self):
|
||||
def test_spawn_from_prot(self):
|
||||
obj1 = spawner.spawn(self.prot1)
|
||||
# check spawned objects have the right tag
|
||||
self.assertEqual(list(protlib.search_objects_with_prototype("testprototype")), obj1)
|
||||
|
|
@ -62,6 +62,14 @@ class TestSpawner(EvenniaTest):
|
|||
_PROTPARENTS["GOBLIN"], _PROTPARENTS["GOBLIN_ARCHWIZARD"],
|
||||
prototype_parents=_PROTPARENTS)], ['goblin grunt', 'goblin archwizard'])
|
||||
|
||||
def test_spawn_from_str(self):
|
||||
protlib.save_prototype(self.prot1)
|
||||
obj1 = spawner.spawn(self.prot1['prototype_key'])
|
||||
self.assertEqual(list(protlib.search_objects_with_prototype("testprototype")), obj1)
|
||||
self.assertEqual([o.key for o in spawner.spawn(
|
||||
_PROTPARENTS["GOBLIN"], _PROTPARENTS["GOBLIN_ARCHWIZARD"],
|
||||
prototype_parents=_PROTPARENTS)], ['goblin grunt', 'goblin archwizard'])
|
||||
|
||||
|
||||
class TestUtils(EvenniaTest):
|
||||
|
||||
|
|
@ -245,6 +253,7 @@ class TestProtLib(EvenniaTest):
|
|||
super(TestProtLib, self).setUp()
|
||||
self.obj1.attributes.add("testattr", "testval")
|
||||
self.prot = spawner.prototype_from_object(self.obj1)
|
||||
|
||||
|
||||
def test_prototype_to_str(self):
|
||||
prstr = protlib.prototype_to_str(self.prot)
|
||||
|
|
@ -253,6 +262,22 @@ class TestProtLib(EvenniaTest):
|
|||
def test_check_permission(self):
|
||||
pass
|
||||
|
||||
def test_save_prototype(self):
|
||||
result = protlib.save_prototype(self.prot)
|
||||
self.assertEqual(result, self.prot)
|
||||
# faulty
|
||||
self.prot['prototype_key'] = None
|
||||
self.assertRaises(protlib.ValidationError, protlib.save_prototype, self.prot)
|
||||
|
||||
def test_search_prototype(self):
|
||||
protlib.save_prototype(self.prot)
|
||||
match = protlib.search_prototype("NotFound")
|
||||
self.assertFalse(match)
|
||||
match = protlib.search_prototype()
|
||||
self.assertTrue(match)
|
||||
match = protlib.search_prototype(self.prot['prototype_key'])
|
||||
self.assertEqual(match, [self.prot])
|
||||
|
||||
|
||||
@override_settings(PROT_FUNC_MODULES=['evennia.prototypes.protfuncs'], CLIENT_DEFAULT_WIDTH=20)
|
||||
class TestProtFuncs(EvenniaTest):
|
||||
|
|
@ -424,7 +449,7 @@ class TestPrototypeStorage(EvenniaTest):
|
|||
def test_prototype_storage(self):
|
||||
|
||||
# from evennia import set_trace;set_trace(term_size=(180, 50))
|
||||
prot1 = protlib.create_prototype(**self.prot1)
|
||||
prot1 = protlib.create_prototype(self.prot1)
|
||||
|
||||
self.assertTrue(bool(prot1))
|
||||
self.assertEqual(prot1, self.prot1)
|
||||
|
|
@ -436,7 +461,7 @@ class TestPrototypeStorage(EvenniaTest):
|
|||
protlib.DbPrototype.objects.get_by_tag(
|
||||
"foo1", _PROTOTYPE_TAG_META_CATEGORY)[0].db.prototype, prot1)
|
||||
|
||||
prot2 = protlib.create_prototype(**self.prot2)
|
||||
prot2 = protlib.create_prototype(self.prot2)
|
||||
self.assertEqual(
|
||||
[pobj.db.prototype
|
||||
for pobj in protlib.DbPrototype.objects.get_by_tag(
|
||||
|
|
@ -445,7 +470,7 @@ class TestPrototypeStorage(EvenniaTest):
|
|||
|
||||
# add to existing prototype
|
||||
prot1b = protlib.create_prototype(
|
||||
prototype_key='testprototype1', foo='bar', prototype_tags=['foo2'])
|
||||
{"prototype_key": 'testprototype1', "foo": 'bar', "prototype_tags": ['foo2']})
|
||||
|
||||
self.assertEqual(
|
||||
[pobj.db.prototype
|
||||
|
|
@ -457,7 +482,7 @@ class TestPrototypeStorage(EvenniaTest):
|
|||
self.assertNotEqual(list(protlib.search_prototype("testprototype1")), [prot1])
|
||||
self.assertEqual(list(protlib.search_prototype("testprototype1")), [prot1b])
|
||||
|
||||
prot3 = protlib.create_prototype(**self.prot3)
|
||||
prot3 = protlib.create_prototype(self.prot3)
|
||||
|
||||
# partial match
|
||||
with mock.patch("evennia.prototypes.prototypes._MODULE_PROTOTYPES", {}):
|
||||
|
|
@ -608,7 +633,7 @@ class TestMenuModule(EvenniaTest):
|
|||
self.assertEqual(olc_menus._display_tag(olc_menus._get_menu_prototype(caller)['tags'][0]), Something)
|
||||
self.assertEqual(olc_menus._caller_tags(caller), ["foo2", "foo3"])
|
||||
|
||||
protlib.save_prototype(**self.test_prot)
|
||||
protlib.save_prototype(self.test_prot)
|
||||
|
||||
# locks helpers
|
||||
self.assertEqual(olc_menus._lock_add(caller, "foo:false()"), "Added lock 'foo:false()'.")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue