@vworlds/vecs 1.0.9 → 1.0.11
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/.husky/pre-commit +1 -0
- package/README.md +218 -229
- package/dist/command.d.ts +1 -0
- package/dist/command.js +2 -0
- package/dist/command.js.map +1 -0
- package/dist/component.d.ts +51 -59
- package/dist/component.js +31 -25
- package/dist/component.js.map +1 -1
- package/dist/dsl.d.ts +34 -26
- package/dist/dsl.js +46 -20
- package/dist/dsl.js.map +1 -1
- package/dist/entity.d.ts +110 -127
- package/dist/entity.js +323 -164
- package/dist/entity.js.map +1 -1
- package/dist/filter.d.ts +31 -23
- package/dist/filter.js +41 -32
- package/dist/filter.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/package.json +3 -1
- package/dist/phase.d.ts +5 -28
- package/dist/phase.js +11 -10
- package/dist/phase.js.map +1 -1
- package/dist/query.d.ts +128 -94
- package/dist/query.js +254 -145
- package/dist/query.js.map +1 -1
- package/dist/system.d.ts +64 -128
- package/dist/system.js +156 -149
- package/dist/system.js.map +1 -1
- package/dist/util/array_map.d.ts +4 -55
- package/dist/util/array_map.js +35 -37
- package/dist/util/array_map.js.map +1 -1
- package/dist/util/bitset.d.ts +40 -50
- package/dist/util/bitset.js +76 -62
- package/dist/util/bitset.js.map +1 -1
- package/dist/util/events.d.ts +14 -18
- package/dist/util/events.js +24 -3
- package/dist/util/events.js.map +1 -1
- package/dist/util/ordered_set.d.ts +1 -17
- package/dist/util/ordered_set.js +74 -25
- package/dist/util/ordered_set.js.map +1 -1
- package/dist/world.d.ts +222 -201
- package/dist/world.js +394 -323
- package/dist/world.js.map +1 -1
- package/eslint-rules/internal-underscore.js +60 -0
- package/eslint.config.js +5 -0
- package/package.json +3 -1
package/dist/util/events.d.ts
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Strongly-typed wrapper around `eventemitter3`.
|
|
3
|
+
*
|
|
4
|
+
* The class declared in this file is purely a typings shim — at module load
|
|
5
|
+
* its prototype is swapped out for `EventEmitter` from `eventemitter3` so the
|
|
6
|
+
* concrete behavior is provided by that library, while consumers see typed
|
|
7
|
+
* `on` / `emit` / `off` signatures driven by an `EventMap`.
|
|
8
|
+
*
|
|
9
|
+
* Inspired by the typings in `@yandeu/events`
|
|
10
|
+
* (https://github.com/yandeu/events). The original typings turned out to be
|
|
11
|
+
* usable directly on top of `eventemitter3`.
|
|
12
|
+
*
|
|
13
|
+
* @internal Used only inside the package, to expose typed entity-level events.
|
|
5
14
|
*/
|
|
6
15
|
declare type ValidEventMap<T = any> = T extends {
|
|
7
16
|
[P in keyof T]: (...args: any[]) => void;
|
|
8
17
|
} ? T : never;
|
|
9
18
|
declare type Handler<T extends any | ((...args: any[]) => R), R = any> = T;
|
|
19
|
+
/** Listener signature inferred from an `EventMap` entry. */
|
|
10
20
|
export declare type EventListener<T extends ValidEventMap, K extends EventNames<T>> = T extends string | symbol ? (...args: any[]) => void : K extends keyof T ? Handler<T[K], void> : never;
|
|
11
|
-
|
|
21
|
+
/** Names of the events declared on an `EventMap`. */
|
|
12
22
|
export declare type EventNames<T extends ValidEventMap> = T extends string | symbol ? T : keyof T;
|
|
13
|
-
declare class events<EventMap extends ValidEventMap = any> {
|
|
14
|
-
on<T extends EventNames<EventMap>>(event: T, fn: EventListener<EventMap, T>, context?: any): events<EventMap>;
|
|
15
|
-
emit<T extends EventNames<EventMap>>(event: T, ...args: EventArgs<EventMap, T>): boolean;
|
|
16
|
-
once<T extends EventNames<EventMap>>(event: T, fn: EventListener<EventMap, T>, context?: any): events<EventMap>;
|
|
17
|
-
eventNames(): EventNames<EventMap>[];
|
|
18
|
-
listeners(event: EventNames<EventMap>): any[];
|
|
19
|
-
listenerCount(event: EventNames<EventMap>): any;
|
|
20
|
-
removeListener<T extends EventNames<EventMap>>(event: T, fn?: EventListener<EventMap, T>, context?: any, once?: boolean): this;
|
|
21
|
-
removeAllListeners(event?: EventNames<EventMap>): this;
|
|
22
|
-
off<T extends EventNames<EventMap>>(event: T, fn?: EventListener<EventMap, T> | undefined, context?: any, once?: boolean | undefined): events<EventMap>;
|
|
23
|
-
addListener<T extends EventNames<EventMap>>(event: T, fn: EventListener<EventMap, T>, context?: any): events<EventMap>;
|
|
24
|
-
}
|
|
25
|
-
export declare class Events<EventMap extends ValidEventMap = any> extends events<EventMap> {
|
|
26
|
-
}
|
|
27
23
|
export {};
|
package/dist/util/events.js
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Strongly-typed wrapper around `eventemitter3`.
|
|
3
|
+
*
|
|
4
|
+
* The class declared in this file is purely a typings shim — at module load
|
|
5
|
+
* its prototype is swapped out for `EventEmitter` from `eventemitter3` so the
|
|
6
|
+
* concrete behavior is provided by that library, while consumers see typed
|
|
7
|
+
* `on` / `emit` / `off` signatures driven by an `EventMap`.
|
|
8
|
+
*
|
|
9
|
+
* Inspired by the typings in `@yandeu/events`
|
|
10
|
+
* (https://github.com/yandeu/events). The original typings turned out to be
|
|
11
|
+
* usable directly on top of `eventemitter3`.
|
|
12
|
+
*
|
|
13
|
+
* @internal Used only inside the package, to expose typed entity-level events.
|
|
5
14
|
*/
|
|
6
15
|
import eventEmitter3 from "eventemitter3";
|
|
7
16
|
const { EventEmitter } = eventEmitter3;
|
|
17
|
+
/**
|
|
18
|
+
* Typed event emitter shape. Replaced at runtime by `EventEmitter` from
|
|
19
|
+
* `eventemitter3` (see the assignment below the class body).
|
|
20
|
+
*/
|
|
8
21
|
class events {
|
|
9
22
|
on(event, fn, context) {
|
|
10
23
|
return 0;
|
|
@@ -38,6 +51,14 @@ class events {
|
|
|
38
51
|
}
|
|
39
52
|
}
|
|
40
53
|
events = EventEmitter;
|
|
54
|
+
/**
|
|
55
|
+
* Typed `EventEmitter` parameterised by an `EventMap` of `eventName -> handler`.
|
|
56
|
+
*
|
|
57
|
+
* Constructed lazily by `Entity.events`. Inherits its concrete behavior from
|
|
58
|
+
* `eventemitter3`'s `EventEmitter`.
|
|
59
|
+
*
|
|
60
|
+
* @internal
|
|
61
|
+
*/
|
|
41
62
|
export class Events extends events {
|
|
42
63
|
}
|
|
43
64
|
//# sourceMappingURL=events.js.map
|
package/dist/util/events.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/util/events.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/util/events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,aAAa,MAAM,eAAe,CAAC;AAC1C,MAAM,EAAE,YAAY,EAAE,GAAG,aAAa,CAAC;AA0BvC;;;GAGG;AACH,MAAM,MAAM;IACH,EAAE,CACP,KAAQ,EACR,EAA8B,EAC9B,OAAa;QAEb,OAAO,CAAQ,CAAC;IAClB,CAAC;IACM,IAAI,CAAiC,KAAQ,EAAE,GAAG,IAA4B;QACnF,OAAO,CAAQ,CAAC;IAClB,CAAC;IACM,IAAI,CACT,KAAQ,EACR,EAA8B,EAC9B,OAAa;QAEb,OAAO,CAAQ,CAAC;IAClB,CAAC;IACM,UAAU;QACf,OAAO,CAAQ,CAAC;IAClB,CAAC;IACM,SAAS,CAAC,KAA2B;QAC1C,OAAO,CAAQ,CAAC;IAClB,CAAC;IACM,aAAa,CAAC,KAA2B;QAC9C,OAAO,CAAQ,CAAC;IAClB,CAAC;IACM,cAAc,CACnB,KAAQ,EACR,EAA+B,EAC/B,OAAa,EACb,IAAc;QAEd,OAAO,CAAQ,CAAC;IAClB,CAAC;IACM,kBAAkB,CAAC,KAA4B;QACpD,OAAO,CAAQ,CAAC;IAClB,CAAC;IACM,GAAG,CACR,KAAQ,EACR,EAA2C,EAC3C,OAAa,EACb,IAA0B;QAE1B,OAAO,CAAQ,CAAC;IAClB,CAAC;IACM,WAAW,CAChB,KAAQ,EACR,EAA8B,EAC9B,OAAa;QAEb,OAAO,CAAQ,CAAC;IAClB,CAAC;CACF;AAEA,MAAc,GAAG,YAAY,CAAC;AAE/B;;;;;;;GAOG;AACH,MAAM,OAAO,MAA6C,SAAQ,MAAgB;CAAG"}
|
|
@@ -1,17 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
private items;
|
|
3
|
-
private readonly compare;
|
|
4
|
-
constructor(compare: (a: T, b: T) => number);
|
|
5
|
-
private bisect;
|
|
6
|
-
add(value: T): this;
|
|
7
|
-
has(value: T): boolean;
|
|
8
|
-
delete(value: T): boolean;
|
|
9
|
-
clear(): void;
|
|
10
|
-
get size(): number;
|
|
11
|
-
forEach(callbackfn: (value: T, value2: T, set: Set<T>) => void, thisArg?: unknown): void;
|
|
12
|
-
[Symbol.iterator](): IterableIterator<T>;
|
|
13
|
-
entries(): IterableIterator<[T, T]>;
|
|
14
|
-
keys(): IterableIterator<T>;
|
|
15
|
-
values(): IterableIterator<T>;
|
|
16
|
-
get [Symbol.toStringTag](): string;
|
|
17
|
-
}
|
|
1
|
+
export {};
|
package/dist/util/ordered_set.js
CHANGED
|
@@ -1,14 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `Set<T>` whose iteration order is determined by a comparator instead of
|
|
3
|
+
* insertion order.
|
|
4
|
+
*
|
|
5
|
+
* Backed by a sorted array. Insertions and lookups are `O(log n)` (binary
|
|
6
|
+
* search) plus the cost of an array splice on `add` / `delete`.
|
|
7
|
+
*
|
|
8
|
+
* Used by `Query.sort` to keep matched entities in a user-defined order so
|
|
9
|
+
* iteration in `forEach` and `each` walks them sorted.
|
|
10
|
+
*
|
|
11
|
+
* @internal Used only inside the package.
|
|
12
|
+
*
|
|
13
|
+
* @typeParam T - Element type stored in the set.
|
|
14
|
+
*/
|
|
1
15
|
export class OrderedSet {
|
|
2
16
|
constructor(compare) {
|
|
3
|
-
this.
|
|
4
|
-
this.
|
|
17
|
+
this._items = [];
|
|
18
|
+
this._compare = compare;
|
|
5
19
|
}
|
|
6
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Return the index where `value` should be inserted to keep the array
|
|
22
|
+
* sorted (binary search; mirrors Python's `bisect_left`).
|
|
23
|
+
*/
|
|
24
|
+
_bisect(value) {
|
|
7
25
|
let lo = 0;
|
|
8
|
-
let hi = this.
|
|
26
|
+
let hi = this._items.length;
|
|
9
27
|
while (lo < hi) {
|
|
10
28
|
const mid = (lo + hi) >>> 1;
|
|
11
|
-
if (this.
|
|
29
|
+
if (this._compare(this._items[mid], value) < 0) {
|
|
12
30
|
lo = mid + 1;
|
|
13
31
|
}
|
|
14
32
|
else {
|
|
@@ -17,53 +35,84 @@ export class OrderedSet {
|
|
|
17
35
|
}
|
|
18
36
|
return lo;
|
|
19
37
|
}
|
|
38
|
+
/** Number of elements currently stored. */
|
|
39
|
+
get size() {
|
|
40
|
+
return this._items.length;
|
|
41
|
+
}
|
|
42
|
+
/** Tag used by `Object.prototype.toString` for stringification. */
|
|
43
|
+
get [Symbol.toStringTag]() {
|
|
44
|
+
return "OrderedSet";
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Insert `value` at the position determined by the comparator. No-op when
|
|
48
|
+
* an element compares equal to `value`.
|
|
49
|
+
*
|
|
50
|
+
* @param value - Element to insert.
|
|
51
|
+
*/
|
|
20
52
|
add(value) {
|
|
21
|
-
const i = this.
|
|
22
|
-
if (i < this.
|
|
53
|
+
const i = this._bisect(value);
|
|
54
|
+
if (i < this._items.length && this._compare(this._items[i], value) === 0) {
|
|
23
55
|
return this;
|
|
24
56
|
}
|
|
25
|
-
this.
|
|
57
|
+
this._items.splice(i, 0, value);
|
|
26
58
|
return this;
|
|
27
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Return `true` when an element comparing equal to `value` is in the set.
|
|
62
|
+
*
|
|
63
|
+
* @param value - Element to look up.
|
|
64
|
+
*/
|
|
28
65
|
has(value) {
|
|
29
|
-
const i = this.
|
|
30
|
-
return i < this.
|
|
66
|
+
const i = this._bisect(value);
|
|
67
|
+
return i < this._items.length && this._compare(this._items[i], value) === 0;
|
|
31
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Remove the element comparing equal to `value`. Returns `true` if an
|
|
71
|
+
* element was removed.
|
|
72
|
+
*
|
|
73
|
+
* @param value - Element to remove.
|
|
74
|
+
*/
|
|
32
75
|
delete(value) {
|
|
33
|
-
const i = this.
|
|
34
|
-
if (i < this.
|
|
35
|
-
this.
|
|
76
|
+
const i = this._bisect(value);
|
|
77
|
+
if (i < this._items.length && this._compare(this._items[i], value) === 0) {
|
|
78
|
+
this._items.splice(i, 1);
|
|
36
79
|
return true;
|
|
37
80
|
}
|
|
38
81
|
return false;
|
|
39
82
|
}
|
|
83
|
+
/** Remove every element. */
|
|
40
84
|
clear() {
|
|
41
|
-
this.
|
|
42
|
-
}
|
|
43
|
-
get size() {
|
|
44
|
-
return this.items.length;
|
|
85
|
+
this._items.length = 0;
|
|
45
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Visit each element in sorted order.
|
|
89
|
+
*
|
|
90
|
+
* @param callbackfn - Invoked with `(value, value, set)` for each element
|
|
91
|
+
* (`Set` interface compatibility — both arguments are the same value).
|
|
92
|
+
* @param thisArg - Optional `this` binding for the callback.
|
|
93
|
+
*/
|
|
46
94
|
forEach(callbackfn, thisArg) {
|
|
47
|
-
for (const item of this.
|
|
95
|
+
for (const item of this._items) {
|
|
48
96
|
callbackfn.call(thisArg, item, item, this);
|
|
49
97
|
}
|
|
50
98
|
}
|
|
99
|
+
/** Iterator over elements in sorted order. */
|
|
51
100
|
[Symbol.iterator]() {
|
|
52
|
-
return this.
|
|
101
|
+
return this._items[Symbol.iterator]();
|
|
53
102
|
}
|
|
103
|
+
/** Iterator yielding `[value, value]` pairs in sorted order. */
|
|
54
104
|
*entries() {
|
|
55
|
-
for (const item of this.
|
|
105
|
+
for (const item of this._items) {
|
|
56
106
|
yield [item, item];
|
|
57
107
|
}
|
|
58
108
|
}
|
|
109
|
+
/** Iterator over elements in sorted order. */
|
|
59
110
|
keys() {
|
|
60
|
-
return this.
|
|
111
|
+
return this._items[Symbol.iterator]();
|
|
61
112
|
}
|
|
113
|
+
/** Iterator over elements in sorted order. */
|
|
62
114
|
values() {
|
|
63
|
-
return this.
|
|
64
|
-
}
|
|
65
|
-
get [Symbol.toStringTag]() {
|
|
66
|
-
return "OrderedSet";
|
|
115
|
+
return this._items[Symbol.iterator]();
|
|
67
116
|
}
|
|
68
117
|
}
|
|
69
118
|
//# sourceMappingURL=ordered_set.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ordered_set.js","sourceRoot":"","sources":["../../src/util/ordered_set.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,UAAU;IAIrB,YAAY,OAA+B;
|
|
1
|
+
{"version":3,"file":"ordered_set.js","sourceRoot":"","sources":["../../src/util/ordered_set.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,UAAU;IAIrB,YAAY,OAA+B;QAHnC,WAAM,GAAQ,EAAE,CAAC;QAIvB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACK,OAAO,CAAC,KAAQ;QACtB,IAAI,EAAE,GAAG,CAAC,CAAC;QACX,IAAI,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;QAC5B,OAAO,EAAE,GAAG,EAAE,EAAE;YACd,MAAM,GAAG,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;YAC5B,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE;gBAC9C,EAAE,GAAG,GAAG,GAAG,CAAC,CAAC;aACd;iBAAM;gBACL,EAAE,GAAG,GAAG,CAAC;a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