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