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
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// Shared Act/Jump controls, allocated only by hub.act. All text comes from
|
|
2
2
|
// the server's current private offer; scene data supplies its world anchor.
|
|
3
3
|
import { makeLayoutCache } from './layoutCache.js';
|
|
4
|
-
import { hub } from './state.js';
|
|
5
|
-
import { footprintDistance } from './idle.js';
|
|
6
4
|
import { clearBox } from './padOccupancy.js';
|
|
7
|
-
import {
|
|
5
|
+
import { mountUiTree } from './uiDom.js';
|
|
6
|
+
import { buildActPair } from './hudTree.js';
|
|
7
|
+
import { makeActCore } from './actCore.js';
|
|
8
8
|
|
|
9
9
|
const intersects = (a, b) => a.left < b.right && a.right > b.left && a.top < b.bottom && a.bottom > b.top;
|
|
10
10
|
export function placeBox(w, h, preferred, bounds, obstacles) {
|
|
@@ -21,9 +21,6 @@ export function placeBox(w, h, preferred, bounds, obstacles) {
|
|
|
21
21
|
return null;
|
|
22
22
|
}
|
|
23
23
|
const textEntry = event => event.target?.isContentEditable || ['INPUT', 'TEXTAREA', 'SELECT'].includes(event.target?.tagName);
|
|
24
|
-
// Authored counter verbs (Trade, Stamp, Buy, Play, Sit...) take focus over a
|
|
25
|
-
// nearby loose body or keeper; distance decides only within a rank.
|
|
26
|
-
const rank = item => item.op === 'talk' || item.op === 'grab' ? 1 : 0;
|
|
27
24
|
const typing = event => textEntry(event) || event.target?.tagName === 'BUTTON';
|
|
28
25
|
// Break only at spaces, keeping any omission after a complete word. Explicit
|
|
29
26
|
// line breaks avoid browser line-clamp ellipses in the middle of a name.
|
|
@@ -64,53 +61,54 @@ export function makeAct(chrome, grab, talk) {
|
|
|
64
61
|
const root = document.createElement('div');
|
|
65
62
|
Object.assign(root.style, { position: 'absolute', inset: '0', pointerEvents: 'none', zIndex: '2' });
|
|
66
63
|
chrome.interactionRoot().appendChild(root);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
64
|
+
// The Act/Jump pair is the HUD root's `actpair` node (`hudTree.js`): drawn
|
|
65
|
+
// here, in this layer, by the UI tree's DOM renderer, and handed to the
|
|
66
|
+
// chrome so a native host's HUD tree carries it too. Its presses come back
|
|
67
|
+
// as the tree's events. Selection, presses and Jump are `actCore.js`'s.
|
|
68
|
+
const core = makeActCore({
|
|
69
|
+
now: () => performance.now(),
|
|
70
|
+
send: (message, mp) => mp.net?.send(message),
|
|
71
|
+
effects: {
|
|
72
|
+
throw: (item, f, done) => grab.perform(item.actor, f.scene, f.mp, f.local, item.op, done),
|
|
73
|
+
grab: (item, f) => grab.perform(item.actor, f.scene, f.mp, f.local, item.op),
|
|
74
|
+
talk: item => talk.prepare(item.actor),
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
const pairState = { show: false, enabled: false, on: {
|
|
78
|
+
press: ({ pointerId } = {}) => {keyboardInput = false; core.start(core.current(), `pointer:${pointerId}`);},
|
|
79
|
+
release: ({ pointerId } = {}) => {if (core.pressSource() === `pointer:${pointerId}`) {core.release();}},
|
|
80
|
+
cancel: ({ pointerId } = {}) => {if (core.pressSource() === `pointer:${pointerId}`) {core.cancel();}},
|
|
81
|
+
jump: () => {keyboardInput = false; core.queueJump();},
|
|
82
|
+
} };
|
|
83
|
+
const pairDom = mountUiTree(root);
|
|
84
|
+
let pairKey = '';
|
|
85
|
+
function drawPair() {
|
|
86
|
+
const key = `${pairState.show}:${pairState.enabled}`;
|
|
87
|
+
if (key === pairKey) {return;}
|
|
88
|
+
pairKey = key;
|
|
89
|
+
pairDom.render({ t: 'stack', k: 'act', c: [buildActPair(pairState)] });
|
|
90
|
+
chrome.setActPair?.(pairState);
|
|
91
|
+
}
|
|
92
|
+
drawPair();
|
|
93
|
+
const pair = pairDom.nodeFor('act/actpair');
|
|
94
|
+
const act = pairDom.nodeFor('act/actpair/act'), jump = pairDom.nodeFor('act/actpair/jump');
|
|
73
95
|
chrome.interactionRail(pair, act, jump);
|
|
74
|
-
act.style.width = jump.style.width = '64px';
|
|
75
96
|
const probe = document.createElement('div');
|
|
76
97
|
Object.assign(probe.style, { position: 'absolute', visibility: 'hidden', pointerEvents: 'none', padding: 'env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left)' });
|
|
77
98
|
root.appendChild(probe);
|
|
78
99
|
geometry.register(probe, { padding: true });
|
|
79
100
|
for (const node of [pair, act, jump]) {geometry.register(node);}
|
|
80
101
|
const nodes = new Map(), listeners = new AbortController(), signal = listeners.signal;
|
|
81
|
-
let
|
|
102
|
+
let input = null, originalJump = null;
|
|
82
103
|
let keyboardInput = false;
|
|
83
104
|
let textMeasure;
|
|
84
105
|
chrome.setActMode(true);
|
|
85
|
-
|
|
86
|
-
if (press) {context?.mp.net?.send({ k: 'hub-act-hold', id: press.id, n: press.n, down: false });}
|
|
87
|
-
press = null;
|
|
88
|
-
}
|
|
89
|
-
function perform(item, n) {
|
|
90
|
-
const c = context;
|
|
91
|
-
if (!c?.can || !item) {return;}
|
|
92
|
-
// The existing client prediction/denial paths carry grabs and NPC panels.
|
|
93
|
-
if (item.op === 'throw') {
|
|
94
|
-
grab.perform(item.actor, c.scene, c.mp, c.local, item.op, () => c.mp.net.send({ k: 'hub-act', id: item.id, n }));
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
if (item.op === 'grab') {grab.perform(item.actor, c.scene, c.mp, c.local, item.op);}
|
|
98
|
-
if (item.op === 'talk') {talk.prepare(item.actor);}
|
|
99
|
-
c.mp.net.send({ k: 'hub-act', id: item.id, n });
|
|
100
|
-
}
|
|
101
|
-
function release() {
|
|
102
|
-
if (!press || performance.now() - press.at < 500) {cancel(); return;}
|
|
103
|
-
const done = press; press = null; perform(done.item, done.n);
|
|
104
|
-
}
|
|
105
|
-
function start(item, source) {
|
|
106
|
-
if (!context?.can || !item || press) {return;}
|
|
107
|
-
const n = ++seq;
|
|
108
|
-
if (item.hold) {
|
|
109
|
-
press = { id: item.id, n, at: performance.now(), source, item };
|
|
110
|
-
context.mp.net.send({ k: 'hub-act-hold', id: item.id, n, down: true });
|
|
111
|
-
} else {perform(item, n);}
|
|
112
|
-
}
|
|
106
|
+
const start = (item, source) => core.start(item, source);
|
|
113
107
|
function bind(node, item) {
|
|
108
|
+
bindPointer(node, item);
|
|
109
|
+
bindKeys(node, item);
|
|
110
|
+
}
|
|
111
|
+
function bindPointer(node, item) {
|
|
114
112
|
node.addEventListener('pointerdown', event => {
|
|
115
113
|
keyboardInput = false;
|
|
116
114
|
event.preventDefault(); event.stopPropagation();
|
|
@@ -120,11 +118,13 @@ export function makeAct(chrome, grab, talk) {
|
|
|
120
118
|
for (const type of ['pointerup', 'pointercancel', 'lostpointercapture']) {
|
|
121
119
|
node.addEventListener(type, event => {
|
|
122
120
|
event.preventDefault(); event.stopPropagation();
|
|
123
|
-
if (
|
|
124
|
-
if (type === 'pointerup') {release();} else {cancel();}
|
|
121
|
+
if (core.pressSource() === `pointer:${event.pointerId}`) {
|
|
122
|
+
if (type === 'pointerup') {core.release();} else {core.cancel();}
|
|
125
123
|
}
|
|
126
124
|
}, { signal });
|
|
127
125
|
}
|
|
126
|
+
}
|
|
127
|
+
function bindKeys(node, item) {
|
|
128
128
|
node.addEventListener('keydown', event => {
|
|
129
129
|
if (event.code === 'Space' || event.code === 'Enter') {
|
|
130
130
|
keyboardInput = true;
|
|
@@ -140,7 +140,7 @@ export function makeAct(chrome, grab, talk) {
|
|
|
140
140
|
}, { signal });
|
|
141
141
|
node.addEventListener('keyup', event => {
|
|
142
142
|
if (['Space', 'Enter'].includes(event.code)) {event.stopPropagation();}
|
|
143
|
-
if (
|
|
143
|
+
if (core.pressSource() === event.code) {event.preventDefault(); core.release();}
|
|
144
144
|
}, { signal });
|
|
145
145
|
// Synthesized activation has no hold duration. It can activate ordinary
|
|
146
146
|
// actions; spending still requires sustained pointer or keyboard input.
|
|
@@ -151,64 +151,42 @@ export function makeAct(chrome, grab, talk) {
|
|
|
151
151
|
if (chosen && !chosen.hold) {start(chosen, 'click');}
|
|
152
152
|
}, { signal });
|
|
153
153
|
}
|
|
154
|
-
|
|
155
|
-
jump.addEventListener('pointerdown', event => {keyboardInput = false; event.preventDefault(); event.stopPropagation(); if (context?.can) {queuedJump = true;}}, { signal });
|
|
154
|
+
bindKeys(act, () => core.current());
|
|
156
155
|
jump.addEventListener('keydown', event => {
|
|
157
|
-
if (['Space', 'Enter'].includes(event.code)) {keyboardInput = true; event.preventDefault(); event.stopPropagation(); if (!event.repeat
|
|
156
|
+
if (['Space', 'Enter'].includes(event.code)) {keyboardInput = true; event.preventDefault(); event.stopPropagation(); if (!event.repeat) {core.queueJump();}}
|
|
158
157
|
}, { signal });
|
|
159
|
-
jump.addEventListener('click', event => {if (event.detail === 0
|
|
158
|
+
jump.addEventListener('click', event => {if (event.detail === 0) {core.queueJump();}}, { signal });
|
|
160
159
|
globalThis.addEventListener?.('pointerdown', () => {keyboardInput = false;}, { capture: true, signal });
|
|
161
160
|
globalThis.addEventListener?.('keydown', event => {
|
|
162
161
|
// Pointer capability does not establish a hardware-keyboard input.
|
|
163
162
|
// Observe game/navigation keys outside editable or composing text instead.
|
|
164
163
|
if (!textEntry(event) && !event.isComposing && !event.altKey && !event.ctrlKey && !event.metaKey &&
|
|
165
164
|
/^(Key[WASDEF]|Arrow(Up|Down|Left|Right)|Space|Enter|Tab)$/.test(event.code)) {keyboardInput = true;}
|
|
166
|
-
if (typing(event) || event.altKey || event.ctrlKey || event.metaKey || !
|
|
165
|
+
if (typing(event) || event.altKey || event.ctrlKey || event.metaKey || !core.can()) {return;}
|
|
166
|
+
const current = core.current();
|
|
167
167
|
if (event.code === 'KeyE' || (event.code === 'Space' && current)) {
|
|
168
168
|
event.preventDefault(); event.stopImmediatePropagation();
|
|
169
|
-
if (event.code === 'Space') {
|
|
169
|
+
if (event.code === 'Space') {core.facade().scene.keys?.delete?.('Space');}
|
|
170
170
|
if (!event.repeat) {start(current, event.code);}
|
|
171
171
|
}
|
|
172
172
|
}, { capture: true, signal });
|
|
173
173
|
globalThis.addEventListener?.('keyup', event => {
|
|
174
|
-
if (
|
|
175
|
-
if (event.code === 'Space') {
|
|
174
|
+
if (core.pressSource() === event.code) {core.release();}
|
|
175
|
+
if (event.code === 'Space') {core.facade()?.scene.keys?.delete?.('Space');}
|
|
176
176
|
}, { capture: true, signal });
|
|
177
|
-
globalThis.addEventListener?.('blur', cancel, { signal });
|
|
178
|
-
document.addEventListener('visibilitychange', () => {if (document.hidden) {cancel();}}, { signal });
|
|
177
|
+
globalThis.addEventListener?.('blur', core.cancel, { signal });
|
|
178
|
+
document.addEventListener('visibilitychange', () => {if (document.hidden) {core.cancel();}}, { signal });
|
|
179
179
|
function frame(scene, mp, local, can) {
|
|
180
|
-
const self = mp.net?.selfId?.();
|
|
181
|
-
can = can && (!hub.held.has(self) || Object.hasOwn(hub.seated, self));
|
|
182
180
|
const status = mp.net?.status?.();
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
if (changed || !can || !connected) {cancel(); queuedJump = false;}
|
|
181
|
+
const changed = core.frame({ scene, link: mp, self: mp.net?.selfId?.(), player: local?.components.Transform,
|
|
182
|
+
online: !status || status.state === 'connected', actors: () => scene.getActors(), getActor: id => scene.getActor(id), mp, local }, can);
|
|
186
183
|
if (changed) {keyboardInput = false;}
|
|
187
|
-
context = { scene, mp, local, can: Boolean(can && connected), self, place: hub.place?.id };
|
|
188
184
|
if (scene.moveInput && input !== scene.moveInput) {
|
|
189
185
|
if (input?.consumeJump === consumeJump) {input.consumeJump = originalJump;}
|
|
190
186
|
input = scene.moveInput; originalJump = input.consumeJump;
|
|
191
187
|
input.consumeJump = consumeJump;
|
|
192
188
|
}
|
|
193
|
-
const
|
|
194
|
-
for (const actor of actors) {
|
|
195
|
-
const item = interaction(actor, hub.place ?? {}, Object.hasOwn(hub.spawned, actor.id));
|
|
196
|
-
if (item) {authored.set(item.id, item);}
|
|
197
|
-
}
|
|
198
|
-
const me = local?.components.Transform;
|
|
199
|
-
const items = (context.can ? hub.prompts ?? [] : []).flatMap(item => {
|
|
200
|
-
const base = authored.get(item.id), actor = base && scene.getActor(base.actor), t = actor?.components.Transform;
|
|
201
|
-
if (!base || !t || hub.hidden.has(actor.id)) {return [];}
|
|
202
|
-
// Stand and Throw are server-selected states of the same actor.
|
|
203
|
-
const op = item.verb === 'Stand' && base.op === 'sit' ? 'stand' : item.verb === 'Throw' && base.op === 'grab' ? 'throw' : base.op;
|
|
204
|
-
const d = op === 'throw' ? 0 : base.op === 'sit' ? footprintDistance(actor, me) : Math.hypot(t.x - me.x, t.y - me.y, t.z - me.z);
|
|
205
|
-
return d <= base.reach ? [{ ...base, ...item, op, t, d }] : [];
|
|
206
|
-
}).sort((a, b) => rank(a) - rank(b) || a.d - b.d || a.id.localeCompare(b.id));
|
|
207
|
-
current = items[0] ?? null;
|
|
208
|
-
if (press && !items.some(item => item.id === press.id && item.verb === press.item.verb && item.hold === press.item.hold)) {cancel();}
|
|
209
|
-
if (press && performance.now() - press.at >= 500) {
|
|
210
|
-
const done = press; press = null; perform(done.item, done.n);
|
|
211
|
-
}
|
|
189
|
+
const items = core.items(), current = core.current();
|
|
212
190
|
const visible = new Set(items.map(item => item.id));
|
|
213
191
|
for (const [id, node] of nodes) {if (!visible.has(id)) {chrome.safeSurface?.(`act-prompt:${id}`, null); geometry.unregister(node); node.remove(); nodes.delete(id);}}
|
|
214
192
|
for (const item of items) {
|
|
@@ -217,7 +195,7 @@ export function makeAct(chrome, grab, talk) {
|
|
|
217
195
|
node = el(root, 'prompt', ''); nodes.set(item.id, node);
|
|
218
196
|
geometry.register(node, { positioned: true });
|
|
219
197
|
chrome.safeSurface?.(`act-prompt:${item.id}`, node, 'control', { transient: true });
|
|
220
|
-
bind(node, () =>
|
|
198
|
+
bind(node, () => core.can() ? node._actItem : null);
|
|
221
199
|
}
|
|
222
200
|
node._actItem = item;
|
|
223
201
|
const label = `${item.verb}${keyboardInput ? ' · E' : ''}`;
|
|
@@ -226,20 +204,16 @@ export function makeAct(chrome, grab, talk) {
|
|
|
226
204
|
if (node.title !== item.verb) {node.title = item.verb;}
|
|
227
205
|
node.style.opacity = item.id === current?.id ? '1' : '.55';
|
|
228
206
|
node.style.borderColor = item.id === current?.id ? '#f2c94c' : 'rgba(255,255,255,.55)';
|
|
229
|
-
const progress =
|
|
207
|
+
const progress = core.progress(item.id);
|
|
230
208
|
node.style.background = progress ? `linear-gradient(90deg, #806521 ${progress * 100}%, rgba(20,16,12,.88) ${progress * 100}%)` : 'rgba(20,16,12,.88)';
|
|
231
209
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
pair.style.display = context.can ? 'block' : 'none';
|
|
235
|
-
act.style.display = jump.style.display = context.can ? 'block' : 'none';
|
|
210
|
+
Object.assign(pairState, core.pairState());
|
|
211
|
+
drawPair();
|
|
236
212
|
chrome.layoutInteractionRail();
|
|
237
213
|
layout(scene, items);
|
|
238
214
|
}
|
|
239
215
|
function consumeJump(...args) {
|
|
240
|
-
|
|
241
|
-
const had = originalJump?.apply(this, args);
|
|
242
|
-
return context?.can && (own || had);
|
|
216
|
+
return core.consumeJump(() => originalJump?.apply(this, args));
|
|
243
217
|
}
|
|
244
218
|
function layout(scene, items) {
|
|
245
219
|
const { w, h } = geometry.view(), inset = geometry.padding(probe);
|
|
@@ -284,7 +258,7 @@ export function makeAct(chrome, grab, talk) {
|
|
|
284
258
|
const at = { left, right: left + r.width, top, bottom: top + r.height };
|
|
285
259
|
// A secondary prompt with nowhere clear yields rather than cover the
|
|
286
260
|
// player; the focused one keeps its projected place.
|
|
287
|
-
box = clearBox(at, placed, { w, h, bounds }, avatar) ?? (item === current ? at : null);
|
|
261
|
+
box = clearBox(at, placed, { w, h, bounds }, avatar) ?? (item === core.current() ? at : null);
|
|
288
262
|
} else {box = placeBox(r.width, r.height, preferred, bounds, obstacles);}
|
|
289
263
|
if (box) {
|
|
290
264
|
Object.assign(node.style, { left: `${box.left}px`, top: `${box.top}px` }); obstacles.push(box);
|
|
@@ -301,9 +275,10 @@ export function makeAct(chrome, grab, talk) {
|
|
|
301
275
|
},
|
|
302
276
|
endLayoutFrame() {if (!sharedGeometry) {geometry.endFrame();}},
|
|
303
277
|
dispose() {
|
|
304
|
-
|
|
278
|
+
core.dispose(); listeners.abort(); geometry.unregister(root);
|
|
305
279
|
if (!sharedGeometry) {geometry.dispose();}
|
|
306
280
|
chrome.interactionRail(null);
|
|
281
|
+
chrome.setActPair?.(null);
|
|
307
282
|
for (const [id] of nodes) {chrome.safeSurface?.(`act-prompt:${id}`, null);}
|
|
308
283
|
root.remove(); chrome.setActMode(false);
|
|
309
284
|
if (input?.consumeJump === consumeJump) {input.consumeJump = originalJump;}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// The DOM-less half of Act (v1.127): which of the server's private offers the
|
|
2
|
+
// player can act on and which one Act takes, press/hold/release/perform, what
|
|
3
|
+
// the Act/Jump pair shows and the queued Jump. `act.js` draws it on the web
|
|
4
|
+
// (prompt chips, keys, layout); a native host drives the same core over its
|
|
5
|
+
// own scene facade.
|
|
6
|
+
//
|
|
7
|
+
// makeActCore({ now, send, state, effects, seq }):
|
|
8
|
+
// now() a millisecond clock (the web passes performance.now)
|
|
9
|
+
// send(message, link) sends `hub-act` / `hub-act-hold` on `link.net`, the
|
|
10
|
+
// link of the frame the press was made in
|
|
11
|
+
// state the hub client state (`state.js` `hub`): place, prompts,
|
|
12
|
+
// held, seated, spawned, hidden
|
|
13
|
+
// effects optional { throw(item, facade, done), grab(item, facade),
|
|
14
|
+
// talk(item, facade) }: the client prediction and panel paths
|
|
15
|
+
// run as an item is performed. A Throw sends when its effect
|
|
16
|
+
// calls `done`, or at once without one.
|
|
17
|
+
// seq the first press nonce (Date.now() * 1000)
|
|
18
|
+
//
|
|
19
|
+
// frame(facade, can), once per frame, with the scene facade:
|
|
20
|
+
// { scene, link, self, player, online, actors(), getActor(id) }
|
|
21
|
+
// scene an identity: another scene cancels any press and queued Jump
|
|
22
|
+
// link the connection's holder, whose `net` (with `send`) is read
|
|
23
|
+
// live, as the web reads its multiplayer object's: another
|
|
24
|
+
// `link.net` is a change too, but a net replaced inside the
|
|
25
|
+
// same link is the link's own business
|
|
26
|
+
// self the local player id
|
|
27
|
+
// player the local player's Transform ({ x, y, z }), or null
|
|
28
|
+
// online the connection is up
|
|
29
|
+
// actors() the scene's actors ({ id, components }); interaction()
|
|
30
|
+
// reads HubAct, HubSeat, HubNpc and a dynamic Body
|
|
31
|
+
// getActor(id) one actor by id, with its Transform
|
|
32
|
+
// Any other facade field is the host's own, handed back to `effects`; the
|
|
33
|
+
// core keeps its own copy of the identities, so a host may reuse one facade.
|
|
34
|
+
import { hub as hubState } from './state.js';
|
|
35
|
+
import { footprintDistance } from './idle.js';
|
|
36
|
+
import { interaction } from '../shared/act.js';
|
|
37
|
+
|
|
38
|
+
export const HOLD_MS = 500;
|
|
39
|
+
// Authored counter verbs (Trade, Stamp, Buy, Play, Sit...) take focus over a
|
|
40
|
+
// nearby loose body or keeper; distance decides only within a rank.
|
|
41
|
+
export const rank = item => item.op === 'talk' || item.op === 'grab' ? 1 : 0;
|
|
42
|
+
|
|
43
|
+
// The offers in reach, focused first: `state.prompts` joined with the scene's
|
|
44
|
+
// authored interactions, nearest within a rank, then by id.
|
|
45
|
+
export function actItems(facade, state, can) {
|
|
46
|
+
const authored = new Map();
|
|
47
|
+
for (const actor of facade.actors()) {
|
|
48
|
+
const item = interaction(actor, state.place ?? {}, Object.hasOwn(state.spawned, actor.id));
|
|
49
|
+
if (item) {authored.set(item.id, item);}
|
|
50
|
+
}
|
|
51
|
+
const me = facade.player;
|
|
52
|
+
return (can ? state.prompts ?? [] : []).flatMap(item => {
|
|
53
|
+
const base = authored.get(item.id), actor = base && facade.getActor(base.actor), t = actor?.components.Transform;
|
|
54
|
+
if (!base || !t || state.hidden.has(actor.id)) {return [];}
|
|
55
|
+
// Stand and Throw are server-selected states of the same actor.
|
|
56
|
+
const op = item.verb === 'Stand' && base.op === 'sit' ? 'stand' : item.verb === 'Throw' && base.op === 'grab' ? 'throw' : base.op;
|
|
57
|
+
const d = op === 'throw' ? 0 : base.op === 'sit' ? footprintDistance(actor, me) : Math.hypot(t.x - me.x, t.y - me.y, t.z - me.z);
|
|
58
|
+
return d <= base.reach ? [{ ...base, ...item, op, t, d }] : [];
|
|
59
|
+
}).sort((a, b) => rank(a) - rank(b) || a.d - b.d || a.id.localeCompare(b.id));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function makeActCore({ now, send, state = hubState, effects = {}, seq = Date.now() * 1000 }) {
|
|
63
|
+
let current = null, context = null, press = null, queuedJump = false, items = [];
|
|
64
|
+
function cancel() {
|
|
65
|
+
if (press) {send({ k: 'hub-act-hold', id: press.id, n: press.n, down: false }, context.link);}
|
|
66
|
+
press = null;
|
|
67
|
+
}
|
|
68
|
+
function perform(item, n) {
|
|
69
|
+
const c = context;
|
|
70
|
+
if (!c?.can || !item) {return;}
|
|
71
|
+
// The existing client prediction/denial paths carry grabs and NPC panels.
|
|
72
|
+
if (item.op === 'throw') {
|
|
73
|
+
const done = () => send({ k: 'hub-act', id: item.id, n }, c.link);
|
|
74
|
+
if (effects.throw) {effects.throw(item, c.facade, done);} else {done();}
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (item.op === 'grab') {effects.grab?.(item, c.facade);}
|
|
78
|
+
if (item.op === 'talk') {effects.talk?.(item, c.facade);}
|
|
79
|
+
send({ k: 'hub-act', id: item.id, n }, c.link);
|
|
80
|
+
}
|
|
81
|
+
function release() {
|
|
82
|
+
if (!press || now() - press.at < HOLD_MS) {cancel(); return;}
|
|
83
|
+
const done = press; press = null; perform(done.item, done.n);
|
|
84
|
+
}
|
|
85
|
+
function start(item, source) {
|
|
86
|
+
if (!context?.can || !item || press) {return;}
|
|
87
|
+
const n = ++seq;
|
|
88
|
+
if (item.hold) {
|
|
89
|
+
press = { id: item.id, n, at: now(), source, item };
|
|
90
|
+
send({ k: 'hub-act-hold', id: item.id, n, down: true }, context.link);
|
|
91
|
+
} else {perform(item, n);}
|
|
92
|
+
}
|
|
93
|
+
// Returns whether the context changed (another scene, connection, player or
|
|
94
|
+
// place), which also drops a host's keyboard-hint state.
|
|
95
|
+
function frame(facade, can) {
|
|
96
|
+
const self = facade.self;
|
|
97
|
+
can = can && (!state.held.has(self) || Object.hasOwn(state.seated, self));
|
|
98
|
+
const { scene, link } = facade;
|
|
99
|
+
const connected = link.net && self && facade.player && facade.online;
|
|
100
|
+
const changed = Boolean(context && (context.scene !== scene || context.link.net !== link.net ||
|
|
101
|
+
context.self !== self || context.place !== state.place?.id));
|
|
102
|
+
if (changed || !can || !connected) {cancel(); queuedJump = false;}
|
|
103
|
+
context = { facade, scene, link, can: Boolean(can && connected), self, place: state.place?.id };
|
|
104
|
+
items = actItems(facade, state, context.can);
|
|
105
|
+
current = items[0] ?? null;
|
|
106
|
+
if (press && !items.some(item => item.id === press.id && item.verb === press.item.verb && item.hold === press.item.hold)) {cancel();}
|
|
107
|
+
if (press && now() - press.at >= HOLD_MS) {
|
|
108
|
+
const done = press; press = null; perform(done.item, done.n);
|
|
109
|
+
}
|
|
110
|
+
return changed;
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
frame, start, release, cancel,
|
|
114
|
+
items: () => items,
|
|
115
|
+
current: () => current,
|
|
116
|
+
can: () => Boolean(context?.can),
|
|
117
|
+
facade: () => context?.facade ?? null,
|
|
118
|
+
// The source ('pointer:<id>', a key code, 'click') of the press in progress.
|
|
119
|
+
pressSource: () => press?.source ?? null,
|
|
120
|
+
// 0..1 of the hold on this item, 0 when it is not being held.
|
|
121
|
+
progress: id => press?.id === id ? Math.min(1, (now() - press.at) / HOLD_MS) : 0,
|
|
122
|
+
// What the Act/Jump pair shows: shown while acting is allowed, Act
|
|
123
|
+
// enabled while something is in reach.
|
|
124
|
+
pairState: () => ({ show: Boolean(context?.can), enabled: Boolean(current) }),
|
|
125
|
+
queueJump() {if (context?.can) {queuedJump = true;}},
|
|
126
|
+
// The movement input's Jump: this pair's queued Jump or the original's.
|
|
127
|
+
consumeJump(original) {
|
|
128
|
+
const own = queuedJump; queuedJump = false;
|
|
129
|
+
const had = original?.();
|
|
130
|
+
return context?.can && (own || had);
|
|
131
|
+
},
|
|
132
|
+
dispose: cancel,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Pure car dynamics, contract v1.160. Heading in radians, signed speed in m/s.
|
|
2
|
+
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
|
|
3
|
+
const toward = (v, target, amount) => v + clamp(target - v, -amount, amount);
|
|
4
|
+
export function carInput(keys, stick) {
|
|
5
|
+
const held = (...codes) => codes.some(code => keys?.has?.(code));
|
|
6
|
+
let forward = Number(held('KeyW', 'ArrowUp')) - Number(held('KeyS', 'ArrowDown'));
|
|
7
|
+
let steer = Number(held('KeyD', 'ArrowRight')) - Number(held('KeyA', 'ArrowLeft'));
|
|
8
|
+
if (!forward && !steer && stick?.active && Math.hypot(stick.x, stick.y) >= 0.15) {
|
|
9
|
+
forward = -stick.y;
|
|
10
|
+
steer = stick.x;
|
|
11
|
+
}
|
|
12
|
+
return { forward: clamp(forward, -1, 1), steer: clamp(steer, -1, 1) };
|
|
13
|
+
}
|
|
14
|
+
export function bumperBlocked(speed, forward, front, back, length) {
|
|
15
|
+
const direction = Math.sign(speed) || Math.sign(forward);
|
|
16
|
+
const hit = direction > 0 ? front : direction < 0 ? back : null;
|
|
17
|
+
return Number.isFinite(hit) && hit >= 0 && hit <= length / 2;
|
|
18
|
+
}
|
|
19
|
+
export function stepCar(state, input, car, dt) {
|
|
20
|
+
dt = Number.isFinite(dt) ? Math.max(0, dt) : 0;
|
|
21
|
+
const forward = clamp(input.forward || 0, -1, 1), steer = clamp(input.steer || 0, -1, 1);
|
|
22
|
+
let speed = clamp(state.speed || 0, -car.reverse, car.speed);
|
|
23
|
+
const target = forward * (forward < 0 ? car.reverse : car.speed);
|
|
24
|
+
if (!forward) {speed = toward(speed, 0, 2 * dt);}
|
|
25
|
+
else if (speed * forward < 0) {
|
|
26
|
+
const braking = Math.min(dt, Math.abs(speed) / car.brake);
|
|
27
|
+
speed = toward(speed, 0, car.brake * braking);
|
|
28
|
+
speed = toward(speed, target, car.accel * (dt - braking));
|
|
29
|
+
} else {speed = toward(speed, target, car.accel * dt);}
|
|
30
|
+
if (bumperBlocked(speed, forward, input.front, input.back, car.length)) {speed = 0;}
|
|
31
|
+
// Steering right lowers the heading, as the walk's right turn lowers its
|
|
32
|
+
// facing: heading 0 runs along +Z, and a right turn swings toward -X.
|
|
33
|
+
const heading = (state.heading || 0) - car.turn * steer * Math.min(1, Math.abs(speed) / 4) * Math.sign(speed) * dt;
|
|
34
|
+
return { ...state, speed, heading };
|
|
35
|
+
}
|