From 48bfc7e54a3e9244963b9b4fa7bdac715a61da41 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 4 Jan 2014 13:24:07 +0100 Subject: [PATCH] Made Empty cmdsets have priority -100, also changed their key from "Empty" to _EMPTY_CMDSET to make it clearer this is a special name. See also discussion in Issue 447. --- src/commands/cmdhandler.py | 3 ++- src/commands/cmdsethandler.py | 15 ++++++++++----- src/commands/default/building.py | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/commands/cmdhandler.py b/src/commands/cmdhandler.py index bf4650f94d..40a92e57e0 100644 --- a/src/commands/cmdhandler.py +++ b/src/commands/cmdhandler.py @@ -200,7 +200,7 @@ def get_and_merge_cmdsets(caller, session, player, obj, # weed out all non-found sets cmdsets = yield [cmdset for cmdset in cmdsets - if cmdset and cmdset.key != "Empty"] + if cmdset and cmdset.key != "_EMPTY_CMDSET"] # report cmdset errors to user (these should already have been logged) yield [report_to.msg(cmdset.errmessage) for cmdset in cmdsets if cmdset.key == "_CMDSET_ERROR"] @@ -218,6 +218,7 @@ def get_and_merge_cmdsets(caller, session, player, obj, tempmergers = {} for cmdset in cmdsets: prio = cmdset.priority + #print cmdset.key, prio if prio in tempmergers: # merge same-prio cmdset together separately tempmergers[prio] = yield cmdset + tempmergers[prio] diff --git a/src/commands/cmdsethandler.py b/src/commands/cmdsethandler.py index 573c19de13..7a4c4c91fe 100644 --- a/src/commands/cmdsethandler.py +++ b/src/commands/cmdsethandler.py @@ -78,6 +78,11 @@ class _ErrorCmdSet(CmdSet): key = "_CMDSET_ERROR" errmessage = "Error when loading cmdset." +class _EmptyCmdSet(CmdSet): + "This cmdset represents an empty cmdset" + key = "_EMPTY_CMDSET" + priority = -100 + mergetype = "Union" def import_cmdset(python_path, cmdsetobj, emit_to_obj=None, no_logging=False): """ @@ -166,7 +171,7 @@ class CmdSetHandler(object): # this holds the "merged" current command set self.current = None # this holds a history of CommandSets - self.cmdset_stack = [CmdSet(cmdsetobj=self.obj, key="Empty")] + self.cmdset_stack = [_EmptyCmdSet(cmdsetobj=self.obj)] # this tracks which mergetypes are actually in play in the stack self.mergetype_stack = ["Union"] @@ -244,7 +249,7 @@ class CmdSetHandler(object): self.cmdset_stack = [] for pos, path in enumerate(storage): if pos == 0 and not path: - self.cmdset_stack = [CmdSet(cmdsetobj=self.obj, key="Empty")] + self.cmdset_stack = [EmptyCmdSet(cmdsetobj=self.obj)] elif path: cmdset = self._import_cmdset(path) if cmdset: @@ -410,9 +415,9 @@ class CmdSetHandler(object): else: storage = [""] self.cmdset_storage = storage - self.cmdset_stack[0] = CmdSet(cmdsetobj=self.obj, key="Empty") + self.cmdset_stack[0] = EmptyCmdSet(cmdsetobj=self.obj) else: - self.cmdset_stack = [CmdSet(cmdsetobj=self.obj, key="Empty")] + self.cmdset_stack = [EmptyCmdSet(cmdsetobj=self.obj)] self.update() def all(self): @@ -453,7 +458,7 @@ class CmdSetHandler(object): new_cmdset_stack = [] new_mergetype_stack = [] for cmdset in self.cmdset_stack: - if cmdset.key == "Empty": + if cmdset.key == "_EMPTY_CMDSET": new_cmdset_stack.append(cmdset) new_mergetype_stack.append("Union") else: diff --git a/src/commands/default/building.py b/src/commands/default/building.py index 9faee293a6..71e7562c78 100644 --- a/src/commands/default/building.py +++ b/src/commands/default/building.py @@ -1685,7 +1685,7 @@ class CmdExamine(ObjManipCommand): string += "\n{wLocks{n:%s" % locks_string - if not (len(obj.cmdset.all()) == 1 and obj.cmdset.current.key == "Empty"): + if not (len(obj.cmdset.all()) == 1 and obj.cmdset.current.key == "_EMPTY_CMDSET"): # list the current cmdsets all_cmdsets = (obj.cmdset.all() + (hasattr(obj, "player") and obj.player and