@vworlds/vecs 1.0.19 → 1.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -48
- package/dist/component.d.ts +5 -2
- package/dist/component.js +4 -57
- package/dist/component.js.map +1 -1
- package/dist/component_meta.d.ts +15 -8
- package/dist/component_meta.js +6 -4
- package/dist/component_meta.js.map +1 -1
- package/dist/dsl.d.ts +56 -11
- package/dist/dsl.js +21 -31
- package/dist/dsl.js.map +1 -1
- package/dist/entity/entity.base.d.ts +4 -3
- package/dist/entity/entity.base.js +4 -4
- package/dist/entity/entity.base.js.map +1 -1
- package/dist/entity/entity.components.d.ts +16 -7
- package/dist/entity/entity.components.js +48 -23
- package/dist/entity/entity.components.js.map +1 -1
- package/dist/entity/entity.d.ts +5 -1
- package/dist/entity/entity.js +5 -0
- package/dist/entity/entity.js.map +1 -1
- package/dist/entity/entity.lifecycle.js +25 -25
- package/dist/entity/entity.lifecycle.js.map +1 -1
- package/dist/entity/entity.queries.js +0 -6
- package/dist/entity/entity.queries.js.map +1 -1
- package/dist/entity/entity.relationships.d.ts +1 -1
- package/dist/entity/entity.relationships.js +7 -5
- package/dist/entity/entity.relationships.js.map +1 -1
- package/dist/entity/index.d.ts +1 -1
- package/dist/entity/index.js.map +1 -1
- package/dist/filter.d.ts +6 -6
- package/dist/filter.js +2 -1
- package/dist/filter.js.map +1 -1
- package/dist/index.d.ts +8 -4
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/inject.d.ts +18 -17
- package/dist/inject.js +34 -34
- package/dist/inject.js.map +1 -1
- package/dist/module.d.ts +0 -2
- package/dist/module.js +0 -3
- package/dist/module.js.map +1 -1
- package/dist/modules/relationship_types.d.ts +34 -0
- package/dist/modules/relationship_types.js +36 -0
- package/dist/modules/relationship_types.js.map +1 -0
- package/dist/modules/relationships.d.ts +24 -0
- package/dist/modules/relationships.js +82 -0
- package/dist/modules/relationships.js.map +1 -0
- package/dist/modules/singleton.js +1 -2
- package/dist/modules/singleton.js.map +1 -1
- package/dist/package.json +1 -1
- package/dist/query/callbacks.d.ts +17 -0
- package/dist/query/callbacks.js +113 -0
- package/dist/query/callbacks.js.map +1 -0
- package/dist/query/constants.d.ts +1 -0
- package/dist/query/constants.js +2 -0
- package/dist/query/constants.js.map +1 -0
- package/dist/query/{query.03.tracking.d.ts → group.d.ts} +11 -9
- package/dist/query/group.js +31 -0
- package/dist/query/group.js.map +1 -0
- package/dist/query/grouped_query.d.ts +26 -0
- package/dist/query/grouped_query.js +121 -0
- package/dist/query/grouped_query.js.map +1 -0
- package/dist/query/grouped_query_registry.d.ts +4 -0
- package/dist/query/grouped_query_registry.js +11 -0
- package/dist/query/grouped_query_registry.js.map +1 -0
- package/dist/query/grouping.d.ts +24 -0
- package/dist/query/{query.07.groups.js → grouping.js} +29 -60
- package/dist/query/grouping.js.map +1 -0
- package/dist/query/index.d.ts +6 -6
- package/dist/query/index.js +6 -4
- package/dist/query/index.js.map +1 -1
- package/dist/query/query.d.ts +58 -28
- package/dist/query/query.js +327 -88
- package/dist/query/query.js.map +1 -1
- package/dist/system.d.ts +18 -34
- package/dist/system.js +33 -49
- package/dist/system.js.map +1 -1
- package/dist/terms/all_term.d.ts +2 -6
- package/dist/terms/all_term.js +2 -7
- package/dist/terms/all_term.js.map +1 -1
- package/dist/terms/any_term.d.ts +2 -6
- package/dist/terms/any_term.js +2 -7
- package/dist/terms/any_term.js.map +1 -1
- package/dist/terms/build.d.ts +9 -6
- package/dist/terms/build.js +17 -14
- package/dist/terms/build.js.map +1 -1
- package/dist/terms/component_term.d.ts +3 -3
- package/dist/terms/component_term.js.map +1 -1
- package/dist/terms/composite_build.d.ts +32 -0
- package/dist/terms/composite_build.js +28 -0
- package/dist/terms/composite_build.js.map +1 -0
- package/dist/terms/only_term.d.ts +3 -3
- package/dist/terms/only_term.js.map +1 -1
- package/dist/terms/predicate_term.d.ts +3 -3
- package/dist/terms/predicate_term.js +3 -3
- package/dist/terms/predicate_term.js.map +1 -1
- package/dist/terms/target_term.d.ts +3 -2
- package/dist/terms/target_term.js +11 -17
- package/dist/terms/target_term.js.map +1 -1
- package/dist/util/dense_set.js +1 -1
- package/dist/util/id_pool.d.ts +2 -0
- package/dist/util/id_pool.js +10 -0
- package/dist/util/id_pool.js.map +1 -1
- package/dist/util/ordered_set.js +15 -10
- package/dist/util/ordered_set.js.map +1 -1
- package/dist/world/world.components.d.ts +5 -4
- package/dist/world/world.components.js +16 -16
- package/dist/world/world.components.js.map +1 -1
- package/dist/world/world.entities.d.ts +2 -2
- package/dist/world/world.entities.js.map +1 -1
- package/dist/world/world.js +2 -4
- package/dist/world/world.js.map +1 -1
- package/dist/world/world.modules.d.ts +2 -2
- package/dist/world/world.modules.js +6 -1
- package/dist/world/world.modules.js.map +1 -1
- package/dist/world/world.pools.d.ts +2 -1
- package/dist/world/world.pools.js.map +1 -1
- package/dist/world/world.queries.d.ts +3 -5
- package/dist/world/world.queries.js +11 -8
- package/dist/world/world.queries.js.map +1 -1
- package/package.json +1 -1
- package/dist/query/query.00.base.d.ts +0 -23
- package/dist/query/query.00.base.js +0 -77
- package/dist/query/query.00.base.js.map +0 -1
- package/dist/query/query.01.reactive.d.ts +0 -7
- package/dist/query/query.01.reactive.js +0 -58
- package/dist/query/query.01.reactive.js.map +0 -1
- package/dist/query/query.02.lifecycle.d.ts +0 -6
- package/dist/query/query.02.lifecycle.js +0 -63
- package/dist/query/query.02.lifecycle.js.map +0 -1
- package/dist/query/query.03.tracking.js +0 -31
- package/dist/query/query.03.tracking.js.map +0 -1
- package/dist/query/query.04.callbacks.d.ts +0 -14
- package/dist/query/query.04.callbacks.js +0 -65
- package/dist/query/query.04.callbacks.js.map +0 -1
- package/dist/query/query.05.updates.d.ts +0 -14
- package/dist/query/query.05.updates.js +0 -81
- package/dist/query/query.05.updates.js.map +0 -1
- package/dist/query/query.06.predicate.d.ts +0 -13
- package/dist/query/query.06.predicate.js +0 -40
- package/dist/query/query.06.predicate.js.map +0 -1
- package/dist/query/query.07.groups.d.ts +0 -41
- package/dist/query/query.07.groups.js.map +0 -1
- package/dist/relationship.d.ts +0 -19
- package/dist/relationship.js +0 -18
- package/dist/relationship.js.map +0 -1
package/dist/entity/entity.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { type ComponentType } from "../component_meta.js";
|
|
2
2
|
import { type World } from "../world/index.js";
|
|
3
3
|
import { IdentityEntity } from "./entity.identity.js";
|
|
4
|
-
|
|
4
|
+
/** Entity id assigned by a {@link World}. */
|
|
5
|
+
export type EID = number;
|
|
6
|
+
export type EntityClass<T extends Entity = Entity> = new (world: World, eid: EID, ownComponentClass?: ComponentType) => T;
|
|
5
7
|
/**
|
|
6
8
|
* A game object: a unique numeric id with an arbitrary set of
|
|
7
9
|
* {@link ComponentInstance | components} attached.
|
|
@@ -32,4 +34,6 @@ export type EntityClass<T extends Entity = Entity> = new (world: World, eid: num
|
|
|
32
34
|
* visible immediately.
|
|
33
35
|
*/
|
|
34
36
|
export declare class Entity extends IdentityEntity {
|
|
37
|
+
/** Attach this entity to `parent` through the built-in `ChildOf` relationship. */
|
|
38
|
+
childOf(parent: Entity): this;
|
|
35
39
|
}
|
package/dist/entity/entity.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ChildOf } from "../modules/relationship_types.js";
|
|
1
2
|
import { IdentityEntity } from "./entity.identity.js";
|
|
2
3
|
/**
|
|
3
4
|
* A game object: a unique numeric id with an arbitrary set of
|
|
@@ -29,5 +30,9 @@ import { IdentityEntity } from "./entity.identity.js";
|
|
|
29
30
|
* visible immediately.
|
|
30
31
|
*/
|
|
31
32
|
export class Entity extends IdentityEntity {
|
|
33
|
+
/** Attach this entity to `parent` through the built-in `ChildOf` relationship. */
|
|
34
|
+
childOf(parent) {
|
|
35
|
+
return this.set(ChildOf, { target: parent });
|
|
36
|
+
}
|
|
32
37
|
}
|
|
33
38
|
//# sourceMappingURL=entity.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../src/entity/entity.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"entity.js","sourceRoot":"","sources":["../../src/entity/entity.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAE3D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAWtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,OAAO,MAAO,SAAQ,cAAc;IACxC,kFAAkF;IAC3E,OAAO,CAAC,MAAc;QAC3B,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC/C,CAAC;CACF"}
|
|
@@ -10,15 +10,15 @@ export class Lifecycle extends Components {
|
|
|
10
10
|
if (this._destroyed) {
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
|
-
const
|
|
13
|
+
const entityMeta = this._meta;
|
|
14
14
|
// Mark destroyed up front so a carrier cleanup that re-enters this entity's
|
|
15
15
|
// `_destroy` (possible with exotic relationship topologies under Delete)
|
|
16
16
|
// hits the guard above instead of tearing down twice.
|
|
17
17
|
this._destroyed = true;
|
|
18
|
-
if (
|
|
19
|
-
const selfCarry = this._components.has(
|
|
20
|
-
if (
|
|
21
|
-
if (
|
|
18
|
+
if (entityMeta) {
|
|
19
|
+
const selfCarry = this._components.has(entityMeta.eid) ? 1 : 0;
|
|
20
|
+
if (entityMeta.usageCount > selfCarry) {
|
|
21
|
+
if (entityMeta.onDelete === CleanupPolicy.Throw) {
|
|
22
22
|
// The public `destroy()` already throws when an in-use component is
|
|
23
23
|
// destroyed; reaching here means usage grew between that check and
|
|
24
24
|
// this deferred apply. Abort instead of throwing so a mid-drain
|
|
@@ -27,20 +27,20 @@ export class Lifecycle extends Components {
|
|
|
27
27
|
this._destroyed = false;
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
|
-
this._applyOnDelete(
|
|
30
|
+
this._applyOnDelete(entityMeta, selfCarry);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
const entity = this;
|
|
34
34
|
this.world._notifyEntityDestroyed(entity);
|
|
35
|
-
this._components.forEach((c,
|
|
36
|
-
const
|
|
37
|
-
if (
|
|
38
|
-
this._removeIncoming(c.target,
|
|
35
|
+
this._components.forEach((c, ceid) => {
|
|
36
|
+
const componentMeta = this.world.entity(ceid).meta;
|
|
37
|
+
if (componentMeta.isRelationship) {
|
|
38
|
+
this._removeIncoming(c.target, ceid);
|
|
39
39
|
}
|
|
40
|
-
this.componentBitmask.deleteBit(
|
|
41
|
-
this.world._notifyComponentRemoved(
|
|
42
|
-
|
|
43
|
-
const removeHandlers =
|
|
40
|
+
this.componentBitmask.deleteBit(componentMeta.bitPtr);
|
|
41
|
+
this.world._notifyComponentRemoved(ceid, entity);
|
|
42
|
+
componentMeta._decrementUsage();
|
|
43
|
+
const removeHandlers = componentMeta._onRemoveHandlers;
|
|
44
44
|
if (removeHandlers) {
|
|
45
45
|
removeHandlers.forEach((handler) => handler(entity, c));
|
|
46
46
|
}
|
|
@@ -51,8 +51,8 @@ export class Lifecycle extends Components {
|
|
|
51
51
|
this._events.emit("destroy");
|
|
52
52
|
this._events.removeAllListeners("destroy");
|
|
53
53
|
}
|
|
54
|
-
if (
|
|
55
|
-
this.world._classRegistry.delete(
|
|
54
|
+
if (entityMeta && entityMeta.usageCount === 0 && entityMeta.Class !== Object) {
|
|
55
|
+
this.world._classRegistry.delete(entityMeta.Class);
|
|
56
56
|
}
|
|
57
57
|
this.world._unregisterEntity(entity);
|
|
58
58
|
this._cleanupIncoming();
|
|
@@ -65,10 +65,10 @@ export class Lifecycle extends Components {
|
|
|
65
65
|
* After destruction the entity must not be used.
|
|
66
66
|
*/
|
|
67
67
|
destroy() {
|
|
68
|
-
const
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
const entityMeta = this._meta;
|
|
69
|
+
if (entityMeta &&
|
|
70
|
+
entityMeta.onDelete === CleanupPolicy.Throw &&
|
|
71
|
+
entityMeta.usageCount > (this._components.has(entityMeta.eid) ? 1 : 0)) {
|
|
72
72
|
throw new Error(`Cannot destroy entity ${this.eid}; component eid is still in use`);
|
|
73
73
|
}
|
|
74
74
|
if (this.world.deferred) {
|
|
@@ -87,23 +87,23 @@ export class Lifecycle extends Components {
|
|
|
87
87
|
// `onDelete = Throw`, its `_destroy` safe-aborts and it survives still holding
|
|
88
88
|
// this now-destroyed component eid. This is the same exotic policy-interaction
|
|
89
89
|
// class flagged in `_cleanupIncoming`; left for the relationship/query rework.
|
|
90
|
-
_applyOnDelete(
|
|
91
|
-
const ceid =
|
|
90
|
+
_applyOnDelete(entityMeta, selfCarry) {
|
|
91
|
+
const ceid = entityMeta.eid;
|
|
92
92
|
const carriers = [];
|
|
93
|
-
let remaining =
|
|
93
|
+
let remaining = entityMeta.usageCount - selfCarry;
|
|
94
94
|
this.world.entities.forEach((e) => {
|
|
95
95
|
if (remaining > 0 && e !== this && e._get(ceid) !== undefined) {
|
|
96
96
|
carriers.push(e);
|
|
97
97
|
remaining--;
|
|
98
98
|
}
|
|
99
99
|
});
|
|
100
|
-
const shouldDelete =
|
|
100
|
+
const shouldDelete = entityMeta.onDelete === CleanupPolicy.Delete;
|
|
101
101
|
for (const carrier of carriers) {
|
|
102
102
|
if (shouldDelete) {
|
|
103
103
|
carrier._destroy();
|
|
104
104
|
}
|
|
105
105
|
else {
|
|
106
|
-
carrier._remove(
|
|
106
|
+
carrier._remove(entityMeta);
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.lifecycle.js","sourceRoot":"","sources":["../../src/entity/entity.lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAIrD,OAAO,EAAE,UAAU,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AAE,CAAC;gBACrF,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;gBACjB,SAAS,EAAE,CAAC;YACd,CAAC;QACH,CAAC,CAAC,CAAC;QACH,MAAM,YAAY,GAAG,UAAU,CAAC,QAAQ,KAAK,aAAa,CAAC,MAAM,CAAC;QAClE,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,IAAI,YAAY,EAAE,CAAC;gBACjB,OAAO,CAAC,QAAQ,EAAE,CAAC;YACrB,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -9,12 +9,6 @@ export class Queries extends Base {
|
|
|
9
9
|
this._queries.add(q);
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
/**
|
|
13
|
-
* @internal Return `true` when this entity is currently tracked by `q`.
|
|
14
|
-
*/
|
|
15
|
-
_isInQuery(q) {
|
|
16
|
-
return this._queries.has(q);
|
|
17
|
-
}
|
|
18
12
|
/**
|
|
19
13
|
* @internal Forget query `q` without firing exit callbacks. Called by
|
|
20
14
|
* {@link World} when a {@link Query.destroy} sweeps every entity.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.queries.js","sourceRoot":"","sources":["../../src/entity/entity.queries.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC,MAAM,OAAO,OAAQ,SAAQ,IAAI;IAC/B;;;OAGG;IACI,mBAAmB,CAAC,CAAQ;QACjC,IAAI,CAAC,CAAC,eAAe,EAAE,EAAE,CAAC;YACxB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IAED
|
|
1
|
+
{"version":3,"file":"entity.queries.js","sourceRoot":"","sources":["../../src/entity/entity.queries.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC,MAAM,OAAO,OAAQ,SAAQ,IAAI;IAC/B;;;OAGG;IACI,mBAAmB,CAAC,CAAQ;QACjC,IAAI,CAAC,CAAC,eAAe,EAAE,EAAE,CAAC;YACxB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,WAAW,CAAC,CAAQ;QACzB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACI,sBAAsB,CAAC,CAAQ;QACpC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -3,7 +3,7 @@ import type { Entity } from "./entity.js";
|
|
|
3
3
|
import { Queries } from "./entity.queries.js";
|
|
4
4
|
export declare class Relationships extends Queries {
|
|
5
5
|
/** Return this entity's target through relationship `ref`, if present. */
|
|
6
|
-
parent(
|
|
6
|
+
parent(rel: ComponentRef): Entity | undefined;
|
|
7
7
|
/** Return entities targeting this one through relationship `ref`. */
|
|
8
8
|
children(ref: ComponentRef): ReadonlySet<Entity>;
|
|
9
9
|
}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import { CleanupPolicy } from "../component_meta.js";
|
|
1
|
+
import { CleanupPolicy, } from "../component_meta.js";
|
|
2
2
|
import { ArrayMap } from "../util/array_map.js";
|
|
3
3
|
import { DenseSet } from "../util/dense_set.js";
|
|
4
4
|
import { Queries } from "./entity.queries.js";
|
|
5
5
|
export class Relationships extends Queries {
|
|
6
6
|
/** Return this entity's target through relationship `ref`, if present. */
|
|
7
|
-
parent(
|
|
8
|
-
|
|
7
|
+
parent(rel) {
|
|
8
|
+
const relEid = typeof rel === "number" ? rel : this.world.entity(rel).eid;
|
|
9
|
+
return this._components.get(relEid)?.target;
|
|
9
10
|
}
|
|
10
11
|
/** Return entities targeting this one through relationship `ref`. */
|
|
11
12
|
children(ref) {
|
|
12
|
-
|
|
13
|
+
const relEid = typeof ref === "number" ? ref : this.world.entity(ref).eid;
|
|
14
|
+
return this._incoming?.get(relEid) ?? Relationships._emptyIncoming;
|
|
13
15
|
}
|
|
14
16
|
/**
|
|
15
17
|
* @internal Fast child set lookup by relationship eid — skips ref -> eid
|
|
@@ -37,7 +39,7 @@ export class Relationships extends Queries {
|
|
|
37
39
|
if (!relEntity) {
|
|
38
40
|
return;
|
|
39
41
|
}
|
|
40
|
-
const policy = relEntity.
|
|
42
|
+
const policy = relEntity.meta.onDeleteTarget;
|
|
41
43
|
for (const source of [...sources]) {
|
|
42
44
|
if (policy === CleanupPolicy.Delete) {
|
|
43
45
|
// If source is also an in-use component entity with onDelete Throw,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.relationships.js","sourceRoot":"","sources":["../../src/entity/entity.relationships.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"entity.relationships.js","sourceRoot":"","sources":["../../src/entity/entity.relationships.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,GAId,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,MAAM,OAAO,aAAc,SAAQ,OAAO;IACxC,0EAA0E;IACnE,MAAM,CAAC,GAAiB;QAC7B,MAAM,MAAM,GAAG,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC;QAC1E,OAAQ,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAA8B,EAAE,MAAM,CAAC;IAC5E,CAAC;IAED,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M,MAAM,IAAI,CAAC,GAAG,OAAO,CAAC,EAAE,CAAC;gBAClC,IAAI,MAAM,KAAK,aAAa,CAAC,MAAM,EAAE,CAAC;oBACpC,oEAAoE;oBACpE,6EAA6E;oBAC7E,MAAM,CAAC,OAAO,EAAE,CAAC;gBACnB,CAAC;qBAAM,CAAC;oBACN,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBACxB,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED,gBAAgB;IACN,eAAe,CAAC,MAA0B,EAAE,MAAW;QAC/D,MAAM,OAAO,GAAG,MAAM,EAAE,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;QAC/C,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO;QACT,CAAC;QACD,OAAO,CAAC,MAAM,CAAC,IAAyB,CAAC,CAAC;QAC1C,IAAI,OAAO,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YACvB,MAAO,CAAC,SAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;IAED,gBAAgB;IACN,eAAe,CACvB,IAAmB,EACnB,SAA6B,EAC7B,SAA6B;QAE7B,IAAI,CAAC,IAAI,CAAC,cAAc,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YACpD,OAAO;QACT,CAAC;QACD,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QAC1C,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IACzC,CAAC;CACF"}
|
package/dist/entity/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Entity, type EntityClass } from "./entity.js";
|
|
1
|
+
export { Entity, type EID, type EntityClass } from "./entity.js";
|
|
2
2
|
export { Identity } from "./entity.identity.js";
|
package/dist/entity/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/entity/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/entity/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAA8B,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/filter.d.ts
CHANGED
|
@@ -52,7 +52,7 @@ export declare class Filter<R extends ComponentType[] = []> {
|
|
|
52
52
|
*
|
|
53
53
|
* @param callback - Receives only the matching entity.
|
|
54
54
|
*/
|
|
55
|
-
forEach(callback: (e: Entity) => void):
|
|
55
|
+
forEach(callback: (e: Entity) => void): this;
|
|
56
56
|
/**
|
|
57
57
|
* Walk all current world entities, call `callback` for each one that
|
|
58
58
|
* satisfies the filter's DSL, and inject the requested component instances.
|
|
@@ -68,19 +68,19 @@ export declare class Filter<R extends ComponentType[] = []> {
|
|
|
68
68
|
* @param callback - Receives the entity and a tuple of resolved component
|
|
69
69
|
* instances.
|
|
70
70
|
*/
|
|
71
|
-
forEach<J extends FanInjectTuple>(components: readonly [...J], callback: (e: Entity, resolved: MaybeResolvedInjectTuple<J, R>) => void):
|
|
71
|
+
forEach<J extends FanInjectTuple>(components: readonly [...J], callback: (e: Entity, resolved: MaybeResolvedInjectTuple<J, R>) => void): this;
|
|
72
72
|
/**
|
|
73
73
|
* As above, but pass `Entity` first to make the entity-first signature
|
|
74
74
|
* explicit. Identical behavior to the no-marker form.
|
|
75
75
|
*/
|
|
76
|
-
forEach<J extends FanInjectTuple>(cursor: typeof Entity, components: readonly [...J], callback: (e: Entity, resolved: MaybeResolvedInjectTuple<J, R>) => void):
|
|
76
|
+
forEach<J extends FanInjectTuple>(cursor: typeof Entity, components: readonly [...J], callback: (e: Entity, resolved: MaybeResolvedInjectTuple<J, R>) => void): this;
|
|
77
77
|
/**
|
|
78
78
|
* As above, but pass `Iter` first to receive a reused {@link Iter}
|
|
79
79
|
* cursor instead of the bare entity. The cursor exposes the visited entity
|
|
80
80
|
* (`it.entity`) and, in `it.src`, the source entity each resolved component
|
|
81
|
-
* was read from (the visited entity for direct components, the
|
|
82
|
-
* target for
|
|
81
|
+
* was read from (the visited entity for direct components, the
|
|
82
|
+
* relationship's target entity for ones injected via `target`).
|
|
83
83
|
*/
|
|
84
|
-
forEach<J extends FanInjectTuple>(cursor: typeof Iter, components: readonly [...J], callback: (it: Iter, resolved: MaybeResolvedInjectTuple<J, R>) => void):
|
|
84
|
+
forEach<J extends FanInjectTuple>(cursor: typeof Iter, components: readonly [...J], callback: (it: Iter, resolved: MaybeResolvedInjectTuple<J, R>) => void): this;
|
|
85
85
|
private _forEachMatch;
|
|
86
86
|
}
|
package/dist/filter.js
CHANGED
|
@@ -51,7 +51,7 @@ export class Filter {
|
|
|
51
51
|
this.world.defer(() => {
|
|
52
52
|
this._forEachMatch(callback);
|
|
53
53
|
});
|
|
54
|
-
return;
|
|
54
|
+
return this;
|
|
55
55
|
}
|
|
56
56
|
const useIter = wantsIter(arg0);
|
|
57
57
|
const components = (isCursorMarker(arg0) ? arg1 : arg0);
|
|
@@ -60,6 +60,7 @@ export class Filter {
|
|
|
60
60
|
const invoke = makeInjectedInvoker(this.world, components, useIter, callback);
|
|
61
61
|
this._forEachMatch(invoke);
|
|
62
62
|
});
|
|
63
|
+
return this;
|
|
63
64
|
}
|
|
64
65
|
_forEachMatch(callback) {
|
|
65
66
|
const rootTerm = this.rootTerm;
|
package/dist/filter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../src/filter.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAsC,MAAM,UAAU,CAAC;AAExE,OAAO,EACL,cAAc,EAEd,mBAAmB,EACnB,SAAS,GAIV,MAAM,aAAa,CAAC;AAErB;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Q,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;YAChC,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;gBACrB,QAAQ,CAAC,CAAC,CAAC,CAAC;YACd,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
export { System, type SystemQuery } from "./system.js";
|
|
2
|
-
export { Query, GroupedQuery, Group
|
|
2
|
+
export { Query, GroupedQuery, Group } from "./query/index.js";
|
|
3
|
+
export type { EntityTestFunc, MaybeRequired, QueryDSL } from "./dsl.js";
|
|
4
|
+
export { Iter } from "./inject.js";
|
|
5
|
+
export type { DownInject, FanInjectElement, FanInjectTuple, InjectElement, InjectTuple, MaybeResolvedInjectTuple, RequiredResolvedInjectTuple, TargetInject, } from "./inject.js";
|
|
3
6
|
export { DEFAULT_POOLS, World, type WorldOptions } from "./world/index.js";
|
|
4
7
|
export { Filter } from "./filter.js";
|
|
5
|
-
export { ChildOf,
|
|
6
|
-
export { CleanupPolicy, Component, type ComponentInstance, type ComponentClass, type ComponentMeta, type ComponentRef, } from "./component.js";
|
|
7
|
-
export { Entity, type EntityClass, Identity } from "./entity/index.js";
|
|
8
|
+
export { ChildOf, SilenceSource } from "./modules/relationships.js";
|
|
9
|
+
export { CleanupPolicy, Component, Relationship, type ComponentInstance, type ComponentClass, type ComponentMeta, type ComponentRef, } from "./component.js";
|
|
10
|
+
export { Entity, type EID, type EntityClass, Identity } from "./entity/index.js";
|
|
8
11
|
export { Module } from "./module.js";
|
|
9
12
|
export { IdentityModule } from "./modules/identity.js";
|
|
10
13
|
export { Singleton, SingletonModule } from "./modules/singleton.js";
|
|
14
|
+
export { Traversable, RelationshipsModule } from "./modules/relationships.js";
|
|
11
15
|
export { type IPhase } from "./phase.js";
|
|
12
16
|
export { getDSLKey } from "./dsl.js";
|
|
13
17
|
export { Term, TermEventKind, type TermConsumer } from "./terms/term.js";
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
export { System } from "./system.js";
|
|
2
|
-
export { Query, GroupedQuery, Group
|
|
2
|
+
export { Query, GroupedQuery, Group } from "./query/index.js";
|
|
3
|
+
export { Iter } from "./inject.js";
|
|
3
4
|
export { DEFAULT_POOLS, World } from "./world/index.js";
|
|
4
5
|
export { Filter } from "./filter.js";
|
|
5
|
-
export { ChildOf,
|
|
6
|
-
export { CleanupPolicy, Component, } from "./component.js";
|
|
6
|
+
export { ChildOf, SilenceSource } from "./modules/relationships.js";
|
|
7
|
+
export { CleanupPolicy, Component, Relationship, } from "./component.js";
|
|
7
8
|
export { Entity, Identity } from "./entity/index.js";
|
|
8
9
|
export { Module } from "./module.js";
|
|
9
10
|
export { IdentityModule } from "./modules/identity.js";
|
|
10
11
|
export { Singleton, SingletonModule } from "./modules/singleton.js";
|
|
12
|
+
export { Traversable, RelationshipsModule } from "./modules/relationships.js";
|
|
11
13
|
export { getDSLKey } from "./dsl.js";
|
|
12
14
|
export { Term } from "./terms/term.js";
|
|
13
15
|
export { IntervalTickSource, RateTickSource } from "./timer.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAoB,MAAM,aAAa,CAAC;AACvD,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAoB,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAE9D,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAWnC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAqB,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EACL,aAAa,EACb,SAAS,EACT,YAAY,GAKb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,MAAM,EAA8B,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACjF,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAE9E,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,IAAI,EAAoC,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAoB,MAAM,YAAY,CAAC;AAClF,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,4BAA4B,EAAqB,MAAM,mBAAmB,CAAC"}
|
package/dist/inject.d.ts
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import { type ComponentInstance, type ComponentRef, type ComponentType } from "./component.js";
|
|
2
|
-
import { Entity } from "./entity/index.js";
|
|
2
|
+
import { Entity, type EID } from "./entity/index.js";
|
|
3
3
|
import { type World } from "./world/index.js";
|
|
4
4
|
import { type MaybeRequired } from "./dsl.js";
|
|
5
|
-
export type
|
|
6
|
-
|
|
5
|
+
export type TargetInject<J extends readonly ComponentType[] = readonly ComponentType[]> = {
|
|
6
|
+
target: readonly [ComponentRef, readonly [...J]];
|
|
7
7
|
};
|
|
8
8
|
export type DownInject<J extends readonly ComponentType[] = readonly ComponentType[]> = {
|
|
9
9
|
down: readonly [ComponentRef, readonly [...J]];
|
|
10
10
|
};
|
|
11
|
-
export type InjectElement = ComponentType |
|
|
11
|
+
export type InjectElement = ComponentType | TargetInject;
|
|
12
12
|
export type InjectTuple = readonly InjectElement[];
|
|
13
13
|
export type FanInjectElement = InjectElement | DownInject;
|
|
14
14
|
export type FanInjectTuple = readonly FanInjectElement[];
|
|
15
|
-
export type ResolvedInjectTerm =
|
|
16
|
-
|
|
15
|
+
export type ResolvedInjectTerm = EID | {
|
|
16
|
+
target: readonly [EID, readonly EID[]];
|
|
17
17
|
} | {
|
|
18
|
-
down: readonly [
|
|
18
|
+
down: readonly [EID, readonly EID[]];
|
|
19
19
|
};
|
|
20
20
|
/** Resolves the component instance type for one injected component class. */
|
|
21
21
|
type ResolvedComponentInstance<T> = T extends ComponentType ? InstanceType<T> : never;
|
|
22
22
|
type OptionalResolvedComponentInstances<J extends readonly ComponentType[]> = {
|
|
23
23
|
[K in keyof J]: InstanceType<J[K]> | undefined;
|
|
24
24
|
};
|
|
25
|
-
type MaybeResolvedInjectElement<T, R extends ComponentType[]> = T extends ComponentType ? [MaybeRequired<T, R>] : T extends
|
|
26
|
-
type RequiredResolvedInjectElement<T> = T extends ComponentType ? [ResolvedComponentInstance<T>] : T extends
|
|
25
|
+
type MaybeResolvedInjectElement<T, R extends ComponentType[]> = T extends ComponentType ? [MaybeRequired<T, R>] : T extends TargetInject<infer J> ? OptionalResolvedComponentInstances<J> : T extends DownInject<infer J> ? OptionalResolvedComponentInstances<J> : [];
|
|
26
|
+
type RequiredResolvedInjectElement<T> = T extends ComponentType ? [ResolvedComponentInstance<T>] : T extends TargetInject<infer J> ? OptionalResolvedComponentInstances<J> : T extends DownInject<infer J> ? OptionalResolvedComponentInstances<J> : [];
|
|
27
27
|
export type MaybeResolvedInjectTuple<J extends FanInjectTuple, R extends ComponentType[]> = J extends readonly [infer First, ...infer Rest extends FanInjectTuple] ? [...MaybeResolvedInjectElement<First, R>, ...MaybeResolvedInjectTuple<Rest, R>] : [];
|
|
28
28
|
export type RequiredResolvedInjectTuple<J extends InjectTuple> = J extends readonly [
|
|
29
29
|
infer First,
|
|
@@ -31,16 +31,16 @@ export type RequiredResolvedInjectTuple<J extends InjectTuple> = J extends reado
|
|
|
31
31
|
] ? [...RequiredResolvedInjectElement<First>, ...RequiredResolvedInjectTuple<Rest>] : [];
|
|
32
32
|
export declare function mapInject(world: World, inject: readonly FanInjectElement[]): ResolvedInjectTerm[];
|
|
33
33
|
export declare function injectArity(inject: readonly ResolvedInjectTerm[]): number;
|
|
34
|
-
export declare function getInjected(e: Entity, inject: readonly ResolvedInjectTerm[], requireDirectComponents: boolean, out: (ComponentInstance | undefined)[], exitSnapshot?: Map<
|
|
35
|
-
export declare function getInjectedWithSrc(e: Entity, inject: readonly ResolvedInjectTerm[], out: (ComponentInstance | undefined)[], src: (Entity | undefined)[], requireDirectComponents?: boolean, exitSnapshot?: Map<
|
|
36
|
-
export declare function directInjectEids(inject: readonly ResolvedInjectTerm[]):
|
|
34
|
+
export declare function getInjected(e: Entity, inject: readonly ResolvedInjectTerm[], requireDirectComponents: boolean, out: (ComponentInstance | undefined)[], exitSnapshot?: Map<EID, ComponentInstance>): void;
|
|
35
|
+
export declare function getInjectedWithSrc(e: Entity, inject: readonly ResolvedInjectTerm[], out: (ComponentInstance | undefined)[], src: (Entity | undefined)[], requireDirectComponents?: boolean, exitSnapshot?: Map<EID, ComponentInstance>): void;
|
|
36
|
+
export declare function directInjectEids(inject: readonly ResolvedInjectTerm[]): EID[];
|
|
37
37
|
/**
|
|
38
38
|
* Per-iteration cursor passed to `each` / `forEach` / `enter` / `exit` /
|
|
39
|
-
* `update` / `
|
|
39
|
+
* `update` / `orderBy` callbacks when the caller opts in by passing `Iter` as
|
|
40
40
|
* the first argument:
|
|
41
41
|
*
|
|
42
42
|
* ```ts
|
|
43
|
-
* system.each(Iter, [Body, {
|
|
43
|
+
* system.each(Iter, [Body, { target: [ChildOf, [Position]] }], (it, [body, pos]) => {
|
|
44
44
|
* it.entity; // the visited entity
|
|
45
45
|
* it.src[0]; // entity `body` was read from (the visited entity)
|
|
46
46
|
* it.src[1]; // entity `pos` was read from (the ChildOf target), or undefined
|
|
@@ -57,9 +57,10 @@ export declare class Iter {
|
|
|
57
57
|
entity: Entity;
|
|
58
58
|
/**
|
|
59
59
|
* Source entity for each injected component, in the same order as the
|
|
60
|
-
* resolved tuple: the visited entity for a directly-injected component,
|
|
61
|
-
*
|
|
62
|
-
* entity has no such relationship
|
|
60
|
+
* resolved tuple: the visited entity for a directly-injected component, the
|
|
61
|
+
* relationship target for a `target`-injected one, or the specific child for
|
|
62
|
+
* a `down`-injected one (`undefined` when the entity has no such relationship,
|
|
63
|
+
* target, or — for `down` — when the slot is unfilled).
|
|
63
64
|
*/
|
|
64
65
|
readonly src: (Entity | undefined)[];
|
|
65
66
|
constructor(arity: number);
|
package/dist/inject.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { Entity } from "./entity/index.js";
|
|
2
2
|
import { _resolveRelationship } from "./dsl.js";
|
|
3
|
-
function
|
|
4
|
-
return typeof value === "object" && value !== null && "
|
|
3
|
+
function _isTargetInject(value) {
|
|
4
|
+
return typeof value === "object" && value !== null && "target" in value;
|
|
5
5
|
}
|
|
6
6
|
function _isDownInject(value) {
|
|
7
7
|
return typeof value === "object" && value !== null && "down" in value;
|
|
8
8
|
}
|
|
9
9
|
export function mapInject(world, inject) {
|
|
10
10
|
return inject.map((term) => {
|
|
11
|
-
if (
|
|
11
|
+
if (_isTargetInject(term)) {
|
|
12
12
|
return {
|
|
13
|
-
|
|
13
|
+
target: [
|
|
14
|
+
_resolveRelationship(term.target[0], world),
|
|
15
|
+
term.target[1].map((C) => world.entity(C).eid),
|
|
16
|
+
],
|
|
14
17
|
};
|
|
15
18
|
}
|
|
16
19
|
if (_isDownInject(term)) {
|
|
@@ -27,7 +30,8 @@ export function mapInject(world, inject) {
|
|
|
27
30
|
export function injectArity(inject) {
|
|
28
31
|
let arity = 0;
|
|
29
32
|
inject.forEach((term) => {
|
|
30
|
-
arity +=
|
|
33
|
+
arity +=
|
|
34
|
+
typeof term === "number" ? 1 : "target" in term ? term.target[1].length : term.down[1].length;
|
|
31
35
|
});
|
|
32
36
|
return arity;
|
|
33
37
|
}
|
|
@@ -45,12 +49,12 @@ export function getInjected(e, inject, requireDirectComponents, out, exitSnapsho
|
|
|
45
49
|
if ("down" in term) {
|
|
46
50
|
throw new Error("down injection is only supported in each/forEach");
|
|
47
51
|
}
|
|
48
|
-
const
|
|
49
|
-
? e._get(term.
|
|
52
|
+
const targetEntity = e.has(term.target[0])
|
|
53
|
+
? e._get(term.target[0])?.target
|
|
50
54
|
: undefined;
|
|
51
|
-
term.
|
|
52
|
-
out[outIndex++] =
|
|
53
|
-
?
|
|
55
|
+
term.target[1].forEach((componentEid) => {
|
|
56
|
+
out[outIndex++] = targetEntity?.has(componentEid)
|
|
57
|
+
? targetEntity._get(componentEid)
|
|
54
58
|
: undefined;
|
|
55
59
|
});
|
|
56
60
|
});
|
|
@@ -71,14 +75,12 @@ export function getInjectedWithSrc(e, inject, out, src, requireDirectComponents
|
|
|
71
75
|
if ("down" in term) {
|
|
72
76
|
throw new Error("down injection is only supported in each/forEach");
|
|
73
77
|
}
|
|
74
|
-
const
|
|
75
|
-
? e._get(term.
|
|
78
|
+
const targetEntity = e.has(term.target[0])
|
|
79
|
+
? e._get(term.target[0])?.target
|
|
76
80
|
: undefined;
|
|
77
|
-
term.
|
|
78
|
-
out[outIndex] =
|
|
79
|
-
|
|
80
|
-
: undefined;
|
|
81
|
-
src[outIndex] = target;
|
|
81
|
+
term.target[1].forEach((componentEid) => {
|
|
82
|
+
out[outIndex] = targetEntity?.has(componentEid) ? targetEntity._get(componentEid) : undefined;
|
|
83
|
+
src[outIndex] = targetEntity;
|
|
82
84
|
outIndex++;
|
|
83
85
|
});
|
|
84
86
|
});
|
|
@@ -88,11 +90,11 @@ export function directInjectEids(inject) {
|
|
|
88
90
|
}
|
|
89
91
|
/**
|
|
90
92
|
* Per-iteration cursor passed to `each` / `forEach` / `enter` / `exit` /
|
|
91
|
-
* `update` / `
|
|
93
|
+
* `update` / `orderBy` callbacks when the caller opts in by passing `Iter` as
|
|
92
94
|
* the first argument:
|
|
93
95
|
*
|
|
94
96
|
* ```ts
|
|
95
|
-
* system.each(Iter, [Body, {
|
|
97
|
+
* system.each(Iter, [Body, { target: [ChildOf, [Position]] }], (it, [body, pos]) => {
|
|
96
98
|
* it.entity; // the visited entity
|
|
97
99
|
* it.src[0]; // entity `body` was read from (the visited entity)
|
|
98
100
|
* it.src[1]; // entity `pos` was read from (the ChildOf target), or undefined
|
|
@@ -200,8 +202,8 @@ function _findSingleDownInject(inject) {
|
|
|
200
202
|
slot++;
|
|
201
203
|
return;
|
|
202
204
|
}
|
|
203
|
-
if ("
|
|
204
|
-
slot += term.
|
|
205
|
+
if ("target" in term) {
|
|
206
|
+
slot += term.target[1].length;
|
|
205
207
|
return;
|
|
206
208
|
}
|
|
207
209
|
if (found !== undefined) {
|
|
@@ -215,7 +217,7 @@ function _findSingleDownInject(inject) {
|
|
|
215
217
|
function fillDownInject(child, componentEids, slot, out, src) {
|
|
216
218
|
componentEids.forEach((componentEid, offset) => {
|
|
217
219
|
const outIndex = slot + offset;
|
|
218
|
-
out[outIndex] = child.
|
|
220
|
+
out[outIndex] = child.has(componentEid) ? child._get(componentEid) : undefined;
|
|
219
221
|
if (src) {
|
|
220
222
|
src[outIndex] = child;
|
|
221
223
|
}
|
|
@@ -232,12 +234,12 @@ function getInjectedSkippingDown(e, inject, out) {
|
|
|
232
234
|
outIndex += term.down[1].length;
|
|
233
235
|
return;
|
|
234
236
|
}
|
|
235
|
-
const
|
|
236
|
-
? e._get(term.
|
|
237
|
+
const targetEntity = e.has(term.target[0])
|
|
238
|
+
? e._get(term.target[0])?.target
|
|
237
239
|
: undefined;
|
|
238
|
-
term.
|
|
239
|
-
out[outIndex++] =
|
|
240
|
-
?
|
|
240
|
+
term.target[1].forEach((componentEid) => {
|
|
241
|
+
out[outIndex++] = targetEntity?.has(componentEid)
|
|
242
|
+
? targetEntity._get(componentEid)
|
|
241
243
|
: undefined;
|
|
242
244
|
});
|
|
243
245
|
});
|
|
@@ -255,14 +257,12 @@ function getInjectedWithSrcSkippingDown(e, inject, out, src) {
|
|
|
255
257
|
outIndex += term.down[1].length;
|
|
256
258
|
return;
|
|
257
259
|
}
|
|
258
|
-
const
|
|
259
|
-
? e._get(term.
|
|
260
|
+
const targetEntity = e.has(term.target[0])
|
|
261
|
+
? e._get(term.target[0])?.target
|
|
260
262
|
: undefined;
|
|
261
|
-
term.
|
|
262
|
-
out[outIndex] =
|
|
263
|
-
|
|
264
|
-
: undefined;
|
|
265
|
-
src[outIndex] = target;
|
|
263
|
+
term.target[1].forEach((componentEid) => {
|
|
264
|
+
out[outIndex] = targetEntity?.has(componentEid) ? targetEntity._get(componentEid) : undefined;
|
|
265
|
+
src[outIndex] = targetEntity;
|
|
266
266
|
outIndex++;
|
|
267
267
|
});
|
|
268
268
|
});
|