mirror of
https://github.com/BlackMATov/evolved.lua.git
synced 2026-09-27 11:07:08 +07:00
update README to reflect the new REQUIRES trait feature
This commit is contained in:
@@ -41,12 +41,13 @@
|
||||
- [Deferred Operations](#deferred-operations)
|
||||
- [Batch Operations](#batch-operations)
|
||||
- [Systems](#systems)
|
||||
- [Advanced Topics](#advanced-topics)
|
||||
- [Predefined Traits](#predefined-traits)
|
||||
- [Fragment Tags](#fragment-tags)
|
||||
- [Fragment Hooks](#fragment-hooks)
|
||||
- [Unique Fragments](#unique-fragments)
|
||||
- [Explicit Fragments](#explicit-fragments)
|
||||
- [Shared Components](#shared-components)
|
||||
- [Fragment Requirements](#fragment-requirements)
|
||||
- [Destruction Policies](#destruction-policies)
|
||||
- [Cheat Sheet](#cheat-sheet)
|
||||
- [Aliases](#aliases)
|
||||
@@ -766,7 +767,7 @@ The prologue and epilogue fragments do not require an explicit query. They will
|
||||
> [!NOTE]
|
||||
> And one more thing about systems. Execution callbacks are called in the [deferred scope](#deferred-operations), which means that all modifying operations inside the callback will be queued and applied after the system has processed all chunks. But prologue and epilogue callbacks are not called in the deferred scope, so all modifying operations inside them will be applied immediately. This is done to avoid confusion and to make it clear that prologue and epilogue callbacks are not part of the chunk processing.
|
||||
|
||||
### Advanced Topics
|
||||
### Predefined Traits
|
||||
|
||||
#### Fragment Tags
|
||||
|
||||
@@ -910,6 +911,35 @@ local enemy2 = evolved.builder()
|
||||
assert(evolved.get(enemy1, position) ~= evolved.get(enemy2, position))
|
||||
```
|
||||
|
||||
#### Fragment Requirements
|
||||
|
||||
Sometimes you want to add additional fragments to an entity when it receives a specific fragment. For example, you might want to add `position` and `velocity` fragments when an entity is given a `physical` fragment. This can be done using the [`evolved.REQUIRES`](#evolvedrequires) fragment trait. This trait expects a list of fragments that will be added to the entity when the fragment is inserted.
|
||||
|
||||
```lua
|
||||
local evolved = require 'evolved'
|
||||
|
||||
local position = evolved.builder()
|
||||
:default(vector2(0, 0))
|
||||
:duplicate(vector2_duplicate)
|
||||
:spawn()
|
||||
|
||||
local velocity = evolved.builder()
|
||||
:default(vector2(0, 0))
|
||||
:duplicate(vector2_duplicate)
|
||||
:spawn()
|
||||
|
||||
local physical = evolved.builder()
|
||||
:tag()
|
||||
:require(position, velocity)
|
||||
:spawn()
|
||||
|
||||
local enemy = evolved.builder()
|
||||
:set(physical)
|
||||
:spawn()
|
||||
|
||||
assert(evolved.has_all(enemy, position, velocity))
|
||||
```
|
||||
|
||||
#### Destruction Policies
|
||||
|
||||
Typically, fragments remain alive for the entire lifetime of the program. However, in some cases, you might want to destroy fragments when they are no longer needed. For example, you can use some runtime entities as fragments for other entities. In this case, you might want to destroy such fragments even while they are still attached to other entities. Since entities cannot have destroyed fragments, a destruction policy must be applied to resolve this. By default, the library will remove the destroyed fragment from all entities that have it.
|
||||
|
||||
Reference in New Issue
Block a user