castle-web-cli 0.4.243 → 0.4.245
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/api.d.ts +1 -0
- package/dist/api.js +13 -0
- package/dist/contentOriginTiming.d.ts +13 -0
- package/dist/contentOriginTiming.js +15 -0
- package/dist/imports.js +28 -6
- package/dist/index.js +54 -5
- package/dist/init.js +1 -1
- package/dist/projectState.d.ts +33 -0
- package/dist/projectState.js +97 -0
- package/dist/serve.d.ts +18 -0
- package/dist/serve.js +103 -2
- package/dist/serveSecurity.d.ts +105 -3
- package/dist/serveSecurity.js +500 -39
- package/dist/shell/assets/{index-DulbYIJm.js → index-Bec6LpAv.js} +87 -87
- package/dist/shell/index.html +1 -1
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/runtime.js +57 -0
- package/kits/hub-game/code/client/chrome.js +9 -2
- package/kits/hub-game/code/client/hookLayer.js +8 -0
- package/kits/hub-game/code/client/padCues.js +2 -0
- package/kits/hub-game/code/client/padReadability.js +6 -1
- package/kits/hub-game/code/client/signals.js +126 -0
- package/kits/hub-game/code/client/state.js +4 -0
- package/kits/hub-game/code/server/friendBests.js +8 -2
- package/kits/hub-game/code/server/hub.js +31 -4
- package/kits/hub-game/code/server/npcs.js +4 -0
- package/kits/hub-game/code/server/party.js +3 -0
- package/kits/hub-game/code/server/resumePose.js +30 -9
- package/kits/hub-game/code/server/signals.js +124 -0
- package/kits/hub-game/code/server/writerLease.js +161 -17
- package/kits/hub-game/code/systems/hub.js +21 -2
- package/kits/hub-game/docs/contract.md +92 -11
- package/kits/hub-game/package.json +1 -1
- package/kits/hub-game/scripts/test-menu-client.mjs +7 -6
- package/kits/hub-game/scripts/test-menu-footer-dom.mjs +94 -0
- package/kits/hub-game/scripts/test-pad-cues.mjs +6 -3
- package/kits/hub-game/scripts/test-resume-pose.mjs +85 -0
- package/kits/hub-game/scripts/test-signals.mjs +412 -0
- package/kits/hub-game/scripts/test-writer-lease-server.mjs +108 -4
- package/kits/hub-game/scripts/test-writer-lease.mjs +385 -1
- package/package.json +2 -2
package/dist/shell/index.html
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
<link rel="icon" type="image/png" sizes="32x32" href="/__castle/ide/favicon-32x32.png" />
|
|
11
11
|
<link rel="icon" type="image/png" sizes="16x16" href="/__castle/ide/favicon-16x16.png" />
|
|
12
12
|
<link rel="icon" href="/__castle/ide/favicon.ico" sizes="any" />
|
|
13
|
-
<script type="module" crossorigin src="/__castle/ide/assets/index-
|
|
13
|
+
<script type="module" crossorigin src="/__castle/ide/assets/index-Bec6LpAv.js"></script>
|
|
14
14
|
<link rel="stylesheet" crossorigin href="/__castle/ide/assets/index-MVLfNYd9.css">
|
|
15
15
|
</head>
|
|
16
16
|
<body>
|
package/kits/base/castle.json
CHANGED
package/kits/base/sdk/runtime.js
CHANGED
|
@@ -741,6 +741,10 @@ function connectBridge() {
|
|
|
741
741
|
return;
|
|
742
742
|
}
|
|
743
743
|
const port = event.ports[0];
|
|
744
|
+
// A shell that answers reload requests: tell it this SDK will ask before
|
|
745
|
+
// reloading, so it lets restarts through to us (we flush saves first).
|
|
746
|
+
const reloadRequests = data.reloadRequests === true;
|
|
747
|
+
bridgeReloadPort = reloadRequests ? port : null;
|
|
744
748
|
const socket = {
|
|
745
749
|
readyState: WebSocket.OPEN,
|
|
746
750
|
send: (value) => {
|
|
@@ -756,9 +760,15 @@ function connectBridge() {
|
|
|
756
760
|
const value = messageEvent.data;
|
|
757
761
|
if (!value || typeof value !== "object")
|
|
758
762
|
return;
|
|
763
|
+
if (value.type === "castle-reload-response") {
|
|
764
|
+
settleReloadRequest(value);
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
759
767
|
handleLocalMessage(value);
|
|
760
768
|
};
|
|
761
769
|
port.start();
|
|
770
|
+
if (reloadRequests)
|
|
771
|
+
port.postMessage({ type: "castle-sdk-hello", reloadRequests: true });
|
|
762
772
|
localServeSeen = true;
|
|
763
773
|
ws = socket;
|
|
764
774
|
for (const msg of logBuffer)
|
|
@@ -1108,6 +1118,48 @@ function stashReloadState() {
|
|
|
1108
1118
|
export function requestReload() {
|
|
1109
1119
|
scheduleReload(REQUEST_RELOAD_DEBOUNCE_MS, "requestReload");
|
|
1110
1120
|
}
|
|
1121
|
+
// Set when the shell's bridge answers reload requests (castle-bridge-init's
|
|
1122
|
+
// `reloadRequests`). Before reloading, this frame asks the shell: a frame whose
|
|
1123
|
+
// content-origin grant has expired would only fail to reload in place, so the
|
|
1124
|
+
// shell moves it to fresh origins instead and this page does nothing more.
|
|
1125
|
+
let bridgeReloadPort = null;
|
|
1126
|
+
const RELOAD_REQUEST_TIMEOUT_MS = 4000;
|
|
1127
|
+
const pendingReloadRequests = new Map();
|
|
1128
|
+
let nextReloadRequest = 1;
|
|
1129
|
+
function settleReloadRequest(value) {
|
|
1130
|
+
if (typeof value.requestId !== "string")
|
|
1131
|
+
return;
|
|
1132
|
+
const settle = pendingReloadRequests.get(value.requestId);
|
|
1133
|
+
if (!settle)
|
|
1134
|
+
return;
|
|
1135
|
+
pendingReloadRequests.delete(value.requestId);
|
|
1136
|
+
settle(value.relocated === true);
|
|
1137
|
+
}
|
|
1138
|
+
/** Whether the shell moved this frame (so it must not reload itself). */
|
|
1139
|
+
function askShellToRelocate() {
|
|
1140
|
+
const port = bridgeReloadPort;
|
|
1141
|
+
if (!port)
|
|
1142
|
+
return Promise.resolve(false);
|
|
1143
|
+
const requestId = `reload-${nextReloadRequest++}`;
|
|
1144
|
+
return new Promise((resolve) => {
|
|
1145
|
+
const timer = setTimeout(() => {
|
|
1146
|
+
pendingReloadRequests.delete(requestId);
|
|
1147
|
+
resolve(false);
|
|
1148
|
+
}, RELOAD_REQUEST_TIMEOUT_MS);
|
|
1149
|
+
pendingReloadRequests.set(requestId, (relocated) => {
|
|
1150
|
+
clearTimeout(timer);
|
|
1151
|
+
resolve(relocated);
|
|
1152
|
+
});
|
|
1153
|
+
try {
|
|
1154
|
+
port.postMessage({ type: "castle-reload-request", requestId, href: location.href });
|
|
1155
|
+
}
|
|
1156
|
+
catch {
|
|
1157
|
+
clearTimeout(timer);
|
|
1158
|
+
pendingReloadRequests.delete(requestId);
|
|
1159
|
+
resolve(false);
|
|
1160
|
+
}
|
|
1161
|
+
});
|
|
1162
|
+
}
|
|
1111
1163
|
function scheduleReload(delayMs, reason = "unknown") {
|
|
1112
1164
|
console.log(`[reload] ${panelTag()} scheduling reload (${reason})`);
|
|
1113
1165
|
if (restartTimer !== null)
|
|
@@ -1121,6 +1173,11 @@ function scheduleReload(delayMs, reason = "unknown") {
|
|
|
1121
1173
|
// a failed flush shouldn't block the reload
|
|
1122
1174
|
}
|
|
1123
1175
|
stashReloadState();
|
|
1176
|
+
// Saves are flushed above either way. A frame the shell moves (its
|
|
1177
|
+
// grant expired) loads afresh elsewhere; otherwise reload in place,
|
|
1178
|
+
// keeping this origin and the save queue stored on it.
|
|
1179
|
+
if (await askShellToRelocate())
|
|
1180
|
+
return;
|
|
1124
1181
|
location.reload();
|
|
1125
1182
|
})();
|
|
1126
1183
|
}, delayMs);
|
|
@@ -1637,6 +1637,12 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
1637
1637
|
// The same column, padding, corners and shadow as the Doors/chat panels.
|
|
1638
1638
|
// Token fallbacks use their existing palette when no tokens are installed.
|
|
1639
1639
|
const sheet = el('div', { position: 'absolute', left: '50%', bottom: '0', transform: 'translateX(-50%)', width: 'min(100%, 720px)', maxHeight: cap('vh'), boxSizing: 'border-box', overflow: 'hidden', pointerEvents: 'auto', display: 'flex', flexDirection: 'column', gap: '6px', padding: '12px', paddingBottom: 'max(12px, env(safe-area-inset-bottom))', borderRadius: '12px 12px 0 0', background: 'var(--castle-surface-3, rgba(20,16,12,0.88))', color: 'var(--castle-text-primary, #fff)', boxShadow: '0 4px 14px rgba(0,0,0,0.45)', zIndex: '9' }, root);
|
|
1640
|
+
// The dvh cap replaces the vh one where dvh exists (an unknown value is
|
|
1641
|
+
// dropped). It stays an inline declaration, never an !important rule, so
|
|
1642
|
+
// the safe-inset pass's own cap (`safeStyle.js`) outranks it: that pass
|
|
1643
|
+
// moves the sheet by the height it capped, and a cap that lost left the
|
|
1644
|
+
// footer (a shop's Buy) under the frame on a short view.
|
|
1645
|
+
sheet.style.maxHeight = cap('dvh');
|
|
1640
1646
|
sheet.className = 'hub-menu-sheet';
|
|
1641
1647
|
sheet.dataset.hub = 'menu';
|
|
1642
1648
|
sheet.setAttribute('role', 'dialog');
|
|
@@ -1650,7 +1656,6 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
1650
1656
|
@media (prefers-reduced-motion: reduce) { .hub-menu-tile:not(:disabled):active, .hub-menu-tile.is-pressed { transform: none; } }
|
|
1651
1657
|
@media (max-width: 600px) { .hub-menu-grid { grid-template-columns: repeat(4, minmax(64px, 1fr)) !important; } }
|
|
1652
1658
|
@media (max-width: 340px) { .hub-menu-grid { grid-template-columns: repeat(3, minmax(64px, 1fr)) !important; } }
|
|
1653
|
-
@supports (height: 1dvh) { .hub-menu-sheet { max-height: ${cap('dvh')} !important; } }
|
|
1654
1659
|
` + (placeMenu.covers ? ` ${MENU_COVERED_RULE}\n ` : '');
|
|
1655
1660
|
for (const type of ['pointerdown', 'pointermove', 'pointerup', 'mousedown', 'wheel', 'contextmenu', 'keydown', 'keyup']) {
|
|
1656
1661
|
sheet.addEventListener(type, (event) => event.stopPropagation(), { signal });
|
|
@@ -2261,6 +2266,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
2261
2266
|
// A owns only this lazy, noninteractive caption. The projected surface
|
|
2262
2267
|
// participates in the shared registry but is placed last, yielding to
|
|
2263
2268
|
// every final control/card/label box rather than moving any of them.
|
|
2269
|
+
// v1.221: true only when the caption is drawn and visible this frame.
|
|
2264
2270
|
setPadContext(item) {
|
|
2265
2271
|
const blocked = pickerOpen || sayOpen || emotesOpen || peopleOpen || doorsOpen || talkOpen ||
|
|
2266
2272
|
!!textAsk?.card || !!placeMenu?.sheet || sound?.open || actionOverflow?.isOpen?.() ||
|
|
@@ -2269,7 +2275,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
2269
2275
|
(cabinet.style.display !== 'none' && cabinet.dataset.drawn === 'board');
|
|
2270
2276
|
if (!item || blocked) {
|
|
2271
2277
|
if (padContext && padContext.node.style.visibility !== 'hidden') {padContext.node.style.visibility = 'hidden';}
|
|
2272
|
-
return;
|
|
2278
|
+
return false;
|
|
2273
2279
|
}
|
|
2274
2280
|
if (!padContext) {
|
|
2275
2281
|
const node = el('div', { position: 'absolute', left: '0px', top: '0px', width: 'max-content', maxWidth: 'min(70vw, 320px)',
|
|
@@ -2318,6 +2324,7 @@ export function makeChrome({ onBack, onAvatar, onColor = () => {}, avatarCount,
|
|
|
2318
2324
|
}
|
|
2319
2325
|
const visibility = at ? '' : 'hidden';
|
|
2320
2326
|
if (node.style.visibility !== visibility) {node.style.visibility = visibility;}
|
|
2327
|
+
return Boolean(at);
|
|
2321
2328
|
},
|
|
2322
2329
|
clearPadContext() {
|
|
2323
2330
|
if (!padContext) {return;}
|
|
@@ -12,6 +12,7 @@ import * as AvatarCap from './avatarCap.js';
|
|
|
12
12
|
import { mergeDictionary } from './interestCap.js';
|
|
13
13
|
import * as Cabinets from './cabinets.js';
|
|
14
14
|
import { firstJoinFor } from './firstJoin.js';
|
|
15
|
+
import { signalReplay } from './signals.js';
|
|
15
16
|
import { deck, earnedNow, hub, holdShowsNow, idleNow, localArrival, mergeHidden, receiveParty, replayCleanup, rolesNow, wearingNow } from './state.js';
|
|
16
17
|
import { clearShot, receiveShot } from './shot.js';
|
|
17
18
|
import * as Ballot from './ballot.js';
|
|
@@ -326,6 +327,13 @@ const hooks = {
|
|
|
326
327
|
break;
|
|
327
328
|
case 'hub-arrived':
|
|
328
329
|
hub.arrivedFacing = typeof msg.facing === 'number' ? msg.facing : 0;
|
|
330
|
+
// v1.221: an arrival the place's `signal` hook hears: its first inputs.
|
|
331
|
+
hub.signalArrival = Number.isSafeInteger(msg.signals) ? { n: msg.signals, at: performance.now() } : null;
|
|
332
|
+
break;
|
|
333
|
+
case 'hub-signals':
|
|
334
|
+
// v1.221: a retained rehello: the same arrival, what is left of its
|
|
335
|
+
// window and the kinds already said (never a fresh allowance).
|
|
336
|
+
hub.signalArrival = signalReplay(msg);
|
|
329
337
|
break;
|
|
330
338
|
case 'hub-hold-face':
|
|
331
339
|
// v1.190: a hold with turnCamera, and its release, turn this player's
|
|
@@ -28,6 +28,8 @@ export function collectPadCues(actors, hidden) {
|
|
|
28
28
|
cues.push({ id: actor.id, x: c.Transform.x, z: c.Transform.z, radius: spec.radius,
|
|
29
29
|
y: (c.Transform.y ?? 0) + (shape?.kind === 'cylinder' ? (shape.height ?? 1) / 2 : 0) + 0.03,
|
|
30
30
|
title: explicit ? spec.title : doors.get(spec.door)?.title, door: !explicit,
|
|
31
|
+
// v1.221: the door a door pad's caption names (first-input signals).
|
|
32
|
+
...(explicit ? {} : { doorId: spec.door }),
|
|
31
33
|
cabinet: !explicit && doors.get(spec.door)?.kind === 'cabinet',
|
|
32
34
|
color: shape?.color ?? '#d9a441' });
|
|
33
35
|
}
|
|
@@ -15,8 +15,13 @@ export function makePadReadability(engine, options) {
|
|
|
15
15
|
rings?.frame(traveling ? null : active?.cue);
|
|
16
16
|
if (engine.hubPadContext === true) {
|
|
17
17
|
if (active !== previous || guest !== previousGuest) {text = padContextText(active, guest); previous = active; previousGuest = guest;}
|
|
18
|
-
|
|
18
|
+
// v1.221: the door whose caption chrome actually drew and shows this
|
|
19
|
+
// frame (not one hidden behind an open panel or left unplaced), for
|
|
20
|
+
// first-input signals.
|
|
21
|
+
const drawn = chrome.setPadContext(traveling || captionBlocked ? null : text) === true;
|
|
22
|
+
return drawn && typeof active?.cue.doorId === 'string' ? active.cue.doorId : null;
|
|
19
23
|
}
|
|
24
|
+
return null;
|
|
20
25
|
},
|
|
21
26
|
dispose() {
|
|
22
27
|
rings?.dispose();
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// v1.221: first-input signals (contract §12 "First-input signals"), the
|
|
2
|
+
// client's half. Only an arrival whose `hub-arrived` carried an arrival number
|
|
3
|
+
// (`signals`, sent only where the place's module has a `signal` hook) says
|
|
4
|
+
// anything, and then each of its first walk, first jump and first door prompt
|
|
5
|
+
// at most once, within WINDOW_MS of that arrival. Once all three are said or
|
|
6
|
+
// the window is over, a frame costs one comparison.
|
|
7
|
+
//
|
|
8
|
+
// `{ k: 'hub-signal', kind: 'move' | 'jump', a }` and
|
|
9
|
+
// `{ k: 'hub-signal', kind: 'prompt', a, door }`, `a` the arrival number they
|
|
10
|
+
// were armed with; the server checks each. A retained rehello is told the same
|
|
11
|
+
// arrival again (`hub-signals`, `signalReplay`): what is left of its window
|
|
12
|
+
// and what was already said.
|
|
13
|
+
|
|
14
|
+
export const WINDOW_MS = 120_000;
|
|
15
|
+
// What walks a player (`idle.js` MOVE_KEYS without Space, which jumps).
|
|
16
|
+
const WALK_KEYS = ['KeyW', 'KeyA', 'KeyS', 'KeyD', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'];
|
|
17
|
+
// The drag stick counts once it is this far over (`idle.js` `moving`).
|
|
18
|
+
const STICK_MIN = 0.15;
|
|
19
|
+
|
|
20
|
+
const KINDS = ['move', 'jump', 'prompt'];
|
|
21
|
+
|
|
22
|
+
// `hub-signals` as the hub's `signalArrival`: the arrival's number, its start
|
|
23
|
+
// moved back by the window already spent, and the kinds already said; null
|
|
24
|
+
// for anything malformed.
|
|
25
|
+
export function signalReplay(msg, now = performance.now()) {
|
|
26
|
+
if (!Number.isSafeInteger(msg?.n) || !Number.isFinite(msg.left) || msg.left <= 0 || msg.left > WINDOW_MS || !Array.isArray(msg.sent)) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return { n: msg.n, at: now - (WINDOW_MS - msg.left), sent: KINDS.filter((kind) => msg.sent.includes(kind)) };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function walking(keys, stick) {
|
|
33
|
+
if (keys && WALK_KEYS.some((code) => keys.has?.(code) === true)) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
return Boolean(stick?.active && Math.hypot(stick.x ?? 0, stick.y ?? 0) >= STICK_MIN);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// The engine hears keys typed into a text field too (a chat line, a name):
|
|
40
|
+
// those are words, not a walk or a jump.
|
|
41
|
+
function typing(doc) {
|
|
42
|
+
const el = doc?.activeElement;
|
|
43
|
+
return Boolean(el && (el.isContentEditable || el.closest?.('input, textarea, select')));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function makeSignals(doc = globalThis.document) {
|
|
47
|
+
// { arrival, move, jump, prompt, done } for the arrival being said
|
|
48
|
+
let record = null;
|
|
49
|
+
// A tap is a jump the Player behavior takes (`moveInput.consumeJump`)
|
|
50
|
+
// before this runs, so it is noted as it is taken. Ours stays the outermost
|
|
51
|
+
// wrapper: Act's own (`act.js`) adds its Jump button's press to what it
|
|
52
|
+
// wrapped, so one put over ours is wrapped again. Act and idle wrap a
|
|
53
|
+
// controls object once, so the chain does not grow.
|
|
54
|
+
let wrapper = null;
|
|
55
|
+
let tapped = false;
|
|
56
|
+
function watch(input) {
|
|
57
|
+
if (!input || typeof input.consumeJump !== 'function' || input.consumeJump === wrapper) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const consume = input.consumeJump;
|
|
61
|
+
wrapper = function consumeJump(...args) {
|
|
62
|
+
const had = consume.apply(this, args);
|
|
63
|
+
if (had) {
|
|
64
|
+
tapped = true;
|
|
65
|
+
}
|
|
66
|
+
return had;
|
|
67
|
+
};
|
|
68
|
+
input.consumeJump = wrapper;
|
|
69
|
+
}
|
|
70
|
+
const up = (net) => !net.closed?.() && (!net.status || net.status().state === 'connected');
|
|
71
|
+
return {
|
|
72
|
+
// Whether a door prompt shown now would still be said (so the caller
|
|
73
|
+
// need not collect one).
|
|
74
|
+
wantsPrompt: (arrival) => Boolean(arrival && record?.arrival === arrival && !record.done && !record.prompt),
|
|
75
|
+
// Each frame. `arrival`: the hub's `signalArrival`, or null (no hook, no
|
|
76
|
+
// arrival yet, a trip). `prompt`: a door id whose prompt is up, or null.
|
|
77
|
+
frame(net, arrival, now, { keys, stick, prompt }) {
|
|
78
|
+
if (!arrival) {
|
|
79
|
+
tapped = false;
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (record?.arrival !== arrival) {
|
|
83
|
+
const said = Array.isArray(arrival.sent) ? arrival.sent : [];
|
|
84
|
+
record = { arrival, move: said.includes('move'), jump: said.includes('jump'), prompt: said.includes('prompt'), done: false };
|
|
85
|
+
record.done = record.move && record.jump && record.prompt;
|
|
86
|
+
tapped = false;
|
|
87
|
+
}
|
|
88
|
+
if (record.done) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (now - arrival.at >= WINDOW_MS) {
|
|
92
|
+
record.done = true;
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (!net) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (!record.jump) {
|
|
99
|
+
watch(stick);
|
|
100
|
+
}
|
|
101
|
+
const tap = tapped;
|
|
102
|
+
tapped = false;
|
|
103
|
+
const typed = (!record.move || !record.jump) && keys?.size > 0 && typing(doc);
|
|
104
|
+
const move = !record.move && walking(typed ? null : keys, stick);
|
|
105
|
+
const jump = !record.jump && (tap || (!typed && keys?.has?.('Space') === true));
|
|
106
|
+
const door = !record.prompt && typeof prompt === 'string' && prompt ? prompt : null;
|
|
107
|
+
// Said only while the connection can carry it; otherwise kept for later.
|
|
108
|
+
if (!(move || jump || door) || !up(net)) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (move) {
|
|
112
|
+
record.move = true;
|
|
113
|
+
net.send({ k: 'hub-signal', kind: 'move', a: arrival.n });
|
|
114
|
+
}
|
|
115
|
+
if (jump) {
|
|
116
|
+
record.jump = true;
|
|
117
|
+
net.send({ k: 'hub-signal', kind: 'jump', a: arrival.n });
|
|
118
|
+
}
|
|
119
|
+
if (door) {
|
|
120
|
+
record.prompt = true;
|
|
121
|
+
net.send({ k: 'hub-signal', kind: 'prompt', a: arrival.n, door });
|
|
122
|
+
}
|
|
123
|
+
record.done = record.move && record.jump && record.prompt;
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
@@ -170,6 +170,9 @@ export const hub = {
|
|
|
170
170
|
// the facing the place gave this player on arrival, or null until it has,
|
|
171
171
|
// and whether the camera has been turned to it
|
|
172
172
|
arrivedFacing: null,
|
|
173
|
+
// v1.221: this connection's latest arrival under a place's `signal` hook,
|
|
174
|
+
// { n, at (performance.now()) }, or null (first-input signals)
|
|
175
|
+
signalArrival: null,
|
|
173
176
|
// v1.165: this client's newest clamped pose row while it matters to a car
|
|
174
177
|
// (`hookLayer` state, vehicle.js `placedHeading`)
|
|
175
178
|
selfClamp: null,
|
|
@@ -323,6 +326,7 @@ export function clear() {
|
|
|
323
326
|
}
|
|
324
327
|
hub.cabinets = {};
|
|
325
328
|
hub.arrivedFacing = null;
|
|
329
|
+
hub.signalArrival = null;
|
|
326
330
|
hub.arrivalPlaced = false;
|
|
327
331
|
hub.faced = false;
|
|
328
332
|
hub.commands.length = 0;
|
|
@@ -88,7 +88,7 @@ export function friendBests(h, key, options, userIdOf) {
|
|
|
88
88
|
return index ?? read();
|
|
89
89
|
}
|
|
90
90
|
const api = {
|
|
91
|
-
async report(playerId, best) {
|
|
91
|
+
async report(playerId, best, saves) {
|
|
92
92
|
try {
|
|
93
93
|
// The kit retains its filtered identity through the leave hook, so
|
|
94
94
|
// the last record may be reported even after the roster lost the player.
|
|
@@ -97,6 +97,12 @@ export function friendBests(h, key, options, userIdOf) {
|
|
|
97
97
|
return Promise.resolve();
|
|
98
98
|
}
|
|
99
99
|
const username = String(h.ctx.username(playerId)).slice(0, 20);
|
|
100
|
+
// Under a writer lease a best is the player's progress: it is written
|
|
101
|
+
// through the claim it was made under (the caller's `hub.saves` view,
|
|
102
|
+
// else the account's view now), so a best another instance has since
|
|
103
|
+
// superseded never reaches the index. Without a lease, the raw store.
|
|
104
|
+
const lease = h.writerLease?.api;
|
|
105
|
+
const store = lease?.enabled ? (saves && typeof saves.set === 'function' ? saves : lease.deck(userId)) : null;
|
|
100
106
|
writer = writer
|
|
101
107
|
.then(async () => {
|
|
102
108
|
const rows = await read();
|
|
@@ -108,7 +114,7 @@ export function friendBests(h, key, options, userIdOf) {
|
|
|
108
114
|
...rows.filter((row) => row.userId !== userId),
|
|
109
115
|
{ userId, username, best, at: Date.now() },
|
|
110
116
|
]);
|
|
111
|
-
await h.session.storage.deck.set({ [storageKey]: next });
|
|
117
|
+
await (store ?? h.session.storage.deck).set({ [storageKey]: next });
|
|
112
118
|
generation++;
|
|
113
119
|
index = next;
|
|
114
120
|
indexAt = Date.now();
|
|
@@ -60,6 +60,7 @@ import * as WriterLease from './writerLease.js';
|
|
|
60
60
|
import * as ArrivalPose from './arrivalPose.js';
|
|
61
61
|
import * as Observe from './observe.js';
|
|
62
62
|
import * as Wallet from './wallet.js';
|
|
63
|
+
import * as Signals from './signals.js';
|
|
63
64
|
import { makeAnonymousEntry } from './anonymousEntry.js';
|
|
64
65
|
import { doorPoint } from '../client/doorFrame.js';
|
|
65
66
|
|
|
@@ -280,7 +281,9 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
|
|
|
280
281
|
h.resumeDeparting ??= new Set();
|
|
281
282
|
}
|
|
282
283
|
if (h.place.resumePose === true && session.storage?.deck) {
|
|
283
|
-
h.poseStore = ResumePose.store(session, id, session.hub?.owner ?? null
|
|
284
|
+
h.poseStore = ResumePose.store(session, id, session.hub?.owner ?? null,
|
|
285
|
+
h.writerLease?.api.enabled ? (userId) => h.writerLease.api.deck(userId) : null,
|
|
286
|
+
h.writerLease?.api.enabled ? (userId) => h.writerLease.api.ready(userId) : null);
|
|
284
287
|
} else { delete h.poseStore; }
|
|
285
288
|
if (h.place.decor) {
|
|
286
289
|
h.ctx.decor = Decor.api(h);
|
|
@@ -433,6 +436,11 @@ export function layer(castleJson, deckHooks, placeHooks, sceneExists, sceneGroun
|
|
|
433
436
|
notifyVisibility(h, player.playerId);
|
|
434
437
|
return;
|
|
435
438
|
}
|
|
439
|
+
// v1.221: telemetry only, so heard during a progress read as well.
|
|
440
|
+
if (data?.k === 'hub-signal' && Signals.on(h)) {
|
|
441
|
+
Signals.message(h, player, data, () => doors(h).map((door) => door.id));
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
436
444
|
if (data?.k === 'hub-hello') {
|
|
437
445
|
LoadAbandon.hello(h, player?.playerId);
|
|
438
446
|
hello(h, player, data);
|
|
@@ -1489,6 +1497,9 @@ function hello(h, player, data, synthetic = false) {
|
|
|
1489
1497
|
// holds none of the cabinet cards it was sent (v1.7).
|
|
1490
1498
|
if (data.again !== true) {
|
|
1491
1499
|
replaySent(h, player.playerId, data.resume === true);
|
|
1500
|
+
// v1.221: a retained rehello's page may have reloaded: the current
|
|
1501
|
+
// arrival's first-input allowance, never a new one.
|
|
1502
|
+
if (known?.arrived) {Signals.replay(h, player.playerId);}
|
|
1492
1503
|
Idle.joinedAfresh(h, player.playerId, data.resume === true);
|
|
1493
1504
|
if (h.manifest.act === true) {Act.replay(h, player.playerId);}
|
|
1494
1505
|
h.vehicleDeparting?.delete(player.playerId);
|
|
@@ -2025,7 +2036,15 @@ function outcomeOrNone(outcome) {
|
|
|
2025
2036
|
// other connection here shares it. Finalize their authored state before join.
|
|
2026
2037
|
function syncWriterVisits(h) {
|
|
2027
2038
|
if (!h.writerLease?.api.enabled) { return; }
|
|
2028
|
-
h.writerLease.sync((h.session?.players ?? []).map(p => [p.playerId, userIdOf(h, p.playerId)]).filter(([, userId]) => userId !== null), h.players.keys(), playerId =>
|
|
2039
|
+
h.writerLease.sync((h.session?.players ?? []).map(p => [p.playerId, userIdOf(h, p.playerId)]).filter(([, userId]) => userId !== null), h.players.keys(), playerId => {
|
|
2040
|
+
// A held visit replaced before any tick saw it go still ends its pose,
|
|
2041
|
+
// under its own claim, ahead of the arrival's take.
|
|
2042
|
+
const kept = h.resumeKept?.get(playerId);
|
|
2043
|
+
if (h.poseStore && kept && kept.awayAt === undefined && !h.resumeDeparting?.has(playerId) && !h.players.get(playerId)?.ended) {
|
|
2044
|
+
void h.poseStore.end(h.players.get(playerId)?.userId, kept, Date.now(), playerId);
|
|
2045
|
+
}
|
|
2046
|
+
forget(h, playerId);
|
|
2047
|
+
});
|
|
2029
2048
|
}
|
|
2030
2049
|
|
|
2031
2050
|
// Forget players the session no longer has, telling the deck first: its
|
|
@@ -2584,6 +2603,7 @@ function forget(h, playerId) {
|
|
|
2584
2603
|
}
|
|
2585
2604
|
Party.forget(h, playerId);
|
|
2586
2605
|
Say.forget(h, playerId);
|
|
2606
|
+
Signals.forget(h, playerId);
|
|
2587
2607
|
if (h.ballotState) {
|
|
2588
2608
|
Ballot.forget(h, playerId);
|
|
2589
2609
|
}
|
|
@@ -2724,7 +2744,9 @@ function finishSignUp(h, playerId, signUp, cancel = false) {
|
|
|
2724
2744
|
h.hooks.arrive?.(h.ctx, [signUp.member]);
|
|
2725
2745
|
settle(h, playerId);
|
|
2726
2746
|
const body = h.sim.players.get(playerId);
|
|
2727
|
-
|
|
2747
|
+
// v1.221: a signal hook's arrival number starts this arrival's first inputs.
|
|
2748
|
+
const signals = Signals.arrived(h, playerId);
|
|
2749
|
+
if (body) {h.session?.send(playerId, { k: 'hub-arrived', facing: body.facing, ...(signals ? { signals } : {}) });}
|
|
2728
2750
|
} catch (err) {
|
|
2729
2751
|
console.warn(`[hub] signup arrival failed: ${err?.message ?? err}`);
|
|
2730
2752
|
} finally {
|
|
@@ -2878,7 +2900,9 @@ function arrivals(h) {
|
|
|
2878
2900
|
if (Math.hypot(body.at.x - was.x, body.at.z - was.z) > HOLD_SLACK) {
|
|
2879
2901
|
settle(h, playerId);
|
|
2880
2902
|
}
|
|
2881
|
-
|
|
2903
|
+
// v1.221: a signal hook's arrival number starts this arrival's first inputs.
|
|
2904
|
+
const signals = Signals.arrived(h, playerId);
|
|
2905
|
+
h.session?.send(playerId, { k: 'hub-arrived', facing: body.facing, ...(signals ? { signals } : {}) });
|
|
2882
2906
|
}
|
|
2883
2907
|
if (h.players.get(playerId)?.endAgain) {
|
|
2884
2908
|
delete h.players.get(playerId).endAgain;
|
|
@@ -3758,6 +3782,7 @@ function doorJump(h, player, data) {
|
|
|
3758
3782
|
placeAt(h, player.playerId, { x: at.x, y: standingY(h, { ...at, y: 1.2 }), z: at.z }, facing);
|
|
3759
3783
|
settle(h, player.playerId);
|
|
3760
3784
|
h.session?.send(player.playerId, { k: 'hub-jumped', facing });
|
|
3785
|
+
Signals.emit(h, player.playerId, { kind: 'press', door: door.id });
|
|
3761
3786
|
}
|
|
3762
3787
|
|
|
3763
3788
|
// Join on a friend at home in their House (§5): through that door into the
|
|
@@ -3785,6 +3810,7 @@ function houseVisit(h, player, data) {
|
|
|
3785
3810
|
h.jumpAt.set(playerId, now);
|
|
3786
3811
|
tellWent(h, [playerId], door.id);
|
|
3787
3812
|
sendGo(h, playerId, { k: 'hub-go', door: door.id, key: null, place: null, scene: null, title: door.title, party: 1, owner });
|
|
3813
|
+
Signals.emit(h, playerId, { kind: 'press', door: door.id });
|
|
3788
3814
|
}
|
|
3789
3815
|
|
|
3790
3816
|
// "Stuck?" (v1.33): whether this place puts a player back at its arrival for
|
|
@@ -4487,6 +4513,7 @@ function gather(h, door, playerIds) {
|
|
|
4487
4513
|
return;
|
|
4488
4514
|
}
|
|
4489
4515
|
const on = new Set(playerIds ?? []);
|
|
4516
|
+
if (Signals.on(h)) {Signals.pad(h, door, h.padDoors.get(door), on);}
|
|
4490
4517
|
h.padDoors.set(door, on);
|
|
4491
4518
|
h.padOccupancy?.reportedAt.set(door, h.sim.timeMs);
|
|
4492
4519
|
for (const [playerId, entry] of h.shut) {
|
|
@@ -37,6 +37,7 @@ import { EMOTES } from './idle.js';
|
|
|
37
37
|
import { npcDisplayText } from '../npcDisplayText.js';
|
|
38
38
|
import { warnOnce } from './actors.js';
|
|
39
39
|
import { readNpcTurnsAtOnce } from './manifest.js';
|
|
40
|
+
import * as Signals from './signals.js';
|
|
40
41
|
|
|
41
42
|
// v1.47: a crowd answers a gesture without calling a mind.
|
|
42
43
|
const REACT_RANGE_M = 6;
|
|
@@ -666,6 +667,9 @@ function open(h, n, playerId, npcId) {
|
|
|
666
667
|
}
|
|
667
668
|
state.talking = talking;
|
|
668
669
|
h.ctx.track?.(playerId, 'npc_chat_count', { subject: 9, value: 1 });
|
|
670
|
+
// v1.221: a companion's id carries its owner's player id; it is named
|
|
671
|
+
// only as 'companion'.
|
|
672
|
+
Signals.emit(h, playerId, { kind: 'talk', npc: npc.owner ? 'companion' : npc.id });
|
|
669
673
|
// A new conversation can ask again for what an earlier one finished.
|
|
670
674
|
const participant = n.participants.get(playerId);
|
|
671
675
|
if (participant) {
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
// member) and by player id for a guest, who is a member only while here.
|
|
12
12
|
|
|
13
13
|
// The most players one party holds.
|
|
14
|
+
import * as Signals from './signals.js';
|
|
14
15
|
export const PARTY_MAX = 8;
|
|
15
16
|
// An invitation and a proposed door wait this long for an answer.
|
|
16
17
|
const INVITE_MS = 60000;
|
|
@@ -258,6 +259,8 @@ export function toPad(d, playerId, door, n) {
|
|
|
258
259
|
const at = padPoint(h, door, n, playerId) ?? d.front(door);
|
|
259
260
|
d.placeAt(h, playerId, { x: at.x, y: d.standingY(h, { ...at, y: 1.2 }), z: at.z }, facing);
|
|
260
261
|
h.session?.send(playerId, { k: 'hub-jumped', facing });
|
|
262
|
+
// v1.221: a party Go or Go-yes is the player's press for this door.
|
|
263
|
+
Signals.emit(h, playerId, { kind: 'press', door: door.id });
|
|
261
264
|
return true;
|
|
262
265
|
}
|
|
263
266
|
|
|
@@ -4,8 +4,13 @@ export const TTL_MS = 10 * 60000;
|
|
|
4
4
|
export const READ_MS = 5000;
|
|
5
5
|
const PREFIX = 'hub:resumePose:';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
// `deckOf(userId)`: the account's writer-lease view (hub.saves.deck), so a
|
|
8
|
+
// fenced instance cannot move the pose revision under the current writer.
|
|
9
|
+
// `readyOf(userId)`: settles once the account's claim does (hub.saves.ready);
|
|
10
|
+
// a take's read budget starts then, not while the claim is still settling.
|
|
11
|
+
export function store(session, placeId, owner = null, deckOf = null, readyOf = null) {
|
|
8
12
|
const storage = session?.storage?.deck;
|
|
13
|
+
const writer = (userId) => deckOf?.(userId) ?? storage;
|
|
9
14
|
const pending = new Map();
|
|
10
15
|
const leases = new Map();
|
|
11
16
|
let cleanup = null;
|
|
@@ -25,8 +30,8 @@ export function store(session, placeId, owner = null) {
|
|
|
25
30
|
});
|
|
26
31
|
return next;
|
|
27
32
|
};
|
|
28
|
-
const change = async (p, snapshot, revision, rows) => {
|
|
29
|
-
const receipt = await
|
|
33
|
+
const change = async (db, p, snapshot, revision, rows) => {
|
|
34
|
+
const receipt = await db.transaction({
|
|
30
35
|
operationId: operationId(),
|
|
31
36
|
expectedAccess: snapshot.access,
|
|
32
37
|
changes: [{ prefix: p, expectedRevision: revision, replace: rows }],
|
|
@@ -47,6 +52,7 @@ export function store(session, placeId, owner = null) {
|
|
|
47
52
|
if (!userId || !supported()) {
|
|
48
53
|
return Promise.resolve();
|
|
49
54
|
}
|
|
55
|
+
const db = writer(userId);
|
|
50
56
|
return enqueue(userId, async () => {
|
|
51
57
|
const lease = leases.get(visitId);
|
|
52
58
|
leases.delete(visitId);
|
|
@@ -54,7 +60,7 @@ export function store(session, placeId, owner = null) {
|
|
|
54
60
|
return;
|
|
55
61
|
}
|
|
56
62
|
const p = prefix(userId);
|
|
57
|
-
await change(p, lease, lease.revision, {
|
|
63
|
+
await change(db, p, lease, lease.revision, {
|
|
58
64
|
[p + 'pose']: { at: { ...pose.at }, facing: pose.facing, endedAt },
|
|
59
65
|
});
|
|
60
66
|
});
|
|
@@ -63,11 +69,12 @@ export function store(session, placeId, owner = null) {
|
|
|
63
69
|
if (!userId || !supported()) {
|
|
64
70
|
return Promise.resolve();
|
|
65
71
|
}
|
|
72
|
+
const db = writer(userId);
|
|
66
73
|
return enqueue(userId, async () => {
|
|
67
74
|
const lease = leases.get(visitId);
|
|
68
75
|
leases.delete(visitId);
|
|
69
76
|
if (lease) {
|
|
70
|
-
await change(prefix(userId), lease, lease.revision, {});
|
|
77
|
+
await change(db, prefix(userId), lease, lease.revision, {});
|
|
71
78
|
}
|
|
72
79
|
});
|
|
73
80
|
},
|
|
@@ -75,13 +82,24 @@ export function store(session, placeId, owner = null) {
|
|
|
75
82
|
if (!userId || !supported()) {
|
|
76
83
|
return null;
|
|
77
84
|
}
|
|
78
|
-
|
|
85
|
+
// The take holds its queue place and view at once (an end asked
|
|
86
|
+
// meanwhile runs after it); under the lease its budget starts only
|
|
87
|
+
// once the claim has settled.
|
|
88
|
+
const ready = readyOf ? Promise.resolve(readyOf(userId)).catch(() => {}) : null;
|
|
89
|
+
let deadline = Date.now() + READ_MS;
|
|
90
|
+
const db = writer(userId);
|
|
79
91
|
const work = enqueue(userId, async () => {
|
|
92
|
+
if (ready) {
|
|
93
|
+
await ready;
|
|
94
|
+
deadline = Date.now() + READ_MS;
|
|
95
|
+
}
|
|
80
96
|
if (Date.now() >= deadline) {
|
|
81
97
|
return null;
|
|
82
98
|
}
|
|
83
99
|
const p = prefix(userId);
|
|
84
|
-
|
|
100
|
+
// Through the lease view, which reads only once the claim settles: a
|
|
101
|
+
// snapshot before it can miss the previous writer's last pose save.
|
|
102
|
+
const snapshot = await db.snapshot({ prefix: p });
|
|
85
103
|
if (Date.now() >= deadline) {
|
|
86
104
|
return null;
|
|
87
105
|
}
|
|
@@ -89,13 +107,16 @@ export function store(session, placeId, owner = null) {
|
|
|
89
107
|
const row = target.rows[p + 'pose'];
|
|
90
108
|
// A concurrent claim or a door clear changes this revision. A failed
|
|
91
109
|
// transaction restores nothing, and an old socket cannot write later.
|
|
92
|
-
const revision = await change(p, snapshot, target.revision, {});
|
|
110
|
+
const revision = await change(db, p, snapshot, target.revision, {});
|
|
93
111
|
if (Date.now() >= deadline) {
|
|
94
112
|
return null;
|
|
95
113
|
}
|
|
96
114
|
leases.set(visitId, { access: snapshot.access, revision });
|
|
97
115
|
return valid(row) ? { at: { ...row.at }, facing: row.facing } : null;
|
|
98
116
|
});
|
|
117
|
+
if (ready) {
|
|
118
|
+
await ready;
|
|
119
|
+
}
|
|
99
120
|
let timer;
|
|
100
121
|
try {
|
|
101
122
|
return await Promise.race([
|
|
@@ -132,7 +153,7 @@ export function store(session, placeId, owner = null) {
|
|
|
132
153
|
const p = key.slice(0, -4);
|
|
133
154
|
const snapshot = await storage.snapshot({ prefix: p });
|
|
134
155
|
if (snapshot.targets[0].rows[key] !== undefined && !valid(snapshot.targets[0].rows[key])) {
|
|
135
|
-
await change(p, snapshot, snapshot.targets[0].revision, {});
|
|
156
|
+
await change(storage, p, snapshot, snapshot.targets[0].revision, {});
|
|
136
157
|
}
|
|
137
158
|
}
|
|
138
159
|
} catch (error) {
|