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
|
@@ -35,8 +35,8 @@ export function arrive(h, group) {
|
|
|
35
35
|
if (key) {a.departed.delete(key);}
|
|
36
36
|
a.visits.set(p.playerId, { at: now, userId: key });
|
|
37
37
|
if (back) {track(h, p.playerId, 'reconnect', { subject: h.manifest.house ? SUBJECTS.house : SUBJECTS.town });}
|
|
38
|
-
else if (h.firstVisit && !h.manifest.house) {a.visits.get(p.playerId).arrival = { subject: SUBJECTS.town, result: p.from ? 2 : 1 };}
|
|
39
|
-
else {track(h, p.playerId, h.manifest.house ? 'house_visit' : 'arrive', { subject: h.manifest.house ? SUBJECTS.house : SUBJECTS.town, result: p.from ? 2 : 1 });}
|
|
38
|
+
else if (h.firstVisit && !h.manifest.house) {a.visits.get(p.playerId).arrival = { subject: SUBJECTS.town, value: p.device ?? 0, result: p.from ? 2 : 1 };}
|
|
39
|
+
else {track(h, p.playerId, h.manifest.house ? 'house_visit' : 'arrive', { subject: h.manifest.house ? SUBJECTS.house : SUBJECTS.town, value: p.device ?? 0, result: p.from ? 2 : 1 });}
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
// Resolve the existing arrival once storage has answered, without duplicating it.
|
|
@@ -48,13 +48,63 @@ export function firstVisitArrived(h, playerId, flags) {
|
|
|
48
48
|
if (accepted) {delete visit.arrival;}
|
|
49
49
|
return accepted;
|
|
50
50
|
}
|
|
51
|
+
// Terminal rows carry how their segment ended in `result` (Ghost owns flags):
|
|
52
|
+
// 0 the visit ended here, 1 its connection dropped and never came back in
|
|
53
|
+
// time, 2 a segment that continued the visit after a late resume. Rows with
|
|
54
|
+
// result 0 or 1 count each real visit once; summing `value` gives its
|
|
55
|
+
// connected time.
|
|
56
|
+
export const END = Object.freeze({ left: 0, dropped: 1, continued: 2 });
|
|
57
|
+
// The host resolves a departed player for under a minute, while a place may
|
|
58
|
+
// hold the visit for five. A drop still away this long is reported now.
|
|
59
|
+
export const DROP_REPORT_MS = 40000;
|
|
60
|
+
function end(h, playerId, visit, value, result) {
|
|
61
|
+
if (visit.arrival) {firstVisitArrived(h, playerId, 0);}
|
|
62
|
+
value = Math.max(0, Math.min(2147483647, Math.round(value)));
|
|
63
|
+
track(h, playerId, 'session_end', { value, result });
|
|
64
|
+
if (h.manifest.house) {track(h, playerId, 'house_time', { subject: SUBJECTS.house, value, result });}
|
|
65
|
+
}
|
|
66
|
+
// Every reconcile, after the place forgot whom it lets go. Presence is the
|
|
67
|
+
// session roster, whatever the place still retains: a stale body or a resume
|
|
68
|
+
// hold must not move the report deadline. A new body under the same id means
|
|
69
|
+
// the connection came back between two ticks; the time between is away.
|
|
70
|
+
export function observe(h) {
|
|
71
|
+
const now = h.sim.timeMs;
|
|
72
|
+
for (const [playerId, visit] of h.analytics.visits) {
|
|
73
|
+
const body = h.sim.players.get(playerId);
|
|
74
|
+
if (h.session?.players.some((p) => p.playerId === playerId)) {
|
|
75
|
+
if (visit.droppedAt !== undefined) {resume(h, visit, now);}
|
|
76
|
+
else if (body && visit.body && body !== visit.body && visit.seen !== undefined) {visit.at += now - visit.seen;}
|
|
77
|
+
if (body) {visit.body = body;}
|
|
78
|
+
visit.seen = now;
|
|
79
|
+
} else if (!h.resumeDeparting?.has(playerId)) {
|
|
80
|
+
if (visit.droppedAt === undefined) {
|
|
81
|
+
visit.droppedAt = visit.seen ?? now;
|
|
82
|
+
visit.droppedWall = Date.now();
|
|
83
|
+
}
|
|
84
|
+
if (!visit.reported && Date.now() - visit.droppedWall >= DROP_REPORT_MS) {
|
|
85
|
+
end(h, playerId, visit, visit.droppedAt - visit.at, visit.continued ? END.continued : END.dropped);
|
|
86
|
+
visit.reported = true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// A quick return is the same segment, without the time away. One after its
|
|
92
|
+
// drop was reported starts a continuation.
|
|
93
|
+
function resume(h, visit, now) {
|
|
94
|
+
if (visit.reported) {
|
|
95
|
+
visit.continued = true;
|
|
96
|
+
visit.at = now;
|
|
97
|
+
} else {visit.at += now - visit.droppedAt;}
|
|
98
|
+
delete visit.droppedAt;
|
|
99
|
+
delete visit.droppedWall;
|
|
100
|
+
delete visit.reported;
|
|
101
|
+
}
|
|
51
102
|
export function leave(h, playerId) {
|
|
52
103
|
const a = h.analytics, visit = a.visits.get(playerId);
|
|
53
104
|
if (!visit) {return;}
|
|
54
|
-
if (visit.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (h.manifest.house) {track(h, playerId, 'house_time', { subject: SUBJECTS.house, value });}
|
|
105
|
+
if (visit.droppedAt !== undefined) {
|
|
106
|
+
if (!visit.reported) {end(h, playerId, visit, visit.droppedAt - visit.at, visit.continued ? END.continued : END.dropped);}
|
|
107
|
+
} else {end(h, playerId, visit, h.sim.timeMs - visit.at, visit.continued ? END.continued : END.left);}
|
|
58
108
|
a.visits.delete(playerId);
|
|
59
109
|
if (visit.userId) {a.departed.set(visit.userId, h.sim.timeMs);}
|
|
60
110
|
}
|
|
@@ -6,6 +6,7 @@ import { DECOR_ID, footprint } from '../shared/decor.js';
|
|
|
6
6
|
export const MAX_ITEMS = 64;
|
|
7
7
|
export const MAX_PLACED = 64;
|
|
8
8
|
export const MAX_SWATCHES = 24;
|
|
9
|
+
const SPEC = ['title', 'grid', 'tabs', 'items', 'swatches', 'placed'];
|
|
9
10
|
const COLOR = /^#[0-9a-fA-F]{6}$/;
|
|
10
11
|
const ACTOR = (value) => typeof value === 'string' && value.trim().length > 0 && value.length <= 128;
|
|
11
12
|
const object = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
@@ -25,24 +26,45 @@ function id(value, where) {
|
|
|
25
26
|
need(typeof value === 'string' && DECOR_ID.test(value), `${where} must be a short id`);
|
|
26
27
|
}
|
|
27
28
|
|
|
29
|
+
function readGrid(value, where) {
|
|
30
|
+
keys(value, ['origin', 'w', 'd', 'cell'], where);
|
|
31
|
+
const { origin, w, d, cell } = value;
|
|
32
|
+
need(ACTOR(origin), `${where}.origin must name an actor`);
|
|
33
|
+
need(int(w, 1, 16) && int(d, 1, 16), `${where} w and d must be integers in 1..16`);
|
|
34
|
+
need(Number.isFinite(cell) && cell >= 0.5 && cell <= 2, `${where}.cell must be 0.5..2 metres`);
|
|
35
|
+
return { origin, w, d, cell };
|
|
36
|
+
}
|
|
37
|
+
|
|
28
38
|
// The manifest and the publish check share this reader. Absence adds no key.
|
|
29
39
|
export function readDecor(value, where, errors) {
|
|
30
40
|
if (value === undefined) {
|
|
31
41
|
return null;
|
|
32
42
|
}
|
|
33
43
|
try {
|
|
34
|
-
keys(value, ['grid', 'layers'], where);
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
keys(value, ['grid', 'grids', 'layers'], where);
|
|
45
|
+
need(value.grid !== undefined || value.grids !== undefined, `${where} needs grid or grids`);
|
|
46
|
+
const out = {};
|
|
47
|
+
if (value.grid !== undefined) {
|
|
48
|
+
out.grid = readGrid(value.grid, `${where}.grid`);
|
|
49
|
+
}
|
|
50
|
+
// v1.159: named grids a spec picks by id, e.g. one per house lot.
|
|
51
|
+
if (value.grids !== undefined) {
|
|
52
|
+
need(object(value.grids), `${where}.grids must be an object`);
|
|
53
|
+
const ids = Object.keys(value.grids);
|
|
54
|
+
need(ids.length >= 1 && ids.length <= 16, `${where}.grids must hold 1..16 grids`);
|
|
55
|
+
out.grids = {};
|
|
56
|
+
for (const gridId of ids) {
|
|
57
|
+
id(gridId, `${where}.grids key`);
|
|
58
|
+
out.grids[gridId] = readGrid(value.grids[gridId], `${where}.grids.${gridId}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
40
61
|
need(Array.isArray(value.layers) && value.layers.length >= 1 && value.layers.length <= 3, `${where}.layers must contain 1..3 ids`);
|
|
41
62
|
for (const layer of value.layers) {
|
|
42
63
|
id(layer, `${where}.layers`);
|
|
43
64
|
}
|
|
44
65
|
need(new Set(value.layers).size === value.layers.length, `${where}.layers must be unique`);
|
|
45
|
-
|
|
66
|
+
out.layers = [...value.layers];
|
|
67
|
+
return out;
|
|
46
68
|
} catch (error) {
|
|
47
69
|
errors.push(error.message);
|
|
48
70
|
return null;
|
|
@@ -56,9 +78,21 @@ function unique(values, where) {
|
|
|
56
78
|
need(new Set(values).size === values.length, `${where} must be unique`);
|
|
57
79
|
}
|
|
58
80
|
|
|
81
|
+
// The declared grid a spec decorates: its named one, else the place's own.
|
|
82
|
+
function declared(h, spec) {
|
|
83
|
+
const decor = h.place.decor;
|
|
84
|
+
if (spec?.grid === undefined) {
|
|
85
|
+
need(decor.grid, 'spec.grid must name one of the place\'s decor grids');
|
|
86
|
+
return decor.grid;
|
|
87
|
+
}
|
|
88
|
+
need(typeof spec.grid === 'string' && decor.grids && Object.hasOwn(decor.grids, spec.grid), 'spec.grid must name one of the place\'s decor grids');
|
|
89
|
+
return decor.grids[spec.grid];
|
|
90
|
+
}
|
|
91
|
+
|
|
59
92
|
export function checkSpec(h, value) {
|
|
60
|
-
keys(value,
|
|
61
|
-
const
|
|
93
|
+
keys(value, SPEC, 'spec');
|
|
94
|
+
const grid = declared(h, value);
|
|
95
|
+
const out = value.grid === undefined ? {} : { grid: value.grid };
|
|
62
96
|
if (value.title !== undefined) {
|
|
63
97
|
need(typeof value.title === 'string' && value.title.length <= 40, 'title must be at most 40 characters');
|
|
64
98
|
out.title = value.title;
|
|
@@ -111,7 +145,7 @@ export function checkSpec(h, value) {
|
|
|
111
145
|
const item = out.items.find((i) => i.id === piece.item);
|
|
112
146
|
need(item && item.layer === piece.layer, 'placed item and layer must match the catalogue');
|
|
113
147
|
need(int(piece.rot, 0, 3), 'placed.rot must be 0..3');
|
|
114
|
-
const size = footprint(item, piece.rot)
|
|
148
|
+
const size = footprint(item, piece.rot);
|
|
115
149
|
need(int(piece.x, 0, grid.w - size.w) && int(piece.z, 0, grid.d - size.d), 'placed piece must fit in the grid');
|
|
116
150
|
return { key: piece.key, item: piece.item, x: piece.x, z: piece.z, rot: piece.rot, layer: piece.layer };
|
|
117
151
|
});
|
|
@@ -126,8 +160,8 @@ function player(h, playerId) {
|
|
|
126
160
|
need(h.place.decor, 'this place does not declare decor');
|
|
127
161
|
need(present(h, playerId), 'playerId must name a player here');
|
|
128
162
|
}
|
|
129
|
-
function gridOf(h) {
|
|
130
|
-
const grid = h
|
|
163
|
+
function gridOf(h, spec) {
|
|
164
|
+
const grid = declared(h, spec);
|
|
131
165
|
const t = h.actors.find((actor) => actor.id === grid.origin)?.components.Transform;
|
|
132
166
|
need(t && ['x', 'y', 'z'].every((key) => t[key] === undefined || Number.isFinite(t[key])), 'grid.origin must have a finite Transform');
|
|
133
167
|
return { x: t.x ?? 0, y: t.y ?? 0, z: t.z ?? 0, w: grid.w, d: grid.d, cell: grid.cell };
|
|
@@ -138,7 +172,12 @@ function current(h, playerId) {
|
|
|
138
172
|
function send(h, playerId, state) {
|
|
139
173
|
const wire = { k: 'hub-decor', ...state };
|
|
140
174
|
if (state.spec) {
|
|
141
|
-
|
|
175
|
+
// The chosen grid's id stays off the wire: its resolved bounds follow.
|
|
176
|
+
if (state.spec.grid !== undefined) {
|
|
177
|
+
wire.spec = { ...state.spec };
|
|
178
|
+
delete wire.spec.grid;
|
|
179
|
+
}
|
|
180
|
+
wire.grid = gridOf(h, state.spec);
|
|
142
181
|
}
|
|
143
182
|
h.session?.send(playerId, wire);
|
|
144
183
|
}
|
|
@@ -161,7 +200,7 @@ export function api(h) {
|
|
|
161
200
|
open(playerId, spec) {
|
|
162
201
|
player(h, playerId);
|
|
163
202
|
const checked = checkSpec(h, spec);
|
|
164
|
-
gridOf(h);
|
|
203
|
+
gridOf(h, checked);
|
|
165
204
|
set(h, playerId, { ...current(h, playerId), spec: checked });
|
|
166
205
|
},
|
|
167
206
|
close(playerId) {
|
|
@@ -172,8 +211,9 @@ export function api(h) {
|
|
|
172
211
|
player(h, playerId);
|
|
173
212
|
const state = current(h, playerId);
|
|
174
213
|
need(state.spec, 'update needs an open catalogue');
|
|
175
|
-
keys(partial,
|
|
214
|
+
keys(partial, SPEC, 'partial spec');
|
|
176
215
|
const checked = checkSpec(h, { ...state.spec, ...partial });
|
|
216
|
+
gridOf(h, checked);
|
|
177
217
|
set(h, playerId, { ...state, spec: checked });
|
|
178
218
|
},
|
|
179
219
|
});
|
|
@@ -200,7 +240,7 @@ export function message(h, playerId, data) {
|
|
|
200
240
|
case 'place':
|
|
201
241
|
case 'move': {
|
|
202
242
|
keys(data, ['k', 'op', data.op === 'place' ? 'item' : 'key', 'x', 'z', 'rot'], 'placement op');
|
|
203
|
-
const grid = h
|
|
243
|
+
const grid = declared(h, spec);
|
|
204
244
|
need(int(data.x, 0, grid.w - 1) && int(data.z, 0, grid.d - 1) && int(data.rot, 0, 3), 'invalid cells or rotation');
|
|
205
245
|
if (data.op === 'place') {
|
|
206
246
|
const item = spec.items.find((i) => i.id === data.item);
|