@vworlds/vecs 1.0.61 → 1.0.62
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 +4 -1
- package/dist/component.d.ts +64 -3
- package/dist/component.js +84 -0
- package/dist/component.js.map +1 -1
- package/dist/component_meta.d.ts +21 -1
- package/dist/component_meta.js +34 -1
- package/dist/component_meta.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/package.json +1 -1
- package/dist/reflection/component_members.d.ts +1 -0
- package/dist/reflection/component_members.js +42 -0
- package/dist/reflection/component_members.js.map +1 -0
- package/dist/reflection/decorators.d.ts +31 -0
- package/dist/reflection/decorators.js +129 -0
- package/dist/reflection/decorators.js.map +1 -0
- package/dist/reflection/defaults.d.ts +4 -0
- package/dist/reflection/defaults.js +149 -0
- package/dist/reflection/defaults.js.map +1 -0
- package/dist/reflection/member_types.d.ts +32 -0
- package/dist/reflection/member_types.js +86 -0
- package/dist/reflection/member_types.js.map +1 -0
- package/dist/reflection/vecs_struct.d.ts +31 -0
- package/dist/reflection/vecs_struct.js +259 -0
- package/dist/reflection/vecs_struct.js.map +1 -0
- package/dist/world/world.components.d.ts +52 -1
- package/dist/world/world.components.js +124 -1
- package/dist/world/world.components.js.map +1 -1
- package/docs/README.md +3 -0
- package/docs/components.md +14 -5
- package/docs/diagrams.md +13 -0
- package/docs/reflection.md +251 -0
- package/package.json +1 -1
- package/tsconfig.types.json +2 -1
package/README.md
CHANGED
|
@@ -70,6 +70,9 @@ For synchronous world teardown and its allowed call sites, see
|
|
|
70
70
|
For local schema reflection, query [`ComponentDef`](./docs/components.md#reflecting-on-component-definitions)
|
|
71
71
|
to enumerate registered component and module entities, and combine it with `Trait` to enumerate
|
|
72
72
|
explicitly declared policy components.
|
|
73
|
+
To reflect on a component's members, declare their types with `@type` or `component.member(...)`
|
|
74
|
+
and read [`VecsStruct`](./docs/reflection.md); `world.validate` and `world.normalize` check and fix
|
|
75
|
+
instances on demand.
|
|
73
76
|
|
|
74
77
|
System entity callbacks can inject [`Now` and `Delta`](./docs/systems.md#clock-injection) alongside
|
|
75
78
|
components to read the processing tick's timestamp and the system's accumulated tick delta.
|
|
@@ -93,7 +96,7 @@ The full documentation lives in [`docs/`](./docs/README.md). Recommended reading
|
|
|
93
96
|
4. Subsystem guides: [Components and traits](./docs/components.md) · [Entities](./docs/entities.md) ·
|
|
94
97
|
[Systems](./docs/systems.md) · [Queries and filters](./docs/queries-and-filters.md) ·
|
|
95
98
|
[Relationships, edges, targets, and ownership](./docs/relationships.md) · [Modules](./docs/modules.md) ·
|
|
96
|
-
[Subtree snapshots](./docs/snapshots.md)
|
|
99
|
+
[Subtree snapshots](./docs/snapshots.md) · [Component reflection](./docs/reflection.md)
|
|
97
100
|
5. [Design guide](./docs/design-guide.md) — patterns and anti-patterns from real designs.
|
|
98
101
|
|
|
99
102
|
Use [ECS design diagrams](./docs/diagrams.md) for Mermaid schema, instance, and systems views in
|
package/dist/component.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { Entity } from "./entity/index.js";
|
|
2
|
-
import { Relationship, type ComponentInstance, type ComponentType, type HookEvent, type HookHandler, type TargetHandler } from "./component_meta.js";
|
|
2
|
+
import { Relationship, type ComponentInstance, type ComponentType, type HookEvent, type HookHandler, type NormalizeHandler, type TargetHandler, type ValidateHandler } from "./component_meta.js";
|
|
3
|
+
import { type MemberType, type RangeBound } from "./reflection/member_types.js";
|
|
3
4
|
import { type SnapshotCapture, type SnapshotMaterialize, ClonePublic, CustomSnapshot, DontSnapshot } from "./modules/snapshot_types.js";
|
|
4
|
-
export { CleanupPolicy, ComponentMeta, Implements, Relationship, type ComponentClass, type ComponentInstance, type ComponentRef, type ComponentRefArray, type ComponentType, type HookEvent, type HookEventMap, type HookHandler, type TargetHandler, } from "./component_meta.js";
|
|
5
|
+
export { CleanupPolicy, ComponentMeta, Implements, Relationship, type ComponentClass, type ComponentInstance, type ComponentRef, type ComponentRefArray, type ComponentType, type HookEvent, type HookEventMap, type HookHandler, type NormalizeHandler, type TargetHandler, type ValidateHandler, } from "./component_meta.js";
|
|
5
6
|
/**
|
|
6
7
|
* A per-component event map that narrows `add` / `remove` / `set` handlers to
|
|
7
|
-
* the instance type `T` produces,
|
|
8
|
+
* the instance type `T` produces, narrows `validate` / `normalize` handlers to
|
|
9
|
+
* that instance type, and narrows `targetAdd` / `targetRemove` /
|
|
8
10
|
* `targetPolicyAdd` / `targetPolicyRemove` handlers to `T`'s relationship
|
|
9
11
|
* instance type when `T` produces a relationship.
|
|
10
12
|
*/
|
|
@@ -14,6 +16,8 @@ type ComponentEventMap<T extends ComponentType> = {
|
|
|
14
16
|
set: HookHandler<InstanceType<T>>;
|
|
15
17
|
targetAdd: TargetHandler<InstanceType<T> & Relationship>;
|
|
16
18
|
targetRemove: TargetHandler<InstanceType<T> & Relationship>;
|
|
19
|
+
validate: ValidateHandler<InstanceType<T>>;
|
|
20
|
+
normalize: NormalizeHandler<InstanceType<T>>;
|
|
17
21
|
targetPolicyAdd: TargetHandler<InstanceType<T> & Relationship>;
|
|
18
22
|
targetPolicyRemove: TargetHandler<InstanceType<T> & Relationship>;
|
|
19
23
|
policyAdd: HookHandler;
|
|
@@ -30,6 +34,40 @@ export interface CustomSnapshotOptions<T extends ComponentInstance = ComponentIn
|
|
|
30
34
|
* A component entity created by {@link World.component}.
|
|
31
35
|
*/
|
|
32
36
|
export declare class Component<T extends ComponentType = ComponentType> extends Entity {
|
|
37
|
+
/**
|
|
38
|
+
* Declare the human-readable description of the member most recently
|
|
39
|
+
* declared with {@link member}.
|
|
40
|
+
*
|
|
41
|
+
* @throws When no member has been declared on this component yet.
|
|
42
|
+
*/
|
|
43
|
+
description(text: string): this;
|
|
44
|
+
/**
|
|
45
|
+
* Declare a member of this component class and its type, for reflection.
|
|
46
|
+
*
|
|
47
|
+
* Member modifiers apply to the member most recently declared here, as in
|
|
48
|
+
* Flecs: chain `.range(min, max)`, `.description(text)`, `.unit(text)` and
|
|
49
|
+
* `.values([...])` after this call, then `.member(...)` for the next member.
|
|
50
|
+
* The chain stays on this component entity, so it can continue with `.on(…)`
|
|
51
|
+
* or any other component method:
|
|
52
|
+
*
|
|
53
|
+
* ```ts
|
|
54
|
+
* world.component(Position)
|
|
55
|
+
* .member("x", "i32").range(-100, 100).unit("m")
|
|
56
|
+
* .member("y", "i32").range(-100, 100)
|
|
57
|
+
* .on("set", (entity, position) => sync(entity, position));
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* The declaration merges into the class's process-wide {@link VecsStruct}
|
|
61
|
+
* definition, which this component entity carries; repeating an identical
|
|
62
|
+
* declaration in another world is a no-op. Subclasses inherit the member, as
|
|
63
|
+
* they inherit decorator declarations.
|
|
64
|
+
*
|
|
65
|
+
* @param name - The member's property name.
|
|
66
|
+
* @param type - A scalar type name, a nested component class, or an array `[type]`.
|
|
67
|
+
* @returns This component entity, for chaining.
|
|
68
|
+
* @throws When the declaration contradicts the existing definition.
|
|
69
|
+
*/
|
|
70
|
+
member<K extends keyof InstanceType<T> & string>(name: K, type: MemberType): this;
|
|
33
71
|
/**
|
|
34
72
|
* Register a handler for a hook event, with the handler signature narrowed
|
|
35
73
|
* to this component's instance type (for `add` / `remove` / `set`) or its
|
|
@@ -39,6 +77,14 @@ export declare class Component<T extends ComponentType = ComponentType> extends
|
|
|
39
77
|
on<E extends HookEvent>(event: E, handler: ComponentEventMap<T>[E], insert?: boolean): this;
|
|
40
78
|
/** Remove a previously-registered handler by reference. See {@link ComponentMeta.off}. */
|
|
41
79
|
off<E extends HookEvent>(event: E, handler: ComponentEventMap<T>[E]): this;
|
|
80
|
+
/**
|
|
81
|
+
* Declare the inclusive `[min, max]` range of the numeric member most
|
|
82
|
+
* recently declared with {@link member}. Metadata only: nothing checks it on
|
|
83
|
+
* `set`.
|
|
84
|
+
*
|
|
85
|
+
* @throws When no member has been declared on this component yet.
|
|
86
|
+
*/
|
|
87
|
+
range(min: RangeBound, max: RangeBound): this;
|
|
42
88
|
/**
|
|
43
89
|
* Declare how cross-world subtree snapshots capture this component type.
|
|
44
90
|
*
|
|
@@ -69,4 +115,19 @@ export declare class Component<T extends ComponentType = ComponentType> extends
|
|
|
69
115
|
* @returns This component entity, for chaining.
|
|
70
116
|
*/
|
|
71
117
|
snapshotPolicy(policy: typeof CustomSnapshot, options: CustomSnapshotOptions<InstanceType<T>>): this;
|
|
118
|
+
/**
|
|
119
|
+
* Declare the unit of measure, for example `"m"`, of the member most recently
|
|
120
|
+
* declared with {@link member}.
|
|
121
|
+
*
|
|
122
|
+
* @throws When no member has been declared on this component yet.
|
|
123
|
+
*/
|
|
124
|
+
unit(text: string): this;
|
|
125
|
+
/**
|
|
126
|
+
* Declare the allowed values of the `enum` member most recently declared
|
|
127
|
+
* with {@link member}.
|
|
128
|
+
*
|
|
129
|
+
* @throws When no member has been declared on this component yet.
|
|
130
|
+
*/
|
|
131
|
+
values(allowed: readonly number[]): this;
|
|
132
|
+
private _declareCurrent;
|
|
72
133
|
}
|
package/dist/component.js
CHANGED
|
@@ -1,10 +1,59 @@
|
|
|
1
1
|
import { Entity } from "./entity/index.js";
|
|
2
|
+
import { _declareComponentMember } from "./reflection/component_members.js";
|
|
2
3
|
import { CustomSnapshot, _declareSnapshotPolicy, } from "./modules/snapshot_types.js";
|
|
3
4
|
export { CleanupPolicy, ComponentMeta, Implements, Relationship, } from "./component_meta.js";
|
|
4
5
|
/**
|
|
5
6
|
* A component entity created by {@link World.component}.
|
|
6
7
|
*/
|
|
7
8
|
export class Component extends Entity {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
/**
|
|
12
|
+
* @internal The member most recently declared with {@link member} on this
|
|
13
|
+
* component entity, which the member modifiers apply to.
|
|
14
|
+
*/
|
|
15
|
+
this._currentMember = undefined;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Declare the human-readable description of the member most recently
|
|
19
|
+
* declared with {@link member}.
|
|
20
|
+
*
|
|
21
|
+
* @throws When no member has been declared on this component yet.
|
|
22
|
+
*/
|
|
23
|
+
description(text) {
|
|
24
|
+
return this._declareCurrent("description", { description: text });
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Declare a member of this component class and its type, for reflection.
|
|
28
|
+
*
|
|
29
|
+
* Member modifiers apply to the member most recently declared here, as in
|
|
30
|
+
* Flecs: chain `.range(min, max)`, `.description(text)`, `.unit(text)` and
|
|
31
|
+
* `.values([...])` after this call, then `.member(...)` for the next member.
|
|
32
|
+
* The chain stays on this component entity, so it can continue with `.on(…)`
|
|
33
|
+
* or any other component method:
|
|
34
|
+
*
|
|
35
|
+
* ```ts
|
|
36
|
+
* world.component(Position)
|
|
37
|
+
* .member("x", "i32").range(-100, 100).unit("m")
|
|
38
|
+
* .member("y", "i32").range(-100, 100)
|
|
39
|
+
* .on("set", (entity, position) => sync(entity, position));
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* The declaration merges into the class's process-wide {@link VecsStruct}
|
|
43
|
+
* definition, which this component entity carries; repeating an identical
|
|
44
|
+
* declaration in another world is a no-op. Subclasses inherit the member, as
|
|
45
|
+
* they inherit decorator declarations.
|
|
46
|
+
*
|
|
47
|
+
* @param name - The member's property name.
|
|
48
|
+
* @param type - A scalar type name, a nested component class, or an array `[type]`.
|
|
49
|
+
* @returns This component entity, for chaining.
|
|
50
|
+
* @throws When the declaration contradicts the existing definition.
|
|
51
|
+
*/
|
|
52
|
+
member(name, type) {
|
|
53
|
+
_declareComponentMember(this, name, { type });
|
|
54
|
+
this._currentMember = name;
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
8
57
|
/**
|
|
9
58
|
* Register a handler for a hook event, with the handler signature narrowed
|
|
10
59
|
* to this component's instance type (for `add` / `remove` / `set`) or its
|
|
@@ -18,6 +67,16 @@ export class Component extends Entity {
|
|
|
18
67
|
off(event, handler) {
|
|
19
68
|
return super.off(event, handler);
|
|
20
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Declare the inclusive `[min, max]` range of the numeric member most
|
|
72
|
+
* recently declared with {@link member}. Metadata only: nothing checks it on
|
|
73
|
+
* `set`.
|
|
74
|
+
*
|
|
75
|
+
* @throws When no member has been declared on this component yet.
|
|
76
|
+
*/
|
|
77
|
+
range(min, max) {
|
|
78
|
+
return this._declareCurrent("range", { range: [min, max] });
|
|
79
|
+
}
|
|
21
80
|
snapshotPolicy(policy, options) {
|
|
22
81
|
if (policy === CustomSnapshot) {
|
|
23
82
|
if (options?.capture === undefined || options.materialize === undefined) {
|
|
@@ -30,5 +89,30 @@ export class Component extends Entity {
|
|
|
30
89
|
}
|
|
31
90
|
return this;
|
|
32
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Declare the unit of measure, for example `"m"`, of the member most recently
|
|
94
|
+
* declared with {@link member}.
|
|
95
|
+
*
|
|
96
|
+
* @throws When no member has been declared on this component yet.
|
|
97
|
+
*/
|
|
98
|
+
unit(text) {
|
|
99
|
+
return this._declareCurrent("unit", { unit: text });
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Declare the allowed values of the `enum` member most recently declared
|
|
103
|
+
* with {@link member}.
|
|
104
|
+
*
|
|
105
|
+
* @throws When no member has been declared on this component yet.
|
|
106
|
+
*/
|
|
107
|
+
values(allowed) {
|
|
108
|
+
return this._declareCurrent("values", { values: allowed });
|
|
109
|
+
}
|
|
110
|
+
_declareCurrent(modifier, declaration) {
|
|
111
|
+
if (this._currentMember === undefined) {
|
|
112
|
+
throw new Error(`${modifier}() on ${this.meta.Class.name}: call .member(name, type) first`);
|
|
113
|
+
}
|
|
114
|
+
_declareComponentMember(this, this._currentMember, declaration);
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
33
117
|
}
|
|
34
118
|
//# sourceMappingURL=component.js.map
|
package/dist/component.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","sourceRoot":"","sources":["../src/component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"component.js","sourceRoot":"","sources":["../src/component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAY3C,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAG5E,OAAO,EAKL,cAAc,EAEd,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,aAAa,EACb,aAAa,EACb,UAAU,EACV,YAAY,GAYb,MAAM,qBAAqB,CAAC;AA+B7B;;GAEG;AACH,MAAM,OAAO,SAAmD,SAAQ,MAAM;IAA9E;;QACE;;;WAGG;QACK,mBAAc,GAAuB,SAAS,CAAC;IAuJzD,CAAC;IArJC;;;;;OAKG;IACI,WAAW,CAAC,IAAY;QAC7B,OAAO,IAAI,CAAC,eAAe,CAAC,aAAa,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;IACpE,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACI,MAAM,CAA2C,IAAO,EAAE,IAAgB;QAC/E,uBAAuB,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;QAC9C,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACa,EAAE,CAChB,KAAQ,EACR,OAAgC,EAChC,MAAM,GAAG,KAAK;QAEd,OAAO,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,OAA0B,EAAE,MAAM,CAAC,CAAC;IAC7D,CAAC;IAED,0FAA0F;IAC1E,GAAG,CAAsB,KAAQ,EAAE,OAAgC;QACjF,OAAO,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,OAA0B,CAAC,CAAC;IACtD,CAAC;IAED;;;;;;OAMG;IACI,KAAK,C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;QAChE,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
package/dist/component_meta.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BitPtr } from "./util/bitset.js";
|
|
2
2
|
import type { EID, Entity, EntityClass } from "./entity/index.js";
|
|
3
|
+
import type { ValidationResult } from "./reflection/defaults.js";
|
|
3
4
|
export declare enum CleanupPolicy {
|
|
4
5
|
Throw = "throw",
|
|
5
6
|
Remove = "remove",
|
|
@@ -13,6 +14,16 @@ export declare abstract class Relationship {
|
|
|
13
14
|
export type TargetHandler<C extends Relationship = Relationship> = (source: Entity, relationship: C, target: Entity) => void;
|
|
14
15
|
/** Callback fired for a component lifecycle event. */
|
|
15
16
|
export type HookHandler<C extends ComponentInstance = ComponentInstance> = (entity: Entity, component: C) => void;
|
|
17
|
+
/**
|
|
18
|
+
* `validate` hook: return `true` when `component` is valid, otherwise the
|
|
19
|
+
* violations (a message or a list of them). Run by {@link World.validate}.
|
|
20
|
+
*/
|
|
21
|
+
export type ValidateHandler<C extends ComponentInstance = ComponentInstance> = (component: C) => ValidationResult;
|
|
22
|
+
/**
|
|
23
|
+
* `normalize` hook: modify `component` in place so it becomes valid. Run by
|
|
24
|
+
* {@link World.normalize}.
|
|
25
|
+
*/
|
|
26
|
+
export type NormalizeHandler<C extends ComponentInstance = ComponentInstance> = (component: C) => void;
|
|
16
27
|
/** A component instance. Components are plain objects created with a no-arg constructor. */
|
|
17
28
|
export type ComponentInstance = object;
|
|
18
29
|
/**
|
|
@@ -34,6 +45,10 @@ export interface HookEventMap {
|
|
|
34
45
|
targetAdd: TargetHandler;
|
|
35
46
|
/** Fired after a relationship edge is removed. Relationship metas only. */
|
|
36
47
|
targetRemove: TargetHandler;
|
|
48
|
+
/** Checks a component; run by {@link World.validate}, never on `set`. */
|
|
49
|
+
validate: ValidateHandler;
|
|
50
|
+
/** Fixes a component in place; run by {@link World.normalize}, never on `set`. */
|
|
51
|
+
normalize: NormalizeHandler;
|
|
37
52
|
}
|
|
38
53
|
/** Event names accepted by {@link ComponentMeta.on} / {@link ComponentMeta.off}. */
|
|
39
54
|
export type HookEvent = keyof HookEventMap;
|
|
@@ -104,8 +119,13 @@ export declare class ComponentMeta {
|
|
|
104
119
|
* events require this meta to be a relationship; registering one on a
|
|
105
120
|
* non-relationship meta throws at registration time.
|
|
106
121
|
*
|
|
122
|
+
* `validate` and `normalize` hooks run only through {@link World.validate},
|
|
123
|
+
* {@link World.isValid} and {@link World.normalize}, never on `set`. The first
|
|
124
|
+
* one registered replaces the default hook derived from member metadata.
|
|
125
|
+
*
|
|
107
126
|
* @param event - One of `add`, `remove`, `set`, `targetAdd`, `targetRemove`,
|
|
108
|
-
* `policyAdd`, `policyRemove`, `targetPolicyAdd`,
|
|
127
|
+
* `validate`, `normalize`, `policyAdd`, `policyRemove`, `targetPolicyAdd`,
|
|
128
|
+
* `targetPolicyRemove`.
|
|
109
129
|
* @param handler - Handler whose signature is constrained by `event`.
|
|
110
130
|
* @param insert - When `true`, prepend the handler; when `false` (default), append.
|
|
111
131
|
* @returns This meta, for chaining.
|
package/dist/component_meta.js
CHANGED
|
@@ -247,6 +247,14 @@ export class ComponentMeta {
|
|
|
247
247
|
this._onTargetPolicyRemove = undefined;
|
|
248
248
|
/** @internal Handlers fired when a component's data is set or modified. */
|
|
249
249
|
this._onSet = undefined;
|
|
250
|
+
/** @internal `validate` hooks, run in order by `World.validate`. */
|
|
251
|
+
this._onValidate = undefined;
|
|
252
|
+
/** @internal `normalize` hooks, run in order by `World.normalize`. */
|
|
253
|
+
this._onNormalize = undefined;
|
|
254
|
+
/** @internal Whether `_onValidate` holds only the metadata-derived default. */
|
|
255
|
+
this._validateIsDefault = false;
|
|
256
|
+
/** @internal Whether `_onNormalize` holds only the metadata-derived default. */
|
|
257
|
+
this._normalizeIsDefault = false;
|
|
250
258
|
/**
|
|
251
259
|
* @internal Reverse index of entities currently carrying this component eid.
|
|
252
260
|
*
|
|
@@ -284,8 +292,13 @@ export class ComponentMeta {
|
|
|
284
292
|
* events require this meta to be a relationship; registering one on a
|
|
285
293
|
* non-relationship meta throws at registration time.
|
|
286
294
|
*
|
|
295
|
+
* `validate` and `normalize` hooks run only through {@link World.validate},
|
|
296
|
+
* {@link World.isValid} and {@link World.normalize}, never on `set`. The first
|
|
297
|
+
* one registered replaces the default hook derived from member metadata.
|
|
298
|
+
*
|
|
287
299
|
* @param event - One of `add`, `remove`, `set`, `targetAdd`, `targetRemove`,
|
|
288
|
-
* `policyAdd`, `policyRemove`, `targetPolicyAdd`,
|
|
300
|
+
* `validate`, `normalize`, `policyAdd`, `policyRemove`, `targetPolicyAdd`,
|
|
301
|
+
* `targetPolicyRemove`.
|
|
289
302
|
* @param handler - Handler whose signature is constrained by `event`.
|
|
290
303
|
* @param insert - When `true`, prepend the handler; when `false` (default), append.
|
|
291
304
|
* @returns This meta, for chaining.
|
|
@@ -309,6 +322,20 @@ export class ComponentMeta {
|
|
|
309
322
|
this._requireRelationship(event);
|
|
310
323
|
this._onTargetRemove = _installHook(this._onTargetRemove, handler, insert);
|
|
311
324
|
break;
|
|
325
|
+
case "validate":
|
|
326
|
+
if (this._validateIsDefault) {
|
|
327
|
+
this._onValidate = undefined;
|
|
328
|
+
this._validateIsDefault = false;
|
|
329
|
+
}
|
|
330
|
+
this._onValidate = _installHook(this._onValidate, handler, insert);
|
|
331
|
+
break;
|
|
332
|
+
case "normalize":
|
|
333
|
+
if (this._normalizeIsDefault) {
|
|
334
|
+
this._onNormalize = undefined;
|
|
335
|
+
this._normalizeIsDefault = false;
|
|
336
|
+
}
|
|
337
|
+
this._onNormalize = _installHook(this._onNormalize, handler, insert);
|
|
338
|
+
break;
|
|
312
339
|
case "policyAdd":
|
|
313
340
|
this._onPolicyAdd = _installHook(this._onPolicyAdd, handler, insert);
|
|
314
341
|
break;
|
|
@@ -357,6 +384,12 @@ export class ComponentMeta {
|
|
|
357
384
|
this._requireRelationship(event);
|
|
358
385
|
this._onTargetRemove = _removeHook(this._onTargetRemove, handler);
|
|
359
386
|
break;
|
|
387
|
+
case "validate":
|
|
388
|
+
this._onValidate = _removeHook(this._onValidate, handler);
|
|
389
|
+
break;
|
|
390
|
+
case "normalize":
|
|
391
|
+
this._onNormalize = _removeHook(this._onNormalize, handler);
|
|
392
|
+
break;
|
|
360
393
|
case "policyAdd":
|
|
361
394
|
this._onPolicyAdd = _removeHook(this._onPolicyAdd, handler);
|
|
362
395
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component_meta.js","sourceRoot":"","sources":["../src/component_meta.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"component_meta.js","sourceRoot":"","sources":["../src/component_meta.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAI/C,MAAM,CAAN,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,gCAAe,CAAA;IACf,kCAAiB,CAAA;IACjB,kCAAiB,CAAA;AACnB,CAAC,EAJW,aAAa,KAAb,aAAa,QAIxB;AAED,2EAA2E;AAC3E,MAAM,OAAgB,YAAY;IAGhC,qEAAqE;IAC9D,UAAU,CAAC,MAAc;QAC9B,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YAChC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC;QACzB,CAAC;aAAM,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;YACxC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC7B,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,QAAQ,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAA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R,KAAK,iBAAiB;gBACpB,IAAI,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC;gBACjC,IAAI,CAAC,kBAAkB,GAAG,WAAW,CAAC,IAAI,CAAC,kBAAkB,EAAE,OAAwB,CAAC,CAAC;gBACzF,MAAM;YACR,KAAK,oBAAoB;gBACvB,IAAI,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC;gBACjC,IAAI,CAAC,qBAAqB,GAAG,WAAW,CACtC,IAAI,CAAC,qBAAqB,EAC1B,OAAwB,CACzB,CAAC;gBACF,MAAM;YACR,OAAO,CAAC,CAAC,CAAC;gBACR,MAAM,WAAW,GAAU,KAAK,CAAC;gBACjC,MAAM,IAAI,KAAK,CAAC,uBAAuB,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;YAChE,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,oBAAoB,CAAC,KAAgB;QAC3C,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,IAAI,KAAK,4DAA4D,CAAC,CAAC;QACzF,CAAC;IACH,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,11 @@ export { WorldStats, type Timing, type SystemTiming, type OperationTiming } from
|
|
|
9
9
|
export { Filter } from "./filter.js";
|
|
10
10
|
export { ComponentDef, Trait } from "./component_def.js";
|
|
11
11
|
export { ChildOf, DependsOn, Exclusive, OneOf, OwnedTarget, SilenceSource, } from "./modules/relationships.js";
|
|
12
|
-
export { CleanupPolicy, Component, Implements, Relationship, type ComponentInstance, type ComponentClass, type ComponentMeta, type ComponentRef, type CustomSnapshotOptions, type HookEvent, type HookEventMap, type HookHandler, type TargetHandler, } from "./component.js";
|
|
12
|
+
export { CleanupPolicy, Component, Implements, Relationship, type ComponentInstance, type ComponentClass, type ComponentMeta, type ComponentRef, type CustomSnapshotOptions, type HookEvent, type HookEventMap, type HookHandler, type NormalizeHandler, type TargetHandler, type ValidateHandler, } from "./component.js";
|
|
13
|
+
export { VecsStruct } from "./reflection/vecs_struct.js";
|
|
14
|
+
export { description, range, type, unit, values, type MemberDecorator, } from "./reflection/decorators.js";
|
|
15
|
+
export type { MemberClass, MemberElementType, MemberScalarType, MemberType, RangeBound, VecsMember, } from "./reflection/member_types.js";
|
|
16
|
+
export type { ValidationResult, Violations } from "./reflection/defaults.js";
|
|
13
17
|
export { Entity, type EID, type EntityClass, Identity } from "./entity/index.js";
|
|
14
18
|
export { Module, type ModuleConfig } from "./module.js";
|
|
15
19
|
export { MoveSubtreeError } from "./world/world.transfers.js";
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,8 @@ export { Filter } from "./filter.js";
|
|
|
7
7
|
export { ComponentDef, Trait } from "./component_def.js";
|
|
8
8
|
export { ChildOf, DependsOn, Exclusive, OneOf, OwnedTarget, SilenceSource, } from "./modules/relationships.js";
|
|
9
9
|
export { CleanupPolicy, Component, Implements, Relationship, } from "./component.js";
|
|
10
|
+
export { VecsStruct } from "./reflection/vecs_struct.js";
|
|
11
|
+
export { description, range, type, unit, values, } from "./reflection/decorators.js";
|
|
10
12
|
export { Entity, Identity } from "./entity/index.js";
|
|
11
13
|
export { Module } from "./module.js";
|
|
12
14
|
export { MoveSubtreeError } from "./world/world.transfers.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,EAA6C,MAAM,aAAa,CAAC;AAEhF,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAE9D,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAmB/C,OAAO,EAAE,aAAa,EAAE,KAAK,EAAqB,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAwD,MAAM,kB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AO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACpF,OAAO,EAGL,WAAW,EACX,cAAc,EACd,YAAY,EACZ,UAAU,EACV,cAAc,GACf,MAAM,uBAAuB,CAAC;AAY/B,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,OAAO,EACP,QAAQ,EACR,SAAS,EACT,WAAW,EACX,SAAS,EACT,WAAW,EACX,SAAS,EACT,UAAU,EACV,KAAK,EACL,cAAc,GACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAoC,MAAM,iBAAiB,CAAC;AACzE,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,cAAc,GAEf,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAuC,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,4BAA4B,EAAqB,MAAM,mBAAmB,CAAC"}
|
package/dist/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { DontSnapshot } from "../modules/snapshot_types.js";
|
|
2
|
+
import { _declareMembers, _structInstance, VecsStruct, } from "./vecs_struct.js";
|
|
3
|
+
/**
|
|
4
|
+
* @internal Merge one declaration and keep this world's `VecsStruct` in step,
|
|
5
|
+
* on this class and on any registered subclass that inherits the member.
|
|
6
|
+
*/
|
|
7
|
+
export function _declareComponentMember(component, name, declaration) {
|
|
8
|
+
const Class = component.meta.Class;
|
|
9
|
+
const changed = _declareMembers(Class, [[name, declaration]]);
|
|
10
|
+
const vecsStruct = _vecsStructComponent(component);
|
|
11
|
+
for (const registered of component.world._classRegistry.values()) {
|
|
12
|
+
const RegisteredClass = registered.meta.Class;
|
|
13
|
+
if (RegisteredClass !== Class && !(RegisteredClass.prototype instanceof Class)) {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if (!registered.has(vecsStruct)) {
|
|
17
|
+
_attachVecsStruct(registered);
|
|
18
|
+
}
|
|
19
|
+
else if (changed) {
|
|
20
|
+
registered.modified(VecsStruct);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** @internal Attach the class's definition to its component entity, if it has one. */
|
|
25
|
+
export function _attachVecsStruct(component) {
|
|
26
|
+
const instance = _structInstance(component.meta.Class);
|
|
27
|
+
if (instance !== undefined) {
|
|
28
|
+
_vecsStructComponent(component);
|
|
29
|
+
component.attach(VecsStruct, instance);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function _vecsStructComponent(component) {
|
|
33
|
+
const world = component.world;
|
|
34
|
+
const registered = world.getEntity(VecsStruct);
|
|
35
|
+
if (registered !== undefined) {
|
|
36
|
+
return registered;
|
|
37
|
+
}
|
|
38
|
+
// Definitions are local schema metadata, like `ComponentDef`. Registering
|
|
39
|
+
// lazily keeps the component ids of worlds that declare no members unchanged.
|
|
40
|
+
return world.component(VecsStruct).snapshotPolicy(DontSnapshot);
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=component_members.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component_members.js","sourceRoot":"","sources":["../../src/reflection/component_members.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5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,CAAC,KAAK,CAAC;IAC9B,MAAM,UAAU,GAAG,KAAK,CAAC,SAAS,CAAC,UAAU,CAA0B,CAAC;IACxE,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC7B,OAAO,UAAU,CAAC;IACpB,CAAC;IACD,0EAA0E;IAC1E,8EAA8E;IAC9E,OAAO,KAAK,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type MemberType, type RangeBound } from "./member_types.js";
|
|
2
|
+
/**
|
|
3
|
+
* A member decorator, usable as a legacy (`experimentalDecorators`) property
|
|
4
|
+
* decorator or a standard (TC39) field decorator.
|
|
5
|
+
*/
|
|
6
|
+
export type MemberDecorator = PropertyDecorator & ((value: undefined, context: ClassFieldDecoratorContext) => void);
|
|
7
|
+
/**
|
|
8
|
+
* Declare a member's type. Every member that carries metadata needs one.
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* class Position {
|
|
12
|
+
* @type("i32") @range(-100, 100) public x = 0;
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @param memberType - A scalar type name, a nested component class, or an array `[type]`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function type(memberType: MemberType): MemberDecorator;
|
|
19
|
+
/**
|
|
20
|
+
* Declare a numeric member's inclusive `[min, max]` range.
|
|
21
|
+
*
|
|
22
|
+
* Ranges are metadata: nothing checks them on `set`. The default `validate`
|
|
23
|
+
* and `normalize` hooks check and clamp to them.
|
|
24
|
+
*/
|
|
25
|
+
export declare function range(min: RangeBound, max: RangeBound): MemberDecorator;
|
|
26
|
+
/** Declare a member's human-readable description. */
|
|
27
|
+
export declare function description(text: string): MemberDecorator;
|
|
28
|
+
/** Declare a member's unit of measure, for example `"m"`. */
|
|
29
|
+
export declare function unit(text: string): MemberDecorator;
|
|
30
|
+
/** Declare the allowed values of an `enum` member. */
|
|
31
|
+
export declare function values(allowed: readonly number[]): MemberDecorator;
|