mirror of
https://github.com/evennia/evennia.git
synced 2026-04-06 07:57:16 +02:00
Fix prototype inheritance of attrs/tags. Resolves #1773.
This commit is contained in:
parent
419d2858fd
commit
bdcecbd945
1 changed files with 28 additions and 0 deletions
|
|
@ -165,7 +165,23 @@ def _get_prototype(inprot, protparents, uninherited=None, _workprot=None):
|
||||||
uninherited (dict): Parts of prototype to not inherit.
|
uninherited (dict): Parts of prototype to not inherit.
|
||||||
_workprot (dict, optional): Work dict for the recursive algorithm.
|
_workprot (dict, optional): Work dict for the recursive algorithm.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
merged (dict): A prototype where parent's have been merged as needed (the
|
||||||
|
`prototype_parent` key is removed).
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
def _inherit_tags(old_tags, new_tags):
|
||||||
|
old = {(tup[0], tup[1]): tup for tup in old_tags}
|
||||||
|
new = {(tup[0], tup[1]): tup for tup in new_tags}
|
||||||
|
old.update(new)
|
||||||
|
return list(old.values())
|
||||||
|
|
||||||
|
def _inherit_attrs(old_attrs, new_attrs):
|
||||||
|
old = {(tup[0], tup[2]): tup for tup in old_attrs}
|
||||||
|
new = {(tup[0], tup[2]): tup for tup in new_attrs}
|
||||||
|
old.update(new)
|
||||||
|
return list(old.values())
|
||||||
|
|
||||||
_workprot = {} if _workprot is None else _workprot
|
_workprot = {} if _workprot is None else _workprot
|
||||||
if "prototype_parent" in inprot:
|
if "prototype_parent" in inprot:
|
||||||
# move backwards through the inheritance
|
# move backwards through the inheritance
|
||||||
|
|
@ -173,8 +189,20 @@ def _get_prototype(inprot, protparents, uninherited=None, _workprot=None):
|
||||||
# Build the prot dictionary in reverse order, overloading
|
# Build the prot dictionary in reverse order, overloading
|
||||||
new_prot = _get_prototype(protparents.get(prototype.lower(), {}),
|
new_prot = _get_prototype(protparents.get(prototype.lower(), {}),
|
||||||
protparents, _workprot=_workprot)
|
protparents, _workprot=_workprot)
|
||||||
|
|
||||||
|
# attrs, tags have internal structure that should be inherited separately
|
||||||
|
new_prot['attrs'] = _inherit_attrs(
|
||||||
|
_workprot.get("attrs", {}), new_prot.get("attrs", {}))
|
||||||
|
new_prot['tags'] = _inherit_tags(
|
||||||
|
_workprot.get("tags", {}), new_prot.get("tags", {}))
|
||||||
|
|
||||||
_workprot.update(new_prot)
|
_workprot.update(new_prot)
|
||||||
# the inprot represents a higher level (a child prot), which should override parents
|
# the inprot represents a higher level (a child prot), which should override parents
|
||||||
|
|
||||||
|
inprot['attrs'] = _inherit_attrs(
|
||||||
|
_workprot.get("attrs", {}), inprot.get("attrs", {}))
|
||||||
|
inprot['tags'] = _inherit_tags(
|
||||||
|
_workprot.get("tags", {}), inprot.get("tags", {}))
|
||||||
_workprot.update(inprot)
|
_workprot.update(inprot)
|
||||||
if uninherited:
|
if uninherited:
|
||||||
# put back the parts that should not be inherited
|
# put back the parts that should not be inherited
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue