mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
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
|
||||
named format tokens, and its values will have their
|
||||
`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:
|
||||
Say char is a Character object and npc is an NPC object:
|
||||
|
||||
action = 'kicks'
|
||||
char.location.msg_contents(
|
||||
"{attacker} attacks {defender}",
|
||||
mapping=dict(attacker=char, defender=npc),
|
||||
"{attacker} {action} {defender}",
|
||||
mapping=dict(attacker=char, defender=npc, action=action),
|
||||
exclude=(char, npc))
|
||||
"""
|
||||
contents = self.contents
|
||||
|
|
@ -575,7 +577,10 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
|
|||
contents = [obj for obj in contents if obj not in exclude]
|
||||
for obj in contents:
|
||||
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)
|
||||
else:
|
||||
obj.msg(message, from_obj=from_obj, **kwargs)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue