diff --git a/evennia/utils/evmenu.py b/evennia/utils/evmenu.py index e9e3f1c8af..6df9142bbb 100644 --- a/evennia/utils/evmenu.py +++ b/evennia/utils/evmenu.py @@ -1132,7 +1132,7 @@ def list_node(option_generator, select=None, examine=None, edit=None, add=None, Args: option_generator (callable or list): A list of strings indicating the options, or a callable - that is called without any arguments to produce such a list. + that is called as option_generator(caller) to produce such a list. select (callable, option): Will be called as select(caller, menuchoice) where menuchoice is the chosen option as a string. Should return the target node to goto after this selection. Note that if this is not given, the decorated node must itself @@ -1217,14 +1217,22 @@ def list_node(option_generator, select=None, examine=None, edit=None, add=None, def _list_node(caller, raw_string, **kwargs): mode = kwargs.get("list_mode", None) - option_list = option_generator() if callable(option_generator) else option_generator + option_list = option_generator(caller) if callable(option_generator) else option_generator - nall_options = len(option_list) - pages = [option_list[ind:ind + pagesize] for ind in range(0, nall_options, pagesize)] - npages = len(pages) + npages = 0 + page_index = 0 + page = None + options = [] - page_index = max(0, min(npages - 1, kwargs.get("optionpage_index", 0))) - page = pages[page_index] + if option_list: + nall_options = len(option_list) + pages = [option_list[ind:ind + pagesize] for ind in range(0, nall_options, pagesize)] + npages = len(pages) + + page_index = max(0, min(npages - 1, kwargs.get("optionpage_index", 0))) + page = pages[page_index] + + text = "" entry = None extra_text = None @@ -1233,19 +1241,19 @@ def list_node(option_generator, select=None, examine=None, edit=None, add=None, mode, entry = _input_parser(caller, raw_string, **{"available_choices": page}) - if examine and mode: # == "look": + if examine and mode: # == "look": # look mode - we are examining a given entry try: text = examine(caller, entry) except Exception: logger.log_trace() text = "|rCould not view." - options = [{"key": ("|wb|Wack|n", "b"), - "goto": (lambda caller: None, - {"optionpage_index": page_index})}, - {"key": "_default", - "goto": (lambda caller: None, - {"optionpage_index": page_index})}] + options.extend([{"key": ("|wb|Wack|n", "b"), + "goto": (lambda caller: None, + {"optionpage_index": page_index})}, + {"key": "_default", + "goto": (lambda caller: None, + {"optionpage_index": page_index})}]) return text, options # if edit and mode == "edit": @@ -1263,9 +1271,9 @@ def list_node(option_generator, select=None, examine=None, edit=None, add=None, # dynamic, multi-page option list. Each selection leads to the `select` # callback being called with a result from the available choices - options = [{"desc": opt, - "goto": (_select_parser, - {"available_choices": page})} for opt in page] + options.extend([{"desc": opt, + "goto": (_select_parser, + {"available_choices": page})} for opt in page]) if add: # We have a processor to handle adding a new entry. Re-run this node diff --git a/evennia/utils/spawner.py b/evennia/utils/spawner.py index eaab84b202..ebf3ce5d67 100644 --- a/evennia/utils/spawner.py +++ b/evennia/utils/spawner.py @@ -916,7 +916,7 @@ def node_meta_key(caller): return text, options -def _all_prototypes(): +def _all_prototypes(caller): return [mproto.key for mproto in search_prototype()] @@ -949,7 +949,7 @@ def node_prototype(caller): return text, options -def _all_typeclasses(): +def _all_typeclasses(caller): return list(sorted(get_all_typeclasses().keys())) # return list(sorted(get_all_typeclasses(parent="evennia.objects.objects.DefaultObject").keys())) @@ -1060,24 +1060,17 @@ def node_attrs(caller): return text, options -def node_tags(caller): +def _caller_tags(caller): metaprot = _get_menu_metaprot(caller) prot = metaprot.prototype tags = prot.get("tags") + return tags - text = ["Set the prototype's |yTags|n. Separate multiple tags with commas. " - "Will retain case sensitivity."] - if tags: - text.append("Current tags are '|y{tags}|n'.".format(tags=tags)) - else: - text.append("No tags are set.") - text = "\n\n".join(text) + +@list_node(_caller_tags) +def node_tags(caller): + text = "Set the prototype's |yTags|n." options = _wizard_options("tags", "attrs", "locks") - options.append({"key": "_default", - "goto": (_set_property, - dict(prop="tags", - processor=lambda s: [part.strip() for part in s.split(",")], - next_node="node_locks"))}) return text, options @@ -1204,6 +1197,7 @@ def node_meta_desc(caller): return text, options + def node_meta_tags(caller): metaprot = _get_menu_metaprot(caller) text = ["|wMeta-Tags|n can be used to classify and find prototypes. Tags are case-insensitive. "