From fb45aa44a35ad334411ebd7d27382e449573930a Mon Sep 17 00:00:00 2001 From: Howard Abrams Date: Thu, 5 Jun 2025 22:01:01 -0700 Subject: [PATCH] Extract the shrub's chalkboard writing This should allow any GM-puppeted account to control the shrub without puppeting it. --- typeclasses/pets.py | 4 +-- typeclasses/puppets.py | 70 +++++++++++++++++++++++------------------- 2 files changed, 41 insertions(+), 33 deletions(-) diff --git a/typeclasses/pets.py b/typeclasses/pets.py index 441cddb..b08516f 100755 --- a/typeclasses/pets.py +++ b/typeclasses/pets.py @@ -558,14 +558,14 @@ class BHB(Friendly): """ match self.friendly_reaction(thrower): case Reaction.SCARED: - msg = "The beast runs away when you throw the stick." + msg = "The beast runs away when $you() throw the stick." case Reaction.CONCERNED: msg = "The beast walks over to the stick, sniffs it, and backs away." self.adjust_character(thrower, 5) case Reaction.INTERESTED: msg = choices(""" The beast <> at the stick, then looks at $you(), <> what to do with a stick the flies back to its owner. ;; - The beast <> the stick, and then veers off, thundering around the <>. The stick returns to your hand. + The beast <> the stick, and then veers off, thundering around the <>. The stick returns to $your() hand. """) self.adjust_character(thrower, 30) diff --git a/typeclasses/puppets.py b/typeclasses/puppets.py index 7286632..4a45a78 100755 --- a/typeclasses/puppets.py +++ b/typeclasses/puppets.py @@ -145,11 +145,7 @@ class CmdShrubSay(Command): aliases = ["write"] def func(self): - here = self.caller.location - msg = routput("The shrub uses a branch to << brush ^ wipe >> << off ^ >> << the chalk from ^ >> its << small ^ >> chalkboard, and with another branch, << slowly ^ carefully ^ deliberately ^ >> starts to write << something ^ a message ^ >>.") - here.msg_contents(msg) - self.caller.db.inside = self.args.strip() - self.caller.record_msg(f"The chalkboard reads: |w{self.args}|n") + self.obj.write(self.args.strip()) class CmdSetShrubSay(CmdSet): @@ -169,54 +165,66 @@ class Shrub(Puppet): "Called when a character is first created." self.cmdset.add(CmdSetShrubSay, persistent=True) - def find_actor(self, msg, default=None): + def write(self, new_text): + """ + Change the readable message on the chalkboard. + + This will also record the new message in the log. + """ + here = self.location + msg = routput("The shrub uses a branch to << brush ^ wipe >> << off ^ >> << the chalk from ^ >> its << small ^ >> chalkboard, and with another branch, << slowly ^ carefully ^ deliberately ^ >> starts to write << something ^ a message ^ >>.") + here.msg_contents(msg) + self.db.inside = f"The chalkboard reads: |w{new_text}|n" + self.record_msg(self.db.inside) + + def find_actor(self, text, default=None): """ Extract the character performing the action from the text. """ if default: return default - m = match(r".*\|b(.*?)\|n.*", msg) + m = match(r".*\|b(.*?)\|n.*", text) if m: return m.group(1) - def capitalize_msg(self, msg, msg_type=None): + def capitalize_msg(self, text, msg_type=None): """ - If msg is lowercase, capitalize it. + If text is lowercase, capitalize it. Maybe prepend a 'The' to the front. """ - if msg_type == 'traverse' or msg_type == 'teleport': - if match(r"^(\|[A-z])?[aeiou]", msg): - return "An " + msg + if msg_type and msg_type in ('traverse', 'teleport'): + if match(r"^(\|[A-z])?[aeiou]", text): + return "An " + text else: - return "A " + msg - elif msg_type == 'say' and match(r"^\|b[a-z]", msg): - return "The " + msg - elif match(r"^(\|[A-z])[a-z]", msg) and len(msg) > 2: - return msg[0:1] + msg[2].upper() + msg[3:] - elif match(r"^(\|[A-z])?[a-z]", msg) and len(msg) > 2: - return msg[0].upper() + msg[1:] - return msg + return "A " + text + elif msg_type and msg_type == 'say' and match(r"^\|b[a-z]", text): + return "The " + text + elif match(r"^(\|[A-z])[a-z]", text) and len(text) > 2: + return text[0:1] + text[2].upper() + text[3:] + elif match(r"^(\|[A-z])?[a-z]", text) and len(text) > 2: + return text[0].upper() + text[1:] + return text - def to_html(self, msg, msg_type=None): + def to_html(self, text, msg_type=None): """ - Convert the 'msg' to an HTML formatted string. + Convert the 'text' to an HTML formatted string. """ # Bold anything white: - msg = sub(r"\|w(.*?)\|n", '\\1', msg) + text = sub(r"\|w(.*?)\|n", '\\1', text) # Remove the rest: - msg = sub(r"\|[A-z]", '', msg) + text = sub(r"\|[A-z]", '', text) # Remove initial or final carriage returns: - msg = sub(r"^\n", '', msg) - msg = sub(r"\n$", '', msg) + text = sub(r"^\n", '', text) + text = sub(r"\n$", '', text) # Convert the carriage returns: - msg = sub(r"\n", '
\n', msg) + text = sub(r"\n", '
\n', text) - if msg_type == 'look': - msg = msg[0].upper + msg[1:] - return f"

{msg}

\n" - return f"

{msg}

\n" + if msg_type and msg_type == 'look': + text = text[0].upper + text[1:] + return f"

{text}

\n" + return f"

{text}

\n" def record_msg(self, text, actor=None): msg_type = None