From 15f1eaaac0c528d5d19b18dec498d5800c207d97 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 28 Mar 2020 20:56:01 +0100 Subject: [PATCH] Hide prototypes from CmdScripts output. Resolves #2067 --- evennia/commands/default/system.py | 4 ++++ evennia/prototypes/menus.py | 4 ++-- evennia/prototypes/prototypes.py | 6 +++--- evennia/prototypes/spawner.py | 14 +++++++------- evennia/prototypes/tests.py | 2 +- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/evennia/commands/default/system.py b/evennia/commands/default/system.py index b6ff6ba25c..4124d0423e 100644 --- a/evennia/commands/default/system.py +++ b/evennia/commands/default/system.py @@ -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) diff --git a/evennia/prototypes/menus.py b/evennia/prototypes/menus.py index 854f9e7ced..1024b9d63f 100644 --- a/evennia/prototypes/menus.py +++ b/evennia/prototypes/menus.py @@ -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. diff --git a/evennia/prototypes/prototypes.py b/evennia/prototypes/prototypes.py index 7e76ee515e..fcadc55488 100644 --- a/evennia/prototypes/prototypes.py +++ b/evennia/prototypes/prototypes.py @@ -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): diff --git a/evennia/prototypes/spawner.py b/evennia/prototypes/spawner.py index 5ba3cd4b62..222e4ed49c 100644 --- a/evennia/prototypes/spawner.py +++ b/evennia/prototypes/spawner.py @@ -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) diff --git a/evennia/prototypes/tests.py b/evennia/prototypes/tests.py index 107e2a127f..2c7d5f0426 100644 --- a/evennia/prototypes/tests.py +++ b/evennia/prototypes/tests.py @@ -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