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.

This commit is contained in:
Griatch 2012-02-17 18:53:47 +01:00
parent a6f3e1f47f
commit 6e53e6a1fd
4 changed files with 14 additions and 3 deletions

View file

@ -35,6 +35,7 @@ command line. The process is as follows:
""" """
from copy import copy
from traceback import format_exc from traceback import format_exc
from django.conf import settings from django.conf import settings
from src.comms.channelhandler import CHANNELHANDLER from src.comms.channelhandler import CHANNELHANDLER
@ -225,7 +226,7 @@ def cmdhandler(caller, raw_string, testing=False):
if testing: if testing:
# only return the command instance # only return the command instance
return cmd return cmd
# pre-command hook # pre-command hook
cmd.at_pre_cmd() cmd.at_pre_cmd()
@ -236,6 +237,14 @@ def cmdhandler(caller, raw_string, testing=False):
# post-command hook # post-command hook
cmd.at_post_cmd() 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 # Done! By default, Evennia does not use this return at all
return ret return ret

View file

@ -1,7 +1,7 @@
""" """
CmdSethandler 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. current merged sum of all CmdSets added to it.
A CmdSet constitues a set of commands. The CmdSet works as a special A CmdSet constitues a set of commands. The CmdSet works as a special

View file

@ -26,6 +26,8 @@ class CommandMeta(type):
except Exception: except Exception:
mcs.aliases = [] mcs.aliases = []
mcs.aliases = [str(alias).strip() for alias in 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 # pre-process locks as defined in class definition
temp = [] temp = []

View file

@ -614,7 +614,7 @@ class CmdOOCLook(CmdLook):
key = "look" key = "look"
aliases = ["l", "ls"] aliases = ["l", "ls"]
locks = "cmd:all()" locks = "cmd:all()"
help_cateogory = "General" help_category = "General"
def func(self): def func(self):
"implement the ooc look command" "implement the ooc look command"