Merge branch 'develop' into contrib/tutorial-game

This commit is contained in:
Griatch 2022-03-27 17:23:38 +02:00
commit fa119eefeb
3 changed files with 55 additions and 7 deletions

View file

@ -64,6 +64,7 @@ class ComponentHandler:
"""
self._set_component(component)
self.db_names.append(component.name)
self.host.tags.add(component.name, category="components")
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="components")
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="components")
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="components")
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="components")
@property
def components(self) -> ComponentHandler:
"""

View file

@ -107,3 +107,39 @@ 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="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)
self.char1.components.add(rct)
test_c = self.char1.components.get('test_c')
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="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="components")
handler.remove(rct)
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="components")
handler.remove_by_name("test_c")
assert not self.char1.tags.has(key="test_c", category="components")

View file

@ -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")
@ -1159,7 +1159,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).`
@ -1243,7 +1243,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
@ -1279,7 +1279,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
@ -1349,7 +1349,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
@ -1377,7 +1377,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(