castle-web-cli 0.4.233 → 0.4.235
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 +266 -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 +68 -5
- package/kits/base/sdk/hubRejoin.d.ts +4 -0
- package/kits/base/sdk/hubRejoin.js +15 -0
- package/kits/base/sdk/multiplayer.d.ts +7 -1
- package/kits/base/sdk/multiplayer.js +147 -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 +1259 -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 +917 -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,295 @@
|
|
|
1
|
+
// Optional, scene-authored active districts. Sleeping actors retain their
|
|
2
|
+
// components, runtime objects and ID lookup while live passes omit them.
|
|
3
|
+
// Source data and server remain complete. Untagged actors always stay live.
|
|
4
|
+
import { makeLookBake } from '@imports/castle.physics-3d/engine3d/lookbake';
|
|
5
|
+
import { readCells, insideOutline } from './tiers.js';
|
|
6
|
+
import { makeWeakestLookBake } from './weakestLookBake.js';
|
|
7
|
+
|
|
8
|
+
export function readDistricts(value) {
|
|
9
|
+
if (
|
|
10
|
+
!value ||
|
|
11
|
+
value.version !== 1 ||
|
|
12
|
+
!Array.isArray(value.districts) ||
|
|
13
|
+
!Array.isArray(value.actors)
|
|
14
|
+
) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
if (!value.districts.every((d) => d && typeof d === 'object' && typeof d.id === 'string')) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const table = readCells({
|
|
21
|
+
version: 1,
|
|
22
|
+
eyeMax: 1000,
|
|
23
|
+
hysteresis: 0,
|
|
24
|
+
cells: value.districts.map((d) => ({ ...d, sees: [d.id] })),
|
|
25
|
+
});
|
|
26
|
+
if (!table) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const actors = new Map();
|
|
30
|
+
for (const row of value.actors) {
|
|
31
|
+
if (
|
|
32
|
+
!row ||
|
|
33
|
+
typeof row.id !== 'string' ||
|
|
34
|
+
actors.has(row.id) ||
|
|
35
|
+
!Array.isArray(row.districts) ||
|
|
36
|
+
!row.districts.length ||
|
|
37
|
+
!row.districts.every((id) => table.byId.has(id)) ||
|
|
38
|
+
!Array.isArray(row.origin) ||
|
|
39
|
+
row.origin.length !== 2 ||
|
|
40
|
+
!row.origin.every(Number.isFinite) ||
|
|
41
|
+
!Array.isArray(row.bounds) ||
|
|
42
|
+
row.bounds.length !== 4 ||
|
|
43
|
+
!row.bounds.every(Number.isFinite) ||
|
|
44
|
+
row.bounds[0] > row.bounds[2] ||
|
|
45
|
+
row.bounds[1] > row.bounds[3]
|
|
46
|
+
) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
actors.set(row.id, row);
|
|
50
|
+
}
|
|
51
|
+
return { table, actors };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// A harmless text difference invalidates existing model signatures. The bake
|
|
55
|
+
// queue applies the cheap look while building; asset look data stays authored,
|
|
56
|
+
// including when a door copies these files into a cached content pack.
|
|
57
|
+
function simplifiedFiles(files) {
|
|
58
|
+
return Object.fromEntries(
|
|
59
|
+
Object.entries(files).map(([path, text]) => [
|
|
60
|
+
path,
|
|
61
|
+
path.endsWith('.pxmodel') && typeof text === 'string' ? text + '\n ' : text,
|
|
62
|
+
]),
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Middle shares only district sleep with Weakest, and halves Low's buffers.
|
|
67
|
+
export function makeWeakestTier({ profile = 'weakest' } = {}) {
|
|
68
|
+
const middle = profile === 'middle';
|
|
69
|
+
let held = null;
|
|
70
|
+
let source = null;
|
|
71
|
+
let map = null;
|
|
72
|
+
let districts = null;
|
|
73
|
+
let originalFiles = null;
|
|
74
|
+
let cheapFiles = null;
|
|
75
|
+
let cheapSnapshot = null;
|
|
76
|
+
let nextAt = -Infinity;
|
|
77
|
+
const asleep = new Map();
|
|
78
|
+
let ownsBake = false;
|
|
79
|
+
let ownsEmptyParts = false;
|
|
80
|
+
let bakeQueue = null;
|
|
81
|
+
let previousSkip;
|
|
82
|
+
let boundedLook = null;
|
|
83
|
+
let wantsBoundedLook = false;
|
|
84
|
+
let resolution = null;
|
|
85
|
+
let active = false;
|
|
86
|
+
let district = null;
|
|
87
|
+
|
|
88
|
+
function restore() {
|
|
89
|
+
if (resolution) {
|
|
90
|
+
const { renderer, composer, pixelRatio, composerRatio, cheapRatio, cheapComposerRatio } = resolution;
|
|
91
|
+
if (renderer.getPixelRatio() === cheapRatio) {
|
|
92
|
+
renderer.setPixelRatio(pixelRatio);
|
|
93
|
+
}
|
|
94
|
+
if (composer._pixelRatio === cheapComposerRatio) {
|
|
95
|
+
composer.setPixelRatio(composerRatio);
|
|
96
|
+
}
|
|
97
|
+
resolution = null;
|
|
98
|
+
}
|
|
99
|
+
for (const actor of asleep.values()) {
|
|
100
|
+
// The runtime checks identity, so replaced actors/loads cannot inherit
|
|
101
|
+
// a wake, while a data edit cannot strand an actor this profile slept.
|
|
102
|
+
held?.setActorSleeping?.(actor, false);
|
|
103
|
+
}
|
|
104
|
+
asleep.clear();
|
|
105
|
+
boundedLook?.restore();
|
|
106
|
+
boundedLook = null;
|
|
107
|
+
if (bakeQueue?.skipSurfaceBakes === !wantsBoundedLook) {
|
|
108
|
+
if (previousSkip === undefined) {
|
|
109
|
+
delete bakeQueue.skipSurfaceBakes;
|
|
110
|
+
} else {
|
|
111
|
+
bakeQueue.skipSurfaceBakes = previousSkip;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
bakeQueue = null;
|
|
115
|
+
if (held?.files === cheapFiles) {
|
|
116
|
+
// Runtime-generated avatars and asset edits belong to the live file map.
|
|
117
|
+
for (const [path, text] of Object.entries(cheapFiles)) {
|
|
118
|
+
if (!cheapSnapshot.has(path) || cheapSnapshot.get(path) !== text) {
|
|
119
|
+
originalFiles[path] =
|
|
120
|
+
path.endsWith('.pxmodel') && typeof text === 'string' ? text + '\n ' : text;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
for (const path of cheapSnapshot.keys()) {
|
|
124
|
+
if (!Object.hasOwn(cheapFiles, path)) {
|
|
125
|
+
delete originalFiles[path];
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
held.files = originalFiles;
|
|
129
|
+
}
|
|
130
|
+
if (
|
|
131
|
+
ownsBake &&
|
|
132
|
+
held &&
|
|
133
|
+
Object.getOwnPropertyDescriptor(held, 'bakesLookLater')?.value === true
|
|
134
|
+
) {
|
|
135
|
+
delete held.bakesLookLater;
|
|
136
|
+
}
|
|
137
|
+
if (
|
|
138
|
+
ownsEmptyParts &&
|
|
139
|
+
Object.getOwnPropertyDescriptor(held, 'dropsEmptyParts')?.value === true
|
|
140
|
+
) {
|
|
141
|
+
delete held.dropsEmptyParts;
|
|
142
|
+
}
|
|
143
|
+
held = source = map = districts = originalFiles = cheapFiles = cheapSnapshot = null;
|
|
144
|
+
nextAt = -Infinity;
|
|
145
|
+
ownsBake = false;
|
|
146
|
+
ownsEmptyParts = false;
|
|
147
|
+
active = false;
|
|
148
|
+
district = null;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function frame(scene, enabled, now, bounded = false, pointerTargets = null) {
|
|
152
|
+
if (
|
|
153
|
+
!enabled ||
|
|
154
|
+
typeof scene.setActorSleeping !== 'function' ||
|
|
155
|
+
scene.content ||
|
|
156
|
+
scene.requestedScene
|
|
157
|
+
) {
|
|
158
|
+
restore();
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (held !== scene || source !== scene.data || map !== scene.actors || wantsBoundedLook !== bounded) {
|
|
162
|
+
restore();
|
|
163
|
+
districts = readDistricts(scene.data?.weakestDistricts);
|
|
164
|
+
if (!districts) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
wantsBoundedLook = bounded;
|
|
168
|
+
held = scene;
|
|
169
|
+
source = scene.data;
|
|
170
|
+
map = scene.actors;
|
|
171
|
+
if (!middle && scene.three) {
|
|
172
|
+
scene.three.lookBake ??= makeLookBake();
|
|
173
|
+
bakeQueue = scene.three.lookBake;
|
|
174
|
+
previousSkip = bakeQueue.skipSurfaceBakes;
|
|
175
|
+
bakeQueue.skipSurfaceBakes = !bounded;
|
|
176
|
+
if (bounded) {boundedLook = makeWeakestLookBake(bakeQueue);}
|
|
177
|
+
}
|
|
178
|
+
if (!middle) {
|
|
179
|
+
originalFiles = scene.files;
|
|
180
|
+
cheapFiles = simplifiedFiles(originalFiles);
|
|
181
|
+
cheapSnapshot = new Map(Object.entries(cheapFiles));
|
|
182
|
+
scene.files = cheapFiles;
|
|
183
|
+
if (!Object.hasOwn(scene, 'bakesLookLater')) {
|
|
184
|
+
ownsBake = true;
|
|
185
|
+
Object.defineProperty(scene, 'bakesLookLater', { value: true, configurable: true });
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const p = scene.actorWith('Player')?.components?.Transform;
|
|
190
|
+
if (!p || !Number.isFinite(p.x) || !Number.isFinite(p.z)) {
|
|
191
|
+
restore();
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const cell = districts.table.cells.find((c) => insideOutline(c.outline, p.x, p.z))?.id ?? null;
|
|
195
|
+
if (!cell) {
|
|
196
|
+
restore();
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
active = true;
|
|
200
|
+
boundedLook?.frame(scene, now);
|
|
201
|
+
// Use the engine's existing model-build variant, retaining animated and
|
|
202
|
+
// named attachment parts. Its signatures also rebuild the full rig on exit.
|
|
203
|
+
if (!middle && !Object.hasOwn(scene, 'dropsEmptyParts')) {
|
|
204
|
+
ownsEmptyParts = true;
|
|
205
|
+
Object.defineProperty(scene, 'dropsEmptyParts', { value: true, configurable: true });
|
|
206
|
+
}
|
|
207
|
+
const renderer = scene.three?.renderer;
|
|
208
|
+
const composer = scene.three?.composer;
|
|
209
|
+
if (
|
|
210
|
+
!resolution &&
|
|
211
|
+
typeof renderer?.getPixelRatio === 'function' &&
|
|
212
|
+
typeof renderer.setPixelRatio === 'function' &&
|
|
213
|
+
typeof composer?.setPixelRatio === 'function' &&
|
|
214
|
+
Number.isFinite(composer._pixelRatio)
|
|
215
|
+
) {
|
|
216
|
+
const pixelRatio = renderer.getPixelRatio();
|
|
217
|
+
if (Number.isFinite(pixelRatio) && pixelRatio > 0) {
|
|
218
|
+
const cheapRatio = middle ? pixelRatio * 0.5 : Math.min(pixelRatio, composer._pixelRatio, 0.5);
|
|
219
|
+
const cheapComposerRatio = middle ? composer._pixelRatio * 0.5 : cheapRatio;
|
|
220
|
+
resolution = {
|
|
221
|
+
renderer,
|
|
222
|
+
composer,
|
|
223
|
+
pixelRatio,
|
|
224
|
+
composerRatio: composer._pixelRatio,
|
|
225
|
+
cheapRatio,
|
|
226
|
+
cheapComposerRatio,
|
|
227
|
+
};
|
|
228
|
+
renderer.setPixelRatio(cheapRatio);
|
|
229
|
+
composer.setPixelRatio(cheapComposerRatio);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
// Labels and goal pointers read retained components through getActor,
|
|
233
|
+
// but keep their targets' behaviors and NPCs live too. A newly received
|
|
234
|
+
// target wakes immediately, even inside the district check interval.
|
|
235
|
+
for (const id of pointerTargets ?? []) {
|
|
236
|
+
const actor = asleep.get(id);
|
|
237
|
+
if (actor) {
|
|
238
|
+
scene.setActorSleeping(actor, false);
|
|
239
|
+
asleep.delete(id);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (district === cell && now < nextAt) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
district = cell;
|
|
246
|
+
nextAt = now + 100;
|
|
247
|
+
for (const [id, row] of districts.actors) {
|
|
248
|
+
const actor = map.get(id);
|
|
249
|
+
if (!actor) {
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
const c = actor.components;
|
|
253
|
+
const dx = Number.isFinite(c.Transform?.x) ? c.Transform.x - row.origin[0] : 0;
|
|
254
|
+
const dz = Number.isFinite(c.Transform?.z) ? c.Transform.z - row.origin[1] : 0;
|
|
255
|
+
const x0 = row.bounds[0] + dx,
|
|
256
|
+
z0 = row.bounds[1] + dz;
|
|
257
|
+
const x1 = row.bounds[2] + dx,
|
|
258
|
+
z1 = row.bounds[3] + dz;
|
|
259
|
+
// A four-metre safety apron wakes colliders before the player crosses.
|
|
260
|
+
const gapX = Math.max(x0 - p.x, 0, p.x - x1);
|
|
261
|
+
const gapZ = Math.max(z0 - p.z, 0, p.z - z1);
|
|
262
|
+
const near = gapX * gapX + gapZ * gapZ <= 16;
|
|
263
|
+
const protectedActor = c.Player || c.RouteAnchor || c.Body?.type === 'dynamic' || pointerTargets?.has(id);
|
|
264
|
+
const hiddenTemplate = Number.isFinite(c.Transform?.y) && c.Transform.y < -50;
|
|
265
|
+
const sameDistrict =
|
|
266
|
+
dx === 0 && dz === 0
|
|
267
|
+
? row.districts.includes(cell)
|
|
268
|
+
: insideOutline(districts.table.byId.get(cell).outline, c.Transform?.x, c.Transform?.z);
|
|
269
|
+
const want = protectedActor || (!hiddenTemplate && (sameDistrict || near));
|
|
270
|
+
if (want) {
|
|
271
|
+
if (asleep.has(id)) {
|
|
272
|
+
scene.setActorSleeping(actor, false);
|
|
273
|
+
asleep.delete(id);
|
|
274
|
+
}
|
|
275
|
+
} else if (asleep.get(id) !== actor) {
|
|
276
|
+
scene.setActorSleeping(actor, true);
|
|
277
|
+
asleep.set(id, actor);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return {
|
|
282
|
+
profile,
|
|
283
|
+
frame,
|
|
284
|
+
restore,
|
|
285
|
+
get active() {
|
|
286
|
+
return active;
|
|
287
|
+
},
|
|
288
|
+
get district() {
|
|
289
|
+
return district;
|
|
290
|
+
},
|
|
291
|
+
get sleeping() {
|
|
292
|
+
return asleep.size;
|
|
293
|
+
},
|
|
294
|
+
};
|
|
295
|
+
}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
// The default world view: goals already become pointers, other actor labels
|
|
2
|
+
// use the existing three-slot distance/hysteresis rule in games as well.
|
|
3
|
+
import { makeLayoutCache } from './layoutCache.js';
|
|
4
|
+
import { near } from './labelsNear.js';
|
|
5
|
+
import { clearBox } from './padOccupancy.js';
|
|
6
|
+
import { overlaps, reservedCorners } from './safeLayout.js';
|
|
7
|
+
|
|
8
|
+
export const worldLabelFocus = (nearPolicy, game, throughDoor) => !nearPolicy || game || throughDoor;
|
|
9
|
+
|
|
10
|
+
export function mapWorldPoint(point, view) {
|
|
11
|
+
const area = view.world;
|
|
12
|
+
if (!area || (area.left === 0 && area.top === 0 && area.width === view.w && area.height === view.h)) {return point;}
|
|
13
|
+
const sx = area.width / view.w, sy = area.height / view.h;
|
|
14
|
+
return { ...point, x: area.left + point.x * sx, y: area.top + point.y * sy };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function offsetWorldPoint(point, view) {
|
|
18
|
+
return view.world ? { ...point, x: point.x + view.world.left, y: point.y + view.world.top } : point;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function relevantLabels(state, items, view, now) {
|
|
22
|
+
const area = view.world;
|
|
23
|
+
return near(state, items.map((item) => ({ ...item, kind: 'sign', box: area && item.box &&
|
|
24
|
+
(item.box.left < area.left || item.box.right > area.right || item.box.top < area.top || item.box.bottom > area.bottom) ? null : item.box })), view, now);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Pointers keep their words before ordinary labels. Labels retain their world
|
|
28
|
+
// anchor: when there is no clear air there, they collapse instead of becoming
|
|
29
|
+
// a second row of HUD. Speech/emotes/marks participate in clearance too.
|
|
30
|
+
export function worldPlacement(pointers, labels, controls, view) {
|
|
31
|
+
const insets = view.insets ?? { top: 0, right: 0, bottom: 0, left: 0 };
|
|
32
|
+
const world = view.world;
|
|
33
|
+
const bounds = {
|
|
34
|
+
left: Math.max(6, insets.left, world?.left ?? 0),
|
|
35
|
+
right: Math.min(view.w - Math.max(6, insets.right), world?.right ?? view.w),
|
|
36
|
+
top: Math.max(6, insets.top, world?.top ?? 0),
|
|
37
|
+
bottom: Math.min(view.h - Math.max(6, insets.bottom), world?.bottom ?? view.h),
|
|
38
|
+
};
|
|
39
|
+
const corners = reservedCorners({ ...view, insets })
|
|
40
|
+
.map(({ x, y, w, h }) => ({ left: x, right: x + w, top: y, bottom: y + h }));
|
|
41
|
+
const safeEdges = [
|
|
42
|
+
{ left: 0, right: bounds.left, top: 0, bottom: view.h },
|
|
43
|
+
{ left: bounds.right, right: view.w, top: 0, bottom: view.h },
|
|
44
|
+
{ left: 0, right: view.w, top: 0, bottom: bounds.top },
|
|
45
|
+
{ left: 0, right: view.w, top: bounds.bottom, bottom: view.h },
|
|
46
|
+
].filter((box) => box.right > box.left && box.bottom > box.top);
|
|
47
|
+
const taken = [...controls, ...corners, ...safeEdges];
|
|
48
|
+
const pointerBoxes = pointers.map((box) => {
|
|
49
|
+
const placed = clearBox(box, taken, view);
|
|
50
|
+
if (placed) {taken.push(placed);}
|
|
51
|
+
return placed;
|
|
52
|
+
});
|
|
53
|
+
const labelBoxes = labels.map((box) => {
|
|
54
|
+
const fits = box.left >= bounds.left && box.right <= bounds.right && box.top >= bounds.top && box.bottom <= bounds.bottom;
|
|
55
|
+
if (!fits || taken.some((other) => overlaps(box, other))) {return null;}
|
|
56
|
+
taken.push(box);
|
|
57
|
+
return box;
|
|
58
|
+
});
|
|
59
|
+
return { pointers: pointerBoxes, labels: labelBoxes };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Try whole-width vertical bands first; the DOM pass can reflow on failure.
|
|
63
|
+
export function captionBand(box, controls, view) {
|
|
64
|
+
const height = box.bottom - box.top;
|
|
65
|
+
const topEdge = Math.max(8, view.insets?.top ?? 0);
|
|
66
|
+
const bottomEdge = view.h - Math.max(8, view.insets?.bottom ?? 0);
|
|
67
|
+
const tops = [...new Set([box.top, topEdge, bottomEdge - height,
|
|
68
|
+
...controls.flatMap((other) => [other.top - height - 8, other.bottom + 8])])]
|
|
69
|
+
.filter((top) => top >= topEdge && top + height <= bottomEdge)
|
|
70
|
+
.sort((a, b) => Math.abs(a - box.top) - Math.abs(b - box.top));
|
|
71
|
+
for (const top of tops) {
|
|
72
|
+
const candidate = { left: box.left, right: box.right, top, bottom: top + height };
|
|
73
|
+
if (!controls.some((other) => overlaps(candidate, other))) {return candidate;}
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Widths come from actual horizontal gaps, including lanes narrower than a
|
|
79
|
+
// conventional text card. Sample each vertical band between obstacle edges.
|
|
80
|
+
export function captionWidths(controls, view) {
|
|
81
|
+
const left = Math.max(8, view.insets?.left ?? 0), right = view.w - Math.max(8, view.insets?.right ?? 0);
|
|
82
|
+
const ys = [...new Set([8, view.h - 8, ...controls.flatMap((box) => [box.top - 8, box.bottom + 8])])]
|
|
83
|
+
.filter((y) => y >= 8 && y <= view.h - 8).sort((a, b) => a - b);
|
|
84
|
+
const widths = new Set([Math.min(320, right - left)]);
|
|
85
|
+
for (let i = 1; i < ys.length; i++) {
|
|
86
|
+
const y = (ys[i - 1] + ys[i]) / 2;
|
|
87
|
+
const intervals = controls.filter((box) => box.top - 8 < y && box.bottom + 8 > y)
|
|
88
|
+
.map((box) => [Math.max(left, box.left - 8), Math.min(right, box.right + 8)])
|
|
89
|
+
.filter(([a, b]) => b > a).sort((a, b) => a[0] - b[0]);
|
|
90
|
+
let start = left;
|
|
91
|
+
for (const [a, b] of intervals) {
|
|
92
|
+
if (a > start) {widths.add(a - start);}
|
|
93
|
+
start = Math.max(start, b);
|
|
94
|
+
}
|
|
95
|
+
if (right > start) {widths.add(right - start);}
|
|
96
|
+
}
|
|
97
|
+
return [...widths].filter((width) => width >= 44).sort((a, b) => b - a);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function captionSlot(box, controls, view) {
|
|
101
|
+
const width = box.right - box.left, height = box.bottom - box.top;
|
|
102
|
+
const edge = (side) => Math.max(8, view.insets?.[side] ?? 0);
|
|
103
|
+
const lefts = [...new Set([box.left, edge('left'), view.w - edge('right') - width,
|
|
104
|
+
...controls.flatMap((other) => [other.left - width - 8, other.right + 8])])]
|
|
105
|
+
.filter((left) => left >= edge('left') && left + width <= view.w - edge('right'))
|
|
106
|
+
.sort((a, b) => Math.abs(a - box.left) - Math.abs(b - box.left));
|
|
107
|
+
const tops = [...new Set([box.top, edge('top'), view.h - edge('bottom') - height,
|
|
108
|
+
...controls.flatMap((other) => [other.top - height - 8, other.bottom + 8])])]
|
|
109
|
+
.filter((top) => top >= edge('top') && top + height <= view.h - edge('bottom'))
|
|
110
|
+
.sort((a, b) => Math.abs(a - box.top) - Math.abs(b - box.top));
|
|
111
|
+
for (const top of tops) {
|
|
112
|
+
for (const left of lefts) {
|
|
113
|
+
const candidate = { left, right: left + width, top, bottom: top + height };
|
|
114
|
+
if (!controls.some((other) => overlaps(candidate, other))) {return candidate;}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function makeWorldLayout(entries, view, obstacles = () => [], geometry = makeLayoutCache()) {
|
|
121
|
+
const hidden = new Set();
|
|
122
|
+
const shifted = new Map();
|
|
123
|
+
const reflowed = new Map();
|
|
124
|
+
function restoreReflowed() {
|
|
125
|
+
for (const [node, styles] of reflowed) {
|
|
126
|
+
Object.assign(node.style, styles);
|
|
127
|
+
// The snapshot may contain the narrower caption from the last flush.
|
|
128
|
+
geometry.invalidate(node);
|
|
129
|
+
}
|
|
130
|
+
reflowed.clear();
|
|
131
|
+
}
|
|
132
|
+
function begin() {
|
|
133
|
+
for (const node of hidden) {node.style.visibility = '';}
|
|
134
|
+
for (const [node, value] of shifted) {node.style.translate = value;}
|
|
135
|
+
restoreReflowed();
|
|
136
|
+
hidden.clear(); shifted.clear();
|
|
137
|
+
}
|
|
138
|
+
function flush() {
|
|
139
|
+
// Width restoration changes wrapping, so only those captions need a fresh
|
|
140
|
+
// DOM read. Ordinary surfaces keep using the frame-start snapshot.
|
|
141
|
+
restoreReflowed();
|
|
142
|
+
const surfaces = entries();
|
|
143
|
+
const styleHides = (style) => style?.display === 'none' || style?.visibility === 'hidden' || style?.opacity === '0';
|
|
144
|
+
// Surfaces share their layers, so each ancestor's style is read once per
|
|
145
|
+
// flush. Nothing is written between these reads.
|
|
146
|
+
const ancestorHidden = new Map();
|
|
147
|
+
const chainHidden = (start) => {
|
|
148
|
+
const walked = [];
|
|
149
|
+
let result = false;
|
|
150
|
+
for (let parent = start; parent; parent = parent.parentElement ?? parent.parent) {
|
|
151
|
+
if (ancestorHidden.has(parent)) {result = ancestorHidden.get(parent); break;}
|
|
152
|
+
walked.push(parent);
|
|
153
|
+
if (styleHides(globalThis.getComputedStyle?.(parent) ?? parent.style)) {result = true; break;}
|
|
154
|
+
}
|
|
155
|
+
for (const parent of walked) {ancestorHidden.set(parent, result);}
|
|
156
|
+
return result;
|
|
157
|
+
};
|
|
158
|
+
const visible = ({ node }) => {
|
|
159
|
+
if (!node || node.isConnected === false) {return null;}
|
|
160
|
+
// The node's own last-pass hide is ignored; an ancestor's is not.
|
|
161
|
+
const own = globalThis.getComputedStyle?.(node) ?? node.style;
|
|
162
|
+
if (own?.display === 'none' || (own?.visibility === 'hidden' && !hidden.has(node)) || own?.opacity === '0') {return null;}
|
|
163
|
+
if (chainHidden(node.parentElement ?? node.parent)) {return null;}
|
|
164
|
+
let box = geometry.rect(node);
|
|
165
|
+
if (shifted.has(node)) {
|
|
166
|
+
const [dx, dy] = node.style.translate.split(' ').map(Number.parseFloat);
|
|
167
|
+
const original = shifted.get(node) || '0 0';
|
|
168
|
+
const [ox, oy = '0'] = original.split(' ');
|
|
169
|
+
const pixels = (value, size) => (Number.parseFloat(value) || 0) * (value.endsWith('%') ? size / 100 : 1);
|
|
170
|
+
const x = pixels(ox, box.width) - dx, y = pixels(oy, box.height) - dy;
|
|
171
|
+
box = { left: box.left + x, right: box.right + x, top: box.top + y, bottom: box.bottom + y, width: box.width, height: box.height };
|
|
172
|
+
}
|
|
173
|
+
return box.width > 0 && box.height > 0 ? box : null;
|
|
174
|
+
};
|
|
175
|
+
const measured = surfaces.map((entry) => ({ ...entry, box: visible(entry) })).filter((entry) => entry.box);
|
|
176
|
+
// Restore the previous pass after reading its unshifted boxes, before the
|
|
177
|
+
// caption pass records this flush's shifts, hides and reflowed styles.
|
|
178
|
+
begin();
|
|
179
|
+
// Text bands yield to navigation, but never escape the viewport while
|
|
180
|
+
// doing so. Dense lanes reflow into a narrower gap before world labels.
|
|
181
|
+
const viewport = view();
|
|
182
|
+
const captions = ['hud-prompt', 'engine-look'].flatMap((id) => measured.filter((entry) => entry.id === id));
|
|
183
|
+
for (const caption of captions) {
|
|
184
|
+
const controls = measured.filter((entry) => entry !== caption &&
|
|
185
|
+
entry.kind !== 'label' && entry.kind !== 'pointer').map((entry) => entry.box)
|
|
186
|
+
.concat(reservedCorners({ ...viewport, insets: viewport.insets ?? { top: 0, right: 0, bottom: 0, left: 0 } })
|
|
187
|
+
.map(({ x, y, w, h }) => ({ left: x, right: x + w, top: y, bottom: y + h })));
|
|
188
|
+
let box = caption.box;
|
|
189
|
+
let placed = captionBand(box, controls, viewport);
|
|
190
|
+
if (!placed) {
|
|
191
|
+
const style = caption.node.style;
|
|
192
|
+
reflowed.set(caption.node, Object.fromEntries(['width', 'maxWidth', 'left', 'right', 'boxSizing', 'whiteSpace', 'maxHeight', 'overflowY', 'pointerEvents'].map((key) => [key, style[key]])));
|
|
193
|
+
for (const width of captionWidths(controls, viewport)) {
|
|
194
|
+
Object.assign(style, { width: `${width}px`, maxWidth: `${width}px`, left: `${(viewport.w - width) / 2}px`, right: 'auto', boxSizing: 'border-box', whiteSpace: 'normal' });
|
|
195
|
+
box = geometry.rect(caption.node);
|
|
196
|
+
placed = captionSlot(box, controls, viewport);
|
|
197
|
+
if (placed) {break;}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (!placed) {
|
|
201
|
+
// A menu owns its reading surface until it closes. Outside a menu,
|
|
202
|
+
// make a one-line scrollable caption in a measured gap, preserving
|
|
203
|
+
// access to the full words even when the complete paragraph won't fit.
|
|
204
|
+
const menu = measured.some((entry) => entry.id === 'menu' || entry.node.dataset?.hub === 'action-sheet');
|
|
205
|
+
if (!menu) {
|
|
206
|
+
for (const width of captionWidths(controls, viewport)) {
|
|
207
|
+
Object.assign(caption.node.style, { width: `${width}px`, maxWidth: `${width}px`, left: `${(viewport.w - width) / 2}px`, right: 'auto', maxHeight: '21px', overflowY: 'auto', pointerEvents: 'auto' });
|
|
208
|
+
box = geometry.rect(caption.node);
|
|
209
|
+
placed = captionSlot(box, controls, viewport);
|
|
210
|
+
if (placed) {break;}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (!placed) {
|
|
214
|
+
caption.node.style.visibility = 'hidden'; hidden.add(caption.node);
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (placed.left !== box.left || placed.top !== box.top) {
|
|
219
|
+
shifted.set(caption.node, caption.node.style.translate);
|
|
220
|
+
caption.node.style.translate = `${placed.left - box.left}px ${placed.top - box.top}px`;
|
|
221
|
+
}
|
|
222
|
+
caption.box = { left: placed.left, right: placed.right, top: placed.top, bottom: placed.top + box.bottom - box.top };
|
|
223
|
+
}
|
|
224
|
+
const pointers = measured.filter((entry) => entry.kind === 'pointer' && entry.id !== 'stuck')
|
|
225
|
+
.sort((a, b) => Number(b.id?.startsWith('pointer:goal:') === true) - Number(a.id?.startsWith('pointer:goal:') === true));
|
|
226
|
+
const labels = measured.filter((entry) => entry.kind === 'label');
|
|
227
|
+
const controls = measured.filter((entry) => (entry.kind !== 'pointer' || entry.id === 'stuck') && entry.kind !== 'label').map((entry) => entry.box);
|
|
228
|
+
const placements = worldPlacement(pointers.map((entry) => entry.box), labels.map((entry) => entry.box), [...controls, ...obstacles()], view());
|
|
229
|
+
for (const [items, boxes] of [[pointers, placements.pointers], [labels, placements.labels]]) {
|
|
230
|
+
items.forEach(({ node, box }, index) => {
|
|
231
|
+
const placed = boxes[index];
|
|
232
|
+
if (!placed) {node.style.visibility = 'hidden'; hidden.add(node);}
|
|
233
|
+
else if (placed.left !== box.left || placed.top !== box.top) {
|
|
234
|
+
shifted.set(node, node.style.translate);
|
|
235
|
+
node.style.translate = `${placed.left - box.left}px ${placed.top - box.top}px`;
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return { begin, flush };
|
|
241
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// One town visit's account hearts and arrival offer. No browser storage.
|
|
2
|
-
const OFFER_MS = 15000;
|
|
3
2
|
const ARRIVAL_WAIT_MS = 60000;
|
|
4
3
|
// hub.results refreshes about once a minute; allow several reads to catch up.
|
|
5
4
|
const HEARTS_CATCH_UP_MS = 3 * 60000;
|
|
@@ -22,6 +21,8 @@ export function toggleHeart(hearts, door) {
|
|
|
22
21
|
|
|
23
22
|
export function makeYours(api, user, toast, clock = () => performance.now()) {
|
|
24
23
|
let visit = 0;
|
|
24
|
+
let occurrence = 0;
|
|
25
|
+
let offerKey = null;
|
|
25
26
|
let started = false;
|
|
26
27
|
let signed = false;
|
|
27
28
|
let available = false;
|
|
@@ -30,7 +31,6 @@ export function makeYours(api, user, toast, clock = () => performance.now()) {
|
|
|
30
31
|
let saving = false;
|
|
31
32
|
let latestHearts = null;
|
|
32
33
|
let authoritativeUntil = 0;
|
|
33
|
-
let until = 0;
|
|
34
34
|
let waitUntil = 0;
|
|
35
35
|
let arrived = false;
|
|
36
36
|
let offered = false;
|
|
@@ -89,22 +89,25 @@ export function makeYours(api, user, toast, clock = () => performance.now()) {
|
|
|
89
89
|
return {
|
|
90
90
|
clear() {
|
|
91
91
|
visit += 1;
|
|
92
|
+
occurrence = 0;
|
|
93
|
+
offerKey = null;
|
|
92
94
|
started = signed = available = saving = offered = dismissed = arrived = false;
|
|
93
95
|
confirmed = [];
|
|
94
96
|
pending = [];
|
|
95
97
|
latestHearts = returning = null;
|
|
96
98
|
authoritativeUntil = 0;
|
|
97
99
|
returnLine = '';
|
|
98
|
-
|
|
100
|
+
waitUntil = 0;
|
|
99
101
|
},
|
|
100
102
|
returned(door, result = null) {
|
|
103
|
+
offerKey = `yours:${visit}:return:${++occurrence}`;
|
|
101
104
|
returning = door;
|
|
102
105
|
const last = Number.isFinite(result?.score) ? `Last ${result.score}${['ms', 's', 'points'].includes(result.unit) ? ` ${result.unit}` : ''}` : result?.outcome ?? '';
|
|
103
106
|
returnLine = [last, 'today'].filter(Boolean).join(' · ');
|
|
104
107
|
offered = false;
|
|
105
108
|
dismissed = false;
|
|
106
109
|
arrived = false;
|
|
107
|
-
|
|
110
|
+
waitUntil = 0;
|
|
108
111
|
},
|
|
109
112
|
frame(town, state, now) {
|
|
110
113
|
if (!town) {
|
|
@@ -169,7 +172,7 @@ export function makeYours(api, user, toast, clock = () => performance.now()) {
|
|
|
169
172
|
void save();
|
|
170
173
|
},
|
|
171
174
|
ask(state, doors, party, now) {
|
|
172
|
-
if (!signed || dismissed || (
|
|
175
|
+
if (!signed || dismissed || (!arrived && !offered && waitUntil && now >= waitUntil)) {
|
|
173
176
|
return null;
|
|
174
177
|
}
|
|
175
178
|
const rows = this.rows(state, doors);
|
|
@@ -182,15 +185,13 @@ export function makeYours(api, user, toast, clock = () => performance.now()) {
|
|
|
182
185
|
}
|
|
183
186
|
if (!offered) {
|
|
184
187
|
offered = true;
|
|
185
|
-
|
|
186
|
-
until = now + OFFER_MS;
|
|
187
|
-
}
|
|
188
|
+
offerKey ??= `yours:${visit}:arrival`;
|
|
188
189
|
}
|
|
189
190
|
const door = doors.find((d) => d.id === row.door);
|
|
190
191
|
const controls = this.controls();
|
|
191
192
|
const line = row.line || (returning ? returnLine : '');
|
|
192
193
|
const together = party?.length && !door?.solo;
|
|
193
|
-
return { key: `yours:${
|
|
194
|
+
return { key: `yours:${offerKey}:${row.door}:${hearts().join(',')}:${line}:${Boolean(together)}:${Boolean(returning && controls)}`, slotKey: offerKey, kind: 'yours', door: row.door, text: `♥ ${row.title}`, line, yes: together ? 'Go together' : 'Go', no: 'Not now', ...(returning ? { requiresArrivalPlacement: true } : {}), ...(returning && controls ? { heart: hearts().includes(row.door) } : {}) };
|
|
194
195
|
},
|
|
195
196
|
dismiss() {
|
|
196
197
|
dismissed = true;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// NPC replies are plain text in the panel and over the body. Keep the mind's
|
|
2
|
+
// canonical reply intact; remove only paired emphasis markers for display.
|
|
3
|
+
export function npcDisplayText(text) {
|
|
4
|
+
let line = text.trim();
|
|
5
|
+
if (line.length > 1 && /^["“]/.test(line) && /["”]$/.test(line)) {
|
|
6
|
+
line = line.slice(1, -1).trim();
|
|
7
|
+
}
|
|
8
|
+
const stack = [];
|
|
9
|
+
const removed = new Set();
|
|
10
|
+
for (let i = 0; i < line.length; i++) {
|
|
11
|
+
const marker = line[i];
|
|
12
|
+
if (marker === '\n') {
|
|
13
|
+
stack.length = 0;
|
|
14
|
+
}
|
|
15
|
+
if (marker !== '*' && marker !== '_') {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
const start = i;
|
|
19
|
+
while (line[i + 1] === marker) {
|
|
20
|
+
i++;
|
|
21
|
+
}
|
|
22
|
+
const size = i - start + 1;
|
|
23
|
+
if (size > 3 || line[start - 1] === '\\') {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const before = line[start - 1] ?? '';
|
|
27
|
+
const after = line[i + 1] ?? '';
|
|
28
|
+
// Whitespace-surrounded stars and underscores inside identifiers are literal.
|
|
29
|
+
const closes = Boolean(before && !/\s/.test(before) && (marker !== '_' || !/\w/.test(after)));
|
|
30
|
+
const opens = Boolean(after && !/\s/.test(after) && (marker !== '_' || !/\w/.test(before)));
|
|
31
|
+
let remaining = size;
|
|
32
|
+
if (closes) {
|
|
33
|
+
while (remaining && stack.length && stack[stack.length - 1].marker === marker) {
|
|
34
|
+
const opening = stack[stack.length - 1];
|
|
35
|
+
const consumed = Math.min(opening.size, remaining);
|
|
36
|
+
for (let j = 0; j < consumed; j++) {
|
|
37
|
+
removed.add(opening.start + opening.size - consumed + j);
|
|
38
|
+
removed.add(start + size - remaining + j);
|
|
39
|
+
}
|
|
40
|
+
remaining -= consumed;
|
|
41
|
+
opening.size -= consumed;
|
|
42
|
+
if (!opening.size) {
|
|
43
|
+
stack.pop();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (opens && remaining) {
|
|
48
|
+
stack.push({ marker, start: start + size - remaining, size: remaining });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return line
|
|
52
|
+
.split('')
|
|
53
|
+
.filter((_char, i) => !removed.has(i))
|
|
54
|
+
.join('');
|
|
55
|
+
}
|