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
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
|
|
21
21
|
import { warnOnce, isActor } from './actors.js';
|
|
22
22
|
import { danceFloors } from '../shared/danceIdle.js';
|
|
23
|
+
import { EXPRESSION_EMOTES } from '../shared/expression.js';
|
|
24
|
+
import { bodySize, solids, footprintHas } from './standing.js';
|
|
23
25
|
|
|
24
26
|
const DEG = Math.PI / 180;
|
|
25
27
|
|
|
@@ -88,9 +90,46 @@ function ask(h, name, ...args) {
|
|
|
88
90
|
|
|
89
91
|
// --- emotes ---------------------------------------------------------------
|
|
90
92
|
|
|
93
|
+
function roleEmote(h, id) {
|
|
94
|
+
return idleOf(h)?.expression?.roleEmotes.find((role) => role.id === id);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function duration(h, id) {
|
|
98
|
+
if (typeof id !== 'string') { return null; }
|
|
99
|
+
if (Object.hasOwn(EMOTES, id)) { return EMOTES[id]; }
|
|
100
|
+
if (!idleOf(h)?.expression) { return null; }
|
|
101
|
+
return (Object.hasOwn(EXPRESSION_EMOTES, id) ? EXPRESSION_EMOTES[id].ms : roleEmote(h, id)?.ms) ?? null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Private visit grants never ride the shared snapshot.
|
|
105
|
+
export function emotesFor(h, playerId, ids) {
|
|
106
|
+
if (!idleOf(h)?.expression || !present(h, playerId) || (ids !== null && !Array.isArray(ids))) { return false; }
|
|
107
|
+
const clean = [];
|
|
108
|
+
for (const id of ids ?? []) {
|
|
109
|
+
if (!roleEmote(h, id)) {
|
|
110
|
+
warnOnce(h, `emotesFor:${String(id)}`, 'hub.emotesFor: unknown role emote');
|
|
111
|
+
} else if (!clean.includes(id)) { clean.push(id); }
|
|
112
|
+
}
|
|
113
|
+
const grants = h.roleEmotes ??= new Map();
|
|
114
|
+
const previous = grants.get(playerId) ?? [];
|
|
115
|
+
if (previous.length === clean.length && previous.every((id) => clean.includes(id))) { return true; }
|
|
116
|
+
grants.set(playerId, clean);
|
|
117
|
+
h.session.send(playerId, { k: 'hub-emotes-for', ids: [...clean] });
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// A fresh client holds no grants: replay a non-empty list on its hello, and
|
|
122
|
+
// any list ever sent on a resume hello (it may have missed a clear).
|
|
123
|
+
export function joinedAfresh(h, playerId, held = false) {
|
|
124
|
+
const ids = h.roleEmotes?.get(playerId);
|
|
125
|
+
if (idleOf(h)?.expression && ids && (held || ids.length)) {
|
|
126
|
+
h.session.send(playerId, { k: 'hub-emotes-for', ids: [...ids] });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
91
130
|
function startEmote(h, playerId, id) {
|
|
92
131
|
const now = h.sim.timeMs;
|
|
93
|
-
h.emotes.set(playerId, { id, at: now, until: now +
|
|
132
|
+
h.emotes.set(playerId, { id, at: now, until: now + duration(h, id) });
|
|
94
133
|
h.emoteAt.set(playerId, now);
|
|
95
134
|
// v1.47: only a player's emote can start nearby bodies reacting.
|
|
96
135
|
if (present(h, playerId)) {
|
|
@@ -103,7 +142,7 @@ function startEmote(h, playerId, id) {
|
|
|
103
142
|
// `emote` hook. Anything else is dropped.
|
|
104
143
|
export function emoteMessage(h, playerId, data) {
|
|
105
144
|
const id = data?.id;
|
|
106
|
-
if (!idleOf(h)?.emotes || !h.sim || typeof id !== 'string' || !
|
|
145
|
+
if (!idleOf(h)?.emotes || !h.sim || typeof id !== 'string' || !duration(h, id) || (roleEmote(h, id) && !h.roleEmotes?.get(playerId)?.includes(id))) {
|
|
107
146
|
return;
|
|
108
147
|
}
|
|
109
148
|
if (!present(h, playerId)) {
|
|
@@ -130,7 +169,7 @@ export function emote(h, playerId, id) {
|
|
|
130
169
|
warnOnce(h, 'emote:off', 'hub.emote: this place does not turn on idle.emotes');
|
|
131
170
|
return false;
|
|
132
171
|
}
|
|
133
|
-
if (
|
|
172
|
+
if (!duration(h, id)) {
|
|
134
173
|
warnOnce(h, `emote:${id}`, `hub.emote: "${id}" is not an emote (${Object.keys(EMOTES).join(', ')})`);
|
|
135
174
|
return false;
|
|
136
175
|
}
|
|
@@ -247,6 +286,7 @@ export function sitMessage(h, placeAt, playerId, data) {
|
|
|
247
286
|
if (!idleOf(h)?.seats || !h.sim || !spendSit(h, playerId)) {
|
|
248
287
|
return;
|
|
249
288
|
}
|
|
289
|
+
if (h.ctx?.vehicle?.(playerId)) {return;}
|
|
250
290
|
const seat = seatOf(h, data?.seat);
|
|
251
291
|
const body = h.sim.players.get(playerId);
|
|
252
292
|
if (!seat || !body || !present(h, playerId)) {
|
|
@@ -281,12 +321,76 @@ export function sitMessage(h, placeAt, playerId, data) {
|
|
|
281
321
|
}
|
|
282
322
|
h.held.set(playerId, { at: { ...seat.at }, facing: seat.facing, seat: seat.id });
|
|
283
323
|
h.seated.set(playerId, seat.id);
|
|
324
|
+
h.expressionStill?.delete(playerId);
|
|
284
325
|
placeAt(h, playerId, seat.at, seat.facing);
|
|
285
326
|
}
|
|
286
327
|
|
|
328
|
+
// Ground support uses the same fixed floor shapes as standing placement: the
|
|
329
|
+
// top a body's feet rest on (within -0.15..0.12 m of them), or null.
|
|
330
|
+
function floorUnder(h, at) {
|
|
331
|
+
const size = bodySize(h);
|
|
332
|
+
if (!size) { return null; }
|
|
333
|
+
const feet = at.y - size.halfHeight;
|
|
334
|
+
let top = null;
|
|
335
|
+
if (h.noGround !== true && Math.abs(at.x) <= 100 && Math.abs(at.z) <= 100 && feet >= -0.15 && feet <= 0.12) { top = 0; }
|
|
336
|
+
for (const { shape, pose, moving } of solids(h)) {
|
|
337
|
+
if (moving || !pose.upright || !['box', 'cylinder'].includes(shape.kind) || !footprintHas(shape, pose, at, 0)) { continue; }
|
|
338
|
+
const surface = pose.y + (shape.height ?? 1) / 2;
|
|
339
|
+
const gap = feet - surface;
|
|
340
|
+
if (gap >= -0.15 && gap <= 0.12 && (top === null || surface > top)) { top = surface; }
|
|
341
|
+
}
|
|
342
|
+
return top;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// Keep the anchor until a meaningful displacement, so small pose jitter
|
|
346
|
+
// does not restart the stillness timer; the last step must also be still
|
|
347
|
+
// across, so a walk's first step never sits. Requests also sample between ticks.
|
|
348
|
+
function stillSample(h, playerId, at) {
|
|
349
|
+
const samples = h.expressionStill ??= new Map();
|
|
350
|
+
let sample = samples.get(playerId);
|
|
351
|
+
if (!sample || Math.hypot(at.x - sample.pose.x, at.z - sample.pose.z) > 0.05 || Math.abs(at.y - sample.pose.y) > 0.08) {
|
|
352
|
+
sample = { pose: { ...at }, since: h.sim.timeMs, prev: { ...at }, last: { ...at }, lastAt: h.sim.timeMs, step: 0 };
|
|
353
|
+
samples.set(playerId, sample);
|
|
354
|
+
}
|
|
355
|
+
// The step is measured from the previous tick's pose. Later reports in
|
|
356
|
+
// the same tick only make it larger, so a request after a mid-tick move
|
|
357
|
+
// sees that move, and repeated checks never measure a pose against itself.
|
|
358
|
+
if (sample.lastAt !== h.sim.timeMs) {
|
|
359
|
+
sample.prev = sample.last ?? sample.pose;
|
|
360
|
+
sample.step = 0;
|
|
361
|
+
sample.lastAt = h.sim.timeMs;
|
|
362
|
+
}
|
|
363
|
+
const prev = sample.prev ?? sample.pose;
|
|
364
|
+
sample.step = Math.max(sample.step ?? 0, Math.hypot(at.x - prev.x, at.z - prev.z));
|
|
365
|
+
sample.last = { ...at };
|
|
366
|
+
return sample;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// The floor top a still player would sit on, or null.
|
|
370
|
+
function stillFloor(h, playerId) {
|
|
371
|
+
const body = h.sim.players.get(playerId);
|
|
372
|
+
if (!body) { return null; }
|
|
373
|
+
const sample = stillSample(h, playerId, body.at);
|
|
374
|
+
return h.sim.timeMs - sample.since >= 250 && sample.step <= 0.015 ? floorUnder(h, body.at) : null;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
export function sitHereMessage(h, placeAt, playerId) {
|
|
378
|
+
if (!idleOf(h)?.expression || !h.sim || !spendSit(h, playerId)) { return; }
|
|
379
|
+
const can = () => present(h, playerId) && !h.held.has(playerId) && !sitting(h, playerId) && !h.grabs?.has(playerId) && stillFloor(h, playerId) !== null;
|
|
380
|
+
if (!can() || !ask(h, 'sit', playerId, null) || !can()) { return; }
|
|
381
|
+
const body = h.sim.players.get(playerId);
|
|
382
|
+
// Held no higher than standing on the floor found: a body caught rising is
|
|
383
|
+
// lowered onto it, never frozen in the air.
|
|
384
|
+
const at = { ...body.at, y: Math.min(body.at.y, stillFloor(h, playerId) + bodySize(h).halfHeight + 0.06) };
|
|
385
|
+
h.held.set(playerId, { at, facing: body.facing, seat: 'ground', ground: true });
|
|
386
|
+
h.seated.set(playerId, 'ground');
|
|
387
|
+
h.expressionStill.delete(playerId);
|
|
388
|
+
placeAt(h, playerId, at, body.facing);
|
|
389
|
+
}
|
|
390
|
+
|
|
287
391
|
// `{ k: 'hub-stand' }` from a client: a sitter gets up where they are.
|
|
288
392
|
export function standMessage(h, playerId) {
|
|
289
|
-
if (!idleOf(h)?.seats || !h.sim || !spendSit(h, playerId)) {
|
|
393
|
+
if (!(idleOf(h)?.seats || idleOf(h)?.expression) || !h.sim || !spendSit(h, playerId)) {
|
|
290
394
|
return;
|
|
291
395
|
}
|
|
292
396
|
stand(h, playerId);
|
|
@@ -299,6 +403,7 @@ export function stand(h, playerId) {
|
|
|
299
403
|
}
|
|
300
404
|
h.held.delete(playerId);
|
|
301
405
|
h.seated.delete(playerId);
|
|
406
|
+
h.expressionStill?.delete(playerId);
|
|
302
407
|
return true;
|
|
303
408
|
}
|
|
304
409
|
|
|
@@ -400,9 +505,15 @@ function loopsNow(h) {
|
|
|
400
505
|
// A seat ends when its hold does: the place released the player, held them
|
|
401
506
|
// itself, ended their visit, or they left; or the place hid the seat.
|
|
402
507
|
export function tick(h) {
|
|
508
|
+
if (idleOf(h)?.expression) {
|
|
509
|
+
for (const [id, body] of h.sim.players) { stillSample(h, id, body.at); }
|
|
510
|
+
}
|
|
403
511
|
for (const [playerId, seatId] of [...h.seated]) {
|
|
404
512
|
if (!h.sim.players.has(playerId) || h.held.get(playerId)?.seat !== seatId) {
|
|
405
513
|
h.seated.delete(playerId);
|
|
514
|
+
h.expressionStill?.delete(playerId);
|
|
515
|
+
} else if (h.held.get(playerId)?.ground) {
|
|
516
|
+
continue;
|
|
406
517
|
} else if (h.hidden.has(seatId)) {
|
|
407
518
|
stand(h, playerId);
|
|
408
519
|
} else if (h.place?.decor) {
|
|
@@ -425,7 +536,7 @@ export function fields(h) {
|
|
|
425
536
|
...(h.danceIdleUsed ? { hubDanceIdle: danceIdleNow(h) } : {}),
|
|
426
537
|
...(idle.emotes ? { hubEmotes: emotesNow(h) } : {}),
|
|
427
538
|
...(idle.emotes ? h.npcs?.emoteFields() : {}),
|
|
428
|
-
...(idle.seats ? { hubSeated: seatedNow(h) } : {}),
|
|
539
|
+
...(idle.seats || idle.expression ? { hubSeated: seatedNow(h) } : {}),
|
|
429
540
|
...(idle.sounds.length ? { hubSounds: loopsNow(h) } : {}),
|
|
430
541
|
};
|
|
431
542
|
}
|
|
@@ -453,6 +564,8 @@ function danceIdleNow(h) {
|
|
|
453
564
|
}
|
|
454
565
|
|
|
455
566
|
export function forget(h, playerId) {
|
|
567
|
+
h.roleEmotes?.delete(playerId);
|
|
568
|
+
h.expressionStill?.delete(playerId);
|
|
456
569
|
h.emotes.delete(playerId);
|
|
457
570
|
h.emoteAt.delete(playerId);
|
|
458
571
|
h.seated.delete(playerId);
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import { readUnlocks } from './earned.js';
|
|
11
11
|
import { readQuality } from '../shared/quality.js';
|
|
12
|
+
import { EMOTE_MOTIONS } from '../shared/expression.js';
|
|
12
13
|
import { readDecor } from './decor.js';
|
|
13
14
|
|
|
14
15
|
// Manifest/wire major stays 1; latest optional contract additions are v1.128.
|
|
@@ -46,7 +47,7 @@ export const GRAB_REACH_LIMITS = [1.6, 3, 'metres'];
|
|
|
46
47
|
const GRAB_KEYS = [...Object.keys(GRAB_DEFAULTS), 'reach', 'steady', 'keepHeld'];
|
|
47
48
|
// Idle play (v1.6, §6): emotes, seats and the place's own sounds. Sounds are
|
|
48
49
|
// files of the deck, listed so the server can refuse any other name.
|
|
49
|
-
export const IDLE_KEYS = ['emotes', 'seats', 'sounds'];
|
|
50
|
+
export const IDLE_KEYS = ['emotes', 'seats', 'sounds', 'expression'];
|
|
50
51
|
export const SOUND_EXTS = ['.mp3', '.wav', '.m4a'];
|
|
51
52
|
export const MAX_SOUND_FILES = 16;
|
|
52
53
|
const SOUND_PATH = /^[A-Za-z0-9_@-][A-Za-z0-9_./@-]{0,199}$/;
|
|
@@ -130,7 +131,7 @@ export const SOUNDSCAPE_SURFACES = ['grass', 'street', 'wood', 'stone', 'sand',
|
|
|
130
131
|
// `unlocks` is the deck's (v1.53): the earned items its places may give
|
|
131
132
|
// (`earned.js`). The manifest carries it only when declared, so a deck
|
|
132
133
|
// without it reads as before.
|
|
133
|
-
const TOP_KEYS = ['firstVisit', 'act', 'bringFriend', 'frameBatch', 'defaultEnvironment', 'weakestTier', 'highOnly', 'weakestLookBake', 'pongTimeoutMs', 'contract', 'places', 'interest', 'tiers', 'quality', 'companionIdle', 'lowActorBudget', 'lowActorDistance', 'mergeFarAvatars', 'playOnlyEntry', 'loadTimings', 'loadingCover', 'cues', 'playCards', 'stuck', 'yourGames', 'avatarColors', 'labels', 'safeInsets', 'soundscape', 'unlocks', 'house', 'weeklyCup', ...PLACE_KEYS];
|
|
134
|
+
const TOP_KEYS = ['firstVisit', 'act', 'bringFriend', 'frameBatch', 'defaultEnvironment', 'weakestTier', 'highOnly', 'weakestLookBake', 'pongTimeoutMs', 'contract', 'places', 'interest', 'tiers', 'quality', 'companionIdle', 'lowActorBudget', 'lowActorDistance', 'mergeFarAvatars', 'playOnlyEntry', 'loadTimings', 'loadingCover', 'cues', 'playCards', 'stuck', 'yourGames', 'avatarColors', 'labels', 'safeInsets', 'soundscape', 'unlocks', 'house', 'weeklyCup', 'spawnCap', ...PLACE_KEYS];
|
|
134
135
|
|
|
135
136
|
const DEFAULT_SCENE = 'scenes/main.scene';
|
|
136
137
|
|
|
@@ -202,6 +203,10 @@ export function readManifest(castleJson, sceneExists = () => true) {
|
|
|
202
203
|
if (hub.playCards !== undefined && typeof hub.playCards !== 'boolean') {
|
|
203
204
|
errors.push('hub.playCards must be true or false.');
|
|
204
205
|
}
|
|
206
|
+
// v1.161: a deck may raise hub.spawn's cap on copies alive from 96.
|
|
207
|
+
if (hub.spawnCap !== undefined && (!Number.isInteger(hub.spawnCap) || hub.spawnCap < 96 || hub.spawnCap > 192)) {
|
|
208
|
+
errors.push('hub.spawnCap must be an integer 96..192.');
|
|
209
|
+
}
|
|
205
210
|
if (hub.yourGames !== undefined && typeof hub.yourGames !== 'boolean') {
|
|
206
211
|
errors.push('hub.yourGames must be true or false.');
|
|
207
212
|
}
|
|
@@ -274,7 +279,7 @@ export function readManifest(castleJson, sceneExists = () => true) {
|
|
|
274
279
|
place.idle = { emotes: false, sounds: [], ...place.idle, seats: true };
|
|
275
280
|
}
|
|
276
281
|
}
|
|
277
|
-
return errors.length ? { errors, manifest: null } : { errors, manifest: { contract: CONTRACT_VERSION, ...(quality ? { quality } : {}), ...(hub.act === true ? { act: true } : {}), cues: hub.cues === true, ...(hub.yourGames === true ? { yourGames: true } : {}), ...(hub.avatarColors === true ? { avatarColors: true } : {}), ...(hub.stuck === true ? { stuck: true } : {}), ...(hub.weeklyCup === true ? { weeklyCup: true } : {}), ...(soundscape ? { soundscape } : {}), ...(unlocks ? { unlocks } : {}), ...(house ? { house } : {}), ...(ballot ? { ballot: true } : {}), places } };
|
|
282
|
+
return errors.length ? { errors, manifest: null } : { errors, manifest: { contract: CONTRACT_VERSION, ...(quality ? { quality } : {}), ...(hub.act === true ? { act: true } : {}), cues: hub.cues === true, ...(hub.yourGames === true ? { yourGames: true } : {}), ...(hub.avatarColors === true ? { avatarColors: true } : {}), ...(hub.stuck === true ? { stuck: true } : {}), ...(hub.weeklyCup === true ? { weeklyCup: true } : {}), ...(soundscape ? { soundscape } : {}), ...(unlocks ? { unlocks } : {}), ...(house ? { house } : {}), ...(ballot ? { ballot: true } : {}), ...(hub.spawnCap !== undefined ? { spawnCap: hub.spawnCap } : {}), places } };
|
|
278
283
|
}
|
|
279
284
|
|
|
280
285
|
// `hub.soundscape`: its parts where it is on, null where it is left out or
|
|
@@ -819,6 +824,43 @@ function readIdle(value, where, errors) {
|
|
|
819
824
|
idle[key] = value[key] === true;
|
|
820
825
|
}
|
|
821
826
|
}
|
|
827
|
+
if (value.expression !== undefined) {
|
|
828
|
+
const expression = value.expression;
|
|
829
|
+
if (!idle.emotes) { errors.push(`${where}.expression requires idle.emotes: true.`); }
|
|
830
|
+
if (expression !== true && !isObject(expression)) {
|
|
831
|
+
errors.push(`${where}.expression must be true or an object.`);
|
|
832
|
+
} else {
|
|
833
|
+
if (expression !== true) { unknownKeys(expression, ['roleEmotes'], `${where}.expression`, errors); }
|
|
834
|
+
const roles = expression === true ? [] : (Object.hasOwn(expression, 'roleEmotes') ? expression.roleEmotes : []);
|
|
835
|
+
const ids = new Set(EMOTE_MOTIONS);
|
|
836
|
+
const checked = [];
|
|
837
|
+
if (!Array.isArray(roles) || roles.length > 12) {
|
|
838
|
+
errors.push(`${where}.expression.roleEmotes must be a list of at most 12 emotes.`);
|
|
839
|
+
} else {
|
|
840
|
+
for (const [i, role] of roles.entries()) {
|
|
841
|
+
const at = `${where}.expression.roleEmotes[${i}]`;
|
|
842
|
+
if (!isObject(role)) { errors.push(`${at} must be an object.`); continue; }
|
|
843
|
+
unknownKeys(role, ['id', 'emoji', 'label', 'motion', 'ms'], at, errors);
|
|
844
|
+
if (typeof role.id !== 'string' || !/^[a-z][a-z0-9-]{0,23}$/.test(role.id) || ids.has(role.id)) {
|
|
845
|
+
errors.push(`${at}.id must be a unique short id, distinct from kit emotes.`);
|
|
846
|
+
}
|
|
847
|
+
ids.add(role.id);
|
|
848
|
+
if (typeof role.emoji !== 'string' || role.emoji.length > 8 || !/^(?:\p{Regional_Indicator}{2}|[#*0-9]\uFE0F?\u20E3|\p{Extended_Pictographic}\uFE0F?\p{Emoji_Modifier}?(?:\u200D\p{Extended_Pictographic}\uFE0F?\p{Emoji_Modifier}?)*)$/u.test(role.emoji)) {
|
|
849
|
+
errors.push(`${at}.emoji must be one emoji of at most 8 UTF-16 units.`);
|
|
850
|
+
}
|
|
851
|
+
if (typeof role.label !== 'string' || !role.label.trim() || [...role.label].length > 16) {
|
|
852
|
+
errors.push(`${at}.label must be 1..16 characters.`);
|
|
853
|
+
}
|
|
854
|
+
if (!EMOTE_MOTIONS.includes(role.motion)) { errors.push(`${at}.motion must be a kit motion.`); }
|
|
855
|
+
if (typeof role.ms !== 'number' || !Number.isFinite(role.ms) || role.ms < 1000 || role.ms > 6000) {
|
|
856
|
+
errors.push(`${at}.ms must be 1000..6000.`);
|
|
857
|
+
}
|
|
858
|
+
checked.push({ id: role.id, emoji: role.emoji, label: role.label, motion: role.motion, ms: role.ms });
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
idle.expression = { roleEmotes: checked };
|
|
862
|
+
}
|
|
863
|
+
}
|
|
822
864
|
if (value.sounds !== undefined) {
|
|
823
865
|
const ok =
|
|
824
866
|
Array.isArray(value.sounds) &&
|
|
@@ -1133,7 +1175,7 @@ export function publicPlace(id, place) {
|
|
|
1133
1175
|
// without it is sent exactly what it was.
|
|
1134
1176
|
...(place.grab ? { grab: { ...place.grab } } : {}),
|
|
1135
1177
|
// v1.6: likewise idle play.
|
|
1136
|
-
...(place.idle ? { idle: { emotes: place.idle.emotes, seats: place.idle.seats, sounds: [...place.idle.sounds] } } : {}),
|
|
1178
|
+
...(place.idle ? { idle: { emotes: place.idle.emotes, seats: place.idle.seats, sounds: [...place.idle.sounds], ...(place.idle.expression ? { expression: { roleEmotes: place.idle.expression.roleEmotes.map((role) => ({ ...role })) } } : {}) } } : {}),
|
|
1137
1179
|
// v1.26: likewise the HUD's layout.
|
|
1138
1180
|
...(place.hud ? { hud: { ...place.hud } } : {}),
|
|
1139
1181
|
...(place.decor ? { decor: place.decor } : {}),
|
|
@@ -497,10 +497,12 @@ function say(h, npc, text, { to, ttlMs = SPEECH_MS, about } = {}) {
|
|
|
497
497
|
}
|
|
498
498
|
|
|
499
499
|
function react(h, n, playerId, emote) {
|
|
500
|
+
const aliases = { sleep: 'wave', eat: 'wave', cry: 'wave', laugh: 'cheer', point: 'wave' };
|
|
501
|
+
const reaction = Object.hasOwn(REACTIONS, emote) ? emote : h.place?.idle?.expression && Object.hasOwn(aliases, emote) ? aliases[emote] : null;
|
|
500
502
|
const player = h.sim?.players.get(playerId);
|
|
501
503
|
const entry = h.players?.get(playerId);
|
|
502
504
|
const now = h.sim?.timeMs ?? 0;
|
|
503
|
-
if (!player || (h.players && (!entry?.arrived || entry.ended)) || !
|
|
505
|
+
if (!player || (h.players && (!entry?.arrived || entry.ended)) || !reaction || !n.bodies.size || now - (n.reactAt.get(playerId) ?? -Infinity) < REACT_PLAYER_MS) {
|
|
504
506
|
return;
|
|
505
507
|
}
|
|
506
508
|
n.reactAt.set(playerId, now);
|
|
@@ -521,7 +523,7 @@ function react(h, n, playerId, emote) {
|
|
|
521
523
|
if (override === false) {
|
|
522
524
|
continue;
|
|
523
525
|
}
|
|
524
|
-
const defaults = REACTIONS[
|
|
526
|
+
const defaults = REACTIONS[reaction];
|
|
525
527
|
const props = npc.props.reactions?.[emote];
|
|
526
528
|
let id = reactionEmote(props?.emote, defaults.emote);
|
|
527
529
|
const lines = Array.isArray(props?.lines) ? props.lines.filter((line) => typeof line === 'string').slice(0, 6).map((line) => cleanLine(line, 80)).filter(Boolean) : defaults.lines;
|
|
@@ -16,6 +16,9 @@ import { readPoint } from '@imports/castle.multiplayer-3d/code/server/limits.js'
|
|
|
16
16
|
export function hubPlayers(hub) {
|
|
17
17
|
return {
|
|
18
18
|
...Players,
|
|
19
|
+
setPose(sim, playerId, message) {
|
|
20
|
+
if (hub.allowPlayerPose?.(playerId) !== false) {Players.setPose(sim, playerId, message);}
|
|
21
|
+
},
|
|
19
22
|
addPlayer(sim, playerId, pose) {
|
|
20
23
|
const result = Players.addPlayer(sim, playerId, pose);
|
|
21
24
|
if (!pose || !readPoint(pose)) {
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// Visit-only roles (contract §11, v1.157). No host calls; shared and private
|
|
2
|
+
// whole blocks follow hub.tryOn, including fresh-client RESEND clears.
|
|
3
|
+
import { warnOnce } from './actors.js';
|
|
4
|
+
import { HATS } from '../client/hats.js';
|
|
5
|
+
import { ROLE_TOPS, ROLE_TOOLS } from '../client/role.js';
|
|
6
|
+
|
|
7
|
+
const ID = /^[a-z][a-z0-9-]{0,23}$/;
|
|
8
|
+
const COLOR = /^#[0-9a-f]{6}$/i;
|
|
9
|
+
const KEYS = ['id', 'label', 'color', 'hat', 'top', 'tool'];
|
|
10
|
+
const RESEND = 'resend';
|
|
11
|
+
|
|
12
|
+
export function newRoleState() {
|
|
13
|
+
return { roles: new Map(), roleOwners: new Map(), sentRoleMe: new Map(), roleAloneUsed: false };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function cleanRole(spec) {
|
|
17
|
+
if (spec === null || spec === undefined) { return null; }
|
|
18
|
+
if (typeof spec !== 'object' || Array.isArray(spec) || Object.keys(spec).some((key) => !KEYS.includes(key))) { return undefined; }
|
|
19
|
+
if (typeof spec.id !== 'string' || !ID.test(spec.id) || typeof spec.label !== 'string' ||
|
|
20
|
+
/[\u0000-\u001f\u007f-\u009f\u2028\u2029]/u.test(spec.label) ||
|
|
21
|
+
typeof spec.color !== 'string' || !COLOR.test(spec.color)) { return undefined; }
|
|
22
|
+
const label = spec.label.trim();
|
|
23
|
+
if (!label || [...label].length > 16) { return undefined; }
|
|
24
|
+
const out = { id: spec.id, label, color: spec.color.toLowerCase() };
|
|
25
|
+
for (const [key, list] of [['hat', HATS], ['top', ROLE_TOPS], ['tool', ROLE_TOOLS]]) {
|
|
26
|
+
if (Object.hasOwn(spec, key)) {
|
|
27
|
+
if (!list.includes(spec[key])) { return undefined; }
|
|
28
|
+
out[key] = spec[key];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const present = (h, id) => h.sim?.players.has(id) && h.session?.players.some((p) => p.playerId === id);
|
|
35
|
+
const owner = (h, id) => h.session?.players.find((p) => p.playerId === id)?.userId ?? null;
|
|
36
|
+
|
|
37
|
+
export function role(h, playerId, spec) {
|
|
38
|
+
if (typeof playerId !== 'string' || !(h.players.has(playerId) || h.sim?.players.has(playerId))) {
|
|
39
|
+
warnOnce(h, `role:${playerId}`, `hub.role: "${playerId}" is not a player here`);
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
const clean = cleanRole(spec);
|
|
43
|
+
if (clean === undefined) {
|
|
44
|
+
warnOnce(h, 'role:spec', 'hub.role: expected { id, label, color: "#rrggbb", hat?, top?, tool? } or null');
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
if (clean) {
|
|
48
|
+
h.roles.set(playerId, clean);
|
|
49
|
+
// Absent through a short drop, the visit's record names the account: a
|
|
50
|
+
// role given then belongs to it, and is kept when that account returns.
|
|
51
|
+
if (h.session?.players.some((p) => p.playerId === playerId)) {
|
|
52
|
+
h.roleOwners.set(playerId, owner(h, playerId));
|
|
53
|
+
} else if (!h.roleOwners.has(playerId)) {
|
|
54
|
+
h.roleOwners.set(playerId, h.players.get(playerId)?.userId ?? null);
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
h.roles.delete(playerId);
|
|
58
|
+
h.roleOwners.delete(playerId);
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function roleOf(h, playerId) {
|
|
64
|
+
if (!(h.players.has(playerId) || h.sim?.players.has(playerId))) { return null; }
|
|
65
|
+
if (h.roleOwners.has(playerId) && h.session?.players.some((p) => p.playerId === playerId) && h.roleOwners.get(playerId) !== owner(h, playerId)) {
|
|
66
|
+
h.roles.delete(playerId);
|
|
67
|
+
h.roleOwners.delete(playerId);
|
|
68
|
+
}
|
|
69
|
+
const spec = h.roles.get(playerId);
|
|
70
|
+
return spec ? { ...spec } : null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Retained records survive a short absence; an account change never inherits
|
|
74
|
+
// the old role, including a roster change without a new hello.
|
|
75
|
+
export function prune(h) {
|
|
76
|
+
for (const id of h.roles.keys()) {
|
|
77
|
+
const present = h.session?.players.some((p) => p.playerId === id);
|
|
78
|
+
if ((!h.players.has(id) && !h.sim?.players.has(id)) ||
|
|
79
|
+
(present && h.roleOwners.get(id) !== owner(h, id))) {
|
|
80
|
+
h.roles.delete(id);
|
|
81
|
+
h.roleOwners.delete(id);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
for (const id of h.sentRoleMe.keys()) {
|
|
85
|
+
if (!h.players.has(id) && !h.sim?.players.has(id)) { h.sentRoleMe.delete(id); }
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function rolesOf(h, hidden) {
|
|
90
|
+
prune(h);
|
|
91
|
+
const out = {};
|
|
92
|
+
for (const [id, spec] of h.roles) {
|
|
93
|
+
if (h.players.get(id)?.hello && present(h, id) && !hidden?.has(id)) { out[id] = spec; }
|
|
94
|
+
}
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function sendOverrides(h, hidden) {
|
|
99
|
+
// Absent retained players are kept server-side, but not shown on the wire.
|
|
100
|
+
const shown = new Map([...h.roles].filter(([id]) => present(h, id)));
|
|
101
|
+
sendAlone(h, hidden, shown, h.sentRoleMe, (out) => {
|
|
102
|
+
h.roleAloneUsed = true;
|
|
103
|
+
return { k: 'hub-role', hubRole: out };
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function joinedAfresh(h, playerId) {
|
|
108
|
+
prune(h);
|
|
109
|
+
if (h.roleAloneUsed) { h.sentRoleMe.set(playerId, RESEND); }
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function used(h) { return h.roles.size > 0 || h.sentRoleMe.size > 0; }
|
|
113
|
+
|
|
114
|
+
export function forget(h, playerId) {
|
|
115
|
+
h.roles.delete(playerId);
|
|
116
|
+
h.roleOwners.delete(playerId);
|
|
117
|
+
h.sentRoleMe.delete(playerId);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function end(h) {
|
|
121
|
+
h.roles.clear();
|
|
122
|
+
h.roleOwners.clear();
|
|
123
|
+
h.sentRoleMe.clear();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function sendAlone(h, hidden, worn, sent, message) {
|
|
127
|
+
for (const playerId of h.sim.players.keys()) {
|
|
128
|
+
const out = {};
|
|
129
|
+
for (const shrouded of hidden?.keys() ?? []) {
|
|
130
|
+
const wearable = worn.get(shrouded);
|
|
131
|
+
if (wearable && h.players.get(shrouded)?.hello && !hidden.get(playerId)?.has(shrouded)) {
|
|
132
|
+
out[shrouded] = wearable;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const json = JSON.stringify(out);
|
|
136
|
+
if ((sent.get(playerId) ?? '{}') !== json) {
|
|
137
|
+
sent.set(playerId, json);
|
|
138
|
+
h.session?.send(playerId, message(out));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
@@ -66,7 +66,9 @@ export function bodySize(h) {
|
|
|
66
66
|
// Spawned copies live outside h.actors. Hide/show changes h.hidden at once.
|
|
67
67
|
// hub.move keeps interpolation in h.moves/h.poses and queues a kinematic
|
|
68
68
|
// target; translation/rotation on the body are the pose physics is at now.
|
|
69
|
-
|
|
69
|
+
// Every solid the place has now: scene actors and the copies a game spawned
|
|
70
|
+
// (a House's placed furniture), each at its body's live pose when it has one.
|
|
71
|
+
export function* solids(h) {
|
|
70
72
|
const actors = [...h.actors, ...[...(h.spawned?.values() ?? [])].map((entry) => entry.actor)];
|
|
71
73
|
for (const actor of actors) {
|
|
72
74
|
const c = actor.components;
|
|
@@ -74,7 +76,7 @@ function* solids(h) {
|
|
|
74
76
|
if (c.Player || h.hidden?.has(actor.id) || !(c.Solid || c.Shape?.solid === true) || !c.Shape) {
|
|
75
77
|
continue;
|
|
76
78
|
}
|
|
77
|
-
const body = h.sim
|
|
79
|
+
const body = h.sim?.bodies?.get(actor.id);
|
|
78
80
|
let pose;
|
|
79
81
|
if (body) {
|
|
80
82
|
const p = body.translation();
|
|
@@ -94,7 +96,7 @@ function* solids(h) {
|
|
|
94
96
|
}
|
|
95
97
|
}
|
|
96
98
|
|
|
97
|
-
function footprintHas(shape, pose, at, pad) {
|
|
99
|
+
export function footprintHas(shape, pose, at, pad) {
|
|
98
100
|
const dx = at.x - pose.x;
|
|
99
101
|
const dz = at.z - pose.z;
|
|
100
102
|
if (shape.kind === 'box') {
|
|
@@ -105,7 +107,7 @@ function footprintHas(shape, pose, at, pad) {
|
|
|
105
107
|
return Math.hypot(dx, dz) <= (shape.radius ?? 0.5) + pad;
|
|
106
108
|
}
|
|
107
109
|
|
|
108
|
-
function boundingRadius(shape) {
|
|
110
|
+
export function boundingRadius(shape) {
|
|
109
111
|
if (shape.kind === 'sphere') {
|
|
110
112
|
return shape.radius ?? 0.5;
|
|
111
113
|
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// Car ownership and passenger holds, contract v1.160. No actor or pose stream.
|
|
2
|
+
import { stilled } from './grab.js';
|
|
3
|
+
import { BOUNDS, warnOnce } from './actors.js';
|
|
4
|
+
import { MAX_CARS, parseCar, seatPose } from '../shared/car.js';
|
|
5
|
+
|
|
6
|
+
function present(h, id) {
|
|
7
|
+
const p = h.players.get(id);
|
|
8
|
+
return p?.arrived && !p.ended && !h.resumeDeparting?.has(id) && !h.vehicleDeparting?.has(id) && h.sim?.players.has(id);
|
|
9
|
+
}
|
|
10
|
+
function refuse(h, reason) {
|
|
11
|
+
warnOnce(h, `vehicle:${reason}`, `hub vehicle: ${reason}`);
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
export function vehicle(h, id) {
|
|
15
|
+
const car = h.cars?.get(id);
|
|
16
|
+
if (car) {return { driver: true, car: structuredClone(car) };}
|
|
17
|
+
for (const [of, c] of h.cars ?? []) {
|
|
18
|
+
for (const [seat, rider] of Object.entries(c.riders)) {
|
|
19
|
+
if (rider === id) {return { driver: false, of, seat: Number(seat) };}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
export function riding(h, id) {
|
|
25
|
+
const v = vehicle(h, id);
|
|
26
|
+
return v && !v.driver ? v : null;
|
|
27
|
+
}
|
|
28
|
+
function clamp(h, id) {
|
|
29
|
+
const body = h.sim?.players.get(id);
|
|
30
|
+
if (!body) {return;}
|
|
31
|
+
const car = h.cars?.get(id), t = h.tunes.get(id);
|
|
32
|
+
const factor = t ? Math.max(1, t.speed, t.jump) : 1;
|
|
33
|
+
body.maxSpeed = car ? Math.max(car.speed, car.reverse) : factor === 1 ? undefined : (h.engine?.maxSpeed?.() ?? 12) * factor;
|
|
34
|
+
}
|
|
35
|
+
function poseOf(h, id) {
|
|
36
|
+
const body = h.sim?.players.get(id);
|
|
37
|
+
return body ? { at: { ...body.at }, facing: body.facing } : h.carPoses?.get(id);
|
|
38
|
+
}
|
|
39
|
+
function exitAt(h, id, car, seat, pose, placeAt) {
|
|
40
|
+
if (pose) {placeAt(id, seatPose(pose.at, pose.facing, car, seat, 1.6), pose.facing);}
|
|
41
|
+
}
|
|
42
|
+
export function ride(h, id, driver, seat, placeAt) {
|
|
43
|
+
const current = riding(h, id);
|
|
44
|
+
if (driver === null) {
|
|
45
|
+
if (!current) {return false;}
|
|
46
|
+
const car = h.cars.get(current.of), pose = poseOf(h, current.of);
|
|
47
|
+
delete car.riders[current.seat];
|
|
48
|
+
if (h.held.get(id)?.vehicle === current.of) {h.held.delete(id);}
|
|
49
|
+
exitAt(h, id, car, current.seat, pose, placeAt);
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
const car = h.cars?.get(driver), body = h.sim?.players.get(id), pose = poseOf(h, driver);
|
|
53
|
+
if (!present(h, id) || !present(h, driver) || !car || !Number.isInteger(seat) || seat < 1 || seat >= car.seats.length || car.riders[seat] || h.held.has(id) || vehicle(h, id) || !pose || Math.hypot(body.at.x - pose.at.x, body.at.y - pose.at.y, body.at.z - pose.at.z) > 6) {
|
|
54
|
+
return refuse(h, 'ride requires a free seat, an unheld walker and a present driver within 6 m');
|
|
55
|
+
}
|
|
56
|
+
stilled(h, id);
|
|
57
|
+
car.riders[seat] = id;
|
|
58
|
+
const at = seatPose(pose.at, pose.facing, car, seat);
|
|
59
|
+
h.held.set(id, { at, facing: pose.facing, vehicle: driver });
|
|
60
|
+
placeAt(id, at, pose.facing);
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
export function drive(h, id, spec, at, placeAt) {
|
|
64
|
+
if (spec === null) {
|
|
65
|
+
const car = h.cars?.get(id);
|
|
66
|
+
if (!car) {return false;}
|
|
67
|
+
const pose = poseOf(h, id);
|
|
68
|
+
let asked = null;
|
|
69
|
+
if (at !== undefined) {
|
|
70
|
+
asked = { x: at?.x, y: at?.y ?? pose?.at.y, z: at?.z };
|
|
71
|
+
if (![asked.x, asked.y, asked.z].every(Number.isFinite) || Math.abs(asked.x) > BOUNDS.xz || Math.abs(asked.z) > BOUNDS.xz || asked.y < BOUNDS.low || asked.y > BOUNDS.high || (at.facing !== undefined && !Number.isFinite(at.facing))) {return refuse(h, 'get-out point must be inside the world');}
|
|
72
|
+
}
|
|
73
|
+
for (const rider of Object.values(car.riders)) {ride(h, rider, null, undefined, placeAt);}
|
|
74
|
+
h.cars.delete(id);
|
|
75
|
+
h.carPoses.delete(id);
|
|
76
|
+
h.carHornAt.delete(id);
|
|
77
|
+
clamp(h, id);
|
|
78
|
+
if (asked) {placeAt(id, asked, at.facing === undefined ? pose?.facing : at.facing * Math.PI / 180);}
|
|
79
|
+
else {exitAt(h, id, car, 0, pose, placeAt);}
|
|
80
|
+
const hold = h.held.get(id), body = h.sim?.players.get(id);
|
|
81
|
+
if (hold && body) {hold.at = { ...body.at }; hold.facing = body.facing;}
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
const car = parseCar(spec), old = h.cars?.get(id);
|
|
85
|
+
if (!present(h, id) || h.held.has(id) || riding(h, id)) {return refuse(h, 'drive requires an arrived unheld player outside a trip');}
|
|
86
|
+
if (!car || !h.actors.some(a => a.id === car.look && a.components?.Model)) {return refuse(h, 'car requires a scene Model look and a valid spec');}
|
|
87
|
+
if (car.horn && !h.place?.idle?.sounds?.includes(car.horn)) {return refuse(h, 'horn must be listed in idle.sounds');}
|
|
88
|
+
if (!old && (h.cars?.size ?? 0) >= MAX_CARS) {return refuse(h, 'at most 24 cars');}
|
|
89
|
+
if (old && Object.keys(old.riders).some(s => Number(s) >= car.seats.length)) {return refuse(h, 'replacement car must keep occupied seats');}
|
|
90
|
+
h.cars ??= new Map(); h.carPoses ??= new Map(); h.carHornAt ??= new Map();
|
|
91
|
+
stilled(h, id);
|
|
92
|
+
h.cars.set(id, { ...car, riders: { ...old?.riders } });
|
|
93
|
+
h.carPoses.set(id, poseOf(h, id));
|
|
94
|
+
clamp(h, id);
|
|
95
|
+
tick(h, placeAt);
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
// Runs before holds and again after authored hooks, so snapshots and retained
|
|
99
|
+
// disconnect poses see seats from the current driver pose, never an old hold.
|
|
100
|
+
export function tick(h, placeAt) {
|
|
101
|
+
for (const [id, car] of h.cars ?? []) {
|
|
102
|
+
const pose = poseOf(h, id);
|
|
103
|
+
if (!pose) {continue;}
|
|
104
|
+
h.carPoses.set(id, pose);
|
|
105
|
+
clamp(h, id);
|
|
106
|
+
for (const [seat, rider] of Object.entries(car.riders)) {
|
|
107
|
+
const at = seatPose(pose.at, pose.facing, car, Number(seat));
|
|
108
|
+
h.held.set(rider, { at, facing: pose.facing, vehicle: id });
|
|
109
|
+
placeAt(rider, at, pose.facing);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
export function forget(h, id, placeAt) {
|
|
114
|
+
if (h.cars?.has(id)) {drive(h, id, null, undefined, placeAt);}
|
|
115
|
+
else if (riding(h, id)) {ride(h, id, null, undefined, placeAt);}
|
|
116
|
+
}
|
|
117
|
+
export function fields(h) {
|
|
118
|
+
return h.cars?.size ? { hubCars: Object.fromEntries([...h.cars].map(([id, car]) => [id, structuredClone(car)])) } : {};
|
|
119
|
+
}
|
|
120
|
+
export function horn(h, id) {
|
|
121
|
+
const car = h.cars?.get(id), now = h.sim?.timeMs ?? 0;
|
|
122
|
+
if (!car?.horn || !present(h, id) || now - (h.carHornAt.get(id) ?? -Infinity) < 1000) {return;}
|
|
123
|
+
h.carHornAt.set(id, now);
|
|
124
|
+
// The existing sound event, with a player source rather than a scene actor.
|
|
125
|
+
h.session?.broadcast({ k: 'hub-sound', player: id, file: car.horn, volume: 1, radius: 20 });
|
|
126
|
+
}
|