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 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

View file

@ -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

View file

@ -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 = []

View file

@ -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"