Compare commits

..

No commits in common. "35b5f04a7c9ca7ef414c5cd4f330277a44cd8145" and "8490dfd294a3932f92667671a9666f0ddb1e7da2" have entirely different histories.

2 changed files with 20 additions and 36 deletions

View file

@ -132,26 +132,26 @@ Component data generally need to adhere to a specific interface, and sometimes r
::: code-group
```luau [luau]
local Transform = world:component()
world:set(Transform, OnAdd, function(entity, id, data)
-- A transform component `id` has been added with `data` to `entity`
world:set(Transform, OnAdd, function(entity)
-- A transform component has been added to an entity
end)
world:set(Transform, OnRemove, function(entity, id)
-- A transform component `id` has been removed from `entity`
world:set(Transform, OnRemove, function(entity)
-- A transform component has been removed from the entity
end)
world:set(Transform, OnChange, function(entity, id, data)
-- A transform component `id` has been changed to `data` on `entity`
world:set(Transform, OnChange, function(entity, value)
-- A transform component has been changed to value on the entity
end)
```
```typescript [typescript]
const Transform = world.component();
world.set(Transform, OnAdd, (entity, id, data) => {
// A transform component `id` has been added with `data` to `entity`
world.set(Transform, OnAdd, (entity) => {
// A transform component has been added to an entity
});
world.set(Transform, OnRemove, (entity, id) => {
// A transform component `id` has been removed from `entity`
world.set(Transform, OnRemove, (entity) => {
// A transform component has been removed from the entity
});
world.set(Transform, OnChange, (entity, id, data) => {
// A transform component `id` has been changed to `data` on `entity`
world.set(Transform, OnChange, (entity, value) => {
// A transform component has been changed to value on the entity
});
```
:::
@ -540,10 +540,10 @@ Test if entity has a relationship wildcard
:::code-group
```luau [luau]
world:has(bob, pair(Eats, jecs.Wildcard))
world:has(bob, pair(Eats, jecs.Wildcard)
```
```typescript [typescript]
world.has(bob, pair(Eats, jecs.Wildcard))
world.has(bob, pair(Eats, jecs.Wildcard)
```
:::
@ -578,7 +578,7 @@ for id in world:query(pair(Eats, Apples)) do
end
```
```typescript [typescript]
for (const [id] of world.query(pair(Eats, Apples))) {
for (const [id] of world.query(pair(Eats, Apples)) {
// ...
}
```
@ -593,7 +593,7 @@ for id in world:query(pair(Eats, jecs.Wildcard)) do
end
```
```typescript [typescript]
for (const [id] of world.query(pair(Eats, jecs.Wildcard))) {
for (const [id] of world.query(pair(Eats, jecs.Wildcard)) {
const food = world.target(id, Eats) // Apples, ...
}
```
@ -608,7 +608,7 @@ for child in world:query(pair(jecs.ChildOf, parent)) do
end
```
```typescript [typescript]
for (const [child] of world.query(pair(jecs.ChildOf, parent))) {
for (const [child] of world.query(pair(jecs.ChildOf, parent)) {
// ...
}
```

22
jecs.d.ts vendored
View file

@ -151,15 +151,6 @@ export class World {
*/
add<C>(entity: Entity, component: undefined extends InferComponent<C> ? C : Id<undefined>): void;
/**
* Installs a hook on the given component.
* @param component The target component.
* @param hook The hook to install.
* @param value The hook callback.
*/
set<T>(component: Entity<T>, hook: StatefulHook, value: (e: Entity<T>, id: Id<T>, data: T) => void): void;
set<T>(component: Entity<T>, hook: StatelessHook, value: (e: Entity<T>, id: Id<T>) => void): void;
/**
* Assigns a value to a component on the given entity.
* @param entity The target entity.
@ -289,16 +280,9 @@ export function pair_first<P, O>(world: World, p: Pair<P, O>): Entity<P>;
*/
export function pair_second<P, O>(world: World, p: Pair<P, O>): Entity<O>;
type StatefulHook = Entity<<T>(e: Entity<T>, id: Id<T>, data: T) => void> & {
readonly __nominal_StatefulHook: unique symbol,
}
type StatelessHook = Entity<<T>(e: Entity<T>, id: Id<T>) => void> & {
readonly __nominal_StatelessHook: unique symbol,
}
export declare const OnAdd: StatefulHook;
export declare const OnRemove: StatelessHook;
export declare const OnChange: StatefulHook;
export declare const OnAdd: Entity<(e: Entity) => void>;
export declare const OnRemove: Entity<(e: Entity) => void>;
export declare const OnChange: Entity<(e: Entity, value: unknown) => void>;
export declare const ChildOf: Tag;
export declare const Wildcard: Entity;
export declare const w: Entity;