@typeonce/ritmo 0.7.0 → 0.9.0
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 +3 -2
- package/dist/Clock.d.ts +19 -4
- package/dist/Clock.d.ts.map +1 -1
- package/dist/Clock.js +18 -2
- package/dist/Clock.js.map +1 -1
- package/dist/Command.d.ts +181 -40
- package/dist/Command.d.ts.map +1 -1
- package/dist/Command.js +31 -11
- package/dist/Command.js.map +1 -1
- package/dist/Condition.d.ts +12 -1
- package/dist/Condition.d.ts.map +1 -1
- package/dist/Condition.js.map +1 -1
- package/dist/Debug.d.ts +127 -13
- package/dist/Debug.d.ts.map +1 -1
- package/dist/Descriptor.d.ts +61 -10
- package/dist/Descriptor.d.ts.map +1 -1
- package/dist/Descriptor.js +22 -10
- package/dist/Descriptor.js.map +1 -1
- package/dist/Entity.d.ts +22 -7
- package/dist/Entity.d.ts.map +1 -1
- package/dist/Entity.js.map +1 -1
- package/dist/EntityScope.d.ts +20 -1
- package/dist/EntityScope.d.ts.map +1 -1
- package/dist/EntityScope.js +8 -2
- package/dist/EntityScope.js.map +1 -1
- package/dist/FixedLoop.d.ts +106 -0
- package/dist/FixedLoop.d.ts.map +1 -0
- package/dist/FixedLoop.js +97 -0
- package/dist/FixedLoop.js.map +1 -0
- package/dist/HostClock.d.ts +1 -1
- package/dist/HostClock.d.ts.map +1 -1
- package/dist/HostClock.js +2 -1
- package/dist/HostClock.js.map +1 -1
- package/dist/Machine.d.ts +59 -34
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +10 -3
- package/dist/Machine.js.map +1 -1
- package/dist/Query.d.ts +100 -14
- package/dist/Query.d.ts.map +1 -1
- package/dist/Query.js +34 -5
- package/dist/Query.js.map +1 -1
- package/dist/Relation.d.ts +5 -14
- package/dist/Relation.d.ts.map +1 -1
- package/dist/Relation.js +0 -32
- package/dist/Relation.js.map +1 -1
- package/dist/Runtime.d.ts +61 -15
- package/dist/Runtime.d.ts.map +1 -1
- package/dist/Runtime.js +594 -70
- package/dist/Runtime.js.map +1 -1
- package/dist/Schedule.d.ts +24 -15
- package/dist/Schedule.d.ts.map +1 -1
- package/dist/Schedule.js +2 -1
- package/dist/Schedule.js.map +1 -1
- package/dist/Schema.d.ts +233 -48
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +33 -7
- package/dist/Schema.js.map +1 -1
- package/dist/Snapshot.d.ts +90 -1
- package/dist/Snapshot.d.ts.map +1 -1
- package/dist/Snapshot.js +42 -1
- package/dist/Snapshot.js.map +1 -1
- package/dist/System.d.ts +132 -31
- package/dist/System.d.ts.map +1 -1
- package/dist/System.js +32 -0
- package/dist/System.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/cells.d.ts +2 -0
- package/dist/internal/cells.d.ts.map +1 -1
- package/dist/internal/cells.js +34 -8
- package/dist/internal/cells.js.map +1 -1
- package/dist/internal/debug.d.ts +10 -0
- package/dist/internal/debug.d.ts.map +1 -1
- package/dist/internal/debug.js +171 -12
- package/dist/internal/debug.js.map +1 -1
- package/dist/internal/equal.d.ts +8 -0
- package/dist/internal/equal.d.ts.map +1 -0
- package/dist/internal/equal.js +38 -0
- package/dist/internal/equal.js.map +1 -0
- package/dist/internal/fragments.d.ts +2 -6
- package/dist/internal/fragments.d.ts.map +1 -1
- package/dist/internal/fragments.js +36 -3
- package/dist/internal/fragments.js.map +1 -1
- package/dist/internal/game.d.ts +2 -0
- package/dist/internal/game.d.ts.map +1 -1
- package/dist/internal/game.js +48 -7
- package/dist/internal/game.js.map +1 -1
- package/dist/internal/order.d.ts.map +1 -1
- package/dist/internal/order.js +4 -2
- package/dist/internal/order.js.map +1 -1
- package/dist/internal/queries.d.ts.map +1 -1
- package/dist/internal/queries.js +57 -26
- package/dist/internal/queries.js.map +1 -1
- package/dist/internal/relations.d.ts +10 -0
- package/dist/internal/relations.d.ts.map +1 -0
- package/dist/internal/relations.js +32 -0
- package/dist/internal/relations.js.map +1 -0
- package/dist/internal/requirements.d.ts +26 -0
- package/dist/internal/requirements.d.ts.map +1 -0
- package/dist/internal/requirements.js +46 -0
- package/dist/internal/requirements.js.map +1 -0
- package/dist/internal/streams.d.ts +2 -0
- package/dist/internal/streams.d.ts.map +1 -1
- package/dist/internal/streams.js +10 -0
- package/dist/internal/streams.js.map +1 -1
- package/dist/internal/world.d.ts +7 -1
- package/dist/internal/world.d.ts.map +1 -1
- package/dist/internal/world.js +53 -3
- package/dist/internal/world.js.map +1 -1
- package/package.json +1 -1
- package/src/Clock.ts +29 -4
- package/src/Command.ts +281 -67
- package/src/Condition.ts +17 -1
- package/src/Debug.ts +124 -15
- package/src/Descriptor.ts +92 -21
- package/src/Entity.ts +23 -7
- package/src/EntityScope.ts +21 -2
- package/src/FixedLoop.ts +218 -0
- package/src/HostClock.ts +2 -1
- package/src/Machine.ts +72 -35
- package/src/Query.ts +118 -17
- package/src/Relation.ts +5 -67
- package/src/Runtime.ts +659 -85
- package/src/Schedule.ts +31 -19
- package/src/Schema.ts +297 -57
- package/src/Snapshot.ts +94 -2
- package/src/System.ts +151 -29
- package/src/index.ts +4 -0
- package/src/internal/cells.ts +42 -10
- package/src/internal/debug.ts +179 -14
- package/src/internal/equal.ts +31 -0
- package/src/internal/fragments.ts +35 -5
- package/src/internal/game.ts +69 -7
- package/src/internal/order.ts +8 -4
- package/src/internal/queries.ts +62 -12
- package/src/internal/relations.ts +52 -0
- package/src/internal/requirements.ts +71 -0
- package/src/internal/streams.ts +11 -0
- package/src/internal/world.ts +60 -4
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import * as Result from "./Result.js";
|
|
2
|
+
/** Wraps a host-specific subscription function in the canonical source type. */
|
|
3
|
+
export const source = (subscribe) => ({ subscribe });
|
|
4
|
+
const validate = (options) => {
|
|
5
|
+
for (const field of ["maxFrameSeconds"]) {
|
|
6
|
+
const value = options[field];
|
|
7
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
8
|
+
return Result.failure({
|
|
9
|
+
kind: "InvalidFixedLoopOptions",
|
|
10
|
+
field,
|
|
11
|
+
reason: "mustBeFiniteAndPositive",
|
|
12
|
+
value
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (!Number.isInteger(options.maxStepsPerFrame) || options.maxStepsPerFrame <= 0) {
|
|
17
|
+
return Result.failure({
|
|
18
|
+
kind: "InvalidFixedLoopOptions",
|
|
19
|
+
field: "maxStepsPerFrame",
|
|
20
|
+
reason: "mustBePositiveInteger",
|
|
21
|
+
value: options.maxStepsPerFrame
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return Result.success(undefined);
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Starts a fixed-step loop after validating its timing policy.
|
|
28
|
+
*
|
|
29
|
+
* Update failures and malformed host ticks are delivered to `onFailure`, then
|
|
30
|
+
* the driver stops. Render defects are deliberately not caught: they are
|
|
31
|
+
* programmer defects, not expected game outcomes.
|
|
32
|
+
*/
|
|
33
|
+
export const start = (options) => {
|
|
34
|
+
const validity = validate(options);
|
|
35
|
+
if (!validity.ok) {
|
|
36
|
+
return validity;
|
|
37
|
+
}
|
|
38
|
+
let accumulator = 0;
|
|
39
|
+
let stopped = false;
|
|
40
|
+
let hostSubscription;
|
|
41
|
+
const stop = () => {
|
|
42
|
+
if (stopped) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
stopped = true;
|
|
46
|
+
hostSubscription?.stop();
|
|
47
|
+
};
|
|
48
|
+
const fail = (failure) => {
|
|
49
|
+
stop();
|
|
50
|
+
options.onFailure(failure);
|
|
51
|
+
};
|
|
52
|
+
const onTick = (tick) => {
|
|
53
|
+
if (stopped) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (!Number.isFinite(tick.deltaMS) || tick.deltaMS < 0) {
|
|
57
|
+
fail({ kind: "InvalidTickDelta", deltaMS: tick.deltaMS });
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const rawSeconds = tick.deltaMS / 1000;
|
|
61
|
+
const elapsedSeconds = Math.min(rawSeconds, options.maxFrameSeconds);
|
|
62
|
+
let droppedSeconds = rawSeconds - elapsedSeconds;
|
|
63
|
+
accumulator += elapsedSeconds;
|
|
64
|
+
let fixedSteps = 0;
|
|
65
|
+
while (accumulator >= options.step.dt && fixedSteps < options.maxStepsPerFrame) {
|
|
66
|
+
const update = options.update(options.step.dt);
|
|
67
|
+
if (!update.ok) {
|
|
68
|
+
fail({ kind: "UpdateFailure", error: update.error });
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
accumulator -= options.step.dt;
|
|
72
|
+
fixedSteps += 1;
|
|
73
|
+
}
|
|
74
|
+
if (accumulator >= options.step.dt) {
|
|
75
|
+
const droppedWholeSteps = Math.floor(accumulator / options.step.dt) * options.step.dt;
|
|
76
|
+
accumulator -= droppedWholeSteps;
|
|
77
|
+
droppedSeconds += droppedWholeSteps;
|
|
78
|
+
}
|
|
79
|
+
options.render({
|
|
80
|
+
elapsedSeconds,
|
|
81
|
+
fixedSteps,
|
|
82
|
+
alpha: accumulator / options.step.dt,
|
|
83
|
+
droppedSeconds
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
hostSubscription = options.source.subscribe(onTick);
|
|
87
|
+
if (stopped) {
|
|
88
|
+
hostSubscription.stop();
|
|
89
|
+
}
|
|
90
|
+
return Result.success({
|
|
91
|
+
stop,
|
|
92
|
+
reset() {
|
|
93
|
+
accumulator = 0;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
//# sourceMappingURL=FixedLoop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FixedLoop.js","sourceRoot":"","sources":["../src/FixedLoop.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AA+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KAAK,EAAE,CAAC,CAAA;gBACpD,OAAM;YACR,CAAC;YACD,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,EAAE,CAAA;YAC9B,UAAU,IAAI,CAAC,CAAA;QACjB,CAAC;QAED,IAAI,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YACnC,MAAM,iBAAiB,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,EAAE,CAAA;YACrF,WAAW,IAAI,iBAAiB,CAAA;YAChC,cAAc,IAAI,iBAAiB,CAAA;QACrC,CAAC;QAED,OAAO,CAAC,MAAM,CAAC;YACb,cAAc;YACd,UAAU;YACV,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,EAAE;YACpC,cAAc;SACf,CAAC,CAAA;IACJ,CAAC,CAAA;IAED,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;IACnD,IAAI,OAAO,EAAE,CAAC;QACZ,gBAAgB,CAAC,IAAI,EAAE,CAAA;IACzB,CAAC;IAED,OAAO,MAAM,CAAC,OAAO,CAAC;QACpB,IAAI;QACJ,KAAK;YACH,WAAW,GAAG,CAAC,CAAA;QACjB,CAAC;KACF,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
package/dist/HostClock.d.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```ts
|
|
16
|
-
* const runtime = Game.Runtime.make({ services, debug: { hostClock: HostClock.standard } })
|
|
16
|
+
* const runtime = Game.Runtime.make({ services, debug: { hostClock: HostClock.standard } }).value
|
|
17
17
|
* ```
|
|
18
18
|
*
|
|
19
19
|
* @module HostClock
|
package/dist/HostClock.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HostClock.d.ts","sourceRoot":"","sources":["../src/HostClock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC,uEAAuE;AACvE,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,MAAM,CAAA;CAC3B;AAED;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"HostClock.d.ts","sourceRoot":"","sources":["../src/HostClock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC,uEAAuE;AACvE,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,MAAM,CAAA;CAC3B;AAED;;;;;;GAMG;AAEH,eAAO,MAAM,QAAQ,EAAE,SAAqC,CAAA;AAE5D,2EAA2E;AAC3E,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAA;IAClC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CACpB;AAED,6EAA6E;AAC7E,MAAM,WAAW,aAAc,SAAQ,SAAS;IAC9C,mDAAmD;IACnD,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAA;CACxE;AAED,4EAA4E;AAC5E,eAAO,MAAM,IAAI,QAAO,aAUvB,CAAA;AAED,mFAAmF;AACnF,eAAO,MAAM,OAAO,SAAU,MAAM,MAAM,MAAM,KAAG,MAAgC,CAAA"}
|
package/dist/HostClock.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```ts
|
|
16
|
-
* const runtime = Game.Runtime.make({ services, debug: { hostClock: HostClock.standard } })
|
|
16
|
+
* const runtime = Game.Runtime.make({ services, debug: { hostClock: HostClock.standard } }).value
|
|
17
17
|
* ```
|
|
18
18
|
*
|
|
19
19
|
* @module HostClock
|
|
@@ -27,6 +27,7 @@ import * as Result from "./Result.js";
|
|
|
27
27
|
* 0. Prefer a monotonic platform clock when there is one
|
|
28
28
|
* (`BrowserHostClock.make(window)`).
|
|
29
29
|
*/
|
|
30
|
+
// oxlint-disable-next-line ritmo/use-clock-for-time -- HostClock is host time, for hosts and tools; systems read Clock.
|
|
30
31
|
export const standard = { now: () => Date.now() };
|
|
31
32
|
/** A test clock at 0. Every reading is the same until `adjust` moves it. */
|
|
32
33
|
export const test = () => {
|
package/dist/HostClock.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HostClock.js","sourceRoot":"","sources":["../src/HostClock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAOrC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAc,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,CAAA;AAc5D,4EAA4E;AAC5E,MAAM,CAAC,MAAM,IAAI,GAAG,GAAkB,EAAE;IACtC,IAAI,OAAO,GAAG,CAAC,CAAA;IACf,OAAO;QACL,GAAG,EAAE,GAAG,EAAE,CAAC,OAAO;QAClB,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE;YACb,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,GAAG,EAAE,CAAC;gBAAE,OAAO,MAAM,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,EAAE,EAAE,CAAC,CAAA;YAC9H,OAAO,IAAI,EAAE,CAAA;YACb,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;QAClC,CAAC;KACF,CAAA;AACH,CA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
39
39
|
*/
|
|
40
40
|
import type { AnyScheduleOrder, Schedule } from "./Schedule.ts";
|
|
41
41
|
import * as Requirement from "./Requirement.ts";
|
|
42
|
+
import type * as Result from "./Result.ts";
|
|
42
43
|
import type { Schema } from "./Schema.ts";
|
|
43
44
|
import type { SystemFailure } from "./System.ts";
|
|
44
45
|
/**
|
|
@@ -51,54 +52,62 @@ export type StateValue = string | number;
|
|
|
51
52
|
/**
|
|
52
53
|
* One schema-bound finite state machine definition.
|
|
53
54
|
*/
|
|
54
|
-
export interface StateMachineDefinition<out Name extends string = string, out Values extends readonly [StateValue, ...StateValue[]] = readonly [StateValue, ...StateValue[]], out Root = unknown> {
|
|
55
|
+
export interface StateMachineDefinition<out Name extends string = string, out Values extends readonly [StateValue, ...StateValue[]] = readonly [StateValue, ...StateValue[]], out Root = unknown, out Parent = unknown> {
|
|
55
56
|
readonly kind: "stateMachine";
|
|
56
57
|
readonly name: Name;
|
|
57
58
|
readonly key: symbol;
|
|
58
59
|
readonly values: Values;
|
|
60
|
+
/** For a sub-state: the machine and the state it exists in. */
|
|
61
|
+
readonly within?: SubStateParent | undefined;
|
|
59
62
|
readonly __schemaRoot?: Root | undefined;
|
|
63
|
+
/** The machine a sub-state exists within; `unknown` for a top-level machine. */
|
|
64
|
+
readonly __parent?: (_: never) => Parent;
|
|
65
|
+
}
|
|
66
|
+
/** Where a sub-state exists: while `machine` is in `state`. */
|
|
67
|
+
export interface SubStateParent {
|
|
68
|
+
readonly machine: StateMachine.Any;
|
|
69
|
+
readonly state: StateValue;
|
|
60
70
|
}
|
|
61
71
|
/**
|
|
62
|
-
*
|
|
72
|
+
* Whether `M` is a sub-state (declared with `within`): it has no value while
|
|
73
|
+
* its parent machine is in another state.
|
|
63
74
|
*/
|
|
64
|
-
export
|
|
65
|
-
readonly
|
|
66
|
-
|
|
67
|
-
}
|
|
75
|
+
export type IsSubState<M> = M extends {
|
|
76
|
+
readonly __parent?: (_: never) => infer Parent;
|
|
77
|
+
} ? unknown extends Parent ? false : true : false;
|
|
68
78
|
/**
|
|
69
|
-
* A
|
|
79
|
+
* The committed value of `M`. A sub-state has none (`undefined`) while its
|
|
80
|
+
* parent machine is not in the state it exists in; a top-level machine
|
|
81
|
+
* always has one.
|
|
70
82
|
*/
|
|
71
|
-
export
|
|
72
|
-
get(): StateMachine.Value<M>;
|
|
73
|
-
is(value: StateMachine.Value<M>): boolean;
|
|
74
|
-
}
|
|
83
|
+
export type CurrentValue<M extends StateMachine.Any> = IsSubState<M> extends true ? StateMachine.Value<M> | undefined : StateMachine.Value<M>;
|
|
75
84
|
/**
|
|
76
|
-
*
|
|
85
|
+
* Why queuing a sub-state's next value failed: its parent machine is not in
|
|
86
|
+
* the state the sub-state exists in, so there is nothing to change.
|
|
77
87
|
*/
|
|
78
|
-
export interface
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
88
|
+
export interface SubStateInactive {
|
|
89
|
+
readonly _tag: "SubStateInactive";
|
|
90
|
+
/** The sub-state's name. */
|
|
91
|
+
readonly machine: string;
|
|
92
|
+
/** The parent machine's name. */
|
|
93
|
+
readonly parent: string;
|
|
94
|
+
/** The parent state the sub-state exists in. */
|
|
95
|
+
readonly requires: StateValue;
|
|
83
96
|
}
|
|
84
97
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* only exposed to systems that explicitly declare transition access.
|
|
98
|
+
* What `nextMachines.x.set(...)` returns: nothing for a top-level machine,
|
|
99
|
+
* and for a sub-state a `Result` that fails with `SubStateInactive` when its
|
|
100
|
+
* parent is in another state.
|
|
89
101
|
*/
|
|
90
|
-
export
|
|
91
|
-
get(): TransitionSnapshot<M>;
|
|
92
|
-
}
|
|
102
|
+
export type SetResult<M extends StateMachine.Any> = IsSubState<M> extends true ? Result.Result<void, SubStateInactive> : void;
|
|
93
103
|
/**
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* transition commits. Like events, each reader sees the transitions published
|
|
98
|
-
* since its own previous run.
|
|
104
|
+
* The runtime-visible transition payload for one machine. For a sub-state,
|
|
105
|
+
* `from` is `undefined` when it starts existing (its parent entered its
|
|
106
|
+
* state) and `to` is `undefined` when it stops.
|
|
99
107
|
*/
|
|
100
|
-
export interface
|
|
101
|
-
|
|
108
|
+
export interface TransitionSnapshot<M extends StateMachineDefinition = StateMachineDefinition> {
|
|
109
|
+
readonly from: CurrentValue<M>;
|
|
110
|
+
readonly to: CurrentValue<M>;
|
|
102
111
|
}
|
|
103
112
|
/**
|
|
104
113
|
* Read access to the current committed state in a system spec.
|
|
@@ -213,12 +222,22 @@ export interface TransitionScheduleDefinition<S extends Schema.Any = Schema.Any,
|
|
|
213
222
|
* Type-level and value-level helpers for finite-state machines.
|
|
214
223
|
*/
|
|
215
224
|
export declare namespace StateMachine {
|
|
216
|
-
type Any = StateMachineDefinition<string, readonly [StateValue, ...StateValue[]], unknown>;
|
|
225
|
+
type Any = StateMachineDefinition<string, readonly [StateValue, ...StateValue[]], unknown, unknown>;
|
|
217
226
|
type Value<M extends Any> = M["values"][number];
|
|
218
227
|
type Root<M extends Any> = M extends StateMachineDefinition<string, readonly [StateValue, ...StateValue[]], infer R> ? R : never;
|
|
219
228
|
type AnyCondition<Root = unknown> = Condition<Root>;
|
|
220
229
|
type AnyTransitionSchedule<S extends Schema.Any = Schema.Any, Root = unknown> = TransitionScheduleDefinition<S, Any, Requirement.Requirement, Root, SystemFailure>;
|
|
221
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* `unknown` when `M` was defined by the game rooted at `Root`; otherwise a
|
|
233
|
+
* type naming the fix, so passing another game's machine fails with that
|
|
234
|
+
* message.
|
|
235
|
+
*/
|
|
236
|
+
export type SameGame<M, Root> = M extends StateMachineDefinition<infer Name, readonly [StateValue, ...StateValue[]], infer MachineRoot> ? [Root] extends [MachineRoot] ? [MachineRoot] extends [Root] ? unknown : ForeignMachine<`${Name} is a state machine of another game: use a machine defined with this game's Game.StateMachine(...)`> : ForeignMachine<`${Name} is a state machine of another game: use a machine defined with this game's Game.StateMachine(...)`> : unknown;
|
|
237
|
+
/** The message type `SameGame` resolves to: a type error prints `Message`. */
|
|
238
|
+
type ForeignMachine<Message extends string> = {
|
|
239
|
+
readonly __foreignMachine__: Message;
|
|
240
|
+
};
|
|
222
241
|
/** Extracts the machine token from one declared machine access slot. */
|
|
223
242
|
type MachineFromAccess<Access> = Access extends {
|
|
224
243
|
readonly machine: infer M extends StateMachine.Any;
|
|
@@ -253,8 +272,11 @@ export type MachineNeedsFromConditions<C extends ReadonlyArray<Condition>> = Mac
|
|
|
253
272
|
*
|
|
254
273
|
* Use `Descriptor.EntityState(...)` instead when every entity carries its own
|
|
255
274
|
* state (per-entity, written immediately, no enter/exit schedules).
|
|
275
|
+
*
|
|
276
|
+
* Pass `within` for a sub-state: a machine that exists only while another
|
|
277
|
+
* machine is in one state (`Game.StateMachine(name, values, { within })`).
|
|
256
278
|
*/
|
|
257
|
-
export declare const StateMachine: <const Name extends string, const Values extends readonly [StateValue, ...StateValue[]], Root = unknown>(name: Name, values: Values) => StateMachineDefinition<Name, Values, Root>;
|
|
279
|
+
export declare const StateMachine: <const Name extends string, const Values extends readonly [StateValue, ...StateValue[]], Root = unknown>(name: Name, values: Values, within?: SubStateParent) => StateMachineDefinition<Name, Values, Root>;
|
|
258
280
|
/**
|
|
259
281
|
* Declares that a system wants to read the current committed state.
|
|
260
282
|
*
|
|
@@ -289,7 +311,10 @@ export declare const readTransitionEvent: <M extends StateMachine.Any>(machine:
|
|
|
289
311
|
*/
|
|
290
312
|
export declare const inState: <M extends StateMachine.Any>(machine: M, value: StateMachine.Value<M>) => InStateCondition<M>;
|
|
291
313
|
/**
|
|
292
|
-
* Creates a condition that passes when the machine changed during the current schedule execution
|
|
314
|
+
* Creates a condition that passes when the machine changed during the current schedule execution:
|
|
315
|
+
* from the `applyStateTransitions(...)` that committed the change to the end of
|
|
316
|
+
* that schedule (or the next `applyStateTransitions(...)`), not for the rest of
|
|
317
|
+
* the tick call or the next schedule.
|
|
293
318
|
*/
|
|
294
319
|
export declare const stateChanged: <M extends StateMachine.Any>(machine: M) => StateChangedCondition<M>;
|
|
295
320
|
/**
|
package/dist/Machine.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Machine.d.ts","sourceRoot":"","sources":["../src/Machine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC/D,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEhD;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,CAAA;AAExC;;GAEG;AACH,MAAM,WAAW,sBAAsB,CACrC,GAAG,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,EAChC,GAAG,CAAC,MAAM,SAAS,SAAS,CAAC,UAAU,EAAE,GAAG,UAAU,EAAE,CAAC,GAAG,SAAS,CAAC,UAAU,EAAE,GAAG,UAAU,EAAE,CAAC,EAClG,GAAG,CAAC,IAAI,GAAG,OAAO;
|
|
1
|
+
{"version":3,"file":"Machine.d.ts","sourceRoot":"","sources":["../src/Machine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC/D,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAC/C,OAAO,KAAK,KAAK,MAAM,MAAM,aAAa,CAAA;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KA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;AACH,eAAO,MAAM,OAAO,GAAI,CAAC,SAAS,YAAY,CAAC,GAAG,WACvC,CAAC,SACH,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,KAC3B,gBAAgB,CAAC,CAAC,CAKnB,CAAA;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,YAAY,CAAC,GAAG,WAC5C,CAAC,KACT,qBAAqB,CAAC,CAAC,CAIxB,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,GAAG,GAAI,CAAC,SAAS,SAAS,aAAa,CAAC,KAAG,YAAY,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAIvF,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,GAAG,GAAI,KAAK,CAAC,CAAC,SAAS,aAAa,CAAC,SAAS,CAAC,iBAAiB,CAAC,KAAG,YAAY,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAIxH,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,EAAE,GAAI,KAAK,CAAC,CAAC,SAAS,aAAa,CAAC,SAAS,CAAC,iBAAiB,CAAC,KAAG,WAAW,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAItH,CAAA"}
|
package/dist/Machine.js
CHANGED
|
@@ -14,12 +14,16 @@ import * as Requirement from "./Requirement.js";
|
|
|
14
14
|
*
|
|
15
15
|
* Use `Descriptor.EntityState(...)` instead when every entity carries its own
|
|
16
16
|
* state (per-entity, written immediately, no enter/exit schedules).
|
|
17
|
+
*
|
|
18
|
+
* Pass `within` for a sub-state: a machine that exists only while another
|
|
19
|
+
* machine is in one state (`Game.StateMachine(name, values, { within })`).
|
|
17
20
|
*/
|
|
18
|
-
export const StateMachine = (name, values) => ({
|
|
21
|
+
export const StateMachine = (name, values, within) => ({
|
|
19
22
|
kind: "stateMachine",
|
|
20
23
|
name,
|
|
21
24
|
key: Symbol.for(`ritmo/stateMachine/${name}`),
|
|
22
|
-
values
|
|
25
|
+
values,
|
|
26
|
+
...(within === undefined ? {} : { within })
|
|
23
27
|
});
|
|
24
28
|
/**
|
|
25
29
|
* Declares that a system wants to read the current committed state.
|
|
@@ -68,7 +72,10 @@ export const inState = (machine, value) => ({
|
|
|
68
72
|
requirements: [machine]
|
|
69
73
|
});
|
|
70
74
|
/**
|
|
71
|
-
* Creates a condition that passes when the machine changed during the current schedule execution
|
|
75
|
+
* Creates a condition that passes when the machine changed during the current schedule execution:
|
|
76
|
+
* from the `applyStateTransitions(...)` that committed the change to the end of
|
|
77
|
+
* that schedule (or the next `applyStateTransitions(...)`), not for the rest of
|
|
78
|
+
* the tick call or the next schedule.
|
|
72
79
|
*/
|
|
73
80
|
export const stateChanged = (machine) => ({
|
|
74
81
|
kind: "stateChanged",
|
package/dist/Machine.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Machine.js","sourceRoot":"","sources":["../src/Machine.ts"],"names":[],"mappings":"AAwCA,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"Machine.js","sourceRoot":"","sources":["../src/Machine.ts"],"names":[],"mappings":"AAwCA,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAkS/C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAK1B,IAAU,EACV,MAAc,EACd,MAAuB,EACqB,EAAE,CAAC,CAAC;IAChD,IAAI,EAAE,cAAc;IACpB,IAAI;IACJ,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,sBAAsB,IAAI,EAAE,CAAC;IAC7C,MAAM;IACN,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5C,CAA+C,CAAA;AAEhD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAA6B,OAAU,E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AAA;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,EAAE,GAAG,CAA2C,GAAG,UAAa,EAA6C,EAAE,CAAC,CAAC;IAC5H,IAAI,EAAE,IAAI;IACV,UAAU;IACV,YAAY,EAAE,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;CAC7F,CAAC,CAAA"}
|
package/dist/Query.d.ts
CHANGED
|
@@ -69,6 +69,7 @@
|
|
|
69
69
|
* Query authoring helpers for selecting components and declaring explicit filters.
|
|
70
70
|
*/
|
|
71
71
|
import type { DecodeError } from "./Decode.ts";
|
|
72
|
+
import * as DescriptorModule from "./Descriptor.ts";
|
|
72
73
|
import type { Descriptor, EntityStateValue } from "./Descriptor.ts";
|
|
73
74
|
import type { EntityId, EntityMut, EntityRef } from "./Entity.ts";
|
|
74
75
|
import type * as Result from "./Result.ts";
|
|
@@ -163,7 +164,17 @@ export interface ChangedFilter<D extends ComponentDescriptor> {
|
|
|
163
164
|
readonly kind: "changed";
|
|
164
165
|
readonly descriptor: D;
|
|
165
166
|
}
|
|
166
|
-
|
|
167
|
+
/** An `added` or `changed` filter: the filters `anyOf` combines. */
|
|
168
|
+
export type LifecycleFilter<D extends ComponentDescriptor> = AddedFilter<D> | ChangedFilter<D>;
|
|
169
|
+
/**
|
|
170
|
+
* A filter that matches entities passing at least one of its `added` /
|
|
171
|
+
* `changed` filters since the reading system's previous run.
|
|
172
|
+
*/
|
|
173
|
+
export interface AnyOfFilter<D extends ComponentDescriptor> {
|
|
174
|
+
readonly kind: "anyOf";
|
|
175
|
+
readonly filters: ReadonlyArray<LifecycleFilter<D>>;
|
|
176
|
+
}
|
|
177
|
+
export type Filter<D extends ComponentDescriptor> = LifecycleFilter<D> | AnyOfFilter<D>;
|
|
167
178
|
/**
|
|
168
179
|
* Declares read-only access to a component in a query selection.
|
|
169
180
|
*
|
|
@@ -180,8 +191,21 @@ export declare const read: <D extends ComponentDescriptor>(descriptor: D) => Rea
|
|
|
180
191
|
* place. A write slot both requires component presence and exposes the slot as
|
|
181
192
|
* a `WriteCell`, so mutation capability stays visible in the query spec rather
|
|
182
193
|
* than appearing ad hoc in the loop body.
|
|
194
|
+
*
|
|
195
|
+
* Components declared `immutable: true` cannot be written: replace them with
|
|
196
|
+
* `commands.insert(...)` instead.
|
|
197
|
+
*/
|
|
198
|
+
export declare const write: <D extends ComponentDescriptor>(descriptor: D & Writable<D>) => WriteAccess<D>;
|
|
199
|
+
type NameOf<D> = D extends {
|
|
200
|
+
readonly name: infer Name extends string;
|
|
201
|
+
} ? Name : never;
|
|
202
|
+
/**
|
|
203
|
+
* `unknown` for a component a query may write; for one declared
|
|
204
|
+
* `immutable: true`, an argument error naming the fix.
|
|
183
205
|
*/
|
|
184
|
-
export
|
|
206
|
+
export type Writable<D> = D extends DescriptorModule.Immutable ? {
|
|
207
|
+
readonly __immutable__: `${NameOf<D>} is immutable: replace it with commands.insert(entity, Game.Command.entry(${NameOf<D>}, ...))`;
|
|
208
|
+
} : unknown;
|
|
185
209
|
/**
|
|
186
210
|
* Declares maybe-present read-only access to a component in a query
|
|
187
211
|
* specification.
|
|
@@ -230,7 +254,8 @@ export declare const added: <D extends ComponentDescriptor>(descriptor: D) => Ad
|
|
|
230
254
|
*
|
|
231
255
|
* Any write through a write cell counts, even when the value is equal to the
|
|
232
256
|
* previous one. Writes from a system whose run failed are rolled back and do
|
|
233
|
-
* not count.
|
|
257
|
+
* not count. A system never sees its own writes as changes on its next run
|
|
258
|
+
* (it does see the events it emitted).
|
|
234
259
|
*
|
|
235
260
|
* @example
|
|
236
261
|
* ```ts
|
|
@@ -243,6 +268,24 @@ export declare const added: <D extends ComponentDescriptor>(descriptor: D) => Ad
|
|
|
243
268
|
* ```
|
|
244
269
|
*/
|
|
245
270
|
export declare const changed: <D extends ComponentDescriptor>(descriptor: D) => ChangedFilter<D>;
|
|
271
|
+
/**
|
|
272
|
+
* Declares a filter that matches entities passing at least one of `filters`
|
|
273
|
+
* (`added` / `changed`) since the reading system's previous run. Each entity
|
|
274
|
+
* is matched once, however many of its filters pass.
|
|
275
|
+
*
|
|
276
|
+
* Filters listed side by side in `filters: [...]` must all pass; use `anyOf`
|
|
277
|
+
* when any one of them is enough, for example to redraw when either the
|
|
278
|
+
* position or the sprite changed.
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```ts
|
|
282
|
+
* const RedrawQuery = Game.Query({
|
|
283
|
+
* selection: { position: Game.Query.read(Position), sprite: Game.Query.read(Sprite) },
|
|
284
|
+
* filters: [Game.Query.anyOf(Game.Query.changed(Position), Game.Query.changed(Sprite))]
|
|
285
|
+
* })
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
export declare const anyOf: <const Filters extends readonly [LifecycleFilter<ComponentDescriptor>, LifecycleFilter<ComponentDescriptor>, ...ReadonlyArray<LifecycleFilter<ComponentDescriptor>>]>(...filters: Filters) => AnyOfFilter<Filters[number]["descriptor"]>;
|
|
246
289
|
/**
|
|
247
290
|
* A fully explicit query specification.
|
|
248
291
|
*
|
|
@@ -303,6 +346,10 @@ export declare namespace Query {
|
|
|
303
346
|
* Extracts the schema-root brand carried by one query.
|
|
304
347
|
*/
|
|
305
348
|
export type Root<T extends Any> = T extends QuerySpec<any, any, any, any, any, any, any, any, infer R> ? R : never;
|
|
349
|
+
type FilteredDescriptors<F> = F extends {
|
|
350
|
+
readonly kind: "added" | "changed";
|
|
351
|
+
readonly descriptor: infer D;
|
|
352
|
+
} ? D : never;
|
|
306
353
|
type RequiredSelectionDescriptors<T extends Any> = {
|
|
307
354
|
readonly [K in keyof T["selection"]]: T["selection"][K] extends ReadAccess<infer D> | WriteAccess<infer D> ? D : never;
|
|
308
355
|
}[keyof T["selection"]];
|
|
@@ -312,9 +359,15 @@ export declare namespace Query {
|
|
|
312
359
|
* This is used by durable-handle resolution so intent-qualified handles can
|
|
313
360
|
* only be resolved with queries that actually prove the intended role.
|
|
314
361
|
*/
|
|
315
|
-
export type ProvesComponent<T extends Any, D extends ComponentDescriptor> = [Extract<
|
|
316
|
-
/**
|
|
317
|
-
|
|
362
|
+
export type ProvesComponent<T extends Any, D extends ComponentDescriptor> = [Extract<Proven<T>, D>] extends [never] ? false : true;
|
|
363
|
+
/**
|
|
364
|
+
* The component descriptors a query proves its matches have: required
|
|
365
|
+
* selection slots, `with`, and the component of each `added` / `changed`
|
|
366
|
+
* filter (a match has it). A `Query.anyOf` member proves nothing alone.
|
|
367
|
+
*/
|
|
368
|
+
export type Proven<T extends Any> = RequiredSelectionDescriptors<T> | T["with"][number] | FilteredDescriptors<T["filters"][number]>;
|
|
369
|
+
/** The component descriptors a query proves its matches lack: its `without`. */
|
|
370
|
+
export type Excluded<T extends Any> = T["without"][number];
|
|
318
371
|
/**
|
|
319
372
|
* The readable proof produced by a query.
|
|
320
373
|
*/
|
|
@@ -399,13 +452,14 @@ export interface ReadCell<T> {
|
|
|
399
452
|
*/
|
|
400
453
|
export interface WriteCell<T> extends ReadCell<T> {
|
|
401
454
|
/**
|
|
402
|
-
* Replaces the current value.
|
|
455
|
+
* Replaces the current value. Takes the readonly shape reads return, so a
|
|
456
|
+
* value read from any cell can be written back as it is.
|
|
403
457
|
*/
|
|
404
|
-
set(value: T): void;
|
|
458
|
+
set(value: ReadonlyValue<T>): void;
|
|
405
459
|
/**
|
|
406
460
|
* Updates the current value based on the previous one.
|
|
407
461
|
*/
|
|
408
|
-
update(f: (current: ReadonlyValue<T>) => T): void;
|
|
462
|
+
update(f: (current: ReadonlyValue<T>) => ReadonlyValue<T>): void;
|
|
409
463
|
}
|
|
410
464
|
/**
|
|
411
465
|
* Writable cell for data backed by a constructed descriptor.
|
|
@@ -460,7 +514,10 @@ export interface EntityStateMismatchError<T> {
|
|
|
460
514
|
*/
|
|
461
515
|
export interface EntityStateWriteCell<T, Transitions> extends ConstructedWriteCell<T, T, DecodeError> {
|
|
462
516
|
/**
|
|
463
|
-
* Moves from `from` to `to` if the component is still in `from`.
|
|
517
|
+
* Moves from `from` to `to` if the component is still in `from`. Use it for
|
|
518
|
+
* every move the transition table describes; `set` writes any state
|
|
519
|
+
* without checking the table, for resets that must not depend on the
|
|
520
|
+
* current state.
|
|
464
521
|
*
|
|
465
522
|
* @example
|
|
466
523
|
* ```ts
|
|
@@ -484,17 +541,24 @@ export type WriteCellForDescriptor<D extends ComponentDescriptor> = D extends im
|
|
|
484
541
|
*/
|
|
485
542
|
export interface PresentOptionalReadCell<T> extends ReadCell<T> {
|
|
486
543
|
readonly present: true;
|
|
544
|
+
/** The value, which is present. */
|
|
545
|
+
value(): T;
|
|
487
546
|
}
|
|
488
547
|
/**
|
|
489
548
|
* Absent branch for a maybe-present query slot.
|
|
490
549
|
*/
|
|
491
550
|
export interface AbsentOptionalReadCell {
|
|
492
551
|
readonly present: false;
|
|
552
|
+
/** `undefined`: the entity does not hold the component. */
|
|
553
|
+
value(): undefined;
|
|
493
554
|
}
|
|
494
555
|
/**
|
|
495
556
|
* A query slot that may or may not be present on the matched entity.
|
|
496
557
|
*
|
|
497
|
-
*
|
|
558
|
+
* Read it with `value()`: the value, or `undefined` when the entity does not
|
|
559
|
+
* hold the component. Narrow on `present` (then `get()`) only when the
|
|
560
|
+
* component's own value can be `undefined`, where `value()` cannot tell the
|
|
561
|
+
* two apart.
|
|
498
562
|
*/
|
|
499
563
|
export type OptionalReadCell<T> = PresentOptionalReadCell<T> | AbsentOptionalReadCell;
|
|
500
564
|
/**
|
|
@@ -504,10 +568,10 @@ export type OptionalReadCell<T> = PresentOptionalReadCell<T> | AbsentOptionalRea
|
|
|
504
568
|
* Otherwise it remains read-only.
|
|
505
569
|
*/
|
|
506
570
|
export type QueryMatch<S extends Schema.Any, Q extends Query.Any> = keyof Query.WriteProof<Q> extends never ? {
|
|
507
|
-
readonly entity: EntityRef<S, Query.ReadProof<Q>, Query.Root<Q>, Query.Proven<Q>>;
|
|
571
|
+
readonly entity: EntityRef<S, Query.ReadProof<Q>, Query.Root<Q>, Query.Proven<Q>, Query.Excluded<Q>>;
|
|
508
572
|
readonly data: Query.Cells<Q>;
|
|
509
573
|
} : {
|
|
510
|
-
readonly entity: EntityMut<S, Query.ReadProof<Q>, Query.WriteProof<Q>, Query.Root<Q>, Query.Proven<Q>>;
|
|
574
|
+
readonly entity: EntityMut<S, Query.ReadProof<Q>, Query.WriteProof<Q>, Query.Root<Q>, Query.Proven<Q>, Query.Excluded<Q>>;
|
|
511
575
|
readonly data: Query.Cells<Q>;
|
|
512
576
|
};
|
|
513
577
|
/**
|
|
@@ -556,10 +620,32 @@ export declare const multipleEntitiesError: (count: number) => Query.MultipleEnt
|
|
|
556
620
|
* (`queries: { ... }` in a spec). Unlike `NoInfer`, it prints as `T`.
|
|
557
621
|
*/
|
|
558
622
|
export type Uninferred<T, Bound> = [T] extends [infer U extends Bound] ? U : never;
|
|
623
|
+
type DescriptorName<D> = D extends {
|
|
624
|
+
readonly name: infer Name extends string;
|
|
625
|
+
} ? Name : never;
|
|
626
|
+
/** The names a query requires: its read and write slots, `with`, and plain `added` / `changed` filters. */
|
|
627
|
+
type RequiredNames<Selection, With extends ReadonlyArray<unknown>, Filters extends ReadonlyArray<unknown>> = DescriptorName<{
|
|
628
|
+
readonly [K in keyof Selection]: Selection[K] extends {
|
|
629
|
+
readonly mode: "read" | "write";
|
|
630
|
+
readonly descriptor: infer D;
|
|
631
|
+
} ? D : never;
|
|
632
|
+
}[keyof Selection]> | DescriptorName<With[number]> | DescriptorName<Filters[number] extends infer F ? F extends {
|
|
633
|
+
readonly kind: "added" | "changed";
|
|
634
|
+
readonly descriptor: infer D;
|
|
635
|
+
} ? D : never : never>;
|
|
636
|
+
/**
|
|
637
|
+
* Rejects a `without` naming a component the query also requires: such a
|
|
638
|
+
* query can never match. Use it on the `without` list of a query spec.
|
|
639
|
+
*/
|
|
640
|
+
export type ExclusionsPossible<Selection, With extends ReadonlyArray<unknown>, Without extends ReadonlyArray<unknown>, Filters extends ReadonlyArray<unknown>> = [
|
|
641
|
+
Extract<DescriptorName<Without[number]>, RequiredNames<Selection, With, Filters>>
|
|
642
|
+
] extends [never] ? unknown : {
|
|
643
|
+
readonly __fixQuery__: `${Extract<DescriptorName<Without[number]>, RequiredNames<Selection, With, Filters>>} is both required and excluded (without): this query can never match; remove it from one side`;
|
|
644
|
+
};
|
|
559
645
|
export declare const Query: <const Selection extends Record<string, SelectionAccess<any, Root>>, const With extends ReadonlyArray<ComponentDescriptor> = [], const Without extends ReadonlyArray<ComponentDescriptor> = [], const Filters extends ReadonlyArray<Filter<ComponentDescriptor>> = [], const WithRelations extends ReadonlyArray<Relation.Relation.Any> = [], const WithoutRelations extends ReadonlyArray<Relation.Relation.Any> = [], const WithRelated extends ReadonlyArray<Relation.Relation.Any> = [], const WithoutRelated extends ReadonlyArray<Relation.Relation.Any> = [], Root = unknown>(spec: {
|
|
560
646
|
readonly selection: Selection;
|
|
561
647
|
readonly with?: With;
|
|
562
|
-
readonly without?: Without
|
|
648
|
+
readonly without?: Without & ExclusionsPossible<Selection, With, Without, Filters>;
|
|
563
649
|
readonly filters?: Filters;
|
|
564
650
|
readonly withRelations?: WithRelations;
|
|
565
651
|
readonly withoutRelations?: WithoutRelations;
|