castle-web-cli 0.4.233 → 0.4.234
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.d.ts +11 -0
- package/dist/api.js +43 -0
- package/dist/bundle.d.ts +64 -0
- package/dist/bundle.js +558 -2
- package/dist/castle-host/host.d.ts +17 -2
- package/dist/castle-host/host.js +793 -36
- package/dist/castleJson.d.ts +20 -1
- package/dist/castleJson.js +44 -2
- package/dist/check.js +9 -2
- package/dist/chunkLoader.d.ts +3 -0
- package/dist/chunkLoader.js +111 -0
- package/dist/devParty.d.ts +26 -0
- package/dist/devParty.js +231 -0
- package/dist/devSaveStorage.js +4 -0
- package/dist/devSessionStorage.js +3 -1
- package/dist/devSocial.d.ts +24 -0
- package/dist/devSocial.js +70 -0
- package/dist/ide.d.ts +2 -0
- package/dist/ide.js +119 -15
- package/dist/index.js +8 -2
- package/dist/init.js +1 -1
- package/dist/save-deck.d.ts +20 -1
- package/dist/save-deck.js +141 -5
- package/dist/serve.js +29 -11
- package/dist/shell/assets/{index-BjOxR-lW.js → index-DulbYIJm.js} +97 -97
- package/dist/shell/index.html +1 -1
- package/dist/vitePlugins.d.ts +2 -1
- package/dist/vitePlugins.js +13 -0
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +260 -3
- package/kits/base/sdk/castle.d.ts +7 -3
- package/kits/base/sdk/castle.js +2 -0
- package/kits/base/sdk/commands.d.ts +162 -1
- package/kits/base/sdk/commands.js +3 -0
- package/kits/base/sdk/display.d.ts +3 -0
- package/kits/base/sdk/display.js +9 -3
- package/kits/base/sdk/hub.d.ts +33 -6
- package/kits/base/sdk/hub.js +50 -4
- package/kits/base/sdk/multiplayer.d.ts +7 -1
- package/kits/base/sdk/multiplayer.js +140 -40
- package/kits/base/sdk/multiplayerProtocol.d.ts +2 -0
- package/kits/base/sdk/party.d.ts +23 -0
- package/kits/base/sdk/party.js +91 -0
- package/kits/base/sdk/reconnectBudget.d.ts +23 -0
- package/kits/base/sdk/reconnectBudget.js +96 -0
- package/kits/base/sdk/save.d.ts +38 -1
- package/kits/base/sdk/save.js +79 -6
- package/kits/base/sdk/server/hub.d.ts +31 -1
- package/kits/base/sdk/server/hub.js +50 -3
- package/kits/base/sdk/server/platformHandle.d.ts +13 -1
- package/kits/base/sdk/server/storage.d.ts +4 -0
- package/kits/base/sdk/server/storage.js +19 -3
- package/kits/base/sdk/server/wrapper.d.ts +7 -1
- package/kits/base/sdk/server/wrapper.js +10 -1
- package/kits/base/sdk/social.d.ts +9 -0
- package/kits/base/sdk/social.js +5 -0
- package/kits/hub-game/CLAUDE.md +123 -3
- package/kits/hub-game/README.md +63 -0
- package/kits/hub-game/castle.json +5 -5
- package/kits/hub-game/code/client/act.js +312 -0
- package/kits/hub-game/code/client/actionLayout.js +147 -0
- package/kits/hub-game/code/client/actionOverflow.js +556 -0
- package/kits/hub-game/code/client/arrivalCamera.js +50 -0
- package/kits/hub-game/code/client/askSlot.js +117 -0
- package/kits/hub-game/code/client/avatar.js +4 -2
- package/kits/hub-game/code/client/avatarShare.js +2 -0
- package/kits/hub-game/code/client/backVisibility.js +13 -0
- package/kits/hub-game/code/client/ballot.js +15 -10
- package/kits/hub-game/code/client/build.js +16 -0
- package/kits/hub-game/code/client/chat.js +41 -5
- package/kits/hub-game/code/client/chatModeration.js +5 -0
- package/kits/hub-game/code/client/chrome.js +1148 -258
- package/kits/hub-game/code/client/crowdNames.js +241 -0
- package/kits/hub-game/code/client/decor.js +10 -4
- package/kits/hub-game/code/client/defaultEnvironment.js +194 -0
- package/kits/hub-game/code/client/doorErrors.js +39 -0
- package/kits/hub-game/code/client/fall.js +18 -0
- package/kits/hub-game/code/client/farAvatars.js +233 -0
- package/kits/hub-game/code/client/firstJoin.js +9 -2
- package/kits/hub-game/code/client/fpsTelemetry.js +50 -0
- package/kits/hub-game/code/client/frameBatch.js +5 -0
- package/kits/hub-game/code/client/grab.js +31 -11
- package/kits/hub-game/code/client/hookLayer.js +87 -8
- package/kits/hub-game/code/client/hudCopy.js +51 -0
- package/kits/hub-game/code/client/hudRate.js +20 -0
- package/kits/hub-game/code/client/idle.js +14 -2
- package/kits/hub-game/code/client/invites.js +231 -0
- package/kits/hub-game/code/client/joinError.js +9 -0
- package/kits/hub-game/code/client/labelsNear.js +31 -2
- package/kits/hub-game/code/client/landscapeLayout.js +17 -0
- package/kits/hub-game/code/client/layoutCache.js +264 -0
- package/kits/hub-game/code/client/loadTelemetry.js +20 -0
- package/kits/hub-game/code/client/loadingCover.js +148 -0
- package/kits/hub-game/code/client/loadingEntry.js +8 -0
- package/kits/hub-game/code/client/menuRows.js +43 -0
- package/kits/hub-game/code/client/modelReady.js +7 -0
- package/kits/hub-game/code/client/padCueArrival.js +23 -0
- package/kits/hub-game/code/client/padCues.js +112 -0
- package/kits/hub-game/code/client/padOccupancy.js +88 -0
- package/kits/hub-game/code/client/padReadability.js +26 -0
- package/kits/hub-game/code/client/padRings.js +69 -0
- package/kits/hub-game/code/client/pushVisit.js +14 -0
- package/kits/hub-game/code/client/quality.js +205 -0
- package/kits/hub-game/code/client/qualityEntry.js +55 -0
- package/kits/hub-game/code/client/safeLayout.js +338 -0
- package/kits/hub-game/code/client/safeStyle.js +42 -0
- package/kits/hub-game/code/client/say.js +12 -3
- package/kits/hub-game/code/client/shot.js +64 -10
- package/kits/hub-game/code/client/shotFit.js +56 -0
- package/kits/hub-game/code/client/signIn.js +28 -0
- package/kits/hub-game/code/client/state.js +53 -0
- package/kits/hub-game/code/client/talk.js +209 -45
- package/kits/hub-game/code/client/tiers.js +68 -66
- package/kits/hub-game/code/client/together.js +7 -2
- package/kits/hub-game/code/client/weakestLookBake.js +92 -0
- package/kits/hub-game/code/client/weakestTier.js +295 -0
- package/kits/hub-game/code/client/worldLabels.js +241 -0
- package/kits/hub-game/code/client/yours.js +10 -9
- package/kits/hub-game/code/npcDisplayText.js +55 -0
- package/kits/hub-game/code/server/act.js +124 -0
- package/kits/hub-game/code/server/actions.js +6 -1
- package/kits/hub-game/code/server/actors.js +2 -1
- package/kits/hub-game/code/server/analytics.js +83 -0
- package/kits/hub-game/code/server/anonymousEntry.js +49 -0
- package/kits/hub-game/code/server/arrivalPose.js +36 -0
- package/kits/hub-game/code/server/companion.js +28 -3
- package/kits/hub-game/code/server/doorAnalytics.js +52 -0
- package/kits/hub-game/code/server/earned.js +22 -5
- package/kits/hub-game/code/server/frameBatch.js +183 -0
- package/kits/hub-game/code/server/friendsAmong.js +49 -9
- package/kits/hub-game/code/server/history.js +2 -0
- package/kits/hub-game/code/server/hub.js +1306 -95
- package/kits/hub-game/code/server/idle.js +30 -1
- package/kits/hub-game/code/server/index.js +26 -4
- package/kits/hub-game/code/server/invites.js +19 -0
- package/kits/hub-game/code/server/labels.js +9 -1
- package/kits/hub-game/code/server/loadAbandon.js +106 -0
- package/kits/hub-game/code/server/manifest.js +211 -3
- package/kits/hub-game/code/server/menu.js +31 -3
- package/kits/hub-game/code/server/npcs.js +226 -64
- package/kits/hub-game/code/server/observe.js +408 -0
- package/kits/hub-game/code/server/padOccupancy.js +85 -0
- package/kits/hub-game/code/server/players.js +9 -1
- package/kits/hub-game/code/server/resumePose.js +152 -0
- package/kits/hub-game/code/server/say.js +1 -1
- package/kits/hub-game/code/server/standing.js +4 -5
- package/kits/hub-game/code/server/storageLimit.js +187 -0
- package/kits/hub-game/code/server/vis.js +67 -5
- package/kits/hub-game/code/shared/act.js +35 -0
- package/kits/hub-game/code/shared/danceIdle.js +28 -0
- package/kits/hub-game/code/shared/loadStages.js +12 -0
- package/kits/hub-game/code/shared/quality.js +74 -0
- package/kits/hub-game/code/shared/say.js +2 -0
- package/kits/hub-game/code/shared/shot.js +35 -1
- package/kits/hub-game/code/systems/hub.js +970 -169
- package/kits/hub-game/docs/analytics.md +279 -0
- package/kits/hub-game/docs/contract.md +1257 -42
- package/kits/hub-game/docs/home-pieces.md +9 -2
- package/kits/hub-game/docs/observed-progress.md +252 -0
- package/kits/hub-game/main.jsx +2 -0
- package/kits/hub-game/package-lock.json +10 -3
- package/kits/hub-game/package.json +6 -3
- package/kits/hub-game/play/player.js +142 -0
- package/kits/hub-game/play/registry.js +47 -0
- package/kits/hub-game/play.jsx +37 -0
- package/kits/hub-game/scripts/check.mjs +39 -5
- package/kits/hub-game/scripts/companion-follower-wire.json +1 -1
- package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +11 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless.json +5 -5
- package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +3 -0
- package/kits/hub-game/scripts/fixtures/fake-dom.mjs +19 -3
- package/kits/hub-game/scripts/fixtures/interest-legacy.json +3 -3
- package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -1
- package/kits/hub-game/scripts/pose-storage-fixture.mjs +46 -0
- package/kits/hub-game/scripts/test-act-client.mjs +186 -0
- package/kits/hub-game/scripts/test-act.mjs +171 -0
- package/kits/hub-game/scripts/test-action-layout.mjs +80 -0
- package/kits/hub-game/scripts/test-action-observers.mjs +46 -0
- package/kits/hub-game/scripts/test-actions-client.mjs +367 -2
- package/kits/hub-game/scripts/test-actors.mjs +20 -7
- package/kits/hub-game/scripts/test-analytics.mjs +76 -0
- package/kits/hub-game/scripts/test-anonymous-entry.mjs +28 -0
- package/kits/hub-game/scripts/test-arrival-pose-server.mjs +196 -0
- package/kits/hub-game/scripts/test-arrival-pose.mjs +24 -0
- package/kits/hub-game/scripts/test-ask-slot.mjs +85 -0
- package/kits/hub-game/scripts/test-avatar-wire.mjs +49 -10
- package/kits/hub-game/scripts/test-avatar.mjs +44 -0
- package/kits/hub-game/scripts/test-back-visibility.mjs +82 -0
- package/kits/hub-game/scripts/test-ballot.mjs +11 -4
- package/kits/hub-game/scripts/test-ban-join.mjs +121 -13
- package/kits/hub-game/scripts/test-build.mjs +20 -2
- package/kits/hub-game/scripts/test-chat.mjs +206 -5
- package/kits/hub-game/scripts/test-companion-chat.mjs +20 -2
- package/kits/hub-game/scripts/test-control-layout-dom.mjs +120 -0
- package/kits/hub-game/scripts/test-crowd-names.mjs +205 -0
- package/kits/hub-game/scripts/test-decor-client.mjs +45 -4
- package/kits/hub-game/scripts/test-decor.mjs +7 -0
- package/kits/hub-game/scripts/test-default-environment-root.mjs +95 -0
- package/kits/hub-game/scripts/test-default-environment.mjs +267 -0
- package/kits/hub-game/scripts/test-door-analytics.mjs +58 -0
- package/kits/hub-game/scripts/test-door-jump.mjs +100 -0
- package/kits/hub-game/scripts/test-earned.mjs +33 -3
- package/kits/hub-game/scripts/test-far-avatars.mjs +340 -0
- package/kits/hub-game/scripts/test-fps-telemetry.mjs +112 -0
- package/kits/hub-game/scripts/test-frame-batch.mjs +252 -0
- package/kits/hub-game/scripts/test-fresh-friends.mjs +118 -0
- package/kits/hub-game/scripts/test-grab-orbit.mjs +47 -4
- package/kits/hub-game/scripts/test-high-only.mjs +170 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +321 -2
- package/kits/hub-game/scripts/test-hub-trip.mjs +879 -11
- package/kits/hub-game/scripts/test-hud-clear.mjs +162 -59
- package/kits/hub-game/scripts/test-hud-defects-dom.mjs +100 -0
- package/kits/hub-game/scripts/test-hud-rate.mjs +224 -0
- package/kits/hub-game/scripts/test-hud-safe-visibility-dom.mjs +83 -0
- package/kits/hub-game/scripts/test-idle.mjs +66 -0
- package/kits/hub-game/scripts/test-interest-cells.mjs +20 -0
- package/kits/hub-game/scripts/test-interest.mjs +15 -0
- package/kits/hub-game/scripts/test-invites-client.mjs +430 -0
- package/kits/hub-game/scripts/test-invites.mjs +109 -0
- package/kits/hub-game/scripts/test-labels.mjs +71 -3
- package/kits/hub-game/scripts/test-landscape-layout.mjs +194 -0
- package/kits/hub-game/scripts/test-list-scroll-dom.mjs +49 -0
- package/kits/hub-game/scripts/test-load-abandon.mjs +246 -0
- package/kits/hub-game/scripts/test-loading-cover.mjs +162 -0
- package/kits/hub-game/scripts/test-manifest.mjs +265 -0
- package/kits/hub-game/scripts/test-menu-client.mjs +105 -0
- package/kits/hub-game/scripts/test-menu.mjs +23 -0
- package/kits/hub-game/scripts/test-npcs.mjs +819 -10
- package/kits/hub-game/scripts/test-observed.mjs +745 -0
- package/kits/hub-game/scripts/test-pad-cues.mjs +304 -0
- package/kits/hub-game/scripts/test-pad-occupancy.mjs +177 -0
- package/kits/hub-game/scripts/test-picker.mjs +234 -7
- package/kits/hub-game/scripts/test-placement-cache.mjs +690 -0
- package/kits/hub-game/scripts/test-progress-reset.mjs +559 -0
- package/kits/hub-game/scripts/test-push-visit.mjs +26 -0
- package/kits/hub-game/scripts/test-quality.mjs +385 -0
- package/kits/hub-game/scripts/test-rehello.mjs +699 -5
- package/kits/hub-game/scripts/test-resume-action-order.mjs +598 -0
- package/kits/hub-game/scripts/test-resume-held.mjs +239 -0
- package/kits/hub-game/scripts/test-resume-pose.mjs +142 -0
- package/kits/hub-game/scripts/test-safe-events-dom.mjs +116 -0
- package/kits/hub-game/scripts/test-safe-layout.mjs +330 -0
- package/kits/hub-game/scripts/test-say.mjs +1 -1
- package/kits/hub-game/scripts/test-shot.mjs +145 -0
- package/kits/hub-game/scripts/test-signin-client.mjs +45 -0
- package/kits/hub-game/scripts/test-soundscape.mjs +22 -17
- package/kits/hub-game/scripts/test-standing.mjs +35 -2
- package/kits/hub-game/scripts/test-storage-limit.mjs +333 -0
- package/kits/hub-game/scripts/test-stuck.mjs +5 -4
- package/kits/hub-game/scripts/test-talk-overlay-dom.mjs +130 -0
- package/kits/hub-game/scripts/test-tiers-render.mjs +86 -13
- package/kits/hub-game/scripts/test-tiers.mjs +7 -8
- package/kits/hub-game/scripts/test-vis.mjs +433 -6
- package/kits/hub-game/scripts/test-weakest-tier.mjs +924 -0
- package/kits/hub-game/scripts/test-world-labels.mjs +367 -0
- package/kits/hub-game/scripts/test-yours-chrome.mjs +50 -6
- package/kits/hub-game/scripts/test-yours.mjs +39 -8
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/joinFailure.js +27 -0
- package/kits/multiplayer-3d/code/client/resumeGate.js +139 -0
- package/kits/multiplayer-3d/code/systems/multiplayer.js +369 -30
- package/kits/multiplayer-3d/package-lock.json +8 -1
- package/kits/multiplayer-3d/package.json +2 -1
- package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +436 -0
- package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +624 -0
- package/kits/physics-2d/CLAUDE.md +10 -1
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/frozenActors.js +233 -0
- package/kits/physics-2d/engine/scene.js +87 -5
- package/kits/physics-2d/eslint.config.js +1 -1
- package/kits/physics-2d/play/behaviors/AnalogStick.js +198 -0
- package/kits/physics-2d/play/behaviors/Camera.js +40 -0
- package/kits/physics-2d/play/behaviors/Collider.js +122 -0
- package/kits/physics-2d/play/behaviors/Draggable.js +115 -0
- package/kits/physics-2d/play/behaviors/Goal.js +46 -0
- package/kits/physics-2d/play/behaviors/Joints.js +126 -0
- package/kits/physics-2d/play/behaviors/Layout.js +71 -0
- package/kits/physics-2d/play/behaviors/RigidBody.js +57 -0
- package/kits/physics-2d/play/behaviors/Slingshot.js +142 -0
- package/kits/physics-2d/play/behaviors/SoundPlayer.js +263 -0
- package/kits/physics-2d/play/behaviors/Sprite.js +406 -0
- package/kits/physics-2d/play/behaviors/Style.js +209 -0
- package/kits/physics-2d/play/behaviors/Text.js +85 -0
- package/kits/physics-2d/play/behaviors/Video.js +93 -0
- package/kits/physics-3d/CLAUDE.md +25 -1651
- package/kits/physics-3d/behaviors/Body.jsx +3 -0
- package/kits/physics-3d/behaviors/Model.jsx +3 -0
- package/kits/physics-3d/behaviors/Player.jsx +35 -18
- package/kits/physics-3d/behaviors/Shape.jsx +3 -0
- package/kits/physics-3d/behaviors/Solid.jsx +3 -0
- package/kits/physics-3d/behaviors/Transform.jsx +3 -0
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/docs/engine-camera.md +542 -0
- package/kits/physics-3d/docs/engine-frame-cap.md +136 -0
- package/kits/physics-3d/docs/engine-load.md +149 -0
- package/kits/physics-3d/docs/engine-look.md +114 -0
- package/kits/physics-3d/docs/engine-shadows.md +372 -0
- package/kits/physics-3d/docs/engine-skip-work.md +187 -0
- package/kits/physics-3d/docs/engine-sky.md +198 -0
- package/kits/physics-3d/docs/engine-static-actors.md +226 -0
- package/kits/physics-3d/docs/engine-view.md +37 -0
- package/kits/physics-3d/docs/pxmodel-format.md +1 -1
- package/kits/physics-3d/engine3d/PlayOnly3D.jsx +5 -1
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +19 -333
- package/kits/physics-3d/engine3d/actornode.js +1 -0
- package/kits/physics-3d/engine3d/branches.js +3 -13
- package/kits/physics-3d/engine3d/cage.js +2 -7
- package/kits/physics-3d/engine3d/cageops.js +2 -17
- package/kits/physics-3d/engine3d/dataBehaviors.js +12 -0
- package/kits/physics-3d/engine3d/framecap.js +4 -1
- package/kits/physics-3d/engine3d/frozenphysics.js +140 -0
- package/kits/physics-3d/engine3d/frozenstatics.js +273 -0
- package/kits/physics-3d/engine3d/gait.js +8 -0
- package/kits/physics-3d/engine3d/initialModelFiles.js +18 -0
- package/kits/physics-3d/engine3d/look.js +7 -0
- package/kits/physics-3d/engine3d/modelFiles.js +3 -17
- package/kits/physics-3d/engine3d/modelMath.js +49 -0
- package/kits/physics-3d/engine3d/modelready.js +16 -0
- package/kits/physics-3d/engine3d/motion.js +3 -3
- package/kits/physics-3d/engine3d/nearshadows.js +77 -10
- package/kits/physics-3d/engine3d/orbitinput.js +59 -25
- package/kits/physics-3d/engine3d/partgeometry.js +1 -16
- package/kits/physics-3d/engine3d/paths.js +1 -9
- package/kits/physics-3d/engine3d/playTimings.js +50 -0
- package/kits/physics-3d/engine3d/playerRun.js +372 -0
- package/kits/physics-3d/engine3d/pxmodel.js +3 -3
- package/kits/physics-3d/engine3d/rapier.js +27 -0
- package/kits/physics-3d/engine3d/scatter.js +1 -11
- package/kits/physics-3d/engine3d/shadowfade.js +23 -15
- package/kits/physics-3d/engine3d/sky.js +1 -1
- package/kits/physics-3d/engine3d/squarefirst.js +177 -0
- package/kits/physics-3d/engine3d/stillshadows.js +399 -0
- package/kits/physics-3d/engine3d/sweep.js +1 -25
- package/kits/physics-3d/engine3d/world3d.js +468 -18
- package/kits/physics-3d/eslint.config.js +2 -1
- package/kits/physics-3d/main.jsx +6 -3
- package/kits/physics-3d/package-lock.json +7 -0
- package/kits/physics-3d/package.json +5 -1
- package/kits/physics-3d/play/behaviors/Body.js +31 -0
- package/kits/physics-3d/play/behaviors/Door.js +37 -0
- package/kits/physics-3d/play/behaviors/Lookable.js +16 -0
- package/kits/physics-3d/play/behaviors/Model.js +23 -0
- package/kits/physics-3d/play/behaviors/Pickup.js +46 -0
- package/kits/physics-3d/play/behaviors/Player.js +1204 -0
- package/kits/physics-3d/play/behaviors/Shape.js +47 -0
- package/kits/physics-3d/play/behaviors/Solid.js +16 -0
- package/kits/physics-3d/play/behaviors/Transform.js +29 -0
- package/kits/physics-3d/pnpm-lock.yaml +8 -0
- package/kits/physics-3d/scripts/bench-shadow-fade.mjs +37 -0
- package/kits/physics-3d/scripts/build-rapier-gz.mjs +56 -0
- package/kits/physics-3d/scripts/frozen-statics-fixture.mjs +141 -0
- package/kits/physics-3d/scripts/test-camera-follow.mjs +5 -1
- package/kits/physics-3d/scripts/test-camera-orbit.mjs +52 -4
- package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +1 -1
- package/kits/physics-3d/scripts/test-empty-gait-hints.mjs +89 -0
- package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +6 -3
- package/kits/physics-3d/scripts/test-frame-cap.mjs +1 -1
- package/kits/physics-3d/scripts/test-frozen-nested.mjs +49 -0
- package/kits/physics-3d/scripts/test-frozen-statics-legacy-physics2d.mjs +123 -0
- package/kits/physics-3d/scripts/test-frozen-statics.mjs +434 -0
- package/kits/physics-3d/scripts/test-look-bake.mjs +1 -1
- package/kits/physics-3d/scripts/test-near-shadows.mjs +2 -2
- package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +88 -7
- package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +40 -3
- package/kits/physics-3d/scripts/test-orbit-shot.mjs +75 -1
- package/kits/physics-3d/scripts/test-rapier-gz.mjs +106 -0
- package/kits/physics-3d/scripts/test-sky.mjs +1 -1
- package/kits/physics-3d/scripts/test-square-first.mjs +921 -0
- package/kits/physics-3d/scripts/test-static-actors.mjs +3 -1
- package/kits/physics-3d/scripts/test-static-physics.mjs +4 -1
- package/kits/physics-3d/scripts/test-static-scenery.mjs +5 -2
- package/kits/physics-3d/scripts/test-steady-hover.mjs +5 -2
- package/kits/physics-3d/scripts/test-still-shadows.mjs +477 -0
- package/kits/physics-3d/systems/physics3d.js +37 -4
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/connection.js +33 -10
- package/kits/real-time/code/client/gameHooks.js +2 -0
- package/kits/real-time/code/client/joinOverlay.js +9 -4
- package/kits/real-time/code/server/session.js +6 -4
- package/kits/real-time/package-lock.json +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
// A scene may opt its existing multiplayer name sprites into a bounded crowd
|
|
2
|
+
// pass (`engine.hubCrowdNames`). The caller supplies only tags the avatar
|
|
3
|
+
// renderer already authorized and drew; this module never discovers players.
|
|
4
|
+
|
|
5
|
+
export const ENTER_M = 1;
|
|
6
|
+
export const LEAVE_M = 1.25;
|
|
7
|
+
export const HOLD_MS = 500;
|
|
8
|
+
export const RESTORE_MS = 250;
|
|
9
|
+
export const RESTORE_PX = 8;
|
|
10
|
+
export const MAX_CANDIDATES = 24;
|
|
11
|
+
export const MIN_FONT_PX = 15;
|
|
12
|
+
|
|
13
|
+
const TAG_FONT_PX = 44;
|
|
14
|
+
const TAG_CANVAS_H = 68;
|
|
15
|
+
|
|
16
|
+
const inView = (box, view) => box && box.left >= 8 && box.top >= 8 && box.right <= view.w - 8 && box.bottom <= view.h - 8;
|
|
17
|
+
const touches = (a, b, gap = 0) => a.left - gap < b.right && b.left - gap < a.right && a.top - gap < b.bottom && b.top - gap < a.bottom;
|
|
18
|
+
const pairKey = (a, b) => JSON.stringify(a < b ? [a, b] : [b, a]);
|
|
19
|
+
const distanceBucket = (d) => Math.floor(Math.max(0, d) * 4);
|
|
20
|
+
|
|
21
|
+
export function makeCrowdNames() {
|
|
22
|
+
return {
|
|
23
|
+
nearPairs: new Set(),
|
|
24
|
+
chosen: new Set(),
|
|
25
|
+
chosenAt: new Map(),
|
|
26
|
+
friends: new Map(),
|
|
27
|
+
suppressed: new Set(),
|
|
28
|
+
clearSince: new Map(),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// State belongs to one loaded scene on one live connection. In particular, a
|
|
33
|
+
// reconnect cannot carry a retained slot into a newly authorized roster.
|
|
34
|
+
export function crowdNamesFor(holder, scope) {
|
|
35
|
+
const was = holder.scope;
|
|
36
|
+
if (!holder.state || !was || was.scene !== scope.scene || was.data !== scope.data || was.net !== scope.net || was.place !== scope.place || was.visit !== scope.visit) {
|
|
37
|
+
holder.state = makeCrowdNames();
|
|
38
|
+
holder.scope = { ...scope };
|
|
39
|
+
}
|
|
40
|
+
return holder.state;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function rank(state, now, a, b) {
|
|
44
|
+
const aHeld = state.chosen.has(a.id) && now - (state.chosenAt.get(a.id) ?? -Infinity) < HOLD_MS;
|
|
45
|
+
const bHeld = state.chosen.has(b.id) && now - (state.chosenAt.get(b.id) ?? -Infinity) < HOLD_MS;
|
|
46
|
+
return Number(Boolean(b.friend)) - Number(Boolean(a.friend)) ||
|
|
47
|
+
Number(bHeld) - Number(aHeld) ||
|
|
48
|
+
distanceBucket(a.distance) - distanceBucket(b.distance) ||
|
|
49
|
+
(a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function groupsOf(items, state) {
|
|
53
|
+
const parent = new Map(items.map((item) => [item.id, item.id]));
|
|
54
|
+
const find = (id) => {
|
|
55
|
+
let root = id;
|
|
56
|
+
while (parent.get(root) !== root) {root = parent.get(root);}
|
|
57
|
+
while (parent.get(id) !== id) {
|
|
58
|
+
const next = parent.get(id);
|
|
59
|
+
parent.set(id, root);
|
|
60
|
+
id = next;
|
|
61
|
+
}
|
|
62
|
+
return root;
|
|
63
|
+
};
|
|
64
|
+
const join = (a, b) => {
|
|
65
|
+
const ar = find(a), br = find(b);
|
|
66
|
+
if (ar !== br) {parent.set(br, ar);}
|
|
67
|
+
};
|
|
68
|
+
let pairTests = 0;
|
|
69
|
+
const livePairs = new Set();
|
|
70
|
+
for (let i = 0; i < items.length; i += 1) {
|
|
71
|
+
for (let j = i + 1; j < items.length; j += 1) {
|
|
72
|
+
pairTests += 1;
|
|
73
|
+
const a = items[i], b = items[j];
|
|
74
|
+
const key = pairKey(a.id, b.id);
|
|
75
|
+
const near = Math.hypot(a.at.x - b.at.x, a.at.z - b.at.z) <= (state.nearPairs.has(key) ? LEAVE_M : ENTER_M);
|
|
76
|
+
if (near) {livePairs.add(key);}
|
|
77
|
+
if (near || touches(a.box, b.box)) {join(a.id, b.id);}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
state.nearPairs = livePairs;
|
|
81
|
+
const groups = new Map();
|
|
82
|
+
for (const item of items) {
|
|
83
|
+
const root = find(item.id);
|
|
84
|
+
const group = groups.get(root) ?? [];
|
|
85
|
+
group.push(item);
|
|
86
|
+
groups.set(root, group);
|
|
87
|
+
}
|
|
88
|
+
return { groups: [...groups.values()], pairTests };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Returns stable player ids whose existing sprites remain visible, plus an
|
|
92
|
+
// anonymous summary request. `candidates` are current authorized, baseline-
|
|
93
|
+
// visible tags: `{ id, friend, distance, at:{x,z}, box }`.
|
|
94
|
+
export function layoutCrowdNames(state, candidates, { now, view, obstacles = [] }) {
|
|
95
|
+
const live = new Set(candidates.map((candidate) => candidate.id));
|
|
96
|
+
// Losing friend priority is effective in this frame; it cannot borrow the
|
|
97
|
+
// old priority's retained-slot hold.
|
|
98
|
+
let friendRevoked = false;
|
|
99
|
+
for (const candidate of candidates) {
|
|
100
|
+
if (state.friends.get(candidate.id) === true && candidate.friend !== true) {
|
|
101
|
+
state.chosen.delete(candidate.id);
|
|
102
|
+
state.chosenAt.delete(candidate.id);
|
|
103
|
+
friendRevoked = true;
|
|
104
|
+
}
|
|
105
|
+
state.friends.set(candidate.id, candidate.friend === true);
|
|
106
|
+
}
|
|
107
|
+
if (friendRevoked) {
|
|
108
|
+
state.suppressed.clear();
|
|
109
|
+
state.clearSince.clear();
|
|
110
|
+
}
|
|
111
|
+
for (const id of state.chosen) {
|
|
112
|
+
if (!live.has(id)) {
|
|
113
|
+
state.chosen.delete(id);
|
|
114
|
+
state.chosenAt.delete(id);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
for (const id of state.suppressed) {
|
|
118
|
+
if (!live.has(id)) {
|
|
119
|
+
state.suppressed.delete(id);
|
|
120
|
+
state.clearSince.delete(id);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
for (const id of state.friends.keys()) {
|
|
124
|
+
if (!live.has(id)) {state.friends.delete(id);}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const drawable = candidates.filter((candidate) => inView(candidate.box, view));
|
|
128
|
+
drawable.sort((a, b) => rank(state, now, a, b));
|
|
129
|
+
const bounded = drawable.slice(0, MAX_CANDIDATES);
|
|
130
|
+
const overflow = drawable.slice(MAX_CANDIDATES);
|
|
131
|
+
const { groups, pairTests } = groupsOf(bounded, state);
|
|
132
|
+
const tiny = view.w <= 509 && view.h <= 218;
|
|
133
|
+
const chosen = new Set();
|
|
134
|
+
const chosenBoxes = [];
|
|
135
|
+
const summary = [];
|
|
136
|
+
|
|
137
|
+
for (const group of groups) {
|
|
138
|
+
const dense = group.length > 1;
|
|
139
|
+
group.sort((a, b) => rank(state, now, a, b));
|
|
140
|
+
const limit = tiny ? 0 : dense ? 2 : 1;
|
|
141
|
+
let used = 0;
|
|
142
|
+
for (const candidate of group) {
|
|
143
|
+
const blocked = obstacles.some((box) => touches(candidate.box, box));
|
|
144
|
+
const conflicts = chosenBoxes.some((box) => touches(candidate.box, box));
|
|
145
|
+
let allowed = used < limit && !blocked && !conflicts;
|
|
146
|
+
let waiting = false;
|
|
147
|
+
if (allowed && state.suppressed.has(candidate.id)) {
|
|
148
|
+
const separated = !obstacles.some((box) => touches(candidate.box, box, RESTORE_PX)) &&
|
|
149
|
+
!chosenBoxes.some((box) => touches(candidate.box, box, RESTORE_PX));
|
|
150
|
+
if (!separated) {
|
|
151
|
+
state.clearSince.delete(candidate.id);
|
|
152
|
+
allowed = false;
|
|
153
|
+
} else {
|
|
154
|
+
const since = state.clearSince.get(candidate.id);
|
|
155
|
+
if (since === undefined) {
|
|
156
|
+
state.clearSince.set(candidate.id, now);
|
|
157
|
+
allowed = false;
|
|
158
|
+
waiting = true;
|
|
159
|
+
} else if (now - since < RESTORE_MS) {
|
|
160
|
+
allowed = false;
|
|
161
|
+
waiting = true;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (allowed) {
|
|
166
|
+
chosen.add(candidate.id);
|
|
167
|
+
chosenBoxes.push(candidate.box);
|
|
168
|
+
used += 1;
|
|
169
|
+
} else {
|
|
170
|
+
if (!waiting) {state.clearSince.delete(candidate.id);}
|
|
171
|
+
if (dense || tiny) {summary.push(candidate);}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
summary.push(...overflow);
|
|
176
|
+
|
|
177
|
+
const previous = state.chosen;
|
|
178
|
+
state.chosen = chosen;
|
|
179
|
+
state.suppressed = new Set(drawable.filter((candidate) => !chosen.has(candidate.id)).map((candidate) => candidate.id));
|
|
180
|
+
for (const id of chosen) {
|
|
181
|
+
if (!previous.has(id)) {state.chosenAt.set(id, now);}
|
|
182
|
+
}
|
|
183
|
+
for (const id of [...state.chosenAt.keys()]) {
|
|
184
|
+
if (!chosen.has(id)) {state.chosenAt.delete(id);}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
let summaryAt = null;
|
|
188
|
+
if (summary.length) {
|
|
189
|
+
summaryAt = {
|
|
190
|
+
x: summary.reduce((sum, candidate) => sum + (candidate.box.left + candidate.box.right) / 2, 0) / summary.length,
|
|
191
|
+
y: Math.min(...summary.map((candidate) => candidate.box.top)) - 6,
|
|
192
|
+
count: summary.length,
|
|
193
|
+
tiny,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
return { visible: chosen, summary: summaryAt, pairTests, considered: bounded.length };
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// The multiplayer tag is a camera-facing sprite. Project its current camera
|
|
200
|
+
// right/up extents so collisions use the final CSS-pixel rectangle rather than
|
|
201
|
+
// stale texture or unscaled text dimensions.
|
|
202
|
+
export function spriteBox(sprite, cam, view, project) {
|
|
203
|
+
const at = sprite?.position;
|
|
204
|
+
const matrix = cam?.matrixWorld?.elements;
|
|
205
|
+
if (!at || !matrix) {return null;}
|
|
206
|
+
const right = { x: matrix[0], y: matrix[1], z: matrix[2] };
|
|
207
|
+
const up = { x: matrix[4], y: matrix[5], z: matrix[6] };
|
|
208
|
+
const halfW = Math.abs(sprite.scale?.x ?? 0) / 2;
|
|
209
|
+
const halfH = Math.abs(sprite.scale?.y ?? 0) / 2;
|
|
210
|
+
const left = project(cam, at.x - right.x * halfW, at.y - right.y * halfW, at.z - right.z * halfW, view);
|
|
211
|
+
const rightAt = project(cam, at.x + right.x * halfW, at.y + right.y * halfW, at.z + right.z * halfW, view);
|
|
212
|
+
const top = project(cam, at.x + up.x * halfH, at.y + up.y * halfH, at.z + up.z * halfH, view);
|
|
213
|
+
const bottom = project(cam, at.x - up.x * halfH, at.y - up.y * halfH, at.z - up.z * halfH, view);
|
|
214
|
+
if (!left || !rightAt || !top || !bottom) {return null;}
|
|
215
|
+
return {
|
|
216
|
+
left: Math.min(left.x, rightAt.x),
|
|
217
|
+
right: Math.max(left.x, rightAt.x),
|
|
218
|
+
top: Math.min(top.y, bottom.y),
|
|
219
|
+
bottom: Math.max(top.y, bottom.y),
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// E may enlarge an already-rendered multiplayer plate just enough for its
|
|
224
|
+
// 44px canvas font to read at 15 CSS pixels. The returned box is projected
|
|
225
|
+
// again after the scale write, so collision uses the current camera result.
|
|
226
|
+
export function readableSpriteBox(sprite, cam, view, project) {
|
|
227
|
+
let box = spriteBox(sprite, cam, view, project);
|
|
228
|
+
if (!box) {return { box: null, resized: null };}
|
|
229
|
+
const fontPx = (box.bottom - box.top) * TAG_FONT_PX / TAG_CANVAS_H;
|
|
230
|
+
if (!(fontPx > 0) || fontPx >= MIN_FONT_PX) {
|
|
231
|
+
return { box, resized: null };
|
|
232
|
+
}
|
|
233
|
+
const x = sprite.scale.x;
|
|
234
|
+
const y = sprite.scale.y;
|
|
235
|
+
const factor = MIN_FONT_PX / fontPx;
|
|
236
|
+
sprite.scale.x = x * factor;
|
|
237
|
+
sprite.scale.y = y * factor;
|
|
238
|
+
const resized = { x, y, scaledX: sprite.scale.x, scaledY: sprite.scale.y };
|
|
239
|
+
box = spriteBox(sprite, cam, view, project);
|
|
240
|
+
return { box, resized };
|
|
241
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ensureActorModel } from './modelReady.js';
|
|
1
2
|
// Decorating (v1.67): private chrome and local previews. No actor or body is
|
|
2
3
|
// changed: the deck's server hook decides every edit and sends the catalogue
|
|
3
4
|
// back. Made only in a place with `decor`, under the existing chrome root.
|
|
@@ -19,6 +20,7 @@ function el(tag, style, parent, text) {
|
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
export function makeDecor(chrome, { renderer = () => new THREE.WebGLRenderer({ alpha: true, antialias: true, preserveDrawingBuffer: true }) } = {}) {
|
|
23
|
+
const geometry = chrome.layoutGeometry?.();
|
|
22
24
|
const listeners = new AbortController();
|
|
23
25
|
function button(parent, label, action, style = {}) {
|
|
24
26
|
const node = el('button', { border: '0', borderRadius: '22px', minHeight: '44px', padding: '10px 14px', font: FONT, color: '#26222b', background: '#fff', cursor: 'pointer', touchAction: 'manipulation', ...style }, parent, label);
|
|
@@ -119,6 +121,7 @@ export function makeDecor(chrome, { renderer = () => new THREE.WebGLRenderer({ a
|
|
|
119
121
|
chrome.setDecorating(false);
|
|
120
122
|
}
|
|
121
123
|
function cloneActor(id) {
|
|
124
|
+
ensureActorModel(t.scene?.three, id);
|
|
122
125
|
const entry = t.scene?.three?.nodes.get(id);
|
|
123
126
|
if (!entry) {
|
|
124
127
|
return null;
|
|
@@ -340,7 +343,7 @@ export function makeDecor(chrome, { renderer = () => new THREE.WebGLRenderer({ a
|
|
|
340
343
|
if (!camera || !t.grid) {
|
|
341
344
|
return null;
|
|
342
345
|
}
|
|
343
|
-
const rect = root.getBoundingClientRect();
|
|
346
|
+
const rect = geometry?.rect(root) ?? root.getBoundingClientRect();
|
|
344
347
|
ray.setFromCamera(new THREE.Vector2((event.clientX - rect.left) / rect.width * 2 - 1, 1 - (event.clientY - rect.top) / rect.height * 2), camera);
|
|
345
348
|
plane.constant = -t.grid.y;
|
|
346
349
|
if (!ray.ray.intersectPlane(plane, point)) {
|
|
@@ -412,6 +415,8 @@ export function makeDecor(chrome, { renderer = () => new THREE.WebGLRenderer({ a
|
|
|
412
415
|
world.addEventListener('pointercancel', up, { signal: listeners.signal });
|
|
413
416
|
root.addEventListener('pointerdown', (event) => event.stopPropagation(), { signal: listeners.signal });
|
|
414
417
|
|
|
418
|
+
for (const node of [root, enter, header, tray, actions]) {geometry?.register(node);}
|
|
419
|
+
|
|
415
420
|
return {
|
|
416
421
|
opened: () => t.open,
|
|
417
422
|
clear,
|
|
@@ -486,12 +491,12 @@ export function makeDecor(chrome, { renderer = () => new THREE.WebGLRenderer({ a
|
|
|
486
491
|
rotate.disabled = false;
|
|
487
492
|
stash.textContent = t.lift.key ? 'Put away' : 'Cancel';
|
|
488
493
|
const p = t.ghost?.position.clone().project(scene.three.camera);
|
|
489
|
-
const rect = root.getBoundingClientRect();
|
|
490
|
-
const trayTop = tray.getBoundingClientRect().top - rect.top;
|
|
494
|
+
const rect = geometry?.rect(root) ?? root.getBoundingClientRect();
|
|
495
|
+
const trayTop = (geometry?.rect(tray) ?? tray.getBoundingClientRect()).top - rect.top;
|
|
491
496
|
const x = p && p.z < 1 && p.z > -1 ? (p.x + 1) * rect.width / 2 : rect.width / 2;
|
|
492
497
|
const y = p && p.z < 1 && p.z > -1 ? (1 - p.y) * rect.height / 2 - 42 : trayTop - 16;
|
|
493
498
|
actions.style.left = `${Math.max(145, Math.min(rect.width - 145, x))}px`;
|
|
494
|
-
actions.style.top = `${Math.max(header.offsetHeight + 82, Math.min(trayTop - 12, y))}px`;
|
|
499
|
+
actions.style.top = `${Math.max((geometry?.size(header).h ?? header.offsetHeight) + 82, Math.min(trayTop - 12, y))}px`;
|
|
495
500
|
}
|
|
496
501
|
},
|
|
497
502
|
dispose() {
|
|
@@ -503,6 +508,7 @@ export function makeDecor(chrome, { renderer = () => new THREE.WebGLRenderer({ a
|
|
|
503
508
|
t.thumbScene = null;
|
|
504
509
|
t.scene = null;
|
|
505
510
|
t.net = null;
|
|
511
|
+
geometry?.unregister(root);
|
|
506
512
|
root.remove();
|
|
507
513
|
},
|
|
508
514
|
};
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { Color, Fog } from 'three';
|
|
2
|
+
|
|
3
|
+
// A hub game's fallback picture. It is deliberately only a clear colour and
|
|
4
|
+
// Three's built-in linear fog: no mesh, texture, shader or render pass. The
|
|
5
|
+
// fog begins before the engine's 60 m ground reaches its edge, while leaving
|
|
6
|
+
// enough distance for an ordinary door game's whole yard.
|
|
7
|
+
export const DEFAULT_SKY_COLOR = '#bfe3f2';
|
|
8
|
+
export const DEFAULT_FOG_NEAR = 18;
|
|
9
|
+
export const DEFAULT_FOG_FAR = 60;
|
|
10
|
+
export const FALL_FADE_BELOW_M = 1;
|
|
11
|
+
export const FALL_RETURN_S = 0.45;
|
|
12
|
+
|
|
13
|
+
const hexColor = (value) => typeof value === 'string' && /^#[\da-f]{6}$/i.test(value);
|
|
14
|
+
const clamp01 = (value) => Math.max(0, Math.min(1, value));
|
|
15
|
+
|
|
16
|
+
// Presence is intentional here. A malformed/newer authored key keeps the
|
|
17
|
+
// picture it had before rather than silently becoming the hub fallback, and a
|
|
18
|
+
// tier may shadow the parsed `scene.sky` getter with an own null without
|
|
19
|
+
// making the authored scene keyless.
|
|
20
|
+
export function hasAuthoredEnvironment(data) {
|
|
21
|
+
const engine = data?.engine;
|
|
22
|
+
return Boolean(
|
|
23
|
+
(data && Object.hasOwn(data, 'background')) ||
|
|
24
|
+
(engine && (Object.hasOwn(engine, 'sky') || Object.hasOwn(engine, 'view')))
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function colorEquals(a, b) {
|
|
29
|
+
return Boolean(a?.isColor && b?.isColor && a.equals(b));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function rendererColor(renderer) {
|
|
33
|
+
if (typeof renderer?.getClearColor !== 'function') {return null;}
|
|
34
|
+
return renderer.getClearColor(new Color()).clone();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function clearAlpha(renderer) {
|
|
38
|
+
return typeof renderer?.getClearAlpha === 'function' ? renderer.getClearAlpha() : 1;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function zoneColor(scene) {
|
|
42
|
+
const data = scene?.data;
|
|
43
|
+
const viewColor = data?.engine?.view?.fogColor;
|
|
44
|
+
if (hexColor(viewColor)) {return new Color(viewColor);}
|
|
45
|
+
const fogColor = scene?.three?.scene?.fog?.color;
|
|
46
|
+
if (fogColor?.isColor) {return fogColor.clone();}
|
|
47
|
+
|
|
48
|
+
const zones = data?.engine?.sky?.zones;
|
|
49
|
+
if (Array.isArray(zones) && zones.length) {
|
|
50
|
+
const state = scene.skyZone;
|
|
51
|
+
const byId = new Map(zones.filter((zone) => hexColor(zone?.color)).map((zone) => [zone.id, zone.color]));
|
|
52
|
+
const home = zones.find((zone) => zone?.box === undefined && hexColor(zone?.color));
|
|
53
|
+
const from = byId.get(state?.from) ?? byId.get(state?.id) ?? home?.color ?? zones.find((zone) => hexColor(zone?.color))?.color;
|
|
54
|
+
if (from) {
|
|
55
|
+
const color = new Color(from);
|
|
56
|
+
const to = byId.get(state?.to);
|
|
57
|
+
if (to && state?.blend > 0) {color.lerp(new Color(to), clamp01(state.blend));}
|
|
58
|
+
return color;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const background = scene?.three?.scene?.background;
|
|
62
|
+
if (background?.isColor) {return background.clone();}
|
|
63
|
+
if (hexColor(data?.background)) {return new Color(data.background);}
|
|
64
|
+
return new Color(DEFAULT_SKY_COLOR);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function cssColor(color) {
|
|
68
|
+
return `#${color.getHexString()}`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// The default environment is scene-local and owns only the exact values it
|
|
72
|
+
// writes. `frame` also supplies the fall transition for authored scenes: the
|
|
73
|
+
// WebGL canvas fades over its parent's sky/fog colour, which covers materials
|
|
74
|
+
// that opt out of fog without another render pass. Chrome remains readable.
|
|
75
|
+
export function makeDefaultEnvironment() {
|
|
76
|
+
const state = {
|
|
77
|
+
scene: null,
|
|
78
|
+
data: null,
|
|
79
|
+
world: null,
|
|
80
|
+
fog: null,
|
|
81
|
+
fogBefore: null,
|
|
82
|
+
clearBefore: null,
|
|
83
|
+
clearAlpha: 1,
|
|
84
|
+
clearWritten: null,
|
|
85
|
+
fade: 0,
|
|
86
|
+
canvas: null,
|
|
87
|
+
parent: null,
|
|
88
|
+
opacityBefore: '',
|
|
89
|
+
backgroundBefore: '',
|
|
90
|
+
opacityWritten: null,
|
|
91
|
+
backgroundWritten: null,
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const restorePicture = () => {
|
|
95
|
+
const world = state.world;
|
|
96
|
+
if (world?.scene?.fog === state.fog) {world.scene.fog = state.fogBefore;}
|
|
97
|
+
const renderer = world?.renderer;
|
|
98
|
+
const current = rendererColor(renderer);
|
|
99
|
+
if (state.clearWritten && colorEquals(current, state.clearWritten) && clearAlpha(renderer) === state.clearAlpha) {
|
|
100
|
+
renderer.setClearColor(state.clearBefore, state.clearAlpha);
|
|
101
|
+
}
|
|
102
|
+
state.fog = null;
|
|
103
|
+
state.fogBefore = null;
|
|
104
|
+
state.clearBefore = null;
|
|
105
|
+
state.clearWritten = null;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const restoreFade = () => {
|
|
109
|
+
if (state.canvas && state.opacityWritten !== null && state.canvas.style.opacity === state.opacityWritten) {
|
|
110
|
+
state.canvas.style.opacity = state.opacityBefore;
|
|
111
|
+
}
|
|
112
|
+
if (state.parent && state.backgroundWritten !== null && state.parent.style.background === state.backgroundWritten) {
|
|
113
|
+
state.parent.style.background = state.backgroundBefore;
|
|
114
|
+
}
|
|
115
|
+
state.fade = 0;
|
|
116
|
+
state.canvas = null;
|
|
117
|
+
state.parent = null;
|
|
118
|
+
state.opacityBefore = '';
|
|
119
|
+
state.backgroundBefore = '';
|
|
120
|
+
state.opacityWritten = null;
|
|
121
|
+
state.backgroundWritten = null;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const restore = () => {
|
|
125
|
+
restoreFade();
|
|
126
|
+
restorePicture();
|
|
127
|
+
state.scene = null;
|
|
128
|
+
state.data = null;
|
|
129
|
+
state.world = null;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const adopt = (scene) => {
|
|
133
|
+
const world = scene?.three;
|
|
134
|
+
if (state.scene === scene && state.data === scene?.data && state.world === world) {return;}
|
|
135
|
+
restore();
|
|
136
|
+
if (!world) {return;}
|
|
137
|
+
state.scene = scene;
|
|
138
|
+
state.data = scene.data;
|
|
139
|
+
state.world = world;
|
|
140
|
+
if (hasAuthoredEnvironment(scene.data) || world.scene?.background || world.scene?.fog) {return;}
|
|
141
|
+
const renderer = world.renderer;
|
|
142
|
+
const before = rendererColor(renderer);
|
|
143
|
+
if (!before || typeof renderer.setClearColor !== 'function') {return;}
|
|
144
|
+
state.fogBefore = world.scene.fog;
|
|
145
|
+
state.fog = new Fog(DEFAULT_SKY_COLOR, DEFAULT_FOG_NEAR, DEFAULT_FOG_FAR);
|
|
146
|
+
world.scene.fog = state.fog;
|
|
147
|
+
state.clearBefore = before;
|
|
148
|
+
state.clearAlpha = clearAlpha(renderer);
|
|
149
|
+
state.clearWritten = new Color(DEFAULT_SKY_COLOR);
|
|
150
|
+
renderer.setClearColor(state.clearWritten, state.clearAlpha);
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const drawFade = (scene, amount) => {
|
|
154
|
+
const canvas = scene?.three?.renderer?.domElement;
|
|
155
|
+
const parent = canvas?.parentElement;
|
|
156
|
+
if (!canvas?.style || !parent?.style) {return;}
|
|
157
|
+
if (state.canvas !== canvas || state.parent !== parent) {
|
|
158
|
+
const fade = state.fade;
|
|
159
|
+
restoreFade();
|
|
160
|
+
state.fade = fade;
|
|
161
|
+
state.canvas = canvas;
|
|
162
|
+
state.parent = parent;
|
|
163
|
+
state.opacityBefore = canvas.style.opacity;
|
|
164
|
+
state.backgroundBefore = parent.style.background;
|
|
165
|
+
}
|
|
166
|
+
const color = cssColor(zoneColor(scene));
|
|
167
|
+
const opacity = String(1 - amount);
|
|
168
|
+
canvas.style.opacity = opacity;
|
|
169
|
+
parent.style.background = color;
|
|
170
|
+
// CSSOM normalizes colours (usually to rgb(...)) and sometimes numbers.
|
|
171
|
+
// Remember what the browser retained, not what was assigned.
|
|
172
|
+
state.opacityWritten = canvas.style.opacity;
|
|
173
|
+
state.backgroundWritten = parent.style.background;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const frame = (scene, local, fallY, dt = 0, enabled = true) => {
|
|
177
|
+
if (enabled === false) {
|
|
178
|
+
restore();
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
adopt(scene);
|
|
182
|
+
const y = local?.components?.Transform?.y;
|
|
183
|
+
let target = 0;
|
|
184
|
+
if (typeof fallY === 'number' && Number.isFinite(y)) {
|
|
185
|
+
target = clamp01((fallY - y) / FALL_FADE_BELOW_M);
|
|
186
|
+
}
|
|
187
|
+
if (target > state.fade) {state.fade = target;}
|
|
188
|
+
else {state.fade = Math.max(target, state.fade - Math.max(0, dt) / FALL_RETURN_S);}
|
|
189
|
+
if (state.fade > 0) {drawFade(scene, state.fade);}
|
|
190
|
+
else if (state.canvas) {restoreFade();}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
return { frame, restore };
|
|
194
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Report only a fixed category to the current server. Never inspect error text.
|
|
2
|
+
export function makeDoorErrors(win = globalThis.window, doc = globalThis.document) {
|
|
3
|
+
let target = null, listening = false, last = null, next = 0;
|
|
4
|
+
const report = result => {
|
|
5
|
+
if (!target || doc?.visibilityState === 'hidden' || target.closed?.() ||
|
|
6
|
+
(target.status && target.status().state !== 'connected')) {return;}
|
|
7
|
+
const now = Date.now();
|
|
8
|
+
if (now < next) {return;}
|
|
9
|
+
next = now + 10000;
|
|
10
|
+
try {target.send({ k: 'hub-door-error', result });} catch { /* Best effort. */ }
|
|
11
|
+
};
|
|
12
|
+
const exception = () => report(2);
|
|
13
|
+
const visibility = () => {last = null;};
|
|
14
|
+
return {
|
|
15
|
+
sync(net, enabled, now) {
|
|
16
|
+
if (!enabled || target !== net) {last = null;}
|
|
17
|
+
target = enabled ? net : null;
|
|
18
|
+
if (Boolean(target) !== listening && win?.addEventListener) {
|
|
19
|
+
for (const name of ['error', 'unhandledrejection']) {
|
|
20
|
+
if (target) {win.addEventListener(name, exception);}
|
|
21
|
+
else {win.removeEventListener(name, exception);}
|
|
22
|
+
}
|
|
23
|
+
if (target) {doc?.addEventListener?.('visibilitychange', visibility);}
|
|
24
|
+
else {doc?.removeEventListener?.('visibilitychange', visibility);}
|
|
25
|
+
listening = Boolean(target);
|
|
26
|
+
}
|
|
27
|
+
// A visible render gap >= 2 seconds. Hidden tabs do not count as stalls.
|
|
28
|
+
if (target && doc?.visibilityState !== 'hidden' && last !== null && now - last >= 2000) {report(1);}
|
|
29
|
+
last = target && doc?.visibilityState !== 'hidden' ? now : null;
|
|
30
|
+
},
|
|
31
|
+
dispose() {
|
|
32
|
+
if (listening) {
|
|
33
|
+
for (const name of ['error', 'unhandledrejection']) {win.removeEventListener(name, exception);}
|
|
34
|
+
}
|
|
35
|
+
doc?.removeEventListener?.('visibilitychange', visibility);
|
|
36
|
+
target = null; listening = false; last = null;
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// The server does not catch a player while the place holds them. Keep the
|
|
2
|
+
// client-side floor guard and fall fade on that same condition: otherwise a
|
|
3
|
+
// legitimate low hold fights the server's pose and can leave the view faded.
|
|
4
|
+
// Travel suppresses both too, because the previous place remains in client
|
|
5
|
+
// state until the trip installs its destination.
|
|
6
|
+
export function activeFallY(fallY, held, travelling) {
|
|
7
|
+
return typeof fallY === 'number' && !held && !travelling ? fallY : null;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function holdFallenPlayer(scene, local, fallY) {
|
|
11
|
+
const t = local?.components.Transform;
|
|
12
|
+
if (typeof fallY !== 'number' || !t || t.y >= fallY - 1) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
t.y = fallY - 1;
|
|
16
|
+
scene.physics3d?.bodyOf?.(local)?.setTranslation({ x: t.x, y: t.y, z: t.z }, true);
|
|
17
|
+
scene.physics3d?.setVelocity?.(local, { x: 0, y: 0, z: 0 });
|
|
18
|
+
}
|