From 2d030b12763183948a534f0273de2cf75ce9fd15 Mon Sep 17 00:00:00 2001 From: Cal Date: Wed, 9 Mar 2022 09:53:39 -0700 Subject: [PATCH 1/4] fix syntax error and docstring typos --- evennia/utils/funcparser.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/evennia/utils/funcparser.py b/evennia/utils/funcparser.py index e0ae1d3eb6..c3455f6774 100644 --- a/evennia/utils/funcparser.py +++ b/evennia/utils/funcparser.py @@ -22,7 +22,7 @@ def _helper(x): # use underscore to NOT make the function available as a callable def funcname(*args, **kwargs): - # this can be accecssed as $funcname(*args, **kwargs) + # this can be accessed as $funcname(*args, **kwargs) # it must always accept *args and **kwargs. ... return something @@ -31,7 +31,7 @@ def funcname(*args, **kwargs): Usage: ```python -from evennia.utils.funcparser +from evennia.utils.funcparser import FuncParser parser = FuncParser("path.to.module_with_callables") result = parser.parse("String with $funcname() in it") @@ -1097,7 +1097,7 @@ def funcparser_callable_you( Examples: This can be used by the say or emote hooks to pass actor stance - strings. This should usually be combined with the $inflect() callable. + strings. This should usually be combined with the $conj() callable. - `With a grin, $you() $conj(jump) at $you(tommy).` @@ -1181,7 +1181,7 @@ def funcparser_callable_conjugate(*args, caller=None, receiver=None, **kwargs): def funcparser_callable_pronoun(*args, caller=None, receiver=None, capitalize=False, **kwargs): """ - Usage: $prop(word, [options]) + Usage: $pron(word, [options]) Adjust pronouns to the expected form. Pronouns are words you use instead of a proper name, such as 'him', 'herself', 'theirs' etc. These look different @@ -1217,7 +1217,7 @@ def funcparser_callable_pronoun(*args, caller=None, receiver=None, capitalize=Fa `male`/`female`/`neutral`/`plural` (plural is considered a gender for this purpose). If no `gender` property/callable is found, `neutral` is used as a fallback. - The pronoun-type default (if not spefified in call) is `subject pronoun`. + The pronoun-type default (if not specified in call) is `subject pronoun`. Args: pronoun (str): Input argument to parsed call. This can be any of the pronouns @@ -1287,7 +1287,7 @@ def funcparser_callable_pronoun(*args, caller=None, receiver=None, capitalize=Fa default_viewpoint = "2nd person" if hasattr(caller, "gender"): - if callable(caller, gender): + if callable(caller.gender): default_gender = caller.gender() else: default_gender = caller.gender @@ -1315,7 +1315,7 @@ def funcparser_callable_pronoun_capitalize( *args, caller=None, receiver=None, capitalize=True, **kwargs ): """ - Usage: $Pron(word) - always maps to a capitalized word. + Usage: $Pron(word, [options]) - always maps to a capitalized word. """ return funcparser_callable_pronoun( From a2fc2f7155c9d9664c3d723ad3a4128a5ef41dc3 Mon Sep 17 00:00:00 2001 From: Narvath <> Date: Sat, 12 Mar 2022 17:09:13 +0100 Subject: [PATCH 2/4] component-contrib:add component name as tag on host --- .../contrib/base_systems/components/holder.py | 12 +++++++ .../contrib/base_systems/components/tests.py | 34 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/evennia/contrib/base_systems/components/holder.py b/evennia/contrib/base_systems/components/holder.py index afcabc95e3..9ea0d69493 100644 --- a/evennia/contrib/base_systems/components/holder.py +++ b/evennia/contrib/base_systems/components/holder.py @@ -64,6 +64,7 @@ class ComponentHandler: """ self._set_component(component) self.db_names.append(component.name) + self.host.tags.add(component.name, category="component") component.at_added(self.host) def add_default(self, name): @@ -84,6 +85,7 @@ class ComponentHandler: new_component = component.default_create(self.host) self._set_component(new_component) self.db_names.append(name) + self.host.tags.add(name, category="component") new_component.at_added(self.host) def remove(self, component): @@ -100,6 +102,7 @@ class ComponentHandler: if component_name in self._loaded_components: component.at_removed(self.host) self.db_names.remove(component_name) + self.host.tags.remove(component_name, category="component") del self._loaded_components[component_name] else: message = f"Cannot remove {component_name} from {self.host.name} as it is not registered." @@ -122,6 +125,7 @@ class ComponentHandler: instance.at_removed(self.host) self.db_names.remove(name) + self.host.tags.remove(name, category="component") del self._loaded_components[name] def get(self, name): @@ -216,6 +220,14 @@ class ComponentHolderMixin(object): self.db.component_names = component_names + def basetype_posthook_setup(self): + """ + Method that add component related tags that were set using ComponentProperty. + """ + super().basetype_posthook_setup() + for component_name in self.db.component_names: + self.tags.add(component_name, category="component") + @property def components(self) -> ComponentHandler: """ diff --git a/evennia/contrib/base_systems/components/tests.py b/evennia/contrib/base_systems/components/tests.py index 23d97a82e3..7a9abd7382 100644 --- a/evennia/contrib/base_systems/components/tests.py +++ b/evennia/contrib/base_systems/components/tests.py @@ -107,3 +107,37 @@ class TestComponents(EvenniaTest): def test_returns_none_with_regular_get_when_no_attribute(self): assert self.char1.cmp.does_not_exist is None + + def test_host_has_class_component_tags(self): + assert self.char1.tags.has(key="test_a", category="component") + assert self.char1.tags.has(key="test_b", category="component") + assert not self.char1.tags.has(key="test_c", category="component") + + def test_host_has_added_component_tags(self): + rct = RuntimeComponentTestC.create(self.char1) + self.char1.components.add(rct) + test_c = self.char1.components.get('test_c') + + assert self.char1.tags.has(key="test_c", category="component") + + def test_host_has_added_default_component_tags(self): + self.char1.components.add_default("test_c") + test_c = self.char1.components.get("test_c") + + assert self.char1.tags.has(key="test_c", category="component") + + def test_host_remove_component_tags(self): + rct = RuntimeComponentTestC.create(self.char1) + handler = self.char1.components + handler.add(rct) + assert self.char1.tags.has(key="test_c", category="component") + handler.remove(rct) + assert not self.char1.tags.has(key="test_c", category="component") + + def test_host_remove_by_name_component_tags(self): + rct = RuntimeComponentTestC.create(self.char1) + handler = self.char1.components + handler.add(rct) + assert self.char1.tags.has(key="test_c", category="component") + handler.remove_by_name("test_c") + assert not self.char1.tags.has(key="test_c", category="component") \ No newline at end of file From cdaf9604c368adeb3fc06089d3597f89d1e3208d Mon Sep 17 00:00:00 2001 From: Narvath <> Date: Sun, 13 Mar 2022 03:02:19 +0100 Subject: [PATCH 3/4] Applying a few corrections --- evennia/contrib/base_systems/components/holder.py | 10 +++++----- evennia/contrib/base_systems/components/tests.py | 14 ++++++++------ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/evennia/contrib/base_systems/components/holder.py b/evennia/contrib/base_systems/components/holder.py index 9ea0d69493..ef0be1a242 100644 --- a/evennia/contrib/base_systems/components/holder.py +++ b/evennia/contrib/base_systems/components/holder.py @@ -64,7 +64,7 @@ class ComponentHandler: """ self._set_component(component) self.db_names.append(component.name) - self.host.tags.add(component.name, category="component") + self.host.tags.add(component.name, category="components") component.at_added(self.host) def add_default(self, name): @@ -85,7 +85,7 @@ class ComponentHandler: new_component = component.default_create(self.host) self._set_component(new_component) self.db_names.append(name) - self.host.tags.add(name, category="component") + self.host.tags.add(name, category="components") new_component.at_added(self.host) def remove(self, component): @@ -102,7 +102,7 @@ class ComponentHandler: if component_name in self._loaded_components: component.at_removed(self.host) self.db_names.remove(component_name) - self.host.tags.remove(component_name, category="component") + self.host.tags.remove(component_name, category="components") del self._loaded_components[component_name] else: message = f"Cannot remove {component_name} from {self.host.name} as it is not registered." @@ -125,7 +125,7 @@ class ComponentHandler: instance.at_removed(self.host) self.db_names.remove(name) - self.host.tags.remove(name, category="component") + self.host.tags.remove(name, category="components") del self._loaded_components[name] def get(self, name): @@ -226,7 +226,7 @@ class ComponentHolderMixin(object): """ super().basetype_posthook_setup() for component_name in self.db.component_names: - self.tags.add(component_name, category="component") + self.tags.add(component_name, category="components") @property def components(self) -> ComponentHandler: diff --git a/evennia/contrib/base_systems/components/tests.py b/evennia/contrib/base_systems/components/tests.py index 7a9abd7382..080571e16e 100644 --- a/evennia/contrib/base_systems/components/tests.py +++ b/evennia/contrib/base_systems/components/tests.py @@ -118,26 +118,28 @@ class TestComponents(EvenniaTest): self.char1.components.add(rct) test_c = self.char1.components.get('test_c') - assert self.char1.tags.has(key="test_c", category="component") + assert self.char1.tags.has(key="test_c", category="components") def test_host_has_added_default_component_tags(self): self.char1.components.add_default("test_c") test_c = self.char1.components.get("test_c") - assert self.char1.tags.has(key="test_c", category="component") + assert self.char1.tags.has(key="test_c", category="components") def test_host_remove_component_tags(self): rct = RuntimeComponentTestC.create(self.char1) handler = self.char1.components handler.add(rct) - assert self.char1.tags.has(key="test_c", category="component") + assert self.char1.tags.has(key="test_c", category="components") handler.remove(rct) - assert not self.char1.tags.has(key="test_c", category="component") + + assert not self.char1.tags.has(key="test_c", category="components") def test_host_remove_by_name_component_tags(self): rct = RuntimeComponentTestC.create(self.char1) handler = self.char1.components handler.add(rct) - assert self.char1.tags.has(key="test_c", category="component") + assert self.char1.tags.has(key="test_c", category="components") handler.remove_by_name("test_c") - assert not self.char1.tags.has(key="test_c", category="component") \ No newline at end of file + + assert not self.char1.tags.has(key="test_c", category="components") \ No newline at end of file From 1117239f698d597b3b7aba52c7e640d7ecffeb79 Mon Sep 17 00:00:00 2001 From: Narvath <> Date: Sun, 13 Mar 2022 03:21:26 +0100 Subject: [PATCH 4/4] Forgot some typo --- evennia/contrib/base_systems/components/tests.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/evennia/contrib/base_systems/components/tests.py b/evennia/contrib/base_systems/components/tests.py index 080571e16e..b9b18f28ba 100644 --- a/evennia/contrib/base_systems/components/tests.py +++ b/evennia/contrib/base_systems/components/tests.py @@ -109,9 +109,9 @@ class TestComponents(EvenniaTest): assert self.char1.cmp.does_not_exist is None def test_host_has_class_component_tags(self): - assert self.char1.tags.has(key="test_a", category="component") - assert self.char1.tags.has(key="test_b", category="component") - assert not self.char1.tags.has(key="test_c", category="component") + assert self.char1.tags.has(key="test_a", category="components") + assert self.char1.tags.has(key="test_b", category="components") + assert not self.char1.tags.has(key="test_c", category="components") def test_host_has_added_component_tags(self): rct = RuntimeComponentTestC.create(self.char1)