update readme and teal defs (VARIANTS fragment)

This commit is contained in:
BlackMATov
2026-01-11 21:08:22 +07:00
parent 52c898f912
commit e396c320ee
2 changed files with 25 additions and 3 deletions

View File

@@ -588,16 +588,22 @@ evolved.set(entity, fragment, 42)
One of the most important features of any ECS library is the ability to process entities by filters or queries. `evolved.lua` provides a simple and efficient way to do this. One of the most important features of any ECS library is the ability to process entities by filters or queries. `evolved.lua` provides a simple and efficient way to do this.
First, you need to create a query that describes which entities you want to process. You can specify fragments you want to include, and fragments you want to exclude. Queries are just identifiers with a special predefined fragments: [`evolved.INCLUDES`](#evolvedincludes) and [`evolved.EXCLUDES`](#evolvedexcludes). These fragments expect a list of fragments as their components. First, you need to create a query that describes which entities you want to process. You can specify fragments you want to include, and fragments you want to exclude. Queries are just identifiers with a special predefined fragments: [`evolved.INCLUDES`](#evolvedincludes), [`evolved.EXCLUDES`](#evolvedexcludes), and [`evolved.VARIANTS`](#evolvedvariants). These fragments expect a list of fragments as their components.
- [`evolved.INCLUDES`](#evolvedincludes) is used to specify fragments that must be present in the entity;
- [`evolved.EXCLUDES`](#evolvedexcludes) is used to specify fragments that must not be present in the entity;
- [`evolved.VARIANTS`](#evolvedvariants) is used to specify fragments where at least one must be present in the entity.
```lua ```lua
local evolved = require 'evolved' local evolved = require 'evolved'
local health, poisoned, resistant = evolved.id(3) local health, poisoned, resistant = evolved.id(3)
local alive, undead = evolved.id(2)
local query = evolved.id() local query = evolved.id()
evolved.set(query, evolved.INCLUDES, { health, poisoned }) evolved.set(query, evolved.INCLUDES, { health, poisoned })
evolved.set(query, evolved.EXCLUDES, { resistant }) evolved.set(query, evolved.EXCLUDES, { resistant })
evolved.set(query, evolved.VARIANTS, { alive, undead })
``` ```
The builder interface can be used to create queries too. It is more convenient to use, because the builder has special methods for including and excluding fragments. Here is a simple example of this: The builder interface can be used to create queries too. It is more convenient to use, because the builder has special methods for including and excluding fragments. Here is a simple example of this:
@@ -606,10 +612,11 @@ The builder interface can be used to create queries too. It is more convenient t
local query = evolved.builder() local query = evolved.builder()
:include(health, poisoned) :include(health, poisoned)
:exclude(resistant) :exclude(resistant)
:variant(alive, undead)
:build() :build()
``` ```
We don't have to set both [`evolved.INCLUDES`](#evolvedincludes) and [`evolved.EXCLUDES`](#evolvedexcludes) fragments, we can even do it without filters at all, then the query will match all chunks in the world. We don't have to set all of [`evolved.INCLUDES`](#evolvedincludes), [`evolved.EXCLUDES`](#evolvedexcludes), and [`evolved.VARIANTS`](#evolvedvariants) fragments, we can even do it without filters at all, then the query will match all chunks in the world.
After the query is created, we are ready to process our filtered by this query entities. You can do this by using the [`evolved.execute`](#evolvedexecute) function. This function takes a query as an argument and returns an iterator that can be used to iterate over all matching with the query chunks. After the query is created, we are ready to process our filtered by this query entities. You can do this by using the [`evolved.execute`](#evolvedexecute) function. This function takes a query as an argument and returns an iterator that can be used to iterate over all matching with the query chunks.
@@ -788,7 +795,7 @@ The [`evolved.process`](#evolvedprocess) function is used to process systems. It
function evolved.process(...) end function evolved.process(...) end
``` ```
If you don't specify a query for the system, the system itself will be treated as a query. This means the system can contain `evolved.INCLUDES` and `evolved.EXCLUDES` fragments, and it will be processed according to them. This is useful for creating systems with unique queries that don't need to be reused in other systems. If you don't specify a query for the system, the system itself will be treated as a query. This means the system can contain `evolved.INCLUDES`, `evolved.EXCLUDES`, and `evolved.VARIANTS` fragments, and it will be processed according to them. This is useful for creating systems with unique queries that don't need to be reused in other systems.
```lua ```lua
local evolved = require 'evolved' local evolved = require 'evolved'
@@ -1198,6 +1205,7 @@ DISABLED :: fragment
INCLUDES :: fragment INCLUDES :: fragment
EXCLUDES :: fragment EXCLUDES :: fragment
VARIANTS :: fragment
REQUIRES :: fragment REQUIRES :: fragment
ON_SET :: fragment ON_SET :: fragment
@@ -1332,6 +1340,7 @@ builder_mt:disabled :: builder
builder_mt:include :: fragment... -> builder builder_mt:include :: fragment... -> builder
builder_mt:exclude :: fragment... -> builder builder_mt:exclude :: fragment... -> builder
builder_mt:variant :: fragment... -> builder
builder_mt:require :: fragment... -> builder builder_mt:require :: fragment... -> builder
builder_mt:on_set :: {entity, fragment, component, component} -> builder builder_mt:on_set :: {entity, fragment, component, component} -> builder
@@ -1354,6 +1363,7 @@ builder_mt:destruction_policy :: id -> builder
### vX.Y.Z ### vX.Y.Z
- Added the new [`evolved.VARIANTS`](#evolvedvariants) query fragment that allows specifying any of multiple fragments in queries
- Added the new [`evolved.process_with`](#evolvedprocess_with) function that allows passing payloads to processing systems - Added the new [`evolved.process_with`](#evolvedprocess_with) function that allows passing payloads to processing systems
### v1.6.0 ### v1.6.0
@@ -1428,6 +1438,8 @@ builder_mt:destruction_policy :: id -> builder
### `evolved.EXCLUDES` ### `evolved.EXCLUDES`
### `evolved.VARIANTS`
### `evolved.REQUIRES` ### `evolved.REQUIRES`
### `evolved.ON_SET` ### `evolved.ON_SET`
@@ -2065,6 +2077,14 @@ function evolved.builder_mt:include(...) end
function evolved.builder_mt:exclude(...) end function evolved.builder_mt:exclude(...) end
``` ```
#### `evolved.builder_mt:variant`
```lua
---@param ... evolved.fragment fragments
---@return evolved.builder builder
function evolved.builder_mt:variant(...) end
```
### `evolved.builder_mt:require` ### `evolved.builder_mt:require`
```lua ```lua

View File

@@ -69,6 +69,7 @@
include: function(self: Builder, ...: Fragment): Builder include: function(self: Builder, ...: Fragment): Builder
exclude: function(self: Builder, ...: Fragment): Builder exclude: function(self: Builder, ...: Fragment): Builder
variant: function(self: Builder, ...: Fragment): Builder
require: function(self: Builder, ...: Fragment): Builder require: function(self: Builder, ...: Fragment): Builder
on_set: function<Component>(self: Builder, on_set: function(Entity, Fragment, ? Component, ? Component)): Builder on_set: function<Component>(self: Builder, on_set: function(Entity, Fragment, ? Component, ? Component)): Builder
@@ -102,6 +103,7 @@
INCLUDES: Fragment INCLUDES: Fragment
EXCLUDES: Fragment EXCLUDES: Fragment
VARIANTS: Fragment
REQUIRES: Fragment REQUIRES: Fragment
ON_SET: Fragment ON_SET: Fragment