castle-web-cli 0.4.236 → 0.4.238
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.d.ts +2 -0
- package/dist/bundle.d.ts +24 -0
- package/dist/bundle.js +447 -4
- package/dist/bundleLatin1.d.ts +6 -0
- package/dist/bundleLatin1.js +333 -0
- package/dist/castle-host/host.d.ts +10 -1
- package/dist/castle-host/host.js +78 -9
- package/dist/castleJson.d.ts +20 -0
- package/dist/castleJson.js +40 -0
- package/dist/deckExports.d.ts +35 -0
- package/dist/deckExports.js +365 -0
- package/dist/importCheckHook.d.ts +1 -0
- package/dist/importCheckHook.js +1 -1
- package/dist/index.js +5 -0
- package/dist/init.js +2 -1
- package/dist/save-deck.js +18 -13
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +47 -0
- package/kits/base/sdk/castle.d.ts +3 -1
- package/kits/base/sdk/castle.js +1 -0
- package/kits/base/sdk/commands.d.ts +25 -1
- package/kits/base/sdk/commands.js +29 -1
- package/kits/base/sdk/hub.d.ts +17 -0
- package/kits/base/sdk/hub.js +33 -9
- package/kits/base/sdk/localCache.d.ts +27 -0
- package/kits/base/sdk/localCache.js +115 -0
- package/kits/base/sdk/localCacheStore.d.ts +15 -0
- package/kits/base/sdk/localCacheStore.js +358 -0
- package/kits/base/sdk/transport.d.ts +1 -0
- package/kits/base/sdk/transport.js +4 -5
- package/kits/hub-game/CLAUDE.md +22 -2
- package/kits/hub-game/castle.json +4 -1
- package/kits/hub-game/code/client/act.js +66 -91
- package/kits/hub-game/code/client/actCore.js +134 -0
- package/kits/hub-game/code/client/car.js +35 -0
- package/kits/hub-game/code/client/chrome.js +207 -381
- package/kits/hub-game/code/client/crowdNames.js +2 -2
- package/kits/hub-game/code/client/emoteWheel.js +109 -0
- package/kits/hub-game/code/client/hats.js +2 -0
- package/kits/hub-game/code/client/hookLayer.js +99 -48
- package/kits/hub-game/code/client/hostGo.js +77 -0
- package/kits/hub-game/code/client/hubControls.js +125 -0
- package/kits/hub-game/code/client/hubEntry.js +187 -0
- package/kits/hub-game/code/client/hudSurface.js +148 -0
- package/kits/hub-game/code/client/hudTree.js +96 -0
- package/kits/hub-game/code/client/idle.js +59 -13
- package/kits/hub-game/code/client/invites.js +13 -4
- package/kits/hub-game/code/client/menuIcons.js +8 -0
- package/kits/hub-game/code/client/noTrips.js +38 -0
- package/kits/hub-game/code/client/qualityEntry.js +6 -1
- package/kits/hub-game/code/client/rehello.js +3 -1
- package/kits/hub-game/code/client/riders.js +26 -0
- package/kits/hub-game/code/client/role.js +79 -0
- package/kits/hub-game/code/client/safeLayout.js +32 -3
- package/kits/hub-game/code/client/sound.js +10 -3
- package/kits/hub-game/code/client/soundscape.js +2 -2
- package/kits/hub-game/code/client/soundscapeAmbience.js +38 -8
- package/kits/hub-game/code/client/soundscapeBaked.js +24 -5
- package/kits/hub-game/code/client/soundscapeCues.js +2 -1
- package/kits/hub-game/code/client/state.js +19 -0
- package/kits/hub-game/code/client/stuck.js +2 -1
- package/kits/hub-game/code/client/talkSurface.js +178 -0
- package/kits/hub-game/code/client/talkTree.js +238 -0
- package/kits/hub-game/code/client/tiers.js +8 -5
- package/kits/hub-game/code/client/uiDom.js +600 -0
- package/kits/hub-game/code/client/uiTree.js +359 -0
- package/kits/hub-game/code/client/vehicle.js +154 -0
- package/kits/hub-game/code/client/wear.js +27 -5
- package/kits/hub-game/code/client/worldLabels.js +3 -2
- package/kits/hub-game/code/client/yours.js +10 -3
- package/kits/hub-game/code/server/actors.js +4 -3
- package/kits/hub-game/code/server/analytics.js +56 -6
- package/kits/hub-game/code/server/decor.js +56 -16
- package/kits/hub-game/code/server/hub.js +258 -46
- package/kits/hub-game/code/server/idle.js +118 -5
- package/kits/hub-game/code/server/manifest.js +46 -4
- package/kits/hub-game/code/server/npcs.js +4 -2
- package/kits/hub-game/code/server/players.js +3 -0
- package/kits/hub-game/code/server/role.js +142 -0
- package/kits/hub-game/code/server/standing.js +6 -4
- package/kits/hub-game/code/server/vehicle.js +126 -0
- package/kits/hub-game/code/shared/car.js +52 -0
- package/kits/hub-game/code/shared/deckFlags.js +34 -0
- package/kits/hub-game/code/shared/deviceClass.js +39 -0
- package/kits/hub-game/code/shared/expression.js +9 -0
- package/kits/hub-game/code/systems/hub.js +300 -85
- package/kits/hub-game/docs/analytics.md +11 -2
- package/kits/hub-game/docs/contract.md +353 -14
- package/kits/hub-game/docs/vehicle-preset.md +132 -0
- package/kits/hub-game/models/hats/baker-cap.pxmodel +89 -0
- package/kits/hub-game/models/hats/chef-toque.pxmodel +60 -0
- package/kits/hub-game/models/hats/delivery-cap.pxmodel +105 -0
- package/kits/hub-game/models/hats/fire-helmet.pxmodel +87 -0
- package/kits/hub-game/models/hats/hard-hat.pxmodel +71 -0
- package/kits/hub-game/models/hats/nurse-cap.pxmodel +61 -0
- package/kits/hub-game/models/hats/police-cap.pxmodel +105 -0
- package/kits/hub-game/models/hats/teacher-beret.pxmodel +52 -0
- package/kits/hub-game/models/role/square/top-apron.pxmodel +109 -0
- package/kits/hub-game/models/role/square/top-cardigan.pxmodel +141 -0
- package/kits/hub-game/models/role/square/top-coat.pxmodel +157 -0
- package/kits/hub-game/models/role/square/top-scrubs.pxmodel +93 -0
- package/kits/hub-game/models/role/square/top-tabard.pxmodel +109 -0
- package/kits/hub-game/models/role/square/top-vest.pxmodel +109 -0
- package/kits/hub-game/models/role/tool-bag.pxmodel +75 -0
- package/kits/hub-game/models/role/tool-bell.pxmodel +71 -0
- package/kits/hub-game/models/role/tool-hose.pxmodel +60 -0
- package/kits/hub-game/models/role/tool-parcel.pxmodel +61 -0
- package/kits/hub-game/models/role/tool-torch.pxmodel +55 -0
- package/kits/hub-game/models/role/tool-tray.pxmodel +75 -0
- package/kits/hub-game/models/role/top-apron.pxmodel +70 -0
- package/kits/hub-game/models/role/top-cardigan.pxmodel +102 -0
- package/kits/hub-game/models/role/top-coat.pxmodel +79 -0
- package/kits/hub-game/models/role/top-scrubs.pxmodel +54 -0
- package/kits/hub-game/models/role/top-tabard.pxmodel +70 -0
- package/kits/hub-game/models/role/top-vest.pxmodel +70 -0
- package/kits/hub-game/package-lock.json +1 -1
- package/kits/hub-game/package.json +1 -1
- package/kits/hub-game/scripts/check.mjs +7 -4
- package/kits/hub-game/scripts/fixtures/car-vectors.json +279 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +2 -1
- package/kits/hub-game/scripts/fixtures/hud-surface.json +670 -0
- package/kits/hub-game/scripts/fixtures/talk-surface.json +3930 -0
- package/kits/hub-game/scripts/gen-hats.mjs +46 -2
- package/kits/hub-game/scripts/gen-role.mjs +80 -0
- package/kits/hub-game/scripts/test-act-core.mjs +167 -0
- package/kits/hub-game/scripts/test-actions-client.mjs +34 -0
- package/kits/hub-game/scripts/test-actors.mjs +48 -0
- package/kits/hub-game/scripts/test-analytics.mjs +99 -5
- package/kits/hub-game/scripts/test-apply-deck.mjs +122 -0
- package/kits/hub-game/scripts/test-back-visibility.mjs +3 -1
- package/kits/hub-game/scripts/test-ballot.mjs +2 -0
- package/kits/hub-game/scripts/test-car.mjs +43 -0
- package/kits/hub-game/scripts/test-decor-client.mjs +2 -1
- package/kits/hub-game/scripts/test-decor.mjs +77 -0
- package/kits/hub-game/scripts/test-device-class.mjs +83 -0
- package/kits/hub-game/scripts/test-emote-wheel.mjs +374 -0
- package/kits/hub-game/scripts/test-hats.mjs +5 -4
- package/kits/hub-game/scripts/test-host-go.mjs +265 -0
- package/kits/hub-game/scripts/test-hub-controls.mjs +108 -0
- package/kits/hub-game/scripts/test-hub-entry.mjs +531 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +75 -0
- package/kits/hub-game/scripts/test-hub-trip.mjs +85 -0
- package/kits/hub-game/scripts/test-hud-clear.mjs +12 -2
- package/kits/hub-game/scripts/test-hud-rate.mjs +6 -2
- package/kits/hub-game/scripts/test-hud-surface.mjs +272 -0
- package/kits/hub-game/scripts/test-idle.mjs +347 -1
- package/kits/hub-game/scripts/test-interest-cells.mjs +8 -1
- package/kits/hub-game/scripts/test-invites-client.mjs +42 -1
- package/kits/hub-game/scripts/test-manifest.mjs +30 -0
- package/kits/hub-game/scripts/test-no-trips.mjs +42 -0
- package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
- package/kits/hub-game/scripts/test-quality.mjs +13 -0
- package/kits/hub-game/scripts/test-rehello.mjs +258 -3
- package/kits/hub-game/scripts/test-resume-pose-server.mjs +203 -0
- package/kits/hub-game/scripts/test-resync.mjs +183 -0
- package/kits/hub-game/scripts/test-role-client.mjs +421 -0
- package/kits/hub-game/scripts/test-role.mjs +350 -0
- package/kits/hub-game/scripts/test-safe-layout.mjs +50 -1
- package/kits/hub-game/scripts/test-soundscape.mjs +124 -7
- package/kits/hub-game/scripts/test-standing.mjs +15 -1
- package/kits/hub-game/scripts/test-talk-surface.mjs +296 -0
- package/kits/hub-game/scripts/test-tiers.mjs +13 -0
- package/kits/hub-game/scripts/test-ui-dom-dom.mjs +96 -0
- package/kits/hub-game/scripts/test-ui-tree.mjs +711 -0
- package/kits/hub-game/scripts/test-vehicle-client.mjs +159 -0
- package/kits/hub-game/scripts/test-vehicle.mjs +135 -0
- package/kits/hub-game/scripts/test-yours.mjs +33 -0
- package/kits/hub-game/tools/hubScene/export.mjs +613 -0
- package/kits/hub-game/tools/hubScene/hubdata.mjs +921 -0
- package/kits/hub-game/tools/hubScene/merge-root.mjs +39 -0
- package/kits/hub-game/tools/hubScene/nodeworld.mjs +227 -0
- package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +798 -0
- package/kits/hub-game/tools/hubScene/test/fixture.json +637 -0
- package/kits/hub-game/tools/hubScene/test/paint-export.mjs +40 -0
- package/kits/hub-game/tools/hubScene/test/upload.test.mjs +655 -0
- package/kits/hub-game/tools/hubScene/upload.mjs +636 -0
- package/kits/hub-game/tools/hubScene/validate-manifest.mjs +291 -0
- package/kits/multiplayer-3d/castle.json +4 -4
- package/kits/multiplayer-3d/code/client/resumeGate.js +30 -2
- package/kits/multiplayer-3d/code/client/steer.js +3 -1
- package/kits/multiplayer-3d/code/systems/multiplayer.js +30 -2
- package/kits/multiplayer-3d/package-lock.json +1 -1
- package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +74 -2
- package/kits/physics-3d/CLAUDE.md +1 -1
- package/kits/physics-3d/behaviors/Player.jsx +37 -27
- package/kits/physics-3d/castle.json +2 -2
- package/kits/physics-3d/docs/engine-geometry-memory.md +23 -0
- package/kits/physics-3d/engine3d/memoryprofile.js +17 -0
- package/kits/physics-3d/engine3d/playerRun.js +6 -1
- package/kits/physics-3d/engine3d/pxmodel.js +6 -1
- package/kits/physics-3d/engine3d/world3d.js +6 -3
- package/kits/physics-3d/package.json +1 -1
- package/kits/physics-3d/play/behaviors/Player.js +40 -28
- package/kits/physics-3d/scripts/test-memory-profile.mjs +237 -0
- package/kits/physics-3d/systems/physics3d.js +5 -2
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/messages.js +5 -0
- package/kits/real-time/code/server/session.js +28 -1
- package/kits/real-time/package-lock.json +1 -1
- package/package.json +5 -4
- package/vendor/three/LICENSE +21 -0
- package/vendor/three/build/three.core.js +58773 -0
- package/vendor/three/build/three.module.js +18251 -0
- package/vendor/three/examples/jsm/controls/OrbitControls.js +1860 -0
- package/vendor/three/examples/jsm/controls/TransformControls.js +1918 -0
- package/vendor/three/examples/jsm/exporters/GLTFExporter.js +3595 -0
- package/vendor/three/examples/jsm/geometries/RoundedBoxGeometry.js +216 -0
- package/vendor/three/examples/jsm/math/MeshSurfaceSampler.js +315 -0
- package/vendor/three/examples/jsm/postprocessing/EffectComposer.js +363 -0
- package/vendor/three/examples/jsm/postprocessing/MaskPass.js +195 -0
- package/vendor/three/examples/jsm/postprocessing/OutputPass.js +139 -0
- package/vendor/three/examples/jsm/postprocessing/Pass.js +191 -0
- package/vendor/three/examples/jsm/postprocessing/RenderPass.js +183 -0
- package/vendor/three/examples/jsm/postprocessing/ShaderPass.js +135 -0
- package/vendor/three/examples/jsm/shaders/CopyShader.js +52 -0
- package/vendor/three/examples/jsm/shaders/OutputShader.js +103 -0
- package/vendor/three/examples/jsm/utils/BufferGeometryUtils.js +1435 -0
- package/vendor/three/package.json +134 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// hookLayer.applyDeck: a host with no castle.json to glob (the native hub's
|
|
2
|
+
// kit bundle) sets `deck` (state.js) from the scene manifest's `deck` block,
|
|
3
|
+
// which the hubScene exporter writes as shared/deckFlags.js of the hub block.
|
|
4
|
+
// Applying that block gives the same `deck` as a page loading the castle.json,
|
|
5
|
+
// from any earlier block; the page's own read is unchanged; and the composed
|
|
6
|
+
// hooks never see applyDeck.
|
|
7
|
+
|
|
8
|
+
import assert from 'node:assert/strict';
|
|
9
|
+
import { register } from 'node:module';
|
|
10
|
+
|
|
11
|
+
register(`data:text/javascript,${encodeURIComponent(`
|
|
12
|
+
import { readFile } from 'node:fs/promises';
|
|
13
|
+
import { fileURLToPath } from 'node:url';
|
|
14
|
+
export async function resolve(specifier, context, next) {
|
|
15
|
+
if (['pxmodel', 'optimize', 'look', 'lookbake'].some((name) => specifier === '@imports/castle.physics-3d/engine3d/' + name)) return { url: ${JSON.stringify(new URL('./fixtures/engine-models-stub.mjs', import.meta.url).href)}, shortCircuit: true };
|
|
16
|
+
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 };
|
|
17
|
+
if (specifier === 'castle-web-sdk') return { url: 'data:text/javascript,export {};', shortCircuit: true };
|
|
18
|
+
if (specifier === '@imports/castle.multiplayer-3d/code/client/avatars.js') return { url: 'data:text/javascript,export const dropMissing = () => {};', shortCircuit: true };
|
|
19
|
+
if (specifier.startsWith('@imports/castle.physics-2d/engine/')) return { url: 'data:text/javascript,export const initialMedia = {}; export const playMedia = () => {}; export const stopMedia = () => {};', shortCircuit: true };
|
|
20
|
+
return next(specifier, context);
|
|
21
|
+
}
|
|
22
|
+
export async function load(url, context, next) {
|
|
23
|
+
if (url.includes('/code/client/hookLayer.js?')) {
|
|
24
|
+
const clean = new URL(url);
|
|
25
|
+
clean.search = '';
|
|
26
|
+
const source = await readFile(fileURLToPath(clean), 'utf8');
|
|
27
|
+
return { format: 'module', source: source.replaceAll('import.meta.glob(', 'globalThis.__rootGlob('), shortCircuit: true };
|
|
28
|
+
}
|
|
29
|
+
return next(url, context);
|
|
30
|
+
}
|
|
31
|
+
`)}`);
|
|
32
|
+
|
|
33
|
+
globalThis.__rootCastleJson = {};
|
|
34
|
+
globalThis.__rootGlob = (pattern) => (pattern === '/castle.json' ? { '/castle.json': globalThis.__rootCastleJson } : {});
|
|
35
|
+
|
|
36
|
+
const State = await import('../code/client/state.js');
|
|
37
|
+
const { DECK_FLAG_KEYS, deckFlags } = await import('../code/shared/deckFlags.js');
|
|
38
|
+
|
|
39
|
+
// Everything applyDeck may write, keys sorted: `deck` but its title and build
|
|
40
|
+
// stamp (the page's own, never the hub block's), and the cue event list.
|
|
41
|
+
const snap = () => {
|
|
42
|
+
const { title, build, ...rest } = State.deck;
|
|
43
|
+
void title;
|
|
44
|
+
void build;
|
|
45
|
+
const sorted = Object.fromEntries(Object.keys(rest).sort().map((k) => [k, rest[k]]));
|
|
46
|
+
return JSON.stringify({ deck: sorted, cueEvents: State.hub.cueEvents });
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const FULL = {
|
|
50
|
+
contract: 1, title: 'Full', arrival: { actor: 'arrival', face: 90 }, npcs: true,
|
|
51
|
+
pongTimeoutMs: 9000, invite: false, places: { main: { invite: true } },
|
|
52
|
+
defaultEnvironment: false, tiers: true, highOnly: true, quality: { low: { decor: 'skip' } },
|
|
53
|
+
safeInsets: true, weakestTier: true, weakestLookBake: true, mergeFarAvatars: true,
|
|
54
|
+
lowActorDistance: true, lowActorBudget: true, companionIdle: true, act: true, cues: true,
|
|
55
|
+
playCards: true, yourGames: true, avatarColors: true, stuck: true, labels: 'near',
|
|
56
|
+
soundscape: { babble: false, steps: { grass: 'soft' }, zones: 'zones', ambience: { wind: 1 }, ui: false, cues: true },
|
|
57
|
+
};
|
|
58
|
+
const TOWN = { contract: 1, title: 'Town', act: true, safeInsets: true, labels: 'near', invite: false, tiers: true, stuck: true };
|
|
59
|
+
const ODD = { act: 'yes', safeInsets: 1, labels: 'all', tiers: false, highOnly: true, quality: { low: {} }, soundscape: true, pongTimeoutMs: -1, places: { main: {} }, invite: true };
|
|
60
|
+
const blocks = { empty: {}, none: undefined, FULL, TOWN, ODD };
|
|
61
|
+
|
|
62
|
+
// The page: each castle.json read at load.
|
|
63
|
+
const page = {};
|
|
64
|
+
let n = 0;
|
|
65
|
+
for (const [name, hub] of Object.entries(blocks)) {
|
|
66
|
+
globalThis.__rootCastleJson = { title: `deck ${name}`, ...(hub === undefined ? {} : { hub }) };
|
|
67
|
+
await import(`../code/client/hookLayer.js?page-${name}-${n++}`);
|
|
68
|
+
assert.equal(State.deck.title, `deck ${name}`);
|
|
69
|
+
page[name] = snap();
|
|
70
|
+
}
|
|
71
|
+
assert.equal(JSON.parse(page.TOWN).deck.act, true);
|
|
72
|
+
assert.equal(JSON.parse(page.TOWN).deck.safeInsets, true);
|
|
73
|
+
assert.equal(JSON.parse(page.TOWN).deck.labels, true);
|
|
74
|
+
assert.equal(JSON.parse(page.FULL).deck.invite, true, 'places.main.invite over the root');
|
|
75
|
+
assert.deepEqual(JSON.parse(page.FULL).cueEvents, []);
|
|
76
|
+
assert.equal(JSON.parse(page.empty).deck.act, undefined);
|
|
77
|
+
assert.equal(page.empty, page.none, 'no hub block reads as an empty one');
|
|
78
|
+
|
|
79
|
+
// The native host: the manifest's block (deckFlags, through JSON as the
|
|
80
|
+
// manifest carries it), applied over whatever an earlier block set.
|
|
81
|
+
const { default: hooks, applyDeck } = await import(`../code/client/hookLayer.js?native-${n++}`);
|
|
82
|
+
assert.equal(hooks.applyDeck, applyDeck, 'hookLayer.applyDeck is the named export');
|
|
83
|
+
assert.ok(!Object.keys(hooks).includes('applyDeck'), 'not enumerable: the composed hooks never copy it');
|
|
84
|
+
const titleNow = State.deck.title;
|
|
85
|
+
for (const [before, prev] of Object.entries(blocks)) {
|
|
86
|
+
for (const [name, hub] of Object.entries(blocks)) {
|
|
87
|
+
applyDeck(JSON.parse(JSON.stringify(deckFlags(prev))));
|
|
88
|
+
const manifestBlock = JSON.parse(JSON.stringify(deckFlags(hub)));
|
|
89
|
+
applyDeck(manifestBlock);
|
|
90
|
+
assert.equal(snap(), page[name], `${name} after ${before}: the page's deck`);
|
|
91
|
+
// The raw hub block gives the same as its flags.
|
|
92
|
+
applyDeck(hub);
|
|
93
|
+
assert.equal(snap(), page[name], `${name} raw`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
assert.equal(State.deck.title, titleNow, 'the title is the page\'s, never the block\'s');
|
|
97
|
+
|
|
98
|
+
// A cue list in use survives a block that keeps cues, and goes with one that drops them.
|
|
99
|
+
applyDeck(deckFlags(FULL));
|
|
100
|
+
State.hub.cueEvents.push({ kind: 'x' });
|
|
101
|
+
applyDeck(deckFlags(FULL));
|
|
102
|
+
assert.equal(State.hub.cueEvents.length, 1);
|
|
103
|
+
applyDeck(deckFlags(TOWN));
|
|
104
|
+
assert.equal(State.hub.cueEvents, null);
|
|
105
|
+
|
|
106
|
+
// deckFlags: only the keys the client reads; invite resolved, so no places.
|
|
107
|
+
assert.deepEqual(Object.keys(deckFlags(FULL)).sort(), [...DECK_FLAG_KEYS].sort());
|
|
108
|
+
assert.deepEqual(deckFlags(TOWN), { invite: false, tiers: true, safeInsets: true, act: true, stuck: true, labels: 'near' });
|
|
109
|
+
assert.deepEqual(deckFlags({}), {});
|
|
110
|
+
assert.deepEqual(deckFlags(null), {});
|
|
111
|
+
assert.deepEqual(deckFlags([]), {});
|
|
112
|
+
assert.equal(deckFlags(ODD).invite, true, 'places.main without invite falls back to the root');
|
|
113
|
+
const copy = deckFlags(FULL);
|
|
114
|
+
copy.soundscape.steps.grass = 'changed';
|
|
115
|
+
assert.equal(FULL.soundscape.steps.grass, 'soft', 'a copy, never the block itself');
|
|
116
|
+
// Garbage in applyDeck reads as no block.
|
|
117
|
+
applyDeck('nonsense');
|
|
118
|
+
assert.equal(snap(), page.empty);
|
|
119
|
+
applyDeck([1, 2]);
|
|
120
|
+
assert.equal(snap(), page.empty);
|
|
121
|
+
|
|
122
|
+
console.log('applyDeck OK');
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import assert from 'node:assert/strict';
|
|
2
2
|
import { readFileSync } from 'node:fs';
|
|
3
3
|
import { kitBackNeeded } from '../code/client/backVisibility.js';
|
|
4
|
+
import { backControl } from '../code/client/hubControls.js';
|
|
4
5
|
|
|
5
6
|
// Exercise the real drawChrome decision, including House visits with no local ticket.
|
|
6
7
|
const source = readFileSync(new URL('../code/systems/hub.js', import.meta.url), 'utf8');
|
|
@@ -12,7 +13,7 @@ const body = source.slice(
|
|
|
12
13
|
start + ' drawChrome(scene, local, now) {'.length,
|
|
13
14
|
backEnd + '\n );'.length,
|
|
14
15
|
);
|
|
15
|
-
const draw = new Function('scene', 'Hub', 'kitBackNeeded', body);
|
|
16
|
+
const draw = new Function('scene', 'Hub', 'kitBackNeeded', 'backControl', body);
|
|
16
17
|
const android = 'Mozilla/5.0 (Linux; Android 12) AppleWebKit/537.36';
|
|
17
18
|
const ios = 'Mozilla/5.0 (iPhone; CPU iPhone OS 18_0 like Mac OS X)';
|
|
18
19
|
const desktop = 'Mozilla/5.0 (Macintosh; Intel Mac OS X)';
|
|
@@ -54,6 +55,7 @@ for (const ua of [android, ios, desktop]) {
|
|
|
54
55
|
scene,
|
|
55
56
|
{ hub: { place: game === null ? null : { result: game } } },
|
|
56
57
|
kitBackNeeded,
|
|
58
|
+
backControl,
|
|
57
59
|
);
|
|
58
60
|
const fallback =
|
|
59
61
|
ua === android &&
|
|
@@ -532,6 +532,8 @@ const FACES = [{ playerId: 'p1' }, { playerId: 'p2', note: 'on the bench' }, { p
|
|
|
532
532
|
'this.ballot = null;',
|
|
533
533
|
'this.carded = false;',
|
|
534
534
|
'this.idle.frame(scene, mp, local, !this.trip && this.pendingEnd === null && !this.talk.talking() && !decorating && !this.carded && !this.actionInput, this.sceneKey);',
|
|
535
|
+
// v1.160: a car's Horn is not offered while a card is up.
|
|
536
|
+
'if (myCar?.horn && !this.trip && this.pendingEnd === null && !this.talk.talking() && !decorating && !this.carded) {',
|
|
535
537
|
'this.act.frame(scene, mp, local, !this.trip && this.pendingEnd === null && !this.talk.talking() && !decorating && !this.actionInput && !this.askInput && !this.menuInput && !this.carded);',
|
|
536
538
|
'}, !this.signIn.pending() && !this.trip && this.pendingEnd === null && !this.talk.talking() && !decorating && !this.carded && !this.askInput && !this.menuInput,',
|
|
537
539
|
'if (this.ballot) {',
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { stepCar, bumperBlocked, carInput } from '../code/client/car.js';
|
|
3
|
+
import { parseCar } from '../code/shared/car.js';
|
|
4
|
+
const car = parseCar({ look: 'car' });
|
|
5
|
+
const start = { speed: 0, heading: 0 };
|
|
6
|
+
const step = (state, input, dt = 1) => stepCar(state, input, car, dt);
|
|
7
|
+
assert.equal(step(start, { forward: 1 }).speed, 6);
|
|
8
|
+
assert.equal(step({ speed: 10 }, { forward: -1 }, 0.5).speed, 3);
|
|
9
|
+
assert.equal(step({ speed: 1 }, { forward: -1 }).speed, -4);
|
|
10
|
+
assert.equal(step(start, { forward: -1 }).speed, -4);
|
|
11
|
+
assert.equal(step({ speed: 8 }, {}).speed, 6);
|
|
12
|
+
assert.equal(step({ speed: -1 }, {}).speed, 0);
|
|
13
|
+
assert.equal(step(start, { steer: 1 }).heading, 0);
|
|
14
|
+
assert.equal(step({ speed: 4, heading: 0 }, { steer: 1, forward: 1 }).heading, -1.6);
|
|
15
|
+
assert.equal(step({ speed: -4, heading: 0 }, { steer: 1, forward: -1 }).heading, 1.6);
|
|
16
|
+
assert.equal(step(start, { forward: 1 }, 100).speed, 12);
|
|
17
|
+
assert.equal(step(start, { forward: -1 }, 100).speed, -4);
|
|
18
|
+
assert.equal(step({ speed: 5 }, { forward: 1, front: 1 }).speed, 0);
|
|
19
|
+
assert.equal(step(start, { forward: 1, front: 1 }).speed, 0);
|
|
20
|
+
assert.equal(step(start, { forward: -1, front: 1 }).speed, -4);
|
|
21
|
+
assert.equal(step(start, { forward: -1, back: 1 }).speed, 0);
|
|
22
|
+
assert.equal(bumperBlocked(2, 1, 2.1, null, 4), false);
|
|
23
|
+
assert.equal(bumperBlocked(-2, -1, null, 2, 4), true);
|
|
24
|
+
assert.deepEqual(start, { speed: 0, heading: 0 });
|
|
25
|
+
assert.deepEqual(carInput(new Set(['KeyW', 'KeyD'])), { forward: 1, steer: 1 });
|
|
26
|
+
assert.deepEqual(carInput(new Set(), { active: true, x: -0.8, y: -0.6 }), { forward: 0.6, steer: -0.8 });
|
|
27
|
+
assert.equal(parseCar({ look: 'car', speed: 999 }).speed, 16);
|
|
28
|
+
assert.equal(parseCar({ look: 'car', speed: NaN }), null);
|
|
29
|
+
assert.equal(parseCar({ look: 'car', seats: [] }), null);
|
|
30
|
+
assert.equal(parseCar({ look: 'car', seats: [[0, Infinity, 0]] }), null);
|
|
31
|
+
assert.equal(parseCar({ look: 'car', color: 'red' }), null);
|
|
32
|
+
assert.equal(parseCar({ look: 'car', camDistance: -1 }), null);
|
|
33
|
+
assert.equal(parseCar({}), null);
|
|
34
|
+
console.log('ok: car dynamics, bumpers, input and shared validation');
|
|
35
|
+
|
|
36
|
+
// The vectors the native engine runs against the same function (contract v1.160).
|
|
37
|
+
import { readFileSync } from 'node:fs';
|
|
38
|
+
const fixture = JSON.parse(readFileSync(new URL('./fixtures/car-vectors.json', import.meta.url), 'utf8'));
|
|
39
|
+
for (const v of fixture.vectors) {
|
|
40
|
+
const out = stepCar(v.state, v.input, parseCar(fixture.cars[v.car]), v.dt);
|
|
41
|
+
assert.ok(Math.abs(out.speed - v.out.speed) < 1e-9 && Math.abs(out.heading - v.out.heading) < 1e-9, JSON.stringify(v));
|
|
42
|
+
}
|
|
43
|
+
console.log(`ok: ${fixture.vectors.length} shared stepCar vectors`);
|
|
@@ -210,7 +210,8 @@ test('stand-in hello omits colours without opt-in and sends them with opt-in', (
|
|
|
210
210
|
if (avatarColors === undefined) { delete State.deck.avatarColors; }
|
|
211
211
|
else { State.deck.avatarColors = avatarColors; }
|
|
212
212
|
system.sendHello(scene, {}, net, 9);
|
|
213
|
-
|
|
213
|
+
const { device: _device, ...hello } = sent.at(-1);
|
|
214
|
+
assert.deepEqual(hello, { k: 'hub-hello', avatar: 9, from: null, party: 1, carry: null });
|
|
214
215
|
}
|
|
215
216
|
State.deck.avatarColors = true;
|
|
216
217
|
system.sendHello(scene, {}, net, 9);
|
|
@@ -26,7 +26,10 @@ const actors = [
|
|
|
26
26
|
{ id: 'floor', components: { Transform: { x: -4, y: 0, z: -3 }, Shape: { kind: 'box', width: 8, height: 0.1, depth: 7 } } },
|
|
27
27
|
{ id: 'chair', components: { Transform: { x: 0, y: 0.25, z: 0 }, Shape: { kind: 'box', width: 1, height: 0.5, depth: 1 }, Body: { type: 'kinematic' }, HubSeat: {} } },
|
|
28
28
|
{ id: 'rug', components: { Transform: { x: 0, y: 0.01, z: 0 }, Shape: { kind: 'box', width: 2, height: 0.02, depth: 2 } } },
|
|
29
|
+
{ id: 'lot-a-floor', components: { Transform: { x: 20, y: 0.5, z: 10 } } },
|
|
30
|
+
{ id: 'lot-b-floor', components: { Transform: { x: -30, z: 40 } } },
|
|
29
31
|
];
|
|
32
|
+
const grids = { 'lot-a': { origin: 'lot-a-floor', w: 3, d: 2, cell: 2 }, 'lot-b': { origin: 'lot-b-floor', w: 10, d: 12, cell: 0.5 } };
|
|
30
33
|
const players = [
|
|
31
34
|
{ playerId: 'p1', userId: '101', username: 'Ada', isAnonymous: false },
|
|
32
35
|
{ playerId: 'p2', userId: '102', username: 'Bo', isAnonymous: false },
|
|
@@ -414,6 +417,71 @@ test('preview swaps w/d, ignores another layer and its own footprint, and finds
|
|
|
414
417
|
assert.equal(fits(decor.grid, items, placed, { item: 'chair', x: 7, z: 6, rot: 1 }), false);
|
|
415
418
|
assert.deepEqual(freeCell(decor.grid, items, placed, items[0], { x: 5, z: 4 }), { x: 5, z: 4 });
|
|
416
419
|
});
|
|
420
|
+
test('v1.159 manifest accepts named grids beside or instead of grid and refuses bad ones', () => {
|
|
421
|
+
const only = { grids, layers: decor.layers }, both = { grid: decor.grid, grids, layers: decor.layers };
|
|
422
|
+
for (const value of [only, both]) {
|
|
423
|
+
const m = Manifest.readManifest(json({ decor: value }));
|
|
424
|
+
assert.deepEqual(m.errors, []);
|
|
425
|
+
assert.deepEqual(m.manifest.places.main.decor, value);
|
|
426
|
+
assert.equal(JSON.stringify(m.manifest.places.main.decor), JSON.stringify(value));
|
|
427
|
+
}
|
|
428
|
+
assert.equal(Object.hasOwn(Manifest.readManifest(json({ decor })).manifest.places.main.decor, 'grids'), false);
|
|
429
|
+
const many = Object.fromEntries(Array.from({ length: 16 }, (_, i) => [`lot-${i}`, grids['lot-a']]));
|
|
430
|
+
assert.deepEqual(Manifest.readManifest(json({ decor: { grids: many, layers: ['floor'] } })).errors, []);
|
|
431
|
+
const bad = [{ layers: ['floor'] }, { grids: {}, layers: ['floor'] }, { grids: [], layers: ['floor'] }, { grids: null, layers: ['floor'] }, { grids: { ...many, extra: grids['lot-a'] }, layers: ['floor'] }, { grids: { 'Not An Id': grids['lot-a'] }, layers: ['floor'] }];
|
|
432
|
+
for (const grid of [{}, null, { ...grids['lot-a'], origin: '' }, { ...grids['lot-a'], w: 17 }, { ...grids['lot-a'], cell: 0.4 }, { ...grids['lot-a'], extra: 1 }]) {
|
|
433
|
+
bad.push({ grids: { ...grids, 'lot-a': grid }, layers: ['floor'] }, { ...decor, grids: { 'lot-a': grid } });
|
|
434
|
+
}
|
|
435
|
+
for (const value of bad) {
|
|
436
|
+
assert.equal(Manifest.readManifest(json({ decor: value })).manifest, null, JSON.stringify(value));
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
test('v1.159 a spec names its grid: placed, ops and the wire follow it; the id stays off the wire', () => {
|
|
440
|
+
for (const value of [{ grids, layers: decor.layers }, { ...decor, grids }]) {
|
|
441
|
+
const r = boot({ decor: value });
|
|
442
|
+
const key = r.hub.spawn('chair', { x: 0, y: 0.25, z: 0 });
|
|
443
|
+
r.hub.decor.open('p1', { ...spec(), grid: 'lot-a', placed: [{ key, item: 'chair', x: 2, z: 1, rot: 0, layer: 'floor' }] });
|
|
444
|
+
const [, wire] = privateWire(r).at(-1);
|
|
445
|
+
assert.deepEqual(wire.grid, { x: 20, y: 0.5, z: 10, w: 3, d: 2, cell: 2 });
|
|
446
|
+
assert.equal(Object.hasOwn(wire.spec, 'grid'), false);
|
|
447
|
+
assert.equal(JSON.stringify(wire), JSON.stringify({ k: 'hub-decor', button: null, spec: { ...spec(), placed: [{ key, item: 'chair', x: 2, z: 1, rot: 0, layer: 'floor' }] }, grid: wire.grid }));
|
|
448
|
+
assert.throws(() => r.hub.decor.open('p1', { ...spec(), grid: 'lot-a', placed: [{ key, item: 'chair', x: 3, z: 0, rot: 0, layer: 'floor' }] }), TypeError);
|
|
449
|
+
assert.throws(() => r.hub.decor.update('p1', { placed: [{ key, item: 'chair', x: 0, z: 2, rot: 0, layer: 'floor' }] }), TypeError);
|
|
450
|
+
r.say('p1', { k: 'decor', op: 'place', item: 'chair', x: 3, z: 0, rot: 0 });
|
|
451
|
+
r.say('p1', { k: 'decor', op: 'place', item: 'chair', x: 0, z: 2, rot: 0 });
|
|
452
|
+
assert.deepEqual(r.ops, []);
|
|
453
|
+
r.say('p1', { k: 'decor', op: 'place', item: 'chair', x: 2, z: 1, rot: 0 });
|
|
454
|
+
assert.equal(r.ops.length, 1);
|
|
455
|
+
r.hub.decor.update('p1', { grid: 'lot-b', placed: [{ key, item: 'chair', x: 9, z: 11, rot: 0, layer: 'floor' }] });
|
|
456
|
+
assert.deepEqual(privateWire(r).at(-1)[1].grid, { x: -30, y: 0, z: 40, w: 10, d: 12, cell: 0.5 });
|
|
457
|
+
r.say('p1', { k: 'decor', op: 'move', key, x: 9, z: 11, rot: 0 });
|
|
458
|
+
assert.equal(r.ops.length, 2);
|
|
459
|
+
assert.throws(() => r.hub.decor.update('p1', { grid: 'lot-c' }), TypeError);
|
|
460
|
+
assert.deepEqual(privateWire(r).at(-1)[1].grid.w, 10, 'a refused update changes nothing');
|
|
461
|
+
r.sent.length = 0;
|
|
462
|
+
r.say('p1', { k: 'hub-hello', avatar: 0 });
|
|
463
|
+
assert.deepEqual(privateWire(r).at(-1)[1].grid, { x: -30, y: 0, z: 40, w: 10, d: 12, cell: 0.5 }, 'a re-hello resends the chosen grid');
|
|
464
|
+
}
|
|
465
|
+
const only = boot({ decor: { grids, layers: decor.layers } });
|
|
466
|
+
for (const value of [spec(), { ...spec(), grid: 'lot-c' }, { ...spec(), grid: null }, { ...spec(), grid: 7 }, { ...spec(), grid: 'toString' }]) {
|
|
467
|
+
assert.throws(() => only.hub.decor.open('p1', value), TypeError, JSON.stringify(value));
|
|
468
|
+
}
|
|
469
|
+
const both = boot({ decor: { ...decor, grids } });
|
|
470
|
+
both.hub.decor.open('p1', spec());
|
|
471
|
+
assert.deepEqual(privateWire(both).at(-1)[1].grid, { x: -4, y: 0, z: -3, w: 8, d: 7, cell: 1 }, 'without spec.grid the place grid is used');
|
|
472
|
+
both.hub.decor.update('p1', { grid: 'lot-a' });
|
|
473
|
+
both.hub.decor.update('p1', { grid: undefined });
|
|
474
|
+
assert.equal(privateWire(both).at(-1)[1].grid.w, 8);
|
|
475
|
+
const single = boot({ decor });
|
|
476
|
+
assert.throws(() => single.hub.decor.open('p1', { ...spec(), grid: 'lot-a' }), TypeError, 'a single-grid place has no named grids');
|
|
477
|
+
});
|
|
478
|
+
test('v1.159 a single-grid place sends the same bytes as before', () => {
|
|
479
|
+
const r = boot({ decor });
|
|
480
|
+
r.hub.decor.button('p1', 'Decorate');
|
|
481
|
+
r.hub.decor.open('p1', spec());
|
|
482
|
+
assert.equal(JSON.stringify(privateWire(r).at(-1)[1]), JSON.stringify({ k: 'hub-decor', button: 'Decorate', spec: spec(), grid: { x: -4, y: 0, z: -3, w: 8, d: 7, cell: 1 } }));
|
|
483
|
+
assert.equal(JSON.stringify(Manifest.readManifest(json({ decor })).manifest.places.main.decor), JSON.stringify(decor));
|
|
484
|
+
});
|
|
417
485
|
|
|
418
486
|
// Exercise the actual real-time router, which intercepts GONE before hub.message.
|
|
419
487
|
const { makeSession } = await import('../../real-time/code/server/session.js');
|
|
@@ -457,6 +525,15 @@ try {
|
|
|
457
525
|
manifest.hub.decor.grid.origin = 'floor'; manifest.hub.decor.grid.w = 17;
|
|
458
526
|
fs.writeFileSync(path.join(dir, 'castle.json'), JSON.stringify(manifest));
|
|
459
527
|
assert.ok((await check({ deckDir: dir, self: true })).errors.some((e) => e.includes('decor')));
|
|
528
|
+
manifest.hub.decor = { grids: { ...grids, 'lot-c': { ...grids['lot-a'], origin: 'missing' } }, layers: ['floor'] };
|
|
529
|
+
fs.writeFileSync(path.join(dir, 'castle.json'), JSON.stringify(manifest));
|
|
530
|
+
assert.deepEqual((await check({ deckDir: dir, self: true })).errors.filter((e) => e.includes('decor')), ['hub.decor.grids.lot-c.origin must name an actor with a finite Transform in scenes/main.scene.']);
|
|
531
|
+
delete manifest.hub.decor.grids['lot-c'];
|
|
532
|
+
fs.writeFileSync(path.join(dir, 'castle.json'), JSON.stringify(manifest));
|
|
533
|
+
assert.deepEqual((await check({ deckDir: dir, self: true })).errors, []);
|
|
534
|
+
manifest.hub.decor.grids['lot-a'] = { ...grids['lot-a'], w: 0 };
|
|
535
|
+
fs.writeFileSync(path.join(dir, 'castle.json'), JSON.stringify(manifest));
|
|
536
|
+
assert.ok((await check({ deckDir: dir, self: true })).errors.some((e) => e.includes('decor.grids.lot-a')));
|
|
460
537
|
console.log('ok: publish check validates grid actor and rejects malformed decor'); passed += 1;
|
|
461
538
|
} finally {
|
|
462
539
|
fs.rmSync(dir, { recursive: true, force: true });
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { runInNewContext } from 'node:vm';
|
|
4
|
+
import { encodeDeviceClass as encode, decodeDeviceClass as decode } from '../code/shared/deviceClass.js';
|
|
5
|
+
|
|
6
|
+
const PRESENT = 2 ** 28;
|
|
7
|
+
const unknown = { lowMemory: false, cores: 0, dpr: 0, width: 0, height: 0, deviceMemory: 0 };
|
|
8
|
+
assert.equal(encode(), PRESENT, 'even an all-unknown class has presence');
|
|
9
|
+
assert.deepEqual(decode(PRESENT), unknown);
|
|
10
|
+
const phone = { lowMemory: true, cores: 4, dpr: 2.75, width: 360, height: 800, deviceMemory: 2 };
|
|
11
|
+
const phoneCode = PRESENT + 1 + (4 << 1) + (11 << 4) + (45 << 8) + (100 << 16) + (3 << 25);
|
|
12
|
+
assert.equal(encode(phone), phoneCode, 'independent wire-layout fixture');
|
|
13
|
+
assert.deepEqual(decode(phoneCode), phone);
|
|
14
|
+
assert.equal(encode({ ...phone, width: 800, height: 360 }), phoneCode, 'orientation independent');
|
|
15
|
+
|
|
16
|
+
for (const [input, expected] of [[0, 0], [0.49, 0], [0.5, 1], [6, 6], [7, 7], [8, 7], [128, 7], [Number.MAX_VALUE, 7]]) {
|
|
17
|
+
assert.equal(decode(encode({ cores: input })).cores, expected);
|
|
18
|
+
}
|
|
19
|
+
for (const [input, expected] of [[0, 0], [0.124, 0], [0.125, 0.25], [1, 1], [3.74, 3.75], [3.75, 3.75], [4, 3.75], [Number.MAX_VALUE, 3.75]]) {
|
|
20
|
+
assert.equal(decode(encode({ dpr: input })).dpr, expected);
|
|
21
|
+
}
|
|
22
|
+
for (const [input, expected] of [[0, 0], [0.25, 0.5], [0.5, 0.5], [0.51, 1], [1, 1], [1.1, 2], [2, 2], [2.1, 4], [4, 4], [4.1, 8], [8, 8], [16, 8], [Number.MAX_VALUE, 8]]) {
|
|
23
|
+
assert.equal(decode(encode({ deviceMemory: input })).deviceMemory, expected);
|
|
24
|
+
}
|
|
25
|
+
for (const [width, height, short, long] of [
|
|
26
|
+
[3.9, 4, 0, 8], [4, 12, 8, 16], [2040, 4088, 2040, 4088],
|
|
27
|
+
[2044, 4092, 2040, 4088], [4096, 8192, 2040, 4088],
|
|
28
|
+
[Number.MAX_VALUE, Number.MAX_VALUE, 2040, 4088],
|
|
29
|
+
]) {
|
|
30
|
+
const decoded = decode(encode({ width, height }));
|
|
31
|
+
assert.equal(decoded.width, short); assert.equal(decoded.height, long);
|
|
32
|
+
}
|
|
33
|
+
for (const bad of [undefined, null, NaN, Infinity, -Infinity, -1, -0.01, '4', true, {}, [], 1n]) {
|
|
34
|
+
assert.deepEqual(decode(encode({ lowMemory: bad, cores: bad, dpr: bad, width: bad, height: bad, deviceMemory: bad })),
|
|
35
|
+
{ ...unknown, lowMemory: bad === true });
|
|
36
|
+
assert.deepEqual(decode(encode({ width: bad, height: 800 })), { ...unknown, height: 800 }, 'a bad dimension does not erase the other');
|
|
37
|
+
}
|
|
38
|
+
for (const bad of [undefined, null, NaN, Infinity, -1, 0, 1, PRESENT - 1, PRESENT + 0.5, 2 ** 29, '268435456', PRESENT | (6 << 25), PRESENT | (7 << 25)]) {
|
|
39
|
+
assert.equal(decode(bad), null);
|
|
40
|
+
}
|
|
41
|
+
// Exercise every cores, DPR and memory bin against the screen field edges.
|
|
42
|
+
for (const lowMemory of [false, true]) for (let cores = 0; cores <= 7; cores++) {
|
|
43
|
+
for (let q = 0; q <= 15; q++) for (const deviceMemory of [0, 0.5, 1, 2, 4, 8]) {
|
|
44
|
+
for (const [width, height] of [[0, 0], [0, 8], [8, 8], [2032, 4080], [2040, 4088]]) {
|
|
45
|
+
const value = { lowMemory, cores, dpr: q / 4, width, height, deviceMemory };
|
|
46
|
+
const code = encode(value);
|
|
47
|
+
assert(Number.isSafeInteger(code) && code > 0 && code < 2 ** 29);
|
|
48
|
+
assert.equal(code & PRESENT, PRESENT);
|
|
49
|
+
assert.deepEqual(decode(code), value);
|
|
50
|
+
assert.equal(encode(decode(code)), code);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
console.log('device class layout, edges, invalid inputs, presence and round trips: passed');
|
|
55
|
+
|
|
56
|
+
// Run the actual hello method without loading the rendering engine.
|
|
57
|
+
const source = readFileSync(new URL('../code/systems/hub.js', import.meta.url), 'utf8');
|
|
58
|
+
const method = source.slice(source.indexOf(' sendHello(scene,'), source.indexOf('\n // Hide what the place hid'));
|
|
59
|
+
function hello(globals = {}, encoder = encode) {
|
|
60
|
+
const messages = [];
|
|
61
|
+
const context = { ...globals, encodeDeviceClass: encoder, Hub: { hub: {}, deck: {} },
|
|
62
|
+
Avatar: { currentColor: () => 0 }, Rehello: { mark: () => null } };
|
|
63
|
+
const sendHello = runInNewContext(`(function ${method.trim()})`, context);
|
|
64
|
+
sendHello.call({}, { persistent: {}, three: { lowMemory: true } }, {}, { send: (m) => messages.push(m) }, 1);
|
|
65
|
+
assert.equal(messages.length, 1); assert.equal(messages[0].k, 'hub-hello');
|
|
66
|
+
return messages[0];
|
|
67
|
+
}
|
|
68
|
+
assert.equal(hello({ navigator: { hardwareConcurrency: 4, deviceMemory: 2 }, devicePixelRatio: 2.75, screen: { width: 360, height: 800 } }).device, phoneCode);
|
|
69
|
+
assert.equal(hello().device, PRESENT | 1, 'missing browser globals are safe');
|
|
70
|
+
const denied = new Proxy({}, { get() { throw new Error('unavailable'); } });
|
|
71
|
+
assert.equal(hello({ navigator: denied, screen: denied, devicePixelRatio: NaN }).device, PRESENT | 1, 'throwing browser getters are safe');
|
|
72
|
+
const throwingGlobals = Object.fromEntries(['navigator', 'screen', 'devicePixelRatio'].map((key) => [key, undefined]));
|
|
73
|
+
// A throwing global getter is guarded too, including the typeof expression.
|
|
74
|
+
for (const key of Object.keys(throwingGlobals)) {
|
|
75
|
+
const context = { encodeDeviceClass: encode, Hub: { hub: {}, deck: {} }, Avatar: { currentColor: () => 0 }, Rehello: { mark: () => null } };
|
|
76
|
+
Object.defineProperty(context, key, { get() { throw new Error('global unavailable'); } });
|
|
77
|
+
const sendHello = runInNewContext(`(function ${method.trim()})`, context);
|
|
78
|
+
let message;
|
|
79
|
+
sendHello.call({}, { persistent: {} }, {}, { send: (m) => { message = m; } }, 1);
|
|
80
|
+
assert.equal(message.device, PRESENT);
|
|
81
|
+
}
|
|
82
|
+
assert.equal(Object.hasOwn(hello({}, () => 0), 'device'), false, 'zero is omitted from the wire');
|
|
83
|
+
console.log('hub hello device class and guarded browser globals: passed');
|