Partial edit_node functionality
This commit is contained in:
parent
ed3e57edd0
commit
cbaa2c56e9
2 changed files with 34 additions and 32 deletions
|
|
@ -1132,7 +1132,7 @@ def list_node(option_generator, select=None, examine=None, edit=None, add=None,
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
option_generator (callable or list): A list of strings indicating the options, or a callable
|
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)
|
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
|
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
|
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):
|
def _list_node(caller, raw_string, **kwargs):
|
||||||
|
|
||||||
mode = kwargs.get("list_mode", None)
|
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)
|
npages = 0
|
||||||
pages = [option_list[ind:ind + pagesize] for ind in range(0, nall_options, pagesize)]
|
page_index = 0
|
||||||
npages = len(pages)
|
page = None
|
||||||
|
options = []
|
||||||
|
|
||||||
page_index = max(0, min(npages - 1, kwargs.get("optionpage_index", 0)))
|
if option_list:
|
||||||
page = pages[page_index]
|
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
|
entry = None
|
||||||
extra_text = 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,
|
mode, entry = _input_parser(caller, raw_string,
|
||||||
**{"available_choices": page})
|
**{"available_choices": page})
|
||||||
|
|
||||||
if examine and mode: # == "look":
|
if examine and mode: # == "look":
|
||||||
# look mode - we are examining a given entry
|
# look mode - we are examining a given entry
|
||||||
try:
|
try:
|
||||||
text = examine(caller, entry)
|
text = examine(caller, entry)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.log_trace()
|
logger.log_trace()
|
||||||
text = "|rCould not view."
|
text = "|rCould not view."
|
||||||
options = [{"key": ("|wb|Wack|n", "b"),
|
options.extend([{"key": ("|wb|Wack|n", "b"),
|
||||||
"goto": (lambda caller: None,
|
"goto": (lambda caller: None,
|
||||||
{"optionpage_index": page_index})},
|
{"optionpage_index": page_index})},
|
||||||
{"key": "_default",
|
{"key": "_default",
|
||||||
"goto": (lambda caller: None,
|
"goto": (lambda caller: None,
|
||||||
{"optionpage_index": page_index})}]
|
{"optionpage_index": page_index})}])
|
||||||
return text, options
|
return text, options
|
||||||
|
|
||||||
# if edit and mode == "edit":
|
# 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`
|
# dynamic, multi-page option list. Each selection leads to the `select`
|
||||||
# callback being called with a result from the available choices
|
# callback being called with a result from the available choices
|
||||||
options = [{"desc": opt,
|
options.extend([{"desc": opt,
|
||||||
"goto": (_select_parser,
|
"goto": (_select_parser,
|
||||||
{"available_choices": page})} for opt in page]
|
{"available_choices": page})} for opt in page])
|
||||||
|
|
||||||
if add:
|
if add:
|
||||||
# We have a processor to handle adding a new entry. Re-run this node
|
# We have a processor to handle adding a new entry. Re-run this node
|
||||||
|
|
|
||||||
|
|
@ -916,7 +916,7 @@ def node_meta_key(caller):
|
||||||
return text, options
|
return text, options
|
||||||
|
|
||||||
|
|
||||||
def _all_prototypes():
|
def _all_prototypes(caller):
|
||||||
return [mproto.key for mproto in search_prototype()]
|
return [mproto.key for mproto in search_prototype()]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -949,7 +949,7 @@ def node_prototype(caller):
|
||||||
return text, options
|
return text, options
|
||||||
|
|
||||||
|
|
||||||
def _all_typeclasses():
|
def _all_typeclasses(caller):
|
||||||
return list(sorted(get_all_typeclasses().keys()))
|
return list(sorted(get_all_typeclasses().keys()))
|
||||||
# return list(sorted(get_all_typeclasses(parent="evennia.objects.objects.DefaultObject").keys()))
|
# return list(sorted(get_all_typeclasses(parent="evennia.objects.objects.DefaultObject").keys()))
|
||||||
|
|
||||||
|
|
@ -1060,24 +1060,17 @@ def node_attrs(caller):
|
||||||
return text, options
|
return text, options
|
||||||
|
|
||||||
|
|
||||||
def node_tags(caller):
|
def _caller_tags(caller):
|
||||||
metaprot = _get_menu_metaprot(caller)
|
metaprot = _get_menu_metaprot(caller)
|
||||||
prot = metaprot.prototype
|
prot = metaprot.prototype
|
||||||
tags = prot.get("tags")
|
tags = prot.get("tags")
|
||||||
|
return tags
|
||||||
|
|
||||||
text = ["Set the prototype's |yTags|n. Separate multiple tags with commas. "
|
|
||||||
"Will retain case sensitivity."]
|
@list_node(_caller_tags)
|
||||||
if tags:
|
def node_tags(caller):
|
||||||
text.append("Current tags are '|y{tags}|n'.".format(tags=tags))
|
text = "Set the prototype's |yTags|n."
|
||||||
else:
|
|
||||||
text.append("No tags are set.")
|
|
||||||
text = "\n\n".join(text)
|
|
||||||
options = _wizard_options("tags", "attrs", "locks")
|
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
|
return text, options
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1204,6 +1197,7 @@ def node_meta_desc(caller):
|
||||||
return text, options
|
return text, options
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def node_meta_tags(caller):
|
def node_meta_tags(caller):
|
||||||
metaprot = _get_menu_metaprot(caller)
|
metaprot = _get_menu_metaprot(caller)
|
||||||
text = ["|wMeta-Tags|n can be used to classify and find prototypes. Tags are case-insensitive. "
|
text = ["|wMeta-Tags|n can be used to classify and find prototypes. Tags are case-insensitive. "
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue