Make rpsystem embedded emote-says handle references embedded in language quotes. Resolves #1054. Also make rpsystem say command use the emote mechanism to give it full support for embedded references.
This commit is contained in:
parent
5021563704
commit
384d08f9d8
1 changed files with 29 additions and 27 deletions
|
|
@ -469,6 +469,9 @@ def send_emote(sender, receivers, emote, anonymous_add="first"):
|
||||||
# handle all error messages, don't hide actual coding errors
|
# handle all error messages, don't hide actual coding errors
|
||||||
sender.msg(err.message)
|
sender.msg(err.message)
|
||||||
return
|
return
|
||||||
|
# we escape the object mappings since we'll do the language ones first
|
||||||
|
# (the text could have nested object mappings).
|
||||||
|
emote = _RE_REF.sub(r"{{#\1}}", emote)
|
||||||
|
|
||||||
if anonymous_add and not "#%i" % sender.id in obj_mapping:
|
if anonymous_add and not "#%i" % sender.id in obj_mapping:
|
||||||
# no self-reference in the emote - add to the end
|
# no self-reference in the emote - add to the end
|
||||||
|
|
@ -482,7 +485,20 @@ def send_emote(sender, receivers, emote, anonymous_add="first"):
|
||||||
|
|
||||||
# broadcast emote to everyone
|
# broadcast emote to everyone
|
||||||
for receiver in receivers:
|
for receiver in receivers:
|
||||||
# we make a temporary copy that we can modify
|
# first handle the language mapping, which always produce different keys ##nn
|
||||||
|
receiver_lang_mapping = {}
|
||||||
|
try:
|
||||||
|
process_language = receiver.process_language
|
||||||
|
except AttributeError:
|
||||||
|
process_language = _dummy_process
|
||||||
|
for key, (langname, saytext) in language_mapping.iteritems():
|
||||||
|
# color says
|
||||||
|
receiver_lang_mapping[key] = process_language(saytext, sender, langname)
|
||||||
|
# map the language {##num} markers. This will convert the escaped sdesc markers on
|
||||||
|
# the form {{#num}} to {#num} markers ready to sdescmat in the next step.
|
||||||
|
send_emote = emote.format(**receiver_lang_mapping)
|
||||||
|
|
||||||
|
# handle sdesc mappings. we make a temporary copy that we can modify
|
||||||
try:
|
try:
|
||||||
process_sdesc = receiver.process_sdesc
|
process_sdesc = receiver.process_sdesc
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
|
@ -495,27 +511,18 @@ def send_emote(sender, receivers, emote, anonymous_add="first"):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
recog_get = receiver.recog.get
|
recog_get = receiver.recog.get
|
||||||
mapping = dict((ref, process_recog(recog_get(obj), obj)) for ref, obj in obj_mapping.items())
|
receiver_sdesc_mapping = dict((ref, process_recog(recog_get(obj), obj)) for ref, obj in obj_mapping.items())
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
mapping = dict((ref, process_sdesc(obj.sdesc.get(), obj)
|
receiver_sdesc_mapping = dict((ref, process_sdesc(obj.sdesc.get(), obj)
|
||||||
if hasattr(obj, "sdesc") else process_sdesc(obj.key, obj))
|
if hasattr(obj, "sdesc") else process_sdesc(obj.key, obj))
|
||||||
for ref, obj in obj_mapping.items())
|
for ref, obj in obj_mapping.items())
|
||||||
# handle the language mapping, which always produce different keys ##nn
|
|
||||||
try:
|
|
||||||
process_language = receiver.process_language
|
|
||||||
except AttributeError:
|
|
||||||
process_language = _dummy_process
|
|
||||||
for key, (langname, saytext) in language_mapping.iteritems():
|
|
||||||
# color says
|
|
||||||
mapping[key] = process_language(saytext, sender, langname)
|
|
||||||
# make sure receiver always sees their real name
|
# make sure receiver always sees their real name
|
||||||
rkey = "#%i" % receiver.id
|
rkey = "#%i" % receiver.id
|
||||||
if rkey in mapping:
|
if rkey in receiver_sdesc_mapping:
|
||||||
mapping[rkey] = process_sdesc(receiver.key, receiver)
|
receiver_sdesc_mapping[rkey] = process_sdesc(receiver.key, receiver)
|
||||||
|
|
||||||
# do the template replacement
|
|
||||||
receiver.msg(emote.format(**mapping))
|
|
||||||
|
|
||||||
|
# do the template replacement of the sdesc/recog {#num} markers
|
||||||
|
receiver.msg(send_emote.format(**receiver_sdesc_mapping))
|
||||||
|
|
||||||
#------------------------------------------------------------
|
#------------------------------------------------------------
|
||||||
# Handlers for sdesc and recog
|
# Handlers for sdesc and recog
|
||||||
|
|
@ -818,6 +825,7 @@ class CmdSay(RPCommand): # replaces standard say
|
||||||
locks = "cmd:all()"
|
locks = "cmd:all()"
|
||||||
|
|
||||||
def func(self):
|
def func(self):
|
||||||
|
|
||||||
"Run the say command"
|
"Run the say command"
|
||||||
|
|
||||||
caller = self.caller
|
caller = self.caller
|
||||||
|
|
@ -826,18 +834,12 @@ class CmdSay(RPCommand): # replaces standard say
|
||||||
caller.msg("Say what?")
|
caller.msg("Say what?")
|
||||||
return
|
return
|
||||||
|
|
||||||
speech = self.args
|
|
||||||
|
|
||||||
# calling the speech hook on the location
|
# calling the speech hook on the location
|
||||||
speech = caller.location.at_say(caller, speech)
|
speech = caller.location.at_say(caller, self.args)
|
||||||
|
# preparing the speech with sdesc/speech parsing.
|
||||||
# Feedback for the object doing the talking.
|
speech = "/me says, \"{speech}\"".format(speech=speech)
|
||||||
emit_string = '{name} says, "{speech}|n"'
|
targets = self.caller.location.contents
|
||||||
for target in caller.location.contents:
|
send_emote(self.caller, targets, speech, anonymous_add=None)
|
||||||
if target == caller:
|
|
||||||
target.msg(emit_string.format(name=caller.get_display_name(caller), speech=speech))
|
|
||||||
else:
|
|
||||||
target.msg(emit_string.format(name=caller.get_display_name(target), speech=speech))
|
|
||||||
|
|
||||||
|
|
||||||
class CmdSdesc(RPCommand): # set/look at own sdesc
|
class CmdSdesc(RPCommand): # set/look at own sdesc
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue