castle-web-cli 0.4.232 → 0.4.233
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/agent-failures.d.ts +8 -0
- package/dist/agent-failures.js +19 -2
- package/dist/agent-prompts.d.ts +1 -1
- package/dist/agent-prompts.js +10 -3
- package/dist/agent.d.ts +64 -3
- package/dist/agent.js +170 -81
- package/dist/castle-host/host.d.ts +1 -0
- package/dist/castle-host/host.js +51 -3
- package/dist/castleJson.d.ts +4 -2
- package/dist/castleJson.js +2 -0
- package/dist/check.d.ts +3 -1
- package/dist/check.js +11 -1
- package/dist/devSessionStorage.js +47 -1
- package/dist/importPinMismatch.d.ts +22 -0
- package/dist/importPinMismatch.js +77 -0
- package/dist/importRegression.js +3 -15
- package/dist/imports.d.ts +10 -3
- package/dist/imports.js +88 -20
- package/dist/index.js +5 -4
- package/dist/init.js +1 -1
- package/dist/platformDoc.js +22 -0
- package/dist/routerFences.d.ts +5 -0
- package/dist/routerFences.js +12 -2
- package/dist/save-deck.d.ts +5 -0
- package/dist/save-deck.js +37 -4
- package/dist/serve.js +3 -0
- package/dist/shell/assets/{index-D2tWM896.js → index-BjOxR-lW.js} +4 -4
- package/dist/shell/assets/index-MVLfNYd9.css +1 -0
- package/dist/shell/index.html +2 -2
- package/dist/taskSteer.d.ts +13 -0
- package/dist/taskSteer.js +22 -2
- package/kits/base/castle.json +1 -1
- package/kits/base/package-lock.json +1 -1
- package/kits/base/sdk/README.md +79 -2
- package/kits/base/sdk/avatar.d.ts +6 -2
- package/kits/base/sdk/avatar.js +12 -4
- package/kits/base/sdk/castle.d.ts +1 -1
- package/kits/base/sdk/commands.d.ts +14 -0
- package/kits/base/sdk/hub.d.ts +6 -2
- package/kits/base/sdk/hub.js +13 -0
- package/kits/base/sdk/multiplayer.js +17 -1
- package/kits/base/sdk/save.js +2 -1
- package/kits/base/sdk/server/hub.d.ts +87 -0
- package/kits/base/sdk/server/hub.js +70 -0
- package/kits/base/sdk/server/platformHandle.d.ts +31 -1
- package/kits/base/sdk/server/storage.d.ts +13 -0
- package/kits/base/sdk/server/storage.js +46 -0
- package/kits/base/sdk/server/wrapper.d.ts +36 -5
- package/kits/base/sdk/server/wrapper.js +83 -8
- package/kits/hub-game/CLAUDE.md +329 -11
- package/kits/hub-game/blueprints/avatar-10.scene +28 -0
- package/kits/hub-game/blueprints/avatar-11.scene +28 -0
- package/kits/hub-game/blueprints/avatar-12.scene +28 -0
- package/kits/hub-game/blueprints/avatar-13.scene +28 -0
- package/kits/hub-game/blueprints/avatar-14.scene +28 -0
- package/kits/hub-game/blueprints/avatar-15.scene +28 -0
- package/kits/hub-game/blueprints/avatar-4.scene +28 -0
- package/kits/hub-game/blueprints/avatar-5.scene +28 -0
- package/kits/hub-game/blueprints/avatar-6.scene +28 -0
- package/kits/hub-game/blueprints/avatar-7.scene +28 -0
- package/kits/hub-game/blueprints/avatar-8.scene +28 -0
- package/kits/hub-game/blueprints/avatar-9.scene +28 -0
- package/kits/hub-game/code/client/actorBudget.js +47 -0
- package/kits/hub-game/code/client/attention.js +11 -2
- package/kits/hub-game/code/client/avatar.js +309 -35
- package/kits/hub-game/code/client/avatarCap.js +228 -0
- package/kits/hub-game/code/client/avatarColors.js +70 -0
- package/kits/hub-game/code/client/avatarFaces.js +21 -0
- package/kits/hub-game/code/client/avatarShare.js +251 -0
- package/kits/hub-game/code/client/ballot.js +467 -0
- package/kits/hub-game/code/client/build.js +22 -0
- package/kits/hub-game/code/client/chrome.js +1144 -50
- package/kits/hub-game/code/client/companion.js +716 -0
- package/kits/hub-game/code/client/companionDress.js +99 -0
- package/kits/hub-game/code/client/decor.js +509 -0
- package/kits/hub-game/code/client/earned.js +131 -0
- package/kits/hub-game/code/client/emoteBubble.js +75 -0
- package/kits/hub-game/code/client/grab.js +339 -20
- package/kits/hub-game/code/client/hookLayer.js +299 -13
- package/kits/hub-game/code/client/idle.js +163 -22
- package/kits/hub-game/code/client/interestCap.js +81 -0
- package/kits/hub-game/code/client/keys.js +36 -0
- package/kits/hub-game/code/client/labelsNear.js +205 -0
- package/kits/hub-game/code/client/menuIcons.js +34 -0
- package/kits/hub-game/code/client/pack.js +6 -2
- package/kits/hub-game/code/client/packFormat.js +3 -3
- package/kits/hub-game/code/client/rehello.js +167 -0
- package/kits/hub-game/code/client/shot.js +92 -0
- package/kits/hub-game/code/client/sound.js +63 -8
- package/kits/hub-game/code/client/soundscape.js +1151 -0
- package/kits/hub-game/code/client/soundscapeActions.js +99 -0
- package/kits/hub-game/code/client/soundscapeAmbience.js +453 -0
- package/kits/hub-game/code/client/soundscapeBaked.js +143 -0
- package/kits/hub-game/code/client/soundscapeBusker.js +217 -0
- package/kits/hub-game/code/client/soundscapeCourt.js +200 -0
- package/kits/hub-game/code/client/soundscapeCrowd.js +331 -0
- package/kits/hub-game/code/client/soundscapeCues.js +362 -0
- package/kits/hub-game/code/client/soundscapeMap.js +181 -0
- package/kits/hub-game/code/client/soundscapeMarket.js +176 -0
- package/kits/hub-game/code/client/soundscapeMusic.js +126 -0
- package/kits/hub-game/code/client/soundscapeMusicEngine.js +460 -0
- package/kits/hub-game/code/client/soundscapeSimlish.js +737 -0
- package/kits/hub-game/code/client/soundscapeSongs.js +127 -0
- package/kits/hub-game/code/client/soundscapeSongsRound3.js +63 -0
- package/kits/hub-game/code/client/soundscapeSynthesis.js +168 -0
- package/kits/hub-game/code/client/soundscapeUi.js +211 -0
- package/kits/hub-game/code/client/soundscapeVoice.js +1209 -0
- package/kits/hub-game/code/client/soundscapeWaves.js +206 -0
- package/kits/hub-game/code/client/spin.js +101 -0
- package/kits/hub-game/code/client/state.js +109 -1
- package/kits/hub-game/code/client/stuck.js +259 -0
- package/kits/hub-game/code/client/talk.js +538 -47
- package/kits/hub-game/code/client/tiers.js +516 -27
- package/kits/hub-game/code/client/toastBand.js +37 -0
- package/kits/hub-game/code/client/together.js +32 -0
- package/kits/hub-game/code/client/visibility.js +43 -0
- package/kits/hub-game/code/client/wear.js +461 -170
- package/kits/hub-game/code/client/yours.js +199 -0
- package/kits/hub-game/code/companionSpec.js +45 -0
- package/kits/hub-game/code/privateText.js +7 -0
- package/kits/hub-game/code/server/actions.js +133 -0
- package/kits/hub-game/code/server/actors.js +9 -1
- package/kits/hub-game/code/server/ask.js +155 -0
- package/kits/hub-game/code/server/ballot.js +539 -0
- package/kits/hub-game/code/server/cells.js +100 -0
- package/kits/hub-game/code/server/companion.js +82 -0
- package/kits/hub-game/code/server/cues.js +70 -0
- package/kits/hub-game/code/server/decor.js +269 -0
- package/kits/hub-game/code/server/earned.js +461 -0
- package/kits/hub-game/code/server/friendBests.js +166 -0
- package/kits/hub-game/code/server/friendsAmong.js +232 -0
- package/kits/hub-game/code/server/history.js +5 -0
- package/kits/hub-game/code/server/hub.js +1254 -50
- package/kits/hub-game/code/server/idle.js +30 -11
- package/kits/hub-game/code/server/index.js +2 -2
- package/kits/hub-game/code/server/labels.js +28 -2
- package/kits/hub-game/code/server/manifest.js +378 -7
- package/kits/hub-game/code/server/menu.js +133 -0
- package/kits/hub-game/code/server/npcs.js +830 -80
- package/kits/hub-game/code/server/party.js +2 -2
- package/kits/hub-game/code/server/players.js +22 -0
- package/kits/hub-game/code/server/shot.js +110 -0
- package/kits/hub-game/code/server/standing.js +124 -0
- package/kits/hub-game/code/server/vis.js +113 -0
- package/kits/hub-game/code/server/wear.js +12 -0
- package/kits/hub-game/code/server/yours.js +59 -0
- package/kits/hub-game/code/shared/cues.js +9 -0
- package/kits/hub-game/code/shared/decor.js +41 -0
- package/kits/hub-game/code/shared/shot.js +19 -0
- package/kits/hub-game/code/shared/spin.js +57 -0
- package/kits/hub-game/code/systems/hub.js +845 -95
- package/kits/hub-game/docs/content-pack.md +1 -1
- package/kits/hub-game/docs/contract.md +2244 -61
- package/kits/hub-game/docs/home-pieces.md +64 -0
- package/kits/hub-game/models/avatar-10.pxmodel +28 -0
- package/kits/hub-game/models/avatar-11.pxmodel +28 -0
- package/kits/hub-game/models/avatar-12.pxmodel +27 -0
- package/kits/hub-game/models/avatar-13.pxmodel +24 -0
- package/kits/hub-game/models/avatar-14.pxmodel +29 -0
- package/kits/hub-game/models/avatar-15.pxmodel +24 -0
- package/kits/hub-game/models/avatar-4.pxmodel +29 -0
- package/kits/hub-game/models/avatar-5.pxmodel +27 -0
- package/kits/hub-game/models/avatar-6.pxmodel +26 -0
- package/kits/hub-game/models/avatar-7.pxmodel +25 -0
- package/kits/hub-game/models/avatar-8.pxmodel +24 -0
- package/kits/hub-game/models/avatar-9.pxmodel +30 -0
- package/kits/hub-game/models/earned/badge-round.pxmodel +100 -0
- package/kits/hub-game/models/earned/badge-shield.pxmodel +117 -0
- package/kits/hub-game/models/earned/badge-star.pxmodel +87 -0
- package/kits/hub-game/models/earned/belt-plain.pxmodel +72 -0
- package/kits/hub-game/models/earned/held-ball.pxmodel +43 -0
- package/kits/hub-game/models/earned/held-lantern.pxmodel +85 -0
- package/kits/hub-game/models/earned/held-net.pxmodel +57 -0
- package/kits/hub-game/models/earned/held-trophy.pxmodel +109 -0
- package/kits/hub-game/models/earned/pin-round.pxmodel +62 -0
- package/kits/hub-game/models/earned/sash-plain.pxmodel +66 -0
- package/kits/hub-game/models/earned/square/belt-plain.pxmodel +104 -0
- package/kits/hub-game/models/earned/square/sash-plain.pxmodel +98 -0
- package/kits/hub-game/models/hats/bat-clip.pxmodel +206 -0
- package/kits/hub-game/models/hats/beekeeper.pxmodel +149 -0
- package/kits/hub-game/models/hats/cap.pxmodel +162 -0
- package/kits/hub-game/models/hats/captain.pxmodel +178 -0
- package/kits/hub-game/models/hats/crooked-top.pxmodel +172 -0
- package/kits/hub-game/models/hats/flower-crown.pxmodel +451 -0
- package/kits/hub-game/models/hats/foam-crown.pxmodel +179 -0
- package/kits/hub-game/models/hats/lantern.pxmodel +230 -0
- package/kits/hub-game/models/hats/laurel.pxmodel +533 -0
- package/kits/hub-game/models/hats/lighthouse.pxmodel +96 -0
- package/kits/hub-game/models/hats/sailor.pxmodel +141 -0
- package/kits/hub-game/models/hats/souwester.pxmodel +131 -0
- package/kits/hub-game/models/hats/straw.pxmodel +139 -0
- package/kits/hub-game/models/hats/sunflower.pxmodel +406 -0
- package/kits/hub-game/models/hats/sweatband.pxmodel +112 -0
- package/kits/hub-game/models/hats/witch.pxmodel +147 -0
- package/kits/hub-game/package-lock.json +2 -0
- package/kits/hub-game/package.json +2 -1
- package/kits/hub-game/scripts/check.mjs +78 -11
- package/kits/hub-game/scripts/companion-follower-wire.json +1 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +121 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless.json +293 -0
- package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +23 -0
- package/kits/hub-game/scripts/fixtures/fake-dom.mjs +107 -0
- package/kits/hub-game/scripts/fixtures/interest-legacy.json +385 -0
- package/kits/hub-game/scripts/fixtures/npc-notes-v1.77.jsonl +4 -0
- package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -0
- package/kits/hub-game/scripts/gen-avatars.mjs +933 -16
- package/kits/hub-game/scripts/gen-earned.mjs +285 -0
- package/kits/hub-game/scripts/gen-hats.mjs +827 -0
- package/kits/hub-game/scripts/grab.before-orbit.mjs +400 -0
- package/kits/hub-game/scripts/soundscape-wave-analysis.mjs +125 -0
- package/kits/hub-game/scripts/test-actions-client.mjs +488 -0
- package/kits/hub-game/scripts/test-actions.mjs +298 -0
- package/kits/hub-game/scripts/test-actor-budget.mjs +44 -0
- package/kits/hub-game/scripts/test-actors.mjs +19 -17
- package/kits/hub-game/scripts/test-ask-client.mjs +358 -0
- package/kits/hub-game/scripts/test-ask.mjs +269 -0
- package/kits/hub-game/scripts/test-attention.mjs +10 -1
- package/kits/hub-game/scripts/test-avatar-cap.mjs +379 -0
- package/kits/hub-game/scripts/test-avatar-colors.mjs +72 -0
- package/kits/hub-game/scripts/test-avatar-models.mjs +181 -0
- package/kits/hub-game/scripts/test-avatar-share.mjs +318 -0
- package/kits/hub-game/scripts/test-avatar-wire.mjs +753 -0
- package/kits/hub-game/scripts/test-avatar.mjs +540 -7
- package/kits/hub-game/scripts/test-ballot.mjs +1001 -0
- package/kits/hub-game/scripts/test-build.mjs +31 -0
- package/kits/hub-game/scripts/test-cells.mjs +71 -0
- package/kits/hub-game/scripts/test-chat.mjs +662 -0
- package/kits/hub-game/scripts/test-classic.mjs +2 -0
- package/kits/hub-game/scripts/test-companion-chat.mjs +198 -0
- package/kits/hub-game/scripts/test-companion-client.mjs +1167 -0
- package/kits/hub-game/scripts/test-companion.mjs +259 -0
- package/kits/hub-game/scripts/test-decor-client.mjs +303 -0
- package/kits/hub-game/scripts/test-decor.mjs +457 -0
- package/kits/hub-game/scripts/test-earned-client.mjs +459 -0
- package/kits/hub-game/scripts/test-earned.mjs +1194 -0
- package/kits/hub-game/scripts/test-emote-bubble.mjs +110 -0
- package/kits/hub-game/scripts/test-friend-bests.mjs +435 -0
- package/kits/hub-game/scripts/test-grab-orbit.mjs +918 -0
- package/kits/hub-game/scripts/test-grab.mjs +7 -0
- package/kits/hub-game/scripts/test-hats.mjs +422 -168
- package/kits/hub-game/scripts/test-hub-leaving.mjs +203 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +439 -2
- package/kits/hub-game/scripts/test-hub-trip.mjs +716 -2
- package/kits/hub-game/scripts/test-hud-clear.mjs +328 -4
- package/kits/hub-game/scripts/test-idle.mjs +361 -1
- package/kits/hub-game/scripts/test-interest-cap.mjs +36 -0
- package/kits/hub-game/scripts/test-interest-cells.mjs +493 -0
- package/kits/hub-game/scripts/test-interest-client.mjs +118 -0
- package/kits/hub-game/scripts/test-keys.mjs +46 -1
- package/kits/hub-game/scripts/test-labels.mjs +596 -0
- package/kits/hub-game/scripts/test-manifest.mjs +207 -0
- package/kits/hub-game/scripts/test-menu-client.mjs +480 -0
- package/kits/hub-game/scripts/test-menu.mjs +296 -0
- package/kits/hub-game/scripts/test-npcs.mjs +1718 -12
- package/kits/hub-game/scripts/test-object-entry.mjs +76 -0
- package/kits/hub-game/scripts/test-pack.mjs +7 -0
- package/kits/hub-game/scripts/test-picker.mjs +314 -0
- package/kits/hub-game/scripts/test-rehello.mjs +1039 -0
- package/kits/hub-game/scripts/test-relations-among.mjs +222 -0
- package/kits/hub-game/scripts/test-relations-refresh.mjs +188 -0
- package/kits/hub-game/scripts/test-shot.mjs +756 -0
- package/kits/hub-game/scripts/test-soundscape.mjs +5432 -0
- package/kits/hub-game/scripts/test-spin.mjs +314 -0
- package/kits/hub-game/scripts/test-standing.mjs +416 -0
- package/kits/hub-game/scripts/test-stuck.mjs +1903 -0
- package/kits/hub-game/scripts/test-tier-cells.mjs +706 -0
- package/kits/hub-game/scripts/test-tiers-render.mjs +339 -0
- package/kits/hub-game/scripts/test-tiers.mjs +477 -2
- package/kits/hub-game/scripts/test-toast-band.mjs +61 -0
- package/kits/hub-game/scripts/test-try-on.mjs +22 -22
- package/kits/hub-game/scripts/test-vis.mjs +343 -0
- package/kits/hub-game/scripts/test-visibility.mjs +134 -0
- package/kits/hub-game/scripts/test-yours-chrome.mjs +166 -0
- package/kits/hub-game/scripts/test-yours.mjs +372 -0
- package/kits/multiplayer-3d/CLAUDE.md +50 -0
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/avatars.js +7 -0
- package/kits/multiplayer-3d/code/client/gait.js +65 -0
- package/kits/multiplayer-3d/code/client/nameTags.js +59 -4
- package/kits/multiplayer-3d/code/options.js +5 -0
- package/kits/multiplayer-3d/code/server/ownership.js +10 -2
- package/kits/multiplayer-3d/code/server/sceneBodies.js +12 -0
- package/kits/multiplayer-3d/code/server/world.js +7 -0
- package/kits/multiplayer-3d/code/systems/multiplayer.js +74 -4
- package/kits/multiplayer-3d/package.json +2 -1
- package/kits/multiplayer-3d/scripts/fixtures/README.md +11 -0
- package/kits/multiplayer-3d/scripts/fixtures/ownership-legacy.json +2 -0
- package/kits/multiplayer-3d/scripts/ownership-harness.mjs +102 -0
- package/kits/multiplayer-3d/scripts/ownership-loader.mjs +46 -0
- package/kits/multiplayer-3d/scripts/ownership-worker.mjs +15 -0
- package/kits/multiplayer-3d/scripts/record-ownership-session.mjs +98 -0
- package/kits/multiplayer-3d/scripts/test-eligible-claims.mjs +167 -0
- package/kits/multiplayer-3d/scripts/test-own-name-tag.mjs +247 -0
- package/kits/physics-2d/CLAUDE.md +9 -0
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/scene.js +253 -1
- package/kits/physics-2d/engine/skyKey.js +129 -0
- package/kits/physics-2d/engine/stillClock.js +106 -0
- package/kits/physics-2d/engine/updateBudget.js +21 -0
- package/kits/physics-2d/scripts/test-skip-unchanged.mjs +326 -1
- package/kits/physics-3d/CLAUDE.md +1169 -30
- package/kits/physics-3d/behaviors/Player.jsx +629 -72
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/docs/pxmodel-format.md +8 -0
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +69 -13
- package/kits/physics-3d/engine3d/actornode.js +86 -0
- package/kits/physics-3d/engine3d/animationBudget.js +23 -0
- package/kits/physics-3d/engine3d/editorWorld.js +6 -0
- package/kits/physics-3d/engine3d/emptynodes.js +232 -0
- package/kits/physics-3d/engine3d/framecap.js +96 -0
- package/kits/physics-3d/engine3d/gait.js +118 -0
- package/kits/physics-3d/engine3d/kithooks.js +47 -0
- package/kits/physics-3d/engine3d/look.js +507 -48
- package/kits/physics-3d/engine3d/lookbake.js +208 -0
- package/kits/physics-3d/engine3d/materialpresets.js +2 -0
- package/kits/physics-3d/engine3d/motion.js +39 -10
- package/kits/physics-3d/engine3d/nearshadows.js +37 -19
- package/kits/physics-3d/engine3d/optimize.js +9 -5
- package/kits/physics-3d/engine3d/orbitinput.js +487 -9
- package/kits/physics-3d/engine3d/orbitlens.js +48 -0
- package/kits/physics-3d/engine3d/ownmodel.js +213 -0
- package/kits/physics-3d/engine3d/pxmodel.js +42 -11
- package/kits/physics-3d/engine3d/shadowfade.js +882 -0
- package/kits/physics-3d/engine3d/sky.js +547 -0
- package/kits/physics-3d/engine3d/skylife.js +306 -0
- package/kits/physics-3d/engine3d/unchanged.js +11 -0
- package/kits/physics-3d/engine3d/viewrange.js +52 -0
- package/kits/physics-3d/engine3d/world3d.js +796 -69
- package/kits/physics-3d/main.jsx +5 -0
- package/kits/physics-3d/package.json +1 -1
- package/kits/physics-3d/scripts/look-baseline.mjs +155 -0
- package/kits/physics-3d/scripts/test-camera-orbit.mjs +2563 -80
- package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +1 -1
- package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +435 -0
- package/kits/physics-3d/scripts/test-frame-cap.mjs +452 -0
- package/kits/physics-3d/scripts/test-gait.mjs +387 -0
- package/kits/physics-3d/scripts/test-look-bake.mjs +1056 -0
- package/kits/physics-3d/scripts/test-model-parse-cache.mjs +92 -0
- package/kits/physics-3d/scripts/test-near-shadows.mjs +3 -0
- package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1920 -0
- package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +545 -0
- package/kits/physics-3d/scripts/test-orbit-shot.mjs +583 -0
- package/kits/physics-3d/scripts/test-orbit-view.mjs +230 -0
- package/kits/physics-3d/scripts/test-skip-empty-nodes.mjs +845 -0
- package/kits/physics-3d/scripts/test-sky.mjs +2470 -0
- package/kits/physics-3d/scripts/test-static-actors.mjs +8 -1
- package/kits/physics-3d/scripts/test-static-scenery.mjs +2171 -0
- package/kits/physics-3d/scripts/test-steady-hover.mjs +2 -0
- package/kits/physics-3d/scripts/test-view-range.mjs +260 -0
- package/kits/physics-3d/systems/physics3d.js +383 -6
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/server/gameHooks.js +7 -0
- package/kits/real-time/code/server/session.js +97 -19
- package/package.json +2 -2
- package/dist/shell/assets/index-Cf61cNfT.css +0 -1
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// Earned items (contract §11, v1.53): the second wearable slot. A hub game
|
|
2
|
+
// declares the small things it gives for a stated deed in its castle.json
|
|
3
|
+
// (`hub.unlocks`), gives one with `hub.unlock(playerId, id)`, and the town
|
|
4
|
+
// alone chooses which one a player shows. Each player shows at most one, drawn
|
|
5
|
+
// beside whatever the Look slot (`hub.wear`) puts on the head: a badge or pin
|
|
6
|
+
// on the chest, a belt round the waist, a sash across the torso, or a small
|
|
7
|
+
// thing held in the right hand.
|
|
8
|
+
//
|
|
9
|
+
// The place sends playerId -> `{ class, shape, color, name }` (`hubEarned`, and
|
|
10
|
+
// `hub-earned` alone for a hidden pair, as `hubWear` / `hub-wear`), and
|
|
11
|
+
// `makeEarned` draws each under the avatar's own node, as `wear.js` draws a
|
|
12
|
+
// hat: so it moves, turns and hides with the avatar, and nothing is sent or
|
|
13
|
+
// made as an actor. Nothing here runs for a place where nobody shows one.
|
|
14
|
+
//
|
|
15
|
+
// The shapes are the kit's models, `models/earned/<shape>.pxmodel`
|
|
16
|
+
// (scripts/gen-earned.mjs), with the avatars' outline look. The item's colour
|
|
17
|
+
// takes the place of the model's main colour (`EARNED_MAIN`, which only main
|
|
18
|
+
// materials carry); trims keep theirs. A shape this kit has no model of, or a
|
|
19
|
+
// shape drawn for another class than the item's, is kept and not drawn.
|
|
20
|
+
//
|
|
21
|
+
// The lists below import nothing, so a place's server may read them
|
|
22
|
+
// (`@imports/castle.hub-game/code/client/earned.js`) to check a declaration
|
|
23
|
+
// against exactly what every client can draw, as it reads `hats.js` `HATS`.
|
|
24
|
+
|
|
25
|
+
export const EARNED_CLASSES = ['badge', 'pin', 'belt', 'sash', 'held'];
|
|
26
|
+
|
|
27
|
+
// Each shape and the class it is drawn for. A badge's shape may be pinned and
|
|
28
|
+
// a pin's worn as a badge: both sit on the chest.
|
|
29
|
+
export const EARNED_SHAPE_CLASS = {
|
|
30
|
+
'badge-round': 'badge',
|
|
31
|
+
'badge-star': 'badge',
|
|
32
|
+
'badge-shield': 'badge',
|
|
33
|
+
'pin-round': 'pin',
|
|
34
|
+
'belt-plain': 'belt',
|
|
35
|
+
'sash-plain': 'sash',
|
|
36
|
+
'held-lantern': 'held',
|
|
37
|
+
'held-trophy': 'held',
|
|
38
|
+
'held-net': 'held',
|
|
39
|
+
'held-ball': 'held',
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const EARNED_SHAPES = Object.keys(EARNED_SHAPE_CLASS);
|
|
43
|
+
|
|
44
|
+
// The colour the models' main materials are written in, replaced by the item's.
|
|
45
|
+
export const EARNED_MAIN = '#3aa0d8';
|
|
46
|
+
|
|
47
|
+
export const earnedFile = (shape, square = false) => `models/earned/${square ? 'square/' : ''}${shape}.pxmodel`;
|
|
48
|
+
// The ring shapes that have a square model for a boxy body.
|
|
49
|
+
export const SQUARE_SHAPES = ['belt-plain', 'sash-plain'];
|
|
50
|
+
|
|
51
|
+
const COLOR = /^#[0-9a-f]{6}$/i;
|
|
52
|
+
const CHEST = new Set(['badge', 'pin']);
|
|
53
|
+
// The model's feet stand this far under the avatar's origin (wear.js).
|
|
54
|
+
const MODEL_FEET_Y = -0.7;
|
|
55
|
+
// Each ring model (a belt, a sash) is made 0.2 m out from its middle and
|
|
56
|
+
// stretched to the body it goes round.
|
|
57
|
+
const RING_R = 0.2;
|
|
58
|
+
// Badges are drawn this much bigger than their models and pins this much, so
|
|
59
|
+
// they read across a street as the halos they replace did.
|
|
60
|
+
export const BADGE_SCALE = 2.6;
|
|
61
|
+
export const PIN_SCALE = 2.1;
|
|
62
|
+
// A badge has a soft glow in its colour behind it (`wear.js` draws it), this
|
|
63
|
+
// far out from its middle: light under the badge fading to nothing.
|
|
64
|
+
export const BADGE_GLOW_R = 0.32;
|
|
65
|
+
// And held things this much bigger, about their grip.
|
|
66
|
+
export const HELD_SCALE = 1.2;
|
|
67
|
+
|
|
68
|
+
// Where an earned item sits on an avatar this kit has no fit for (`avatar.js`
|
|
69
|
+
// `earnedFit` gives null): a body about toon's.
|
|
70
|
+
const DEFAULT_FIT = {
|
|
71
|
+
chest: [0.09, 0.6, 0.2, 20],
|
|
72
|
+
waist: [0.37, 0.23, 0.23],
|
|
73
|
+
sash: [0.51, 0.35, 0.26, 45],
|
|
74
|
+
hand: [-0.33, 0.34, 0.01],
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const mm = (n) => Math.round(n * 1000) / 1000;
|
|
78
|
+
|
|
79
|
+
// Whether `shape` is drawn for class `cls`.
|
|
80
|
+
export function drawnFor(shape, cls) {
|
|
81
|
+
const own = EARNED_SHAPE_CLASS[shape];
|
|
82
|
+
if (!own) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
return own === cls || (CHEST.has(own) && CHEST.has(cls));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// What to draw for an earned item `{ class, shape, color }` on an avatar with
|
|
89
|
+
// earned fit `fit` (`avatar.js`): a plain description, the same every time for
|
|
90
|
+
// the same arguments, or null for nothing (an unknown shape, a shape of
|
|
91
|
+
// another class, no colour).
|
|
92
|
+
// { shape, file, color, position: [x, y, z], yaw, tilt, scale: [x, y, z], glow? }
|
|
93
|
+
// in metres over the avatar's origin and degrees: the model is scaled, then
|
|
94
|
+
// tilted about z (a sash, rising to the wearer's right shoulder), then turned
|
|
95
|
+
// `yaw` about y, then moved to `position`. `glow` (a badge) is the radius of
|
|
96
|
+
// its soft glow.
|
|
97
|
+
export function earnedLook(item, fit = null) {
|
|
98
|
+
const cls = item?.class;
|
|
99
|
+
const shape = item?.shape;
|
|
100
|
+
const color = typeof item?.color === 'string' && COLOR.test(item.color) ? item.color.toLowerCase() : null;
|
|
101
|
+
if (!color || !EARNED_CLASSES.includes(cls) || !drawnFor(shape, cls)) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
const f = fit ?? DEFAULT_FIT;
|
|
105
|
+
const square = f.square === true && SQUARE_SHAPES.includes(shape);
|
|
106
|
+
const base = { shape, file: earnedFile(shape, square), color };
|
|
107
|
+
if (CHEST.has(cls)) {
|
|
108
|
+
// The shape says how big it is drawn: a badge's shape pinned is a badge.
|
|
109
|
+
const [x, y, z, yaw, size = 1] = f.chest;
|
|
110
|
+
const badge = EARNED_SHAPE_CLASS[shape] === 'badge';
|
|
111
|
+
const k = mm((badge ? BADGE_SCALE : PIN_SCALE) * size);
|
|
112
|
+
return { ...base, position: [x, mm(MODEL_FEET_Y + y), z], yaw, tilt: 0, scale: [k, k, k], ...(badge ? { glow: mm(BADGE_GLOW_R * size) } : {}) };
|
|
113
|
+
}
|
|
114
|
+
if (cls === 'belt') {
|
|
115
|
+
const [y, rx, rz] = f.waist;
|
|
116
|
+
return { ...base, position: [0, mm(MODEL_FEET_Y + y), 0], yaw: 0, tilt: 0, scale: [mm(rx / RING_R), 1, mm(rz / RING_R)] };
|
|
117
|
+
}
|
|
118
|
+
if (cls === 'sash') {
|
|
119
|
+
// `a` is the half length of the ring in its tilted plane.
|
|
120
|
+
const [y, a, rz, tilt] = f.sash;
|
|
121
|
+
return { ...base, position: [0, mm(MODEL_FEET_Y + y), 0], yaw: 0, tilt: -tilt, scale: [mm(a / RING_R), 1, mm(rz / RING_R)] };
|
|
122
|
+
}
|
|
123
|
+
const [x, y, z] = f.hand;
|
|
124
|
+
return { ...base, position: [x, mm(MODEL_FEET_Y + y), z], yaw: 0, tilt: 0, scale: [HELD_SCALE, HELD_SCALE, HELD_SCALE] };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// The model text an item is built from: the shape's model with its main
|
|
128
|
+
// colour made the item's. Trims never carry `EARNED_MAIN`.
|
|
129
|
+
export function tinted(text, color) {
|
|
130
|
+
return text.split(`"${EARNED_MAIN}"`).join(JSON.stringify(color.toLowerCase()));
|
|
131
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Where an emote's emoji is drawn: on the head it belongs to, never under
|
|
2
|
+
// the top chrome (the HUD's box, a question card, Back, the sound button).
|
|
3
|
+
// In a portrait phone with the camera looking down, a fixed height over the
|
|
4
|
+
// body projects far up the screen, into the HUD's lines or the sky, and the
|
|
5
|
+
// player never reads it as their own wave. No DOM here, so
|
|
6
|
+
// `scripts/test-emote-bubble.mjs` can hold it; the client projects the head
|
|
7
|
+
// (`idle.js` `labels`) and the chrome (`chrome.js` `setLabels`) measures and
|
|
8
|
+
// moves.
|
|
9
|
+
//
|
|
10
|
+
// The rule (`placeEmoteBubble`): just above the head's top, centred on it;
|
|
11
|
+
// where that leaves the view's top edge or meets a band, beside the head on
|
|
12
|
+
// the side with more room, centred on it; kept on the view; and last, from
|
|
13
|
+
// under any band it still meets (`emoteBubbleShift`).
|
|
14
|
+
|
|
15
|
+
// Pixels between a bubble beside the head and the head, a moved bubble and
|
|
16
|
+
// the band it was moved under, and kept off every side of the view.
|
|
17
|
+
export const BUBBLE_GAP = 8;
|
|
18
|
+
export const BUBBLE_EDGE = 6;
|
|
19
|
+
// Over the head, the emoji's own glyph leaves a little air: it sits right on
|
|
20
|
+
// the model's box (whose top, ears and hats included, is often above what
|
|
21
|
+
// reads as the head).
|
|
22
|
+
export const HEAD_GAP = 0;
|
|
23
|
+
|
|
24
|
+
const overlaps = (a, b) => a.left < b.right && b.left < a.right && a.top < b.bottom && b.top < a.bottom;
|
|
25
|
+
const clamp = (v, lo, hi) => Math.max(lo, Math.min(v, Math.max(lo, hi)));
|
|
26
|
+
|
|
27
|
+
// `rect` and `bands` are `{ left, right, top, bottom }` in CSS pixels;
|
|
28
|
+
// `viewW` the view's width. Returns `{ dx, dy }`, both 0 when nothing is in
|
|
29
|
+
// the way: a bubble over a band goes to just under the lowest band it meets,
|
|
30
|
+
// a bubble's width to the right, and again under any band it then meets.
|
|
31
|
+
export function emoteBubbleShift(rect, bands, viewW) {
|
|
32
|
+
const w = rect.right - rect.left;
|
|
33
|
+
let r = rect;
|
|
34
|
+
let moved = false;
|
|
35
|
+
for (let i = 0; i <= bands.length; i += 1) {
|
|
36
|
+
const hit = bands.filter((b) => overlaps(r, b));
|
|
37
|
+
if (!hit.length) {
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
const down = Math.max(...hit.map((b) => b.bottom)) + BUBBLE_GAP - r.top;
|
|
41
|
+
let left = r.left;
|
|
42
|
+
if (!moved) {
|
|
43
|
+
moved = true;
|
|
44
|
+
left = clamp(rect.left + w, BUBBLE_EDGE, viewW - BUBBLE_EDGE - w);
|
|
45
|
+
}
|
|
46
|
+
r = { left, right: left + w, top: r.top + down, bottom: r.bottom + down };
|
|
47
|
+
}
|
|
48
|
+
return { dx: r.left - rect.left, dy: r.top - rect.top };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// `head` is the head's rect on screen, `size` the bubble's `{ w, h }`, `view`
|
|
52
|
+
// `{ w, h }`, `lift` pixels more above the head (its rise). The placed rect,
|
|
53
|
+
// or null for a head wholly off the view: its bubble is not drawn, as an off-
|
|
54
|
+
// screen label never was, rather than clamped beside someone else.
|
|
55
|
+
export function placeEmoteBubble(head, size, bands, view, lift = 0) {
|
|
56
|
+
if (head.right <= 0 || head.left >= view.w || head.bottom <= 0 || head.top >= view.h) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
const { w, h } = size;
|
|
60
|
+
const cx = (head.left + head.right) / 2;
|
|
61
|
+
const left = clamp(cx - w / 2, BUBBLE_EDGE, view.w - BUBBLE_EDGE - w);
|
|
62
|
+
const bottom = head.top - HEAD_GAP - lift;
|
|
63
|
+
let r = { left, right: left + w, top: bottom - h, bottom };
|
|
64
|
+
if (r.top < BUBBLE_EDGE || bands.some((b) => overlaps(r, b))) {
|
|
65
|
+
// Beside the head, on its open side, centred on it.
|
|
66
|
+
const roomRight = view.w - head.right;
|
|
67
|
+
const roomLeft = head.left;
|
|
68
|
+
const x = roomRight >= roomLeft ? head.right + BUBBLE_GAP : head.left - BUBBLE_GAP - w;
|
|
69
|
+
const bx = clamp(x, BUBBLE_EDGE, view.w - BUBBLE_EDGE - w);
|
|
70
|
+
const by = clamp((head.top + head.bottom) / 2 - h / 2, BUBBLE_EDGE, view.h - BUBBLE_EDGE - h);
|
|
71
|
+
r = { left: bx, right: bx + w, top: by, bottom: by + h };
|
|
72
|
+
}
|
|
73
|
+
const { dx, dy } = emoteBubbleShift(r, bands, view.w);
|
|
74
|
+
return { left: r.left + dx, right: r.right + dx, top: r.top + dy, bottom: r.bottom + dy };
|
|
75
|
+
}
|
|
@@ -18,6 +18,12 @@
|
|
|
18
18
|
// A place may keep an object for one player (v1.27, `hub.keepFor`): it is
|
|
19
19
|
// never offered to anyone else, so the nearest object a player may take is
|
|
20
20
|
// the one offered. Where nothing is kept the offer is exactly what it was.
|
|
21
|
+
//
|
|
22
|
+
// Under the engine's orbit camera key (a scene whose `engine.camera` is
|
|
23
|
+
// `{ "follow": "rigid", "control": "orbit" }`, `scene.cameraControl ===
|
|
24
|
+
// 'orbit'`) the camera and the character turn apart, so a throw goes where
|
|
25
|
+
// the camera looks rather than where the character happens to face: see
|
|
26
|
+
// `aimThrow`. Without the key every throw runs the code it always did.
|
|
21
27
|
|
|
22
28
|
import { hub } from './state.js';
|
|
23
29
|
|
|
@@ -78,6 +84,35 @@ export const PRESS_WAIT_MS = 500;
|
|
|
78
84
|
// v1.25 `grab.keepHeld`: how often the server is told a hold goes on (its
|
|
79
85
|
// pin on the held object lasts 2.5 s past the last word).
|
|
80
86
|
export const KEEP_TELL_MS = 1000;
|
|
87
|
+
// Under the orbit camera key: a throw waits for the character to face the
|
|
88
|
+
// camera's way and for a movement report saying so to have gone out, at most
|
|
89
|
+
// AIM_WAIT_MS; and for the held object to swing round to the hold point along
|
|
90
|
+
// the throw, which takes no time at all when the camera already looks the way
|
|
91
|
+
// the character faces, and otherwise as long as the server takes to hear the
|
|
92
|
+
// swing (AIM_SLACK_M, below). Nothing waits past AIM_GIVE_UP_MS: a throw is
|
|
93
|
+
// never lost. The server judges a throw from the pose it last heard.
|
|
94
|
+
export const AIM_WAIT_MS = 150;
|
|
95
|
+
export const AIM_GIVE_UP_MS = 2000;
|
|
96
|
+
// How far (metres, in a straight line) the swing may put the held object
|
|
97
|
+
// from anywhere the server's body for it may be. multiplayer-3d checks each
|
|
98
|
+
// owned-object report against where its kinematic body is when the report
|
|
99
|
+
// arrives: no farther than MAX_OBJECT_SPEED (40 m/s) times the server time
|
|
100
|
+
// since the last report, plus MOVE_SLACK (0.6 m); a report past that takes
|
|
101
|
+
// the object away and ends the hold. Reports bunched by the network between
|
|
102
|
+
// two physics steps get no time at all, only the 0.6 m, and the body moves
|
|
103
|
+
// only at a step, to the newest report applied before it. So the swing never
|
|
104
|
+
// counts on time, and puts the object within this of every position this
|
|
105
|
+
// client has reported since the one the body is sure to have reached (see
|
|
106
|
+
// `reach`): wherever among them the body is, the next report is inside the
|
|
107
|
+
// bound. The report carries exactly where the swing put the object (the
|
|
108
|
+
// client's physics runs before this system, the report after it); the rest
|
|
109
|
+
// of the 0.6 m is margin.
|
|
110
|
+
export const AIM_SLACK_M = 0.5;
|
|
111
|
+
// How near the character's facing must be to the throw's to count as facing
|
|
112
|
+
// it (radians). The Player takes a facing request exactly, so standing still
|
|
113
|
+
// it is met the frame after the request; walking, the Player eases the
|
|
114
|
+
// facing toward the walk at once and the wait runs out instead.
|
|
115
|
+
const AIM_FACE_RAD = 1 * DEG;
|
|
81
116
|
// Where the walk preset's capsule stands (physics-3d `Player`): its radius and
|
|
82
117
|
// height, and how far it hovers.
|
|
83
118
|
const PLAYER = { radius: 0.35, height: 1.4, hover: 0.15 };
|
|
@@ -161,19 +196,35 @@ function frame(t, scene, mp, local, idle) {
|
|
|
161
196
|
!scene.getActor(id)
|
|
162
197
|
) {
|
|
163
198
|
t.held = null;
|
|
164
|
-
} else if (pressed) {
|
|
165
|
-
throwHeld(t, scene, body, local, config, net, now);
|
|
166
199
|
} else {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
//
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
200
|
+
if (scene.cameraControl === 'orbit') {
|
|
201
|
+
// What this client has told the server of the hold, for a throw's
|
|
202
|
+
// swing to keep inside (`reach`); it changes nothing here.
|
|
203
|
+
listen(t.held, mp);
|
|
204
|
+
}
|
|
205
|
+
if (t.held.aim) {
|
|
206
|
+
aimFrame(t, scene, mp, body, local, config, net, now, dt);
|
|
207
|
+
} else if (pressed && scene.cameraControl === 'orbit') {
|
|
208
|
+
aimThrow(t, scene, mp, body, local, config, dt, now);
|
|
209
|
+
} else if (pressed) {
|
|
210
|
+
throwHeld(t, scene, body, local, config, net, now);
|
|
211
|
+
} else {
|
|
212
|
+
carry(t, scene, body, local, config, dt);
|
|
213
|
+
if (config.keepHeld === true) {
|
|
214
|
+
// v1.25: the server keeps a held object this client's only while it
|
|
215
|
+
// hears the hold goes on.
|
|
216
|
+
t.held.toldAt ??= now;
|
|
217
|
+
if (now - t.held.toldAt >= KEEP_TELL_MS) {
|
|
218
|
+
t.held.toldAt = now;
|
|
219
|
+
net.send({ k: 'hub-grab', actor: id, op: 'hold' });
|
|
220
|
+
}
|
|
175
221
|
}
|
|
176
222
|
}
|
|
223
|
+
if (t.held && scene.cameraControl === 'orbit') {
|
|
224
|
+
// Where the body is now is what the multiplayer kit's report, after
|
|
225
|
+
// this system, packs if one goes out this frame (`listen`).
|
|
226
|
+
put(t.held, body);
|
|
227
|
+
}
|
|
177
228
|
}
|
|
178
229
|
}
|
|
179
230
|
if (t.held) {
|
|
@@ -341,14 +392,14 @@ function sizeOf(shape) {
|
|
|
341
392
|
|
|
342
393
|
// Where a held object goes: `holdDistance` in front of the player (never so
|
|
343
394
|
// close that it touches them) and `holdHeight` above their feet (never so low
|
|
344
|
-
// that it is in the ground).
|
|
345
|
-
|
|
395
|
+
// that it is in the ground). `f`, radians, is the way it is in front along:
|
|
396
|
+
// the player's facing unless an aimed throw (below) says otherwise.
|
|
397
|
+
function holdPoint(local, config, held, f = (local.components.Transform.rotationY ?? 0) * DEG) {
|
|
346
398
|
const t = local.components.Transform;
|
|
347
399
|
const shape = local.components.Shape;
|
|
348
400
|
const radius = typeof shape?.radius === 'number' ? shape.radius : PLAYER.radius;
|
|
349
401
|
const height = typeof shape?.height === 'number' ? shape.height : PLAYER.height;
|
|
350
402
|
const feet = t.y - (height / 2 + PLAYER.hover);
|
|
351
|
-
const f = (t.rotationY ?? 0) * DEG;
|
|
352
403
|
const distance = Math.max(config.holdDistance, radius + held.extent + 0.15);
|
|
353
404
|
return {
|
|
354
405
|
x: t.x + Math.sin(f) * distance,
|
|
@@ -359,16 +410,25 @@ function holdPoint(local, config, held) {
|
|
|
359
410
|
|
|
360
411
|
// Move the held object toward its hold point, at most CARRY_SPEED. It keeps
|
|
361
412
|
// the velocity it is carried at, which the multiplayer kit reports with its
|
|
362
|
-
// pose, so other players draw it moving smoothly.
|
|
363
|
-
|
|
413
|
+
// pose, so other players draw it moving smoothly. `to` is where it goes: the
|
|
414
|
+
// hold point unless an aimed throw says otherwise, and `most` how far it may
|
|
415
|
+
// go this frame. Returns whether it got there this frame.
|
|
416
|
+
function carry(
|
|
417
|
+
t,
|
|
418
|
+
scene,
|
|
419
|
+
body,
|
|
420
|
+
local,
|
|
421
|
+
config,
|
|
422
|
+
dt,
|
|
423
|
+
to = holdPoint(local, config, t.held),
|
|
424
|
+
most = CARRY_SPEED * dt,
|
|
425
|
+
) {
|
|
364
426
|
const held = t.held;
|
|
365
|
-
const to = holdPoint(local, config, held);
|
|
366
427
|
const from = held.at;
|
|
367
428
|
const dx = to.x - from.x;
|
|
368
429
|
const dy = to.y - from.y;
|
|
369
430
|
const dz = to.z - from.z;
|
|
370
431
|
const d = Math.hypot(dx, dy, dz);
|
|
371
|
-
const most = CARRY_SPEED * dt;
|
|
372
432
|
const k = d > most && d > 0 ? most / d : 1;
|
|
373
433
|
const next = { x: from.x + dx * k, y: from.y + dy * k, z: from.z + dz * k };
|
|
374
434
|
body.setTranslation(next, true);
|
|
@@ -387,14 +447,273 @@ function carry(t, scene, body, local, config, dt) {
|
|
|
387
447
|
transform.y = next.y;
|
|
388
448
|
transform.z = next.z;
|
|
389
449
|
}
|
|
450
|
+
return k === 1;
|
|
390
451
|
}
|
|
391
452
|
|
|
392
|
-
// Let go along the player's facing at `throwSpeed`, a little upward
|
|
393
|
-
|
|
394
|
-
|
|
453
|
+
// Let go along the player's facing at `throwSpeed`, a little upward (or
|
|
454
|
+
// along `f`, radians, for an aimed throw).
|
|
455
|
+
function throwHeld(
|
|
456
|
+
t,
|
|
457
|
+
scene,
|
|
458
|
+
body,
|
|
459
|
+
local,
|
|
460
|
+
config,
|
|
461
|
+
net,
|
|
462
|
+
now,
|
|
463
|
+
f = (local.components.Transform.rotationY ?? 0) * DEG,
|
|
464
|
+
) {
|
|
395
465
|
const speed = config.throwSpeed;
|
|
396
466
|
body.setLinvel({ x: Math.sin(f) * speed, y: speed * THROW_UP, z: Math.cos(f) * speed }, true);
|
|
397
467
|
net.send({ k: 'hub-grab', actor: t.held.id, op: 'throw' });
|
|
398
468
|
t.held = null;
|
|
399
469
|
t.quietUntil = now + REGRAB_MS;
|
|
400
470
|
}
|
|
471
|
+
|
|
472
|
+
// ---- Under the orbit camera key only ------------------------------------------
|
|
473
|
+
//
|
|
474
|
+
// Throw where the camera looks: along f = PI - camAngle, the camera's forward
|
|
475
|
+
// on the ground (the facing the character always has without the key; Player
|
|
476
|
+
// keyless: `rt.facing = Math.PI - per.camAngle`). The press does not let go at
|
|
477
|
+
// once. It asks the Player to turn the character to f (`scene.faceRequest`,
|
|
478
|
+
// taken by the Player's next update), and from then on the held object swings
|
|
479
|
+
// round the player, at the hold distance and no faster than it is carried, to
|
|
480
|
+
// the hold point along f, so a throw toward the camera does not start inside
|
|
481
|
+
// the player. The swing goes only as fast as the server hears it: never more
|
|
482
|
+
// than AIM_SLACK_M, in a straight line, from any position this client has
|
|
483
|
+
// reported since the one the server's body is sure to have reached (`reach`,
|
|
484
|
+
// from multiplayer-3d's `acks` and the broadcasts' simulation time), carry
|
|
485
|
+
// reports from before the press included, so no bunch of its reports and no
|
|
486
|
+
// tick without a physics step can break the owned-object move bound and take
|
|
487
|
+
// the object away mid-throw. The throw is let go -- the velocity and the
|
|
488
|
+
// `hub-grab` throw -- on the first frame where:
|
|
489
|
+
// - the object is at that hold point, and
|
|
490
|
+
// - the character has faced f on every frame since some frame F (its
|
|
491
|
+
// Transform.rotationY, which the multiplayer kit packs into each movement
|
|
492
|
+
// report), and a movement report went out after F's: the multiplayer
|
|
493
|
+
// kit's `moveSeq` counts reports sent, and it reports after this system
|
|
494
|
+
// every frame, so a count that moved on since F means a report carrying
|
|
495
|
+
// f is on the wire before the throw, on the same connection.
|
|
496
|
+
// Past AIM_WAIT_MS after the press the object's place is enough, whatever the
|
|
497
|
+
// facing: a throw is not held up by a facing the Player did not take (a walk
|
|
498
|
+
// eases the facing toward it at once) or a report that never went out. The
|
|
499
|
+
// swing always gets there (it turns at the carry speed round a player who
|
|
500
|
+
// is placed every frame), unless the player outruns the carry (a tune far
|
|
501
|
+
// past the walk) or the server stops acknowledging (a stalled connection):
|
|
502
|
+
// AIM_GIVE_UP_MS after the press the throw goes from wherever the object is.
|
|
503
|
+
// A multiplayer kit without acknowledgements or report numbers swings at the
|
|
504
|
+
// carry speed, unbounded, as before.
|
|
505
|
+
// Meanwhile the object stays held: carried (at rest where it is put, under
|
|
506
|
+
// the acknowledgement bound; at the carry's velocity without it), the
|
|
507
|
+
// v1.25 `keepHeld` word still said; another press does nothing; anything that
|
|
508
|
+
// ends a hold (a drop, a refusal, the object handed on or hidden, the player
|
|
509
|
+
// unable to act, a new session or scene) ends it with no throw sent, as it
|
|
510
|
+
// ends any hold.
|
|
511
|
+
|
|
512
|
+
function aimThrow(t, scene, mp, body, local, config, dt, now) {
|
|
513
|
+
const me = local.components.Transform;
|
|
514
|
+
const cam = scene.persistent?.camAngle;
|
|
515
|
+
const f = Number.isFinite(cam) ? Math.PI - cam : (me.rotationY ?? 0) * DEG;
|
|
516
|
+
const at = t.held.at;
|
|
517
|
+
t.held.aim = {
|
|
518
|
+
f,
|
|
519
|
+
until: now + AIM_WAIT_MS,
|
|
520
|
+
last: now + AIM_GIVE_UP_MS,
|
|
521
|
+
// The object's bearing round the player, swung toward f.
|
|
522
|
+
a: Math.atan2(at.x - me.x, at.z - me.z),
|
|
523
|
+
facedSeq: null,
|
|
524
|
+
local,
|
|
525
|
+
};
|
|
526
|
+
scene.faceRequest = f;
|
|
527
|
+
swing(t, scene, mp, body, local, config, dt);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
function aimFrame(t, scene, mp, body, local, config, net, now, dt) {
|
|
531
|
+
const aim = t.held.aim;
|
|
532
|
+
if (aim.local !== local) {
|
|
533
|
+
// A scene load: the request was dropped with the scene, and the hold
|
|
534
|
+
// ends as one across a load does.
|
|
535
|
+
t.held = null;
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
if (config.keepHeld === true) {
|
|
539
|
+
t.held.toldAt ??= now;
|
|
540
|
+
if (now - t.held.toldAt >= KEEP_TELL_MS) {
|
|
541
|
+
t.held.toldAt = now;
|
|
542
|
+
net.send({ k: 'hub-grab', actor: t.held.id, op: 'hold' });
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
const there = swing(t, scene, mp, body, local, config, dt);
|
|
546
|
+
const seq = Number.isFinite(mp.moveSeq) ? mp.moveSeq : null;
|
|
547
|
+
const reported = aim.facedSeq !== null && seq !== aim.facedSeq;
|
|
548
|
+
if ((there && (reported || now >= aim.until)) || now >= aim.last) {
|
|
549
|
+
throwHeld(t, scene, body, local, config, net, now, aim.f);
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
const faced =
|
|
553
|
+
Math.abs(turn((local.components.Transform.rotationY ?? 0) * DEG - aim.f)) <= AIM_FACE_RAD;
|
|
554
|
+
aim.facedSeq = faced && seq !== null ? (aim.facedSeq ?? seq) : null;
|
|
555
|
+
// Asked again each frame it waits: a request is taken once.
|
|
556
|
+
scene.faceRequest = aim.f;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
// One frame of the swing: the bearing turns toward f by what `most` metres
|
|
560
|
+
// covers at the hold distance, and the object goes at most `most` toward the
|
|
561
|
+
// hold point on that bearing. `most` is what the carry speed covers, or, where
|
|
562
|
+
// the server's acknowledgements bound the swing, the most of that which keeps
|
|
563
|
+
// the object within AIM_SLACK_M of every place `reach` says the server's body
|
|
564
|
+
// may be (none at all while it cannot say). Returns whether the object is at
|
|
565
|
+
// the hold point along f.
|
|
566
|
+
function swing(t, scene, mp, body, local, config, dt) {
|
|
567
|
+
const held = t.held;
|
|
568
|
+
const aim = held.aim;
|
|
569
|
+
const shape = local.components.Shape;
|
|
570
|
+
const radius = typeof shape?.radius === 'number' ? shape.radius : PLAYER.radius;
|
|
571
|
+
const distance = Math.max(config.holdDistance, radius + held.extent + 0.15);
|
|
572
|
+
const step = (most) => {
|
|
573
|
+
const by = most / distance;
|
|
574
|
+
const left = turn(aim.f - aim.a);
|
|
575
|
+
const a = Math.abs(left) <= by ? aim.f : aim.a + Math.sign(left) * by;
|
|
576
|
+
const to = holdPoint(local, config, held, a);
|
|
577
|
+
const from = held.at;
|
|
578
|
+
const d = Math.hypot(to.x - from.x, to.y - from.y, to.z - from.z);
|
|
579
|
+
const k = d > most && d > 0 ? most / d : 1;
|
|
580
|
+
const next = {
|
|
581
|
+
x: from.x + (to.x - from.x) * k,
|
|
582
|
+
y: from.y + (to.y - from.y) * k,
|
|
583
|
+
z: from.z + (to.z - from.z) * k,
|
|
584
|
+
};
|
|
585
|
+
return { a, to, next };
|
|
586
|
+
};
|
|
587
|
+
const full = CARRY_SPEED * dt;
|
|
588
|
+
const places = reach(held, mp);
|
|
589
|
+
let most = full;
|
|
590
|
+
if (places === false) {
|
|
591
|
+
most = 0;
|
|
592
|
+
} else if (places !== null) {
|
|
593
|
+
const fits = (p) =>
|
|
594
|
+
places.every((q) => Math.hypot(p.x - q.x, p.y - q.y, p.z - q.z) <= AIM_SLACK_M);
|
|
595
|
+
if (!fits(step(full).next)) {
|
|
596
|
+
// The farthest that fits, to well under a millimetre; none, when even a
|
|
597
|
+
// little way does not (the object stays where it was last reported).
|
|
598
|
+
let lo = 0;
|
|
599
|
+
let hi = full;
|
|
600
|
+
for (let i = 0; i < 24; i += 1) {
|
|
601
|
+
const mid = (lo + hi) / 2;
|
|
602
|
+
if (fits(step(mid).next)) {
|
|
603
|
+
lo = mid;
|
|
604
|
+
} else {
|
|
605
|
+
hi = mid;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
most = lo;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
const { a, to } = step(most);
|
|
612
|
+
aim.a = a;
|
|
613
|
+
const reached = carry(t, scene, body, local, config, dt, to, most);
|
|
614
|
+
if (places !== null) {
|
|
615
|
+
// Reported at rest where it is put: the swing's own pace is the
|
|
616
|
+
// acknowledgements', not a velocity the next physics step carries on.
|
|
617
|
+
body.setLinvel({ x: 0, y: 0, z: 0 }, true);
|
|
618
|
+
}
|
|
619
|
+
return reached && aim.a === aim.f;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// What this client has told the server about a held object, kept frame by
|
|
623
|
+
// frame under the orbit key while it is held: `trail`, `[report number,
|
|
624
|
+
// position]` for each movement report since the hold began (carry and swing
|
|
625
|
+
// alike), known from report number `from` on; and `sure`, the newest report
|
|
626
|
+
// the server's body is sure to have reached (`reach`). The position is the one
|
|
627
|
+
// the report carried: the body where this system left it the frame the report
|
|
628
|
+
// went out (`put`), which the multiplayer kit reads straight after, before the
|
|
629
|
+
// next frame's physics moves it on at its velocity. Never the body read back a
|
|
630
|
+
// frame later, which is not where it was reported. Without acknowledgements or
|
|
631
|
+
// report numbers there is nothing to keep.
|
|
632
|
+
function listen(held, mp) {
|
|
633
|
+
if (!(mp.acks instanceof Map) || !Number.isFinite(mp.moveSeq)) {
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
const epoch = mp.handed?.get?.(held.id)?.epoch;
|
|
637
|
+
let sent = held.sent;
|
|
638
|
+
if (!sent || sent.epoch !== epoch) {
|
|
639
|
+
// Reports up to now are of an object not yet held here (or under another
|
|
640
|
+
// grant): where they put it is not known.
|
|
641
|
+
sent = held.sent = {
|
|
642
|
+
epoch,
|
|
643
|
+
seq: mp.moveSeq,
|
|
644
|
+
from: mp.moveSeq + 1,
|
|
645
|
+
trail: [],
|
|
646
|
+
sure: -Infinity,
|
|
647
|
+
put: null,
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
if (mp.moveSeq !== sent.seq) {
|
|
651
|
+
if (mp.moveSeq === sent.seq + 1 && sent.put) {
|
|
652
|
+
sent.trail.push([mp.moveSeq, sent.put]);
|
|
653
|
+
} else {
|
|
654
|
+
// Reports went out unseen, or after a frame that left nothing put:
|
|
655
|
+
// what they carried is not known.
|
|
656
|
+
sent.from = mp.moveSeq + 1;
|
|
657
|
+
}
|
|
658
|
+
sent.seq = mp.moveSeq;
|
|
659
|
+
}
|
|
660
|
+
sent.put = null;
|
|
661
|
+
// multiplayer-3d's acknowledgement is `[epoch, lastSeq, tAck, ...]`: the
|
|
662
|
+
// newest report applied, and the simulation time it was applied at.
|
|
663
|
+
const ack = mp.acks.get(held.id);
|
|
664
|
+
if (
|
|
665
|
+
Array.isArray(ack) &&
|
|
666
|
+
Number.isFinite(ack[1]) &&
|
|
667
|
+
Number.isFinite(ack[2]) &&
|
|
668
|
+
(!Number.isFinite(epoch) || ack[0] === epoch) &&
|
|
669
|
+
hub.lastT > ack[2]
|
|
670
|
+
) {
|
|
671
|
+
sent.sure = Math.max(sent.sure, ack[1]);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// The body of a held object where this system leaves it this frame: the
|
|
676
|
+
// position a movement report going out this frame carries (`listen`).
|
|
677
|
+
function put(held, body) {
|
|
678
|
+
if (held.sent) {
|
|
679
|
+
const p = body.translation();
|
|
680
|
+
held.sent.put = { x: p.x, y: p.y, z: p.z };
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
// Every place the server's body for a held object may be when the next
|
|
685
|
+
// report reaches it: the reported positions from the newest one it is sure to
|
|
686
|
+
// have reached on. null when the multiplayer kit gives no acknowledgements
|
|
687
|
+
// or report numbers (the swing is unbounded, as before them); false when no
|
|
688
|
+
// such report is known yet.
|
|
689
|
+
//
|
|
690
|
+
// An acknowledgement alone is not a body moved. multiplayer-3d applies a
|
|
691
|
+
// report as it arrives (its kinematic target, stamped with the simulation
|
|
692
|
+
// time, `tAck`), moves the body to the newest applied target at each physics
|
|
693
|
+
// step, and acknowledges in the broadcast after a tick's steps; but a tick may
|
|
694
|
+
// run no step (its elapsed time short of one) and acknowledge all the same,
|
|
695
|
+
// leaving the body where the last step put it. The simulation time advances
|
|
696
|
+
// only by physics steps (a tick that falls behind skips time only after its
|
|
697
|
+
// full four), so a broadcast whose time (`msg.t`, which the hub's state hook
|
|
698
|
+
// keeps as `hub.lastT`) is past a report's `tAck` comes after a step that
|
|
699
|
+
// moved the body to that report or a later one. Later reports are ordered
|
|
700
|
+
// after it on the one connection, so the body may be at any of them, and
|
|
701
|
+
// never back before it.
|
|
702
|
+
function reach(held, mp) {
|
|
703
|
+
if (!(mp.acks instanceof Map) || !Number.isFinite(mp.moveSeq)) {
|
|
704
|
+
return null;
|
|
705
|
+
}
|
|
706
|
+
const sent = held.sent;
|
|
707
|
+
if (!sent || sent.sure < sent.from) {
|
|
708
|
+
return false;
|
|
709
|
+
}
|
|
710
|
+
while (sent.trail.length > 0 && sent.trail[0][0] < sent.sure) {
|
|
711
|
+
sent.trail.shift();
|
|
712
|
+
}
|
|
713
|
+
return sent.trail.length > 0 ? sent.trail.map(([, p]) => p) : false;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
// An angle as the shortest way round: -PI..PI.
|
|
717
|
+
function turn(angle) {
|
|
718
|
+
return angle - 2 * Math.PI * Math.floor((angle + Math.PI) / (2 * Math.PI));
|
|
719
|
+
}
|