Skip to content

Commit 655c0ae

Browse files
committed
update README
1 parent 2c4cb17 commit 655c0ae

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
- [Internal Fragments](#internal-fragments)
5454
- [Shared Components](#shared-components)
5555
- [Fragment Requirements](#fragment-requirements)
56+
- [Id Names](#id-names)
5657
- [Destruction Policies](#destruction-policies)
5758
- [Custom Component Storages](#custom-component-storages)
5859
- [Garbage Collection](#garbage-collection)
@@ -64,6 +65,7 @@
6465
- [Chunk](#chunk)
6566
- [Builder](#builder)
6667
- [Changelog](#changelog)
68+
- [vX.Y.Z](#vxyz)
6769
- [v1.9.0](#v190)
6870
- [v1.8.0](#v180)
6971
- [v1.7.0](#v170)
@@ -1161,6 +1163,41 @@ local enemy = evolved.builder()
11611163
assert(evolved.has_all(enemy, position, velocity))
11621164
```
11631165

1166+
#### Id Names
1167+
1168+
The library provides a way to assign names to any id using the [`evolved.NAME`](#evolvedname) fragment. This is useful for debugging and development purposes, as it allows you to identify entities or fragments by their names instead of their identifiers. The name of an entity can be retrieved using the [`evolved.name`](#evolvedname-1) function.
1169+
1170+
```lua
1171+
local evolved = require 'evolved'
1172+
1173+
local player = evolved.builder()
1174+
:name('Player')
1175+
:build()
1176+
1177+
assert(evolved.name(player) == 'Player')
1178+
```
1179+
1180+
Names are not unique, so multiple entities can have the same name. Also, the name of an entity can be changed at any time by setting a new name using the [`evolved.NAME`](#evolvedname) fragment as a usual component.
1181+
1182+
You can find entities by their names using the [`evolved.lookup`](#evolvedlookup) and [`evolved.multi_lookup`](#evolvedmulti_lookup) functions. The [`evolved.lookup`](#evolvedlookup) function returns the first entity with the specified name, while the [`evolved.multi_lookup`](#evolvedmulti_lookup) function returns a list of all entities with the specified name.
1183+
1184+
```lua
1185+
local evolved = require 'evolved'
1186+
1187+
local player1 = evolved.builder()
1188+
:name('Player')
1189+
:build()
1190+
1191+
local player2 = evolved.builder()
1192+
:name('Player')
1193+
:build()
1194+
1195+
assert(evolved.lookup('Player') == player1)
1196+
1197+
local player_list, player_count = evolved.multi_lookup('Player')
1198+
assert(player_count == 2 and player_list[1] == player1 and player_list[2] == player2)
1199+
```
1200+
11641201
#### Destruction Policies
11651202

11661203
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.
@@ -1588,6 +1625,10 @@ builder_mt:destruction_policy :: id -> builder
15881625

15891626
## Changelog
15901627

1628+
### vX.Y.Z
1629+
1630+
- Added the new [`evolved.lookup`](#evolvedlookup) and [`evolved.multi_lookup`](#evolvedmulti_lookup) functions that allow finding ids by their names
1631+
15911632
### v1.9.0
15921633

15931634
- Performance improvements of the [`evolved.destroy`](#evolveddestroy) and [`evolved.batch_destroy`](#evolvedbatch_destroy) functions

0 commit comments

Comments
 (0)