From 97cc7ff59e5334bd66c2be854a6aca12b8a30532 Mon Sep 17 00:00:00 2001 From: ChrisLR Date: Tue, 22 Mar 2022 09:54:01 -0400 Subject: [PATCH] Updated the readme to include tag functionality --- .../contrib/base_systems/components/README.md | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/evennia/contrib/base_systems/components/README.md b/evennia/contrib/base_systems/components/README.md index 75489e3008..fc594aa036 100644 --- a/evennia/contrib/base_systems/components/README.md +++ b/evennia/contrib/base_systems/components/README.md @@ -50,7 +50,29 @@ class Health(Component): health = DBField(default=1) ``` -Note that default is optional and will default to None +Note that default is optional and will default to None. + +Adding a component to a host will also a similarly named tag with 'components' as category. +A Component named health will appear as key="health, category="components". +This allows you to retrieve objects with specific components by searching with the tag. + +It is also possible to add Component Tags the same way, using TagField. +TagField accepts a default value and can be used to store a single or multiple tags. +Default values are automatically added when the component is added. +Component Tags are cleared from the host if the component is removed. + +Example: +```python +from evennia.contrib.base_systems.components import Component, TagField + +class Health(Component): + resistances = TagField() + vulnerability = TagField(default="fire", enforce_single=True) +``` + +The 'resistances' field in this example can be set to multiple times and it will keep the added tags. +The 'vulnerability' field in this example will override the previous tag with the new one. + Each typeclass using the ComponentHolderMixin can declare its components