castle-web-cli 0.4.236 → 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/api.d.ts +2 -0
- 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 +20 -0
- package/dist/castleJson.js +40 -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 +18 -13
- 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 +300 -85
- package/kits/hub-game/docs/analytics.md +11 -2
- package/kits/hub-game/docs/contract.md +353 -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-hub-trip.mjs +85 -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,178 @@
|
|
|
1
|
+
// The talk surface: the NPC talk panel's API (the one `talk.js` speaks to)
|
|
2
|
+
// over the talk view (`talkTree.js`), published as the `talk` UI tree root.
|
|
3
|
+
// No DOM and no window: the web chrome (`chrome.js`) draws each built root
|
|
4
|
+
// through `uiDom.js` (its `draw` hook) and adds its own DOM around the panel
|
|
5
|
+
// (`afterChange`); a native host gives `talk.js` this surface itself and
|
|
6
|
+
// takes the same root from the UI tree sink.
|
|
7
|
+
//
|
|
8
|
+
// makeTalkSurface({ view, autoFocus, onChip, draftNow, afterChange, draw }):
|
|
9
|
+
// view() the stage: { landscape, desktop, w, safeInsets };
|
|
10
|
+
// autoFocus() true when the field takes focus as it appears (a desktop
|
|
11
|
+
// keyboard); a phone keeps its keyboard down until a tap;
|
|
12
|
+
// onChip() a question chip was tapped (a sound);
|
|
13
|
+
// draftNow() the field's words as typed (the page's input while the page
|
|
14
|
+
// draws it); default: the view's mirror of the host's input;
|
|
15
|
+
// afterChange(what) the chrome's own surfaces follow the panel:
|
|
16
|
+
// 'open' / 'close' as the panel opens or closes, before it is
|
|
17
|
+
// drawn; 'surfaces' when what sits over the HUD changed;
|
|
18
|
+
// 'toast' when only the panel's size may have; 'shown' once
|
|
19
|
+
// an opened panel is drawn; 'layout' at the end of an open or
|
|
20
|
+
// close;
|
|
21
|
+
// draw(tree) called with each root built (only when the view changed).
|
|
22
|
+
import { publishUiRoot } from './uiTree.js';
|
|
23
|
+
import { buildTalk, makeTalkView } from './talkTree.js';
|
|
24
|
+
|
|
25
|
+
export function makeTalkSurface({ view = () => ({}), autoFocus = () => false, onChip = null, draftNow = null, afterChange = () => {}, draw = null } = {}) {
|
|
26
|
+
const talkView = makeTalkView();
|
|
27
|
+
let handlers = { open() {}, send() {}, end() {} };
|
|
28
|
+
let asksHandler = null;
|
|
29
|
+
const draft = () => (draftNow ? draftNow() : talkView.state.field.value);
|
|
30
|
+
function submit(typed) {
|
|
31
|
+
const text = typed ?? draft();
|
|
32
|
+
talkView.submitted();
|
|
33
|
+
render();
|
|
34
|
+
handlers.send(text);
|
|
35
|
+
}
|
|
36
|
+
const env = () => ({
|
|
37
|
+
...view(),
|
|
38
|
+
on: {
|
|
39
|
+
end: () => handlers.end(),
|
|
40
|
+
send: (text) => submit(text ?? undefined),
|
|
41
|
+
input: (event) => talkView.input(event),
|
|
42
|
+
focus: () => talkView.focused(true),
|
|
43
|
+
blur: () => talkView.focused(false),
|
|
44
|
+
ask: (ask) => {
|
|
45
|
+
if (onChip) {
|
|
46
|
+
onChip();
|
|
47
|
+
}
|
|
48
|
+
asksHandler?.(ask);
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
// Rebuilt only when the talk view changed (its `rev`) or the stage did:
|
|
53
|
+
// talk.js says `talkWaiting` every frame, and a long log is not rebuilt,
|
|
54
|
+
// serialized and reconciled for a frame that changed nothing. A closed
|
|
55
|
+
// panel is drawn once, hidden; lines that land after it closed wait for
|
|
56
|
+
// the next open (which starts a fresh log), and only a draft set while it
|
|
57
|
+
// is closed (the field's version) redraws it.
|
|
58
|
+
let key = '';
|
|
59
|
+
function render() {
|
|
60
|
+
const state = talkView.state;
|
|
61
|
+
const stage = env();
|
|
62
|
+
const next = `${state.open ? `o${state.rev}` : `c${state.field.ver}`}|${stage.landscape}|${stage.desktop}|${stage.w}`;
|
|
63
|
+
if (next === key) {return;}
|
|
64
|
+
key = next;
|
|
65
|
+
const tree = buildTalk(state, stage);
|
|
66
|
+
publishUiRoot('talk', tree);
|
|
67
|
+
draw?.(tree);
|
|
68
|
+
}
|
|
69
|
+
// The questions are taken out again, not hidden: the panel of a
|
|
70
|
+
// conversation with no questions has the nodes it always had.
|
|
71
|
+
const dropAsks = () => {
|
|
72
|
+
talkView.setAsks(null);
|
|
73
|
+
asksHandler = null;
|
|
74
|
+
render();
|
|
75
|
+
afterChange('surfaces');
|
|
76
|
+
};
|
|
77
|
+
const setTyping = (allowed) => {
|
|
78
|
+
// A child's choices stay when the field hides; other questions go.
|
|
79
|
+
const drop = !allowed && !talkView.state.asks?.child;
|
|
80
|
+
talkView.setTyping(allowed, autoFocus());
|
|
81
|
+
if (drop) {asksHandler = null;}
|
|
82
|
+
render();
|
|
83
|
+
if (drop) {afterChange('surfaces');}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
render();
|
|
87
|
+
return {
|
|
88
|
+
// The talk view's state (read only): `open`, `asks`, the field.
|
|
89
|
+
state: talkView.state,
|
|
90
|
+
// A turned or resized stage: the panel's width, height and log.
|
|
91
|
+
render,
|
|
92
|
+
// The controller's handlers: { open, send, end }.
|
|
93
|
+
onTalk(next) {
|
|
94
|
+
handlers = next;
|
|
95
|
+
},
|
|
96
|
+
// The Talk button was pressed.
|
|
97
|
+
requestOpen() {
|
|
98
|
+
handlers.open();
|
|
99
|
+
},
|
|
100
|
+
openTalk(name, { mind = false, canType = true } = {}) {
|
|
101
|
+
afterChange('open');
|
|
102
|
+
talkView.openTalk(name, { mind });
|
|
103
|
+
asksHandler = null;
|
|
104
|
+
render();
|
|
105
|
+
afterChange('surfaces');
|
|
106
|
+
afterChange('shown');
|
|
107
|
+
setTyping(canType);
|
|
108
|
+
afterChange('layout');
|
|
109
|
+
},
|
|
110
|
+
closeTalk() {
|
|
111
|
+
afterChange('close');
|
|
112
|
+
talkView.closeTalk();
|
|
113
|
+
asksHandler = null;
|
|
114
|
+
render();
|
|
115
|
+
afterChange('surfaces');
|
|
116
|
+
afterChange('layout');
|
|
117
|
+
},
|
|
118
|
+
talkTyping: setTyping,
|
|
119
|
+
// Plain muted words under the log (the opening), or null for none: why an
|
|
120
|
+
// under-13 speaker has no field ("Talking with Biscuit is for players 13
|
|
121
|
+
// and up"). Not a button.
|
|
122
|
+
talkHint(text) {
|
|
123
|
+
if (!talkView.setHint(talkView.state.open ? text : null)) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
render();
|
|
127
|
+
afterChange('surfaces');
|
|
128
|
+
},
|
|
129
|
+
// A refused re-attach keeps the unsent question for the next open.
|
|
130
|
+
talkDraft(text) {
|
|
131
|
+
if (text !== undefined) {
|
|
132
|
+
talkView.setDraft(text);
|
|
133
|
+
render();
|
|
134
|
+
}
|
|
135
|
+
return draft();
|
|
136
|
+
},
|
|
137
|
+
// v1.47: replace the opening in place; questions and later lines stay put.
|
|
138
|
+
talkOpening(text) {
|
|
139
|
+
if (talkView.state.open && talkView.setOpening(text)) {
|
|
140
|
+
render();
|
|
141
|
+
afterChange('toast');
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
// v1.46: a mind's chips sit below its field; an empty list removes them.
|
|
145
|
+
talkAsks(asks, onAsk) {
|
|
146
|
+
if (!talkView.setAsks(asks)) {
|
|
147
|
+
dropAsks();
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
asksHandler = onAsk;
|
|
151
|
+
// Drawn, then laid out; a reply followed to its top stays followed
|
|
152
|
+
// (the log's `refollow`) unless the player has scrolled.
|
|
153
|
+
render();
|
|
154
|
+
afterChange('surfaces');
|
|
155
|
+
},
|
|
156
|
+
// `note`, when given, is a small caption under the line (a scripted reply).
|
|
157
|
+
// v1.35: a reply is read from its first word, its top at the top of what
|
|
158
|
+
// shows, when the log was at its end; the player's own words scroll to
|
|
159
|
+
// the end; a player reading further up is left there (the log's `follow`).
|
|
160
|
+
talkLine(who, text, note = null) {
|
|
161
|
+
talkView.line(who, text, note);
|
|
162
|
+
render();
|
|
163
|
+
afterChange('toast');
|
|
164
|
+
},
|
|
165
|
+
talkWaiting(waiting) {
|
|
166
|
+
if (talkView.setWaiting(waiting)) {render();}
|
|
167
|
+
afterChange('toast');
|
|
168
|
+
},
|
|
169
|
+
// Whether the field has focus, as the host last said.
|
|
170
|
+
talkFocused() {
|
|
171
|
+
return talkView.state.field.focused;
|
|
172
|
+
},
|
|
173
|
+
// A host drops the root.
|
|
174
|
+
dispose() {
|
|
175
|
+
publishUiRoot('talk', null);
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
// The NPC talk panel as a UI tree (schema v0 §12), and the state it is drawn
|
|
2
|
+
// from. The controller (`talk.js`) still speaks to the chrome in events
|
|
3
|
+
// (openTalk, talkLine, talkAsks, ...); each one now changes this talk view,
|
|
4
|
+
// and the panel is rebuilt from it: the web chrome draws it with `uiDom.js`,
|
|
5
|
+
// a native host gets the same tree through the UI tree sink. Pure: no DOM,
|
|
6
|
+
// no window.
|
|
7
|
+
|
|
8
|
+
import { h } from './uiTree.js';
|
|
9
|
+
|
|
10
|
+
// The talk panel's log counts as at its end within this many pixels of it.
|
|
11
|
+
export const TALK_END_PX = 8;
|
|
12
|
+
|
|
13
|
+
// The talk view: { open, name, mind, canType, lines: [{ key, who, text,
|
|
14
|
+
// note }], typing, waiting, asks: null | { list, child }, hint, field: {
|
|
15
|
+
// value, ver, focus, focused }, follow, refollow, rev }. Its methods are the
|
|
16
|
+
// chrome talk API's state changes, one for one. `rev` counts the changes the
|
|
17
|
+
// panel shows: a caller compares it with the rev it last drew and skips the
|
|
18
|
+
// rebuild when nothing moved (talk.js says `talkWaiting` every frame). The
|
|
19
|
+
// field's mirrored input and focus flag are not drawn and do not move it.
|
|
20
|
+
export function makeTalkView() {
|
|
21
|
+
let lineIds = 0;
|
|
22
|
+
const view = {
|
|
23
|
+
open: false,
|
|
24
|
+
name: '',
|
|
25
|
+
mind: false,
|
|
26
|
+
canType: false,
|
|
27
|
+
lines: [],
|
|
28
|
+
typing: false,
|
|
29
|
+
waiting: false,
|
|
30
|
+
asks: null,
|
|
31
|
+
hint: null,
|
|
32
|
+
// The line a later `talkOpening` replaces in place (the first reply).
|
|
33
|
+
opening: null,
|
|
34
|
+
field: { value: '', ver: 0, focus: 0, focused: false },
|
|
35
|
+
// The last line's scroll rule ('end' for the player's own words, 'top'
|
|
36
|
+
// for a reply); `refollow` counts the chip refills that re-apply it.
|
|
37
|
+
follow: null,
|
|
38
|
+
refollow: 0,
|
|
39
|
+
rev: 0,
|
|
40
|
+
};
|
|
41
|
+
const touch = () => {view.rev += 1;};
|
|
42
|
+
const focusField = () => {view.field.focus = Math.abs(view.field.focus) + 1;};
|
|
43
|
+
const blurField = () => {view.field.focus = -(Math.abs(view.field.focus) + 1);};
|
|
44
|
+
return {
|
|
45
|
+
state: view,
|
|
46
|
+
openTalk(name, { mind = false } = {}) {
|
|
47
|
+
Object.assign(view, { open: true, name: String(name ?? ''), mind, lines: [], typing: false, waiting: false, asks: null, hint: null, opening: null, follow: null, canType: false });
|
|
48
|
+
view.field.value = '';
|
|
49
|
+
view.field.ver += 1;
|
|
50
|
+
touch();
|
|
51
|
+
},
|
|
52
|
+
closeTalk() {
|
|
53
|
+
view.open = false;
|
|
54
|
+
view.opening = null;
|
|
55
|
+
view.asks = null;
|
|
56
|
+
view.hint = null;
|
|
57
|
+
view.typing = false;
|
|
58
|
+
blurField();
|
|
59
|
+
touch();
|
|
60
|
+
},
|
|
61
|
+
// Whether the field shows; true (when `autoFocus`) asks for focus as it
|
|
62
|
+
// appears, as a desktop keyboard expects. Returns whether asks were
|
|
63
|
+
// dropped (the field hid and the chips were not a child's choices).
|
|
64
|
+
setTyping(allowed, autoFocus = false) {
|
|
65
|
+
touch();
|
|
66
|
+
const wasHidden = !view.canType;
|
|
67
|
+
view.canType = Boolean(allowed);
|
|
68
|
+
if (!allowed) {
|
|
69
|
+
blurField();
|
|
70
|
+
if (!view.asks?.child) {
|
|
71
|
+
const had = view.asks !== null;
|
|
72
|
+
view.asks = null;
|
|
73
|
+
return had;
|
|
74
|
+
}
|
|
75
|
+
} else if (wasHidden && autoFocus) {
|
|
76
|
+
focusField();
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
},
|
|
80
|
+
// Plain words under the log, or null; false when nothing changed.
|
|
81
|
+
setHint(text) {
|
|
82
|
+
const words = view.open && typeof text === 'string' && text ? text : null;
|
|
83
|
+
if (view.hint === words) {return false;}
|
|
84
|
+
view.hint = words;
|
|
85
|
+
touch();
|
|
86
|
+
return true;
|
|
87
|
+
},
|
|
88
|
+
setDraft(text) {
|
|
89
|
+
view.field.value = String(text);
|
|
90
|
+
view.field.ver += 1;
|
|
91
|
+
touch();
|
|
92
|
+
},
|
|
93
|
+
// The field's input, mirrored without moving its version; input typed
|
|
94
|
+
// before a reset landed (an older base) is dropped.
|
|
95
|
+
input({ text, base } = {}) {
|
|
96
|
+
if (base !== undefined && base < view.field.ver) {return;}
|
|
97
|
+
view.field.value = String(text ?? '');
|
|
98
|
+
},
|
|
99
|
+
// A submitted line clears the field (a version bump).
|
|
100
|
+
submitted() {
|
|
101
|
+
view.field.value = '';
|
|
102
|
+
view.field.ver += 1;
|
|
103
|
+
touch();
|
|
104
|
+
},
|
|
105
|
+
focused(on) {
|
|
106
|
+
view.field.focused = Boolean(on);
|
|
107
|
+
},
|
|
108
|
+
setOpening(text) {
|
|
109
|
+
if (!view.open || !view.opening) {return false;}
|
|
110
|
+
const line = view.lines.find((item) => item.key === view.opening);
|
|
111
|
+
if (!line) {return false;}
|
|
112
|
+
line.text = String(text);
|
|
113
|
+
touch();
|
|
114
|
+
return true;
|
|
115
|
+
},
|
|
116
|
+
// `list`: up to three questions (strings) or up to four child choices
|
|
117
|
+
// ({ id, label }); empty or not a list removes the row.
|
|
118
|
+
setAsks(asks) {
|
|
119
|
+
const child = Array.isArray(asks) && typeof asks[0]?.id === 'string';
|
|
120
|
+
const list = Array.isArray(asks) ? asks.slice(0, child ? 4 : 3) : [];
|
|
121
|
+
touch();
|
|
122
|
+
if (!list.length) {
|
|
123
|
+
view.asks = null;
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
view.asks = { list, child };
|
|
127
|
+
view.refollow += 1;
|
|
128
|
+
return true;
|
|
129
|
+
},
|
|
130
|
+
line(who, text, note = null) {
|
|
131
|
+
if (who === 'them') {view.typing = false;}
|
|
132
|
+
const key = `l${(lineIds += 1)}`;
|
|
133
|
+
view.lines.push({ key, who, text: String(text ?? ''), note: note ? String(note) : null });
|
|
134
|
+
if (who === 'them' && view.lines.length === 1) {view.opening = key;}
|
|
135
|
+
view.follow = { key, mode: who === 'me' ? 'end' : 'top', endPx: TALK_END_PX };
|
|
136
|
+
touch();
|
|
137
|
+
},
|
|
138
|
+
// Said every frame; true when anything drawn changed.
|
|
139
|
+
setWaiting(waiting) {
|
|
140
|
+
const was = [view.waiting, view.typing];
|
|
141
|
+
view.waiting = Boolean(waiting);
|
|
142
|
+
if (!waiting) {view.typing = false;}
|
|
143
|
+
else if (view.open && view.mind) {view.typing = true;}
|
|
144
|
+
if (was[0] === view.waiting && was[1] === view.typing) {return false;}
|
|
145
|
+
touch();
|
|
146
|
+
return true;
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Whether a submit belongs to the field as it is now: the panel is open and
|
|
152
|
+
// the submit carries the field's current version. A submit typed before a
|
|
153
|
+
// reset (a sent line, a draft set, another conversation opened) is late: it
|
|
154
|
+
// is dropped, neither sent nor clearing the field. A submit with no version
|
|
155
|
+
// at all is refused too; every renderer sends one.
|
|
156
|
+
export function submitCurrent(view, e) {
|
|
157
|
+
return Boolean(view.open) && Number.isFinite(e?.base) && e.base === view.field.ver;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const LINE = { maxW: '85%', pad: [5, 9], radius: 10 };
|
|
161
|
+
const THEM = { self: 'start', bg: 'cream', color: 'inkText' };
|
|
162
|
+
const ME = { self: 'end', bg: 'goldSoft', color: '#fff' };
|
|
163
|
+
|
|
164
|
+
// env = { landscape, desktop, w (view width), safeInsets, on: { end, send,
|
|
165
|
+
// input, focus, blur, ask } }; `on.send(text)` and `on.ask(item)` are called
|
|
166
|
+
// by the Say button / Enter and by a chip.
|
|
167
|
+
export function buildTalk(view, env = {}) {
|
|
168
|
+
const on = env.on ?? {};
|
|
169
|
+
const landscape = Boolean(env.landscape);
|
|
170
|
+
const wide = !landscape && Boolean(env.desktop);
|
|
171
|
+
const firstName = String(view.name ?? '').split(',')[0].trim();
|
|
172
|
+
const panelStyle = landscape
|
|
173
|
+
? { w: (env.w ?? 0) < 740 ? [{ vw: 70 }, { px: 420 }] : [{ vw: 56 }, { max: [220, { vw: 100, px: -344 }] }, { px: 560 }], maxH: [{ dvh: 100, px: -88, safe: 'tb' }], box: 'border', clip: true }
|
|
174
|
+
: wide ? { w: 340 } : { w: [{ vw: 92 }, { px: 420 }] };
|
|
175
|
+
const at = wide
|
|
176
|
+
? { anchor: 'bottomLeft', bottom: [12, 0], left: env.safeInsets ? [10, 0] : 10 }
|
|
177
|
+
: { anchor: 'bottom', bottom: [12, 0] };
|
|
178
|
+
const logStyle = landscape
|
|
179
|
+
? { maxH: 'none', minH: 0, flex: '1 1 auto' }
|
|
180
|
+
: { maxH: wide ? [{ vh: 28 }, { px: 220 }] : [{ vh: 28 }] };
|
|
181
|
+
|
|
182
|
+
const lines = view.lines.map((line) => {
|
|
183
|
+
const style = { ...(line.who === 'me' ? ME : THEM), ...LINE };
|
|
184
|
+
return line.note
|
|
185
|
+
? h('column', { key: line.key, style: { ...style, gap: 2 } }, line.text,
|
|
186
|
+
h('text', { key: 'note', text: line.note, style: { size: 11, italic: true, opacity: 0.65 } }))
|
|
187
|
+
: h('text', { key: line.key, text: line.text, style });
|
|
188
|
+
});
|
|
189
|
+
if (view.typing && view.open && view.mind) {
|
|
190
|
+
lines.push(h('activity', {
|
|
191
|
+
key: 'typing', kind: 'dots', role: 'status', label: `${view.name} is typing`,
|
|
192
|
+
style: { self: 'start', gap: 3, pad: [5, 9], radius: 10, bg: 'cream', color: 'inkText' },
|
|
193
|
+
}));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const asks = view.asks && h(landscape ? 'grid' : 'row', { key: 'asks', ...(landscape ? { cols: 2 } : {}), style: { wrap: true, gap: 6 } },
|
|
197
|
+
view.mind && !view.asks.child ? h('text', { key: 'or', text: 'or try:', style: { size: 12, opacity: 0.7, basis: '100%' } }) : null,
|
|
198
|
+
view.asks.list.map((ask, i) => h('button', {
|
|
199
|
+
key: `a${i}`, fire: 'down', keepFocus: true,
|
|
200
|
+
style: { hit: 'auto', maxW: '100%', wrap: 'anywhere', pad: [6, 11], radius: 14, border: { w: 1, c: 'askLine' }, bg: 'askChip', color: 'askText', size: 13, weight: 600, lh: 1.25, talign: 'start' },
|
|
201
|
+
on: { tap: () => on.ask?.(ask) },
|
|
202
|
+
}, view.asks.child ? ask.label : ask)));
|
|
203
|
+
|
|
204
|
+
// Cancel (a host's Back) ends the conversation only while there is one: a
|
|
205
|
+
// closed panel's root binds none, so Back passes it by.
|
|
206
|
+
return h('stack', { key: 'talk', style: { font: 'ui', size: 15, weight: 600, lh: 1.3, color: '#fff' }, on: { cancel: view.open ? on.end : undefined } },
|
|
207
|
+
h('column', { key: 'panel', at, style: { ...panelStyle, gap: 6, pad: 10, radius: 12, bg: 'card', shadow: 'card', hit: 'auto', gone: !view.open } },
|
|
208
|
+
h('row', { key: 'head', style: { align: 'baseline', gap: 8 } },
|
|
209
|
+
h('text', { key: 'name', text: view.name, style: { weight: 700, flex: 1 } }),
|
|
210
|
+
h('button', {
|
|
211
|
+
key: 'done', fire: 'down',
|
|
212
|
+
style: { pad: [4, 10], radius: 12, border: { w: 1, c: 'line35' }, bg: 'transparent', color: '#fff', size: 13, weight: 600, lh: 'normal' },
|
|
213
|
+
on: { tap: on.end },
|
|
214
|
+
}, 'Done')),
|
|
215
|
+
h('scroll', {
|
|
216
|
+
key: 'log', axis: 'y',
|
|
217
|
+
follow: [...(view.follow ? [view.follow] : []), { key: 'typing', mode: 'stick', endPx: TALK_END_PX }],
|
|
218
|
+
refollow: view.refollow,
|
|
219
|
+
style: { ...logStyle, gap: 4, size: 14, weight: 500 },
|
|
220
|
+
}, lines),
|
|
221
|
+
// An authored NPC's choices come before the field, a mind's after it.
|
|
222
|
+
view.mind ? null : asks,
|
|
223
|
+
view.hint ? h('text', { key: 'hint', text: view.hint, style: { size: 12, weight: 500, opacity: 0.7 } }) : null,
|
|
224
|
+
h('row', { key: 'form', style: { gap: 6, gone: !view.canType } },
|
|
225
|
+
h('field', {
|
|
226
|
+
key: 'say', name: 'say', value: view.field.value, ver: view.field.ver, focus: view.field.focus,
|
|
227
|
+
ph: view.mind ? `Ask ${firstName} anything…` : 'Say something…',
|
|
228
|
+
max: 280, maxUnit: 'utf16', enter: 'send', cap: 'sentences', spell: true,
|
|
229
|
+
style: { flex: 1, minW: 0, pad: [8, 10], radius: 8, border: { w: 1, c: 'fieldLine' }, bg: 'field', color: '#fff', size: 15, weight: 500, lh: 'normal' },
|
|
230
|
+
on: { input: on.input, submit: (e) => {if (submitCurrent(view, e)) {on.send?.(e?.text ?? '');}}, cancel: on.end, focus: on.focus, blur: on.blur },
|
|
231
|
+
}),
|
|
232
|
+
h('button', {
|
|
233
|
+
key: 'send', disabled: view.waiting,
|
|
234
|
+
style: { pad: [8, 14], radius: 8, border: 'none', bg: 'gold', color: 'onGold', size: 14, weight: 700, lh: 'normal', opacity: view.waiting ? 0.5 : 1 },
|
|
235
|
+
on: { tap: () => on.send?.(null) },
|
|
236
|
+
}, view.waiting ? '…' : 'Say')),
|
|
237
|
+
view.mind ? asks : null));
|
|
238
|
+
}
|
|
@@ -94,7 +94,10 @@ export function weakGpu(renderer) {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
// The tier the device's own hints give, before a frame is drawn.
|
|
97
|
-
export function hintedTier({ gpu = null, deviceMemory = null } = {}) {
|
|
97
|
+
export function hintedTier({ gpu = null, deviceMemory = null, lowMemory = false } = {}) {
|
|
98
|
+
if (lowMemory === true) {
|
|
99
|
+
return { tier: 'low', reason: 'memory' };
|
|
100
|
+
}
|
|
98
101
|
if (weakGpu(gpu)) {
|
|
99
102
|
return { tier: 'low', reason: 'gpu' };
|
|
100
103
|
}
|
|
@@ -131,12 +134,12 @@ export function readMode(storage, weakest = false) {
|
|
|
131
134
|
}
|
|
132
135
|
|
|
133
136
|
// Where a device starts: found slow here within the week, then its hints.
|
|
134
|
-
export function initialTier({ storage, now, gpu, deviceMemory }) {
|
|
137
|
+
export function initialTier({ storage, now, gpu, deviceMemory, lowMemory }) {
|
|
135
138
|
const seen = readJson(storage, TIER_KEY);
|
|
136
139
|
if (seen?.tier === 'low' && typeof seen.at === 'number' && now - seen.at >= 0 && now - seen.at < REMEMBER_MS) {
|
|
137
140
|
return { tier: 'low', reason: 'remembered' };
|
|
138
141
|
}
|
|
139
|
-
return hintedTier({ gpu, deviceMemory });
|
|
142
|
+
return hintedTier({ gpu, deviceMemory, lowMemory });
|
|
140
143
|
}
|
|
141
144
|
|
|
142
145
|
export function median(values) {
|
|
@@ -892,7 +895,7 @@ function pageStorage() {
|
|
|
892
895
|
|
|
893
896
|
// The hub system's tiers: `frame(scene, counts, now)` each frame. `counts` is
|
|
894
897
|
// whether this frame says how the device draws the place (see `makeJudge`).
|
|
895
|
-
export function makeTiers({ storage = pageStorage(), clock = () => Date.now(), deviceMemory = globalThis.navigator?.deviceMemory ?? null, onLayout, levers = makeLevers({ onLayout }), weakest = false } = {}) {
|
|
898
|
+
export function makeTiers({ storage = pageStorage(), clock = () => Date.now(), deviceMemory = globalThis.navigator?.deviceMemory ?? null, lowMemory = false, onLayout, levers = makeLevers({ onLayout }), weakest = false } = {}) {
|
|
896
899
|
const t = {
|
|
897
900
|
mode: readMode(storage, weakest),
|
|
898
901
|
auto: null,
|
|
@@ -926,7 +929,7 @@ export function makeTiers({ storage = pageStorage(), clock = () => Date.now(), d
|
|
|
926
929
|
const gpu = gpuOf(renderer);
|
|
927
930
|
t.weakestDevice = weakest && weakestGpu(gpu);
|
|
928
931
|
t.middleDevice = weakest && middleGpu(gpu);
|
|
929
|
-
t.auto = initialTier({ storage, now: clock(), gpu, deviceMemory });
|
|
932
|
+
t.auto = initialTier({ storage, now: clock(), gpu, deviceMemory, lowMemory });
|
|
930
933
|
if (t.weakestDevice) { t.auto = { tier: 'low', reason: 'gpu' }; }
|
|
931
934
|
}
|
|
932
935
|
return t.current();
|