jecs/docs/api/world.md

188 lines
3.4 KiB
Markdown
Raw Normal View History

2024-05-27 01:50:46 +00:00
# World
### World.new
2024-05-27 09:45:41 +00:00
World.new(): [World](../api-typesk.md#World)
2024-05-27 01:50:46 +00:00
Create a new world.
#### Returns
A new world
---
### World.entity
2024-05-27 09:45:41 +00:00
World.entity(world: [World](../api-types.md#World)): [Entity](../api-types.md#Entity)
2024-05-27 01:50:46 +00:00
Creates an entity in the world.
#### Returns
A new entiity id
---
### World.target
2024-05-27 09:45:41 +00:00
World.target(world: [World](../api-types.md#World),
entity: [Entity](../api-types.md#Entity),
rel: [Entity](../api-types.md#Entity)): [Entity](../api-types.md#Entity)
2024-05-27 01:50:46 +00:00
Get the target of a relationship.
This will return a target (second element of a pair) of the entity for the specified relationship.
#### Parameters
world The world.
entity The entity.
rel The relationship between the entity and the target.
#### Returns
The first target for the relationship
---
### World.add
2024-05-27 09:45:41 +00:00
World.add(world: [World](../api-types.md#World),
entity: [Entity](../api-types.md#Entity),
id: [Entity](../api-types.md#Entity)): [Entity](..#api-types.md#Entity)
2024-05-27 01:50:46 +00:00
Add a (component) id to an entity.
This operation adds a single (component) id to an entity.
If the entity already has the id, this operation will have no side effects.
#### Parameters
world The world.
entity The entity.
id The id to add.
---
### World.remove
2024-05-27 09:33:59 +00:00
World.remove(world: [World](../api-types#World),
entity: [Entity](../api-types#Entity),
id: [Entity](../api-types#Entity)): [Entity](../api-types#Entity)
2024-05-27 01:50:46 +00:00
Remove a (component) id to an entity.
This operation removes a single (component) id to an entity.
If the entity already has the id, this operation will have no side effects.
#### Parameters
world The world.
entity The entity.
id The id to add.
---
### World.get
2024-05-27 09:45:41 +00:00
World.get(world: [World](../api-types.md#World),
entity: [Entity](../api-types.md#Entity),
id: [Entity](../api-types.md#Entity)): any
2024-05-27 01:50:46 +00:00
Gets the component data.
#### Parameters
world The world.
entity The entity.
id The id of component to get.
#### Returns
The component data, nil if the entity does not have the componnet.
---
### World.set
2024-05-27 09:45:41 +00:00
World.set(world: [World](../api-types.md#World),
entity: [Entity](../api-types.md#Entity),
id: [Entity](../api-types.md#Entity)
2024-05-27 01:50:46 +00:00
data: any)
Set the value of a component.
#### Parameters
world The world.
entity The entity.
id The id of the componment set.
data The data to the component.
---
### World.query
2024-05-27 09:45:41 +00:00
World.query(world: [World](../api-types.md#World),
...: [Entity](../api-types.mdEntity)): [QueryIter](../api-types.md#QueryIter)
2024-05-27 01:50:46 +00:00
Create a QueryIter from the list of filters.
#### Parameters
world The world.
... The collection of components to match entities against.
#### Returns
The query iterator.
---
# Pair
### pair
2024-05-27 18:09:22 +00:00
pair(first: [Entity](../api-types#Entity), second: [Entity](../api-types#Entity)): [Entity](../api-types#Entity)
2024-05-27 01:50:46 +00:00
Creates a composite key.
#### Parameters
first The first element.
second The second element.
#### Returns
The pair of the two elements
---
### IS_PAIR
2024-05-27 09:33:59 +00:00
jecs.IS_PAIR(id: [Entity](../api-types#Entity)): boolean
2024-05-27 01:50:46 +00:00
Creates a composite key.
#### Parameters
id The id to check.
#### Returns
If id is a pair.
---
# Constants
### OnAdd
---
### OnRemove
---
### Rest
---
### OnSet
---
### Wildcard
2024-05-27 09:33:59 +00:00
Matches any id, returns all matches.