From 6e53e6a1fdd0ec15ccaa0798bb49487ccac61116 Mon Sep 17 00:00:00 2001 From: Griatch Date: Fri, 17 Feb 2012 18:53:47 +0100 Subject: [PATCH] Added state persistence to commands. For commands that want to, their state will be saved for the next command to access through the self.caller.ndb.last_cmd variable. The state only persists one command before it is cleared or replaced. --- src/commands/cmdhandler.py | 11 ++++++++++- src/commands/cmdsethandler.py | 2 +- src/commands/command.py | 2 ++ src/commands/default/general.py | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/commands/cmdhandler.py b/src/commands/cmdhandler.py index c5cb40bf5b..ab71361ff6 100644 --- a/src/commands/cmdhandler.py +++ b/src/commands/cmdhandler.py @@ -35,6 +35,7 @@ command line. The process is as follows: """ +from copy import copy from traceback import format_exc from django.conf import settings from src.comms.channelhandler import CHANNELHANDLER @@ -225,7 +226,7 @@ def cmdhandler(caller, raw_string, testing=False): if testing: # only return the command instance return cmd - + # pre-command hook cmd.at_pre_cmd() @@ -236,6 +237,14 @@ def cmdhandler(caller, raw_string, testing=False): # post-command hook cmd.at_post_cmd() + + if cmd.save_next: + # store a reference to this command, possibly + # accessible by the next command. + caller.ndb.last_cmd = copy(cmd) + else: + caller.ndb.last_cmd = None + # Done! By default, Evennia does not use this return at all return ret diff --git a/src/commands/cmdsethandler.py b/src/commands/cmdsethandler.py index 9025c3ca08..7406c7d814 100644 --- a/src/commands/cmdsethandler.py +++ b/src/commands/cmdsethandler.py @@ -1,7 +1,7 @@ """ CmdSethandler -The Cmdhandler tracks an object's 'Current CmdSet', which is the +The Cmdsethandler tracks an object's 'Current CmdSet', which is the current merged sum of all CmdSets added to it. A CmdSet constitues a set of commands. The CmdSet works as a special diff --git a/src/commands/command.py b/src/commands/command.py index 7491e31128..6e2960d533 100644 --- a/src/commands/command.py +++ b/src/commands/command.py @@ -26,6 +26,8 @@ class CommandMeta(type): except Exception: mcs.aliases = [] mcs.aliases = [str(alias).strip() for alias in mcs.aliases] + if not hasattr(mcs, "save_next"): + mcs.save_next = False # pre-process locks as defined in class definition temp = [] diff --git a/src/commands/default/general.py b/src/commands/default/general.py index edc0ecc9b2..aa516d597c 100644 --- a/src/commands/default/general.py +++ b/src/commands/default/general.py @@ -614,7 +614,7 @@ class CmdOOCLook(CmdLook): key = "look" aliases = ["l", "ls"] locks = "cmd:all()" - help_cateogory = "General" + help_category = "General" def func(self): "implement the ooc look command"