castle-web-cli 0.4.237 → 0.4.238
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/bundle.d.ts +24 -0
- package/dist/bundle.js +447 -4
- package/dist/bundleLatin1.d.ts +6 -0
- package/dist/bundleLatin1.js +333 -0
- package/dist/castle-host/host.d.ts +10 -1
- package/dist/castle-host/host.js +78 -9
- package/dist/castleJson.d.ts +2 -0
- package/dist/castleJson.js +1 -0
- package/dist/deckExports.d.ts +35 -0
- package/dist/deckExports.js +365 -0
- package/dist/importCheckHook.d.ts +1 -0
- package/dist/importCheckHook.js +1 -1
- package/dist/index.js +5 -0
- package/dist/init.js +2 -1
- package/dist/save-deck.js +4 -0
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +47 -0
- package/kits/base/sdk/castle.d.ts +3 -1
- package/kits/base/sdk/castle.js +1 -0
- package/kits/base/sdk/commands.d.ts +25 -1
- package/kits/base/sdk/commands.js +29 -1
- package/kits/base/sdk/hub.d.ts +17 -0
- package/kits/base/sdk/hub.js +33 -9
- package/kits/base/sdk/localCache.d.ts +27 -0
- package/kits/base/sdk/localCache.js +115 -0
- package/kits/base/sdk/localCacheStore.d.ts +15 -0
- package/kits/base/sdk/localCacheStore.js +358 -0
- package/kits/base/sdk/transport.d.ts +1 -0
- package/kits/base/sdk/transport.js +4 -5
- package/kits/hub-game/CLAUDE.md +22 -2
- package/kits/hub-game/castle.json +4 -1
- package/kits/hub-game/code/client/act.js +66 -91
- package/kits/hub-game/code/client/actCore.js +134 -0
- package/kits/hub-game/code/client/car.js +35 -0
- package/kits/hub-game/code/client/chrome.js +207 -381
- package/kits/hub-game/code/client/crowdNames.js +2 -2
- package/kits/hub-game/code/client/emoteWheel.js +109 -0
- package/kits/hub-game/code/client/hats.js +2 -0
- package/kits/hub-game/code/client/hookLayer.js +99 -48
- package/kits/hub-game/code/client/hostGo.js +77 -0
- package/kits/hub-game/code/client/hubControls.js +125 -0
- package/kits/hub-game/code/client/hubEntry.js +187 -0
- package/kits/hub-game/code/client/hudSurface.js +148 -0
- package/kits/hub-game/code/client/hudTree.js +96 -0
- package/kits/hub-game/code/client/idle.js +59 -13
- package/kits/hub-game/code/client/invites.js +13 -4
- package/kits/hub-game/code/client/menuIcons.js +8 -0
- package/kits/hub-game/code/client/noTrips.js +38 -0
- package/kits/hub-game/code/client/qualityEntry.js +6 -1
- package/kits/hub-game/code/client/rehello.js +3 -1
- package/kits/hub-game/code/client/riders.js +26 -0
- package/kits/hub-game/code/client/role.js +79 -0
- package/kits/hub-game/code/client/safeLayout.js +32 -3
- package/kits/hub-game/code/client/sound.js +10 -3
- package/kits/hub-game/code/client/soundscape.js +2 -2
- package/kits/hub-game/code/client/soundscapeAmbience.js +38 -8
- package/kits/hub-game/code/client/soundscapeBaked.js +24 -5
- package/kits/hub-game/code/client/soundscapeCues.js +2 -1
- package/kits/hub-game/code/client/state.js +19 -0
- package/kits/hub-game/code/client/stuck.js +2 -1
- package/kits/hub-game/code/client/talkSurface.js +178 -0
- package/kits/hub-game/code/client/talkTree.js +238 -0
- package/kits/hub-game/code/client/tiers.js +8 -5
- package/kits/hub-game/code/client/uiDom.js +600 -0
- package/kits/hub-game/code/client/uiTree.js +359 -0
- package/kits/hub-game/code/client/vehicle.js +154 -0
- package/kits/hub-game/code/client/wear.js +27 -5
- package/kits/hub-game/code/client/worldLabels.js +3 -2
- package/kits/hub-game/code/client/yours.js +10 -3
- package/kits/hub-game/code/server/actors.js +4 -3
- package/kits/hub-game/code/server/analytics.js +56 -6
- package/kits/hub-game/code/server/decor.js +56 -16
- package/kits/hub-game/code/server/hub.js +258 -46
- package/kits/hub-game/code/server/idle.js +118 -5
- package/kits/hub-game/code/server/manifest.js +46 -4
- package/kits/hub-game/code/server/npcs.js +4 -2
- package/kits/hub-game/code/server/players.js +3 -0
- package/kits/hub-game/code/server/role.js +142 -0
- package/kits/hub-game/code/server/standing.js +6 -4
- package/kits/hub-game/code/server/vehicle.js +126 -0
- package/kits/hub-game/code/shared/car.js +52 -0
- package/kits/hub-game/code/shared/deckFlags.js +34 -0
- package/kits/hub-game/code/shared/deviceClass.js +39 -0
- package/kits/hub-game/code/shared/expression.js +9 -0
- package/kits/hub-game/code/systems/hub.js +272 -84
- package/kits/hub-game/docs/analytics.md +11 -2
- package/kits/hub-game/docs/contract.md +352 -14
- package/kits/hub-game/docs/vehicle-preset.md +132 -0
- package/kits/hub-game/models/hats/baker-cap.pxmodel +89 -0
- package/kits/hub-game/models/hats/chef-toque.pxmodel +60 -0
- package/kits/hub-game/models/hats/delivery-cap.pxmodel +105 -0
- package/kits/hub-game/models/hats/fire-helmet.pxmodel +87 -0
- package/kits/hub-game/models/hats/hard-hat.pxmodel +71 -0
- package/kits/hub-game/models/hats/nurse-cap.pxmodel +61 -0
- package/kits/hub-game/models/hats/police-cap.pxmodel +105 -0
- package/kits/hub-game/models/hats/teacher-beret.pxmodel +52 -0
- package/kits/hub-game/models/role/square/top-apron.pxmodel +109 -0
- package/kits/hub-game/models/role/square/top-cardigan.pxmodel +141 -0
- package/kits/hub-game/models/role/square/top-coat.pxmodel +157 -0
- package/kits/hub-game/models/role/square/top-scrubs.pxmodel +93 -0
- package/kits/hub-game/models/role/square/top-tabard.pxmodel +109 -0
- package/kits/hub-game/models/role/square/top-vest.pxmodel +109 -0
- package/kits/hub-game/models/role/tool-bag.pxmodel +75 -0
- package/kits/hub-game/models/role/tool-bell.pxmodel +71 -0
- package/kits/hub-game/models/role/tool-hose.pxmodel +60 -0
- package/kits/hub-game/models/role/tool-parcel.pxmodel +61 -0
- package/kits/hub-game/models/role/tool-torch.pxmodel +55 -0
- package/kits/hub-game/models/role/tool-tray.pxmodel +75 -0
- package/kits/hub-game/models/role/top-apron.pxmodel +70 -0
- package/kits/hub-game/models/role/top-cardigan.pxmodel +102 -0
- package/kits/hub-game/models/role/top-coat.pxmodel +79 -0
- package/kits/hub-game/models/role/top-scrubs.pxmodel +54 -0
- package/kits/hub-game/models/role/top-tabard.pxmodel +70 -0
- package/kits/hub-game/models/role/top-vest.pxmodel +70 -0
- package/kits/hub-game/package-lock.json +1 -1
- package/kits/hub-game/package.json +1 -1
- package/kits/hub-game/scripts/check.mjs +7 -4
- package/kits/hub-game/scripts/fixtures/car-vectors.json +279 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +2 -1
- package/kits/hub-game/scripts/fixtures/hud-surface.json +670 -0
- package/kits/hub-game/scripts/fixtures/talk-surface.json +3930 -0
- package/kits/hub-game/scripts/gen-hats.mjs +46 -2
- package/kits/hub-game/scripts/gen-role.mjs +80 -0
- package/kits/hub-game/scripts/test-act-core.mjs +167 -0
- package/kits/hub-game/scripts/test-actions-client.mjs +34 -0
- package/kits/hub-game/scripts/test-actors.mjs +48 -0
- package/kits/hub-game/scripts/test-analytics.mjs +99 -5
- package/kits/hub-game/scripts/test-apply-deck.mjs +122 -0
- package/kits/hub-game/scripts/test-back-visibility.mjs +3 -1
- package/kits/hub-game/scripts/test-ballot.mjs +2 -0
- package/kits/hub-game/scripts/test-car.mjs +43 -0
- package/kits/hub-game/scripts/test-decor-client.mjs +2 -1
- package/kits/hub-game/scripts/test-decor.mjs +77 -0
- package/kits/hub-game/scripts/test-device-class.mjs +83 -0
- package/kits/hub-game/scripts/test-emote-wheel.mjs +374 -0
- package/kits/hub-game/scripts/test-hats.mjs +5 -4
- package/kits/hub-game/scripts/test-host-go.mjs +265 -0
- package/kits/hub-game/scripts/test-hub-controls.mjs +108 -0
- package/kits/hub-game/scripts/test-hub-entry.mjs +531 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +75 -0
- package/kits/hub-game/scripts/test-hud-clear.mjs +12 -2
- package/kits/hub-game/scripts/test-hud-rate.mjs +6 -2
- package/kits/hub-game/scripts/test-hud-surface.mjs +272 -0
- package/kits/hub-game/scripts/test-idle.mjs +347 -1
- package/kits/hub-game/scripts/test-interest-cells.mjs +8 -1
- package/kits/hub-game/scripts/test-invites-client.mjs +42 -1
- package/kits/hub-game/scripts/test-manifest.mjs +30 -0
- package/kits/hub-game/scripts/test-no-trips.mjs +42 -0
- package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
- package/kits/hub-game/scripts/test-quality.mjs +13 -0
- package/kits/hub-game/scripts/test-rehello.mjs +258 -3
- package/kits/hub-game/scripts/test-resume-pose-server.mjs +203 -0
- package/kits/hub-game/scripts/test-resync.mjs +183 -0
- package/kits/hub-game/scripts/test-role-client.mjs +421 -0
- package/kits/hub-game/scripts/test-role.mjs +350 -0
- package/kits/hub-game/scripts/test-safe-layout.mjs +50 -1
- package/kits/hub-game/scripts/test-soundscape.mjs +124 -7
- package/kits/hub-game/scripts/test-standing.mjs +15 -1
- package/kits/hub-game/scripts/test-talk-surface.mjs +296 -0
- package/kits/hub-game/scripts/test-tiers.mjs +13 -0
- package/kits/hub-game/scripts/test-ui-dom-dom.mjs +96 -0
- package/kits/hub-game/scripts/test-ui-tree.mjs +711 -0
- package/kits/hub-game/scripts/test-vehicle-client.mjs +159 -0
- package/kits/hub-game/scripts/test-vehicle.mjs +135 -0
- package/kits/hub-game/scripts/test-yours.mjs +33 -0
- package/kits/hub-game/tools/hubScene/export.mjs +613 -0
- package/kits/hub-game/tools/hubScene/hubdata.mjs +921 -0
- package/kits/hub-game/tools/hubScene/merge-root.mjs +39 -0
- package/kits/hub-game/tools/hubScene/nodeworld.mjs +227 -0
- package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +798 -0
- package/kits/hub-game/tools/hubScene/test/fixture.json +637 -0
- package/kits/hub-game/tools/hubScene/test/paint-export.mjs +40 -0
- package/kits/hub-game/tools/hubScene/test/upload.test.mjs +655 -0
- package/kits/hub-game/tools/hubScene/upload.mjs +636 -0
- package/kits/hub-game/tools/hubScene/validate-manifest.mjs +291 -0
- package/kits/multiplayer-3d/castle.json +4 -4
- package/kits/multiplayer-3d/code/client/resumeGate.js +30 -2
- package/kits/multiplayer-3d/code/client/steer.js +3 -1
- package/kits/multiplayer-3d/code/systems/multiplayer.js +30 -2
- package/kits/multiplayer-3d/package-lock.json +1 -1
- package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +74 -2
- package/kits/physics-3d/CLAUDE.md +1 -1
- package/kits/physics-3d/behaviors/Player.jsx +37 -27
- package/kits/physics-3d/castle.json +2 -2
- package/kits/physics-3d/docs/engine-geometry-memory.md +23 -0
- package/kits/physics-3d/engine3d/memoryprofile.js +17 -0
- package/kits/physics-3d/engine3d/playerRun.js +6 -1
- package/kits/physics-3d/engine3d/pxmodel.js +6 -1
- package/kits/physics-3d/engine3d/world3d.js +6 -3
- package/kits/physics-3d/package.json +1 -1
- package/kits/physics-3d/play/behaviors/Player.js +40 -28
- package/kits/physics-3d/scripts/test-memory-profile.mjs +237 -0
- package/kits/physics-3d/systems/physics3d.js +5 -2
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/messages.js +5 -0
- package/kits/real-time/code/server/session.js +28 -1
- package/kits/real-time/package-lock.json +1 -1
- package/package.json +5 -4
- package/vendor/three/LICENSE +21 -0
- package/vendor/three/build/three.core.js +58773 -0
- package/vendor/three/build/three.module.js +18251 -0
- package/vendor/three/examples/jsm/controls/OrbitControls.js +1860 -0
- package/vendor/three/examples/jsm/controls/TransformControls.js +1918 -0
- package/vendor/three/examples/jsm/exporters/GLTFExporter.js +3595 -0
- package/vendor/three/examples/jsm/geometries/RoundedBoxGeometry.js +216 -0
- package/vendor/three/examples/jsm/math/MeshSurfaceSampler.js +315 -0
- package/vendor/three/examples/jsm/postprocessing/EffectComposer.js +363 -0
- package/vendor/three/examples/jsm/postprocessing/MaskPass.js +195 -0
- package/vendor/three/examples/jsm/postprocessing/OutputPass.js +139 -0
- package/vendor/three/examples/jsm/postprocessing/Pass.js +191 -0
- package/vendor/three/examples/jsm/postprocessing/RenderPass.js +183 -0
- package/vendor/three/examples/jsm/postprocessing/ShaderPass.js +135 -0
- package/vendor/three/examples/jsm/shaders/CopyShader.js +52 -0
- package/vendor/three/examples/jsm/shaders/OutputShader.js +103 -0
- package/vendor/three/examples/jsm/utils/BufferGeometryUtils.js +1435 -0
- package/vendor/three/package.json +134 -0
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
// The talk surface (`code/client/talkSurface.js`): the NPC talk panel's
|
|
2
|
+
// API over the talk view, with no DOM, for the web chrome and a native host
|
|
3
|
+
// alike. The talk controller (`talk.js`) is driven through scripted
|
|
4
|
+
// conversations -- an authored NPC (opening, a late greeting, chips, a typed
|
|
5
|
+
// line, the draft), a late submit from a closed conversation, a mind (its
|
|
6
|
+
// inspect, a turn and its reply), a child's choices and an under-13 hint --
|
|
7
|
+
// and everything the host is told is recorded: each `talk` root (bytes, rev
|
|
8
|
+
// and binding ids), each message sent, each event and what the panel says
|
|
9
|
+
// back. `fixtures/talk-surface.json` was recorded from the chrome before the
|
|
10
|
+
// talk API moved out of it; the chrome must still produce it (with the DOM
|
|
11
|
+
// drawn, its DOM writes too), and talk.js over the surface alone (no DOM)
|
|
12
|
+
// must tell a host the same.
|
|
13
|
+
//
|
|
14
|
+
// One change from the recording, made on purpose: a closed panel's root no
|
|
15
|
+
// longer binds `cancel` (a host's Back went to a talk panel that was not
|
|
16
|
+
// there). The web never drew that binding (`uiDom.js` wires events on
|
|
17
|
+
// buttons and fields only), so its DOM writes are unchanged.
|
|
18
|
+
// `RECORD=1` writes the recording anew.
|
|
19
|
+
import assert from 'node:assert/strict';
|
|
20
|
+
import { createHash } from 'node:crypto';
|
|
21
|
+
import { execFileSync } from 'node:child_process';
|
|
22
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
23
|
+
import { fakeDom } from './fixtures/fake-dom.mjs';
|
|
24
|
+
import { dispatchUiEvent, resetUiTrees, setUiTreeSink } from '../code/client/uiTree.js';
|
|
25
|
+
import { hub as clientHub, clear as clearClientHub } from '../code/client/state.js';
|
|
26
|
+
|
|
27
|
+
const RECORD = process.env.RECORD === '1';
|
|
28
|
+
const FIXTURE = new URL('./fixtures/talk-surface.json', import.meta.url);
|
|
29
|
+
const VIEWS = { portrait: { viewW: 390, viewH: 844 }, landscape: { viewW: 844, viewH: 390 } };
|
|
30
|
+
|
|
31
|
+
// What a message says, without the random ids it carries.
|
|
32
|
+
const plain = (msg) => Object.fromEntries(Object.entries(msg).filter(([key]) => !['rid', 'requestId', 'operationId'].includes(key)));
|
|
33
|
+
|
|
34
|
+
// A rig: fake timers (nothing fires unless run), a page clock, a net that
|
|
35
|
+
// records what it is sent, and a mind whose inspect answers and whose turns
|
|
36
|
+
// are admitted.
|
|
37
|
+
function makeRig() {
|
|
38
|
+
const rig = { record: [], now: 10_000, timers: [], rid: null, op: null };
|
|
39
|
+
rig.net = {
|
|
40
|
+
selfId: () => 'p1',
|
|
41
|
+
send(msg) {
|
|
42
|
+
if (msg.rid) {rig.rid = msg.rid;}
|
|
43
|
+
rig.record.push(['net', plain(msg)]);
|
|
44
|
+
},
|
|
45
|
+
characters: {
|
|
46
|
+
async readCharacters({ query }) {
|
|
47
|
+
rig.record.push(['read', query.type]);
|
|
48
|
+
if (query.type === 'inspect') {return { gameplay: { objects: {} } };}
|
|
49
|
+
return new Promise(() => {});
|
|
50
|
+
},
|
|
51
|
+
async requestCharacterTurn(request) {
|
|
52
|
+
rig.op = request.operationId;
|
|
53
|
+
rig.record.push(['turn', request.characterId, request.input, request.audience]);
|
|
54
|
+
return {};
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
rig.mp = { net: rig.net, joined: true };
|
|
59
|
+
rig.scene = { multiplayer: rig.mp, actorWith: () => null, getActors: () => [] };
|
|
60
|
+
rig.sink = (name, wire, handlers, info) => {
|
|
61
|
+
if (name === 'talk') {rig.record.push(['root', info.json, info.rev, [...handlers.keys()]]);}
|
|
62
|
+
};
|
|
63
|
+
return rig;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// The conversations. `api`: push(msg) a panel event from the server, frame(),
|
|
67
|
+
// settle() (promises run), event(id, payload) on the talk root, draft(text?),
|
|
68
|
+
// focused(), field() the field node as the host was last sent it, advance(ms).
|
|
69
|
+
function play(api, rig) {
|
|
70
|
+
api.frame();
|
|
71
|
+
// An authored NPC: its opening and questions, then a late greeting.
|
|
72
|
+
api.push({ k: 'hub-npc', npc: 'baker', open: true, name: 'Mabel, the baker', mind: false, opening: { text: 'Fresh bread!', asks: ['What is fresh?', 'Any rolls?'] } });
|
|
73
|
+
api.frame();
|
|
74
|
+
api.push({ k: 'hub-npc-opening', npc: 'baker', text: 'Fresh bread, still warm!' });
|
|
75
|
+
api.frame();
|
|
76
|
+
// A chip, then the place's reply.
|
|
77
|
+
api.event('talk/panel/asks/a0#tap');
|
|
78
|
+
api.frame(); api.frame();
|
|
79
|
+
api.push({ k: 'hub-npc-line', npc: 'baker', text: 'The rye, this morning.', why: 'authored', rid: rig.rid });
|
|
80
|
+
api.frame();
|
|
81
|
+
// A draft, then typed words sent from the field.
|
|
82
|
+
api.draft('half a thought');
|
|
83
|
+
api.draft();
|
|
84
|
+
api.advance(1_000);
|
|
85
|
+
const ver = api.field().ver;
|
|
86
|
+
api.event('talk/panel/form/say#focus', {});
|
|
87
|
+
api.focused();
|
|
88
|
+
api.event('talk/panel/form/say#input', { text: 'Any rolls today?', base: ver });
|
|
89
|
+
api.event('talk/panel/form/say#submit', { text: 'Any rolls today?', base: ver });
|
|
90
|
+
api.event('talk/panel/form/say#blur', {});
|
|
91
|
+
api.focused();
|
|
92
|
+
api.draft();
|
|
93
|
+
api.frame();
|
|
94
|
+
api.push({ k: 'hub-npc-line', npc: 'baker', text: 'Two left.', why: 'authored', rid: rig.rid });
|
|
95
|
+
api.frame();
|
|
96
|
+
// Done; then a mind opens, and a submit typed in the baker's panel lands late.
|
|
97
|
+
const late = api.field().ver;
|
|
98
|
+
api.event('talk/panel/head/done#tap');
|
|
99
|
+
api.frame();
|
|
100
|
+
api.push({ k: 'hub-npc', npc: 'puppy', open: true, name: 'Biscuit, the puppy', mind: true, character: 'biscuit', opening: { text: 'Woof!', asks: ['Where do you live?', 'Who are you?'] } });
|
|
101
|
+
api.frame();
|
|
102
|
+
return api.settle().then(async () => {
|
|
103
|
+
api.frame();
|
|
104
|
+
api.event('talk/panel/form/say#submit', { text: 'for Mabel', base: late });
|
|
105
|
+
api.draft();
|
|
106
|
+
// The Say button sends the draft.
|
|
107
|
+
api.draft('Who are you?');
|
|
108
|
+
api.event('talk/panel/form/send#tap');
|
|
109
|
+
await api.settle();
|
|
110
|
+
api.frame();
|
|
111
|
+
api.frame();
|
|
112
|
+
api.push({ k: 'hub-npc-line', npc: 'puppy', text: 'A puppy!', why: 'mind', op: rig.op });
|
|
113
|
+
api.frame();
|
|
114
|
+
// Lines while the mind thinks: the typing dots come and go.
|
|
115
|
+
api.event('talk/panel/asks/a0#tap');
|
|
116
|
+
await api.settle();
|
|
117
|
+
api.frame();
|
|
118
|
+
api.push({ k: 'hub-npc-line', npc: 'puppy', text: 'Under the bakery.', why: 'mind', op: rig.op });
|
|
119
|
+
api.frame();
|
|
120
|
+
// The place closes it.
|
|
121
|
+
api.push({ k: 'hub-npc', npc: 'puppy', open: false, why: 'end' });
|
|
122
|
+
api.frame();
|
|
123
|
+
// A child's choices: a tap row and no field.
|
|
124
|
+
api.push({ k: 'hub-npc', npc: 'gnome', open: true, name: 'Pip', mind: false, choices: [{ id: 'hi', label: 'Hi!' }, { id: 'bye', label: 'Bye!' }] });
|
|
125
|
+
api.frame();
|
|
126
|
+
api.advance(1_000);
|
|
127
|
+
api.event('talk/panel/asks/a1#tap');
|
|
128
|
+
api.frame();
|
|
129
|
+
api.push({ k: 'hub-npc-line', npc: 'gnome', text: 'Bye then!', why: 'authored', rid: rig.rid });
|
|
130
|
+
api.frame();
|
|
131
|
+
// Back, while the panel is open, ends it.
|
|
132
|
+
api.event('talk#cancel');
|
|
133
|
+
api.frame();
|
|
134
|
+
// An under-13 speaker: the hint, no field.
|
|
135
|
+
api.push({ k: 'hub-npc', npc: 'puppy', open: true, name: 'Biscuit, the puppy', mind: true, character: 'biscuit', ageOff: true, opening: { text: 'Woof!' } });
|
|
136
|
+
api.frame();
|
|
137
|
+
await api.settle();
|
|
138
|
+
api.frame();
|
|
139
|
+
api.event('talk/panel/head/done#tap');
|
|
140
|
+
api.frame();
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const digest = (lines) => createHash('sha256').update(lines.join('\n')).digest('hex');
|
|
145
|
+
|
|
146
|
+
// One run. `how`: 'dom' (the chrome, drawing), 'host' (the chrome with a
|
|
147
|
+
// host that draws: `dom: false`) or 'surface' (the surface alone, no DOM).
|
|
148
|
+
async function run(how, viewName) {
|
|
149
|
+
const view = VIEWS[viewName];
|
|
150
|
+
resetUiTrees();
|
|
151
|
+
clearClientHub();
|
|
152
|
+
let dom = null;
|
|
153
|
+
if (how === 'surface') {
|
|
154
|
+
delete globalThis.document;
|
|
155
|
+
delete globalThis.window;
|
|
156
|
+
} else {
|
|
157
|
+
dom = fakeDom(view);
|
|
158
|
+
}
|
|
159
|
+
globalThis.matchMedia = () => ({ matches: false });
|
|
160
|
+
const rig = makeRig();
|
|
161
|
+
const real = { now: performance.now, setTimeout: globalThis.setTimeout, clearTimeout: globalThis.clearTimeout };
|
|
162
|
+
performance.now = () => rig.now;
|
|
163
|
+
globalThis.setTimeout = (fn, ms) => {rig.timers.push({ fn, ms }); return rig.timers.length;};
|
|
164
|
+
globalThis.clearTimeout = () => {};
|
|
165
|
+
setUiTreeSink(rig.sink, { dom: how === 'dom' });
|
|
166
|
+
let chrome = null;
|
|
167
|
+
let dispose = null;
|
|
168
|
+
if (how === 'surface') {
|
|
169
|
+
const { makeTalkSurface } = await import('../code/client/talkSurface.js');
|
|
170
|
+
const surface = makeTalkSurface({ view: () => ({ landscape: view.viewW > view.viewH, desktop: false, w: view.viewW, safeInsets: false }) });
|
|
171
|
+
chrome = { ...surface, talkPrompt() {} };
|
|
172
|
+
dispose = () => surface.dispose();
|
|
173
|
+
} else {
|
|
174
|
+
const { makeChrome } = await import('../code/client/chrome.js');
|
|
175
|
+
chrome = makeChrome({ avatarCount: 4, onBack() {}, onAvatar() {} });
|
|
176
|
+
dispose = () => chrome.dispose();
|
|
177
|
+
}
|
|
178
|
+
const { makeTalk } = await import('../code/client/talk.js');
|
|
179
|
+
const talk = makeTalk(chrome);
|
|
180
|
+
let lastTalk = null;
|
|
181
|
+
const sink = rig.sink;
|
|
182
|
+
rig.sink = (name, wire, ...rest) => {if (name === 'talk') {lastTalk = wire;} sink(name, wire, ...rest);};
|
|
183
|
+
setUiTreeSink(rig.sink, { dom: how === 'dom' });
|
|
184
|
+
const settle = async () => {for (let i = 0; i < 20; i++) {await Promise.resolve();}};
|
|
185
|
+
const api = {
|
|
186
|
+
push: (msg) => clientHub.npcEvents.push(msg),
|
|
187
|
+
frame: () => talk.frame(rig.scene, rig.mp, true),
|
|
188
|
+
settle,
|
|
189
|
+
event: (id, payload) => rig.record.push(['event', id, dispatchUiEvent('talk', id, payload)]),
|
|
190
|
+
draft: (text) => rig.record.push(['draft', text === undefined ? chrome.talkDraft() : chrome.talkDraft(text)]),
|
|
191
|
+
focused: () => rig.record.push(['focused', chrome.talkFocused()]),
|
|
192
|
+
field: () => lastTalk.c[0].c.find((n) => n.k === 'form').c[0],
|
|
193
|
+
advance: (ms) => {rig.now += ms;},
|
|
194
|
+
};
|
|
195
|
+
try {
|
|
196
|
+
await play(api, rig);
|
|
197
|
+
talk.reset();
|
|
198
|
+
dispose();
|
|
199
|
+
} finally {
|
|
200
|
+
performance.now = real.now;
|
|
201
|
+
globalThis.setTimeout = real.setTimeout;
|
|
202
|
+
globalThis.clearTimeout = real.clearTimeout;
|
|
203
|
+
clearClientHub();
|
|
204
|
+
resetUiTrees();
|
|
205
|
+
}
|
|
206
|
+
return { record: rig.record, ...(dom ? { dom: digest(dom.log), writes: dom.log.length } : {}) };
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// The recording with the one deliberate change: a closed panel's root binds
|
|
210
|
+
// no `cancel`.
|
|
211
|
+
function closedHasNoCancel(record) {
|
|
212
|
+
return record.map((entry) => {
|
|
213
|
+
if (entry[0] !== 'root' || entry[1] === 'null') {return entry;}
|
|
214
|
+
const wire = JSON.parse(entry[1]);
|
|
215
|
+
if (!wire.c[0].s.gone) {return entry;}
|
|
216
|
+
assert.deepEqual(wire.on, { cancel: 'talk#cancel' }, 'the recording bound cancel while closed');
|
|
217
|
+
delete wire.on;
|
|
218
|
+
return ['root', JSON.stringify(wire), entry[2], entry[3].filter((id) => id !== 'talk#cancel')];
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
let passed = 0;
|
|
223
|
+
const runs = [['dom', 'portrait'], ['host', 'portrait'], ['dom', 'landscape'], ['host', 'landscape']];
|
|
224
|
+
if (RECORD) {
|
|
225
|
+
const out = {};
|
|
226
|
+
for (const [how, viewName] of runs) {out[`${how}:${viewName}`] = await run(how, viewName);}
|
|
227
|
+
writeFileSync(FIXTURE, `${JSON.stringify(out, null, 1)}\n`);
|
|
228
|
+
console.log(`talk surface: recorded ${runs.length} runs`);
|
|
229
|
+
} else {
|
|
230
|
+
assert(existsSync(FIXTURE));
|
|
231
|
+
const fixture = JSON.parse(readFileSync(FIXTURE, 'utf8'));
|
|
232
|
+
for (const [how, viewName] of runs) {
|
|
233
|
+
const want = fixture[`${how}:${viewName}`];
|
|
234
|
+
const got = await run(how, viewName);
|
|
235
|
+
assert.deepEqual(got.record, closedHasNoCancel(want.record), `${how} ${viewName}: the chrome tells the host what it was recorded telling`);
|
|
236
|
+
if (how === 'dom') {
|
|
237
|
+
assert.equal(got.writes, want.writes, `${how} ${viewName}: the recorded DOM writes`);
|
|
238
|
+
assert.equal(got.dom, want.dom, `${how} ${viewName}: the recorded DOM bytes`);
|
|
239
|
+
}
|
|
240
|
+
passed += 1;
|
|
241
|
+
if (how === 'host') {
|
|
242
|
+
const surface = await run('surface', viewName);
|
|
243
|
+
assert.deepEqual(surface.record, closedHasNoCancel(want.record), `${viewName}: talk.js over the surface alone tells the host the same`);
|
|
244
|
+
passed += 1;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
// A closed panel binds no cancel, so a host's Back passes it by; an open
|
|
248
|
+
// one ends the conversation on cancel.
|
|
249
|
+
const { buildTalk, makeTalkView } = await import('../code/client/talkTree.js');
|
|
250
|
+
const view = makeTalkView();
|
|
251
|
+
let ends = 0;
|
|
252
|
+
const on = { end: () => {ends += 1;} };
|
|
253
|
+
assert.equal(buildTalk(view.state, { on }).on, undefined, 'never opened');
|
|
254
|
+
view.openTalk('Mabel');
|
|
255
|
+
assert.equal(buildTalk(view.state, { on }).on.cancel, on.end, 'open');
|
|
256
|
+
view.closeTalk();
|
|
257
|
+
assert.equal(buildTalk(view.state, { on }).on, undefined, 'closed');
|
|
258
|
+
resetUiTrees();
|
|
259
|
+
const { makeTalkSurface } = await import('../code/client/talkSurface.js');
|
|
260
|
+
const surface = makeTalkSurface({ view: () => ({ landscape: false, desktop: false, w: 390, safeInsets: false }) });
|
|
261
|
+
surface.onTalk({ open() {}, send() {}, end: () => {ends += 1;} });
|
|
262
|
+
assert.equal(dispatchUiEvent('talk', 'talk#cancel'), false, 'a closed panel takes no cancel');
|
|
263
|
+
surface.openTalk('Mabel');
|
|
264
|
+
assert.equal(dispatchUiEvent('talk', 'talk#cancel'), true);
|
|
265
|
+
assert.equal(ends, 1);
|
|
266
|
+
surface.closeTalk();
|
|
267
|
+
assert.equal(dispatchUiEvent('talk', 'talk#cancel'), false);
|
|
268
|
+
surface.dispose();
|
|
269
|
+
resetUiTrees();
|
|
270
|
+
passed += 1;
|
|
271
|
+
// Both surfaces load and run in a fresh process that has never had a DOM
|
|
272
|
+
// or a window (a native JS host), with talk.js driving the talk surface.
|
|
273
|
+
const probe = `
|
|
274
|
+
if (globalThis.document || globalThis.window) throw new Error('a DOM');
|
|
275
|
+
const { setUiTreeSink } = await import(${JSON.stringify(new URL('../code/client/uiTree.js', import.meta.url).href)});
|
|
276
|
+
const { makeHudSurface } = await import(${JSON.stringify(new URL('../code/client/hudSurface.js', import.meta.url).href)});
|
|
277
|
+
const { makeTalkSurface } = await import(${JSON.stringify(new URL('../code/client/talkSurface.js', import.meta.url).href)});
|
|
278
|
+
const { makeTalk } = await import(${JSON.stringify(new URL('../code/client/talk.js', import.meta.url).href)});
|
|
279
|
+
const roots = [];
|
|
280
|
+
setUiTreeSink((name, wire) => roots.push(name + ':' + (wire ? wire.k : null)), { dom: false });
|
|
281
|
+
const hud = makeHudSurface({ safeInsets: true });
|
|
282
|
+
hud.showBack(true, 'Town');
|
|
283
|
+
hud.setHud({ title: 'Race', timer: { until: 9000 } }, 4, 5000);
|
|
284
|
+
const surface = makeTalkSurface();
|
|
285
|
+
const talk = makeTalk({ ...surface, talkPrompt() {} });
|
|
286
|
+
talk.frame({ multiplayer: { net: null }, actorWith: () => null, getActors: () => [] }, { net: null }, true);
|
|
287
|
+
surface.openTalk('Mabel');
|
|
288
|
+
talk.reset();
|
|
289
|
+
hud.dispose();
|
|
290
|
+
surface.dispose();
|
|
291
|
+
console.log(roots.join(' '));
|
|
292
|
+
`;
|
|
293
|
+
assert.equal(execFileSync(process.execPath, ['--input-type=module', '-e', probe], { encoding: 'utf8' }).trim(), 'hud:hud hud:hud hud:hud talk:talk talk:talk talk:talk talk:talk hud:null talk:null');
|
|
294
|
+
passed += 1;
|
|
295
|
+
console.log(`talk surface: ${passed} checks passed`);
|
|
296
|
+
}
|
|
@@ -102,6 +102,19 @@ test('hints: a weak GPU or 2 GB is low, anything else high', () => {
|
|
|
102
102
|
assert.deepEqual(hintedTier({}), { tier: 'high', reason: 'auto' });
|
|
103
103
|
});
|
|
104
104
|
|
|
105
|
+
test('low-memory renderer profile hints Low without changing manual or Weakest rules', () => {
|
|
106
|
+
assert.deepEqual(hintedTier({ lowMemory: true }), { tier: 'low', reason: 'memory' });
|
|
107
|
+
assert.deepEqual(hintedTier({ gpu: 'Mali-G52 MC2', deviceMemory: 8, lowMemory: true }), { tier: 'low', reason: 'memory' });
|
|
108
|
+
assert.deepEqual(hintedTier({ gpu: 'Apple GPU', deviceMemory: 8, lowMemory: false }), { tier: 'high', reason: 'auto' });
|
|
109
|
+
const t = makeTiers({ storage: null, deviceMemory: 8, lowMemory: true, weakest: true });
|
|
110
|
+
assert.equal(t.pick(null), 'low');
|
|
111
|
+
assert.equal(t.reason(), 'memory');
|
|
112
|
+
assert.equal(t.weakest(), false, 'memory alone does not request Weakest');
|
|
113
|
+
assert.equal(t.middle(), false);
|
|
114
|
+
t.set('high');
|
|
115
|
+
assert.equal(t.pick(null), 'high', 'manual High still wins');
|
|
116
|
+
});
|
|
117
|
+
|
|
105
118
|
test('a slow visit is remembered for a week, then tried from high again', () => {
|
|
106
119
|
const now = 1_000_000_000_000;
|
|
107
120
|
const at = (ago) => memoryStorage({ [TIER_KEY]: JSON.stringify({ tier: 'low', at: now - ago }) });
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// The UI tree's DOM renderer in a real browser: rebuilding a root keeps a
|
|
2
|
+
// focused field's caret and selection, keeps a log's scroll position, and
|
|
3
|
+
// applies the talk log's scroll rules from measured layout.
|
|
4
|
+
import assert from 'node:assert/strict';
|
|
5
|
+
import { readFile } from 'node:fs/promises';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { chromium } from 'playwright-core';
|
|
8
|
+
import { launchChromium, logRenderer } from '../../../experiments/hub-town/qa/launch.mjs';
|
|
9
|
+
|
|
10
|
+
const root = new URL('../../../', import.meta.url);
|
|
11
|
+
const browser = await launchChromium(chromium, { executablePath: process.env.CHROME });
|
|
12
|
+
try {
|
|
13
|
+
const page = await browser.newPage();
|
|
14
|
+
await page.route('http://uidom.test/**', async (route) => {
|
|
15
|
+
const pathname = new URL(route.request().url()).pathname;
|
|
16
|
+
if (pathname === '/') {return route.fulfill({ contentType: 'text/html', body: '<body style="margin:0"></body>' });}
|
|
17
|
+
const url = new URL(`.${pathname}`, root);
|
|
18
|
+
assert(fileURLToPath(url).startsWith(fileURLToPath(root)));
|
|
19
|
+
await route.fulfill({ contentType: 'text/javascript', body: await readFile(url, 'utf8') });
|
|
20
|
+
});
|
|
21
|
+
await page.setViewportSize({ width: 390, height: 844 });
|
|
22
|
+
await page.goto('http://uidom.test/');
|
|
23
|
+
await logRenderer(page, 'UI tree DOM');
|
|
24
|
+
const result = await page.evaluate(async () => {
|
|
25
|
+
const { h } = await import('/kits/hub-game/code/client/uiTree.js');
|
|
26
|
+
const { mountUiTree } = await import('/kits/hub-game/code/client/uiDom.js');
|
|
27
|
+
const container = document.createElement('div');
|
|
28
|
+
container.style.cssText = 'position:fixed;inset:0;font:600 15px/1.3 system-ui, sans-serif';
|
|
29
|
+
document.body.append(container);
|
|
30
|
+
const ui = mountUiTree(container);
|
|
31
|
+
const state = { lines: [], follow: null, refollow: 0, chips: 0, value: '', ver: 1, focus: 0 };
|
|
32
|
+
let key = 0;
|
|
33
|
+
const draw = () => ui.render(h('stack', { key: 'talk' },
|
|
34
|
+
h('column', { key: 'panel', at: { anchor: 'bottom', bottom: 12 }, style: { w: 300, gap: 6, pad: 10, bg: 'card', hit: 'auto' } },
|
|
35
|
+
h('scroll', { key: 'log', axis: 'y', follow: [...(state.follow ? [state.follow] : []), { key: 'typing', mode: 'stick', endPx: 8 }], refollow: state.refollow, style: { maxH: state.chips > 3 ? 100 : 160, gap: 4 } },
|
|
36
|
+
state.lines.map((line) => h('text', { key: line.key, text: line.text, style: { self: line.me ? 'end' : 'start', maxW: '85%', pad: [5, 9], bg: line.me ? 'goldSoft' : 'cream', color: line.me ? '#fff' : 'inkText' } })),
|
|
37
|
+
state.typing ? h('activity', { key: 'typing', kind: 'dots', style: { self: 'start', gap: 3, pad: [5, 9], bg: 'cream' } }) : null),
|
|
38
|
+
h('field', { key: 'say', value: state.value, ver: state.ver, focus: state.focus, on: { input: (e) => {state.value = e.text;} } }),
|
|
39
|
+
state.chips ? h('row', { key: 'asks', style: { wrap: true, gap: 6 } }, Array.from({ length: state.chips }, (_, i) => h('button', { key: `a${i}`, style: { pad: [20, 11] } }, `Chip ${i}`))) : null)));
|
|
40
|
+
const line = (me, text) => {key += 1; state.lines.push({ key: `l${key}`, me, text }); state.follow = { key: `l${key}`, mode: me ? 'end' : 'top', endPx: 8 }; draw();};
|
|
41
|
+
draw();
|
|
42
|
+
const log = ui.nodeFor('talk/panel/log');
|
|
43
|
+
const input = ui.nodeFor('talk/panel/say');
|
|
44
|
+
const out = {};
|
|
45
|
+
// Caret and selection survive rebuilds that do not move the version.
|
|
46
|
+
state.focus = 1; draw();
|
|
47
|
+
input.value = 'hello world'; input.dispatchEvent(new Event('input'));
|
|
48
|
+
input.setSelectionRange(2, 7);
|
|
49
|
+
for (let i = 0; i < 6; i++) {line(i % 2 === 0, `Line ${i} `.repeat(6));}
|
|
50
|
+
out.focusKept = document.activeElement === input;
|
|
51
|
+
out.selection = [input.selectionStart, input.selectionEnd, input.value];
|
|
52
|
+
out.sameInput = ui.nodeFor('talk/panel/say') === input && ui.nodeFor('talk/panel/log') === log;
|
|
53
|
+
// A reply arriving at the end: its top at the top of what shows.
|
|
54
|
+
log.scrollTop = log.scrollHeight;
|
|
55
|
+
line(false, 'A long reply. '.repeat(30));
|
|
56
|
+
const reply = ui.nodeFor(`talk/panel/log/l${key}`);
|
|
57
|
+
out.replyTop = Math.round(reply.getBoundingClientRect().top - log.getBoundingClientRect().top);
|
|
58
|
+
// The player's own words: the end.
|
|
59
|
+
line(true, 'Mine');
|
|
60
|
+
out.mineAtEnd = Math.abs(log.scrollHeight - log.clientHeight - log.scrollTop) <= 1;
|
|
61
|
+
// Typing dots keep a viewer at the end at the end.
|
|
62
|
+
state.typing = true; draw();
|
|
63
|
+
out.typingAtEnd = Math.abs(log.scrollHeight - log.clientHeight - log.scrollTop) <= 1;
|
|
64
|
+
state.typing = false;
|
|
65
|
+
// A reader who scrolled up stays put through rebuilds, a reply and chips.
|
|
66
|
+
log.scrollTop = 40;
|
|
67
|
+
line(false, 'Another reply');
|
|
68
|
+
state.chips = 3; state.refollow += 1; draw();
|
|
69
|
+
out.readerKept = log.scrollTop;
|
|
70
|
+
// A JS write (a cleared field) is adopted when the version moves.
|
|
71
|
+
state.value = ''; state.ver += 1; draw();
|
|
72
|
+
out.cleared = input.value;
|
|
73
|
+
// Chips arriving under a followed reply (and shrinking the log, as a
|
|
74
|
+
// landscape panel's does) re-apply its alignment: it stays in view.
|
|
75
|
+
state.chips = 0; draw();
|
|
76
|
+
log.scrollTop = log.scrollHeight;
|
|
77
|
+
line(false, 'Followed reply. '.repeat(5));
|
|
78
|
+
const followed = ui.nodeFor(`talk/panel/log/l${key}`);
|
|
79
|
+
state.chips = 4; state.refollow += 1; draw();
|
|
80
|
+
const box = followed.getBoundingClientRect(), view = log.getBoundingClientRect();
|
|
81
|
+
out.refollowVisible = box.top >= view.top - 1 && box.bottom <= view.bottom + 1 && log.clientHeight === 100;
|
|
82
|
+
ui.dispose();
|
|
83
|
+
out.disposed = container.children.length === 0;
|
|
84
|
+
return out;
|
|
85
|
+
});
|
|
86
|
+
assert(result.focusKept, 'rebuilds keep the field focused');
|
|
87
|
+
assert.deepEqual(result.selection, [2, 7, 'hello world'], 'rebuilds keep the caret, selection and typed words');
|
|
88
|
+
assert(result.sameInput, 'the same elements throughout');
|
|
89
|
+
assert.equal(result.replyTop, 0, 'a reply at the end is read from its first word');
|
|
90
|
+
assert(result.mineAtEnd && result.typingAtEnd, 'own words and typing dots keep the end in view');
|
|
91
|
+
assert.equal(result.readerKept, 40, 'a reader who scrolled up is left there');
|
|
92
|
+
assert.equal(result.cleared, '', 'a version bump writes the value');
|
|
93
|
+
assert(result.refollowVisible, 'chips re-apply a followed reply\'s alignment');
|
|
94
|
+
assert(result.disposed, 'dispose takes out every node and the dots\' style');
|
|
95
|
+
console.log('UI tree DOM: focus, selection, scroll keeping and scroll rules passed');
|
|
96
|
+
} finally {await browser.close();}
|