Hide prototypes from CmdScripts output. Resolves #2067

This commit is contained in:
Griatch 2020-03-28 20:56:01 +01:00
parent 8c44766c0a
commit 15f1eaaac0
5 changed files with 17 additions and 13 deletions

View file

@ -487,6 +487,8 @@ class CmdScripts(COMMAND_DEFAULT_CLASS):
locks = "cmd:perm(listscripts) or perm(Admin)"
help_category = "System"
excluded_typeclass_paths = ["evennia.prototypes.prototypes.DbPrototype"]
def func(self):
"""implement method"""
@ -519,6 +521,8 @@ class CmdScripts(COMMAND_DEFAULT_CLASS):
if not scripts:
caller.msg("No scripts are running.")
return
# filter any found scripts by tag category.
scripts = scripts.exclude(db_typeclass_path__in=self.excluded_typeclass_paths)
if not scripts:
string = "No scripts found with a key '%s', or on an object named '%s'." % (args, args)

View file

@ -1488,7 +1488,7 @@ def node_tags(caller):
as the |cprototype_key|n and with a category "{tag_category}". This allows the spawner to
optionally update previously spawned objects when their prototype changes.
""".format(
tag_category=protlib._PROTOTYPE_TAG_CATEGORY
tag_category=protlib.PROTOTYPE_TAG_CATEGORY
)
text = (text, helptext)
@ -2182,7 +2182,7 @@ def _format_diff_text_and_options(diff, minimal=True, **kwargs):
texts.append(" |c[{optnum}] |yADD|n: {new}".format(
optnum=optnum, new=_visualize(new, rootname)))
elif instruction == "REMOVE" and not new:
if rootname == "tags" and old[1] == protlib._PROTOTYPE_TAG_CATEGORY:
if rootname == "tags" and old[1] == protlib.PROTOTYPE_TAG_CATEGORY:
# special exception for the prototype-tag mechanism
# this is added post-spawn automatically and should
# not be listed as REMOVE.

View file

@ -52,7 +52,7 @@ _PROTOTYPE_RESERVED_KEYS = _PROTOTYPE_META_NAMES + (
"tags",
"attrs",
)
_PROTOTYPE_TAG_CATEGORY = "from_prototype"
PROTOTYPE_TAG_CATEGORY = "from_prototype"
_PROTOTYPE_TAG_META_CATEGORY = "db_prototype"
PROT_FUNCS = {}
@ -263,7 +263,7 @@ def save_prototype(prototype):
stored_prototype = stored_prototype[0]
stored_prototype.desc = in_prototype["prototype_desc"]
if prototype_tags:
stored_prototype.tags.clear(category=_PROTOTYPE_TAG_CATEGORY)
stored_prototype.tags.clear(category=PROTOTYPE_TAG_CATEGORY)
stored_prototype.tags.batch_add(*in_prototype["prototype_tags"])
stored_prototype.locks.add(in_prototype["prototype_locks"])
stored_prototype.attributes.add("prototype", in_prototype)
@ -421,7 +421,7 @@ def search_objects_with_prototype(prototype_key):
matches (Queryset): All matching objects spawned from this prototype.
"""
return ObjectDB.objects.get_by_tag(key=prototype_key, category=_PROTOTYPE_TAG_CATEGORY)
return ObjectDB.objects.get_by_tag(key=prototype_key, category=PROTOTYPE_TAG_CATEGORY)
def list_prototypes(caller, key=None, tags=None, show_non_use=False, show_non_edit=True):

View file

@ -145,7 +145,7 @@ from evennia.prototypes.prototypes import (
value_to_obj,
value_to_obj_or_any,
init_spawn_value,
_PROTOTYPE_TAG_CATEGORY,
PROTOTYPE_TAG_CATEGORY,
)
@ -269,7 +269,7 @@ def prototype_from_object(obj):
"""
# first, check if this object already has a prototype
prot = obj.tags.get(category=_PROTOTYPE_TAG_CATEGORY, return_list=True)
prot = obj.tags.get(category=PROTOTYPE_TAG_CATEGORY, return_list=True)
if prot:
prot = protlib.search_prototype(prot[0])
@ -625,7 +625,7 @@ def batch_update_objects_with_prototype(prototype, diff=None, objects=None, exac
prototype_key = new_prototype["prototype_key"]
if not objects:
objects = ObjectDB.objects.get_by_tag(prototype_key, category=_PROTOTYPE_TAG_CATEGORY)
objects = ObjectDB.objects.get_by_tag(prototype_key, category=PROTOTYPE_TAG_CATEGORY)
if not objects:
return 0
@ -640,7 +640,7 @@ def batch_update_objects_with_prototype(prototype, diff=None, objects=None, exac
for obj in objects:
do_save = False
old_prot_key = obj.tags.get(category=_PROTOTYPE_TAG_CATEGORY, return_list=True)
old_prot_key = obj.tags.get(category=PROTOTYPE_TAG_CATEGORY, return_list=True)
old_prot_key = old_prot_key[0] if old_prot_key else None
try:
@ -743,8 +743,8 @@ def batch_update_objects_with_prototype(prototype, diff=None, objects=None, exac
logger.log_trace(f"Failed to apply prototype '{prototype_key}' to {obj}.")
finally:
# we must always make sure to re-add the prototype tag
obj.tags.clear(category=_PROTOTYPE_TAG_CATEGORY)
obj.tags.add(prototype_key, category=_PROTOTYPE_TAG_CATEGORY)
obj.tags.clear(category=PROTOTYPE_TAG_CATEGORY)
obj.tags.add(prototype_key, category=PROTOTYPE_TAG_CATEGORY)
if do_save:
changed += 1
@ -927,7 +927,7 @@ def spawn(*prototypes, **kwargs):
prototype_key = prototype.get("prototype_key", None)
if prototype_key:
# we make sure to add a tag identifying which prototype created this object
tags.append((prototype_key, _PROTOTYPE_TAG_CATEGORY))
tags.append((prototype_key, PROTOTYPE_TAG_CATEGORY))
val = prot.pop("exec", "")
execs = init_spawn_value(val, make_iter)

View file

@ -851,7 +851,7 @@ class TestMenuModule(EvenniaTest):
self.assertEqual(obj.typeclass_path, "evennia.objects.objects.DefaultObject")
self.assertEqual(
obj.tags.get(category=spawner._PROTOTYPE_TAG_CATEGORY), self.test_prot["prototype_key"]
obj.tags.get(category=spawner.PROTOTYPE_TAG_CATEGORY), self.test_prot["prototype_key"]
)
# update helpers