Updated the readme to include tag functionality
This commit is contained in:
parent
79be6a4689
commit
909e34528b
1 changed files with 23 additions and 1 deletions
|
|
@ -50,7 +50,29 @@ class Health(Component):
|
||||||
health = DBField(default=1)
|
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
|
Each typeclass using the ComponentHolderMixin can declare its components
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue