mirror of
https://github.com/Ukendio/jecs.git
synced 2026-05-13 14:24:14 +00:00
docs for world:targets
This commit is contained in:
parent
e2c56f5420
commit
7824c1aa55
2 changed files with 17 additions and 0 deletions
|
|
@ -6,6 +6,10 @@
|
||||||
Use target when you have queried with a wildcard (e.g. pair(Eats, jecs.Wildcard))
|
Use target when you have queried with a wildcard (e.g. pair(Eats, jecs.Wildcard))
|
||||||
and need the actual target entity for each result. Without an index, the
|
and need the actual target entity for each result. Without an index, the
|
||||||
default is 0 (the first target).
|
default is 0 (the first target).
|
||||||
|
|
||||||
|
world:targets(entity, relation) returns an iterator for all targets of a relation.
|
||||||
|
|
||||||
|
Use targets when you need to get every possible target for all indexes.
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local jecs = require("@jecs")
|
local jecs = require("@jecs")
|
||||||
|
|
@ -35,3 +39,8 @@ print(third == nil) -- true
|
||||||
-- Omitting the index is the same as index 0
|
-- Omitting the index is the same as index 0
|
||||||
local default = world:target(bob, Eats)
|
local default = world:target(bob, Eats)
|
||||||
print(default == Apples) -- true
|
print(default == Apples) -- true
|
||||||
|
|
||||||
|
-- Iterates through all targets
|
||||||
|
for target in world:targets(bob, Eats) do
|
||||||
|
print(target)
|
||||||
|
end
|
||||||
|
|
|
||||||
8
src/jecs.d.ts
vendored
8
src/jecs.d.ts
vendored
|
|
@ -155,6 +155,14 @@ export class World {
|
||||||
*/
|
*/
|
||||||
target(entity: Entity, relation: Entity, index?: number): Entity | undefined;
|
target(entity: Entity, relation: Entity, index?: number): Entity | undefined;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an iterator for all targets of a relationship.
|
||||||
|
* Returns an empty iterator if no matches are found.
|
||||||
|
* @param entity The entity using a relationship pair.
|
||||||
|
* @param relation The "relationship" component/tag
|
||||||
|
*/
|
||||||
|
targets(entity: Entity, relation: Entity): Iter<Entity>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes an entity (and its components/relationships) from the world entirely.
|
* Deletes an entity (and its components/relationships) from the world entirely.
|
||||||
* @param entity The entity to delete.
|
* @param entity The entity to delete.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue