@vworlds/vecs 1.0.20 → 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
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { _resolveRelationship } from "../dsl.js";
|
|
2
|
+
import { Entity } from "../entity/index.js";
|
|
3
|
+
import { directInjectEids, getInjected, injectArity, mapInject, } from "../inject.js";
|
|
4
|
+
import { Grouping } from "./grouping.js";
|
|
5
|
+
import { registerGroupedQueryPrototype } from "./grouped_query_registry.js";
|
|
6
|
+
import { Query } from "./query.js";
|
|
7
|
+
const EMPTY_GROUPS = new Map();
|
|
8
|
+
/**
|
|
9
|
+
* A {@link Query} that has been partitioned by {@link Query.groupBy}. Adds the
|
|
10
|
+
* typed group-accessor surface ({@link group}, {@link groups}, etc.) on top of
|
|
11
|
+
* the query's usual reactive membership.
|
|
12
|
+
*
|
|
13
|
+
* Instances are created lazily by {@link Query.groupBy} via
|
|
14
|
+
* `Object.setPrototypeOf`, so callers keep the same configured query object.
|
|
15
|
+
*
|
|
16
|
+
* @typeParam K - The grouping key type produced by the key function (or the
|
|
17
|
+
* relationship target entity, for the relationship form).
|
|
18
|
+
* @typeParam R - Component classes guaranteed present on every matched entity.
|
|
19
|
+
*/
|
|
20
|
+
export class GroupedQuery extends Query {
|
|
21
|
+
get groupCount() {
|
|
22
|
+
return this._grouping?.groups.size ?? 0;
|
|
23
|
+
}
|
|
24
|
+
/** @internal */
|
|
25
|
+
_enter(e) {
|
|
26
|
+
this._grouping.enter(e);
|
|
27
|
+
super._enter(e);
|
|
28
|
+
}
|
|
29
|
+
/** @internal */
|
|
30
|
+
_exit(e) {
|
|
31
|
+
super._exit(e);
|
|
32
|
+
this._grouping.exit(e);
|
|
33
|
+
}
|
|
34
|
+
/** @internal */
|
|
35
|
+
_initialize(arg0, arg1) {
|
|
36
|
+
if (this._grouping !== undefined) {
|
|
37
|
+
throw new Error(`query '${this.name}' is already grouped`);
|
|
38
|
+
}
|
|
39
|
+
let keyOf;
|
|
40
|
+
let watchEids;
|
|
41
|
+
if (typeof arg1 === "function") {
|
|
42
|
+
const components = arg0;
|
|
43
|
+
const inject = mapInject(this.world, components);
|
|
44
|
+
const arity = injectArity(inject);
|
|
45
|
+
const resolved = new Array(arity);
|
|
46
|
+
keyOf = (e) => {
|
|
47
|
+
getInjected(e, inject, false, resolved);
|
|
48
|
+
return arg1(e, resolved);
|
|
49
|
+
};
|
|
50
|
+
watchEids = directInjectEids(inject);
|
|
51
|
+
this._composeGroupMembership(components);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
const relEid = _resolveRelationship(arg0, this.world);
|
|
55
|
+
keyOf = (e) => e.parent(relEid);
|
|
56
|
+
watchEids = [relEid];
|
|
57
|
+
this._composeGroupMembership([arg0]);
|
|
58
|
+
}
|
|
59
|
+
for (const ceid of watchEids) {
|
|
60
|
+
this._watchlistBitmask.add(ceid);
|
|
61
|
+
}
|
|
62
|
+
this.track();
|
|
63
|
+
this._grouping = new Grouping(this.world, keyOf, watchEids);
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
/** @internal */
|
|
67
|
+
_notifyModified(e, ceid, c) {
|
|
68
|
+
super._notifyModified(e, ceid, c);
|
|
69
|
+
// A mutation routed from a silenced source must be invisible to the query,
|
|
70
|
+
// including its group membership: re-keying here would leak the silenced
|
|
71
|
+
// write through `group(...)`. Mirror the base early-return.
|
|
72
|
+
if (this._isSourceSilenced()) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
this._grouping.refresh(e, ceid);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* @internal A grouped query always reacts to component changes: a watched
|
|
79
|
+
* component changing can re-key an entity into a different group, so the
|
|
80
|
+
* host entity must register it in `_queries` regardless of whether a user
|
|
81
|
+
* `update` callback is present.
|
|
82
|
+
*/
|
|
83
|
+
_watchesUpdates() {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
destroy() {
|
|
87
|
+
this._grouping?.clear();
|
|
88
|
+
this._grouping = undefined;
|
|
89
|
+
super.destroy();
|
|
90
|
+
}
|
|
91
|
+
group(key) {
|
|
92
|
+
return this._grouping?.get(key);
|
|
93
|
+
}
|
|
94
|
+
groups() {
|
|
95
|
+
return (this._grouping?.groups.values() ?? EMPTY_GROUPS.values());
|
|
96
|
+
}
|
|
97
|
+
groupKeys() {
|
|
98
|
+
return (this._grouping?.keys() ?? EMPTY_GROUPS.keys());
|
|
99
|
+
}
|
|
100
|
+
onGroupEnter(callback) {
|
|
101
|
+
this._assertConfigurable();
|
|
102
|
+
this._grouping?.setOnGroupEnter(callback);
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
onGroupExit(callback) {
|
|
106
|
+
this._assertConfigurable();
|
|
107
|
+
this._grouping?.setOnGroupExit(callback);
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
_composeGroupMembership(refs) {
|
|
111
|
+
const componentRefs = refs.filter((ref) => typeof ref === "number" || typeof ref === "function" || ref instanceof Entity);
|
|
112
|
+
if (componentRefs.length === 0) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const existing = this._dsl ?? true;
|
|
116
|
+
this._dsl = { all: [existing, ...componentRefs] };
|
|
117
|
+
this._hasExplicitQuery = true;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
registerGroupedQueryPrototype(GroupedQuery.prototype);
|
|
121
|
+
//# sourceMappingURL=grouped_query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grouped_query.js","sourceRoot":"","sources":["../../src/query/grouped_query.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,MAAM,EAAY,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,WAAW,EACX,SA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,IAAI,CAAC;QACxC,IAAI,CAAC,IAAI,GAAG,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,GAAG,aAAa,CAAC,EAAE,CAAC;QAClD,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAChC,CAAC;CACF;AAED,6BAA6B,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
let groupedQueryPrototype;
|
|
2
|
+
export function getGroupedQueryPrototype() {
|
|
3
|
+
if (groupedQueryPrototype === undefined) {
|
|
4
|
+
throw new Error("GroupedQuery has not been registered");
|
|
5
|
+
}
|
|
6
|
+
return groupedQueryPrototype;
|
|
7
|
+
}
|
|
8
|
+
export function registerGroupedQueryPrototype(prototype) {
|
|
9
|
+
groupedQueryPrototype = prototype;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=grouped_query_registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grouped_query_registry.js","sourceRoot":"","sources":["../../src/query/grouped_query_registry.ts"],"names":[],"mappings":"AAEA,IAAI,qBAAwD,CAAC;AAE7D,MAAM,UAAU,wBAAwB;IACtC,IAAI,qBAAqB,KAAK,SAAS,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAC1D,CAAC;IACD,OAAO,qBAAqB,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,6BAA6B,CAAC,SAAgC;IAC5E,qBAAqB,GAAG,SAAS,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Entity, type EID } from "../entity/index.js";
|
|
2
|
+
import { type World } from "../world/index.js";
|
|
3
|
+
import { Group } from "./group.js";
|
|
4
|
+
export declare class Grouping {
|
|
5
|
+
readonly groups: Map<unknown, Group<unknown, []>>;
|
|
6
|
+
private readonly _entityKeys;
|
|
7
|
+
private readonly _keyOf;
|
|
8
|
+
private readonly _watchEids;
|
|
9
|
+
private readonly _world;
|
|
10
|
+
private _onGroupEnter;
|
|
11
|
+
private _onGroupExit;
|
|
12
|
+
constructor(world: World, keyOf: (e: Entity) => unknown, watchEids: Iterable<EID>);
|
|
13
|
+
clear(): void;
|
|
14
|
+
enter(e: Entity): void;
|
|
15
|
+
exit(e: Entity): void;
|
|
16
|
+
get(key: unknown): Group | undefined;
|
|
17
|
+
keys(): IterableIterator<unknown>;
|
|
18
|
+
refresh(e: Entity, ceid: EID): void;
|
|
19
|
+
setOnGroupEnter(callback: (group: Group) => void): void;
|
|
20
|
+
setOnGroupExit(callback: (key: unknown, group: Group) => void): void;
|
|
21
|
+
private _addToBucket;
|
|
22
|
+
private _assign;
|
|
23
|
+
private _removeFromBucket;
|
|
24
|
+
}
|
|
@@ -1,33 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Predicate } from "./query.06.predicate.js";
|
|
3
|
-
export class Group {
|
|
4
|
-
constructor(world, key) {
|
|
5
|
-
this._entities = new Set();
|
|
6
|
-
this._world = world;
|
|
7
|
-
this.key = key;
|
|
8
|
-
}
|
|
9
|
-
get count() {
|
|
10
|
-
return this._entities.size;
|
|
11
|
-
}
|
|
12
|
-
has(e) {
|
|
13
|
-
return this._entities.has(e);
|
|
14
|
-
}
|
|
15
|
-
[Symbol.iterator]() {
|
|
16
|
-
return this._entities[Symbol.iterator]();
|
|
17
|
-
}
|
|
18
|
-
forEach(arg0, arg1, arg2) {
|
|
19
|
-
forEachInjected(this._world, this._entities, arg0, arg1, arg2);
|
|
20
|
-
}
|
|
21
|
-
/** @internal */
|
|
22
|
-
_add(e) {
|
|
23
|
-
this._entities.add(e);
|
|
24
|
-
}
|
|
25
|
-
/** @internal */
|
|
26
|
-
_remove(e) {
|
|
27
|
-
this._entities.delete(e);
|
|
28
|
-
return this._entities.size === 0;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
1
|
+
import { Group } from "./group.js";
|
|
31
2
|
export class Grouping {
|
|
32
3
|
constructor(world, keyOf, watchEids) {
|
|
33
4
|
this.groups = new Map();
|
|
@@ -36,17 +7,9 @@ export class Grouping {
|
|
|
36
7
|
this._keyOf = keyOf;
|
|
37
8
|
this._watchEids = new Set(watchEids);
|
|
38
9
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
keys() {
|
|
43
|
-
return this.groups.keys();
|
|
44
|
-
}
|
|
45
|
-
setOnGroupEnter(callback) {
|
|
46
|
-
this._onGroupEnter = callback;
|
|
47
|
-
}
|
|
48
|
-
setOnGroupExit(callback) {
|
|
49
|
-
this._onGroupExit = callback;
|
|
10
|
+
clear() {
|
|
11
|
+
this.groups.clear();
|
|
12
|
+
this._entityKeys.clear();
|
|
50
13
|
}
|
|
51
14
|
enter(e) {
|
|
52
15
|
this._assign(e, this._keyOf(e));
|
|
@@ -58,15 +21,34 @@ export class Grouping {
|
|
|
58
21
|
}
|
|
59
22
|
this._entityKeys.delete(e);
|
|
60
23
|
}
|
|
61
|
-
|
|
62
|
-
|
|
24
|
+
get(key) {
|
|
25
|
+
return this.groups.get(key);
|
|
26
|
+
}
|
|
27
|
+
keys() {
|
|
28
|
+
return this.groups.keys();
|
|
29
|
+
}
|
|
30
|
+
refresh(e, ceid) {
|
|
31
|
+
if (!this._watchEids.has(ceid)) {
|
|
63
32
|
return;
|
|
64
33
|
}
|
|
65
34
|
this._assign(e, this._keyOf(e));
|
|
66
35
|
}
|
|
67
|
-
|
|
68
|
-
this.
|
|
69
|
-
|
|
36
|
+
setOnGroupEnter(callback) {
|
|
37
|
+
this._onGroupEnter = callback;
|
|
38
|
+
}
|
|
39
|
+
setOnGroupExit(callback) {
|
|
40
|
+
this._onGroupExit = callback;
|
|
41
|
+
}
|
|
42
|
+
_addToBucket(e, key) {
|
|
43
|
+
let group = this.groups.get(key);
|
|
44
|
+
if (group === undefined) {
|
|
45
|
+
group = new Group(this._world, key);
|
|
46
|
+
this.groups.set(key, group);
|
|
47
|
+
group._add(e);
|
|
48
|
+
this._onGroupEnter?.(group);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
group._add(e);
|
|
70
52
|
}
|
|
71
53
|
_assign(e, newKey) {
|
|
72
54
|
const oldKey = this._entityKeys.get(e);
|
|
@@ -83,17 +65,6 @@ export class Grouping {
|
|
|
83
65
|
this._addToBucket(e, newKey);
|
|
84
66
|
this._entityKeys.set(e, newKey);
|
|
85
67
|
}
|
|
86
|
-
_addToBucket(e, key) {
|
|
87
|
-
let group = this.groups.get(key);
|
|
88
|
-
if (group === undefined) {
|
|
89
|
-
group = new Group(this._world, key);
|
|
90
|
-
this.groups.set(key, group);
|
|
91
|
-
group._add(e);
|
|
92
|
-
this._onGroupEnter?.(group);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
group._add(e);
|
|
96
|
-
}
|
|
97
68
|
_removeFromBucket(e, key) {
|
|
98
69
|
const group = this.groups.get(key);
|
|
99
70
|
if (group === undefined) {
|
|
@@ -105,6 +76,4 @@ export class Grouping {
|
|
|
105
76
|
}
|
|
106
77
|
}
|
|
107
78
|
}
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
//# sourceMappingURL=query.07.groups.js.map
|
|
79
|
+
//# sourceMappingURL=grouping.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grouping.js","sourceRoot":"","sources":["../../src/query/grouping.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,MAAM,OAAO,QAAQ;IASnB,YAAmB,KAAY,EAAE,KAA6B,EAAE,SAAwB;QARxE,WAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;QAClC,gBAAW,GAAG,IAAI,GAAG,EAAmB,CAAC;QAQxD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC;IACvC,CAA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,GAAG,CAAC,CAAC;YACxB,IAAI,CAAC,YAAY,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;CACF"}
|
package/dist/query/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export
|
|
5
|
-
export {
|
|
6
|
-
export
|
|
1
|
+
import "./grouped_query.js";
|
|
2
|
+
export { SOURCE_TRACKED_QUERY_ERROR } from "./constants.js";
|
|
3
|
+
export { Group } from "./group.js";
|
|
4
|
+
export { GroupedQuery } from "./grouped_query.js";
|
|
5
|
+
export { Grouping } from "./grouping.js";
|
|
6
|
+
export { Query } from "./query.js";
|
package/dist/query/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
1
|
+
import "./grouped_query.js";
|
|
2
|
+
export { SOURCE_TRACKED_QUERY_ERROR } from "./constants.js";
|
|
3
|
+
export { Group } from "./group.js";
|
|
4
|
+
export { GroupedQuery } from "./grouped_query.js";
|
|
5
|
+
export { Grouping } from "./grouping.js";
|
|
6
|
+
export { Query } from "./query.js";
|
|
5
7
|
//# sourceMappingURL=index.js.map
|
package/dist/query/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/query/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/query/index.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,CAAC;AAE5B,OAAO,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/query/query.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { type ComponentType } from "../component.js";
|
|
1
|
+
import { type ComponentRef, type ComponentType } from "../component.js";
|
|
2
|
+
import { type ExtractSpecsRequired, type QueryDSL, type QuerySpec } from "../dsl.js";
|
|
3
|
+
import { Entity } from "../entity/index.js";
|
|
4
|
+
import { Iter, type FanInjectTuple, type InjectTuple, type MaybeResolvedInjectTuple, type RequiredResolvedInjectTuple } from "../inject.js";
|
|
5
|
+
import { TermConsumer, TermEventKind, type Term } from "../terms/term.js";
|
|
2
6
|
import { type World } from "../world/index.js";
|
|
3
|
-
import {
|
|
4
|
-
import { Groups } from "./query.07.groups.js";
|
|
7
|
+
import { type GroupedQuery } from "./grouped_query.js";
|
|
5
8
|
/**
|
|
6
9
|
* A reactive, always-up-to-date set of entities matching a {@link QueryDSL}
|
|
7
10
|
* predicate.
|
|
@@ -21,33 +24,60 @@ import { Groups } from "./query.07.groups.js";
|
|
|
21
24
|
* you want a reactive entity set without pipeline integration.
|
|
22
25
|
*
|
|
23
26
|
* @typeParam R - Component classes guaranteed present on every matched entity
|
|
24
|
-
* (declared via {@link
|
|
25
|
-
* Components in `R` appear as non-nullable in {@link
|
|
27
|
+
* (declared via {@link with} or the `hint` field of a {@link QueryConfig}).
|
|
28
|
+
* Components in `R` appear as non-nullable in {@link orderBy}, {@link forEach},
|
|
26
29
|
* and {@link update} callback tuples.
|
|
27
30
|
*/
|
|
28
|
-
export declare class Query<R extends ComponentType[] = []>
|
|
31
|
+
export declare class Query<R extends ComponentType[] = []> implements TermConsumer {
|
|
32
|
+
/** True when membership or watched component data changed since the last reset. */
|
|
33
|
+
changed: boolean;
|
|
34
|
+
/** Entity that stores this query as a component and carries query traits. */
|
|
35
|
+
readonly entity: Entity;
|
|
36
|
+
/** Materialized root term that owns membership for this query. */
|
|
37
|
+
rootTerm: Term | undefined;
|
|
29
38
|
constructor(name: string, world: World, track?: boolean);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
39
|
+
/** `true` once this query has been registered with its world. */
|
|
40
|
+
get built(): boolean;
|
|
41
|
+
/** Unique display name; forwards to the backing entity identity. */
|
|
42
|
+
get name(): string | undefined;
|
|
43
|
+
/** World that owns this query; forwards to the backing entity. */
|
|
44
|
+
get world(): World;
|
|
45
|
+
get count(): number;
|
|
46
|
+
[Symbol.iterator](): IterableIterator<Entity>;
|
|
47
|
+
belongs(e: Entity): boolean;
|
|
48
|
+
has(e: Entity): boolean;
|
|
49
|
+
forEach(callback: (e: Entity) => void): this;
|
|
50
|
+
forEach<J extends FanInjectTuple>(components: readonly [...J], callback: (e: Entity, resolved: MaybeResolvedInjectTuple<J, R>) => void): this;
|
|
51
|
+
forEach<J extends FanInjectTuple>(cursor: typeof Entity, components: readonly [...J], callback: (e: Entity, resolved: MaybeResolvedInjectTuple<J, R>) => void): this;
|
|
52
|
+
forEach<J extends FanInjectTuple>(cursor: typeof Iter, components: readonly [...J], callback: (it: Iter, resolved: MaybeResolvedInjectTuple<J, R>) => void): this;
|
|
53
|
+
toString(): string;
|
|
54
|
+
with<const S extends readonly QuerySpec[]>(...specs: [...S]): Query<[...R, ...ExtractSpecsRequired<S>]>;
|
|
55
|
+
without(dsl: QueryDSL): this;
|
|
56
|
+
track(): this;
|
|
57
|
+
orderBy<J extends InjectTuple>(components: readonly [...J], compare: (entityA: Entity, a: MaybeResolvedInjectTuple<J, R>, entityB: Entity, b: MaybeResolvedInjectTuple<J, R>) => number): this;
|
|
58
|
+
orderBy<J extends InjectTuple>(cursor: typeof Entity, components: readonly [...J], compare: (entityA: Entity, a: MaybeResolvedInjectTuple<J, R>, entityB: Entity, b: MaybeResolvedInjectTuple<J, R>) => number): this;
|
|
59
|
+
orderBy<J extends InjectTuple>(cursor: typeof Iter, components: readonly [...J], compare: (a: Iter, aResolved: MaybeResolvedInjectTuple<J, R>, b: Iter, bResolved: MaybeResolvedInjectTuple<J, R>) => number): this;
|
|
60
|
+
cascade(rel: ComponentRef): this;
|
|
61
|
+
cascade(rel: ComponentRef, compare: (a: Entity, b: Entity) => number): this;
|
|
62
|
+
groupBy<K, J extends FanInjectTuple>(components: readonly [...J], key: (e: Entity, resolved: MaybeResolvedInjectTuple<J, R>) => K): GroupedQuery<K, R>;
|
|
63
|
+
groupBy(relationship: ComponentRef): GroupedQuery<Entity, R>;
|
|
64
|
+
ignoreSource(source: QueryDSL | Query): this;
|
|
65
|
+
enter<J extends InjectTuple>(inject: readonly [...J], callback: (e: Entity, injected: RequiredResolvedInjectTuple<J>) => void): this;
|
|
66
|
+
enter<J extends InjectTuple>(cursor: typeof Entity, inject: readonly [...J], callback: (e: Entity, injected: RequiredResolvedInjectTuple<J>) => void): this;
|
|
67
|
+
enter<J extends InjectTuple>(cursor: typeof Iter, inject: readonly [...J], callback: (it: Iter, injected: RequiredResolvedInjectTuple<J>) => void): this;
|
|
68
|
+
enter(callback: (e: Entity) => void): this;
|
|
69
|
+
exit<J extends InjectTuple>(inject: readonly [...J], callback: (e: Entity, injected: RequiredResolvedInjectTuple<J>) => void): this;
|
|
70
|
+
exit<J extends InjectTuple>(cursor: typeof Entity, inject: readonly [...J], callback: (e: Entity, injected: RequiredResolvedInjectTuple<J>) => void): this;
|
|
71
|
+
exit<J extends InjectTuple>(cursor: typeof Iter, inject: readonly [...J], callback: (it: Iter, injected: RequiredResolvedInjectTuple<J>) => void): this;
|
|
72
|
+
exit(callback: (e: Entity) => void): this;
|
|
73
|
+
update<C extends ComponentType>(ComponentClass: C, callback: (e: Entity, c: InstanceType<C>) => void): this;
|
|
74
|
+
update<C extends ComponentType, J extends InjectTuple>(ComponentClass: C, inject: readonly [...J], callback: (e: Entity, c: InstanceType<C>, injected: MaybeResolvedInjectTuple<J, R>) => void): this;
|
|
75
|
+
update<C extends ComponentType, J extends InjectTuple>(cursor: typeof Entity, ComponentClass: C, inject: readonly [...J], callback: (e: Entity, c: InstanceType<C>, injected: MaybeResolvedInjectTuple<J, R>) => void): this;
|
|
76
|
+
update<C extends ComponentType>(cursor: typeof Entity, ComponentClass: C, callback: (e: Entity, c: InstanceType<C>) => void): this;
|
|
77
|
+
update<C extends ComponentType, J extends InjectTuple>(cursor: typeof Iter, ComponentClass: C, inject: readonly [...J], callback: (it: Iter, c: InstanceType<C>, injected: MaybeResolvedInjectTuple<J, R>) => void): this;
|
|
78
|
+
build(): this;
|
|
52
79
|
destroy(): void;
|
|
80
|
+
onTermEvent(kind: TermEventKind, entity: Entity): void;
|
|
81
|
+
private _buildSilenceQuery;
|
|
82
|
+
private _reSortCascade;
|
|
53
83
|
}
|