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,430 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { register } from 'node:module';
|
|
3
|
+
import { makeInvites } from '../code/client/invites.js';
|
|
4
|
+
register(`data:text/javascript,${encodeURIComponent(`
|
|
5
|
+
import { readFile } from 'node:fs/promises';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
export async function resolve(specifier, context, next) {
|
|
8
|
+
if (['pxmodel', 'optimize', 'look', 'lookbake'].some((m) => specifier === '@imports/castle.physics-3d/engine3d/' + m)) return { url: ${JSON.stringify(new URL('./fixtures/engine-models-stub.mjs', import.meta.url).href)}, shortCircuit: true };
|
|
9
|
+
if (specifier === '@imports/castle.physics-3d/engine3d/orbitlens.js') return { url: ${JSON.stringify(new URL('../../physics-3d/engine3d/orbitlens.js', import.meta.url).href)}, shortCircuit: true };
|
|
10
|
+
if (specifier === 'castle-web-sdk') return { url: 'data:text/javascript,export {};', shortCircuit: true };
|
|
11
|
+
if (specifier === '@imports/castle.multiplayer-3d/code/client/avatars.js') return { url: 'data:text/javascript,export const dropMissing = () => {};', shortCircuit: true };
|
|
12
|
+
if (specifier.startsWith('@imports/castle.physics-2d/engine/')) return { url: 'data:text/javascript,export const initialMedia = {}; export const playMedia = () => {}; export const stopMedia = () => {};', shortCircuit: true };
|
|
13
|
+
return next(specifier, context);
|
|
14
|
+
}
|
|
15
|
+
export async function load(url, context, next) {
|
|
16
|
+
if (url.endsWith('/code/client/hookLayer.js')) {
|
|
17
|
+
const source = await readFile(fileURLToPath(url), 'utf8');
|
|
18
|
+
return { format: 'module', source: source.replaceAll('import.meta.glob(', '(() => ({}))('), shortCircuit: true };
|
|
19
|
+
}
|
|
20
|
+
return next(url, context);
|
|
21
|
+
}
|
|
22
|
+
`)}`);
|
|
23
|
+
const elements = [];
|
|
24
|
+
let dynamicViewportUnits = true;
|
|
25
|
+
globalThis.document = {
|
|
26
|
+
body: { append() {} },
|
|
27
|
+
createElement(tag) {
|
|
28
|
+
const style = new Proxy({}, { set(target, key, value) {
|
|
29
|
+
if (!dynamicViewportUnits && String(value).includes('dvh')) {return true;}
|
|
30
|
+
target[key] = value; return true;
|
|
31
|
+
} });
|
|
32
|
+
const e = { tag, style, dataset: {}, children: [], textContent: '', removed: false, append(...children) { this.children.push(...children); }, remove() {this.removed = true;}, setAttribute() {}, addEventListener(type, fn) { this[type] = fn; } };
|
|
33
|
+
elements.push(e); return e;
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
const flush = () => new Promise((resolve) => setImmediate(resolve));
|
|
37
|
+
const deferred = () => {let resolve, reject; const promise = new Promise((yes, no) => {resolve = yes; reject = no;}); return { promise, resolve, reject };};
|
|
38
|
+
const activePanel = () => elements.findLast((e) => e.tag === 'section' && !e.removed);
|
|
39
|
+
const hostYes = { canInvite: async () => ({ status: 'ok', canInvite: true }) };
|
|
40
|
+
const net = { selfId: () => 'a' };
|
|
41
|
+
let now = 0, calls = 0;
|
|
42
|
+
const api = { inviteArrival: async () => { if (++calls === 1) throw new Error('response lost'); return { status: 'ok', friends: [{ userId: '102', username: 'Ada' }] }; }, undoInvite: async () => ({ status: 'ok' }) };
|
|
43
|
+
const surface = makeInvites(api, () => {}, () => {}, () => now);
|
|
44
|
+
surface.frame(net); await flush();
|
|
45
|
+
surface.frame(net); await flush(); assert.equal(calls, 1, 'backoff prevents a per-frame request loop');
|
|
46
|
+
now = 500; surface.frame(net); await flush();
|
|
47
|
+
assert.equal(calls, 2, 'same connection retries a lost arrival response');
|
|
48
|
+
assert.ok(elements.some((e) => e.textContent.includes('You and Ada are now friends.')));
|
|
49
|
+
assert.ok(elements.some((e) => e.textContent === 'Undo'));
|
|
50
|
+
surface.frame(net); await flush(); assert.equal(calls, 2, 'success latches this connection');
|
|
51
|
+
surface.dispose();
|
|
52
|
+
let routes = 0;
|
|
53
|
+
const routed = makeInvites({ inviteArrival: async () => ({ status: 'route', doorId: 'home' }) }, () => {}, () => { routes++; }, () => now);
|
|
54
|
+
routed.frame(net); await flush(); now += 500; routed.frame(net); await flush();
|
|
55
|
+
assert.equal(routes, 2, 'failed house trip is retried on the same connection');
|
|
56
|
+
routed.dispose();
|
|
57
|
+
let failures = 0;
|
|
58
|
+
const failed = makeInvites({ inviteArrival: async () => { failures++; throw new Error('offline'); } }, () => {}, () => {}, () => now);
|
|
59
|
+
for (let i = 0; i < 8; i++) { failed.frame(net); await flush(); now += 10000; }
|
|
60
|
+
assert.equal(failures, 6, 'automatic retries are bounded');
|
|
61
|
+
assert.equal(activePanel(), undefined, 'plain arrival failures never show friend recovery');
|
|
62
|
+
assert.equal(failed.hello(net).ready, true, 'plain arrival can hello after bounded retries');
|
|
63
|
+
failed.dispose();
|
|
64
|
+
|
|
65
|
+
for (const code of ['UNKNOWN_COMMAND', 'CASTLE_HOST_UNAVAILABLE']) {
|
|
66
|
+
let unsupportedCalls = 0;
|
|
67
|
+
const unsupported = makeInvites({ inviteArrival: async () => {
|
|
68
|
+
unsupportedCalls++;
|
|
69
|
+
throw Object.assign(new Error('unsupported host'), { name: 'CastleError', code });
|
|
70
|
+
} }, () => {}, () => {}, () => now);
|
|
71
|
+
unsupported.hello(net); await flush();
|
|
72
|
+
assert.deepEqual(unsupported.hello(net), { ready: true, near: null }, `${code} releases hello without an invite`);
|
|
73
|
+
for (let i = 0; i < 8; i++) {now += 10000; unsupported.frame(net); await flush();}
|
|
74
|
+
assert.equal(unsupportedCalls, 1, `${code} without a channel never retries`);
|
|
75
|
+
assert.equal(activePanel(), undefined, `${code} never shows a panel`);
|
|
76
|
+
unsupported.dispose();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
globalThis.window = { ReactNativeWebView: { postMessage() {} } };
|
|
80
|
+
let timeoutCalls = 0;
|
|
81
|
+
const timedOut = makeInvites({ inviteArrival: async () => {
|
|
82
|
+
if (++timeoutCalls === 1) {throw Object.assign(new Error('host timeout'), { code: 'CASTLE_HOST_UNAVAILABLE' });}
|
|
83
|
+
return { status: 'ok' };
|
|
84
|
+
} }, () => {}, () => {}, () => now);
|
|
85
|
+
timedOut.frame(net); await flush();
|
|
86
|
+
timedOut.frame(net); await flush(); assert.equal(timeoutCalls, 1);
|
|
87
|
+
now += 500; timedOut.frame(net); await flush();
|
|
88
|
+
assert.equal(timeoutCalls, 2, 'unavailable host with a channel retains transient backoff');
|
|
89
|
+
timedOut.dispose(); delete globalThis.window;
|
|
90
|
+
|
|
91
|
+
let inviteFailures = 0;
|
|
92
|
+
const unresolved = makeInvites({ inviteArrival: async () => {
|
|
93
|
+
if (++inviteFailures === 1) {return { status: 'route', doorId: 'home' };}
|
|
94
|
+
throw new Error('offline');
|
|
95
|
+
} }, () => {}, () => {}, () => now);
|
|
96
|
+
unresolved.hello(net); await flush(); unresolved.frame(net);
|
|
97
|
+
const routedNet = { selfId: () => 'house' };
|
|
98
|
+
for (let i = 0; i < 8; i++) {now += 10000; unresolved.frame(routedNet); await flush();}
|
|
99
|
+
assert.equal(inviteFailures, 7, 'route evidence survives the destination connection and six failures');
|
|
100
|
+
const retry = activePanel().children.find((e) => e.textContent === 'Try again');
|
|
101
|
+
assert.ok(retry); retry.click(); unresolved.frame(routedNet); await flush();
|
|
102
|
+
assert.equal(inviteFailures, 8, 'confirmed invite keeps manual recovery');
|
|
103
|
+
unresolved.reset();
|
|
104
|
+
for (let i = 0; i < 8; i++) {now += 10000; unresolved.frame(net); await flush();}
|
|
105
|
+
assert.equal(activePanel(), undefined, 'reset clears invite evidence before a plain arrival');
|
|
106
|
+
unresolved.dispose();
|
|
107
|
+
let finish;
|
|
108
|
+
const stale = makeInvites({ inviteArrival: () => new Promise((resolve) => { finish = resolve; }) }, () => { throw new Error('stale target'); }, () => {}, () => now);
|
|
109
|
+
stale.frame(net); stale.reset(); finish({ status: 'ok', destination: { hub: { target: { kind: 'player', id: '102' } } } }); await flush();
|
|
110
|
+
stale.dispose();
|
|
111
|
+
|
|
112
|
+
Object.defineProperty(globalThis, 'navigator', { configurable: true, value: { clipboard: { writeText: async () => {} } } });
|
|
113
|
+
for (const intent of [undefined, false, true]) {
|
|
114
|
+
let minted = 0;
|
|
115
|
+
const direct = makeInvites({ ...hostYes, invite: async (options) => {
|
|
116
|
+
assert.deepEqual(options, { crew: true }, 'ordinary and share intent request five uses even through an older SDK');
|
|
117
|
+
minted++;
|
|
118
|
+
return { status: 'ok', url: 'https://castle.xyz/i/five' };
|
|
119
|
+
} }, () => {}, () => {});
|
|
120
|
+
direct.open(intent); await flush();
|
|
121
|
+
const sheet = activePanel();
|
|
122
|
+
assert.equal(minted, 1, 'one opening mints exactly one link without a choice step');
|
|
123
|
+
assert.ok(sheet.children.some((e) => e.textContent === 'Invite up to five friends. This link lasts 24 hours.'));
|
|
124
|
+
assert.ok(sheet.children.some((e) => e.textContent === 'Copy link'));
|
|
125
|
+
assert(!sheet.children.some((e) => ['One friend', 'Bring the crew'].includes(e.textContent)));
|
|
126
|
+
direct.dispose();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const shared = [], copied = [], notices = [];
|
|
130
|
+
Object.defineProperty(globalThis, 'navigator', { configurable: true, value: { share: async (value) => {shared.push(value); throw new DOMException('cancelled', 'AbortError');}, clipboard: { writeText: async (value) => copied.push(value) } } });
|
|
131
|
+
const native = makeInvites({ ...hostYes, invite: async (options) => { assert.deepEqual(options, { crew: true }); return { status: 'ok', url: 'https://castle.xyz/i/one' }; } }, () => {}, () => {}, () => now, (text) => notices.push(text), () => 'Castle Town');
|
|
132
|
+
native.open(true); await flush();
|
|
133
|
+
assert.ok(activePanel().children.some((e) => e.textContent === 'Copy link'), 'Copy is offered alongside native Share before sharing');
|
|
134
|
+
const share = elements.findLast((e) => e.textContent === 'Share'); assert.ok(share); share.click(); await flush();
|
|
135
|
+
assert.deepEqual(shared, [{ text: 'Join me in Castle Town.', url: 'https://castle.xyz/i/one' }]);
|
|
136
|
+
assert.deepEqual(copied, [], 'native cancellation or success never falls through to clipboard');
|
|
137
|
+
native.dispose();
|
|
138
|
+
|
|
139
|
+
Object.defineProperty(navigator, 'share', { configurable: true, value: async () => {throw new TypeError('unsupported payload');} });
|
|
140
|
+
const refused = makeInvites({ ...hostYes, invite: async () => ({ status: 'ok', url: 'https://castle.xyz/i/refused' }) }, () => {}, () => {}, () => now, (text) => notices.push(text), () => 'Castle Town');
|
|
141
|
+
refused.open(true); await flush(); elements.findLast((e) => e.textContent === 'Share').click(); await flush();
|
|
142
|
+
const refusedCopy = elements.findLast((e) => e.textContent === 'Copy link'); assert.ok(refusedCopy); refusedCopy.click(); await flush();
|
|
143
|
+
assert.deepEqual(copied, ['Join me in Castle Town. https://castle.xyz/i/refused']);
|
|
144
|
+
refused.dispose();
|
|
145
|
+
|
|
146
|
+
delete navigator.share;
|
|
147
|
+
const fallback = makeInvites({ ...hostYes, invite: async () => ({ status: 'ok', url: 'https://castle.xyz/i/copy' }) }, () => {}, () => {}, () => now, (text) => notices.push(text), () => 'Castle Town');
|
|
148
|
+
fallback.open(true); await flush();
|
|
149
|
+
const copy = elements.findLast((e) => e.textContent === 'Copy link'); assert.ok(copy); copy.click(); await flush();
|
|
150
|
+
assert.deepEqual(copied, ['Join me in Castle Town. https://castle.xyz/i/refused', 'Join me in Castle Town. https://castle.xyz/i/copy']);
|
|
151
|
+
assert.deepEqual(notices, ['Link copied', 'Link copied']);
|
|
152
|
+
fallback.dispose();
|
|
153
|
+
|
|
154
|
+
for (const outcome of ['success', 'error']) {
|
|
155
|
+
const gate = deferred();
|
|
156
|
+
Object.defineProperty(navigator, 'share', { configurable: true, value: () => gate.promise });
|
|
157
|
+
const delayed = makeInvites({ ...hostYes, invite: async () => ({ status: 'ok', url: `https://castle.xyz/i/${outcome}` }) }, () => {}, () => {}, () => now, (text) => notices.push(text), () => 'Castle Town');
|
|
158
|
+
delayed.open(true); await flush();
|
|
159
|
+
const old = activePanel(), oldShare = old.children.find((e) => e.textContent === 'Share'); oldShare.click();
|
|
160
|
+
delayed.open(false); await flush(); const replacement = activePanel();
|
|
161
|
+
if (outcome === 'success') gate.resolve(); else gate.reject(new TypeError('unsupported payload'));
|
|
162
|
+
await flush();
|
|
163
|
+
assert.equal(activePanel(), replacement, `deferred native ${outcome} keeps the replacement Invite panel`);
|
|
164
|
+
assert.equal(replacement.removed, false);
|
|
165
|
+
assert.equal(old.children.filter((e) => e.textContent === 'Copy link').length, 1, 'a stale native error adds no duplicate Copy action');
|
|
166
|
+
delayed.dispose();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
delete navigator.share;
|
|
170
|
+
for (const transition of ['open', 'reset', 'dispose']) {
|
|
171
|
+
const gate = deferred(), staleNotices = [];
|
|
172
|
+
navigator.clipboard.writeText = () => gate.promise;
|
|
173
|
+
const delayed = makeInvites({ ...hostYes, invite: async () => ({ status: 'ok', url: `https://castle.xyz/i/${transition}` }) }, () => {}, () => {}, () => now, (text) => staleNotices.push(text));
|
|
174
|
+
delayed.open(true); await flush();
|
|
175
|
+
activePanel().children.find((e) => e.textContent === 'Copy link').click();
|
|
176
|
+
if (transition === 'open') { delayed.open(false); await flush(); } else delayed[transition]();
|
|
177
|
+
const replacement = transition === 'open' ? activePanel() : null;
|
|
178
|
+
gate.resolve(); await flush();
|
|
179
|
+
assert.deepEqual(staleNotices, [], `deferred copy after ${transition} sends no stale toast`);
|
|
180
|
+
if (replacement) {assert.equal(activePanel(), replacement); assert.equal(replacement.removed, false); delayed.dispose();}
|
|
181
|
+
else assert.equal(activePanel(), undefined);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const State = await import('../code/client/state.js');
|
|
185
|
+
const hook = (await import('../code/client/hookLayer.js')).default;
|
|
186
|
+
State.clear(); hook.state({}, { hubPlace: { id: 'main', invite: true } }, null);
|
|
187
|
+
hook.message({}, { k: 'hub-invite', share: true, text: 'ignored' });
|
|
188
|
+
hook.message({}, { k: 'hub-invite', share: 'true' });
|
|
189
|
+
assert.deepEqual(State.hub.commands, [{ k: 'hub-invite', share: true }, { k: 'hub-invite' }]);
|
|
190
|
+
State.clear(); hook.state({}, { hubPlace: { id: 'plain' } }, null); hook.message({}, { k: 'hub-invite', share: true });
|
|
191
|
+
assert.deepEqual(State.hub.commands, [], 'a place without invite retains no share command');
|
|
192
|
+
console.log('invite client: retries, stale reset, fixed native/clipboard sharing, truthful copy toast and real hook wire passed');
|
|
193
|
+
console.log('invite client: same-net lost response, bounded backoff/manual retry, failed house route and stale reset passed');
|
|
194
|
+
|
|
195
|
+
let resolveHello;
|
|
196
|
+
const invitedNet = { selfId: () => 'invitee', others: () => new Map([['inviter', 'Ada']]), userId: () => '102' };
|
|
197
|
+
const arrival = makeInvites({ inviteArrival: () => new Promise((resolve) => { resolveHello = resolve; }) }, () => {}, () => {}, () => now);
|
|
198
|
+
assert.equal(arrival.hello(invitedNet).ready, false, 'hello waits for actual socket-roster completion');
|
|
199
|
+
resolveHello({ status: 'ok', destination: { hub: { target: { kind: 'player', id: '102' } } } });
|
|
200
|
+
await flush();
|
|
201
|
+
assert.deepEqual(arrival.hello(invitedNet), { ready: true, near: '102' }, 'first hello carries inviter for server placement');
|
|
202
|
+
const friendAt = { x: 1.6, y: 1, z: 0 };
|
|
203
|
+
const scene = { multiplayer: { net: invitedNet, avatars: { actors: new Map([['inviter', 'avatar-inviter']]) } }, getActor: () => ({ components: { Transform: friendAt } }), actorWith: () => ({ components: { Transform: { x: 0, y: 1, z: 0 } } }) };
|
|
204
|
+
assert.deepEqual(arrival.pointer(scene), { id: 'inviter', at: friendAt }, 'arrival pointer draws even beside inviter');
|
|
205
|
+
now += 11000;
|
|
206
|
+
assert.equal(arrival.pointer(scene), null, 'near arrival confirmation expires');
|
|
207
|
+
friendAt.x = 10;
|
|
208
|
+
assert.equal(arrival.pointer(scene)?.id, 'inviter', 'pointer still guides an inviter who walks away');
|
|
209
|
+
scene.multiplayer.net = { ...invitedNet, others: () => new Map() };
|
|
210
|
+
assert.equal(arrival.pointer(scene), null, 'a hidden or departed player is never pointed at');
|
|
211
|
+
arrival.landed();
|
|
212
|
+
assert.equal(arrival.hello(invitedNet).near, null, 'reconnect never replays invite placement');
|
|
213
|
+
arrival.dispose();
|
|
214
|
+
console.log('invite arrival: prehello placement, near pointer, expiry, visible roster and reconnect passed');
|
|
215
|
+
|
|
216
|
+
let houseCalls = 0, houseRoutes = 0;
|
|
217
|
+
const house = makeInvites({ inviteArrival: async () => ++houseCalls === 1 ? { status: 'route', doorId: 'home' } : { status: 'ok', destination: { hub: { target: { kind: 'player', id: '102' } } } } }, () => {}, () => { houseRoutes++; }, () => now);
|
|
218
|
+
house.hello(net); await flush();
|
|
219
|
+
assert.equal(house.hello(net).ready, true, 'routing town may hello before house completion');
|
|
220
|
+
assert.equal(houseRoutes, 0, 'house routing waits for town hello');
|
|
221
|
+
house.landed(); house.frame(net);
|
|
222
|
+
assert.equal(houseRoutes, 1);
|
|
223
|
+
const houseNet = { selfId: () => 'house-guest' };
|
|
224
|
+
house.hello(houseNet); await flush();
|
|
225
|
+
assert.equal(house.hello(houseNet).near, '102', 'routing town hello never consumes house placement');
|
|
226
|
+
house.landed(); assert.equal(house.hello(houseNet).near, null);
|
|
227
|
+
house.dispose();
|
|
228
|
+
console.log('invite house: route after town hello, first house placement consumed once passed');
|
|
229
|
+
|
|
230
|
+
for (const mode of ['refused', 'throw']) {
|
|
231
|
+
let minted = 0;
|
|
232
|
+
const refused = makeInvites({ ...hostYes, invite: async () => {
|
|
233
|
+
minted++;
|
|
234
|
+
if (mode === 'throw') throw new Error('gate refused');
|
|
235
|
+
return { status: 'unavailable' };
|
|
236
|
+
} }, () => {}, () => {});
|
|
237
|
+
refused.open(true); await flush(); await flush();
|
|
238
|
+
assert.equal(minted, 1, 'share refusal never retries minting');
|
|
239
|
+
assert.ok(activePanel().children.some((e) => e.textContent === 'Sharing is unavailable here.'));
|
|
240
|
+
assert.equal(activePanel().children.some((e) => e.textContent === 'Try again'), false);
|
|
241
|
+
refused.dispose();
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const identityNet = { selfId: () => 'me', userId: () => '2387022' };
|
|
245
|
+
for (const me of [null, { userId: '2387022', isAnonymous: true }, { userId: '102', isAnonymous: false }, { userId: '2387022' }, { userId: '2387022', isAnonymous: false }]) {
|
|
246
|
+
let reads = 0;
|
|
247
|
+
const identity = makeInvites(hostYes, () => {}, () => {});
|
|
248
|
+
const user = { getCurrent: async () => { reads++; return me; } };
|
|
249
|
+
assert.equal(identity.canInvite(identityNet, user), false, 'identity starts unresolved');
|
|
250
|
+
await flush();
|
|
251
|
+
// A guest (isAnonymous) is over 13 like anyone else: only the account match counts.
|
|
252
|
+
assert.equal(identity.canInvite(identityNet, user), me?.userId === '2387022');
|
|
253
|
+
assert.equal(reads, 1);
|
|
254
|
+
identity.dispose();
|
|
255
|
+
}
|
|
256
|
+
// v1.146: a host that names its links' account decides the match, so a web guest
|
|
257
|
+
// (User.getCurrent has no guest account) is offered the rail as that player.
|
|
258
|
+
for (const [label, hostUser, expected] of [['guest named by the host', '2387022', true], ['another account', '102', false]]) {
|
|
259
|
+
const named = makeInvites({ canInvite: async () => ({ status: 'ok', canInvite: true, userId: hostUser }) }, () => {}, () => {});
|
|
260
|
+
const guest = { getCurrent: async () => null };
|
|
261
|
+
assert.equal(named.canInvite(identityNet, guest), false, `${label}: unresolved`);
|
|
262
|
+
await flush();
|
|
263
|
+
assert.equal(named.canInvite(identityNet, guest), expected, label);
|
|
264
|
+
named.dispose();
|
|
265
|
+
}
|
|
266
|
+
{
|
|
267
|
+
const refused = makeInvites({ canInvite: async () => ({ status: 'ok', canInvite: false, userId: '2387022' }) }, () => {}, () => {});
|
|
268
|
+
refused.canInvite(identityNet, { getCurrent: async () => null }); await flush();
|
|
269
|
+
assert.equal(refused.canInvite(identityNet, { getCurrent: async () => null }), false, 'a named account without canInvite stays hidden');
|
|
270
|
+
refused.dispose();
|
|
271
|
+
}
|
|
272
|
+
// The host decides invite eligibility (under-13s, accounts outside the invite
|
|
273
|
+
// audience); an older host or SDK that cannot answer leaves the rail hidden.
|
|
274
|
+
{
|
|
275
|
+
const signedIn = { getCurrent: async () => ({ userId: '2387022', isAnonymous: false }) };
|
|
276
|
+
const unknown = Object.assign(new Error('Unknown Castle command.'), { code: 'UNKNOWN_COMMAND' });
|
|
277
|
+
for (const [label, api, expected] of [
|
|
278
|
+
['host says yes', hostYes, true],
|
|
279
|
+
['host says no', { canInvite: async () => ({ status: 'ok', canInvite: false }) }, false],
|
|
280
|
+
['host without hub', { canInvite: async () => ({ status: 'unavailable', canInvite: false }) }, false],
|
|
281
|
+
['host older than the command', { canInvite: async () => { throw unknown; } }, false],
|
|
282
|
+
['malformed answer', { canInvite: async () => ({ status: 'ok', canInvite: 'yes' }) }, false],
|
|
283
|
+
['SDK without canInvite', {}, false],
|
|
284
|
+
]) {
|
|
285
|
+
let asks = 0;
|
|
286
|
+
const counted = typeof api.canInvite === 'function' ? { ...api, canInvite: () => { asks++; return api.canInvite(); } } : api;
|
|
287
|
+
const gate = makeInvites(counted, () => {}, () => {});
|
|
288
|
+
assert.equal(gate.canInvite(identityNet, signedIn), false, `${label}: unresolved`);
|
|
289
|
+
await flush();
|
|
290
|
+
assert.equal(gate.canInvite(identityNet, signedIn), expected, label);
|
|
291
|
+
assert.equal(gate.canInvite(identityNet, signedIn), expected, `${label}: cached`);
|
|
292
|
+
if (typeof api.canInvite === 'function') {assert.equal(asks, 1, `${label}: one host read per socket`);}
|
|
293
|
+
gate.dispose();
|
|
294
|
+
}
|
|
295
|
+
const pendingHost = makeInvites({ canInvite: () => new Promise(() => {}) }, () => {}, () => {});
|
|
296
|
+
pendingHost.canInvite(identityNet, signedIn); await flush();
|
|
297
|
+
assert.equal(pendingHost.canInvite(identityNet, signedIn), false, 'a host that never answers keeps the rail hidden');
|
|
298
|
+
pendingHost.dispose();
|
|
299
|
+
let asks = 0;
|
|
300
|
+
const fresh = makeInvites({ canInvite: async () => ({ status: 'ok', canInvite: ++asks > 1 }) }, () => {}, () => {});
|
|
301
|
+
fresh.canInvite(identityNet, signedIn); await flush();
|
|
302
|
+
assert.equal(fresh.canInvite(identityNet, signedIn), false);
|
|
303
|
+
const rejoined = { ...identityNet };
|
|
304
|
+
fresh.canInvite(rejoined, signedIn); await flush();
|
|
305
|
+
assert.equal(fresh.canInvite(rejoined, signedIn), true, 'a new socket asks the host again');
|
|
306
|
+
fresh.dispose();
|
|
307
|
+
}
|
|
308
|
+
const identityGate = deferred();
|
|
309
|
+
const identity = makeInvites(hostYes, () => {}, () => {});
|
|
310
|
+
identity.canInvite(identityNet, { getCurrent: () => identityGate.promise });
|
|
311
|
+
await flush();
|
|
312
|
+
identity.reset(); identityGate.resolve({ userId: '2387022', isAnonymous: false }); await flush();
|
|
313
|
+
assert.equal(identity.canInvite(identityNet, {}), false, 'stale identity read cannot survive reset');
|
|
314
|
+
assert.equal(identity.canInvite({ ...identityNet, userId: () => 'solo' }, {}), false);
|
|
315
|
+
identity.dispose();
|
|
316
|
+
|
|
317
|
+
// The gate can close mid-socket (the host replaces its visit): the answer is
|
|
318
|
+
// asked again after 15 s, and a share asks fresh before making a link.
|
|
319
|
+
{
|
|
320
|
+
let clock = 0, allow = true, asks = 0, minted = 0;
|
|
321
|
+
const signedIn = { getCurrent: async () => ({ userId: '2387022', isAnonymous: false }) };
|
|
322
|
+
const revoked = makeInvites({ canInvite: async () => { asks++; return { status: 'ok', canInvite: allow }; }, invite: async () => { minted++; return { status: 'ok', url: 'https://castle.xyz/i/revoked' }; } }, () => {}, () => {}, () => clock);
|
|
323
|
+
revoked.canInvite(identityNet, signedIn); await flush();
|
|
324
|
+
assert.equal(revoked.canInvite(identityNet, signedIn), true);
|
|
325
|
+
allow = false; clock = 14999; revoked.canInvite(identityNet, signedIn); await flush();
|
|
326
|
+
assert.equal(asks, 1, 'no recheck inside 15 s');
|
|
327
|
+
const panelsBefore = elements.filter((e) => e.tag === 'section').length;
|
|
328
|
+
revoked.open(true); await flush();
|
|
329
|
+
assert.equal(minted, 0, 'a share asks the host first and makes no link once the gate closed');
|
|
330
|
+
assert.equal(elements.filter((e) => e.tag === 'section').length, panelsBefore, 'a refused share opens no panel');
|
|
331
|
+
assert.equal(revoked.canInvite(identityNet, signedIn), false, 'a refused share hides the rail at once');
|
|
332
|
+
allow = true; clock = 30000; revoked.canInvite(identityNet, signedIn); await flush();
|
|
333
|
+
assert.equal(revoked.canInvite(identityNet, signedIn), true, 'the rail returns when the host allows again');
|
|
334
|
+
allow = false; clock = 45000; revoked.canInvite(identityNet, signedIn); await flush();
|
|
335
|
+
assert.equal(revoked.canInvite(identityNet, signedIn), false, 'a periodic recheck hides the rail after revocation');
|
|
336
|
+
revoked.dispose();
|
|
337
|
+
const unknown = Object.assign(new Error('Unknown Castle command.'), { code: 'UNKNOWN_COMMAND' });
|
|
338
|
+
for (const api of [{}, { canInvite: async () => { throw unknown; } }]) {
|
|
339
|
+
let made = 0;
|
|
340
|
+
const old = makeInvites({ ...api, invite: async () => { made++; return { status: 'ok', url: 'https://castle.xyz/i/old' }; } }, () => {}, () => {});
|
|
341
|
+
old.open(true); await flush();
|
|
342
|
+
assert.equal(made, 0, 'a host or SDK without canInvite never makes a link');
|
|
343
|
+
old.dispose();
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// A share still asking the host is cancelled by a reset, a new socket or a
|
|
348
|
+
// closed one, even if the host then says yes.
|
|
349
|
+
for (const invalidate of ['reset', 'socket', 'closed']) {
|
|
350
|
+
const answer = deferred();
|
|
351
|
+
let made = 0;
|
|
352
|
+
const signedIn = { getCurrent: async () => ({ userId: '2387022', isAnonymous: false }) };
|
|
353
|
+
let first = true;
|
|
354
|
+
const stale = makeInvites({ canInvite: () => first ? (first = false, Promise.resolve({ status: 'ok', canInvite: true })) : answer.promise,
|
|
355
|
+
invite: async () => { made++; return { status: 'ok', url: 'https://castle.xyz/i/stale' }; }, inviteArrival: async () => ({ status: 'unavailable' }) }, () => {}, () => {});
|
|
356
|
+
let closed = false;
|
|
357
|
+
const live = { ...identityNet, closed: () => closed };
|
|
358
|
+
stale.canInvite(live, signedIn); await flush();
|
|
359
|
+
assert.equal(stale.canInvite(live, signedIn), true);
|
|
360
|
+
const panels = elements.filter((e) => e.tag === 'section').length;
|
|
361
|
+
stale.open(true); await flush();
|
|
362
|
+
if (invalidate === 'reset') {stale.reset();}
|
|
363
|
+
if (invalidate === 'socket') {stale.frame({ ...identityNet });}
|
|
364
|
+
if (invalidate === 'closed') {closed = true; stale.canInvite(live, signedIn);}
|
|
365
|
+
answer.resolve({ status: 'ok', canInvite: true }); await flush();
|
|
366
|
+
assert.equal(made, 0, `${invalidate}: a stale share makes no link`);
|
|
367
|
+
assert.equal(elements.filter((e) => e.tag === 'section').length, panels, `${invalidate}: a stale share opens no panel`);
|
|
368
|
+
stale.dispose();
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
for (const [title, words] of [[' Castle Town ', 'Join me in Castle Town.'], ['', 'Join me here.']]) {
|
|
372
|
+
const titleShare = makeInvites({ ...hostYes, invite: async () => ({ status: 'ok', url: 'https://castle.xyz/i/title' }) }, () => {}, () => {}, undefined, undefined, () => title);
|
|
373
|
+
titleShare.open(true); await flush();
|
|
374
|
+
assert.equal(activePanel().children.find((e) => e.tag === 'textarea').value, `${words}\nhttps://castle.xyz/i/title`);
|
|
375
|
+
assert.ok(activePanel().children.some((e) => e.textContent === 'Invite up to five friends. This link lasts 24 hours.'));
|
|
376
|
+
titleShare.dispose();
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// Wrapping the displayed share payload must never truncate what Copy sends.
|
|
380
|
+
{
|
|
381
|
+
const url = `https://castle.xyz/i/${'a'.repeat(43)}`;
|
|
382
|
+
const fittedShare = makeInvites({ ...hostYes, invite: async () => ({ status: 'ok', url }) }, () => {}, () => {}, undefined, undefined, () => 'Castle Town');
|
|
383
|
+
navigator.clipboard.writeText = async (text) => copied.push(text);
|
|
384
|
+
fittedShare.open(true); await flush();
|
|
385
|
+
const field = activePanel().children.find((e) => e.tag === 'textarea');
|
|
386
|
+
assert.ok(field.value.startsWith('Join me in Castle Town.\nhttps://castle.xyz/i/'));
|
|
387
|
+
assert.ok(field.value.includes('…'), 'long links display a middle ellipsis');
|
|
388
|
+
const before = copied.length;
|
|
389
|
+
activePanel().children.find((e) => e.textContent === 'Copy link').click(); await flush();
|
|
390
|
+
assert.equal(copied.length, before + 1);
|
|
391
|
+
assert.equal(copied.at(-1), `Join me in Castle Town. ${url}`, 'Copy retains the whole link despite the display ellipsis');
|
|
392
|
+
fittedShare.dispose();
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
for (const copiedOk of [true, false]) {
|
|
396
|
+
const url = `https://castle.xyz/i/${'b'.repeat(43)}`;
|
|
397
|
+
navigator.clipboard.writeText = async () => {throw new Error('clipboard unavailable');};
|
|
398
|
+
const fallbackShare = makeInvites({ ...hostYes, invite: async () => ({ status: 'ok', url }) }, () => {}, () => {}, undefined, undefined, () => 'Castle Town');
|
|
399
|
+
fallbackShare.open(true); await flush();
|
|
400
|
+
const original = activePanel(), field = original.children.find((e) => e.tag === 'textarea'), shown = field.value;
|
|
401
|
+
field.focus = () => {}; field.select = () => {};
|
|
402
|
+
document.execCommand = (command) => {
|
|
403
|
+
assert.equal(command, 'copy');
|
|
404
|
+
assert.equal(field.value, `Join me in Castle Town. ${url}`, 'legacy clipboard fallback selects the complete payload');
|
|
405
|
+
return copiedOk;
|
|
406
|
+
};
|
|
407
|
+
original.children.find((e) => e.textContent === 'Copy link').click(); await flush();
|
|
408
|
+
if (copiedOk) {assert.ok(original.removed);}
|
|
409
|
+
else {assert.equal(activePanel(), original); assert.equal(field.value, shown, 'failed copy restores the fitted display');}
|
|
410
|
+
fallbackShare.dispose(); delete document.execCommand;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
{
|
|
414
|
+
dynamicViewportUnits = false; // Older CSS parsers retain the prior valid declaration.
|
|
415
|
+
const legacyViewport = makeInvites({ ...hostYes, invite: async () => ({ status: 'ok', url: 'https://castle.xyz/i/legacy' }) }, () => {}, () => {}, undefined, undefined, () => 'Castle Town');
|
|
416
|
+
legacyViewport.open(true); await flush();
|
|
417
|
+
assert.ok(activePanel().style.maxHeight.startsWith('calc(100vh - 24px'), 'fitted invite stays capped when dvh is unsupported');
|
|
418
|
+
legacyViewport.dispose(); dynamicViewportUnits = true;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
{
|
|
422
|
+
const layouts = [];
|
|
423
|
+
const registered = makeInvites(hostYes, () => {}, () => {}, undefined, undefined, undefined, (node) => layouts.push(node));
|
|
424
|
+
registered.open(false); await flush();
|
|
425
|
+
assert.equal(registered.surface(), activePanel());
|
|
426
|
+
assert.equal(layouts.at(-1), registered.surface());
|
|
427
|
+
registered.reset(); assert.equal(layouts.at(-1), null); assert.equal(registered.surface(), null);
|
|
428
|
+
registered.dispose(); assert.equal(layouts.at(-1), null);
|
|
429
|
+
console.log('invite dialog layout registration and cleanup passed');
|
|
430
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { request } from '../code/server/invites.js';
|
|
3
|
+
import { readManifest, publicPlace } from '../code/server/manifest.js';
|
|
4
|
+
import { makeInvites } from '../../../experiments/hub-town/code/server/invites.js';
|
|
5
|
+
import { makeHeard } from '../../../experiments/hub-town/code/server/heard.js';
|
|
6
|
+
import { makeLabelRegistry } from '../../../experiments/hub-town/code/server/pointer.js';
|
|
7
|
+
import { actions } from '../../../experiments/hub-town/code/server/actions.js';
|
|
8
|
+
const json = (invite) => ({ server: { maxPlayers: 8 }, hub: { contract: 1, title: 'Town', ...(invite === undefined ? {} : { invite }) } });
|
|
9
|
+
const old = readManifest(json(), () => true);
|
|
10
|
+
assert.equal('invite' in old.manifest.places.main, false);
|
|
11
|
+
assert.equal('invite' in publicPlace('main', old.manifest.places.main), false);
|
|
12
|
+
const opted = readManifest(json(true), () => true);
|
|
13
|
+
assert.equal(publicPlace('main', opted.manifest.places.main).invite, true);
|
|
14
|
+
for (const invalid of [false, 1, 'true', null]) assert.ok(readManifest(json(invalid), () => true).errors.length);
|
|
15
|
+
const sent = [];
|
|
16
|
+
const h = { place: { invite: true }, players: new Map([['a', { arrived: true }]]), sim: { timeMs: 0, players: new Map([['a', {}]]) }, session: { send: (...args) => sent.push(args) } };
|
|
17
|
+
assert.equal(request(h, 'missing'), false);
|
|
18
|
+
assert.equal(request(h, 'a'), true);
|
|
19
|
+
assert.deepEqual(sent, [['a', { k: 'hub-invite' }]]);
|
|
20
|
+
assert.equal(request(h, 'a'), false);
|
|
21
|
+
h.sim.timeMs += 1000;
|
|
22
|
+
assert.equal(request(h, 'a', { share: true }), true);
|
|
23
|
+
assert.deepEqual(sent.at(-1), ['a', { k: 'hub-invite', share: true }]);
|
|
24
|
+
assert.throws(() => request(h, 'a', { share: 'true' }), /optional boolean share/);
|
|
25
|
+
assert.throws(() => request(h, 'a', { share: true, text: 'Ada' }), /optional boolean share/);
|
|
26
|
+
assert.throws(() => request({ ...h, place: {} }, 'a'), /does not declare invite/);
|
|
27
|
+
assert.throws(() => request(h, {}), /playerId must be a string/);
|
|
28
|
+
const labels = [], offered = [], invited = [];
|
|
29
|
+
const people = [{ playerId: 'a', userId: '101', at: { x: 0, z: 0 } }, { playerId: 'b', userId: '102', at: { x: 20, z: 0 } }];
|
|
30
|
+
const hub = { now: 0, players: () => people, actions: (id, items) => { offered.push([id, items]); return true; }, invite: (id) => invited.push(id) };
|
|
31
|
+
const pointer = { request: (...args) => labels.push(['request', ...args]), show: (...args) => labels.push(['show', ...args]), clear: (...args) => labels.push(['clear', ...args]) };
|
|
32
|
+
const pads = new Map([['pair', { door: { minPlayers: 2 }, onPad: new Map([['a', 0]]) }]]);
|
|
33
|
+
const dormant = makeInvites({ enabled: false, pointerRegistry: { source() { throw new Error('no pointer state without opt-in'); } } });
|
|
34
|
+
dormant.pads(hub, pads); dormant.step(hub); dormant.target(hub, people[0], { k: 'hub-invite-target', userId: '102' });
|
|
35
|
+
assert.equal(offered.length, 0);
|
|
36
|
+
const invites = makeInvites({ enabled: true, pointerRegistry: { source: (name) => { assert.equal(name, 'invite'); return pointer; } } });
|
|
37
|
+
invites.pads(hub, pads);
|
|
38
|
+
assert.deepEqual(actions.offered(hub, 'a'), [{ id: 'invite-friend', label: 'Invite a friend' }]);
|
|
39
|
+
actions.press(hub, 'a', 'invite-friend'); assert.deepEqual(invited, ['a']);
|
|
40
|
+
pads.get('pair').onPad.set('b', 0); invites.pads(hub, pads);
|
|
41
|
+
assert.deepEqual(actions.offered(hub, 'a'), []);
|
|
42
|
+
invites.target(hub, people[0], { k: 'hub-invite-target', userId: '102' });
|
|
43
|
+
assert.deepEqual(labels.at(-1), ['request', 'a']);
|
|
44
|
+
invites.step(hub);
|
|
45
|
+
assert.equal(labels.at(-1)[0], 'show');
|
|
46
|
+
assert.deepEqual(labels.at(-1)[4](), { id: 'b', x: 20, z: 0 });
|
|
47
|
+
people[1].at.x = 1; invites.step(hub);
|
|
48
|
+
assert.equal(labels.at(-1)[0], 'clear');
|
|
49
|
+
|
|
50
|
+
let wall = 100000;
|
|
51
|
+
const shareCalls = [], sharePeople = [{ playerId: 'winner', userId: '201', at: { x: 0, z: 0 } }];
|
|
52
|
+
const shareHub = { now: 0, players: () => sharePeople, username: () => 'Winner', doors: () => [],
|
|
53
|
+
session: { players: [{ playerId: 'winner', userId: '201', isAnonymous: false }] },
|
|
54
|
+
actions() { return true; }, invite: (...args) => shareCalls.push(args) };
|
|
55
|
+
const shares = makeInvites({ enabled: true, pointerRegistry: null, keyOf: (_hub, id) => `u:${sharePeople.find((p) => p.playerId === id)?.userId}`, now: () => wall });
|
|
56
|
+
const heard = makeHeard({ now: () => wall });
|
|
57
|
+
heard.onResult((key, entry) => shares.result(key, entry));
|
|
58
|
+
for (const entry of [
|
|
59
|
+
{ outcome: 'win', verified: true, at: wall },
|
|
60
|
+
{ outcome: 'win', verified: true, carried: true, at: wall - 30000 },
|
|
61
|
+
{ outcome: 'win', verified: true, carried: true, at: wall + 1 },
|
|
62
|
+
{ outcome: 'lose', verified: true, carried: true, at: wall },
|
|
63
|
+
{ outcome: 'win', verified: false, carried: true, at: wall },
|
|
64
|
+
]) shares.result('u:201', entry);
|
|
65
|
+
shares.step(shareHub);
|
|
66
|
+
assert.deepEqual(actions.offered(shareHub, 'winner'), [], 'polled, stale, future, lost and unverified results do not offer Share');
|
|
67
|
+
actions.set(shareHub, 'garden', 'winner', [{ id: 'garden', label: 'Garden' }], () => {});
|
|
68
|
+
heard.carried(shareHub, 'winner', 'race', { outcome: 'win', verified: true });
|
|
69
|
+
shares.step(shareHub);
|
|
70
|
+
assert.deepEqual(actions.offered(shareHub, 'winner'), [{ id: 'garden', label: 'Garden' }, { id: 'share-win', label: 'Share' }]);
|
|
71
|
+
actions.press(shareHub, 'winner', 'share-win');
|
|
72
|
+
assert.deepEqual(shareCalls, [['winner', { share: true }]]);
|
|
73
|
+
shares.step(shareHub);
|
|
74
|
+
assert.deepEqual(actions.offered(shareHub, 'winner'), [{ id: 'garden', label: 'Garden' }], 'Share is private, temporary and consumed after use');
|
|
75
|
+
heard.carried(shareHub, 'winner', 'race', { outcome: 'win', verified: true });
|
|
76
|
+
shares.step(shareHub); wall += 30000;
|
|
77
|
+
actions.press(shareHub, 'winner', 'share-win');
|
|
78
|
+
assert.deepEqual(shareCalls, [['winner', { share: true }]], 'a visible stale action cannot share at the exact deadline');
|
|
79
|
+
shares.step(shareHub);
|
|
80
|
+
assert.deepEqual(actions.offered(shareHub, 'winner'), [{ id: 'garden', label: 'Garden' }]);
|
|
81
|
+
console.log('hub invites: dormant manifest, private request/share wire, pair offer, carried-win arbitration and live pointer passed');
|
|
82
|
+
|
|
83
|
+
const realLabels = [];
|
|
84
|
+
people[1].at.x = 20;
|
|
85
|
+
const liveHub = { ...hub, label: (...args) => realLabels.push(args) };
|
|
86
|
+
const real = makeInvites({ enabled: true, pointerRegistry: makeLabelRegistry(() => ({ id: 'corner' })) });
|
|
87
|
+
real.target(liveHub, people[0], { k: 'hub-invite-target', userId: '102' });
|
|
88
|
+
real.step(liveHub);
|
|
89
|
+
assert.equal(realLabels.at(-1)[2].edge, undefined, 'invite uses the existing triggered arrow');
|
|
90
|
+
assert.deepEqual(realLabels.at(-1)[2].to, ['a']);
|
|
91
|
+
|
|
92
|
+
// The authored town offers its existing invite command away from pair pads.
|
|
93
|
+
const townPeople = [{ playerId: 'town-a' }, { playerId: 'town-b' }], townCalls = [];
|
|
94
|
+
const townHub = { players: () => townPeople, actions: () => true, invite: (id) => townCalls.push(id) };
|
|
95
|
+
const townInvites = makeInvites({ enabled: true, anywhere: true });
|
|
96
|
+
townInvites.step(townHub);
|
|
97
|
+
for (const p of townPeople) assert.deepEqual(actions.offered(townHub, p.playerId), [{ id: 'invite-friend', label: 'Invite a friend' }]);
|
|
98
|
+
actions.press(townHub, 'town-a', 'invite-friend');
|
|
99
|
+
assert.deepEqual(townCalls, ['town-a']);
|
|
100
|
+
townPeople.shift();
|
|
101
|
+
actions.press(townHub, 'town-a', 'invite-friend');
|
|
102
|
+
assert.deepEqual(townCalls, ['town-a'], 'a stale control cannot invite after leaving');
|
|
103
|
+
|
|
104
|
+
// Root-only capability never changes the public place or the v1.95 wire.
|
|
105
|
+
const friendManifest = readManifest({ ...json(true), hub: { ...json(true).hub, bringFriend: true } }, () => true);
|
|
106
|
+
assert.deepEqual(publicPlace('main', friendManifest.manifest.places.main), publicPlace('main', opted.manifest.places.main));
|
|
107
|
+
|
|
108
|
+
for (const bad of [false, null, 1]) assert.ok(readManifest({ ...json(true), hub: { ...json(true).hub, bringFriend: bad } }, () => true).errors.length);
|
|
109
|
+
assert.ok(readManifest({ ...json(), hub: { ...json().hub, bringFriend: true } }, () => true).errors.length);
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import assert from 'node:assert/strict';
|
|
7
7
|
import fs from 'node:fs';
|
|
8
|
-
import { chromeItem, CLEAR_PX, HIDE_MS, labelBox, makeNear, MAX, near, nearFor, SIGN_FAR_M, SIGN_NEAR_M, STICK_M } from '../code/client/labelsNear.js';
|
|
8
|
+
import { goalAt, chromeItem, CLEAR_PX, HIDE_MS, labelBox, makeNear, MAX, near, nearCandidates, nearFor, SIGN_FAR_M, SIGN_NEAR_M, STICK_M } from '../code/client/labelsNear.js';
|
|
9
9
|
import { fakeDom } from './fixtures/fake-dom.mjs';
|
|
10
10
|
import { readManifest } from '../code/server/manifest.js';
|
|
11
11
|
|
|
@@ -408,10 +408,11 @@ const dom = fakeDom(PHONE, layout);
|
|
|
408
408
|
const { makeChrome } = await import('../code/client/chrome.js');
|
|
409
409
|
const chrome = makeChrome({ onBack() {}, onAvatar() {}, avatarCount: 4 });
|
|
410
410
|
const root = dom.body.children[0];
|
|
411
|
-
const hudNode = root.children.find((c) => c.styles.
|
|
412
|
-
const labelLayer = root.children[root.children.indexOf(hudNode) +
|
|
411
|
+
const hudNode = root.children.find((c) => c.styles.textShadow?.includes('rgba(0,0,0,0.95)'));
|
|
412
|
+
const labelLayer = root.children[root.children.indexOf(hudNode) + 3];
|
|
413
413
|
const view = { w: PHONE.viewW, h: PHONE.viewH };
|
|
414
414
|
hudNode.rect = { left: 60, right: 300, top: 12, bottom: 124 };
|
|
415
|
+
dom.made.find(node => node.dataset.hub === 'hud-prompt').rect = { left: 72, right: 288, top: 660, bottom: 686, width: 216, height: 26 };
|
|
415
416
|
// One frame as the hub system draws it under the key (`nearLabels`): the HUD,
|
|
416
417
|
// each label's box from `labelBox`, the rule, `chromeItem` to `setLabels`,
|
|
417
418
|
// and the frame's flush. `wanted` is `{ id, kind, npc, text, d, x, y }`, (x, y)
|
|
@@ -593,4 +594,71 @@ test('the chrome draws a world label from its box alone: no width read, no move
|
|
|
593
594
|
clearAll();
|
|
594
595
|
});
|
|
595
596
|
|
|
597
|
+
test('private goal position projects independently of a hidden actor Transform', () => {
|
|
598
|
+
const hidden = { x: 0, y: -9998.8, z: 0 };
|
|
599
|
+
const at = { x: 30, y: 1.2, z: 40 };
|
|
600
|
+
assert.deepEqual(goalAt({style:'goal',at}, hidden), at);
|
|
601
|
+
assert.deepEqual(goalAt({style:'goal',at}, undefined), at);
|
|
602
|
+
assert.strictEqual(goalAt({style:'tag',at}, hidden), hidden);
|
|
603
|
+
assert.strictEqual(goalAt({style:'goal',at:{x:NaN,y:1,z:0}}, hidden), hidden);
|
|
604
|
+
assert.strictEqual(goalAt({style:'goal'}, hidden), hidden);
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
test('v1.131 prompt clearance happens before near-label selection', () => {
|
|
610
|
+
const hud = { left: 120, right: 724, top: 12, bottom: 80 };
|
|
611
|
+
const prompt = { left: 260, right: 584, top: 310, bottom: 336 };
|
|
612
|
+
const view = { w: 844, h: 390 };
|
|
613
|
+
const placed = labelBox(422, 330, { w: 100, h: 26 }, false, view, hud, prompt);
|
|
614
|
+
assert.equal(placed.bottom, 304);
|
|
615
|
+
assert.equal(touching(placed, prompt), false);
|
|
616
|
+
assert.equal(touching(placed, hud), false);
|
|
617
|
+
assert.equal(labelBox(422, 330, { w: 100, h: 300 }, false, view, hud, prompt), null, 'oversized label cannot cover either band');
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
// Cache only a conservative distance shortlist; compare every rendered frame
|
|
622
|
+
// with the original unthrottled selection, including camera-only changes.
|
|
623
|
+
for (const scenario of ['camera turn', 'overlap', 'distance boundary', 'teleport', 'source change']) {
|
|
624
|
+
test(`${scenario}: cached candidates equal fresh selection each frame`, () => {
|
|
625
|
+
const fresh = makeNear(), cached = makeNear(), holder = {}, scope = {};
|
|
626
|
+
let placed = Array.from({ length: 6 }, (_, i) => ({ id: `sign${i}`, at: { x: i + 2, y: 0, z: 0 }, label: { style: 'sign', text: `Sign ${i}` }, always: true }));
|
|
627
|
+
placed.push({ id: 'edge', at: { x: 15.1, y: 0, z: 0 }, label: { style: 'sign', text: 'Edge' }, always: true });
|
|
628
|
+
if (scenario === 'distance boundary') {placed.at(-1).at.x = 12.2;}
|
|
629
|
+
const position = { x: 0, y: 0, z: 0 };
|
|
630
|
+
let first;
|
|
631
|
+
for (let frame = 0; frame < 12; frame += 1) {
|
|
632
|
+
if (scenario === 'distance boundary') {position.x = frame * 0.11;}
|
|
633
|
+
if (scenario === 'teleport' && frame === 2) {position.x = 10;}
|
|
634
|
+
if (scenario === 'source change' && frame === 2) {placed = [...placed, { id: 'new', at: { x: 1, y: 0, z: 0 }, label: { style: 'sign', text: 'New' }, always: true }];}
|
|
635
|
+
const ids = nearCandidates(holder, placed, position, 1000 + frame * 16, scope);
|
|
636
|
+
if (frame === 0) {first = ids;}
|
|
637
|
+
if (frame === 2 && ['camera turn', 'overlap'].includes(scenario)) {assert.strictEqual(ids, first, 'camera changes reuse distance candidates');}
|
|
638
|
+
const project = (entry, index) => {
|
|
639
|
+
if (scenario === 'camera turn' && (frame < 2 ? index > 0 : index === 0)) {return null;}
|
|
640
|
+
return box(scenario === 'overlap' && frame >= 2 ? 200 : 60 + index * 110, 300);
|
|
641
|
+
};
|
|
642
|
+
const items = placed.map((entry, index) => ({ id: entry.id, kind: 'sign', d: Math.abs(entry.at.x - position.x), box: project(entry, index) }));
|
|
643
|
+
const shortlisted = items.map((item) => ids.has(item.id) ? item : { ...item, d: Infinity, box: null });
|
|
644
|
+
assert.deepEqual(near(cached, shortlisted, VIEW, 1000 + frame * 16), near(fresh, items, VIEW, 1000 + frame * 16), `frame ${frame}`);
|
|
645
|
+
if (scenario === 'camera turn' && frame === 2) {assert(!cached.chosen.has('sign0') && cached.chosen.size > 0, 'turn reveals a different sign immediately');}
|
|
646
|
+
if (scenario === 'distance boundary' && frame === 2) {assert(cached.reach.has('edge'), 'reach updates between candidate refreshes');}
|
|
647
|
+
if (scenario === 'overlap' && frame >= 2) {assert(cached.chosen.size <= 1, 'collisions run between candidate refreshes');}
|
|
648
|
+
}
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
test('candidate refreshes cover arrival, movement, source changes and cadence', () => {
|
|
653
|
+
const holder = {}, scope = {}, position = { x: 0, y: 0, z: 0 };
|
|
654
|
+
const placed = [{ id: 'a', at: { x: 2, y: 0, z: 0 }, label: {}, always: true }];
|
|
655
|
+
const initial = nearCandidates(holder, placed, position, 1000, scope);
|
|
656
|
+
assert.strictEqual(nearCandidates(holder, placed, { ...position, x: 0.5 }, 1099, scope), initial);
|
|
657
|
+
const moved = nearCandidates(holder, placed, { ...position, x: 0.51 }, 1099, scope);
|
|
658
|
+
assert.notStrictEqual(moved, initial);
|
|
659
|
+
const arrived = nearCandidates(holder, placed, position, 1100, {});
|
|
660
|
+
assert.notStrictEqual(arrived, moved);
|
|
661
|
+
assert.notStrictEqual(nearCandidates(holder, placed, position, 1200, scope), arrived);
|
|
662
|
+
});
|
|
663
|
+
|
|
596
664
|
console.log(`hub-game labels: ${passed} tests passed`);
|