mirror of
https://github.com/evennia/evennia.git
synced 2026-03-21 07:16:31 +01:00
Correct issues with object-update in OLC menu. Resolves #1647.
This commit is contained in:
parent
982f977429
commit
3537ae13a4
3 changed files with 50 additions and 14 deletions
|
|
@ -1965,6 +1965,7 @@ def _format_diff_text_and_options(diff, **kwargs):
|
|||
any (any): Forwarded into the generated options as arguments to the callable.
|
||||
|
||||
Returns:
|
||||
texts (list): List of texts.
|
||||
options (list): List of options dict.
|
||||
|
||||
"""
|
||||
|
|
@ -1978,7 +1979,7 @@ def _format_diff_text_and_options(diff, **kwargs):
|
|||
return "{} |W=|n {} |W(category:|n {}|W, locks:|n {}|W)|n".format(*obj)
|
||||
elif rootname == "tags":
|
||||
return "{} |W(category:|n {}|W)|n".format(obj[0], obj[1])
|
||||
return obj
|
||||
return "{}".format(obj)
|
||||
|
||||
def _parse_diffpart(diffpart, optnum, *args):
|
||||
typ = type(diffpart)
|
||||
|
|
@ -1988,7 +1989,7 @@ def _format_diff_text_and_options(diff, **kwargs):
|
|||
rootname = args[0]
|
||||
old, new, instruction = diffpart
|
||||
if instruction == 'KEEP':
|
||||
texts.append(" |gKEEP|W:|n {old}".format(old=old))
|
||||
texts.append(" |gKEEP|W:|n {old}".format(old=_visualize(old, rootname)))
|
||||
else:
|
||||
vold = _visualize(old, rootname)
|
||||
vnew = _visualize(new, rootname)
|
||||
|
|
|
|||
|
|
@ -502,19 +502,26 @@ def batch_update_objects_with_prototype(prototype, diff=None, objects=None):
|
|||
elif key == 'permissions':
|
||||
if directive == 'REPLACE':
|
||||
obj.permissions.clear()
|
||||
obj.permissions.batch_add(*init_spawn_value(val, make_iter))
|
||||
obj.permissions.batch_add(*(init_spawn_value(perm, str) for perm in val))
|
||||
elif key == 'aliases':
|
||||
if directive == 'REPLACE':
|
||||
obj.aliases.clear()
|
||||
obj.aliases.batch_add(*init_spawn_value(val, make_iter))
|
||||
obj.aliases.batch_add(*(init_spawn_value(alias, str) for alias in val))
|
||||
elif key == 'tags':
|
||||
if directive == 'REPLACE':
|
||||
obj.tags.clear()
|
||||
obj.tags.batch_add(*init_spawn_value(val, make_iter))
|
||||
obj.tags.batch_add(*(
|
||||
(init_spawn_value(ttag, str), tcategory, tdata)
|
||||
for ttag, tcategory, tdata in val))
|
||||
elif key == 'attrs':
|
||||
if directive == 'REPLACE':
|
||||
obj.attributes.clear()
|
||||
obj.attributes.batch_add(*init_spawn_value(val, make_iter))
|
||||
obj.attributes.batch_add(*(
|
||||
(init_spawn_value(akey, str),
|
||||
init_spawn_value(aval, value_to_obj),
|
||||
acategory,
|
||||
alocks)
|
||||
for akey, aval, acategory, alocks in val))
|
||||
elif key == 'exec':
|
||||
# we don't auto-rerun exec statements, it would be huge security risk!
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ class TestUtils(EvenniaTest):
|
|||
# modify prototype
|
||||
old_prot['new'] = 'new_val'
|
||||
old_prot['test'] = 'testval_changed'
|
||||
old_prot['permissions'] = 'Builder'
|
||||
old_prot['permissions'] = ['Builder']
|
||||
# this will not update, since we don't update the prototype on-disk
|
||||
old_prot['prototype_desc'] = 'New version of prototype'
|
||||
old_prot['attrs'] += (("fooattr", "fooattrval", None, ''),)
|
||||
|
|
@ -146,7 +146,7 @@ class TestUtils(EvenniaTest):
|
|||
'edit:perm(Admin);examine:perm(Builder);get:all();'
|
||||
'puppet:pperm(Developer);tell:perm(Admin);view:all()',
|
||||
'new': 'new_val',
|
||||
'permissions': 'Builder',
|
||||
'permissions': ['Builder'],
|
||||
'prototype_desc': 'New version of prototype',
|
||||
'prototype_key': Something,
|
||||
'prototype_locks': 'spawn:all();edit:all()',
|
||||
|
|
@ -154,7 +154,6 @@ class TestUtils(EvenniaTest):
|
|||
'test': 'testval_changed',
|
||||
'typeclass': 'evennia.objects.objects.DefaultObject'})
|
||||
|
||||
# from evennia import set_trace; set_trace(term_size=(182, 50))
|
||||
self.assertEqual(
|
||||
pdiff,
|
||||
{'home': ('#1', '#1', 'KEEP'),
|
||||
|
|
@ -182,13 +181,12 @@ class TestUtils(EvenniaTest):
|
|||
'key': ('Obj', 'Obj', 'KEEP'),
|
||||
'typeclass': ('evennia.objects.objects.DefaultObject',
|
||||
'evennia.objects.objects.DefaultObject', 'KEEP'),
|
||||
'aliases': (['foo'], None, 'REMOVE'),
|
||||
'aliases': {'foo': ('foo', None, 'REMOVE')},
|
||||
'prototype_desc': ('Built from Obj',
|
||||
'New version of prototype', 'UPDATE'),
|
||||
'permissions': (None, 'Builder', 'ADD')}
|
||||
)
|
||||
'permissions': {"Builder": (None, 'Builder', 'ADD')}
|
||||
})
|
||||
|
||||
# from evennia import set_trace;set_trace()
|
||||
self.assertEqual(
|
||||
spawner.flatten_diff(pdiff),
|
||||
{'aliases': 'REMOVE',
|
||||
|
|
@ -598,7 +596,37 @@ class TestMenuModule(EvenniaTest):
|
|||
'tags': {'foo': (None, ('foo', None, ''), 'ADD')},
|
||||
'typeclass': (u'typeclasses.characters.Character',
|
||||
u'typeclasses.characters.Character', 'KEEP')}
|
||||
self.assertEqual(olc_menus._format_diff_text_and_options(obj_diff), "")
|
||||
|
||||
texts, options = olc_menus._format_diff_text_and_options(obj_diff)
|
||||
self.assertEqual(
|
||||
"\n".join(texts),
|
||||
'- |wattrs:|n \n'
|
||||
' |c[1] |yADD|n|W:|n None |W->|n foo |W=|n bar |W(category:|n None|W, locks:|n |W)|n\n'
|
||||
' |gKEEP|W:|n prelogout_location |W=|n #2 |W(category:|n None|W, locks:|n |W)|n\n'
|
||||
' |gKEEP|W:|n desc |W=|n This is User #1. |W(category:|n None|W, locks:|n |W)|n\n'
|
||||
'- |whome:|n |gKEEP|W:|n #2\n'
|
||||
'- |wkey:|n |gKEEP|W:|n TestChar\n'
|
||||
'- |wlocks:|n |gKEEP|W:|n boot:false();call:false();control:perm(Developer);delete:false();edit:false();examine:perm(Developer);get:false();msg:all();puppet:false();tell:perm(Admin);view:all()\n'
|
||||
'- |wpermissions:|n \n'
|
||||
' |gKEEP|W:|n developer\n'
|
||||
'- |wprototype_desc:|n |c[2] |rREMOVE|n|W:|n Testobject build |W->|n None\n'
|
||||
'- |wprototype_key:|n |gKEEP|W:|n TestDiffKey\n'
|
||||
'- |wprototype_locks:|n |gKEEP|W:|n spawn:all();edit:all()\n'
|
||||
'- |wprototype_tags:|n \n'
|
||||
'- |wtags:|n \n'
|
||||
' |c[3] |yADD|n|W:|n None |W->|n foo |W(category:|n None|W)|n\n'
|
||||
'- |wtypeclass:|n |gKEEP|W:|n typeclasses.characters.Character')
|
||||
self.assertEqual(
|
||||
options,
|
||||
[{'goto': (Something, Something),
|
||||
'key': '1',
|
||||
'desc': '|gKEEP|n (attrs) None'},
|
||||
{'goto': (Something, Something),
|
||||
'key': '2',
|
||||
'desc': '|gKEEP|n (prototype_desc) Testobject build'},
|
||||
{'goto': (Something, Something),
|
||||
'key': '3',
|
||||
'desc': '|gKEEP|n (tags) None'}])
|
||||
|
||||
|
||||
@mock.patch("evennia.prototypes.menus.protlib.search_prototype", new=mock.MagicMock(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue