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,374 @@
|
|
|
1
|
+
// v1.158: the dormant five-button picker, expression wheel and local input.
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { register } from 'node:module';
|
|
4
|
+
register(`data:text/javascript,${encodeURIComponent(`
|
|
5
|
+
export async function resolve(specifier, context, next) {
|
|
6
|
+
if (specifier === 'castle-web-sdk') return { url: ${JSON.stringify(new URL('./fixtures/sdk-stub.mjs', import.meta.url).href)}, shortCircuit: true };
|
|
7
|
+
return next(specifier, context);
|
|
8
|
+
}
|
|
9
|
+
`)}`);
|
|
10
|
+
const { makeChrome } = await import('../code/client/chrome.js');
|
|
11
|
+
const { makeEmoteWheel } = await import('../code/client/emoteWheel.js');
|
|
12
|
+
const { EMOTES, expressionChoices, emoteDefinition, makeIdle } = await import('../code/client/idle.js');
|
|
13
|
+
const { hub, clear } = await import('../code/client/state.js');
|
|
14
|
+
const { ACTION_VOICES } = await import('../code/client/soundscapeCues.js');
|
|
15
|
+
const role = { id: 'doctor', emoji: '🩺', label: 'Checkup', motion: 'bow', ms: 3500 };
|
|
16
|
+
const expression = { roleEmotes: [role, { ...role, id: 'baker', label: 'Baking' }] };
|
|
17
|
+
const globalEvents = new Map();
|
|
18
|
+
const frames = new Map();
|
|
19
|
+
let frameId = 0;
|
|
20
|
+
globalThis.requestAnimationFrame = (fn) => { frames.set(++frameId, fn); return frameId; };
|
|
21
|
+
globalThis.cancelAnimationFrame = (id) => frames.delete(id);
|
|
22
|
+
const nextFrame = () => {
|
|
23
|
+
const pending = [...frames.values()]; frames.clear();
|
|
24
|
+
for (const fn of pending) { fn(); }
|
|
25
|
+
};
|
|
26
|
+
globalThis.addEventListener = (type, fn, options) => {
|
|
27
|
+
if (!globalEvents.has(type)) { globalEvents.set(type, new Set()); }
|
|
28
|
+
globalEvents.get(type).add(fn);
|
|
29
|
+
options?.signal?.addEventListener('abort', () => globalEvents.get(type).delete(fn), { once: true });
|
|
30
|
+
};
|
|
31
|
+
const dispatch = (type, extra) => {
|
|
32
|
+
for (const fn of globalEvents.get(type) ?? []) { fn({ preventDefault() {}, stopPropagation() {}, ...extra }); }
|
|
33
|
+
};
|
|
34
|
+
const descendants = (node) => [node, ...node.children.flatMap(descendants)];
|
|
35
|
+
let n = 0;
|
|
36
|
+
function test(name, fn) { try { fn(); n += 1; } catch (error) { console.error(name); throw error; } }
|
|
37
|
+
function fakeDom(view) {
|
|
38
|
+
const made = [];
|
|
39
|
+
function node(tag) {
|
|
40
|
+
const listeners = {};
|
|
41
|
+
const self = {
|
|
42
|
+
tag,
|
|
43
|
+
children: [],
|
|
44
|
+
parent: null,
|
|
45
|
+
dataset: {},
|
|
46
|
+
attrs: {},
|
|
47
|
+
style: {},
|
|
48
|
+
// Every value a style was given, in order.
|
|
49
|
+
wrote: [],
|
|
50
|
+
textContent: '',
|
|
51
|
+
innerHTML: '',
|
|
52
|
+
appendChild(child) {
|
|
53
|
+
child.parent = self;
|
|
54
|
+
self.children.push(child);
|
|
55
|
+
return child;
|
|
56
|
+
},
|
|
57
|
+
insertBefore(child, before) {
|
|
58
|
+
child.parent = self;
|
|
59
|
+
const prior = self.children.indexOf(child);
|
|
60
|
+
if (prior >= 0) {self.children.splice(prior, 1);}
|
|
61
|
+
const at = self.children.indexOf(before);
|
|
62
|
+
self.children.splice(at < 0 ? self.children.length : at, 0, child);
|
|
63
|
+
return child;
|
|
64
|
+
},
|
|
65
|
+
remove() { if (self.parent) { self.parent.children = self.parent.children.filter((c) => c !== self); } },
|
|
66
|
+
contains(other) { return self === other || self.children.some((child) => child.contains(other)); },
|
|
67
|
+
replaceChildren() {
|
|
68
|
+
self.children = [];
|
|
69
|
+
},
|
|
70
|
+
addEventListener: (type, fn) => (listeners[type] = fn),
|
|
71
|
+
removeEventListener() {},
|
|
72
|
+
setAttribute: (key, value) => (self.attrs[key] = String(value)),
|
|
73
|
+
getAttribute: (key) => self.attrs[key] ?? null,
|
|
74
|
+
fire: (type, extra = {}) => listeners[type]?.({ target: self, stopPropagation() {}, preventDefault() {}, ...extra }),
|
|
75
|
+
hears: (type) => typeof listeners[type] === 'function',
|
|
76
|
+
focus() {},
|
|
77
|
+
blur() {},
|
|
78
|
+
getBoundingClientRect: () => ({ left: 0, right: 0, top: 0, bottom: 0, width: 0, height: 0 }),
|
|
79
|
+
offsetWidth: 100,
|
|
80
|
+
offsetHeight: 40,
|
|
81
|
+
offsetLeft: 0,
|
|
82
|
+
offsetTop: 0,
|
|
83
|
+
};
|
|
84
|
+
self.style = new Proxy(
|
|
85
|
+
{},
|
|
86
|
+
{
|
|
87
|
+
set(target, key, value) {
|
|
88
|
+
if (view.dvh === false && String(value).includes('dvh')) {return true;}
|
|
89
|
+
target[key] = String(value);
|
|
90
|
+
self.wrote.push([key, String(value)]);
|
|
91
|
+
return true;
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
);
|
|
95
|
+
made.push(self);
|
|
96
|
+
return self;
|
|
97
|
+
}
|
|
98
|
+
const body = node('body');
|
|
99
|
+
globalThis.document = { body, createElement: node, activeElement: null };
|
|
100
|
+
globalThis.window = { innerWidth: view.w, innerHeight: view.h };
|
|
101
|
+
return { made };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
test('plain places render exactly the original five-button picker and create no wheel', () => {
|
|
106
|
+
const dom = fakeDom({ w: 360, h: 640 });
|
|
107
|
+
const chrome = makeChrome({ onBack() {}, onAvatar() {}, avatarCount: 4 });
|
|
108
|
+
const picked = []; chrome.onEmote((id) => picked.push(id));
|
|
109
|
+
chrome.setEmotes(EMOTES);
|
|
110
|
+
assert.equal(dom.made.some((node) => node.attrs['aria-label'] === 'Emotes'), false);
|
|
111
|
+
const trigger = dom.made.find((node) => node.attrs['aria-label'] === 'Emote');
|
|
112
|
+
trigger.fire('pointerdown');
|
|
113
|
+
const wave = dom.made.find((node) => node.attrs['aria-label'] === 'wave');
|
|
114
|
+
assert.deepEqual(wave.parent.children.map((node) => node.attrs['aria-label']), ['wave', 'dance', 'cheer', 'bow', 'spin']);
|
|
115
|
+
assert.equal(wave.parent.style.display, 'flex');
|
|
116
|
+
wave.fire('pointerdown'); assert.deepEqual(picked, ['wave']);
|
|
117
|
+
assert.equal(wave.parent.style.display, 'none'); chrome.dispose();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
for (const view of [{ w: 360, h: 640 }, { w: 640, h: 360 }]) {
|
|
121
|
+
test(`wheel at ${view.w}x${view.h}: basics, grants, original extras, dismissal and keyboard picks`, () => {
|
|
122
|
+
const dom = fakeDom(view);
|
|
123
|
+
const chrome = makeChrome({ onBack() {}, onAvatar() {}, avatarCount: 4 });
|
|
124
|
+
const picked = []; chrome.onEmote((...args) => picked.push(args));
|
|
125
|
+
const choices = expressionChoices(expression, ['doctor']);
|
|
126
|
+
chrome.setEmotes(EMOTES, choices);
|
|
127
|
+
const sheet = dom.made.find((node) => node.attrs['aria-label'] === 'Emotes');
|
|
128
|
+
const trigger = dom.made.find((node) => node.attrs['aria-label'] === 'Emote');
|
|
129
|
+
trigger.fire('pointerdown');
|
|
130
|
+
const slots = () => descendants(sheet).filter((node) => node.dataset.emote);
|
|
131
|
+
assert.deepEqual(slots().map((node) => node.dataset.emote), ['wave', 'sit', 'sleep', 'eat', 'dance', 'cry', 'laugh', 'point']);
|
|
132
|
+
assert.ok(slots().every((node) => parseFloat(node.style.width) >= 44 && parseFloat(node.style.height) >= 44 && node.attrs['aria-label']));
|
|
133
|
+
const boxes = slots().map((node) => ({ left: parseFloat(node.style.left), top: parseFloat(node.style.top), right: parseFloat(node.style.left) + 56, bottom: parseFloat(node.style.top) + 48 }));
|
|
134
|
+
for (const [i, a] of boxes.entries()) { for (const b of boxes.slice(i + 1)) { assert.ok(a.right <= b.left || b.right <= a.left || a.bottom <= b.top || b.bottom <= a.top); } }
|
|
135
|
+
assert.ok(parseFloat(sheet.style.left) >= 12 && parseFloat(sheet.style.left) + 240 <= view.w - 12);
|
|
136
|
+
assert.ok(parseFloat(sheet.style.top) >= 64 && parseFloat(sheet.style.top) + parseFloat(sheet.style.maxHeight) <= view.h - 12);
|
|
137
|
+
slots()[1].fire('click'); assert.deepEqual(picked, [['sit', true]]); assert.equal(sheet.style.display, 'none');
|
|
138
|
+
trigger.fire('click', { detail: 0 }); assert.equal(sheet.style.display, 'block');
|
|
139
|
+
descendants(sheet).find((node) => node.attrs['aria-label'] === 'More emotes').fire('click');
|
|
140
|
+
assert.deepEqual(slots().map((node) => node.dataset.emote), ['cheer', 'bow', 'spin', 'doctor']);
|
|
141
|
+
assert.equal(slots().at(-1).children[0].textContent, role.emoji);
|
|
142
|
+
assert.equal(slots().at(-1).attrs['aria-label'], role.label);
|
|
143
|
+
slots().at(-1).fire('click'); assert.deepEqual(picked.at(-1), ['doctor', false]);
|
|
144
|
+
trigger.fire('pointerdown'); dispatch('keydown', { key: 'Escape' }); assert.equal(sheet.style.display, 'none');
|
|
145
|
+
trigger.fire('pointerdown'); dispatch('pointerdown', { target: document.body }); assert.equal(sheet.style.display, 'none');
|
|
146
|
+
trigger.fire('pointerdown'); dispatch('pointerdown', { target: sheet }); assert.equal(sheet.style.display, 'block');
|
|
147
|
+
dispatch('pointerdown', { target: trigger }); trigger.fire('pointerdown'); assert.equal(sheet.style.display, 'none');
|
|
148
|
+
chrome.setEmotes(null); assert.equal(trigger.style.display, 'none');
|
|
149
|
+
chrome.dispose();
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
test('twelve grants are reachable over bounded pages, with safe geometry clear of phone chrome', () => {
|
|
154
|
+
fakeDom({ w: 360, h: 640 });
|
|
155
|
+
const el = (tag, styles, parent) => { const node = document.createElement(tag); Object.assign(node.style, styles); parent.appendChild(node); return node; };
|
|
156
|
+
const roles = Array.from({ length: 12 }, (_, i) => ({ ...role, id: `role-${i}` }));
|
|
157
|
+
const choices = expressionChoices({ roleEmotes: roles }, roles.map((entry) => entry.id));
|
|
158
|
+
for (const [view, bands] of [
|
|
159
|
+
[{ w: 360, h: 640, insets: { top: 24, right: 0, bottom: 24, left: 0 } }, [{ left: 70, right: 350, top: 10, bottom: 150 }, { left: 270, right: 350, top: 440, bottom: 620 }]],
|
|
160
|
+
[{ w: 640, h: 360, insets: { top: 0, right: 20, bottom: 0, left: 20 } }, [{ left: 500, right: 628, top: 64, bottom: 348 }, { left: 20, right: 160, top: 64, bottom: 348 }]],
|
|
161
|
+
]) {
|
|
162
|
+
const wheel = makeEmoteWheel({ root: document.body, el, view: () => view, bands: () => bands, pick() {}, close() {} });
|
|
163
|
+
wheel.set(choices); wheel.open(true);
|
|
164
|
+
const placed = { left: parseFloat(wheel.node.style.left), top: parseFloat(wheel.node.style.top) };
|
|
165
|
+
placed.right = placed.left + 240; placed.bottom = placed.top + Math.min(284, parseFloat(wheel.node.style.maxHeight));
|
|
166
|
+
for (const band of bands) { assert.ok(placed.right <= band.left || band.right <= placed.left || placed.bottom <= band.top || band.bottom <= placed.top, JSON.stringify({ placed, band })); }
|
|
167
|
+
descendants(wheel.node).find((node) => node.attrs['aria-label'] === 'More emotes').fire('click');
|
|
168
|
+
const seen = [];
|
|
169
|
+
for (let i = 0; i < 3; i += 1) {
|
|
170
|
+
seen.push(...descendants(wheel.node).filter((node) => node.dataset.emote).map((node) => node.dataset.emote));
|
|
171
|
+
descendants(wheel.node).find((node) => node.attrs['aria-label'] === 'Next emotes').fire('click');
|
|
172
|
+
}
|
|
173
|
+
assert.deepEqual(seen, ['cheer', 'bow', 'spin', ...roles.map((entry) => entry.id)]);
|
|
174
|
+
wheel.dispose();
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
const shortControls = [
|
|
179
|
+
{ left: 462, top: 199, right: 562, bottom: 237 }, // Character
|
|
180
|
+
{ left: 518, top: 148, right: 562, bottom: 192 }, // Emote
|
|
181
|
+
{ left: 518, top: 98, right: 562, bottom: 142 }, // Quick chat
|
|
182
|
+
{ left: 10, top: 68, right: 110, bottom: 106 }, // People
|
|
183
|
+
];
|
|
184
|
+
const intersects = (a, b) => a.left < b.right && a.right > b.left && a.top < b.bottom && a.bottom > b.top;
|
|
185
|
+
function visibleSlots(sheet, view, controls) {
|
|
186
|
+
const left = parseFloat(sheet.style.left), top = parseFloat(sheet.style.top);
|
|
187
|
+
const visible = { left, top, right: left + parseFloat(sheet.style.width), bottom: top + Math.min(parseFloat(sheet.style.height), parseFloat(sheet.style.maxHeight)) };
|
|
188
|
+
assert.ok(parseFloat(sheet.style.height) <= parseFloat(sheet.style.maxHeight), 'no scrolling is needed to reach slots or navigation');
|
|
189
|
+
const slots = descendants(sheet).filter((node) => node.dataset.emote);
|
|
190
|
+
const boxes = slots.map((node) => {
|
|
191
|
+
const width = parseFloat(node.style.width), height = parseFloat(node.style.height);
|
|
192
|
+
assert.ok(width >= 44 && height >= 44, `${node.dataset.emote} is a full touch target`);
|
|
193
|
+
const x = left + 4 + parseFloat(node.style.left), y = top + 4 + parseFloat(node.style.top);
|
|
194
|
+
const box = { left: x, top: y, right: x + width, bottom: y + height };
|
|
195
|
+
assert.ok(box.left >= visible.left && box.right <= visible.right && box.top >= visible.top && box.bottom <= visible.bottom, JSON.stringify({ box, visible }));
|
|
196
|
+
assert.ok(box.left >= 0 && box.right <= view.w && box.top >= 0 && box.bottom <= view.h);
|
|
197
|
+
for (const control of controls) { assert.equal(intersects(box, control), false, JSON.stringify({ box, control })); }
|
|
198
|
+
return box;
|
|
199
|
+
});
|
|
200
|
+
for (const [i, box] of boxes.entries()) { for (const other of boxes.slice(i + 1)) { assert.equal(intersects(box, other), false); } }
|
|
201
|
+
const nav = sheet.children[1];
|
|
202
|
+
assert.ok(parseFloat(nav.style.height) >= 44);
|
|
203
|
+
for (const node of nav.children) { assert.ok(parseFloat(node.style.minWidth) >= 44 && parseFloat(node.style.minHeight) >= 44); }
|
|
204
|
+
assert.ok(top + 4 + parseFloat(sheet.children[0].style.height) + 44 <= visible.bottom, 'navigation is fully visible');
|
|
205
|
+
for (const control of controls) { assert.equal(intersects(visible, control), false, 'sheet clears controls'); }
|
|
206
|
+
return slots.map((node) => node.dataset.emote);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
test('574x246 grid fits all eight basics and all extras, and resize restores the portrait ring', () => {
|
|
210
|
+
const view = { w: 382, h: 700, insets: { top: 0, right: 0, bottom: 0, left: 0 } };
|
|
211
|
+
fakeDom(view);
|
|
212
|
+
const el = (tag, styles, parent) => { const node = document.createElement(tag); Object.assign(node.style, styles); parent.appendChild(node); return node; };
|
|
213
|
+
const roles = Array.from({ length: 12 }, (_, i) => ({ ...role, id: `role-${i}` }));
|
|
214
|
+
const choices = expressionChoices({ roleEmotes: roles }, roles.map((entry) => entry.id));
|
|
215
|
+
const wheel = makeEmoteWheel({ root: document.body, el, view: () => view, bands: () => view.h === 246 ? shortControls : [], pick() {}, close() {} });
|
|
216
|
+
wheel.set(choices); wheel.open(true);
|
|
217
|
+
assert.deepEqual(visibleSlots(wheel.node, view, []), choices.basics.map(([id]) => id));
|
|
218
|
+
assert.equal(wheel.node.children[0].style.height, '232px', 'portrait keeps the ring');
|
|
219
|
+
Object.assign(view, { w: 574, h: 246 }); dispatch('resize'); nextFrame();
|
|
220
|
+
assert.deepEqual(visibleSlots(wheel.node, view, shortControls), choices.basics.map(([id]) => id));
|
|
221
|
+
const slots = descendants(wheel.node).filter((node) => node.dataset.emote);
|
|
222
|
+
assert.equal(new Set(slots.map((node) => node.style.left)).size, 4);
|
|
223
|
+
assert.equal(new Set(slots.map((node) => node.style.top)).size, 2);
|
|
224
|
+
descendants(wheel.node).find((node) => node.attrs['aria-label'] === 'More emotes').fire('click');
|
|
225
|
+
const seen = [];
|
|
226
|
+
for (let i = 0; i < 3; i += 1) {
|
|
227
|
+
seen.push(...visibleSlots(wheel.node, view, shortControls));
|
|
228
|
+
descendants(wheel.node).find((node) => node.attrs['aria-label'] === 'Next emotes').fire('click');
|
|
229
|
+
}
|
|
230
|
+
assert.deepEqual(seen, choices.more.map(([id]) => id));
|
|
231
|
+
descendants(wheel.node).find((node) => node.attrs['aria-label'] === 'Basic emotes').fire('click');
|
|
232
|
+
Object.assign(view, { w: 382, h: 700 }); dispatch('orientationchange'); nextFrame();
|
|
233
|
+
assert.equal(wheel.node.children[0].style.height, '232px');
|
|
234
|
+
visibleSlots(wheel.node, view, []);
|
|
235
|
+
wheel.dispose();
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
test('safe-inset wheel redraws after the delayed viewport refresh and settles without DOM changes', () => {
|
|
239
|
+
const view = { w: 382, h: 700 };
|
|
240
|
+
const dom = fakeDom(view);
|
|
241
|
+
window.addEventListener = globalThis.addEventListener;
|
|
242
|
+
window.removeEventListener = (type, fn) => globalEvents.get(type)?.delete(fn);
|
|
243
|
+
const chrome = makeChrome({ onBack() {}, onAvatar() {}, avatarCount: 4, safeInsets: true });
|
|
244
|
+
const choices = expressionChoices(expression, []);
|
|
245
|
+
chrome.setEmotes(EMOTES, choices);
|
|
246
|
+
const sheet = dom.made.find((node) => node.attrs['aria-label'] === 'Emotes');
|
|
247
|
+
const trigger = dom.made.find((node) => node.attrs['aria-label'] === 'Emote');
|
|
248
|
+
trigger.fire('pointerdown');
|
|
249
|
+
assert.equal(sheet.children[0].style.height, '232px', 'portrait starts as a ring');
|
|
250
|
+
Object.assign(view, { w: 574, h: 246 });
|
|
251
|
+
Object.assign(window, { innerWidth: view.w, innerHeight: view.h });
|
|
252
|
+
dispatch('resize'); dispatch('orientationchange');
|
|
253
|
+
nextFrame();
|
|
254
|
+
assert.equal(sheet.children[0].style.height, '232px', 'the next frame still sees the cached portrait view');
|
|
255
|
+
chrome.flushSafeInsets();
|
|
256
|
+
assert.equal(sheet.children[0].style.height, '96px', 'safe-layout refresh switches to the compact grid');
|
|
257
|
+
assert.deepEqual(visibleSlots(sheet, view, []), choices.basics.map(([id]) => id));
|
|
258
|
+
const slots = descendants(sheet).filter((node) => node.dataset.emote);
|
|
259
|
+
assert.equal(new Set(slots.map((node) => node.style.left)).size, 4);
|
|
260
|
+
assert.equal(new Set(slots.map((node) => node.style.top)).size, 2);
|
|
261
|
+
const body = sheet.children[0], writes = sheet.wrote.length;
|
|
262
|
+
chrome.flushSafeInsets(); chrome.flushSafeInsets();
|
|
263
|
+
assert.equal(sheet.children[0], body, 'repeated layout callbacks keep the same DOM');
|
|
264
|
+
assert.equal(sheet.wrote.length, writes, 'repeated callbacks do not rewrite styles');
|
|
265
|
+
dispatch('resize'); trigger.fire('pointerdown');
|
|
266
|
+
const closedWrites = sheet.wrote.length;
|
|
267
|
+
nextFrame(); chrome.flushSafeInsets();
|
|
268
|
+
assert.equal(sheet.style.display, 'none');
|
|
269
|
+
assert.equal(sheet.children[0], body, 'a closed wheel skips queued and refresh draws');
|
|
270
|
+
assert.equal(sheet.wrote.length, closedWrites);
|
|
271
|
+
trigger.fire('pointerdown'); dispatch('resize');
|
|
272
|
+
chrome.dispose();
|
|
273
|
+
assert.equal(frames.size, 0, 'disposing cancels a pending resize frame');
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
test('short wheel reduces the top margin when HUD bands leave too little space below 64 px', () => {
|
|
277
|
+
const view = { w: 574, h: 246, insets: { top: 12, right: 0, bottom: 0, left: 0 } };
|
|
278
|
+
fakeDom(view);
|
|
279
|
+
const el = (tag, styles, parent) => { const node = document.createElement(tag); Object.assign(node.style, styles); parent.appendChild(node); return node; };
|
|
280
|
+
const controls = [...shortControls, { left: 0, right: 574, top: 176, bottom: 246 }];
|
|
281
|
+
const wheel = makeEmoteWheel({ root: document.body, el, view: () => view, bands: () => controls, pick() {}, close() {} });
|
|
282
|
+
wheel.set(expressionChoices(expression, [])); wheel.open(true);
|
|
283
|
+
visibleSlots(wheel.node, view, controls);
|
|
284
|
+
assert.ok(parseFloat(wheel.node.style.top) < 64 && parseFloat(wheel.node.style.top) >= view.insets.top);
|
|
285
|
+
wheel.dispose();
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
test('More reduces to one row per page when HUD space contracts', () => {
|
|
289
|
+
const view = { w: 574, h: 246, insets: { top: 0, right: 0, bottom: 0, left: 0 } };
|
|
290
|
+
fakeDom(view);
|
|
291
|
+
const el = (tag, styles, parent) => { const node = document.createElement(tag); Object.assign(node.style, styles); parent.appendChild(node); return node; };
|
|
292
|
+
const controls = [...shortControls];
|
|
293
|
+
const roles = Array.from({ length: 12 }, (_, i) => ({ ...role, id: `role-${i}` }));
|
|
294
|
+
const choices = expressionChoices({ roleEmotes: roles }, roles.map((entry) => entry.id));
|
|
295
|
+
const wheel = makeEmoteWheel({ root: document.body, el, view: () => view, bands: () => controls, pick() {}, close() {} });
|
|
296
|
+
wheel.set(choices); wheel.open(true);
|
|
297
|
+
descendants(wheel.node).find((node) => node.attrs['aria-label'] === 'More emotes').fire('click');
|
|
298
|
+
controls.push({ left: 0, right: 574, top: 118, bottom: 246 }); dispatch('resize'); nextFrame();
|
|
299
|
+
const seen = [];
|
|
300
|
+
for (let i = 0; i < 4; i += 1) {
|
|
301
|
+
const slots = visibleSlots(wheel.node, view, controls);
|
|
302
|
+
assert.ok(slots.length <= 4);
|
|
303
|
+
seen.push(...slots);
|
|
304
|
+
descendants(wheel.node).find((node) => node.attrs['aria-label'] === 'Next emotes').fire('click');
|
|
305
|
+
}
|
|
306
|
+
assert.deepEqual(seen, choices.more.map(([id]) => id));
|
|
307
|
+
wheel.dispose();
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
test('client sends ground action, resolves remote roles and stands on all movement inputs', () => {
|
|
311
|
+
const sent = []; let pick, press;
|
|
312
|
+
const chrome = { onEmote(fn) { pick = fn; }, onSit(fn) { press = fn; }, setEmotes() {}, sitPrompt() {} };
|
|
313
|
+
const local = { id: 'local', components: { Transform: { x: 10, y: 0.85, z: 10 } } };
|
|
314
|
+
const scene = { keys: new Set(), moveInput: { consumeJump: () => true }, allActors: () => [], getActor: () => null };
|
|
315
|
+
const mp = { net: { selfId: () => 'self', send: (data) => sent.push(data) } };
|
|
316
|
+
const frame = (idle) => idle.frame(scene, mp, local, true, 'main');
|
|
317
|
+
clear(); hub.place = { idle: { emotes: true, expression } }; hub.roleEmotes = ['doctor'];
|
|
318
|
+
let idle = makeIdle(chrome);
|
|
319
|
+
pick('sit', true); frame(idle); assert.deepEqual(sent.pop(), { k: 'hub-sit-here' });
|
|
320
|
+
pick('doctor'); frame(idle); assert.deepEqual(sent.pop(), { k: 'hub-emote', id: 'doctor' });
|
|
321
|
+
pick('baker'); frame(idle); assert.equal(sent.length, 0);
|
|
322
|
+
assert.equal(emoteDefinition('baker').motion, 'bow', 'remote roles resolve even without a local grant');
|
|
323
|
+
assert.equal(emoteDefinition('doctor').emoji, role.emoji);
|
|
324
|
+
for (const input of [() => scene.keys.add('KeyW'), () => scene.keys.add('ArrowLeft'), () => scene.keys.add('Space'), () => { scene.moveInput.active = true; scene.moveInput.x = 0.5; }, () => scene.moveInput.consumeJump(), () => press()]) {
|
|
325
|
+
idle = makeIdle(chrome); frame(idle); hub.seated = { self: 'ground' }; input(); frame(idle);
|
|
326
|
+
assert.deepEqual(sent.pop(), { k: 'hub-stand' });
|
|
327
|
+
hub.seated = {}; scene.keys.clear(); scene.moveInput.active = false;
|
|
328
|
+
}
|
|
329
|
+
hub.place = { idle: { emotes: true, expression: { roleEmotes: [{ ...role, id: 'sit' }] } } }; hub.roleEmotes = ['sit'];
|
|
330
|
+
pick('sit'); frame(idle); assert.deepEqual(sent.pop(), { k: 'hub-emote', id: 'sit' });
|
|
331
|
+
pick('sit', true); frame(idle); assert.deepEqual(sent.pop(), { k: 'hub-sit-here' });
|
|
332
|
+
hub.place = { idle: { emotes: true } }; frame(idle);
|
|
333
|
+
assert.equal(emoteDefinition('doctor'), null); assert.equal(emoteDefinition('sleep'), null);
|
|
334
|
+
pick('sleep'); frame(idle); assert.equal(sent.length, 0);
|
|
335
|
+
for (const [id, reuse] of Object.entries({ sleep: 'bow', eat: 'wave', cry: 'bow', laugh: 'cheer', point: 'wave' })) { assert.equal(ACTION_VOICES[id], ACTION_VOICES[reuse]); }
|
|
336
|
+
clear(); assert.deepEqual(hub.roleEmotes, []);
|
|
337
|
+
});
|
|
338
|
+
test('sit-here retries every 400 ms, stops on confirmation or timeout, and cancels on any movement', () => {
|
|
339
|
+
const realNow = performance.now;
|
|
340
|
+
let now = 0;
|
|
341
|
+
performance.now = () => now;
|
|
342
|
+
const sent = []; let pick;
|
|
343
|
+
const local = { components: { Transform: {} } };
|
|
344
|
+
const mp = { net: { selfId: () => 'self', send: (data) => sent.push([now, data]) } };
|
|
345
|
+
const scene = { keys: new Set(), moveInput: { consumeJump: () => true }, getActor: () => null };
|
|
346
|
+
const chrome = { onEmote(fn) { pick = fn; }, setEmotes() {}, sitPrompt() {} };
|
|
347
|
+
const frame = (idle, ms) => { now = ms; idle.frame(scene, mp, local, true, 'main'); };
|
|
348
|
+
clear(); hub.place = { idle: { emotes: true, expression } };
|
|
349
|
+
try {
|
|
350
|
+
let idle = makeIdle(chrome);
|
|
351
|
+
pick('sit', true); frame(idle, 0); frame(idle, 399); frame(idle, 400); frame(idle, 800); frame(idle, 1200); frame(idle, 1600); frame(idle, 2000);
|
|
352
|
+
assert.deepEqual(sent.map(([ms]) => ms), [0, 400, 800, 1200]);
|
|
353
|
+
assert.ok(sent.every(([, data]) => data.k === 'hub-sit-here'));
|
|
354
|
+
sent.length = 0;
|
|
355
|
+
pick('sit', true); frame(idle, 2100); hub.seated = { self: 'ground' }; frame(idle, 2500); hub.seated = {}; frame(idle, 2900);
|
|
356
|
+
assert.deepEqual(sent, [[2100, { k: 'hub-sit-here' }]], 'confirmation ends the request');
|
|
357
|
+
idle.dispose();
|
|
358
|
+
for (const cancel of [() => scene.keys.add('KeyW'), () => scene.keys.add('ArrowLeft'), () => scene.keys.add('Space'), () => { scene.moveInput.active = true; scene.moveInput.x = 0.5; }, () => scene.moveInput.consumeJump()]) {
|
|
359
|
+
sent.length = 0; idle = makeIdle(chrome);
|
|
360
|
+
pick('sit', true); frame(idle, 0); cancel(); frame(idle, 100);
|
|
361
|
+
scene.keys.clear(); scene.moveInput.active = false;
|
|
362
|
+
frame(idle, 400); frame(idle, 800);
|
|
363
|
+
assert.deepEqual(sent, [[0, { k: 'hub-sit-here' }]], 'movement cancels retries even after input ends');
|
|
364
|
+
idle.dispose();
|
|
365
|
+
}
|
|
366
|
+
for (const cancel of [() => idle.release(), () => { hub.place = { idle: { emotes: true } }; }]) {
|
|
367
|
+
sent.length = 0; idle = makeIdle(chrome); hub.place = { idle: { emotes: true, expression } };
|
|
368
|
+
pick('sit', true); frame(idle, 0); cancel(); frame(idle, 100); frame(idle, 400);
|
|
369
|
+
assert.equal(sent.length, 1, 'scene release and leaving expression cancel retries');
|
|
370
|
+
idle.dispose();
|
|
371
|
+
}
|
|
372
|
+
} finally { performance.now = realNow; clear(); }
|
|
373
|
+
});
|
|
374
|
+
console.log(`emote wheel: ${n} tests passed`);
|
|
@@ -57,10 +57,11 @@ const NAME_TAG_Y = 1.25;
|
|
|
57
57
|
const read = (id) => fs.readFileSync(new URL(`../${hatFile(id)}`, import.meta.url), 'utf8');
|
|
58
58
|
|
|
59
59
|
test('the list a server reads is the hats the kit has models of', () => {
|
|
60
|
-
assert.equal(HATS.length,
|
|
61
|
-
assert.equal(new Set(HATS).size,
|
|
62
|
-
assert.deepEqual(Object.keys(HAT_SETS), ['stadium', 'hollow', 'sunny', 'harbour']);
|
|
60
|
+
assert.equal(HATS.length, 24);
|
|
61
|
+
assert.equal(new Set(HATS).size, 24);
|
|
62
|
+
assert.deepEqual(Object.keys(HAT_SETS), ['stadium', 'hollow', 'sunny', 'harbour', 'services', 'neighbourhood']);
|
|
63
63
|
assert.deepEqual([...Gen.HAT_IDS].sort(), [...HATS].sort());
|
|
64
|
+
assert.ok(Object.values(HAT_SETS).every((set) => set.length === 4));
|
|
64
65
|
for (const id of HATS) {
|
|
65
66
|
const kind = hatKind(id);
|
|
66
67
|
assert.equal(hatId(kind), id);
|
|
@@ -121,7 +122,7 @@ test("every hat model is the generator's, small, and fits on a head under its na
|
|
|
121
122
|
assert.ok(process.env.HAT_SIZES || triangles <= 1000, `${id}: ${triangles} triangles`);
|
|
122
123
|
sizes.push(`${id} ${text.length} B, ${model.parts.length} parts, ${triangles} tris`);
|
|
123
124
|
}
|
|
124
|
-
assert.ok(bytes <=
|
|
125
|
+
assert.ok(bytes <= 64000, `all hats ${bytes} bytes`);
|
|
125
126
|
if (process.env.HAT_SIZES) console.log(`${sizes.join('\n')}\nall ${bytes} B`);
|
|
126
127
|
});
|
|
127
128
|
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
// Tests for the host's Go (code/client/hostGo.js and its wiring in
|
|
2
|
+
// code/systems/hub.js, contract v1.155): the host asks the place to take the
|
|
3
|
+
// player through one of its doors (SDK Hub.onGo), and the kit answers it like
|
|
4
|
+
// a fired pad (goHub -> Hub.go). `npm run check` runs this.
|
|
5
|
+
|
|
6
|
+
import assert from 'node:assert/strict';
|
|
7
|
+
import { register } from 'node:module';
|
|
8
|
+
|
|
9
|
+
const sdkStub = `
|
|
10
|
+
export const Hub = globalThis.__goHub;
|
|
11
|
+
export const User = { getCurrent: async () => ({ userId: '101', isAnonymous: false }) };
|
|
12
|
+
export const Multiplayer = { joinHint: async () => null };
|
|
13
|
+
`;
|
|
14
|
+
const packStub = `
|
|
15
|
+
export const loadPack = () => Promise.reject(new Error('no packs here'));
|
|
16
|
+
export const cachedPacks = () => [];
|
|
17
|
+
export const matchesOwn = () => false;
|
|
18
|
+
export const resolveDeckDoor = () => Promise.reject(new Error('no dev decks here'));
|
|
19
|
+
`;
|
|
20
|
+
const mediaStub = 'export const initialMedia = {}; export const playMedia = () => {}; export const stopMedia = () => {};';
|
|
21
|
+
register(
|
|
22
|
+
'data:text/javascript,' +
|
|
23
|
+
encodeURIComponent(`
|
|
24
|
+
import { readFile } from 'node:fs/promises';
|
|
25
|
+
import { fileURLToPath } from 'node:url';
|
|
26
|
+
export async function resolve(specifier, context, next) {
|
|
27
|
+
if (['pxmodel', 'optimize', 'look', 'lookbake'].some((m) => specifier === '@imports/castle.physics-3d/engine3d/' + m)) return { url: ${JSON.stringify(new URL('./fixtures/engine-models-stub.mjs', import.meta.url).href)}, shortCircuit: true };
|
|
28
|
+
if (specifier === '@imports/castle.physics-3d/engine3d/orbitlens.js') return { url: ${JSON.stringify(new URL('../../physics-3d/engine3d/orbitlens.js', import.meta.url).href)}, shortCircuit: true };
|
|
29
|
+
if (specifier === '@imports/castle.real-time/code/client/messages.js') return { url: ${JSON.stringify(new URL('../../real-time/code/client/messages.js', import.meta.url).href)}, shortCircuit: true };
|
|
30
|
+
if (specifier === '@imports/castle.multiplayer-3d/code/client/avatars.js') return { url: 'data:text/javascript,export const dropMissing = () => {};', shortCircuit: true };
|
|
31
|
+
if (specifier === 'castle-web-sdk') return { url: ${JSON.stringify('data:text/javascript,' + encodeURIComponent(sdkStub))}, shortCircuit: true };
|
|
32
|
+
if (specifier.startsWith('@imports/castle.physics-2d/engine/')) return { url: ${JSON.stringify('data:text/javascript,' + encodeURIComponent(mediaStub))}, shortCircuit: true };
|
|
33
|
+
if (specifier === '../client/pack.js') return { url: ${JSON.stringify('data:text/javascript,' + encodeURIComponent(packStub))}, shortCircuit: true };
|
|
34
|
+
return next(specifier, context);
|
|
35
|
+
}
|
|
36
|
+
export async function load(url, context, next) {
|
|
37
|
+
if (url.endsWith('/code/client/hookLayer.js')) {
|
|
38
|
+
const source = await readFile(fileURLToPath(url), 'utf8');
|
|
39
|
+
return { format: 'module', source: source.replaceAll('import.meta.glob(', '(() => ({}))('), shortCircuit: true };
|
|
40
|
+
}
|
|
41
|
+
return next(url, context);
|
|
42
|
+
}`),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const calls = [];
|
|
46
|
+
let goListener = null;
|
|
47
|
+
globalThis.__goHub = {
|
|
48
|
+
go: async (doorId, ...options) => { calls.push(['go', doorId, ...options]); return { status: 'full', url: null, nonce: null }; },
|
|
49
|
+
back: async () => ({ status: 'not_found' }),
|
|
50
|
+
cancel: async () => ({ status: 'ok' }),
|
|
51
|
+
doors: async () => ({ status: 'unavailable', doors: null }),
|
|
52
|
+
onBack: () => () => {},
|
|
53
|
+
onGo: (listener) => { goListener = listener; return () => { goListener = null; }; },
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const { makeHostGo, HOST_GO_WAIT_MS } = await import('../code/client/hostGo.js');
|
|
57
|
+
const { installSystem } = await import('../code/systems/hub.js');
|
|
58
|
+
const HubState = await import('../code/client/state.js');
|
|
59
|
+
|
|
60
|
+
const tick = () => new Promise((resolve) => setTimeout(resolve, 0));
|
|
61
|
+
const flush = async () => { for (let i = 0; i < 6; i += 1) {await tick();} };
|
|
62
|
+
|
|
63
|
+
let n = 0;
|
|
64
|
+
const log = console.log;
|
|
65
|
+
const warn = console.warn;
|
|
66
|
+
console.log = () => {};
|
|
67
|
+
console.warn = () => {};
|
|
68
|
+
async function test(name, fn) {
|
|
69
|
+
try {
|
|
70
|
+
await fn();
|
|
71
|
+
} catch (err) {
|
|
72
|
+
console.log = log;
|
|
73
|
+
console.warn = warn;
|
|
74
|
+
console.error(`not ok: ${name}`);
|
|
75
|
+
throw err;
|
|
76
|
+
}
|
|
77
|
+
n += 1;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const doors = [{ id: 'home-1', title: 'Home' }, { id: 'door-prism', title: 'Prism' }];
|
|
81
|
+
const ready = { settled: true, tripping: false, result: false, doors };
|
|
82
|
+
|
|
83
|
+
// ---- the pure decision ----
|
|
84
|
+
|
|
85
|
+
await test('decide: waits until settled, then takes the latest Go once as a hub-go', () => {
|
|
86
|
+
const warned = [];
|
|
87
|
+
const go = makeHostGo({ warn: (t) => warned.push(t) });
|
|
88
|
+
assert.equal(go.take({ ...ready, now: 0 }), null, 'nothing pending');
|
|
89
|
+
go.offer({ doorId: 'home-1' }, { at: 0, tripping: false });
|
|
90
|
+
go.offer({ doorId: 'door-prism', party: 2 }, { at: 10, tripping: false });
|
|
91
|
+
assert.equal(go.take({ ...ready, now: 20, settled: false }), null, 'not settled: waits');
|
|
92
|
+
assert.equal(go.take({ ...ready, now: 30, result: true }), null, 'a game: waits');
|
|
93
|
+
assert.deepEqual(go.take({ ...ready, now: 40 }),
|
|
94
|
+
{ k: 'hub-go', door: 'door-prism', key: null, place: null, scene: null, title: 'Prism', party: 2 }, 'latest wins; listed title');
|
|
95
|
+
assert.equal(go.take({ ...ready, now: 50 }), null, 'taken once');
|
|
96
|
+
assert.equal(warned.length, 0);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
await test('decide: the host title and owner pass through; party defaults to 1', () => {
|
|
100
|
+
const go = makeHostGo({ warn() {} });
|
|
101
|
+
go.offer({ doorId: 'home-1', title: "Amy's House", owner: '42' }, { at: 0, tripping: false });
|
|
102
|
+
assert.deepEqual(go.take({ ...ready, now: 1 }),
|
|
103
|
+
{ k: 'hub-go', door: 'home-1', key: null, place: null, scene: null, title: "Amy's House", party: 1, owner: '42' });
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
await test('decide: an unknown door (a cabinet is never listed) is dropped with a warning', () => {
|
|
107
|
+
const warned = [];
|
|
108
|
+
const go = makeHostGo({ warn: (t) => warned.push(t) });
|
|
109
|
+
go.offer({ doorId: 'cabinet-1' }, { at: 0, tripping: false });
|
|
110
|
+
assert.equal(go.take({ ...ready, now: 1 }), null);
|
|
111
|
+
assert.equal(go.pending(), null);
|
|
112
|
+
assert.equal(warned.length, 1);
|
|
113
|
+
assert.match(warned[0], /no such door/);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
await test('decide: a Go older than 60 s is dropped', () => {
|
|
117
|
+
const go = makeHostGo({ warn() {} });
|
|
118
|
+
go.offer({ doorId: 'home-1' }, { at: 0, tripping: false });
|
|
119
|
+
assert.equal(go.take({ ...ready, now: HOST_GO_WAIT_MS - 1, settled: false }), null);
|
|
120
|
+
assert.ok(go.pending());
|
|
121
|
+
assert.equal(go.take({ ...ready, now: HOST_GO_WAIT_MS + 1 }), null);
|
|
122
|
+
assert.equal(go.pending(), null);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
await test('decide: a Go during a trip is ignored; a trip starting first drops one waiting', () => {
|
|
126
|
+
const go = makeHostGo({ warn() {} });
|
|
127
|
+
go.offer({ doorId: 'home-1' }, { at: 0, tripping: true });
|
|
128
|
+
assert.equal(go.pending(), null, 'not queued behind the trip');
|
|
129
|
+
go.offer({ doorId: 'home-1' }, { at: 0, tripping: false });
|
|
130
|
+
assert.equal(go.take({ ...ready, now: 1, tripping: true }), null);
|
|
131
|
+
assert.equal(go.pending(), null);
|
|
132
|
+
assert.equal(go.take({ ...ready, now: 2 }), null, 'not after the trip either');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// ---- the system ----
|
|
136
|
+
|
|
137
|
+
function setup({ sdkGo = true } = {}) {
|
|
138
|
+
let system;
|
|
139
|
+
installSystem({ registerSystem: (s) => (system = s) });
|
|
140
|
+
HubState.clear();
|
|
141
|
+
calls.length = 0;
|
|
142
|
+
goListener = null;
|
|
143
|
+
const savedOnGo = globalThis.__goHub.onGo;
|
|
144
|
+
if (!sdkGo) {delete globalThis.__goHub.onGo;}
|
|
145
|
+
const net = { selfId: () => 'p1', send() {}, closed: () => false };
|
|
146
|
+
const actors = new Map([
|
|
147
|
+
['me', { id: 'me', components: { Player: {}, Transform: { x: 0, z: 0 } } }],
|
|
148
|
+
['d1', { id: 'd1', components: { HubDoor: { id: 'home-1', to: 'deck:house' }, Transform: { x: 30, z: 0 } } }],
|
|
149
|
+
['d3', { id: 'd3', components: { HubDoor: { id: 'door-prism', to: 'deck:prism' }, Transform: { x: 0, z: 9 } } }],
|
|
150
|
+
]);
|
|
151
|
+
const scene = {
|
|
152
|
+
persistent: { hubTickets: [] },
|
|
153
|
+
multiplayer: { target: { mode: 'public' }, net, placed: () => true },
|
|
154
|
+
content: null,
|
|
155
|
+
files: {},
|
|
156
|
+
actors,
|
|
157
|
+
actorWith: (c) => [...actors.values()].find((a) => a.components[c]) ?? null,
|
|
158
|
+
getActor: (id) => actors.get(id) ?? null,
|
|
159
|
+
getActors: () => [...actors.values()],
|
|
160
|
+
setContent() {},
|
|
161
|
+
};
|
|
162
|
+
system.chrome = { setCover() {}, showBack() {}, setToast() {} };
|
|
163
|
+
system.scenePath = 'scenes/main.scene';
|
|
164
|
+
system.scene = scene;
|
|
165
|
+
system.helloNet = net;
|
|
166
|
+
HubState.hub.place = { id: 'main', title: 'Town', result: null };
|
|
167
|
+
HubState.hub.doors = doors;
|
|
168
|
+
try {
|
|
169
|
+
system.hookHostGo();
|
|
170
|
+
} finally {
|
|
171
|
+
globalThis.__goHub.onGo = savedOnGo;
|
|
172
|
+
}
|
|
173
|
+
const hooked = Boolean(goListener);
|
|
174
|
+
const local = scene.actorWith('Player');
|
|
175
|
+
const frame = async (times = 2) => {
|
|
176
|
+
for (let i = 0; i < times; i++) {
|
|
177
|
+
system.hostGoFrame(scene, scene.multiplayer, local);
|
|
178
|
+
await flush();
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
return { system, scene, net, frame, hooked };
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const goes = () => calls.filter((c) => c[0] === 'go');
|
|
185
|
+
|
|
186
|
+
await test('system: a Go before settled waits, then goes through the door like a fired pad', async () => {
|
|
187
|
+
const { system, scene, frame, hooked } = setup();
|
|
188
|
+
assert.ok(hooked, 'Hub.onGo is hooked');
|
|
189
|
+
system.helloNet = null; // the first hello has not been sent yet
|
|
190
|
+
goListener({ doorId: 'door-prism', owner: null, title: null, party: 1 });
|
|
191
|
+
await frame();
|
|
192
|
+
assert.equal(goes().length, 0, 'waits for settled');
|
|
193
|
+
system.helloNet = scene.multiplayer.net;
|
|
194
|
+
await frame();
|
|
195
|
+
assert.deepEqual(goes(), [['go', 'door-prism']]);
|
|
196
|
+
assert.ok(system.trip, 'a trip is under way');
|
|
197
|
+
assert.equal(system.trip.target.arrive.door, 'door-prism');
|
|
198
|
+
assert.equal(scene.persistent.hubTickets.at(-1).door, 'door-prism', 'the way back is pushed as for a pad');
|
|
199
|
+
await frame();
|
|
200
|
+
assert.equal(goes().length, 1, 'once');
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
await test('system: an owner rides to Hub.go as ownerUserId', async () => {
|
|
204
|
+
const { system, frame } = setup();
|
|
205
|
+
goListener({ doorId: 'home-1', owner: '42', title: "Amy's House", party: 1 });
|
|
206
|
+
await frame();
|
|
207
|
+
assert.deepEqual(goes(), [['go', 'home-1', { ownerUserId: '42' }]]);
|
|
208
|
+
assert.ok(system.trip);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
await test('system: a Go for a door this place lacks is dropped', async () => {
|
|
212
|
+
const { system, frame } = setup();
|
|
213
|
+
goListener({ doorId: 'door-nope', owner: null, title: null, party: 1 });
|
|
214
|
+
await frame();
|
|
215
|
+
assert.equal(goes().length, 0);
|
|
216
|
+
assert.equal(system.trip, null);
|
|
217
|
+
assert.equal(system.hostGo.pending(), null);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
await test('system: a Go older than 60 s is dropped', async () => {
|
|
221
|
+
const { system, scene, frame } = setup();
|
|
222
|
+
system.helloNet = null;
|
|
223
|
+
goListener({ doorId: 'door-prism', owner: null, title: null, party: 1 });
|
|
224
|
+
await frame(1);
|
|
225
|
+
const real = performance.now;
|
|
226
|
+
const skew = HOST_GO_WAIT_MS + 1000;
|
|
227
|
+
performance.now = () => real.call(performance) + skew;
|
|
228
|
+
try {
|
|
229
|
+
system.helloNet = scene.multiplayer.net;
|
|
230
|
+
await frame();
|
|
231
|
+
} finally {
|
|
232
|
+
performance.now = real;
|
|
233
|
+
}
|
|
234
|
+
assert.equal(goes().length, 0);
|
|
235
|
+
assert.equal(system.trip, null);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
await test('system: a Go during a trip is ignored', async () => {
|
|
239
|
+
const { system, frame } = setup();
|
|
240
|
+
system.trip = { n: 1, target: {} };
|
|
241
|
+
goListener({ doorId: 'door-prism', owner: null, title: null, party: 1 });
|
|
242
|
+
system.trip = null;
|
|
243
|
+
await frame();
|
|
244
|
+
assert.equal(goes().length, 0, 'not queued behind the trip');
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
await test('system: a host that never sends Go changes nothing', async () => {
|
|
248
|
+
const { system, frame } = setup();
|
|
249
|
+
await frame(3);
|
|
250
|
+
assert.equal(goes().length, 0);
|
|
251
|
+
assert.equal(system.trip, null);
|
|
252
|
+
assert.equal(system.hostGo.pending(), null);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
await test('system: an SDK without Hub.onGo does not throw and never goes', async () => {
|
|
256
|
+
const { system, frame, hooked } = setup({ sdkGo: false });
|
|
257
|
+
assert.equal(hooked, false);
|
|
258
|
+
assert.equal(system.hostGo, undefined);
|
|
259
|
+
await frame();
|
|
260
|
+
assert.equal(goes().length, 0);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
console.log = log;
|
|
264
|
+
console.warn = warn;
|
|
265
|
+
console.log(`host go: ${n} tests passed`);
|