modified msg_contents to allow objects without get_display_name to be included in mapping
This commit is contained in:
parent
402a4c8aa0
commit
7f63393cb7
1 changed files with 9 additions and 4 deletions
|
|
@ -559,14 +559,16 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
|
||||||
{}-style format syntax. The keys of `mapping` should match
|
{}-style format syntax. The keys of `mapping` should match
|
||||||
named format tokens, and its values will have their
|
named format tokens, and its values will have their
|
||||||
`get_display_name()` function called for each object in
|
`get_display_name()` function called for each object in
|
||||||
the room before substitution.
|
the room before substitution. If an item in the mapping does
|
||||||
|
not have `get_display_name()`, its string value will be used.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
Say char is a Character object and npc is an NPC object:
|
Say char is a Character object and npc is an NPC object:
|
||||||
|
|
||||||
|
action = 'kicks'
|
||||||
char.location.msg_contents(
|
char.location.msg_contents(
|
||||||
"{attacker} attacks {defender}",
|
"{attacker} {action} {defender}",
|
||||||
mapping=dict(attacker=char, defender=npc),
|
mapping=dict(attacker=char, defender=npc, action=action),
|
||||||
exclude=(char, npc))
|
exclude=(char, npc))
|
||||||
"""
|
"""
|
||||||
contents = self.contents
|
contents = self.contents
|
||||||
|
|
@ -575,7 +577,10 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
|
||||||
contents = [obj for obj in contents if obj not in exclude]
|
contents = [obj for obj in contents if obj not in exclude]
|
||||||
for obj in contents:
|
for obj in contents:
|
||||||
if mapping:
|
if mapping:
|
||||||
substitutions = {t: sub.get_display_name(obj) for t, sub in mapping.items()}
|
substitutions = {t: sub.get_display_name(obj)
|
||||||
|
if hasattr(sub, 'get_display_name')
|
||||||
|
else str(sub)
|
||||||
|
for t, sub in mapping.items()}
|
||||||
obj.msg(message.format(**substitutions), from_obj=from_obj, **kwargs)
|
obj.msg(message.format(**substitutions), from_obj=from_obj, **kwargs)
|
||||||
else:
|
else:
|
||||||
obj.msg(message, from_obj=from_obj, **kwargs)
|
obj.msg(message, from_obj=from_obj, **kwargs)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue