@moku-labs/game 0.15.50 → 0.15.52
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/dist/app/page.d.mts +1 -1
- package/dist/app/system.d.mts +3 -3
- package/dist/app.d.mts +3 -3
- package/dist/app.mjs +1 -1
- package/dist/{assets-DIYDAar4.mjs → assets-BRTUagOC.mjs} +108 -74
- package/dist/assets.d.mts +3 -3
- package/dist/assets.mjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/{commands-B4bQrMk7.d.mts → commands-bfj6-tZt.d.mts} +5 -5
- package/dist/control.d.mts +4 -4
- package/dist/{define-3weG6IEb.d.mts → define-BGM6htbK.d.mts} +2 -2
- package/dist/{headless-oFoYPHp1.d.mts → headless-Bk4PtaMO.d.mts} +1 -1
- package/dist/{index-BMnrhJy2.d.mts → index-C26tRxC6.d.mts} +10 -8
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +1 -1
- package/dist/inspect.d.mts +6 -6
- package/dist/jsx-dev-runtime.d.mts +1 -1
- package/dist/jsx-runtime.d.mts +1 -1
- package/dist/{runtime-6XmgPNsS.d.mts → runtime-LI4Ixax6.d.mts} +1 -1
- package/dist/{src-D7vFymuY.mjs → src-raYLhvHh.mjs} +886 -221
- package/dist/testing.d.mts +4 -4
- package/dist/testing.mjs +1 -1
- package/dist/{types-B5tiMe_r.d.mts → types-B-njMbRn.d.mts} +4 -4
- package/dist/{types-BS0JBrBZ.d.mts → types-BnK1FqER.d.mts} +3066 -2900
- package/dist/{types-OvmeuFbz.d.mts → types-C5plKkdG.d.mts} +95 -3
- package/dist/{types-CEWtlmPp.d.mts → types-DJTRzq16.d.mts} +2 -2
- package/dist/{types-DPliH9lD.d.mts → types-ggSg0D6A.d.mts} +2 -2
- package/dist/{visual-BJ8-LEjY.d.mts → visual-C9qDbPW6.d.mts} +6 -6
- package/dist/visual.d.mts +1 -1
- package/llms.txt +31 -3
- package/package.json +1 -1
|
@@ -3273,13 +3273,103 @@ function createFxApi(ctx, deps) {
|
|
|
3273
3273
|
};
|
|
3274
3274
|
}
|
|
3275
3275
|
//#endregion
|
|
3276
|
-
//#region src/plugins/flow/
|
|
3276
|
+
//#region src/plugins/flow/guide.ts
|
|
3277
|
+
/**
|
|
3278
|
+
* Copies one answer into plain JSON. The `payload` key is absent when there is none, so the
|
|
3279
|
+
* descriptor survives `JSON.stringify` unchanged.
|
|
3280
|
+
*
|
|
3281
|
+
* @param allow - The answer a guide lets through, or the one a press outside its window gives.
|
|
3282
|
+
* @returns The answer as plain JSON.
|
|
3283
|
+
* @example
|
|
3284
|
+
* ```ts
|
|
3285
|
+
* allowJson({ intent: "merge" }); // { intent: "merge" }: no payload key
|
|
3286
|
+
* ```
|
|
3287
|
+
*/
|
|
3288
|
+
function allowJson(allow) {
|
|
3289
|
+
if (allow.payload === void 0) return { intent: allow.intent };
|
|
3290
|
+
return {
|
|
3291
|
+
intent: allow.intent,
|
|
3292
|
+
payload: allow.payload
|
|
3293
|
+
};
|
|
3294
|
+
}
|
|
3295
|
+
/**
|
|
3296
|
+
* Tells a list of targets from one target.
|
|
3297
|
+
*
|
|
3298
|
+
* @param target - What `target` was given.
|
|
3299
|
+
* @returns True for a list.
|
|
3300
|
+
* @example
|
|
3301
|
+
* ```ts
|
|
3302
|
+
* isTargetList([{ projection: "board", key: "c3" }]); // true
|
|
3303
|
+
* ```
|
|
3304
|
+
*/
|
|
3305
|
+
function isTargetList$1(target) {
|
|
3306
|
+
return Array.isArray(target);
|
|
3307
|
+
}
|
|
3308
|
+
/**
|
|
3309
|
+
* Copies one target into plain JSON: its projection and its key, nothing else.
|
|
3310
|
+
*
|
|
3311
|
+
* @param target - A view or an element by projection and key.
|
|
3312
|
+
* @returns The target as plain JSON.
|
|
3313
|
+
* @example
|
|
3314
|
+
* ```ts
|
|
3315
|
+
* targetJson({ projection: "board", key: "c3" }); // { projection: "board", key: "c3" }
|
|
3316
|
+
* ```
|
|
3317
|
+
*/
|
|
3318
|
+
function targetJson$1(target) {
|
|
3319
|
+
return {
|
|
3320
|
+
projection: target.projection,
|
|
3321
|
+
key: target.key
|
|
3322
|
+
};
|
|
3323
|
+
}
|
|
3324
|
+
/**
|
|
3325
|
+
* Copies the veil of a guide into plain JSON: `false`, or the colour and the alpha it names.
|
|
3326
|
+
*
|
|
3327
|
+
* @param veil - The veil of the options.
|
|
3328
|
+
* @returns The veil as plain JSON.
|
|
3329
|
+
* @example
|
|
3330
|
+
* ```ts
|
|
3331
|
+
* veilJson({ alpha: 0 }); // { alpha: 0 }: no colour key
|
|
3332
|
+
* ```
|
|
3333
|
+
*/
|
|
3334
|
+
function veilJson(veil) {
|
|
3335
|
+
if (veil === false) return false;
|
|
3336
|
+
const copy = {};
|
|
3337
|
+
if (veil.color !== void 0) copy.color = veil.color;
|
|
3338
|
+
if (veil.alpha !== void 0) copy.alpha = veil.alpha;
|
|
3339
|
+
return copy;
|
|
3340
|
+
}
|
|
3341
|
+
/**
|
|
3342
|
+
* Builds the payload of a `guide` descriptor: the answers, the targets, the padding and the veil
|
|
3343
|
+
* in plain JSON, a key only for an option that was given. The targets, the veil and the highlight
|
|
3344
|
+
* list are copied, so a later change of the caller's objects cannot reach them; an answer's payload
|
|
3345
|
+
* is taken as it is, as the gate compares it.
|
|
3346
|
+
*
|
|
3347
|
+
* @param options - The guide's options.
|
|
3348
|
+
* @returns The payload.
|
|
3349
|
+
* @example
|
|
3350
|
+
* ```ts
|
|
3351
|
+
* guidePayload({ allow: { intent: "merge" }, target: [{ projection: "board", key: "c3" }], pad: 4 });
|
|
3352
|
+
* // { allow: { intent: "merge" }, target: [{ projection: "board", key: "c3" }], pad: 4 }
|
|
3353
|
+
* ```
|
|
3354
|
+
*/
|
|
3355
|
+
function guidePayload(options) {
|
|
3356
|
+
const payload = { allow: allowJson(options.allow) };
|
|
3357
|
+
const { target, pad, veil, blocked, highlight, hand, text } = options;
|
|
3358
|
+
if (target !== void 0) payload.target = isTargetList$1(target) ? target.map((entry) => targetJson$1(entry)) : targetJson$1(target);
|
|
3359
|
+
if (pad !== void 0) payload.pad = pad;
|
|
3360
|
+
if (veil !== void 0) payload.veil = veilJson(veil);
|
|
3361
|
+
if (blocked !== void 0) payload.blocked = allowJson(blocked);
|
|
3362
|
+
if (highlight !== void 0) payload.highlight = [...highlight];
|
|
3363
|
+
if (hand !== void 0) payload.hand = hand;
|
|
3364
|
+
if (text !== void 0) payload.text = text;
|
|
3365
|
+
return payload;
|
|
3366
|
+
}
|
|
3277
3367
|
/**
|
|
3278
|
-
* Compares two JSON values by value
|
|
3279
|
-
* concrete move,
|
|
3368
|
+
* Compares two JSON values by value: the payload of a guide's answer, which points at one
|
|
3369
|
+
* concrete move, and two results of a node's `guide`.
|
|
3280
3370
|
*
|
|
3281
|
-
* @param left - First value, `undefined` when
|
|
3282
|
-
* @param right - Second value, `undefined` when
|
|
3371
|
+
* @param left - First value, `undefined` when absent.
|
|
3372
|
+
* @param right - Second value, `undefined` when absent.
|
|
3283
3373
|
* @returns True when both sides carry the same data.
|
|
3284
3374
|
* @example
|
|
3285
3375
|
* ```ts
|
|
@@ -3325,23 +3415,58 @@ function objectEquals(left, right) {
|
|
|
3325
3415
|
if (keys.length !== Object.keys(right).length) return false;
|
|
3326
3416
|
return keys.every((key) => jsonEquals(left[key], right[key]));
|
|
3327
3417
|
}
|
|
3418
|
+
//#endregion
|
|
3419
|
+
//#region src/plugins/flow/gate/api.ts
|
|
3420
|
+
/**
|
|
3421
|
+
* @file flow/gate — API factory. The single entry of player answers: close before deliver, a hold
|
|
3422
|
+
* for an answer that arrived while the gate was closed, and the `guide` narrow.
|
|
3423
|
+
*/
|
|
3424
|
+
/**
|
|
3425
|
+
* Tells whether an answer is the one a guide names: the intent matches, and the payload too when
|
|
3426
|
+
* the guide's answer carries one.
|
|
3427
|
+
*
|
|
3428
|
+
* @param named - The answer a `guide` names: the one it lets through, or the one of a blocked press.
|
|
3429
|
+
* @param answer - The answer given.
|
|
3430
|
+
* @returns True when the answer is that one.
|
|
3431
|
+
* @example
|
|
3432
|
+
* ```ts
|
|
3433
|
+
* matchesAnswer({ intent: "merge" }, { intent: "sell" }); // false
|
|
3434
|
+
* ```
|
|
3435
|
+
*/
|
|
3436
|
+
function matchesAnswer(named, answer) {
|
|
3437
|
+
if (named.intent !== answer.intent) return false;
|
|
3438
|
+
if (named.payload === void 0) return true;
|
|
3439
|
+
return jsonEquals(named.payload, answer.payload);
|
|
3440
|
+
}
|
|
3328
3441
|
/**
|
|
3329
3442
|
* Tells whether a running `guide` lets this answer through. Without a narrow every answer passes;
|
|
3330
|
-
* with one
|
|
3443
|
+
* with one it must be the answer the guide allows or the answer of a press outside its window.
|
|
3331
3444
|
*
|
|
3332
|
-
* @param
|
|
3445
|
+
* @param state - Gate state: the narrow and the answer of a blocked press.
|
|
3333
3446
|
* @param answer - The answer given.
|
|
3334
3447
|
* @returns True when the answer passes the narrow.
|
|
3448
|
+
*/
|
|
3449
|
+
function passesNarrow(state, answer) {
|
|
3450
|
+
if (state.narrow === void 0) return true;
|
|
3451
|
+
if (matchesAnswer(state.narrow, answer)) return true;
|
|
3452
|
+
return state.blocked !== void 0 && matchesAnswer(state.blocked, answer);
|
|
3453
|
+
}
|
|
3454
|
+
/**
|
|
3455
|
+
* Copies a guide's answer for a reader: the intent, and a copy of the payload when there is one.
|
|
3456
|
+
*
|
|
3457
|
+
* @param named - The answer the gate keeps.
|
|
3458
|
+
* @returns A copy nobody shares.
|
|
3335
3459
|
* @example
|
|
3336
3460
|
* ```ts
|
|
3337
|
-
*
|
|
3461
|
+
* copyAnswer({ intent: "tutorialBlocked", payload: { step: 2 } }); // { intent: "tutorialBlocked", payload: { step: 2 } }
|
|
3338
3462
|
* ```
|
|
3339
3463
|
*/
|
|
3340
|
-
function
|
|
3341
|
-
if (
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3464
|
+
function copyAnswer(named) {
|
|
3465
|
+
if (named.payload === void 0) return { intent: named.intent };
|
|
3466
|
+
return {
|
|
3467
|
+
intent: named.intent,
|
|
3468
|
+
payload: structuredClone(named.payload)
|
|
3469
|
+
};
|
|
3345
3470
|
}
|
|
3346
3471
|
/**
|
|
3347
3472
|
* Tells whether the open gate takes this answer. A closed gate takes nothing.
|
|
@@ -3353,7 +3478,7 @@ function passesNarrow(narrow, answer) {
|
|
|
3353
3478
|
function accepts(state, answer) {
|
|
3354
3479
|
if (state.open === void 0) return false;
|
|
3355
3480
|
if (!state.open.allowed.includes(answer.intent)) return false;
|
|
3356
|
-
return passesNarrow(state
|
|
3481
|
+
return passesNarrow(state, answer);
|
|
3357
3482
|
}
|
|
3358
3483
|
/**
|
|
3359
3484
|
* Shuts the gate. The narrow survives: a `guide` is lifted by the runner on node exit, not by the
|
|
@@ -3436,11 +3561,18 @@ function createGateApi(ctx) {
|
|
|
3436
3561
|
pointer: (active) => {
|
|
3437
3562
|
ctx.state.gate.pointerActive = active;
|
|
3438
3563
|
},
|
|
3439
|
-
state: () =>
|
|
3440
|
-
open
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3564
|
+
state: () => {
|
|
3565
|
+
const { open, narrow, blocked } = ctx.state.gate;
|
|
3566
|
+
const read = {
|
|
3567
|
+
open: open !== void 0,
|
|
3568
|
+
allowed: open?.allowed ?? [],
|
|
3569
|
+
narrowed: narrow !== void 0
|
|
3570
|
+
};
|
|
3571
|
+
return blocked === void 0 ? read : {
|
|
3572
|
+
...read,
|
|
3573
|
+
blocked: copyAnswer(blocked)
|
|
3574
|
+
};
|
|
3575
|
+
},
|
|
3444
3576
|
open: (spec) => {
|
|
3445
3577
|
if (ctx.state.gate.open !== void 0) throw new Error("[game] The gate is already open.\n Close it before opening it again.");
|
|
3446
3578
|
return new Promise((resolve) => {
|
|
@@ -3452,8 +3584,9 @@ function createGateApi(ctx) {
|
|
|
3452
3584
|
close: () => {
|
|
3453
3585
|
shut(ctx.state.gate);
|
|
3454
3586
|
},
|
|
3455
|
-
narrow: (allow) => {
|
|
3587
|
+
narrow: (allow, blocked) => {
|
|
3456
3588
|
ctx.state.gate.narrow = allow;
|
|
3589
|
+
ctx.state.gate.blocked = allow === void 0 ? void 0 : blocked;
|
|
3457
3590
|
},
|
|
3458
3591
|
clearHeld: (frame, elapsed) => {
|
|
3459
3592
|
const held = ctx.state.gate.held;
|
|
@@ -5028,8 +5161,8 @@ function type() {
|
|
|
5028
5161
|
/**
|
|
5029
5162
|
* Defines a node. `out` of the body has one method per declared outcome; `run` is required
|
|
5030
5163
|
* unless `rest: true`. A rest node may carry `recover`: the engine runs it before the node is
|
|
5031
|
-
* entered as the safe node. `
|
|
5032
|
-
* `Json`.
|
|
5164
|
+
* entered as the safe node. `guide` derives the tutorial guide that stands while the node does.
|
|
5165
|
+
* `Game` is bound by `defineGame<Types>()`; here it is the engine's `Json`.
|
|
5033
5166
|
*
|
|
5034
5167
|
* @param spec - Input tag, outcomes, flags, inbox and the body.
|
|
5035
5168
|
* @returns The node as plain data.
|
|
@@ -5057,7 +5190,8 @@ function defineNode(spec) {
|
|
|
5057
5190
|
barrier: spec.barrier === true,
|
|
5058
5191
|
inbox: spec.inbox ?? [],
|
|
5059
5192
|
...spec.scene === void 0 ? {} : { scene: spec.scene },
|
|
5060
|
-
...spec.recover === void 0 ? {} : { recover: spec.recover }
|
|
5193
|
+
...spec.recover === void 0 ? {} : { recover: spec.recover },
|
|
5194
|
+
...spec.guide === void 0 ? {} : { guide: spec.guide }
|
|
5061
5195
|
};
|
|
5062
5196
|
return spec.run ? {
|
|
5063
5197
|
...node,
|
|
@@ -5202,29 +5336,31 @@ function createOut(outcomes) {
|
|
|
5202
5336
|
* isPlainRecord(["c2"]); // false: an array is not a record
|
|
5203
5337
|
* ```
|
|
5204
5338
|
*/
|
|
5205
|
-
function isPlainRecord(value) {
|
|
5339
|
+
function isPlainRecord$1(value) {
|
|
5206
5340
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
5207
5341
|
}
|
|
5208
5342
|
/**
|
|
5209
|
-
* Reads
|
|
5343
|
+
* Reads one answer a `guide` descriptor names: the one it lets through (`allow`), or the one a
|
|
5344
|
+
* press outside its window gives (`blocked`).
|
|
5210
5345
|
*
|
|
5211
5346
|
* @param payload - Payload of the descriptor, as JSON.
|
|
5212
|
-
* @
|
|
5347
|
+
* @param key - Which answer: `"allow"` or `"blocked"`.
|
|
5348
|
+
* @returns The answer, or `undefined` when the payload names none.
|
|
5213
5349
|
* @example
|
|
5214
5350
|
* ```ts
|
|
5215
|
-
*
|
|
5216
|
-
*
|
|
5351
|
+
* guideAnswer({ allow: { intent: "merge" } }, "allow"); // { intent: "merge" }
|
|
5352
|
+
* guideAnswer({ allow: { intent: "merge" } }, "blocked"); // undefined
|
|
5217
5353
|
* ```
|
|
5218
5354
|
*/
|
|
5219
|
-
function
|
|
5220
|
-
if (!isPlainRecord(payload)) return void 0;
|
|
5221
|
-
const
|
|
5222
|
-
if (!isPlainRecord(
|
|
5223
|
-
const intent =
|
|
5355
|
+
function guideAnswer(payload, key) {
|
|
5356
|
+
if (!isPlainRecord$1(payload)) return void 0;
|
|
5357
|
+
const answer = payload[key];
|
|
5358
|
+
if (!isPlainRecord$1(answer)) return void 0;
|
|
5359
|
+
const intent = answer.intent;
|
|
5224
5360
|
if (typeof intent !== "string") return void 0;
|
|
5225
|
-
return
|
|
5361
|
+
return answer.payload === void 0 ? { intent } : {
|
|
5226
5362
|
intent,
|
|
5227
|
-
payload:
|
|
5363
|
+
payload: answer.payload
|
|
5228
5364
|
};
|
|
5229
5365
|
}
|
|
5230
5366
|
/**
|
|
@@ -5286,8 +5422,8 @@ function nodeFx(modules, step) {
|
|
|
5286
5422
|
const run = (descriptor) => {
|
|
5287
5423
|
if (step.signal.aborted) return refuseEffect(step.signal);
|
|
5288
5424
|
if (descriptor.kind === "guide") {
|
|
5289
|
-
const allow =
|
|
5290
|
-
if (allow !== void 0) modules.gate.narrow(allow);
|
|
5425
|
+
const allow = guideAnswer(descriptor.payload, "allow");
|
|
5426
|
+
if (allow !== void 0) modules.gate.narrow(allow, guideAnswer(descriptor.payload, "blocked"));
|
|
5291
5427
|
}
|
|
5292
5428
|
const value = modules.fx.run(descriptor, step.signal);
|
|
5293
5429
|
if (descriptor.answers !== void 0) step.gateOpened();
|
|
@@ -5614,7 +5750,7 @@ function waitForAnswer(modules, step) {
|
|
|
5614
5750
|
* @param modules - Injected sibling APIs.
|
|
5615
5751
|
* @param step - The node run in progress.
|
|
5616
5752
|
* @param delivered - Holder of the event the inbox delivered.
|
|
5617
|
-
* @returns The outcome of that node
|
|
5753
|
+
* @returns The outcome of that node; read it through `failedOrAsIs`.
|
|
5618
5754
|
*/
|
|
5619
5755
|
function nodeOutcome(modules, step, delivered) {
|
|
5620
5756
|
if (step.node.run === void 0) return waitForAnswer(modules, step);
|
|
@@ -5622,6 +5758,28 @@ function nodeOutcome(modules, step, delivered) {
|
|
|
5622
5758
|
return runBody(modules, step);
|
|
5623
5759
|
}
|
|
5624
5760
|
/**
|
|
5761
|
+
* Reads the outcome of a node that may have been failed from outside its body. `step.fail` (a
|
|
5762
|
+
* `guide` that threw after a commit) aborts the node with `"failed"`: its outcome is that failure,
|
|
5763
|
+
* not an abort.
|
|
5764
|
+
*
|
|
5765
|
+
* @param step - The node run, with the failure `fail` recorded.
|
|
5766
|
+
* @param outcome - What the wait of the node settled with.
|
|
5767
|
+
* @returns The recorded failure for an abort that `fail` caused, the outcome otherwise.
|
|
5768
|
+
* @example
|
|
5769
|
+
* ```ts
|
|
5770
|
+
* failedOrAsIs({ failure: { error: "no step" } }, { kind: "aborted", reason: "failed" });
|
|
5771
|
+
* // { kind: "failed", error: "no step" }
|
|
5772
|
+
* ```
|
|
5773
|
+
*/
|
|
5774
|
+
function failedOrAsIs(step, outcome) {
|
|
5775
|
+
const failure = step.failure;
|
|
5776
|
+
if (outcome.kind !== "aborted" || failure === void 0) return outcome;
|
|
5777
|
+
return {
|
|
5778
|
+
kind: "failed",
|
|
5779
|
+
error: failure.error
|
|
5780
|
+
};
|
|
5781
|
+
}
|
|
5782
|
+
/**
|
|
5625
5783
|
* Waits while a pointer is down, so an `over` node never appears mid-drag. Without a running frame
|
|
5626
5784
|
* loop nothing would ever wake the wait, so the node is entered at once. A stop ends the wait as
|
|
5627
5785
|
* well: the runner must not hold the loop open for a pointer that is never lifted.
|
|
@@ -5649,6 +5807,118 @@ function waitForPointer(ctx) {
|
|
|
5649
5807
|
});
|
|
5650
5808
|
}
|
|
5651
5809
|
//#endregion
|
|
5810
|
+
//#region src/plugins/flow/runner/guide.ts
|
|
5811
|
+
/**
|
|
5812
|
+
* Builds the failure of a `guide` that threw, or returned what is no `GuideOptions`. The thrown
|
|
5813
|
+
* message keeps its own punctuation.
|
|
5814
|
+
*
|
|
5815
|
+
* @param path - Runtime path of the node.
|
|
5816
|
+
* @param error - What the `guide` threw.
|
|
5817
|
+
* @returns The error the node fails with; the thrown value is its cause.
|
|
5818
|
+
* @example
|
|
5819
|
+
* ```ts
|
|
5820
|
+
* guideThrew("board/awaitIntent", new Error("no step.")).message;
|
|
5821
|
+
* // '[game] The guide of node "board/awaitIntent" threw: no step.\n Return GuideOptions or undefined from guide.'
|
|
5822
|
+
* ```
|
|
5823
|
+
*/
|
|
5824
|
+
function guideThrew(path, error) {
|
|
5825
|
+
return new Error(`[game] The guide of node "${path}" threw: ${asError$4(error).message}\n Return GuideOptions or undefined from guide.`, { cause: error });
|
|
5826
|
+
}
|
|
5827
|
+
/**
|
|
5828
|
+
* Checks, in a dev build, that the answer of a blocked press is an outcome of the node: the gate
|
|
5829
|
+
* lists only the node's outcomes, so any other intent would be refused at every press.
|
|
5830
|
+
*
|
|
5831
|
+
* @param step - The node run in progress.
|
|
5832
|
+
* @param payload - The guide's payload, or `undefined` for none.
|
|
5833
|
+
* @returns The error of a `blocked` the node does not take, `undefined` otherwise.
|
|
5834
|
+
*/
|
|
5835
|
+
function wrongBlocked(step, payload) {
|
|
5836
|
+
if (typeof __MOKU_GAME_DEV__ === "undefined" || !__MOKU_GAME_DEV__) return void 0;
|
|
5837
|
+
const blocked = guideAnswer(payload, "blocked");
|
|
5838
|
+
if (blocked === void 0 || Object.hasOwn(step.node.outcomes, blocked.intent)) return void 0;
|
|
5839
|
+
return /* @__PURE__ */ new Error(`[game] The guide of node "${step.path}" blocks with "${blocked.intent}", which is no outcome of the node.\n Add it to outcomes or drop blocked.`);
|
|
5840
|
+
}
|
|
5841
|
+
/**
|
|
5842
|
+
* Shows a new result of the guide: the guide shown so far ends with its narrow, the gate is
|
|
5843
|
+
* narrowed to `allow` and `blocked`, and the `guide` handler gets the payload with a signal of its
|
|
5844
|
+
* own. A result equal to the last one changes nothing; `undefined` only lifts. A handler that fails
|
|
5845
|
+
* is logged, `flow:guide-handler-failed`; one that fails after the node's abort was told to stop.
|
|
5846
|
+
*
|
|
5847
|
+
* @param ctx - Domain context of the flow plugin.
|
|
5848
|
+
* @param modules - Injected sibling APIs.
|
|
5849
|
+
* @param step - The node run in progress.
|
|
5850
|
+
* @param guide - The node's guide: its last result is compared and replaced.
|
|
5851
|
+
* @param payload - The new result as the descriptor's payload, or `undefined` for none.
|
|
5852
|
+
*/
|
|
5853
|
+
function show$1(ctx, modules, step, guide, payload) {
|
|
5854
|
+
if (jsonEquals(payload, guide.last)) return;
|
|
5855
|
+
const shown = guide.last !== void 0;
|
|
5856
|
+
guide.last = payload;
|
|
5857
|
+
if (shown) modules.fx.endGuides();
|
|
5858
|
+
if (payload === void 0) {
|
|
5859
|
+
modules.gate.narrow(void 0);
|
|
5860
|
+
return;
|
|
5861
|
+
}
|
|
5862
|
+
modules.gate.narrow(guideAnswer(payload, "allow"), guideAnswer(payload, "blocked"));
|
|
5863
|
+
modules.fx.run({
|
|
5864
|
+
kind: "guide",
|
|
5865
|
+
payload
|
|
5866
|
+
}, step.signal).catch((error) => {
|
|
5867
|
+
if (step.signal.aborted) return;
|
|
5868
|
+
ctx.log.error("flow:guide-handler-failed", { path: step.path }, asError$4(error));
|
|
5869
|
+
});
|
|
5870
|
+
}
|
|
5871
|
+
/**
|
|
5872
|
+
* Derives the guide from the committed state and shows a new result.
|
|
5873
|
+
*
|
|
5874
|
+
* @param ctx - Domain context of the flow plugin.
|
|
5875
|
+
* @param modules - Injected sibling APIs.
|
|
5876
|
+
* @param step - The node run in progress.
|
|
5877
|
+
* @param guide - The node's guide.
|
|
5878
|
+
* @returns The error the node fails with: its `guide` threw, or names a `blocked` it does not take.
|
|
5879
|
+
*/
|
|
5880
|
+
function derive(ctx, modules, step, guide) {
|
|
5881
|
+
const { player, session } = ctx.deps.model.store.snapshot();
|
|
5882
|
+
let payload;
|
|
5883
|
+
try {
|
|
5884
|
+
const options = step.node.guide?.({
|
|
5885
|
+
player,
|
|
5886
|
+
session
|
|
5887
|
+
});
|
|
5888
|
+
payload = options === void 0 ? void 0 : guidePayload(options);
|
|
5889
|
+
} catch (error) {
|
|
5890
|
+
return guideThrew(step.path, error);
|
|
5891
|
+
}
|
|
5892
|
+
const wrong = wrongBlocked(step, payload);
|
|
5893
|
+
if (wrong !== void 0) return wrong;
|
|
5894
|
+
show$1(ctx, modules, step, guide, payload);
|
|
5895
|
+
}
|
|
5896
|
+
/**
|
|
5897
|
+
* Enters the guide of a node: derives it from the committed state and keeps it in the runner state,
|
|
5898
|
+
* so a commit while the node waits at its gate derives it again. Called after the node's `onEnter`
|
|
5899
|
+
* stages and before its outcome is awaited. A node without `guide`, and one already aborted, change
|
|
5900
|
+
* nothing. A `guide` that throws again after a commit fails the node through `step.fail`.
|
|
5901
|
+
*
|
|
5902
|
+
* @param ctx - Domain context of the flow plugin.
|
|
5903
|
+
* @param modules - Injected sibling APIs.
|
|
5904
|
+
* @param step - The node run in progress.
|
|
5905
|
+
* @returns The error the node fails with at its entry, `undefined` when it goes on.
|
|
5906
|
+
*/
|
|
5907
|
+
function enterGuide(ctx, modules, step) {
|
|
5908
|
+
if (step.node.guide === void 0 || step.signal.aborted) return void 0;
|
|
5909
|
+
const guide = {
|
|
5910
|
+
last: void 0,
|
|
5911
|
+
refresh: noop
|
|
5912
|
+
};
|
|
5913
|
+
guide.refresh = () => {
|
|
5914
|
+
if (step.signal.aborted || ctx.state.runner.guide !== guide) return;
|
|
5915
|
+
const failed = derive(ctx, modules, step, guide);
|
|
5916
|
+
if (failed !== void 0) step.fail(failed);
|
|
5917
|
+
};
|
|
5918
|
+
ctx.state.runner.guide = guide;
|
|
5919
|
+
return derive(ctx, modules, step, guide);
|
|
5920
|
+
}
|
|
5921
|
+
//#endregion
|
|
5652
5922
|
//#region src/plugins/flow/runner/recover.ts
|
|
5653
5923
|
/**
|
|
5654
5924
|
* Takes the recovery the loop owes the safe node. It is owed once per give-up, to the first node
|
|
@@ -5858,7 +6128,9 @@ async function stopRunner(ctx) {
|
|
|
5858
6128
|
//#region src/plugins/flow/runner/loop.ts
|
|
5859
6129
|
/**
|
|
5860
6130
|
* Runs one node: wait for the pointer, the recovery the loop owes the safe node, `onEnter` stages,
|
|
5861
|
-
* open the transaction, produce the outcome, then commit on the edge or
|
|
6131
|
+
* open the transaction, derive the node's guide, produce the outcome, then commit on the edge or
|
|
6132
|
+
* recover. A `guide` that throws on entry fails the node before its gate opens or its body runs:
|
|
6133
|
+
* it is aborted with `"failed"`, as for a stage that throws.
|
|
5862
6134
|
*
|
|
5863
6135
|
* @param ctx - Domain context of the flow plugin.
|
|
5864
6136
|
* @param modules - Injected sibling APIs.
|
|
@@ -5906,9 +6178,27 @@ async function runNode(ctx, modules, location, node, safe) {
|
|
|
5906
6178
|
gateOpened: () => {
|
|
5907
6179
|
notifyGateOpen(state);
|
|
5908
6180
|
},
|
|
5909
|
-
log: ctx.log
|
|
6181
|
+
log: ctx.log,
|
|
6182
|
+
/**
|
|
6183
|
+
* Fails the node from outside its body: keeps the error and aborts the node with `"failed"`.
|
|
6184
|
+
*
|
|
6185
|
+
* @param error - What the node fails with.
|
|
6186
|
+
*/
|
|
6187
|
+
fail: (error) => {
|
|
6188
|
+
if (abort.signal.aborted) return;
|
|
6189
|
+
step.failure = { error };
|
|
6190
|
+
abort.abort("failed");
|
|
6191
|
+
},
|
|
6192
|
+
failure: void 0
|
|
6193
|
+
};
|
|
6194
|
+
const delivered = { event: void 0 };
|
|
6195
|
+
const entered = enterGuide(ctx, modules, step);
|
|
6196
|
+
if (entered !== void 0) abort.abort("failed");
|
|
6197
|
+
const outcome = entered === void 0 ? failedOrAsIs(step, await nodeOutcome(modules, step, delivered)) : {
|
|
6198
|
+
kind: "failed",
|
|
6199
|
+
error: entered
|
|
5910
6200
|
};
|
|
5911
|
-
|
|
6201
|
+
state.guide = void 0;
|
|
5912
6202
|
modules.gate.narrow(void 0);
|
|
5913
6203
|
modules.fx.endGuides();
|
|
5914
6204
|
if (outcome.kind === "failed") return handleFailure(ctx, modules, step.transaction, outcome.error, path, safe);
|
|
@@ -6022,6 +6312,7 @@ function enterBookmark(ctx, modules, bookmark, safe) {
|
|
|
6022
6312
|
safe.inside = false;
|
|
6023
6313
|
safe.recover = false;
|
|
6024
6314
|
modules.gate.dropHeld();
|
|
6315
|
+
state.guide = void 0;
|
|
6025
6316
|
ctx.deps.model.store.restore({
|
|
6026
6317
|
player: bookmark.player,
|
|
6027
6318
|
session: bookmark.session,
|
|
@@ -6096,6 +6387,7 @@ async function runLoop(ctx, modules) {
|
|
|
6096
6387
|
state.slotLeave = void 0;
|
|
6097
6388
|
state.failures = 0;
|
|
6098
6389
|
state.restless = 0;
|
|
6390
|
+
state.guide = void 0;
|
|
6099
6391
|
const safe = {
|
|
6100
6392
|
inside: false,
|
|
6101
6393
|
recover: false
|
|
@@ -6832,9 +7124,6 @@ function createFlowApi(ctx) {
|
|
|
6832
7124
|
//#endregion
|
|
6833
7125
|
//#region src/plugins/flow/handlers.ts
|
|
6834
7126
|
/**
|
|
6835
|
-
* @file flow plugin — event handlers.
|
|
6836
|
-
*/
|
|
6837
|
-
/**
|
|
6838
7127
|
* Reacts to a change of the pause stack: a resume pokes the clock, going to background starts a
|
|
6839
7128
|
* flush that `onStop` awaits.
|
|
6840
7129
|
*
|
|
@@ -6849,27 +7138,52 @@ function reactToLifecycle(ctx, payload) {
|
|
|
6849
7138
|
ctx.state.runner.flushing = deps.model.store.flush().catch(noop);
|
|
6850
7139
|
}
|
|
6851
7140
|
/**
|
|
7141
|
+
* Derives the guide of the node that stands again after a commit: only while a node with a `guide`
|
|
7142
|
+
* waits at its open gate, and never for the commit of an edge. The loop lifts the narrow before
|
|
7143
|
+
* it commits the edge that leaves the node, so that commit must not show the guide again; the
|
|
7144
|
+
* node's abort makes the derive a no-op.
|
|
7145
|
+
*
|
|
7146
|
+
* @param ctx - Kernel context of the flow plugin.
|
|
7147
|
+
* @param payload - What was committed and why.
|
|
7148
|
+
*/
|
|
7149
|
+
function refreshGuide(ctx, payload) {
|
|
7150
|
+
const guide = ctx.state.runner.guide;
|
|
7151
|
+
if (guide === void 0 || payload.cause === "edge") return;
|
|
7152
|
+
if (ctx.state.gate.open === void 0) return;
|
|
7153
|
+
guide.refresh();
|
|
7154
|
+
}
|
|
7155
|
+
/**
|
|
6852
7156
|
* Creates the hook handlers. On `lifecycle:changed` with `resumed: true` the clock is poked, so
|
|
6853
7157
|
* the time that passed in the background arrives as one `elapsed`; on a `"background"` push the
|
|
6854
|
-
* model flush is started and tracked in `state.runner.flushing`, which `onStop` awaits.
|
|
7158
|
+
* model flush is started and tracked in `state.runner.flushing`, which `onStop` awaits. On
|
|
7159
|
+
* `model:committed` the guide of the node that waits at its gate is derived again.
|
|
6855
7160
|
*
|
|
6856
7161
|
* The handler is synchronous — every engine hook is — and it resolves its dependencies when it
|
|
6857
7162
|
* fires: the kernel registers hooks before it builds the plugin APIs, so nothing is resolvable
|
|
6858
7163
|
* while this factory runs.
|
|
6859
7164
|
*
|
|
6860
7165
|
* @param ctx - Kernel context of the flow plugin.
|
|
6861
|
-
* @returns The
|
|
7166
|
+
* @returns The two hooks of the plugin.
|
|
6862
7167
|
*/
|
|
6863
7168
|
function createHandlers$7(ctx) {
|
|
6864
|
-
return {
|
|
6865
|
-
|
|
6866
|
-
|
|
6867
|
-
|
|
6868
|
-
|
|
6869
|
-
|
|
6870
|
-
"lifecycle:changed": (payload) => {
|
|
6871
|
-
|
|
6872
|
-
|
|
7169
|
+
return {
|
|
7170
|
+
/**
|
|
7171
|
+
* Reacts to a change of the pause stack.
|
|
7172
|
+
*
|
|
7173
|
+
* @param payload - What changed: the reason, the direction and whether the game resumed.
|
|
7174
|
+
*/
|
|
7175
|
+
"lifecycle:changed": (payload) => {
|
|
7176
|
+
reactToLifecycle(ctx, payload);
|
|
7177
|
+
},
|
|
7178
|
+
/**
|
|
7179
|
+
* Derives the guide of the node that waits at its gate again.
|
|
7180
|
+
*
|
|
7181
|
+
* @param payload - What was committed and why.
|
|
7182
|
+
*/
|
|
7183
|
+
"model:committed": (payload) => {
|
|
7184
|
+
refreshGuide(ctx, payload);
|
|
7185
|
+
}
|
|
7186
|
+
};
|
|
6873
7187
|
}
|
|
6874
7188
|
//#endregion
|
|
6875
7189
|
//#region src/plugins/flow/features/state.ts
|
|
@@ -6956,6 +7270,7 @@ function createGateState() {
|
|
|
6956
7270
|
held: void 0,
|
|
6957
7271
|
aged: 0,
|
|
6958
7272
|
narrow: void 0,
|
|
7273
|
+
blocked: void 0,
|
|
6959
7274
|
pointerActive: false,
|
|
6960
7275
|
wake: void 0
|
|
6961
7276
|
};
|
|
@@ -7016,7 +7331,8 @@ function createRunnerState() {
|
|
|
7016
7331
|
journalIndex: 0,
|
|
7017
7332
|
running: void 0,
|
|
7018
7333
|
abort: void 0,
|
|
7019
|
-
failures: 0
|
|
7334
|
+
failures: 0,
|
|
7335
|
+
guide: void 0
|
|
7020
7336
|
};
|
|
7021
7337
|
}
|
|
7022
7338
|
//#endregion
|
|
@@ -11129,7 +11445,7 @@ function clearMounted(pctx, mounted) {
|
|
|
11129
11445
|
* @param hint - The released hint.
|
|
11130
11446
|
* @returns The payload fields, or `undefined`.
|
|
11131
11447
|
*/
|
|
11132
|
-
function fieldsOf(hint) {
|
|
11448
|
+
function fieldsOf$1(hint) {
|
|
11133
11449
|
const payload = hint.payload;
|
|
11134
11450
|
if (payload === void 0 || payload === null) return void 0;
|
|
11135
11451
|
if (typeof payload !== "object" || Array.isArray(payload)) return void 0;
|
|
@@ -11146,7 +11462,7 @@ function fieldsOf(hint) {
|
|
|
11146
11462
|
*/
|
|
11147
11463
|
function routeHint(hints, projection, key) {
|
|
11148
11464
|
for (const hint of hints) {
|
|
11149
|
-
const fields = fieldsOf(hint);
|
|
11465
|
+
const fields = fieldsOf$1(hint);
|
|
11150
11466
|
if (fields === void 0) continue;
|
|
11151
11467
|
const narrow = fields.projection;
|
|
11152
11468
|
if (typeof narrow === "string" && narrow !== projection) continue;
|
|
@@ -16139,7 +16455,7 @@ function sourceBytes(source) {
|
|
|
16139
16455
|
* isTarget({ uploadMethodId: "unknown", resource: null }); // true
|
|
16140
16456
|
* ```
|
|
16141
16457
|
*/
|
|
16142
|
-
function isTarget$
|
|
16458
|
+
function isTarget$3(source) {
|
|
16143
16459
|
return source.uploadMethodId === "unknown" && (source.resource === null || source.resource === void 0);
|
|
16144
16460
|
}
|
|
16145
16461
|
/**
|
|
@@ -16174,7 +16490,7 @@ function textureUsage(app, kept) {
|
|
|
16174
16490
|
usage.count += 1;
|
|
16175
16491
|
usage.bytes += bytes;
|
|
16176
16492
|
if (kept.has(source)) usage.kept += bytes;
|
|
16177
|
-
else if (isTarget$
|
|
16493
|
+
else if (isTarget$3(source)) usage.targets += bytes;
|
|
16178
16494
|
else usage.art += bytes;
|
|
16179
16495
|
}
|
|
16180
16496
|
return usage;
|
|
@@ -30550,7 +30866,7 @@ function countApply(sinks, filter, input) {
|
|
|
30550
30866
|
* @param source - The source.
|
|
30551
30867
|
* @returns True for a render target.
|
|
30552
30868
|
*/
|
|
30553
|
-
function isTarget$
|
|
30869
|
+
function isTarget$2(source) {
|
|
30554
30870
|
return source.uploadMethodId === "unknown";
|
|
30555
30871
|
}
|
|
30556
30872
|
/**
|
|
@@ -30751,7 +31067,7 @@ function createCountingClasses(pixi, sinks, batcherPipe = pixi.BatcherPipe) {
|
|
|
30751
31067
|
* @returns The GPU texture.
|
|
30752
31068
|
*/
|
|
30753
31069
|
initSource(source) {
|
|
30754
|
-
const made = isTarget$
|
|
31070
|
+
const made = isTarget$2(source) && !this.targets.has(source);
|
|
30755
31071
|
const texture = super.initSource(source);
|
|
30756
31072
|
if (made) {
|
|
30757
31073
|
this.targets.add(source);
|
|
@@ -50049,6 +50365,19 @@ function submit(ctx, entity, answer) {
|
|
|
50049
50365
|
if (answer.intent === "") ctx.log.warn("input: empty intent", { view: ctx.deps.world.projection.keyOf(entity) });
|
|
50050
50366
|
return ctx.deps.flow.gate.answer(answer);
|
|
50051
50367
|
}
|
|
50368
|
+
/**
|
|
50369
|
+
* Answers a press the lock of a guide kept from every view: the gate's `blocked`, the answer the
|
|
50370
|
+
* running guide names for a press outside its window, with its payload. A guide that names none
|
|
50371
|
+
* drops the press: the gate is not called.
|
|
50372
|
+
*
|
|
50373
|
+
* @param ctx - Domain context of the input plugin.
|
|
50374
|
+
* @returns What `flow.gate.answer` returned; `false` when the guide names no `blocked`.
|
|
50375
|
+
*/
|
|
50376
|
+
function submitBlocked(ctx) {
|
|
50377
|
+
const blocked = ctx.deps.flow.gate.state().blocked;
|
|
50378
|
+
if (blocked === void 0) return false;
|
|
50379
|
+
return ctx.deps.flow.gate.answer(blocked);
|
|
50380
|
+
}
|
|
50052
50381
|
//#endregion
|
|
50053
50382
|
//#region src/plugins/input/components.ts
|
|
50054
50383
|
const scrollableDefaults = {
|
|
@@ -50172,7 +50501,8 @@ const Pointer = /*#__PURE__*/ resource("Pointer", pointerDefaults);
|
|
|
50172
50501
|
* which answers `undefined` without a DOM, and every accept function refuses a view that is
|
|
50173
50502
|
* already playing its exit. A trace takes a cell only inside a circle smaller than its box. The
|
|
50174
50503
|
* scroll a press belongs to is found up the pressed view's own `Parent` chain, never under the
|
|
50175
|
-
* point: a view drawn over a scroll from another root keeps its press.
|
|
50504
|
+
* point: a view drawn over a scroll from another root keeps its press. While the lock of a guide
|
|
50505
|
+
* stands, a point outside its window finds no view at all.
|
|
50176
50506
|
*/
|
|
50177
50507
|
/** How deep a `Parent` chain is followed; deeper is treated as a loop. */
|
|
50178
50508
|
const MAX_DEPTH$2 = 32;
|
|
@@ -50247,7 +50577,23 @@ function acceptTrace(ctx, point) {
|
|
|
50247
50577
|
};
|
|
50248
50578
|
}
|
|
50249
50579
|
/**
|
|
50250
|
-
*
|
|
50580
|
+
* Tells whether the lock of a guide keeps a point from every view: the lock holds everything, or
|
|
50581
|
+
* the point lies outside its window. The edges belong to the window, as they belong to a hit box.
|
|
50582
|
+
* Reads four numbers, allocates nothing.
|
|
50583
|
+
*
|
|
50584
|
+
* @param state - The input state, which holds the lock.
|
|
50585
|
+
* @param x - Reference x.
|
|
50586
|
+
* @param y - Reference y.
|
|
50587
|
+
* @returns True when no view may take the point.
|
|
50588
|
+
*/
|
|
50589
|
+
function lockedOut(state, x, y) {
|
|
50590
|
+
const window = state.lock;
|
|
50591
|
+
if (window === void 0) return false;
|
|
50592
|
+
if (window === null) return true;
|
|
50593
|
+
return x < window.x || x > window.x + window.w || y < window.y || y > window.y + window.h;
|
|
50594
|
+
}
|
|
50595
|
+
/**
|
|
50596
|
+
* The topmost view that takes the press at a point. Outside the window of a guide's lock: none.
|
|
50251
50597
|
*
|
|
50252
50598
|
* @param ctx - Domain context of the input plugin.
|
|
50253
50599
|
* @param x - Reference x.
|
|
@@ -50255,6 +50601,7 @@ function acceptTrace(ctx, point) {
|
|
|
50255
50601
|
* @returns The entity, or `undefined` when nothing was hit.
|
|
50256
50602
|
*/
|
|
50257
50603
|
function findPressed(ctx, x, y) {
|
|
50604
|
+
if (lockedOut(ctx.state, x, y)) return void 0;
|
|
50258
50605
|
return ctx.deps.renderer.sync.hitTest(x, y, (entity) => acceptPress(ctx, entity));
|
|
50259
50606
|
}
|
|
50260
50607
|
/**
|
|
@@ -50296,7 +50643,8 @@ function scrollOnAxisOf(ctx, entity, axis) {
|
|
|
50296
50643
|
}
|
|
50297
50644
|
}
|
|
50298
50645
|
/**
|
|
50299
|
-
* The topmost drop target at a point.
|
|
50646
|
+
* The topmost drop target at a point. Outside the window of a guide's lock: none, so the stack
|
|
50647
|
+
* settles home.
|
|
50300
50648
|
*
|
|
50301
50649
|
* @param ctx - Domain context of the input plugin.
|
|
50302
50650
|
* @param x - Reference x.
|
|
@@ -50305,16 +50653,19 @@ function scrollOnAxisOf(ctx, entity, axis) {
|
|
|
50305
50653
|
* @returns The entity, or `undefined` when the finger is over nothing.
|
|
50306
50654
|
*/
|
|
50307
50655
|
function findDropTarget(ctx, x, y, excluded) {
|
|
50656
|
+
if (lockedOut(ctx.state, x, y)) return void 0;
|
|
50308
50657
|
return ctx.deps.renderer.sync.hitTest(x, y, acceptDrop(ctx, excluded));
|
|
50309
50658
|
}
|
|
50310
50659
|
/**
|
|
50311
|
-
* The topmost trace cell whose inset circle holds a sample.
|
|
50660
|
+
* The topmost trace cell whose inset circle holds a sample. Outside the window of a guide's lock:
|
|
50661
|
+
* none, as over a gap.
|
|
50312
50662
|
*
|
|
50313
50663
|
* @param ctx - Domain context of the input plugin.
|
|
50314
50664
|
* @param point - The sample, in reference units.
|
|
50315
50665
|
* @returns The cell, or `undefined` over a gap.
|
|
50316
50666
|
*/
|
|
50317
50667
|
function findTraced(ctx, point) {
|
|
50668
|
+
if (lockedOut(ctx.state, point.x, point.y)) return void 0;
|
|
50318
50669
|
return ctx.deps.renderer.sync.hitTest(point.x, point.y, acceptTrace(ctx, point));
|
|
50319
50670
|
}
|
|
50320
50671
|
//#endregion
|
|
@@ -51389,7 +51740,9 @@ function press(ctx, entity) {
|
|
|
51389
51740
|
* trace — a second finger stays ignored. When the view under the finger sits in a moving scroll,
|
|
51390
51741
|
* that scroll takes the press: the finger stops it, and the press is caught. A view drawn over a
|
|
51391
51742
|
* moving scroll from another root, a HUD or a popup button, keeps its press. A view that carries
|
|
51392
|
-
* `Traceable` starts a trace instead of a press: it is not tagged `Pressed`.
|
|
51743
|
+
* `Traceable` starts a trace instead of a press: it is not tagged `Pressed`. A press outside the
|
|
51744
|
+
* window of a guide's lock reaches no view: it answers the guide's `blocked`, or nothing, and its
|
|
51745
|
+
* release answers nothing more.
|
|
51393
51746
|
*
|
|
51394
51747
|
* @param ctx - Domain context of the input plugin.
|
|
51395
51748
|
* @param pointer - The `Pointer` resource of this frame.
|
|
@@ -51410,6 +51763,10 @@ function onDown(ctx, pointer, point, sample) {
|
|
|
51410
51763
|
pointer.down = true;
|
|
51411
51764
|
pointer.justPressed = true;
|
|
51412
51765
|
capture(ctx, true);
|
|
51766
|
+
if (lockedOut(ctx.state, point.x, point.y)) {
|
|
51767
|
+
submitBlocked(ctx);
|
|
51768
|
+
return;
|
|
51769
|
+
}
|
|
51413
51770
|
const entity = findPressed(ctx, point.x, point.y);
|
|
51414
51771
|
if (entity === void 0) return;
|
|
51415
51772
|
const scroll = movingScrollOf(ctx, entity);
|
|
@@ -51831,7 +52188,8 @@ function createInputState(_ctx) {
|
|
|
51831
52188
|
resolveNow: void 0,
|
|
51832
52189
|
resolvedEarly: false,
|
|
51833
52190
|
cursor: void 0,
|
|
51834
|
-
controls: []
|
|
52191
|
+
controls: [],
|
|
52192
|
+
lock: void 0
|
|
51835
52193
|
};
|
|
51836
52194
|
}
|
|
51837
52195
|
/**
|
|
@@ -51914,7 +52272,7 @@ function startInput(ctx) {
|
|
|
51914
52272
|
/**
|
|
51915
52273
|
* Closes what the plugin opened: the six pointer listeners, the key listener, the frame callback,
|
|
51916
52274
|
* the `onTap`, `onKey` and `onPointer` listeners and the mutes a drag still holds on the held view
|
|
51917
|
-
* and on every view it carries. The path of a trace
|
|
52275
|
+
* and on every view it carries. The path of a trace and the lock of a guide are forgotten. The tags, `Traced` among them,
|
|
51918
52276
|
* die with the world, which stops after `input`: a teardown context reaches no world.
|
|
51919
52277
|
*
|
|
51920
52278
|
* @param state - The plugin state, the only thing a teardown context carries.
|
|
@@ -51949,6 +52307,7 @@ function stopInput(state) {
|
|
|
51949
52307
|
state.tapListeners = [];
|
|
51950
52308
|
state.keyListeners = [];
|
|
51951
52309
|
state.pointerListeners = [];
|
|
52310
|
+
state.lock = void 0;
|
|
51952
52311
|
}
|
|
51953
52312
|
//#endregion
|
|
51954
52313
|
//#region src/plugins/input/api.ts
|
|
@@ -52065,7 +52424,7 @@ function answerTrace(ctx, path) {
|
|
|
52065
52424
|
}
|
|
52066
52425
|
/**
|
|
52067
52426
|
* Creates the input API: `app.input.tap`, `.press`, `.drag`, `.swipe`, `.trace`, `.onTap`,
|
|
52068
|
-
* `.onPointer`, `.onKey`, `.pressKey`, `.cursor`, `.listeners` and `.controls`.
|
|
52427
|
+
* `.onPointer`, `.onKey`, `.pressKey`, `.cursor`, `.listeners`, `.lock` and `.controls`.
|
|
52069
52428
|
*
|
|
52070
52429
|
* @param ctx - Kernel context of the input plugin.
|
|
52071
52430
|
* @returns The plugin API.
|
|
@@ -52087,6 +52446,9 @@ function createInputApi(ctx) {
|
|
|
52087
52446
|
}),
|
|
52088
52447
|
cursor: () => inputCtx.state.cursor ?? inputCtx.config.cursor.idle,
|
|
52089
52448
|
listeners: () => countListeners(inputCtx.state),
|
|
52449
|
+
lock: { window: (rect) => {
|
|
52450
|
+
inputCtx.state.lock = rect;
|
|
52451
|
+
} },
|
|
52090
52452
|
controls: { add: (component) => addControl(inputCtx.state, component) }
|
|
52091
52453
|
};
|
|
52092
52454
|
}
|
|
@@ -63794,157 +64156,475 @@ function canDespawn(element) {
|
|
|
63794
64156
|
}
|
|
63795
64157
|
//#endregion
|
|
63796
64158
|
//#region src/plugins/ui/layout/guide.ts
|
|
63797
|
-
/** How dark the
|
|
64159
|
+
/** How dark the veil is when the guide names no alpha. */
|
|
63798
64160
|
const DIM_ALPHA = .6;
|
|
64161
|
+
/** The colour of the veil when the guide names none. */
|
|
64162
|
+
const DIM_COLOR = 0;
|
|
63799
64163
|
/** Where the guide is drawn: above every popup root of the `ui` layer. */
|
|
63800
64164
|
const GUIDE_ORDER = 1e6;
|
|
64165
|
+
/** The patch that only marks a component changed: its fields were written in place. */
|
|
64166
|
+
const NO_PATCH$1 = Object.freeze({});
|
|
64167
|
+
/**
|
|
64168
|
+
* Frames of the pass a guide that replaced one with the same targets keeps that guide's window while
|
|
64169
|
+
* none of its targets is shown yet: a node that derives its guide again in the tick its edge
|
|
64170
|
+
* committed finds a view the edge made before the world laid it out.
|
|
64171
|
+
*/
|
|
64172
|
+
const GRACE_FRAMES = 2;
|
|
64173
|
+
/** Frames in a row a key of the guide names no entity before a dev build names it, as for an anchor. */
|
|
64174
|
+
const MISSING_FRAMES = 2;
|
|
64175
|
+
/**
|
|
64176
|
+
* Creates a rect the guide writes in place every frame. Its keys come in the order `w, h, x, y`, the
|
|
64177
|
+
* order of `ownRect` in `jsx/state.ts`: a rect of the order `x, y, w, h` shares its shape with the
|
|
64178
|
+
* frozen `Box` values, and V8 boxes every fractional number written into one.
|
|
64179
|
+
*
|
|
64180
|
+
* @returns A rect at 0, 0 of size 0.
|
|
64181
|
+
* @example
|
|
64182
|
+
* ```ts
|
|
64183
|
+
* Object.keys(emptyRect()); // ["w", "h", "x", "y"]
|
|
64184
|
+
* ```
|
|
64185
|
+
*/
|
|
64186
|
+
function emptyRect() {
|
|
64187
|
+
return {
|
|
64188
|
+
w: 0,
|
|
64189
|
+
h: 0,
|
|
64190
|
+
x: 0,
|
|
64191
|
+
y: 0
|
|
64192
|
+
};
|
|
64193
|
+
}
|
|
64194
|
+
/**
|
|
64195
|
+
* Tells whether a JSON value is an object with keys: not `null`, not an array.
|
|
64196
|
+
*
|
|
64197
|
+
* @param value - Any JSON value, or nothing.
|
|
64198
|
+
* @returns `true` for a plain object.
|
|
64199
|
+
* @example
|
|
64200
|
+
* ```ts
|
|
64201
|
+
* isPlainRecord({ target: [] }); // true
|
|
64202
|
+
* ```
|
|
64203
|
+
*/
|
|
64204
|
+
function isPlainRecord(value) {
|
|
64205
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
64206
|
+
}
|
|
64207
|
+
/**
|
|
64208
|
+
* Tells whether a JSON value is a target: an object with a string `projection` and a string `key`.
|
|
64209
|
+
*
|
|
64210
|
+
* @param value - One entry of a guide's `target`.
|
|
64211
|
+
* @returns True for a target.
|
|
64212
|
+
* @example
|
|
64213
|
+
* ```ts
|
|
64214
|
+
* isTarget({ projection: "hud", key: "play" }); // true
|
|
64215
|
+
* ```
|
|
64216
|
+
*/
|
|
64217
|
+
function isTarget$1(value) {
|
|
64218
|
+
return isPlainRecord(value) && typeof value.projection === "string" && typeof value.key === "string";
|
|
64219
|
+
}
|
|
63801
64220
|
/**
|
|
63802
|
-
* Reads the
|
|
64221
|
+
* Reads the payload of a guide, or of its veil, as a record.
|
|
64222
|
+
*
|
|
64223
|
+
* @param payload - What `guide()` put in the descriptor, or one of its fields.
|
|
64224
|
+
* @returns The record, or an empty one for anything else.
|
|
64225
|
+
* @example
|
|
64226
|
+
* ```ts
|
|
64227
|
+
* fieldsOf(undefined); // {}
|
|
64228
|
+
* ```
|
|
64229
|
+
*/
|
|
64230
|
+
function fieldsOf(payload) {
|
|
64231
|
+
return isPlainRecord(payload) ? payload : {};
|
|
64232
|
+
}
|
|
64233
|
+
/**
|
|
64234
|
+
* Reads the target a guide names out of its payload, when it names one.
|
|
63803
64235
|
*
|
|
63804
64236
|
* @param payload - What `guide()` put in the descriptor.
|
|
63805
|
-
* @returns The projection and key, or `undefined` when the guide names no target.
|
|
64237
|
+
* @returns The projection and key, or `undefined` when the guide names no single target.
|
|
63806
64238
|
* @example
|
|
63807
64239
|
* ```ts
|
|
63808
64240
|
* readTarget({ target: { projection: "hud", key: "play" } })?.key; // "play"
|
|
63809
64241
|
* ```
|
|
63810
64242
|
*/
|
|
63811
64243
|
function readTarget(payload) {
|
|
63812
|
-
|
|
63813
|
-
|
|
63814
|
-
if (typeof target !== "object" || target === null) return void 0;
|
|
63815
|
-
const record = target;
|
|
63816
|
-
if (typeof record.projection !== "string" || typeof record.key !== "string") return void 0;
|
|
64244
|
+
const target = fieldsOf(payload).target;
|
|
64245
|
+
if (!isTarget$1(target)) return void 0;
|
|
63817
64246
|
return {
|
|
63818
|
-
projection:
|
|
63819
|
-
key:
|
|
64247
|
+
projection: target.projection,
|
|
64248
|
+
key: target.key
|
|
63820
64249
|
};
|
|
63821
64250
|
}
|
|
63822
64251
|
/**
|
|
63823
|
-
*
|
|
63824
|
-
* fitted element on the way up, through the pose of its slot for a root laid out in one), the `Box`
|
|
63825
|
-
* of an element the lookup does not know, else where a
|
|
63826
|
-
* view is drawn: its pose composed through the `Parent` chain (a view a ui slot hosts sits in the
|
|
63827
|
-
* slot's space) with the size of its panel or its sprite. A sprite of size 0 is drawn at its
|
|
63828
|
-
* texture's size, which `ui` does not know: its hole has size 0.
|
|
64252
|
+
* Reads every target a guide names: its one target, or the targets of its list.
|
|
63829
64253
|
*
|
|
63830
|
-
* @param
|
|
63831
|
-
* @
|
|
63832
|
-
* @
|
|
63833
|
-
*
|
|
64254
|
+
* @param payload - What `guide()` put in the descriptor.
|
|
64255
|
+
* @returns The targets, copied; empty when the guide names none.
|
|
64256
|
+
* @example
|
|
64257
|
+
* ```ts
|
|
64258
|
+
* readTargets({ target: [{ projection: "board", key: "c2" }, { projection: "board", key: "c3" }] }).length; // 2
|
|
64259
|
+
* ```
|
|
63834
64260
|
*/
|
|
63835
|
-
function
|
|
63836
|
-
const
|
|
63837
|
-
if (
|
|
63838
|
-
const
|
|
63839
|
-
|
|
63840
|
-
return slot === void 0 ? rect : drawnRect(rootPoseOf(ctx.deps.world.ecs, slot), rect);
|
|
64261
|
+
function readTargets(payload) {
|
|
64262
|
+
const target = fieldsOf(payload).target;
|
|
64263
|
+
if (!Array.isArray(target)) {
|
|
64264
|
+
const one = readTarget(payload);
|
|
64265
|
+
return one === void 0 ? [] : [one];
|
|
63841
64266
|
}
|
|
63842
|
-
|
|
63843
|
-
|
|
63844
|
-
|
|
63845
|
-
|
|
63846
|
-
|
|
63847
|
-
|
|
63848
|
-
|
|
63849
|
-
|
|
63850
|
-
|
|
63851
|
-
|
|
63852
|
-
|
|
63853
|
-
|
|
63854
|
-
|
|
63855
|
-
|
|
63856
|
-
|
|
63857
|
-
|
|
63858
|
-
|
|
63859
|
-
|
|
63860
|
-
|
|
63861
|
-
|
|
63862
|
-
|
|
63863
|
-
|
|
63864
|
-
|
|
63865
|
-
|
|
63866
|
-
|
|
63867
|
-
|
|
64267
|
+
return target.filter((entry) => isTarget$1(entry)).map((entry) => ({
|
|
64268
|
+
projection: entry.projection,
|
|
64269
|
+
key: entry.key
|
|
64270
|
+
}));
|
|
64271
|
+
}
|
|
64272
|
+
/**
|
|
64273
|
+
* Reads the padding of a guide's window: a finite number, 0 otherwise.
|
|
64274
|
+
*
|
|
64275
|
+
* @param payload - What `guide()` put in the descriptor.
|
|
64276
|
+
* @returns The padding in screen reference units.
|
|
64277
|
+
* @example
|
|
64278
|
+
* ```ts
|
|
64279
|
+
* readPad({ pad: 4 }); // 4
|
|
64280
|
+
* ```
|
|
64281
|
+
*/
|
|
64282
|
+
function readPad(payload) {
|
|
64283
|
+
const pad = fieldsOf(payload).pad;
|
|
64284
|
+
return typeof pad === "number" && Number.isFinite(pad) ? pad : 0;
|
|
64285
|
+
}
|
|
64286
|
+
/**
|
|
64287
|
+
* Reads the veil of a guide: `false` draws none, otherwise its colour and alpha, black at 0.6 for
|
|
64288
|
+
* what the guide leaves out.
|
|
64289
|
+
*
|
|
64290
|
+
* @param payload - What `guide()` put in the descriptor.
|
|
64291
|
+
* @returns The veil.
|
|
64292
|
+
* @example
|
|
64293
|
+
* ```ts
|
|
64294
|
+
* readVeil({ veil: { alpha: 0 } }); // { color: 0, alpha: 0 }
|
|
64295
|
+
* ```
|
|
64296
|
+
*/
|
|
64297
|
+
function readVeil(payload) {
|
|
64298
|
+
const veil = fieldsOf(payload).veil;
|
|
64299
|
+
if (veil === false) return false;
|
|
64300
|
+
const { color, alpha } = fieldsOf(veil);
|
|
64301
|
+
return {
|
|
64302
|
+
color: typeof color === "number" ? color : DIM_COLOR,
|
|
64303
|
+
alpha: typeof alpha === "number" ? alpha : DIM_ALPHA
|
|
64304
|
+
};
|
|
64305
|
+
}
|
|
64306
|
+
/**
|
|
64307
|
+
* Writes one rect in place.
|
|
64308
|
+
*
|
|
64309
|
+
* @param out - The rect written.
|
|
64310
|
+
* @param x - Its left.
|
|
64311
|
+
* @param y - Its top.
|
|
64312
|
+
* @param w - Its width.
|
|
64313
|
+
* @param h - Its height.
|
|
64314
|
+
*/
|
|
64315
|
+
function setRect(out, x, y, w, h) {
|
|
64316
|
+
if (out === void 0) return;
|
|
64317
|
+
out.x = x;
|
|
64318
|
+
out.y = y;
|
|
64319
|
+
out.w = w;
|
|
64320
|
+
out.h = h;
|
|
63868
64321
|
}
|
|
63869
64322
|
/**
|
|
63870
|
-
*
|
|
64323
|
+
* Writes the rectangles that cover the screen except the window, in place: one over the whole
|
|
64324
|
+
* screen when there is no window (the others, if any, take no room), four around it otherwise. A
|
|
64325
|
+
* side the window leaves no room for has size 0.
|
|
63871
64326
|
*
|
|
63872
64327
|
* @param screen - The viewport rect.
|
|
63873
|
-
* @param hole - The
|
|
63874
|
-
* @
|
|
64328
|
+
* @param hole - The window left uncovered, or nothing for a full veil.
|
|
64329
|
+
* @param out - One rect for a guide with no target, four for one with a window, none for no veil.
|
|
64330
|
+
*/
|
|
64331
|
+
function dimInto(screen, hole, out) {
|
|
64332
|
+
if (hole === void 0) {
|
|
64333
|
+
setRect(out[0], 0, 0, screen.w, screen.h);
|
|
64334
|
+
for (let index = 1; index < out.length; index += 1) setRect(out[index], 0, 0, 0, 0);
|
|
64335
|
+
return;
|
|
64336
|
+
}
|
|
64337
|
+
const below = hole.y + hole.h;
|
|
64338
|
+
const after = hole.x + hole.w;
|
|
64339
|
+
setRect(out[0], 0, 0, screen.w, Math.max(0, hole.y));
|
|
64340
|
+
setRect(out[1], 0, below, screen.w, Math.max(0, screen.h - below));
|
|
64341
|
+
setRect(out[2], 0, hole.y, Math.max(0, hole.x), hole.h);
|
|
64342
|
+
setRect(out[3], after, hole.y, Math.max(0, screen.w - after), hole.h);
|
|
64343
|
+
}
|
|
64344
|
+
/**
|
|
64345
|
+
* Places a guide for this frame: its window over the union of its shown targets, grown by its
|
|
64346
|
+
* padding, and the rects of its veil around it, all written in place. No target shown: the window
|
|
64347
|
+
* keeps its last numbers; during its grace, a guide that took over the window of the one it
|
|
64348
|
+
* replaced keeps that window, otherwise the veil covers the screen.
|
|
64349
|
+
*
|
|
64350
|
+
* @param reader - What the resolver reads.
|
|
64351
|
+
* @param viewport - The viewport the veil covers.
|
|
64352
|
+
* @param guide - The guide: `found` is written.
|
|
64353
|
+
* @returns True when the window holds a rect to cut: a shown target's, or the one kept.
|
|
64354
|
+
*/
|
|
64355
|
+
function placeGuide(reader, viewport, guide) {
|
|
64356
|
+
const { window, pad } = guide;
|
|
64357
|
+
guide.found = guide.targets.length > 0 && targetsInto(reader, guide.targets, window, guide.scratch);
|
|
64358
|
+
let shown = guide.grace > 0;
|
|
64359
|
+
if (guide.found) {
|
|
64360
|
+
window.x -= pad;
|
|
64361
|
+
window.y -= pad;
|
|
64362
|
+
window.w += 2 * pad;
|
|
64363
|
+
window.h += 2 * pad;
|
|
64364
|
+
shown = window.w > 0 && window.h > 0;
|
|
64365
|
+
guide.grace = 0;
|
|
64366
|
+
}
|
|
64367
|
+
const size = viewport.size();
|
|
64368
|
+
guide.screen.w = size.width;
|
|
64369
|
+
guide.screen.h = size.height;
|
|
64370
|
+
dimInto(guide.screen, shown ? window : void 0, guide.rects);
|
|
64371
|
+
return shown;
|
|
64372
|
+
}
|
|
64373
|
+
/**
|
|
64374
|
+
* Writes the rects of a guide onto its veil, field by field on the stored `Transform` and `Shape`
|
|
64375
|
+
* values, which are only marked changed: a patch of doubles boxes 16 B a field. A rect that did not
|
|
64376
|
+
* move writes nothing; a veil whose components wait for the flush is written in the next frame.
|
|
64377
|
+
*
|
|
64378
|
+
* @param ecs - The world's entities.
|
|
64379
|
+
* @param guide - The guide, its rects placed.
|
|
64380
|
+
*/
|
|
64381
|
+
function writeVeils(ecs, guide) {
|
|
64382
|
+
const rects = guide.rects;
|
|
64383
|
+
let index = 0;
|
|
64384
|
+
for (const entity of guide.veils) {
|
|
64385
|
+
const rect = rects[index];
|
|
64386
|
+
const pose = ecs.get(entity, Transform);
|
|
64387
|
+
const shape = ecs.get(entity, Shape);
|
|
64388
|
+
index += 1;
|
|
64389
|
+
if (rect === void 0 || pose === void 0 || shape === void 0) continue;
|
|
64390
|
+
if (pose.x !== rect.x || pose.y !== rect.y) {
|
|
64391
|
+
pose.x = rect.x;
|
|
64392
|
+
pose.y = rect.y;
|
|
64393
|
+
ecs.set(entity, Transform, NO_PATCH$1);
|
|
64394
|
+
}
|
|
64395
|
+
if (shape.w !== rect.w || shape.h !== rect.h) {
|
|
64396
|
+
shape.w = rect.w;
|
|
64397
|
+
shape.h = rect.h;
|
|
64398
|
+
ecs.set(entity, Shape, NO_PATCH$1);
|
|
64399
|
+
}
|
|
64400
|
+
}
|
|
64401
|
+
}
|
|
64402
|
+
/**
|
|
64403
|
+
* Hands `input` the lock of a guide when it changes: the window while a target is shown, everything
|
|
64404
|
+
* while none is. The window is handed by reference once; `placeGuide` writes it in place.
|
|
64405
|
+
*
|
|
64406
|
+
* @param ctx - Domain context of the ui plugin.
|
|
64407
|
+
* @param guide - The guide.
|
|
64408
|
+
* @param shown - Whether a target is shown in this frame.
|
|
64409
|
+
*/
|
|
64410
|
+
function lockTo(ctx, guide, shown) {
|
|
64411
|
+
const wanted = shown ? "window" : "all";
|
|
64412
|
+
if (guide.locked === wanted) return;
|
|
64413
|
+
guide.locked = wanted;
|
|
64414
|
+
ctx.deps.input.lock.window(shown ? guide.window : null);
|
|
64415
|
+
}
|
|
64416
|
+
/**
|
|
64417
|
+
* Spawns the veil of a guide at the rects placed for it: none for `veil: false`, one over the
|
|
64418
|
+
* screen for a guide with no target, four around its window otherwise.
|
|
64419
|
+
*
|
|
64420
|
+
* @param ecs - The world's entities.
|
|
64421
|
+
* @param rects - The rects placed for the guide, one per rectangle of the veil.
|
|
64422
|
+
* @param veil - The colour and alpha of the veil.
|
|
64423
|
+
* @returns The spawned rectangles, in the order of `rects`.
|
|
64424
|
+
*/
|
|
64425
|
+
function spawnVeils(ecs, rects, veil) {
|
|
64426
|
+
if (veil === false) return [];
|
|
64427
|
+
return rects.map((rect) => ecs.spawn(UI_OWNER, [
|
|
64428
|
+
Layer({ name: "ui" }),
|
|
64429
|
+
Order({ value: GUIDE_ORDER }),
|
|
64430
|
+
Transform({
|
|
64431
|
+
x: rect.x,
|
|
64432
|
+
y: rect.y
|
|
64433
|
+
}),
|
|
64434
|
+
Shape({
|
|
64435
|
+
w: rect.w,
|
|
64436
|
+
h: rect.h,
|
|
64437
|
+
fill: veil.color,
|
|
64438
|
+
alpha: veil.alpha
|
|
64439
|
+
})
|
|
64440
|
+
]));
|
|
64441
|
+
}
|
|
64442
|
+
/**
|
|
64443
|
+
* Ends a guide once: its veil leaves and, when it is still the guide `ui` shows, the lock is
|
|
64444
|
+
* lifted.
|
|
64445
|
+
*
|
|
64446
|
+
* @param ctx - Domain context of the ui plugin.
|
|
64447
|
+
* @param guide - The guide that ends.
|
|
64448
|
+
*/
|
|
64449
|
+
function endGuide(ctx, guide) {
|
|
64450
|
+
if (guide.ended) return;
|
|
64451
|
+
guide.ended = true;
|
|
64452
|
+
for (const veil of guide.veils) ctx.deps.world.ecs.despawn(veil);
|
|
64453
|
+
if (ctx.state.layout.guide !== guide) return;
|
|
64454
|
+
ctx.state.layout.guide = void 0;
|
|
64455
|
+
ctx.state.layout.lastGuide = guide;
|
|
64456
|
+
guide.endedAt = ctx.deps.time.snapshot().frame;
|
|
64457
|
+
ctx.deps.input.lock.window(void 0);
|
|
64458
|
+
}
|
|
64459
|
+
/**
|
|
64460
|
+
* Tells whether two guides name the same targets, in the same order.
|
|
64461
|
+
*
|
|
64462
|
+
* @param first - One list of targets.
|
|
64463
|
+
* @param second - The other.
|
|
64464
|
+
* @returns True when every target matches.
|
|
63875
64465
|
* @example
|
|
63876
64466
|
* ```ts
|
|
63877
|
-
*
|
|
64467
|
+
* sameTargets([{ projection: "hud", key: "play" }], [{ projection: "hud", key: "play" }]); // true
|
|
63878
64468
|
* ```
|
|
63879
64469
|
*/
|
|
63880
|
-
function
|
|
63881
|
-
|
|
63882
|
-
|
|
63883
|
-
|
|
63884
|
-
|
|
63885
|
-
|
|
63886
|
-
|
|
63887
|
-
|
|
63888
|
-
|
|
63889
|
-
|
|
63890
|
-
|
|
63891
|
-
|
|
63892
|
-
|
|
63893
|
-
|
|
63894
|
-
|
|
63895
|
-
|
|
63896
|
-
|
|
63897
|
-
|
|
63898
|
-
|
|
63899
|
-
|
|
64470
|
+
function sameTargets(first, second) {
|
|
64471
|
+
return first.length === second.length && first.every((target, index) => target.projection === second[index]?.projection && target.key === second[index]?.key);
|
|
64472
|
+
}
|
|
64473
|
+
/**
|
|
64474
|
+
* Hands a new guide the window of the guide it replaces, when that one names the same targets and
|
|
64475
|
+
* cut a window: the guide shown now, or one that ended in this frame (a node left and entered again
|
|
64476
|
+
* in one tick). The new guide keeps it for its grace while none of its targets is shown.
|
|
64477
|
+
*
|
|
64478
|
+
* @param ctx - Domain context of the ui plugin.
|
|
64479
|
+
* @param guide - The new guide, not placed yet.
|
|
64480
|
+
* @param replaced - The guide shown now, if any.
|
|
64481
|
+
*/
|
|
64482
|
+
function takeOver(ctx, guide, replaced) {
|
|
64483
|
+
const last = ctx.state.layout.lastGuide;
|
|
64484
|
+
const before = replaced ?? (last !== void 0 && last.endedAt === ctx.deps.time.snapshot().frame ? last : void 0);
|
|
64485
|
+
if (before?.locked !== "window" || !sameTargets(before.targets, guide.targets)) return;
|
|
64486
|
+
guide.window.x = before.window.x;
|
|
64487
|
+
guide.window.y = before.window.y;
|
|
64488
|
+
guide.window.w = before.window.w;
|
|
64489
|
+
guide.window.h = before.window.h;
|
|
64490
|
+
guide.grace = GRACE_FRAMES;
|
|
64491
|
+
}
|
|
64492
|
+
/**
|
|
64493
|
+
* Names, in a dev build, a guide a key of which named no entity two frames in a row, once: a target
|
|
64494
|
+
* that never shows keeps the whole screen veiled and every press locked.
|
|
64495
|
+
*
|
|
64496
|
+
* @param ctx - Domain context of the ui plugin.
|
|
64497
|
+
* @param guide - The guide.
|
|
64498
|
+
*/
|
|
64499
|
+
function countMissing(ctx, guide) {
|
|
64500
|
+
const projection = ctx.deps.world.projection;
|
|
64501
|
+
let missing = false;
|
|
64502
|
+
for (const target of guide.targets) if (projection.entityOf(target.projection, target.key) === void 0) missing = true;
|
|
64503
|
+
guide.missing = missing ? guide.missing + 1 : 0;
|
|
64504
|
+
if (guide.missing < MISSING_FRAMES) return;
|
|
64505
|
+
guide.warned = true;
|
|
64506
|
+
ctx.log.warn("ui:guide-target-missing", { targets: guide.targets });
|
|
64507
|
+
}
|
|
64508
|
+
/**
|
|
64509
|
+
* Builds the guide a descriptor names, before its first placement: the targets, the padding, one
|
|
64510
|
+
* rect per rectangle of its veil and the window.
|
|
64511
|
+
*
|
|
64512
|
+
* @param payload - What `guide()` put in the descriptor.
|
|
64513
|
+
* @param veil - The veil of the guide.
|
|
64514
|
+
* @returns The guide, nothing placed and nothing locked yet.
|
|
64515
|
+
*/
|
|
64516
|
+
function createGuide(payload, veil) {
|
|
64517
|
+
const targets = readTargets(payload);
|
|
64518
|
+
const count = targets.length === 0 ? 1 : 4;
|
|
64519
|
+
return {
|
|
64520
|
+
targets,
|
|
64521
|
+
pad: readPad(payload),
|
|
64522
|
+
veils: [],
|
|
64523
|
+
rects: veil === false ? [] : Array.from({ length: count }, () => emptyRect()),
|
|
64524
|
+
window: emptyRect(),
|
|
64525
|
+
screen: emptyRect(),
|
|
64526
|
+
scratch: {
|
|
64527
|
+
part: emptyRect(),
|
|
64528
|
+
pose: {
|
|
64529
|
+
x: 0,
|
|
64530
|
+
y: 0,
|
|
64531
|
+
rotation: 0,
|
|
64532
|
+
scale: 1,
|
|
64533
|
+
pivot: {
|
|
64534
|
+
x: 0,
|
|
64535
|
+
y: 0
|
|
64536
|
+
}
|
|
64537
|
+
}
|
|
63900
64538
|
},
|
|
63901
|
-
|
|
63902
|
-
|
|
63903
|
-
|
|
63904
|
-
|
|
63905
|
-
|
|
63906
|
-
|
|
63907
|
-
|
|
64539
|
+
locked: "none",
|
|
64540
|
+
found: false,
|
|
64541
|
+
grace: 0,
|
|
64542
|
+
missing: 0,
|
|
64543
|
+
warned: false,
|
|
64544
|
+
ended: false,
|
|
64545
|
+
endedAt: -1
|
|
64546
|
+
};
|
|
63908
64547
|
}
|
|
63909
64548
|
/**
|
|
63910
|
-
* Builds the `guide
|
|
63911
|
-
*
|
|
64549
|
+
* Builds the system `ui.guide`: places the guide `ui` shows, its veil and its lock, once a frame.
|
|
64550
|
+
*
|
|
64551
|
+
* @param ctx - Domain context of the ui plugin.
|
|
64552
|
+
* @returns The step the system runs once a frame.
|
|
64553
|
+
*/
|
|
64554
|
+
function createGuidePass(ctx) {
|
|
64555
|
+
const reader = readerOf(ctx);
|
|
64556
|
+
const viewport = ctx.deps.renderer.viewport;
|
|
64557
|
+
const ecs = ctx.deps.world.ecs;
|
|
64558
|
+
return () => {
|
|
64559
|
+
const guide = ctx.state.layout.guide;
|
|
64560
|
+
if (guide === void 0) return;
|
|
64561
|
+
const shown = placeGuide(reader, viewport, guide);
|
|
64562
|
+
if (!guide.found && guide.grace > 0) guide.grace -= 1;
|
|
64563
|
+
if (typeof __MOKU_GAME_DEV__ !== "undefined" && __MOKU_GAME_DEV__ && !guide.warned) countMissing(ctx, guide);
|
|
64564
|
+
writeVeils(ecs, guide);
|
|
64565
|
+
lockTo(ctx, guide, shown);
|
|
64566
|
+
};
|
|
64567
|
+
}
|
|
64568
|
+
/**
|
|
64569
|
+
* Builds the `guide` handler. It returns at once: the node continues while the veil stays on
|
|
64570
|
+
* screen, and the veil and the lock leave when the narrow is lifted. A new guide replaces the one
|
|
64571
|
+
* `ui` shows; one with the same targets as the guide it replaces (shown now, or ended in this
|
|
64572
|
+
* frame) keeps that guide's window for its grace while its targets are not laid out yet. Fast mode
|
|
64573
|
+
* draws nothing.
|
|
63912
64574
|
*
|
|
63913
64575
|
* @param ctx - Domain context of the ui plugin.
|
|
63914
64576
|
* @returns The handler `flow.fx.handle("guide", ...)` takes.
|
|
63915
64577
|
*/
|
|
63916
64578
|
function createGuideHandler(ctx) {
|
|
64579
|
+
const reader = readerOf(ctx);
|
|
64580
|
+
const viewport = ctx.deps.renderer.viewport;
|
|
63917
64581
|
return (descriptor, { signal, mode }) => {
|
|
63918
|
-
if (mode === "fast") return;
|
|
63919
|
-
const
|
|
63920
|
-
|
|
63921
|
-
const
|
|
63922
|
-
const
|
|
63923
|
-
|
|
63924
|
-
|
|
63925
|
-
|
|
63926
|
-
|
|
63927
|
-
|
|
63928
|
-
|
|
63929
|
-
|
|
63930
|
-
|
|
63931
|
-
|
|
63932
|
-
|
|
63933
|
-
|
|
63934
|
-
|
|
63935
|
-
|
|
63936
|
-
|
|
63937
|
-
|
|
63938
|
-
|
|
63939
|
-
|
|
63940
|
-
|
|
63941
|
-
|
|
63942
|
-
|
|
63943
|
-
|
|
63944
|
-
|
|
63945
|
-
|
|
63946
|
-
|
|
63947
|
-
|
|
64582
|
+
if (mode === "fast" || signal.aborted) return;
|
|
64583
|
+
const replaced = ctx.state.layout.guide;
|
|
64584
|
+
if (replaced !== void 0) endGuide(ctx, replaced);
|
|
64585
|
+
const veil = readVeil(descriptor.payload);
|
|
64586
|
+
const guide = createGuide(descriptor.payload, veil);
|
|
64587
|
+
takeOver(ctx, guide, replaced);
|
|
64588
|
+
const shown = placeGuide(reader, viewport, guide);
|
|
64589
|
+
guide.veils = spawnVeils(ctx.deps.world.ecs, guide.rects, veil);
|
|
64590
|
+
ctx.state.layout.guide = guide;
|
|
64591
|
+
lockTo(ctx, guide, shown);
|
|
64592
|
+
signal.addEventListener("abort", () => endGuide(ctx, guide), { once: true });
|
|
64593
|
+
};
|
|
64594
|
+
}
|
|
64595
|
+
/**
|
|
64596
|
+
* Tells whether the lock of a guide keeps a point from every view: it locks everything, or the
|
|
64597
|
+
* point lies outside its window, edges included, as `input` decides it.
|
|
64598
|
+
*
|
|
64599
|
+
* @param guide - The guide on screen.
|
|
64600
|
+
* @param x - Reference x.
|
|
64601
|
+
* @param y - Reference y.
|
|
64602
|
+
* @returns True when the point is locked.
|
|
64603
|
+
*/
|
|
64604
|
+
function locksPoint(guide, x, y) {
|
|
64605
|
+
if (guide.locked === "all") return true;
|
|
64606
|
+
if (guide.locked !== "window") return false;
|
|
64607
|
+
const { window } = guide;
|
|
64608
|
+
return x < window.x || x > window.x + window.w || y < window.y || y > window.y + window.h;
|
|
64609
|
+
}
|
|
64610
|
+
/**
|
|
64611
|
+
* Wraps the pointer door of the text fields, which finds the field under a sample on its own:
|
|
64612
|
+
* while a guide stands, a sample whose point its lock keeps from every view does nothing, so a
|
|
64613
|
+
* field outside the window is neither focused nor blurred. The point is brought into reference
|
|
64614
|
+
* units as `input` brings it.
|
|
64615
|
+
*
|
|
64616
|
+
* @param ctx - Domain context of the ui plugin.
|
|
64617
|
+
* @param door - The `onPointer` listener of the text fields.
|
|
64618
|
+
* @returns The listener `input.onPointer` takes.
|
|
64619
|
+
*/
|
|
64620
|
+
function guardPointer(ctx, door) {
|
|
64621
|
+
return (sample) => {
|
|
64622
|
+
const guide = ctx.state.layout.guide;
|
|
64623
|
+
if (guide !== void 0) {
|
|
64624
|
+
const point = ctx.deps.renderer.viewport.toReference(sample.clientX, sample.clientY);
|
|
64625
|
+
if (locksPoint(guide, point.x, point.y)) return;
|
|
64626
|
+
}
|
|
64627
|
+
door(sample);
|
|
63948
64628
|
};
|
|
63949
64629
|
}
|
|
63950
64630
|
//#endregion
|
|
@@ -66547,7 +67227,7 @@ function drawsViews(ctx) {
|
|
|
66547
67227
|
return ctx.deps.renderer.host.kind() !== "none";
|
|
66548
67228
|
}
|
|
66549
67229
|
/**
|
|
66550
|
-
* Opens the
|
|
67230
|
+
* Opens the four systems of phase `layout`, the system `ui.enter` of phase `sync`, the seven world
|
|
66551
67231
|
* hooks of `Tree`, `Box`, `Pressed` and `PointerOver`, the two that tell the hosting step a view
|
|
66552
67232
|
* lost its `Parent` or its `Held` (a view freed so may hang under its host again), the listener
|
|
66553
67233
|
* that asks for every root to be built again after a restore or a load, the two effect handlers,
|
|
@@ -66559,7 +67239,7 @@ function drawsViews(ctx) {
|
|
|
66559
67239
|
* `ui`'s part of a scene build (`onBuild`: the roots built aside are reconciled and solved, spec
|
|
66560
67240
|
* 31). On an agent page also the tap counter of `DebugTrigger` and its check of a view that takes
|
|
66561
67241
|
* no press. The third system of `layout`, `ui.anchor`, runs after the solve and places every
|
|
66562
|
-
* `<anchor>` on its targets.
|
|
67242
|
+
* `<anchor>` on its targets; the fourth, `ui.guide`, places the veil and the lock window of a guide.
|
|
66563
67243
|
*
|
|
66564
67244
|
* The `Box` hook plays an element's enter hook and queues it, so the game's systems see its start
|
|
66565
67245
|
* pose (F49); `ui.enter` starts its loop after them and before the frame is drawn, and plays the
|
|
@@ -66589,6 +67269,11 @@ function openRegistrations(ctx, jsx, layout) {
|
|
|
66589
67269
|
phase: "layout",
|
|
66590
67270
|
query: [],
|
|
66591
67271
|
run: anchors
|
|
67272
|
+
})), ecs.system(system({
|
|
67273
|
+
name: "ui.guide",
|
|
67274
|
+
phase: "layout",
|
|
67275
|
+
query: [],
|
|
67276
|
+
run: createGuidePass(ctx)
|
|
66592
67277
|
})), ecs.system(system({
|
|
66593
67278
|
name: "ui.enter",
|
|
66594
67279
|
phase: "sync",
|
|
@@ -66599,7 +67284,7 @@ function openRegistrations(ctx, jsx, layout) {
|
|
|
66599
67284
|
jsx.mountRoot(entity, place?.projection ?? "ui", ecs.get(entity, Layer)?.name ?? "ui");
|
|
66600
67285
|
}), ecs.onRemoved(Tree, (entity) => jsx.unmountRoot(entity)), ecs.onAdded(Box, (entity) => jsx.queueEnter(entity)), projection.onConverged(jsx.converged), ecs.onAdded(Pressed, (entity) => jsx.markPointer(entity, "pressed", true)), ecs.onRemoved(Pressed, (entity) => jsx.markPointer(entity, "pressed", false)), ecs.onAdded(PointerOver, (entity) => jsx.markPointer(entity, "hover", true)), ecs.onRemoved(PointerOver, (entity) => jsx.markPointer(entity, "hover", false)), ecs.onRemoved(Parent, () => hostsMoved(ctx.state.jsx)), ecs.onRemoved(Held, () => hostsMoved(ctx.state.jsx)), ctx.deps.flow.fx.handle("popup", layout.popupHandler(jsx)), ctx.deps.flow.fx.handle("guide", layout.guideHandler()), ctx.deps.flow.fx.onHint((hint) => {
|
|
66601
67286
|
ctx.state.jsx.hints.push(hint);
|
|
66602
|
-
}), ctx.deps.input.onTap(jsx.applyTap), ctx.deps.input.onTap(() => jsx.blur()), ctx.deps.input.onTap(jsx.tapped), ctx.deps.input.onPointer(jsx.pointer), ctx.deps.input.onKey(jsx.key), ctx.deps.input.controls.add(LocalWrite), () => jsx.releaseHosted(), () => ecs.despawnOwnedBy(UI_OWNER));
|
|
67287
|
+
}), ctx.deps.input.onTap(jsx.applyTap), ctx.deps.input.onTap(() => jsx.blur()), ctx.deps.input.onTap(jsx.tapped), ctx.deps.input.onPointer(guardPointer(ctx, jsx.pointer)), ctx.deps.input.onKey(jsx.key), ctx.deps.input.controls.add(LocalWrite), () => jsx.releaseHosted(), () => ecs.despawnOwnedBy(UI_OWNER));
|
|
66603
67288
|
if (drawsViews(ctx)) ctx.state.layout.cleanups.push(projection.onBuild(jsx.asideBuilt));
|
|
66604
67289
|
if (typeof __MOKU_GAME_AGENT__ !== "undefined" && __MOKU_GAME_AGENT__) ctx.state.layout.cleanups.push(ctx.deps.input.onTap((entity) => debugTap(ctx, entity)), ecs.onAdded(DebugTrigger, (entity) => checkTrigger(ctx, entity)));
|
|
66605
67290
|
}
|
|
@@ -66643,6 +67328,8 @@ function stopUi(state) {
|
|
|
66643
67328
|
state.layout.scrolling = void 0;
|
|
66644
67329
|
state.layout.scrollSamples = 0;
|
|
66645
67330
|
state.layout.iconLine = void 0;
|
|
67331
|
+
state.layout.guide = void 0;
|
|
67332
|
+
state.layout.lastGuide = void 0;
|
|
66646
67333
|
state.jsx.components.clear();
|
|
66647
67334
|
state.jsx.roots.clear();
|
|
66648
67335
|
state.jsx.elements.clear();
|
|
@@ -67015,7 +67702,9 @@ function createLayoutState() {
|
|
|
67015
67702
|
scrollPatches: scrollPatches(),
|
|
67016
67703
|
iconLine: void 0,
|
|
67017
67704
|
order: 0,
|
|
67018
|
-
cleanups: []
|
|
67705
|
+
cleanups: [],
|
|
67706
|
+
guide: void 0,
|
|
67707
|
+
lastGuide: void 0
|
|
67019
67708
|
};
|
|
67020
67709
|
}
|
|
67021
67710
|
//#endregion
|
|
@@ -68180,24 +68869,6 @@ function projectionFor() {
|
|
|
68180
68869
|
//#endregion
|
|
68181
68870
|
//#region src/plugins/flow/fx/descriptors.ts
|
|
68182
68871
|
/**
|
|
68183
|
-
* Copies one allowed answer into plain JSON. The `payload` key is absent when there is none, so
|
|
68184
|
-
* the descriptor survives `JSON.stringify` unchanged.
|
|
68185
|
-
*
|
|
68186
|
-
* @param allow - The one answer a guide lets through.
|
|
68187
|
-
* @returns The answer as plain JSON.
|
|
68188
|
-
* @example
|
|
68189
|
-
* ```ts
|
|
68190
|
-
* allowJson({ intent: "merge" }); // { intent: "merge" }: no payload key
|
|
68191
|
-
* ```
|
|
68192
|
-
*/
|
|
68193
|
-
function allowJson(allow) {
|
|
68194
|
-
if (allow.payload === void 0) return { intent: allow.intent };
|
|
68195
|
-
return {
|
|
68196
|
-
intent: allow.intent,
|
|
68197
|
-
payload: allow.payload
|
|
68198
|
-
};
|
|
68199
|
-
}
|
|
68200
|
-
/**
|
|
68201
68872
|
* Creates a fire-and-forget cosmetic descriptor for `fx.emit`. It is dispatched only after the
|
|
68202
68873
|
* commit of its transaction and dropped in fast mode.
|
|
68203
68874
|
*
|
|
@@ -68247,12 +68918,14 @@ function schedule(moment) {
|
|
|
68247
68918
|
};
|
|
68248
68919
|
}
|
|
68249
68920
|
/**
|
|
68250
|
-
* Creates the tutorial descriptor: it narrows the gate to one answer
|
|
68251
|
-
*
|
|
68252
|
-
*
|
|
68253
|
-
*
|
|
68921
|
+
* Creates the tutorial descriptor: it narrows the gate to one answer, and to the `blocked` one a
|
|
68922
|
+
* press outside the window gives, until the node exits. Its visual part is drawn by `ui`: a veil
|
|
68923
|
+
* over the screen with a window cut over the targets (one or the union of a list), grown by `pad`,
|
|
68924
|
+
* and the input lock outside that window; `veil: false` draws nothing and still locks. The targets,
|
|
68925
|
+
* the veil and the highlight list are copied, so a later change of the caller's objects cannot
|
|
68926
|
+
* reach the descriptor.
|
|
68254
68927
|
*
|
|
68255
|
-
* @param options - The allowed answer and the
|
|
68928
|
+
* @param options - The allowed answer, the targets, the veil and the answer of a blocked press.
|
|
68256
68929
|
* @returns The descriptor a node awaits.
|
|
68257
68930
|
* @example
|
|
68258
68931
|
* ```ts
|
|
@@ -68263,17 +68936,9 @@ function schedule(moment) {
|
|
|
68263
68936
|
* ```
|
|
68264
68937
|
*/
|
|
68265
68938
|
function guide(options) {
|
|
68266
|
-
const payload = { allow: allowJson(options.allow) };
|
|
68267
|
-
if (options.target !== void 0) payload.target = {
|
|
68268
|
-
projection: options.target.projection,
|
|
68269
|
-
key: options.target.key
|
|
68270
|
-
};
|
|
68271
|
-
if (options.highlight !== void 0) payload.highlight = [...options.highlight];
|
|
68272
|
-
if (options.hand !== void 0) payload.hand = options.hand;
|
|
68273
|
-
if (options.text !== void 0) payload.text = options.text;
|
|
68274
68939
|
return {
|
|
68275
68940
|
kind: "guide",
|
|
68276
|
-
payload
|
|
68941
|
+
payload: guidePayload(options)
|
|
68277
68942
|
};
|
|
68278
68943
|
}
|
|
68279
68944
|
//#endregion
|