mirror of
https://github.com/evennia/evennia.git
synced 2026-03-23 00:06:30 +01:00
Fixed some strange behaviour in the help system due to recent changes in how cmdsets are merged by cmdhandler.
This commit is contained in:
parent
e767b3458a
commit
9be2b5a64b
3 changed files with 49 additions and 16 deletions
|
|
@ -17,7 +17,9 @@ LIST_ARGS = ["list", "all"]
|
|||
|
||||
def format_help_entry(title, help_text, aliases=None,
|
||||
suggested=None):
|
||||
"This visually formats the help entry."
|
||||
"""
|
||||
This visually formats the help entry.
|
||||
"""
|
||||
string = "-"*70 + "\n"
|
||||
if title:
|
||||
string += "Help topic for {w%s{n" % (title.capitalize())
|
||||
|
|
@ -33,13 +35,17 @@ def format_help_entry(title, help_text, aliases=None,
|
|||
return string
|
||||
|
||||
def format_help_list(hdict_cmds, hdict_db):
|
||||
"Output a category-ordered list"
|
||||
string = "\n\r" + "-"*70 + "\n\r {gCommand help entries{n\n" + "-"*70
|
||||
for category in sorted(hdict_cmds.keys()):
|
||||
string += "\n {w%s{n:\n" % \
|
||||
(str(category).capitalize())
|
||||
string += fill(", ".join(sorted(hdict_cmds[category])))
|
||||
if hdict_db:
|
||||
"""
|
||||
Output a category-ordered list.
|
||||
"""
|
||||
string = ""
|
||||
if hdict_cmds and hdict_cmds.values():
|
||||
string += "\n\r" + "-"*70 + "\n\r {gCommand help entries{n\n" + "-"*70
|
||||
for category in sorted(hdict_cmds.keys()):
|
||||
string += "\n {w%s{n:\n" % \
|
||||
(str(category).capitalize())
|
||||
string += fill(", ".join(sorted(hdict_cmds[category])))
|
||||
if hdict_db and hdict_db.values():
|
||||
string += "\n\r\n\r" + "-"*70 + "\n\r {gOther help entries{n\n" + '-'*70
|
||||
for category in sorted(hdict_db.keys()):
|
||||
string += "\n\r {w%s{n:\n" % (str(category).capitalize())
|
||||
|
|
@ -78,6 +84,10 @@ class CmdHelp(Command):
|
|||
|
||||
if not query:
|
||||
query = "all"
|
||||
|
||||
# removing doublets in cmdset, caused by cmdhandler
|
||||
# having to allow doublet commands to manage exits etc.
|
||||
cmdset.make_unique(caller)
|
||||
|
||||
# Listing help entries
|
||||
|
||||
|
|
@ -129,15 +139,20 @@ class CmdHelp(Command):
|
|||
# Handle result
|
||||
if (not cmdmatches) and (not dbmatches):
|
||||
# no normal match. Check if this is a category match instead
|
||||
categ_cmdmatches = [cmd for cmd in cmdset
|
||||
categ_cmdmatches = [cmd.key for cmd in cmdset
|
||||
if query == cmd.help_category and has_perm(caller, cmd, 'cmd')]
|
||||
categ_dbmatches = \
|
||||
[topic for topic in
|
||||
[topic.key for topic in
|
||||
HelpEntry.objects.find_topics_with_category(query)
|
||||
if has_perm(caller, topic, 'view')]
|
||||
if categ_cmdmatches or categ_dbmatches:
|
||||
help_entry = format_help_list({query:categ_cmdmatches},
|
||||
{query:categ_dbmatches})
|
||||
cmddict = None
|
||||
dbdict = None
|
||||
if categ_cmdmatches:
|
||||
cmddict = {query:categ_cmdmatches}
|
||||
if categ_dbmatches:
|
||||
dbdict = {query:categ_dbmatches}
|
||||
if cmddict or dbdict:
|
||||
help_entry = format_help_list(cmddict, dbdict)
|
||||
else:
|
||||
help_entry = "No help entry found for '%s'" % query
|
||||
|
||||
|
|
|
|||
|
|
@ -70,8 +70,6 @@ caller.msg("A %s was created." % red_button.key)
|
|||
# again (so as to avoid duplicate objects when testing the script many
|
||||
# times).
|
||||
|
||||
caller.msg(limbo.key)
|
||||
|
||||
# the python variables we assign to must match the ones given in the
|
||||
# header for the system to be able to delete them afterwards during a
|
||||
# debugging run.
|
||||
|
|
|
|||
|
|
@ -259,7 +259,27 @@ class CmdSet(object):
|
|||
cmdset.key_mergetypes = copy.deepcopy(self.key_mergetypes)
|
||||
return cmdset
|
||||
|
||||
|
||||
def make_unique(self, caller):
|
||||
"""
|
||||
This is an unsafe command meant to clean out a cmdset of
|
||||
doublet commands after it has been created. It is useful
|
||||
for commands inheriting cmdsets from the cmdhandler where
|
||||
obj-based cmdsets always are added double. Doublets will
|
||||
be weeded out with preference to commands defined on caller,
|
||||
otherwise just by first-come-first-served.
|
||||
"""
|
||||
unique = {}
|
||||
for cmd in self.commands:
|
||||
if cmd.key in unique:
|
||||
ocmd = unique[cmd.key]
|
||||
if (hasattr(cmd, 'obj') and cmd.obj == caller) and not \
|
||||
(hasattr(ocmd, 'obj') and ocmd.obj == caller):
|
||||
unique[cmd.key] = cmd
|
||||
else:
|
||||
unique[cmd.key] = cmd
|
||||
self.commands = unique.values()
|
||||
|
||||
|
||||
def __str__(self):
|
||||
"""
|
||||
Show all commands in cmdset when printing it.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue