Made examine command more verbose about the cmdset stack and just which cmdsets go into the currently merged set. This meant a change to merged sets where they store their component sets as a variable "merged_from".

This commit is contained in:
Griatch 2014-01-20 22:46:30 +01:00
parent 1cabcae771
commit c321ccb332
5 changed files with 44 additions and 20 deletions

View file

@ -1663,7 +1663,7 @@ class CmdExamine(ObjManipCommand):
string += "\n{wLocation{n: %s" % obj.location
if obj.location:
string += " (#%s)" % obj.location.id
if hasattr(obj, "destination"):
if hasattr(obj, "destination") and obj.destination:
string += "\n{wDestination{n: %s" % obj.destination
if obj.destination:
string += " (#%s)" % obj.destination.id
@ -1686,26 +1686,39 @@ class CmdExamine(ObjManipCommand):
string += "\n{wLocks{n:%s" % locks_string
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
obj.player and obj.player.cmdset.all() or []))
try:
# we have to protect this since many objects don't have player/sessions.
all_cmdsets += obj.player.get_session(obj.sessid).cmdset.all()
except (TypeError, AttributeError):
pass
stored_cmdsets = obj.cmdset.all()
stored_cmdsets.sort(key=lambda x: x.priority, reverse=True)
string += "\n{wStored Cmdset(s){n:\n %s" % ("\n ".join("%s [%s] (%s, prio %s)" % \
(cmdset.path, cmdset.key, cmdset.mergetype, cmdset.priority)
for cmdset in stored_cmdsets if cmdset.key != "_EMPTY_CMDSET"))
# this gets all components of the currently merged set
all_cmdsets = [(cmdset.key, cmdset) for cmdset in avail_cmdset.merged_from]
# we always at least try to add player- and session sets since these are ignored
# if we merge on the object level.
if hasattr(obj, "player") and obj.player:
all_cmdsets.extend([(cmdset.key, cmdset) for cmdset in obj.player.cmdset.all()])
if obj.sessid:
all_cmdsets.extend([(cmdset.key, cmdset) for cmdset in obj.player.get_session(obj.sessid).cmdset.all()])
else:
try:
# we have to protect this since many objects don't have sessions.
all_cmdsets.extend([(cmdset.key, cmdset) for cmdset in obj.get_session(obj.sessid).cmdset.all()])
except (TypeError, AttributeError):
pass
all_cmdsets = [cmdset for cmdset in dict(all_cmdsets).values()]
all_cmdsets.sort(key=lambda x: x.priority, reverse=True)
string += "\n{wStored Cmdset(s){n:\n %s" % ("\n ".join("%s [%s] (prio %s)" % \
(cmdset.path, cmdset.key, cmdset.priority)
string += "\n{wMerged Cmdset(s){n:\n %s" % ("\n ".join("%s [%s] (%s, prio %s)" % \
(cmdset.path, cmdset.key, cmdset.mergetype, cmdset.priority)
for cmdset in all_cmdsets))
# list the commands available to this object
avail_cmdset = sorted([cmd.key for cmd in avail_cmdset
if cmd.access(obj, "cmd")])
cmdsetstr = utils.fill(", ".join(avail_cmdset), indent=2)
string += "\n{wCommands available to %s (all cmdsets + exits and external cmds){n:\n %s" % (obj.key, cmdsetstr)
string += "\n{wCommands available to %s (result of Merged CmdSets){n:\n %s" % (obj.key, cmdsetstr)
if hasattr(obj, "scripts") and hasattr(obj.scripts, "all") and obj.scripts.all():
string += "\n{wScripts{n:\n %s" % obj.scripts
@ -1759,7 +1772,7 @@ class CmdExamine(ObjManipCommand):
caller.execute_cmd('look %s' % obj.name)
return
# using callback for printing result whenever function returns.
get_and_merge_cmdsets(obj, self.session, self.player, obj, "session").addCallback(get_cmdset_callback)
get_and_merge_cmdsets(obj, self.session, self.player, obj, "object").addCallback(get_cmdset_callback)
else:
self.msg("You need to supply a target to examine.")
return
@ -1794,8 +1807,14 @@ class CmdExamine(ObjManipCommand):
# we are only interested in specific attributes
caller.msg(self.format_attributes(obj, attrname, crop=False))
else:
if obj.sessid:
mergemode = "session"
elif self.player_mode:
mergemode = "player"
else:
mergemode = "object"
# using callback to print results whenever function returns.
get_and_merge_cmdsets(obj, self.session, self.player, obj, "session").addCallback(get_cmdset_callback)
get_and_merge_cmdsets(obj, self.session, self.player, obj, mergemode).addCallback(get_cmdset_callback)
class CmdFind(MuxCommand):

View file

@ -9,7 +9,7 @@ class SessionCmdSet(CmdSet):
Sets up the unlogged cmdset.
"""
key = "DefaultSession"
priority = 0
priority = -7
def at_cmdset_creation(self):
"Populate the cmdset"