@oasys/oecs 0.5.0 → 0.5.1
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/CHANGELOG.md +84 -1
- package/README.md +11 -7
- package/dist/core/ecs/archetype.d.cts +3 -3
- package/dist/core/ecs/archetype.d.ts +3 -3
- package/dist/core/ecs/component.d.cts +25 -0
- package/dist/core/ecs/component.d.ts +25 -0
- package/dist/core/ecs/component.d.ts.map +1 -1
- package/dist/core/ecs/ecs.d.cts +67 -49
- package/dist/core/ecs/ecs.d.ts +67 -49
- package/dist/core/ecs/ecs.d.ts.map +1 -1
- package/dist/core/ecs/entity.d.cts +1 -1
- package/dist/core/ecs/entity.d.ts +1 -1
- package/dist/core/ecs/facades.d.cts +1 -1
- package/dist/core/ecs/facades.d.ts +1 -1
- package/dist/core/ecs/host_commands.d.cts +30 -20
- package/dist/core/ecs/host_commands.d.ts +30 -20
- package/dist/core/ecs/host_commands.d.ts.map +1 -1
- package/dist/core/ecs/index.d.cts +3 -3
- package/dist/core/ecs/index.d.ts +3 -3
- package/dist/core/ecs/index.d.ts.map +1 -1
- package/dist/core/ecs/observer.d.cts +1 -1
- package/dist/core/ecs/observer.d.ts +1 -1
- package/dist/core/ecs/observer.d.ts.map +1 -1
- package/dist/core/ecs/query.d.cts +22 -6
- package/dist/core/ecs/query.d.ts +22 -6
- package/dist/core/ecs/query.d.ts.map +1 -1
- package/dist/core/ecs/ref.d.ts.map +1 -1
- package/dist/core/ecs/run_condition.d.cts +1 -1
- package/dist/core/ecs/run_condition.d.ts +1 -1
- package/dist/core/ecs/run_condition.d.ts.map +1 -1
- package/dist/core/ecs/store.d.cts +10 -23
- package/dist/core/ecs/store.d.ts +10 -23
- package/dist/core/ecs/store.d.ts.map +1 -1
- package/dist/dev_flag.d.cts +0 -15
- package/dist/dev_flag.d.ts +0 -15
- package/dist/dev_flag.d.ts.map +1 -1
- package/dist/extensions/editor/editor.d.cts +31 -29
- package/dist/extensions/editor/editor.d.ts +31 -29
- package/dist/extensions/editor/editor.d.ts.map +1 -1
- package/dist/extensions/editor/field_handle.d.cts +3 -3
- package/dist/extensions/editor/field_handle.d.ts +3 -3
- package/dist/extensions/editor/field_handle.d.ts.map +1 -1
- package/dist/extensions/editor/index.cjs +1 -1
- package/dist/extensions/editor/index.js +53 -51
- package/dist/{host_commands-i4cAeyL5.js → host_commands-BI8pEmjH.js} +26 -18
- package/dist/{host_commands-BF8QMi3c.cjs → host_commands-CxhpzMx9.cjs} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +269 -214
- package/dist/internal.cjs +1 -1
- package/dist/internal.js +1 -1
- package/dist/version.d.cts +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ import { ComponentDef, ComponentHandle, ComponentSchema, EntityID, CompleteField
|
|
|
5
5
|
* to the reactive read channel (e.g. a `reactiveMap`/`reactiveStruct` projection)
|
|
6
6
|
* or to `ecs.getField`; `undefined` for an unknown slot falls back to `0`.
|
|
7
7
|
*/
|
|
8
|
-
export type FieldReader = (
|
|
8
|
+
export type FieldReader = (entityId: EntityID, def: ComponentDef, field: string) => number | undefined;
|
|
9
9
|
/**
|
|
10
10
|
* A reified, undoable unit of editor work: the `forward` commands and their
|
|
11
11
|
* `inverse`, both plain `HostCommand` data on the one bus. The arrays are mutable
|
|
@@ -42,33 +42,35 @@ export declare class TransactionBuilder {
|
|
|
42
42
|
* also forwards the new id to the caller. The finalizer re-fires on redo, so the
|
|
43
43
|
* inverse tracks the current id.
|
|
44
44
|
*/
|
|
45
|
-
spawn<Defs extends readonly ComponentDef[]>(components: SpawnEntries<Defs>, onSpawned?: (
|
|
45
|
+
spawn<Defs extends readonly ComponentDef[]>(components: SpawnEntries<Defs>, onSpawned?: (entityId: EntityID) => void): this;
|
|
46
46
|
/**
|
|
47
|
-
* Despawn `
|
|
47
|
+
* Despawn `entityId`. Inverse: respawn from `restore` (the components+values to
|
|
48
48
|
* recreate — read them from the channel before despawning). Undo respawns the
|
|
49
49
|
* DATA, not the identity: the new entity gets a fresh id, and the respawn's
|
|
50
50
|
* `onSpawned` rewrites this despawn's target so redo removes the respawned
|
|
51
51
|
* entity rather than the dead original.
|
|
52
52
|
*/
|
|
53
|
-
despawn<Defs extends readonly ComponentDef[]>(
|
|
53
|
+
despawn<Defs extends readonly ComponentDef[]>(entityId: EntityID, restore: SpawnEntries<Defs>): this;
|
|
54
54
|
/**
|
|
55
|
-
* Set `field` of `def` on `
|
|
55
|
+
* Set `field` of `def` on `entityId` to `value`. Inverse: set it back to the value
|
|
56
56
|
* this edit replaced — read from the staged overlay / shadow (so stacked edits,
|
|
57
57
|
* within one build or before a commit, invert correctly) or, failing that, the
|
|
58
58
|
* read channel (`0` if unknown).
|
|
59
59
|
*/
|
|
60
|
-
setField<S extends ComponentSchema>(
|
|
61
|
-
/**
|
|
62
|
-
|
|
60
|
+
setField<S extends ComponentSchema>(entityId: EntityID, def: ComponentDef<S>, field: string & keyof S, value: number): this;
|
|
61
|
+
/** Attach `def` (with complete `values`) to `entityId`. Inverse: remove it.
|
|
62
|
+
* Bare `add` — the namespaced-handle grammar (matches `ctx.commands.add` and
|
|
63
|
+
* the queue's `add`), not `addComponent`. */
|
|
64
|
+
add<S extends ComponentSchema>(entityId: EntityID, def: ComponentDef<S>, values: CompleteFieldValues<S>): this;
|
|
63
65
|
/**
|
|
64
|
-
*
|
|
65
|
-
* to recreate — read them from the channel before removing).
|
|
66
|
+
* Detach `def` from `entityId`. Inverse: re-add it from `restore` (the field values
|
|
67
|
+
* to recreate — read them from the channel before removing). Bare `remove` — see `add`.
|
|
66
68
|
*/
|
|
67
|
-
|
|
68
|
-
/** Disable `
|
|
69
|
-
disable(
|
|
70
|
-
/** Enable `
|
|
71
|
-
enable(
|
|
69
|
+
remove<S extends ComponentSchema>(entityId: EntityID, def: ComponentDef<S>, restore: CompleteFieldValues<S>): this;
|
|
70
|
+
/** Disable `entityId`. Inverse: enable it. */
|
|
71
|
+
disable(entityId: EntityID): this;
|
|
72
|
+
/** Enable `entityId`. Inverse: disable it. */
|
|
73
|
+
enable(entityId: EntityID): this;
|
|
72
74
|
}
|
|
73
75
|
/**
|
|
74
76
|
* The editor's undo/redo manager over a {@link HostCommandQueue}. Each action is a
|
|
@@ -97,19 +99,19 @@ export declare class Editor {
|
|
|
97
99
|
*/
|
|
98
100
|
transaction(build: (tx: TransactionBuilder) => void): EditorTransaction;
|
|
99
101
|
/** Spawn `components` as its own undo entry. `onSpawned` reports the new id. */
|
|
100
|
-
spawn<Defs extends readonly ComponentDef[]>(components: SpawnEntries<Defs>, onSpawned?: (
|
|
101
|
-
/** Despawn `
|
|
102
|
-
despawn<Defs extends readonly ComponentDef[]>(
|
|
102
|
+
spawn<Defs extends readonly ComponentDef[]>(components: SpawnEntries<Defs>, onSpawned?: (entityId: EntityID) => void): EditorTransaction;
|
|
103
|
+
/** Despawn `entityId` as its own undo entry; `restore` recreates it on undo. */
|
|
104
|
+
despawn<Defs extends readonly ComponentDef[]>(entityId: EntityID, restore: SpawnEntries<Defs>): EditorTransaction;
|
|
103
105
|
/** Set one field as its own undo entry. */
|
|
104
|
-
setField<S extends ComponentSchema>(
|
|
105
|
-
/**
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
|
|
109
|
-
/** Disable `
|
|
110
|
-
disable(
|
|
111
|
-
/** Enable `
|
|
112
|
-
enable(
|
|
106
|
+
setField<S extends ComponentSchema>(entityId: EntityID, def: ComponentDef<S>, field: string & keyof S, value: number): EditorTransaction;
|
|
107
|
+
/** Attach a component as its own undo entry. Bare `add` (see `TransactionBuilder.add`). */
|
|
108
|
+
add<S extends ComponentSchema>(entityId: EntityID, def: ComponentDef<S>, values: CompleteFieldValues<S>): EditorTransaction;
|
|
109
|
+
/** Detach a component as its own undo entry; `restore` re-adds it on undo. Bare `remove`. */
|
|
110
|
+
remove<S extends ComponentSchema>(entityId: EntityID, def: ComponentDef<S>, restore: CompleteFieldValues<S>): EditorTransaction;
|
|
111
|
+
/** Disable `entityId` as its own undo entry. */
|
|
112
|
+
disable(entityId: EntityID): EditorTransaction;
|
|
113
|
+
/** Enable `entityId` as its own undo entry. */
|
|
114
|
+
enable(entityId: EntityID): EditorTransaction;
|
|
113
115
|
/**
|
|
114
116
|
* Undo the most recent transaction: enqueue its inverse commands (in reverse
|
|
115
117
|
* order — a group unwinds last-action-first) on the bus and move it to the redo
|
|
@@ -145,7 +147,7 @@ export declare class Editor {
|
|
|
145
147
|
/** Read one committed `(entity, component, field)` slot through the reader
|
|
146
148
|
* this editor was constructed with — the default read for `fieldHandle`
|
|
147
149
|
* when no channel thunk is supplied (M11). */
|
|
148
|
-
committedField(
|
|
150
|
+
committedField(entityId: EntityID, def: ComponentDef, field: string): number | undefined;
|
|
149
151
|
/**
|
|
150
152
|
* The pending value the editor believes for a field that the committed read
|
|
151
153
|
* channel has NOT caught up to yet (the shadow), or `undefined` if none. Lets an
|
|
@@ -161,7 +163,7 @@ export declare class Editor {
|
|
|
161
163
|
* the next edit to the slot. `value` (the read channel) is always the source of
|
|
162
164
|
* truth; `pending` is only the optimistic bridge.
|
|
163
165
|
*/
|
|
164
|
-
pendingField(
|
|
166
|
+
pendingField(entityId: EntityID, def: ComponentHandle, field: string): number | undefined;
|
|
165
167
|
/** Enqueue forward commands, record the transaction, clear redo, sync shadow. */
|
|
166
168
|
private commit;
|
|
167
169
|
/** Keep the setField shadow in step with the commands just enqueued. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../../../src/extensions/editor/editor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,OAAO,KAAK,EACX,YAAY,EACZ,eAAe,EACf,eAAe,EACf,QAAQ,EACR,mBAAmB,EACnB,WAAW,EACX,gBAAgB,EA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,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE;IAIxC,uEAAuE;IACvE,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,uEAAuE;IACvE,IAAI,OAAO,IAAI,OAAO,CAErB;IAED;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAQpC,OAAO,CAAC,MAAM;IAId;;kDAE8C;IAC9C,cAAc,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAIxF;;;;;;;;;;;;;;OAcG;IACH,YAAY,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAkBzF,iFAAiF;IACjF,OAAO,CAAC,MAAM;IAad,wEAAwE;IACxE,OAAO,CAAC,WAAW;CAOnB"}
|
|
@@ -26,9 +26,9 @@ export interface FieldHandle {
|
|
|
26
26
|
readonly pending: number | undefined;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
* Build a {@link FieldHandle} for one `(
|
|
29
|
+
* Build a {@link FieldHandle} for one `(entityId, def, field)` slot. `read` is the
|
|
30
30
|
* tracked read of the reactive channel for this field (e.g.
|
|
31
|
-
* `() => sync.map.get(
|
|
31
|
+
* `() => sync.map.get(entityId)?.x`); `set` routes through `editor.setField`, so the
|
|
32
32
|
* edit is queued, batched, and undoable.
|
|
33
33
|
*
|
|
34
34
|
* `read` is optional (M11): omitted, the handle reads through the editor's own
|
|
@@ -36,5 +36,5 @@ export interface FieldHandle {
|
|
|
36
36
|
* but NOT reactive — supply the channel thunk when the handle's `value` must
|
|
37
37
|
* subscribe inside a tracking scope.
|
|
38
38
|
*/
|
|
39
|
-
export declare function fieldHandle<S extends ComponentSchema>(editor: Editor,
|
|
39
|
+
export declare function fieldHandle<S extends ComponentSchema>(editor: Editor, entityId: EntityID, def: ComponentDef<S>, field: string & keyof S, read?: () => number | undefined): FieldHandle;
|
|
40
40
|
//# sourceMappingURL=field_handle.d.ts.map
|
|
@@ -26,9 +26,9 @@ export interface FieldHandle {
|
|
|
26
26
|
readonly pending: number | undefined;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
* Build a {@link FieldHandle} for one `(
|
|
29
|
+
* Build a {@link FieldHandle} for one `(entityId, def, field)` slot. `read` is the
|
|
30
30
|
* tracked read of the reactive channel for this field (e.g.
|
|
31
|
-
* `() => sync.map.get(
|
|
31
|
+
* `() => sync.map.get(entityId)?.x`); `set` routes through `editor.setField`, so the
|
|
32
32
|
* edit is queued, batched, and undoable.
|
|
33
33
|
*
|
|
34
34
|
* `read` is optional (M11): omitted, the handle reads through the editor's own
|
|
@@ -36,5 +36,5 @@ export interface FieldHandle {
|
|
|
36
36
|
* but NOT reactive — supply the channel thunk when the handle's `value` must
|
|
37
37
|
* subscribe inside a tracking scope.
|
|
38
38
|
*/
|
|
39
|
-
export declare function fieldHandle<S extends ComponentSchema>(editor: Editor,
|
|
39
|
+
export declare function fieldHandle<S extends ComponentSchema>(editor: Editor, entityId: EntityID, def: ComponentDef<S>, field: string & keyof S, read?: () => number | undefined): FieldHandle;
|
|
40
40
|
//# sourceMappingURL=field_handle.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field_handle.d.ts","sourceRoot":"","sources":["../../../src/extensions/editor/field_handle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC3B;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,8EAA8E;IAC9E,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB;;;;;;;OAOG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,eAAe,EACpD,MAAM,EAAE,MAAM,EACd,
|
|
1
|
+
{"version":3,"file":"field_handle.d.ts","sourceRoot":"","sources":["../../../src/extensions/editor/field_handle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC3B;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,8EAA8E;IAC9E,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB;;;;;;;OAOG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,eAAe,EACpD,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,EAClB,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC,EACpB,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,EACvB,IAAI,CAAC,EAAE,MAAM,MAAM,GAAG,SAAS,GAC7B,WAAW,CAYb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(r,t,e){return`${r}:${t.id}:${e}`}const a=new WeakMap;class h{constructor(t,e){this.readField=t,this.shadow=e,a.set(this,{forward:[],inverse:[]})}staged=new Map;get _txn(){return a.get(this)}spawn(t,e){const s={kind:"despawn",eid:0};return this._txn.inverse.push(s),this._txn.forward.push({kind:"spawn",components:t,onSpawned:n=>{s.eid=n,e?.(n)}}),this}despawn(t,e){const s={kind:"despawn",eid:t};return this._txn.forward.push(s),this._txn.inverse.push({kind:"spawn",components:e,onSpawned:n=>{s.eid=n}}),this}setField(t,e,s,n){const i=o(t,e,s),d=this.staged.get(i)??this.shadow.get(i)??this.readField(t,e,s)??0;return this.staged.set(i,n),this._txn.forward.push({kind:"set_field",eid:t,def:e,field:s,value:n}),this._txn.inverse.push({kind:"set_field",eid:t,def:e,field:s,value:d}),this}add(t,e,s){return this._txn.forward.push({kind:"add_component",eid:t,def:e,values:s}),this._txn.inverse.push({kind:"remove_component",eid:t,def:e}),this}remove(t,e,s){return this._txn.forward.push({kind:"remove_component",eid:t,def:e}),this._txn.inverse.push({kind:"add_component",eid:t,def:e,values:s}),this}disable(t){return this._txn.forward.push({kind:"disable",eid:t}),this._txn.inverse.push({kind:"enable",eid:t}),this}enable(t){return this._txn.forward.push({kind:"enable",eid:t}),this._txn.inverse.push({kind:"disable",eid:t}),this}}class u{constructor(t,e){this.queue=t,this.readField=e}undoStack=[];redoStack=[];listeners=[];shadow=new Map;transaction(t){const e=new h(this.readField,this.shadow);return t(e),this.commit(a.get(e))}spawn(t,e){return this.transaction(s=>s.spawn(t,e))}despawn(t,e){return this.transaction(s=>s.despawn(t,e))}setField(t,e,s,n){return this.transaction(i=>i.setField(t,e,s,n))}add(t,e,s){return this.transaction(n=>n.add(t,e,s))}remove(t,e,s){return this.transaction(n=>n.remove(t,e,s))}disable(t){return this.transaction(e=>e.disable(t))}enable(t){return this.transaction(e=>e.enable(t))}undo(){const t=this.undoStack.pop();if(t===void 0)return!1;const e=t.inverse.slice().reverse();for(const s of e)this.queue.push(s);return this.applyShadow(e),this.redoStack.push(t),this.notify(),!0}redo(){const t=this.redoStack.pop();if(t===void 0)return!1;for(const e of t.forward)this.queue.push(e);return this.applyShadow(t.forward),this.undoStack.push(t),this.notify(),!0}clear(){this.undoStack.length=0,this.redoStack.length=0,this.shadow.clear(),this.notify()}depths(){return{undo:this.undoStack.length,redo:this.redoStack.length}}get canUndo(){return this.undoStack.length>0}get canRedo(){return this.redoStack.length>0}onChange(t){return this.listeners.push(t),()=>{const e=this.listeners.indexOf(t);e!==-1&&this.listeners.splice(e,1)}}notify(){for(const t of this.listeners.slice())t()}committedField(t,e,s){return this.readField(t,e,s)}pendingField(t,e,s){const n=o(t,e,s),i=this.shadow.get(n);if(i===void 0)return;const d=this.readField(t,e,s);if(d===i||d===void 0){this.shadow.delete(n);return}return i}commit(t){if(t.forward.length===0)return t;for(const e of t.forward)this.queue.push(e);return this.applyShadow(t.forward),this.undoStack.push(t),this.redoStack.length=0,this.notify(),t}applyShadow(t){for(const e of t)e.kind==="set_field"&&this.shadow.set(o(e.eid,e.def,e.field),e.value)}}function c(r,t,e,s,n){return{get value(){return n!==void 0?n():r.committedField(t,e,s)},set(i){r.setField(t,e,s,i)},get pending(){return r.pendingField(t,e,s)}}}exports.Editor=u;exports.TransactionBuilder=h;exports.fieldHandle=c;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
function
|
|
1
|
+
function o(r, t, e) {
|
|
2
2
|
return `${r}:${t.id}:${e}`;
|
|
3
3
|
}
|
|
4
|
-
const
|
|
4
|
+
const a = /* @__PURE__ */ new WeakMap();
|
|
5
5
|
class h {
|
|
6
6
|
/** @internal */
|
|
7
7
|
constructor(t, e) {
|
|
8
|
-
this.readField = t, this.shadow = e,
|
|
8
|
+
this.readField = t, this.shadow = e, a.set(this, { forward: [], inverse: [] });
|
|
9
9
|
}
|
|
10
10
|
/** Values staged by THIS build, layered over the editor's shared shadow. Kept
|
|
11
11
|
* transaction-local so an aborted build (the callback throws before commit)
|
|
@@ -14,62 +14,64 @@ class h {
|
|
|
14
14
|
* held. The one merge point into the shared shadow is commit's `applyShadow`. */
|
|
15
15
|
staged = /* @__PURE__ */ new Map();
|
|
16
16
|
get _txn() {
|
|
17
|
-
return
|
|
17
|
+
return a.get(this);
|
|
18
18
|
}
|
|
19
19
|
spawn(t, e) {
|
|
20
|
-
const
|
|
20
|
+
const s = {
|
|
21
21
|
kind: "despawn",
|
|
22
22
|
eid: 0
|
|
23
23
|
};
|
|
24
|
-
return this._txn.inverse.push(
|
|
24
|
+
return this._txn.inverse.push(s), this._txn.forward.push({
|
|
25
25
|
kind: "spawn",
|
|
26
26
|
components: t,
|
|
27
|
-
onSpawned: (
|
|
28
|
-
|
|
27
|
+
onSpawned: (n) => {
|
|
28
|
+
s.eid = n, e?.(n);
|
|
29
29
|
}
|
|
30
30
|
}), this;
|
|
31
31
|
}
|
|
32
32
|
despawn(t, e) {
|
|
33
|
-
const
|
|
34
|
-
return this._txn.forward.push(
|
|
33
|
+
const s = { kind: "despawn", eid: t };
|
|
34
|
+
return this._txn.forward.push(s), this._txn.inverse.push({
|
|
35
35
|
kind: "spawn",
|
|
36
36
|
components: e,
|
|
37
|
-
onSpawned: (
|
|
38
|
-
|
|
37
|
+
onSpawned: (n) => {
|
|
38
|
+
s.eid = n;
|
|
39
39
|
}
|
|
40
40
|
}), this;
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
|
-
* Set `field` of `def` on `
|
|
43
|
+
* Set `field` of `def` on `entityId` to `value`. Inverse: set it back to the value
|
|
44
44
|
* this edit replaced — read from the staged overlay / shadow (so stacked edits,
|
|
45
45
|
* within one build or before a commit, invert correctly) or, failing that, the
|
|
46
46
|
* read channel (`0` if unknown).
|
|
47
47
|
*/
|
|
48
|
-
setField(t, e,
|
|
49
|
-
const i =
|
|
50
|
-
return this.staged.set(i,
|
|
48
|
+
setField(t, e, s, n) {
|
|
49
|
+
const i = o(t, e, s), d = this.staged.get(i) ?? this.shadow.get(i) ?? this.readField(t, e, s) ?? 0;
|
|
50
|
+
return this.staged.set(i, n), this._txn.forward.push({ kind: "set_field", eid: t, def: e, field: s, value: n }), this._txn.inverse.push({ kind: "set_field", eid: t, def: e, field: s, value: d }), this;
|
|
51
51
|
}
|
|
52
|
-
/**
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
/** Attach `def` (with complete `values`) to `entityId`. Inverse: remove it.
|
|
53
|
+
* Bare `add` — the namespaced-handle grammar (matches `ctx.commands.add` and
|
|
54
|
+
* the queue's `add`), not `addComponent`. */
|
|
55
|
+
add(t, e, s) {
|
|
56
|
+
return this._txn.forward.push({ kind: "add_component", eid: t, def: e, values: s }), this._txn.inverse.push({ kind: "remove_component", eid: t, def: e }), this;
|
|
55
57
|
}
|
|
56
58
|
/**
|
|
57
|
-
*
|
|
58
|
-
* to recreate — read them from the channel before removing).
|
|
59
|
+
* Detach `def` from `entityId`. Inverse: re-add it from `restore` (the field values
|
|
60
|
+
* to recreate — read them from the channel before removing). Bare `remove` — see `add`.
|
|
59
61
|
*/
|
|
60
|
-
|
|
62
|
+
remove(t, e, s) {
|
|
61
63
|
return this._txn.forward.push({ kind: "remove_component", eid: t, def: e }), this._txn.inverse.push({
|
|
62
64
|
kind: "add_component",
|
|
63
65
|
eid: t,
|
|
64
66
|
def: e,
|
|
65
|
-
values:
|
|
67
|
+
values: s
|
|
66
68
|
}), this;
|
|
67
69
|
}
|
|
68
|
-
/** Disable `
|
|
70
|
+
/** Disable `entityId`. Inverse: enable it. */
|
|
69
71
|
disable(t) {
|
|
70
72
|
return this._txn.forward.push({ kind: "disable", eid: t }), this._txn.inverse.push({ kind: "enable", eid: t }), this;
|
|
71
73
|
}
|
|
72
|
-
/** Enable `
|
|
74
|
+
/** Enable `entityId`. Inverse: disable it. */
|
|
73
75
|
enable(t) {
|
|
74
76
|
return this._txn.forward.push({ kind: "enable", eid: t }), this._txn.inverse.push({ kind: "disable", eid: t }), this;
|
|
75
77
|
}
|
|
@@ -91,31 +93,31 @@ class u {
|
|
|
91
93
|
*/
|
|
92
94
|
transaction(t) {
|
|
93
95
|
const e = new h(this.readField, this.shadow);
|
|
94
|
-
return t(e), this.commit(
|
|
96
|
+
return t(e), this.commit(a.get(e));
|
|
95
97
|
}
|
|
96
98
|
spawn(t, e) {
|
|
97
|
-
return this.transaction((
|
|
99
|
+
return this.transaction((s) => s.spawn(t, e));
|
|
98
100
|
}
|
|
99
101
|
despawn(t, e) {
|
|
100
|
-
return this.transaction((
|
|
102
|
+
return this.transaction((s) => s.despawn(t, e));
|
|
101
103
|
}
|
|
102
104
|
/** Set one field as its own undo entry. */
|
|
103
|
-
setField(t, e,
|
|
104
|
-
return this.transaction((i) => i.setField(t, e,
|
|
105
|
+
setField(t, e, s, n) {
|
|
106
|
+
return this.transaction((i) => i.setField(t, e, s, n));
|
|
105
107
|
}
|
|
106
|
-
/**
|
|
107
|
-
|
|
108
|
-
return this.transaction((
|
|
108
|
+
/** Attach a component as its own undo entry. Bare `add` (see `TransactionBuilder.add`). */
|
|
109
|
+
add(t, e, s) {
|
|
110
|
+
return this.transaction((n) => n.add(t, e, s));
|
|
109
111
|
}
|
|
110
|
-
/**
|
|
111
|
-
|
|
112
|
-
return this.transaction((
|
|
112
|
+
/** Detach a component as its own undo entry; `restore` re-adds it on undo. Bare `remove`. */
|
|
113
|
+
remove(t, e, s) {
|
|
114
|
+
return this.transaction((n) => n.remove(t, e, s));
|
|
113
115
|
}
|
|
114
|
-
/** Disable `
|
|
116
|
+
/** Disable `entityId` as its own undo entry. */
|
|
115
117
|
disable(t) {
|
|
116
118
|
return this.transaction((e) => e.disable(t));
|
|
117
119
|
}
|
|
118
|
-
/** Enable `
|
|
120
|
+
/** Enable `entityId` as its own undo entry. */
|
|
119
121
|
enable(t) {
|
|
120
122
|
return this.transaction((e) => e.enable(t));
|
|
121
123
|
}
|
|
@@ -128,7 +130,7 @@ class u {
|
|
|
128
130
|
const t = this.undoStack.pop();
|
|
129
131
|
if (t === void 0) return !1;
|
|
130
132
|
const e = t.inverse.slice().reverse();
|
|
131
|
-
for (const
|
|
133
|
+
for (const s of e) this.queue.push(s);
|
|
132
134
|
return this.applyShadow(e), this.redoStack.push(t), this.notify(), !0;
|
|
133
135
|
}
|
|
134
136
|
/**
|
|
@@ -177,8 +179,8 @@ class u {
|
|
|
177
179
|
/** Read one committed `(entity, component, field)` slot through the reader
|
|
178
180
|
* this editor was constructed with — the default read for `fieldHandle`
|
|
179
181
|
* when no channel thunk is supplied (M11). */
|
|
180
|
-
committedField(t, e,
|
|
181
|
-
return this.readField(t, e,
|
|
182
|
+
committedField(t, e, s) {
|
|
183
|
+
return this.readField(t, e, s);
|
|
182
184
|
}
|
|
183
185
|
/**
|
|
184
186
|
* The pending value the editor believes for a field that the committed read
|
|
@@ -195,12 +197,12 @@ class u {
|
|
|
195
197
|
* the next edit to the slot. `value` (the read channel) is always the source of
|
|
196
198
|
* truth; `pending` is only the optimistic bridge.
|
|
197
199
|
*/
|
|
198
|
-
pendingField(t, e,
|
|
199
|
-
const
|
|
200
|
+
pendingField(t, e, s) {
|
|
201
|
+
const n = o(t, e, s), i = this.shadow.get(n);
|
|
200
202
|
if (i === void 0) return;
|
|
201
|
-
const
|
|
202
|
-
if (
|
|
203
|
-
this.shadow.delete(
|
|
203
|
+
const d = this.readField(t, e, s);
|
|
204
|
+
if (d === i || d === void 0) {
|
|
205
|
+
this.shadow.delete(n);
|
|
204
206
|
return;
|
|
205
207
|
}
|
|
206
208
|
return i;
|
|
@@ -214,19 +216,19 @@ class u {
|
|
|
214
216
|
/** Keep the setField shadow in step with the commands just enqueued. */
|
|
215
217
|
applyShadow(t) {
|
|
216
218
|
for (const e of t)
|
|
217
|
-
e.kind === "set_field" && this.shadow.set(
|
|
219
|
+
e.kind === "set_field" && this.shadow.set(o(e.eid, e.def, e.field), e.value);
|
|
218
220
|
}
|
|
219
221
|
}
|
|
220
|
-
function c(r, t, e,
|
|
222
|
+
function c(r, t, e, s, n) {
|
|
221
223
|
return {
|
|
222
224
|
get value() {
|
|
223
|
-
return
|
|
225
|
+
return n !== void 0 ? n() : r.committedField(t, e, s);
|
|
224
226
|
},
|
|
225
227
|
set(i) {
|
|
226
|
-
r.setField(t, e,
|
|
228
|
+
r.setField(t, e, s, i);
|
|
227
229
|
},
|
|
228
230
|
get pending() {
|
|
229
|
-
return r.pendingField(t, e,
|
|
231
|
+
return r.pendingField(t, e, s);
|
|
230
232
|
}
|
|
231
233
|
};
|
|
232
234
|
}
|
|
@@ -1991,40 +1991,48 @@ function ue(e, t) {
|
|
|
1991
1991
|
class _n {
|
|
1992
1992
|
queued = [];
|
|
1993
1993
|
spawn(t, n) {
|
|
1994
|
-
this.queued.push({ kind: "spawn", components: t, onSpawned: n });
|
|
1994
|
+
return this.queued.push({ kind: "spawn", components: t, onSpawned: n }), this;
|
|
1995
1995
|
}
|
|
1996
1996
|
despawn(t) {
|
|
1997
|
-
this.queued.push({ kind: "despawn", eid: t });
|
|
1998
|
-
}
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
1997
|
+
return this.queued.push({ kind: "despawn", eid: t }), this;
|
|
1998
|
+
}
|
|
1999
|
+
/** Attach `def` (with complete `values`) to `entityId` (deferred to the
|
|
2000
|
+
* drain). The namespaced-handle grammar — the queue is a commands buffer, so
|
|
2001
|
+
* it drops the noun (`add`, not `addComponent`), matching `ctx.commands.add`
|
|
2002
|
+
* and the queue's own bare `spawn`/`despawn`/`disable`/`enable`. Values are
|
|
2003
|
+
* complete (transport carries explicit intent per field; see `spawnEntry`),
|
|
2004
|
+
* unlike the authoring-side bundle sugar. */
|
|
2005
|
+
add(t, n, r) {
|
|
2006
|
+
return this.queued.push({ kind: "add_component", eid: t, def: n, values: r }), this;
|
|
2007
|
+
}
|
|
2008
|
+
/** Detach `def` from `entityId` (deferred to the drain). Bare `remove`
|
|
2009
|
+
* matching `ctx.commands.remove` — see `add`. */
|
|
2010
|
+
remove(t, n) {
|
|
2011
|
+
return this.queued.push({ kind: "remove_component", eid: t, def: n }), this;
|
|
2012
|
+
}
|
|
2013
|
+
/** Set `field` of `def` on `entityId`. Applied IMMEDIATELY at the drain, unlike
|
|
2014
|
+
* the deferred structural ops — so `def` must already be on `entityId`. Do NOT
|
|
2015
|
+
* `add`/`spawn` `def` and `setField` it in the same frame: the add is
|
|
2008
2016
|
* still pending its flush when the immediate set runs (carry the value in
|
|
2009
|
-
* `
|
|
2017
|
+
* `add`/`spawnEntry` instead). `applyHostCommand` throws an
|
|
2010
2018
|
* actionable error in `DEV` if you do. */
|
|
2011
2019
|
setField(t, n, r, s) {
|
|
2012
|
-
this.queued.push({ kind: "set_field", eid: t, def: n, field: r, value: s });
|
|
2020
|
+
return this.queued.push({ kind: "set_field", eid: t, def: n, field: r, value: s }), this;
|
|
2013
2021
|
}
|
|
2014
2022
|
disable(t) {
|
|
2015
|
-
this.queued.push({ kind: "disable", eid: t });
|
|
2023
|
+
return this.queued.push({ kind: "disable", eid: t }), this;
|
|
2016
2024
|
}
|
|
2017
2025
|
enable(t) {
|
|
2018
|
-
this.queued.push({ kind: "enable", eid: t });
|
|
2026
|
+
return this.queued.push({ kind: "enable", eid: t }), this;
|
|
2019
2027
|
}
|
|
2020
2028
|
/** Enqueue a pre-built command. The path for a SAB-ring codec, an editor's
|
|
2021
2029
|
* reified inverse, or a replay log — all of which produce `HostCommand` data
|
|
2022
2030
|
* directly rather than calling the typed sugar above. */
|
|
2023
2031
|
push(t) {
|
|
2024
|
-
this.queued.push(t);
|
|
2032
|
+
return this.queued.push(t), this;
|
|
2025
2033
|
}
|
|
2026
2034
|
/** Commands buffered but not yet applied. */
|
|
2027
|
-
pending() {
|
|
2035
|
+
get pending() {
|
|
2028
2036
|
return this.queued.length;
|
|
2029
2037
|
}
|
|
2030
2038
|
/** Drop every buffered command without applying it (M15) — e.g. abandoning
|