castle-web-cli 0.4.232 → 0.4.234
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-failures.d.ts +8 -0
- package/dist/agent-failures.js +19 -2
- package/dist/agent-prompts.d.ts +1 -1
- package/dist/agent-prompts.js +10 -3
- package/dist/agent.d.ts +64 -3
- package/dist/agent.js +170 -81
- package/dist/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 +18 -2
- package/dist/castle-host/host.js +844 -39
- package/dist/castleJson.d.ts +23 -2
- package/dist/castleJson.js +46 -2
- package/dist/check.d.ts +3 -1
- package/dist/check.js +20 -3
- 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 +50 -2
- 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/importPinMismatch.d.ts +22 -0
- package/dist/importPinMismatch.js +77 -0
- package/dist/importRegression.js +3 -15
- package/dist/imports.d.ts +10 -3
- package/dist/imports.js +88 -20
- package/dist/index.js +11 -4
- package/dist/init.js +1 -1
- package/dist/platformDoc.js +22 -0
- package/dist/routerFences.d.ts +5 -0
- package/dist/routerFences.js +12 -2
- package/dist/save-deck.d.ts +25 -1
- package/dist/save-deck.js +178 -9
- package/dist/serve.js +32 -11
- package/dist/shell/assets/{index-D2tWM896.js → index-DulbYIJm.js} +97 -97
- package/dist/shell/assets/index-MVLfNYd9.css +1 -0
- package/dist/shell/index.html +2 -2
- package/dist/taskSteer.d.ts +13 -0
- package/dist/taskSteer.js +22 -2
- package/dist/vitePlugins.d.ts +2 -1
- package/dist/vitePlugins.js +13 -0
- package/kits/base/castle.json +1 -1
- package/kits/base/package-lock.json +1 -1
- package/kits/base/sdk/README.md +339 -5
- package/kits/base/sdk/avatar.d.ts +6 -2
- package/kits/base/sdk/avatar.js +12 -4
- package/kits/base/sdk/castle.d.ts +7 -3
- package/kits/base/sdk/castle.js +2 -0
- package/kits/base/sdk/commands.d.ts +176 -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 +37 -6
- package/kits/base/sdk/hub.js +63 -4
- package/kits/base/sdk/multiplayer.d.ts +7 -1
- package/kits/base/sdk/multiplayer.js +148 -32
- 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 +81 -7
- package/kits/base/sdk/server/hub.d.ts +117 -0
- package/kits/base/sdk/server/hub.js +119 -2
- package/kits/base/sdk/server/platformHandle.d.ts +43 -1
- package/kits/base/sdk/server/storage.d.ts +17 -0
- package/kits/base/sdk/server/storage.js +65 -3
- package/kits/base/sdk/server/wrapper.d.ts +43 -6
- package/kits/base/sdk/server/wrapper.js +93 -9
- package/kits/base/sdk/social.d.ts +9 -0
- package/kits/base/sdk/social.js +5 -0
- package/kits/hub-game/CLAUDE.md +451 -13
- package/kits/hub-game/README.md +63 -0
- package/kits/hub-game/blueprints/avatar-10.scene +28 -0
- package/kits/hub-game/blueprints/avatar-11.scene +28 -0
- package/kits/hub-game/blueprints/avatar-12.scene +28 -0
- package/kits/hub-game/blueprints/avatar-13.scene +28 -0
- package/kits/hub-game/blueprints/avatar-14.scene +28 -0
- package/kits/hub-game/blueprints/avatar-15.scene +28 -0
- package/kits/hub-game/blueprints/avatar-4.scene +28 -0
- package/kits/hub-game/blueprints/avatar-5.scene +28 -0
- package/kits/hub-game/blueprints/avatar-6.scene +28 -0
- package/kits/hub-game/blueprints/avatar-7.scene +28 -0
- package/kits/hub-game/blueprints/avatar-8.scene +28 -0
- package/kits/hub-game/blueprints/avatar-9.scene +28 -0
- package/kits/hub-game/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/actorBudget.js +47 -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/attention.js +11 -2
- package/kits/hub-game/code/client/avatar.js +311 -35
- package/kits/hub-game/code/client/avatarCap.js +228 -0
- package/kits/hub-game/code/client/avatarColors.js +70 -0
- package/kits/hub-game/code/client/avatarFaces.js +21 -0
- package/kits/hub-game/code/client/avatarShare.js +253 -0
- package/kits/hub-game/code/client/backVisibility.js +13 -0
- package/kits/hub-game/code/client/ballot.js +472 -0
- package/kits/hub-game/code/client/build.js +38 -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 +2144 -160
- package/kits/hub-game/code/client/companion.js +716 -0
- package/kits/hub-game/code/client/companionDress.js +99 -0
- package/kits/hub-game/code/client/crowdNames.js +241 -0
- package/kits/hub-game/code/client/decor.js +515 -0
- 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/earned.js +131 -0
- package/kits/hub-game/code/client/emoteBubble.js +75 -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 +368 -29
- package/kits/hub-game/code/client/hookLayer.js +385 -20
- 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 +177 -24
- package/kits/hub-game/code/client/interestCap.js +81 -0
- 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/keys.js +36 -0
- package/kits/hub-game/code/client/labelsNear.js +234 -0
- 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/menuIcons.js +34 -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/pack.js +6 -2
- package/kits/hub-game/code/client/packFormat.js +3 -3
- 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/rehello.js +167 -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 +146 -0
- 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/sound.js +63 -8
- package/kits/hub-game/code/client/soundscape.js +1151 -0
- package/kits/hub-game/code/client/soundscapeActions.js +99 -0
- package/kits/hub-game/code/client/soundscapeAmbience.js +453 -0
- package/kits/hub-game/code/client/soundscapeBaked.js +143 -0
- package/kits/hub-game/code/client/soundscapeBusker.js +217 -0
- package/kits/hub-game/code/client/soundscapeCourt.js +200 -0
- package/kits/hub-game/code/client/soundscapeCrowd.js +331 -0
- package/kits/hub-game/code/client/soundscapeCues.js +362 -0
- package/kits/hub-game/code/client/soundscapeMap.js +181 -0
- package/kits/hub-game/code/client/soundscapeMarket.js +176 -0
- package/kits/hub-game/code/client/soundscapeMusic.js +126 -0
- package/kits/hub-game/code/client/soundscapeMusicEngine.js +460 -0
- package/kits/hub-game/code/client/soundscapeSimlish.js +737 -0
- package/kits/hub-game/code/client/soundscapeSongs.js +127 -0
- package/kits/hub-game/code/client/soundscapeSongsRound3.js +63 -0
- package/kits/hub-game/code/client/soundscapeSynthesis.js +168 -0
- package/kits/hub-game/code/client/soundscapeUi.js +211 -0
- package/kits/hub-game/code/client/soundscapeVoice.js +1209 -0
- package/kits/hub-game/code/client/soundscapeWaves.js +206 -0
- package/kits/hub-game/code/client/spin.js +101 -0
- package/kits/hub-game/code/client/state.js +162 -1
- package/kits/hub-game/code/client/stuck.js +259 -0
- package/kits/hub-game/code/client/talk.js +714 -59
- package/kits/hub-game/code/client/tiers.js +543 -52
- package/kits/hub-game/code/client/toastBand.js +37 -0
- package/kits/hub-game/code/client/together.js +39 -2
- package/kits/hub-game/code/client/visibility.js +43 -0
- 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/wear.js +461 -170
- package/kits/hub-game/code/client/worldLabels.js +241 -0
- package/kits/hub-game/code/client/yours.js +200 -0
- package/kits/hub-game/code/companionSpec.js +45 -0
- package/kits/hub-game/code/npcDisplayText.js +55 -0
- package/kits/hub-game/code/privateText.js +7 -0
- package/kits/hub-game/code/server/act.js +124 -0
- package/kits/hub-game/code/server/actions.js +138 -0
- package/kits/hub-game/code/server/actors.js +11 -2
- 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/ask.js +155 -0
- package/kits/hub-game/code/server/ballot.js +539 -0
- package/kits/hub-game/code/server/cells.js +100 -0
- package/kits/hub-game/code/server/companion.js +107 -0
- package/kits/hub-game/code/server/cues.js +70 -0
- package/kits/hub-game/code/server/decor.js +269 -0
- package/kits/hub-game/code/server/doorAnalytics.js +52 -0
- package/kits/hub-game/code/server/earned.js +478 -0
- package/kits/hub-game/code/server/frameBatch.js +183 -0
- package/kits/hub-game/code/server/friendBests.js +166 -0
- package/kits/hub-game/code/server/friendsAmong.js +272 -0
- package/kits/hub-game/code/server/history.js +7 -0
- package/kits/hub-game/code/server/hub.js +2510 -95
- package/kits/hub-game/code/server/idle.js +60 -12
- package/kits/hub-game/code/server/index.js +28 -6
- package/kits/hub-game/code/server/invites.js +19 -0
- package/kits/hub-game/code/server/labels.js +36 -2
- package/kits/hub-game/code/server/loadAbandon.js +106 -0
- package/kits/hub-game/code/server/manifest.js +586 -7
- package/kits/hub-game/code/server/menu.js +161 -0
- package/kits/hub-game/code/server/npcs.js +1025 -113
- 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/party.js +2 -2
- package/kits/hub-game/code/server/players.js +30 -0
- 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/shot.js +110 -0
- package/kits/hub-game/code/server/standing.js +123 -0
- package/kits/hub-game/code/server/storageLimit.js +187 -0
- package/kits/hub-game/code/server/vis.js +175 -0
- package/kits/hub-game/code/server/wear.js +12 -0
- package/kits/hub-game/code/server/yours.js +59 -0
- package/kits/hub-game/code/shared/act.js +35 -0
- package/kits/hub-game/code/shared/cues.js +9 -0
- package/kits/hub-game/code/shared/danceIdle.js +28 -0
- package/kits/hub-game/code/shared/decor.js +41 -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 +53 -0
- package/kits/hub-game/code/shared/spin.js +57 -0
- package/kits/hub-game/code/systems/hub.js +1753 -202
- package/kits/hub-game/docs/analytics.md +279 -0
- package/kits/hub-game/docs/content-pack.md +1 -1
- package/kits/hub-game/docs/contract.md +3475 -77
- package/kits/hub-game/docs/home-pieces.md +71 -0
- package/kits/hub-game/docs/observed-progress.md +252 -0
- package/kits/hub-game/main.jsx +2 -0
- package/kits/hub-game/models/avatar-10.pxmodel +28 -0
- package/kits/hub-game/models/avatar-11.pxmodel +28 -0
- package/kits/hub-game/models/avatar-12.pxmodel +27 -0
- package/kits/hub-game/models/avatar-13.pxmodel +24 -0
- package/kits/hub-game/models/avatar-14.pxmodel +29 -0
- package/kits/hub-game/models/avatar-15.pxmodel +24 -0
- package/kits/hub-game/models/avatar-4.pxmodel +29 -0
- package/kits/hub-game/models/avatar-5.pxmodel +27 -0
- package/kits/hub-game/models/avatar-6.pxmodel +26 -0
- package/kits/hub-game/models/avatar-7.pxmodel +25 -0
- package/kits/hub-game/models/avatar-8.pxmodel +24 -0
- package/kits/hub-game/models/avatar-9.pxmodel +30 -0
- package/kits/hub-game/models/earned/badge-round.pxmodel +100 -0
- package/kits/hub-game/models/earned/badge-shield.pxmodel +117 -0
- package/kits/hub-game/models/earned/badge-star.pxmodel +87 -0
- package/kits/hub-game/models/earned/belt-plain.pxmodel +72 -0
- package/kits/hub-game/models/earned/held-ball.pxmodel +43 -0
- package/kits/hub-game/models/earned/held-lantern.pxmodel +85 -0
- package/kits/hub-game/models/earned/held-net.pxmodel +57 -0
- package/kits/hub-game/models/earned/held-trophy.pxmodel +109 -0
- package/kits/hub-game/models/earned/pin-round.pxmodel +62 -0
- package/kits/hub-game/models/earned/sash-plain.pxmodel +66 -0
- package/kits/hub-game/models/earned/square/belt-plain.pxmodel +104 -0
- package/kits/hub-game/models/earned/square/sash-plain.pxmodel +98 -0
- package/kits/hub-game/models/hats/bat-clip.pxmodel +206 -0
- package/kits/hub-game/models/hats/beekeeper.pxmodel +149 -0
- package/kits/hub-game/models/hats/cap.pxmodel +162 -0
- package/kits/hub-game/models/hats/captain.pxmodel +178 -0
- package/kits/hub-game/models/hats/crooked-top.pxmodel +172 -0
- package/kits/hub-game/models/hats/flower-crown.pxmodel +451 -0
- package/kits/hub-game/models/hats/foam-crown.pxmodel +179 -0
- package/kits/hub-game/models/hats/lantern.pxmodel +230 -0
- package/kits/hub-game/models/hats/laurel.pxmodel +533 -0
- package/kits/hub-game/models/hats/lighthouse.pxmodel +96 -0
- package/kits/hub-game/models/hats/sailor.pxmodel +141 -0
- package/kits/hub-game/models/hats/souwester.pxmodel +131 -0
- package/kits/hub-game/models/hats/straw.pxmodel +139 -0
- package/kits/hub-game/models/hats/sunflower.pxmodel +406 -0
- package/kits/hub-game/models/hats/sweatband.pxmodel +112 -0
- package/kits/hub-game/models/hats/witch.pxmodel +147 -0
- package/kits/hub-game/package-lock.json +10 -1
- package/kits/hub-game/package.json +6 -2
- 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 +117 -16
- package/kits/hub-game/scripts/companion-follower-wire.json +1 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +132 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless.json +293 -0
- package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +26 -0
- package/kits/hub-game/scripts/fixtures/fake-dom.mjs +123 -0
- package/kits/hub-game/scripts/fixtures/interest-legacy.json +385 -0
- package/kits/hub-game/scripts/fixtures/npc-notes-v1.77.jsonl +4 -0
- package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -0
- package/kits/hub-game/scripts/gen-avatars.mjs +933 -16
- package/kits/hub-game/scripts/gen-earned.mjs +285 -0
- package/kits/hub-game/scripts/gen-hats.mjs +827 -0
- package/kits/hub-game/scripts/grab.before-orbit.mjs +400 -0
- package/kits/hub-game/scripts/pose-storage-fixture.mjs +46 -0
- package/kits/hub-game/scripts/soundscape-wave-analysis.mjs +125 -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 +853 -0
- package/kits/hub-game/scripts/test-actions.mjs +298 -0
- package/kits/hub-game/scripts/test-actor-budget.mjs +44 -0
- package/kits/hub-game/scripts/test-actors.mjs +38 -23
- 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-client.mjs +358 -0
- package/kits/hub-game/scripts/test-ask-slot.mjs +85 -0
- package/kits/hub-game/scripts/test-ask.mjs +269 -0
- package/kits/hub-game/scripts/test-attention.mjs +10 -1
- package/kits/hub-game/scripts/test-avatar-cap.mjs +379 -0
- package/kits/hub-game/scripts/test-avatar-colors.mjs +72 -0
- package/kits/hub-game/scripts/test-avatar-models.mjs +181 -0
- package/kits/hub-game/scripts/test-avatar-share.mjs +318 -0
- package/kits/hub-game/scripts/test-avatar-wire.mjs +792 -0
- package/kits/hub-game/scripts/test-avatar.mjs +584 -7
- package/kits/hub-game/scripts/test-back-visibility.mjs +82 -0
- package/kits/hub-game/scripts/test-ballot.mjs +1008 -0
- package/kits/hub-game/scripts/test-ban-join.mjs +121 -13
- package/kits/hub-game/scripts/test-build.mjs +49 -0
- package/kits/hub-game/scripts/test-cells.mjs +71 -0
- package/kits/hub-game/scripts/test-chat.mjs +863 -0
- package/kits/hub-game/scripts/test-classic.mjs +2 -0
- package/kits/hub-game/scripts/test-companion-chat.mjs +216 -0
- package/kits/hub-game/scripts/test-companion-client.mjs +1167 -0
- package/kits/hub-game/scripts/test-companion.mjs +259 -0
- package/kits/hub-game/scripts/test-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 +344 -0
- package/kits/hub-game/scripts/test-decor.mjs +464 -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-client.mjs +459 -0
- package/kits/hub-game/scripts/test-earned.mjs +1224 -0
- package/kits/hub-game/scripts/test-emote-bubble.mjs +110 -0
- 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-friend-bests.mjs +435 -0
- package/kits/hub-game/scripts/test-grab-orbit.mjs +961 -0
- package/kits/hub-game/scripts/test-grab.mjs +7 -0
- package/kits/hub-game/scripts/test-hats.mjs +422 -168
- package/kits/hub-game/scripts/test-high-only.mjs +170 -0
- package/kits/hub-game/scripts/test-hub-leaving.mjs +203 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +758 -2
- package/kits/hub-game/scripts/test-hub-trip.mjs +1594 -12
- package/kits/hub-game/scripts/test-hud-clear.mjs +484 -57
- 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 +427 -1
- package/kits/hub-game/scripts/test-interest-cap.mjs +36 -0
- package/kits/hub-game/scripts/test-interest-cells.mjs +513 -0
- package/kits/hub-game/scripts/test-interest-client.mjs +118 -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-keys.mjs +46 -1
- package/kits/hub-game/scripts/test-labels.mjs +664 -0
- 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 +472 -0
- package/kits/hub-game/scripts/test-menu-client.mjs +585 -0
- package/kits/hub-game/scripts/test-menu.mjs +319 -0
- package/kits/hub-game/scripts/test-npcs.mjs +2528 -13
- package/kits/hub-game/scripts/test-object-entry.mjs +76 -0
- package/kits/hub-game/scripts/test-observed.mjs +745 -0
- package/kits/hub-game/scripts/test-pack.mjs +7 -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 +541 -0
- 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 +1733 -0
- package/kits/hub-game/scripts/test-relations-among.mjs +222 -0
- package/kits/hub-game/scripts/test-relations-refresh.mjs +188 -0
- package/kits/hub-game/scripts/test-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 +901 -0
- package/kits/hub-game/scripts/test-signin-client.mjs +45 -0
- package/kits/hub-game/scripts/test-soundscape.mjs +5437 -0
- package/kits/hub-game/scripts/test-spin.mjs +314 -0
- package/kits/hub-game/scripts/test-standing.mjs +449 -0
- package/kits/hub-game/scripts/test-storage-limit.mjs +333 -0
- package/kits/hub-game/scripts/test-stuck.mjs +1904 -0
- package/kits/hub-game/scripts/test-talk-overlay-dom.mjs +130 -0
- package/kits/hub-game/scripts/test-tier-cells.mjs +706 -0
- package/kits/hub-game/scripts/test-tiers-render.mjs +412 -0
- package/kits/hub-game/scripts/test-tiers.mjs +476 -2
- package/kits/hub-game/scripts/test-toast-band.mjs +61 -0
- package/kits/hub-game/scripts/test-try-on.mjs +22 -22
- package/kits/hub-game/scripts/test-vis.mjs +770 -0
- package/kits/hub-game/scripts/test-visibility.mjs +134 -0
- 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 +210 -0
- package/kits/hub-game/scripts/test-yours.mjs +403 -0
- package/kits/multiplayer-3d/CLAUDE.md +50 -0
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/avatars.js +7 -0
- package/kits/multiplayer-3d/code/client/gait.js +65 -0
- package/kits/multiplayer-3d/code/client/joinFailure.js +27 -0
- package/kits/multiplayer-3d/code/client/nameTags.js +59 -4
- package/kits/multiplayer-3d/code/client/resumeGate.js +139 -0
- package/kits/multiplayer-3d/code/options.js +5 -0
- package/kits/multiplayer-3d/code/server/ownership.js +10 -2
- package/kits/multiplayer-3d/code/server/sceneBodies.js +12 -0
- package/kits/multiplayer-3d/code/server/world.js +7 -0
- package/kits/multiplayer-3d/code/systems/multiplayer.js +443 -34
- package/kits/multiplayer-3d/package-lock.json +8 -1
- package/kits/multiplayer-3d/package.json +3 -1
- package/kits/multiplayer-3d/scripts/fixtures/README.md +11 -0
- package/kits/multiplayer-3d/scripts/fixtures/ownership-legacy.json +2 -0
- package/kits/multiplayer-3d/scripts/ownership-harness.mjs +102 -0
- package/kits/multiplayer-3d/scripts/ownership-loader.mjs +46 -0
- package/kits/multiplayer-3d/scripts/ownership-worker.mjs +15 -0
- package/kits/multiplayer-3d/scripts/record-ownership-session.mjs +98 -0
- package/kits/multiplayer-3d/scripts/test-eligible-claims.mjs +167 -0
- package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +436 -0
- package/kits/multiplayer-3d/scripts/test-own-name-tag.mjs +247 -0
- package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +624 -0
- package/kits/physics-2d/CLAUDE.md +19 -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 +337 -3
- package/kits/physics-2d/engine/skyKey.js +129 -0
- package/kits/physics-2d/engine/stillClock.js +106 -0
- package/kits/physics-2d/engine/updateBudget.js +21 -0
- package/kits/physics-2d/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-2d/scripts/test-skip-unchanged.mjs +326 -1
- package/kits/physics-3d/CLAUDE.md +42 -529
- 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 +661 -87
- 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 +9 -1
- package/kits/physics-3d/engine3d/PlayOnly3D.jsx +5 -1
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +19 -277
- package/kits/physics-3d/engine3d/actornode.js +87 -0
- package/kits/physics-3d/engine3d/animationBudget.js +23 -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/editorWorld.js +6 -0
- package/kits/physics-3d/engine3d/emptynodes.js +232 -0
- package/kits/physics-3d/engine3d/framecap.js +99 -0
- 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 +126 -0
- package/kits/physics-3d/engine3d/initialModelFiles.js +18 -0
- package/kits/physics-3d/engine3d/kithooks.js +47 -0
- package/kits/physics-3d/engine3d/look.js +514 -48
- package/kits/physics-3d/engine3d/lookbake.js +208 -0
- package/kits/physics-3d/engine3d/materialpresets.js +2 -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 +39 -10
- package/kits/physics-3d/engine3d/nearshadows.js +106 -21
- package/kits/physics-3d/engine3d/optimize.js +9 -5
- package/kits/physics-3d/engine3d/orbitinput.js +522 -10
- package/kits/physics-3d/engine3d/orbitlens.js +48 -0
- package/kits/physics-3d/engine3d/ownmodel.js +213 -0
- 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 +42 -11
- 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 +890 -0
- package/kits/physics-3d/engine3d/sky.js +547 -0
- package/kits/physics-3d/engine3d/skylife.js +306 -0
- 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/unchanged.js +11 -0
- package/kits/physics-3d/engine3d/viewrange.js +52 -0
- package/kits/physics-3d/engine3d/world3d.js +1253 -76
- package/kits/physics-3d/eslint.config.js +2 -1
- package/kits/physics-3d/main.jsx +10 -2
- 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/look-baseline.mjs +155 -0
- package/kits/physics-3d/scripts/test-camera-follow.mjs +5 -1
- package/kits/physics-3d/scripts/test-camera-orbit.mjs +2613 -82
- package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +2 -2
- package/kits/physics-3d/scripts/test-empty-gait-hints.mjs +89 -0
- package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +438 -0
- package/kits/physics-3d/scripts/test-frame-cap.mjs +452 -0
- 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-gait.mjs +387 -0
- package/kits/physics-3d/scripts/test-look-bake.mjs +1056 -0
- package/kits/physics-3d/scripts/test-model-parse-cache.mjs +92 -0
- package/kits/physics-3d/scripts/test-near-shadows.mjs +5 -2
- package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +2001 -0
- package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +582 -0
- package/kits/physics-3d/scripts/test-orbit-shot.mjs +657 -0
- package/kits/physics-3d/scripts/test-orbit-view.mjs +230 -0
- package/kits/physics-3d/scripts/test-rapier-gz.mjs +106 -0
- package/kits/physics-3d/scripts/test-skip-empty-nodes.mjs +845 -0
- package/kits/physics-3d/scripts/test-sky.mjs +2470 -0
- package/kits/physics-3d/scripts/test-square-first.mjs +921 -0
- package/kits/physics-3d/scripts/test-static-actors.mjs +10 -1
- package/kits/physics-3d/scripts/test-static-physics.mjs +4 -1
- package/kits/physics-3d/scripts/test-static-scenery.mjs +2174 -0
- package/kits/physics-3d/scripts/test-steady-hover.mjs +7 -2
- package/kits/physics-3d/scripts/test-still-shadows.mjs +477 -0
- package/kits/physics-3d/scripts/test-view-range.mjs +260 -0
- package/kits/physics-3d/systems/physics3d.js +419 -9
- 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/gameHooks.js +7 -0
- package/kits/real-time/code/server/session.js +102 -22
- package/kits/real-time/package-lock.json +1 -1
- package/package.json +2 -2
- package/dist/shell/assets/index-Cf61cNfT.css +0 -1
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
// The cap on different characters drawn at once (code/client/avatarCap.js):
|
|
2
|
+
// beyond the limit the farthest players are drawn as their stand-in (`% 4`),
|
|
3
|
+
// nearer players win, nobody within NEAR_M, the local player and the first
|
|
4
|
+
// four are never capped, nobody flickers, `?hubAvDistinct=N` sets the limit,
|
|
5
|
+
// and a change respawns the player through the hook layer's own avatar-change
|
|
6
|
+
// path, fade guard included. The client is the kit's real hook layer over the multiplayer
|
|
7
|
+
// kit's real avatar bookkeeping, as test-avatar-wire.mjs runs them.
|
|
8
|
+
// `npm run check` runs this.
|
|
9
|
+
|
|
10
|
+
import assert from 'node:assert/strict';
|
|
11
|
+
import { register } from 'node:module';
|
|
12
|
+
import path from 'node:path';
|
|
13
|
+
import { pathToFileURL } from 'node:url';
|
|
14
|
+
|
|
15
|
+
const renderer = new URL('../../multiplayer-3d/code/client/avatars.js', import.meta.url).href;
|
|
16
|
+
const rendererStubs = {
|
|
17
|
+
'./nameTags.js': '',
|
|
18
|
+
'./poses.js': 'export function applyPose(transform, pose) { [transform.x, transform.y, transform.z] = pose; }',
|
|
19
|
+
'@imports/castle.physics-2d/engine/art.js': 'export const artReady = () => false;',
|
|
20
|
+
'@imports/castle.physics-2d/engine/avatarArt.js': 'export const avatarFacePath = () => null;',
|
|
21
|
+
'@imports/castle.physics-3d/engine3d/materials.js': 'export function makeShapeMesh() { throw new Error("unexpected head drawing"); }',
|
|
22
|
+
};
|
|
23
|
+
register(
|
|
24
|
+
`data:text/javascript,${encodeURIComponent(`
|
|
25
|
+
import { readFile } from 'node:fs/promises';
|
|
26
|
+
import { fileURLToPath } from 'node:url';
|
|
27
|
+
const stubs = {
|
|
28
|
+
'@imports/castle.physics-3d/engine3d/orbitlens.js': ${JSON.stringify(new URL('../../physics-3d/engine3d/orbitlens.js', import.meta.url).href)},
|
|
29
|
+
'@imports/castle.multiplayer-3d/code/client/avatars.js': ${JSON.stringify(renderer)},
|
|
30
|
+
'castle-web-sdk': ${JSON.stringify(new URL('./fixtures/sdk-stub.mjs', import.meta.url).href)},
|
|
31
|
+
};
|
|
32
|
+
export async function resolve(specifier, context, next) {
|
|
33
|
+
const rendererStubs = ${JSON.stringify(rendererStubs)};
|
|
34
|
+
if (context.parentURL === ${JSON.stringify(renderer)} && specifier in rendererStubs) {
|
|
35
|
+
return { url: 'data:text/javascript,' + encodeURIComponent(rendererStubs[specifier]), shortCircuit: true };
|
|
36
|
+
}
|
|
37
|
+
if (stubs[specifier]) {
|
|
38
|
+
return { url: stubs[specifier], shortCircuit: true };
|
|
39
|
+
}
|
|
40
|
+
return next(specifier, context);
|
|
41
|
+
}
|
|
42
|
+
// The hook layer reads the deck's castle.json through the bundler.
|
|
43
|
+
export async function load(url, context, next) {
|
|
44
|
+
if (url.endsWith('/code/client/hookLayer.js')) {
|
|
45
|
+
const source = await readFile(fileURLToPath(url), 'utf8');
|
|
46
|
+
return { format: 'module', source: source.replaceAll('import.meta.glob(', '(() => ({}))('), shortCircuit: true };
|
|
47
|
+
}
|
|
48
|
+
return next(url, context);
|
|
49
|
+
}
|
|
50
|
+
`)}`,
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const at = (file) => pathToFileURL(path.join(import.meta.dirname, '..', file)).href;
|
|
54
|
+
const AvatarCap = await import(at('code/client/avatarCap.js'));
|
|
55
|
+
const State = await import(at('code/client/state.js'));
|
|
56
|
+
const Avatar = await import(at('code/client/avatar.js'));
|
|
57
|
+
const hookLayer = (await import(at('code/client/hookLayer.js'))).default;
|
|
58
|
+
const Avatars = await import(renderer);
|
|
59
|
+
const { choose, HOLD_MS, NEARER_M, NEAR_M } = AvatarCap;
|
|
60
|
+
// Past the distance within which nobody is a stand-in, whoever they are.
|
|
61
|
+
const D = NEAR_M + NEARER_M + 1;
|
|
62
|
+
|
|
63
|
+
let n = 0;
|
|
64
|
+
function test(name, fn) {
|
|
65
|
+
try {
|
|
66
|
+
fn();
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error(`hub-game avatar cap: FAILED ${name}`);
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
n += 1;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const row = (...pairs) => pairs.map(([playerId, index, distance]) => ({ playerId, index, distance }));
|
|
75
|
+
const ids = (set) => [...set].sort();
|
|
76
|
+
|
|
77
|
+
test('colour variants count as models and lose colour before their character', () => {
|
|
78
|
+
const players = [{ playerId: 'a', index: 9, color: 1, distance: D }, { playerId: 'b', index: 9, color: 2, distance: D + 1 }];
|
|
79
|
+
const limited = choose({ own: 9, ownColor: 0, players, limit: 2 });
|
|
80
|
+
assert.deepEqual(ids(limited), []);
|
|
81
|
+
assert.deepEqual(ids(limited.colorStandIns), ['b']);
|
|
82
|
+
const plain = choose({ own: 9, players, limit: 1 });
|
|
83
|
+
assert.deepEqual(ids(plain), []);
|
|
84
|
+
assert.deepEqual(ids(plain.colorStandIns), ['a', 'b']);
|
|
85
|
+
const same = choose({ own: 9, ownColor: 1, players: [players[0]], limit: 1 });
|
|
86
|
+
assert.deepEqual(ids(same.colorStandIns), []);
|
|
87
|
+
const fallback = choose({ own: 1, players: [players[0]], limit: 1 });
|
|
88
|
+
assert.deepEqual(ids(fallback), ['a']);
|
|
89
|
+
const near = choose({ own: 9, players: [{ ...players[0], distance: 1 }], limit: 1 });
|
|
90
|
+
assert.deepEqual(ids(near.colorStandIns), []);
|
|
91
|
+
const held = choose({ own: 9, players: [players[0]], limit: 2, colorStandIns: new Set(['a']), changedAt: new Map([['a', 1000]]), now: 1001 });
|
|
92
|
+
assert.deepEqual(ids(held.colorStandIns), ['a']);
|
|
93
|
+
const released = choose({ own: 9, players: [players[0]], limit: 2, colorStandIns: new Set(['a']), changedAt: new Map([['a', 1000]]), now: 1000 + HOLD_MS });
|
|
94
|
+
assert.deepEqual(ids(released.colorStandIns), []);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('dropping colour reuses a drawn plain character even when exempt neighbours exceed the cap', () => {
|
|
98
|
+
const limited = choose({
|
|
99
|
+
own: 9,
|
|
100
|
+
limit: 2,
|
|
101
|
+
players: [
|
|
102
|
+
{ playerId: 'near0', index: 0, distance: 1 },
|
|
103
|
+
{ playerId: 'near1', index: 1, distance: 2 },
|
|
104
|
+
{ playerId: 'far9', index: 9, color: 1, distance: D },
|
|
105
|
+
],
|
|
106
|
+
});
|
|
107
|
+
assert.deepEqual(ids(limited), [], 'keep character 9 rather than its stand-in 1');
|
|
108
|
+
assert.deepEqual(ids(limited.colorStandIns), ['far9'], 'draw character 9 in colour 0');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('?hubAvDistinct=N sets the limit; absent, 0 or nonsense is the default', () => {
|
|
112
|
+
const limitFor = (search) => {
|
|
113
|
+
AvatarCap.setCapEnv({ location: { search } });
|
|
114
|
+
return AvatarCap.limit();
|
|
115
|
+
};
|
|
116
|
+
assert.equal(limitFor(''), AvatarCap.DISTINCT_DEFAULT);
|
|
117
|
+
// Every character: by default nobody is a stand-in.
|
|
118
|
+
assert.equal(AvatarCap.DISTINCT_DEFAULT, 16);
|
|
119
|
+
assert.equal(AvatarCap.DISTINCT_DEFAULT, Avatar.AVATARS);
|
|
120
|
+
assert.equal(limitFor('?hubAvDistinct=0'), 16);
|
|
121
|
+
assert.equal(limitFor('?hubAvDistinct=x'), 16);
|
|
122
|
+
assert.equal(limitFor('?hubAvDistinct=-3'), 16);
|
|
123
|
+
assert.equal(limitFor('?hubAvDistinct=6'), 6);
|
|
124
|
+
assert.equal(limitFor('?hubAvDistinct=3'), 3);
|
|
125
|
+
assert.equal(limitFor('?a=1&hubAvDistinct=99'), 99);
|
|
126
|
+
AvatarCap.setCapEnv({ location: null });
|
|
127
|
+
assert.equal(AvatarCap.limit(), 16);
|
|
128
|
+
AvatarCap.setCapEnv(null);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test('the stand-ins count: nobody is given their own character unless the total stays within the limit', () => {
|
|
132
|
+
// The local player wears 4; eleven others at 1..11 m past D wear 5..15. Their
|
|
133
|
+
// stand-ins alone are 0-3, so with the local player's, six leave room for
|
|
134
|
+
// one more character: the nearest player's.
|
|
135
|
+
const players = Array.from({ length: 11 }, (_, i) => ({ playerId: `p${String(i + 1).padStart(2, '0')}`, index: 5 + i, distance: D + i + 1 }));
|
|
136
|
+
const capped = choose({ own: 4, players, limit: 6 });
|
|
137
|
+
assert.deepEqual(ids(capped), players.slice(1).map((player) => player.playerId));
|
|
138
|
+
const models = new Set([4, ...players.map((player) => (capped.has(player.playerId) ? player.index % 4 : player.index))]);
|
|
139
|
+
assert.deepEqual([...models].sort((x, y) => x - y), [0, 1, 2, 3, 4, 5]);
|
|
140
|
+
// A large limit is no cap.
|
|
141
|
+
assert.equal(choose({ own: 4, players, limit: 99 }).size, 0);
|
|
142
|
+
// A character already drawn (the local player's, or a nearer player's) costs nothing more.
|
|
143
|
+
const same = row(['a', 9, D + 1], ['b', 10, D + 2], ['c', 4, D + 30], ['d', 9, D + 31]);
|
|
144
|
+
assert.deepEqual(ids(choose({ own: 4, players: same, limit: 3 })), []);
|
|
145
|
+
// Where even the stand-ins pass the limit, everyone who can be is one.
|
|
146
|
+
assert.deepEqual(ids(choose({ own: 4, players: same, limit: 2 })), ['a', 'b', 'd']);
|
|
147
|
+
// The first four are never capped, and count as drawn.
|
|
148
|
+
const four = row(['a', 0, D + 1], ['b', 1, D + 2], ['c', 2, D + 3], ['d', 3, D + 4], ['e', 7, D + 5]);
|
|
149
|
+
assert.deepEqual(ids(choose({ own: 4, players: four, limit: 2 })), ['e']);
|
|
150
|
+
// Nobody's body known yet: the farthest. Nothing that is not an avatar is drawn as anything.
|
|
151
|
+
const unknown = row(['far', 5, null], ['near', 9, D + 5], ['one', 1, D + 1], ['none', null, D + 1]);
|
|
152
|
+
assert.deepEqual(ids(choose({ own: 4, players: unknown, limit: 3 })), ['far']);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test('nobody flickers: one drawn as their own counts as nearer, and a change holds for a while', () => {
|
|
156
|
+
// Stand-ins of 8 and 12 are 0, which `c` wears anyway: one of a and b fits.
|
|
157
|
+
// `a` is a stand-in at D + 10 m; `b`, drawn as their own, at D + 11 m: b keeps the place.
|
|
158
|
+
const players = row(['a', 8, D + 10], ['b', 12, D + 11], ['c', 0, D + 50]);
|
|
159
|
+
assert.deepEqual(ids(choose({ own: 4, players, limit: 3, standIns: new Set(['a']) })), ['a']);
|
|
160
|
+
// Past the margin, a takes it.
|
|
161
|
+
const passed = row(['a', 8, D + 10], ['b', 12, D + 10 + NEARER_M + 0.5], ['c', 0, D + 50]);
|
|
162
|
+
assert.deepEqual(ids(choose({ own: 4, players: passed, limit: 3, standIns: new Set(['a']) })), ['b']);
|
|
163
|
+
// But not while b changed less than HOLD_MS ago, nor while a did.
|
|
164
|
+
const changedAt = new Map([['b', 1000]]);
|
|
165
|
+
assert.deepEqual(ids(choose({ own: 4, players: passed, limit: 3, standIns: new Set(['a']), changedAt, now: 1000 + HOLD_MS - 1 })), ['a']);
|
|
166
|
+
assert.deepEqual(ids(choose({ own: 4, players: passed, limit: 3, standIns: new Set(['a']), changedAt, now: 1000 + HOLD_MS })), ['b']);
|
|
167
|
+
const aChanged = new Map([['a', 1000]]);
|
|
168
|
+
assert.deepEqual(ids(choose({ own: 4, players: passed, limit: 3, standIns: new Set(['a']), changedAt: aChanged, now: 1000 + HOLD_MS - 1 })), ['a']);
|
|
169
|
+
// A held player drawn as their own still becomes a stand-in rather than pass the limit.
|
|
170
|
+
const crowd = row(['x', 9, D + 1], ['y', 10, D + 2]);
|
|
171
|
+
assert.deepEqual(ids(choose({ own: 4, players: crowd, limit: 2, changedAt: new Map([['x', 1000], ['y', 1000]]), now: 1001 })), ['x', 'y']);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test('nobody within NEAR_M is a stand-in, past the limit too, and one who walks up swaps at once', () => {
|
|
175
|
+
// A crowd of eleven different characters all around: none is capped.
|
|
176
|
+
const close = Array.from({ length: 11 }, (_, i) => ({ playerId: `n${String(i).padStart(2, '0')}`, index: 5 + i, distance: (i * (NEAR_M - 1)) / 10 }));
|
|
177
|
+
assert.deepEqual(ids(choose({ own: 4, players: close, limit: 6 })), []);
|
|
178
|
+
// Those near take their places first: the farther ones are the stand-ins.
|
|
179
|
+
const mixed = row(['near', 9, NEAR_M - 1], ['mid', 10, D + 1], ['far', 11, D + 20]);
|
|
180
|
+
assert.deepEqual(ids(choose({ own: 4, players: mixed, limit: 3 })), ['far', 'mid']);
|
|
181
|
+
// A stand-in who changed a moment ago and walks up is drawn as their own at once.
|
|
182
|
+
const changedAt = new Map([['near', 1000]]);
|
|
183
|
+
assert.deepEqual(ids(choose({ own: 4, players: mixed, limit: 3, standIns: new Set(['near']), changedAt, now: 1001 })), ['far', 'mid']);
|
|
184
|
+
// Between NEAR_M and NEAR_M + NEARER_M, whoever they are now they stay.
|
|
185
|
+
const edge = row(['e', 9, NEAR_M + NEARER_M / 2], ['f', 10, D + 1]);
|
|
186
|
+
assert.deepEqual(ids(choose({ own: 4, players: edge, limit: 2 })), ['f']);
|
|
187
|
+
assert.deepEqual(ids(choose({ own: 4, players: edge, limit: 2, standIns: new Set(['e', 'f']) })), ['e', 'f']);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test('a stationary crowd settles within the limit and stays put', () => {
|
|
191
|
+
// The reported case: local avatar 4, others wearing 5-15 at 1-11 m past D, limit 6.
|
|
192
|
+
AvatarCap.setCapEnv({ location: { search: '?hubAvDistinct=6' } });
|
|
193
|
+
State.clear();
|
|
194
|
+
AvatarCap.resetCap();
|
|
195
|
+
const bodies = new Map();
|
|
196
|
+
const actors = new Map();
|
|
197
|
+
for (let i = 0; i < 11; i += 1) {
|
|
198
|
+
const playerId = `p${String(i + 1).padStart(2, '0')}`;
|
|
199
|
+
State.hub.avatars.set(playerId, 5 + i);
|
|
200
|
+
actors.set(playerId, `body-${playerId}`);
|
|
201
|
+
bodies.set(`body-${playerId}`, { components: { Transform: { x: D + i + 1, y: 1, z: 0 } } });
|
|
202
|
+
}
|
|
203
|
+
State.hub.avatars.set('me', 4);
|
|
204
|
+
const local = { components: { Transform: { x: 0, y: 1, z: 0 } } };
|
|
205
|
+
const scene = { persistent: { hubAvatar: 4 }, actorWith: () => local, getActor: (id) => bodies.get(id) ?? null };
|
|
206
|
+
const system = { net: { selfId: () => 'me' }, avatars: { actors } };
|
|
207
|
+
const seen = [];
|
|
208
|
+
for (const now of [1000, 1250, 3250, 11000]) {
|
|
209
|
+
AvatarCap.frame(scene, system, now);
|
|
210
|
+
const models = new Set([4, ...[...actors.keys()].map((playerId) => AvatarCap.shown(playerId))]);
|
|
211
|
+
assert.ok(models.size <= 6, `${models.size} different models at ${now} ms`);
|
|
212
|
+
seen.push(JSON.stringify([ids(State.hub.avatarStandIns), [...models].sort((x, y) => x - y)]));
|
|
213
|
+
}
|
|
214
|
+
assert.equal(new Set(seen).size, 1, seen.join('\n'));
|
|
215
|
+
AvatarCap.setCapEnv(null);
|
|
216
|
+
State.clear();
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// A client as the page runs one: a scene with the local player and bodies
|
|
220
|
+
// that keep a Transform, the multiplayer kit's bookkeeping, the hook layer.
|
|
221
|
+
function client() {
|
|
222
|
+
State.clear();
|
|
223
|
+
AvatarCap.resetCap();
|
|
224
|
+
const actors = new Map();
|
|
225
|
+
const nodes = new Map();
|
|
226
|
+
let spawned = 0;
|
|
227
|
+
const local = { id: 'me-body', components: { Transform: { x: 0, y: 1, z: 0 } } };
|
|
228
|
+
const files = {};
|
|
229
|
+
for (let i = 0; i < 16; i += 1) {
|
|
230
|
+
files[`imports/castle.hub-game/blueprints/avatar-${i}.scene`] = '{}';
|
|
231
|
+
}
|
|
232
|
+
const scene = {
|
|
233
|
+
files,
|
|
234
|
+
persistent: { hubAvatar: 4 },
|
|
235
|
+
three: { nodes },
|
|
236
|
+
actorWith: (name) => (name === 'Player' ? local : null),
|
|
237
|
+
getActor: (id) => actors.get(id) ?? null,
|
|
238
|
+
despawnActor(id) {
|
|
239
|
+
actors.delete(id);
|
|
240
|
+
nodes.delete(id);
|
|
241
|
+
},
|
|
242
|
+
spawnFromBlueprint(blueprint, options) {
|
|
243
|
+
const actor = { id: `body-${++spawned}`, blueprint, components: options.components };
|
|
244
|
+
actors.set(actor.id, actor);
|
|
245
|
+
nodes.set(actor.id, { node: { scale: { value: 1, setScalar(value) { this.value = value; } }, userData: {} } });
|
|
246
|
+
return actor;
|
|
247
|
+
},
|
|
248
|
+
};
|
|
249
|
+
const others = new Map();
|
|
250
|
+
const system = { net: { selfId: () => 'me', others: () => others }, avatars: Avatars.makeAvatars() };
|
|
251
|
+
const place = (playerId, x) => {
|
|
252
|
+
const actor = Avatars.showPlayer(system.avatars, scene, playerId, null, [x, 1, 0, 0], hookLayer.avatar(playerId, playerId));
|
|
253
|
+
actor.components.Transform = { ...actor.components.Transform, x, y: 1, z: 0 };
|
|
254
|
+
return actor;
|
|
255
|
+
};
|
|
256
|
+
const drawnAs = (playerId) => Number(/avatar-(\d+)\.scene$/.exec(actors.get(system.avatars.actors.get(playerId))?.blueprint ?? '')?.[1] ?? NaN);
|
|
257
|
+
return { scene, system, others, place, drawnAs, actors };
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
test('a capped player respawns as their stand-in, through the avatar-change path, and back when nearer', () => {
|
|
261
|
+
AvatarCap.setCapEnv({ location: { search: '?hubAvDistinct=4' } });
|
|
262
|
+
const { scene, system, others, place, drawnAs, actors } = client();
|
|
263
|
+
// Five others at 2, 4, 6, 8 and 10 m past D; the local player wears 4. Their
|
|
264
|
+
// stand-ins are 1, 1, 1, 2 and 2: with the local player's, room for one more.
|
|
265
|
+
const wear = [5, 9, 13, 6, 10];
|
|
266
|
+
const hubAv = {};
|
|
267
|
+
const hubAv2 = {};
|
|
268
|
+
wear.forEach((index, i) => {
|
|
269
|
+
hubAv[`p${i}`] = index % 4;
|
|
270
|
+
hubAv2[`p${i}`] = index;
|
|
271
|
+
others.set(`p${i}`, `p${i}`);
|
|
272
|
+
});
|
|
273
|
+
hookLayer.state(scene, { hubPlace: { id: 'main' }, hubAv, hubAv2 }, null);
|
|
274
|
+
wear.forEach((_, i) => place(`p${i}`, D + 2 + 2 * i));
|
|
275
|
+
const first = new Map([...system.avatars.actors]);
|
|
276
|
+
// The next message decides.
|
|
277
|
+
hookLayer.state(scene, { t: 1 }, system);
|
|
278
|
+
assert.deepEqual(ids(State.hub.avatarStandIns), ['p1', 'p2', 'p3', 'p4']);
|
|
279
|
+
// Their bodies are gone and respawn as the stand-in; the nearest kept theirs.
|
|
280
|
+
for (const playerId of ['p1', 'p2', 'p3', 'p4']) {
|
|
281
|
+
const i = Number(playerId.slice(1));
|
|
282
|
+
assert.equal(system.avatars.actors.has(playerId), false, playerId);
|
|
283
|
+
assert.equal(actors.has(first.get(playerId)), false, playerId);
|
|
284
|
+
place(playerId, D + 2 + 2 * i);
|
|
285
|
+
assert.equal(drawnAs(playerId), wear[i] % 4, playerId);
|
|
286
|
+
assert.equal(AvatarCap.shown(playerId), wear[i] % 4);
|
|
287
|
+
}
|
|
288
|
+
assert.equal(system.avatars.actors.get('p0'), first.get('p0'));
|
|
289
|
+
assert.equal(drawnAs('p0'), 5);
|
|
290
|
+
// What the wire says is unchanged.
|
|
291
|
+
assert.equal(State.hub.avatars.get('p4'), 10);
|
|
292
|
+
// p4 walks up to the local player; p0 walks away. Nothing changes within a
|
|
293
|
+
// quarter second (the next decision).
|
|
294
|
+
const move = (playerId, x) => {
|
|
295
|
+
scene.getActor(system.avatars.actors.get(playerId)).components.Transform.x = x;
|
|
296
|
+
};
|
|
297
|
+
move('p4', 1);
|
|
298
|
+
move('p0', D + 30);
|
|
299
|
+
hookLayer.state(scene, { t: 2 }, system);
|
|
300
|
+
assert.deepEqual(ids(State.hub.avatarStandIns), ['p1', 'p2', 'p3', 'p4']);
|
|
301
|
+
const realNow = performance.now;
|
|
302
|
+
const later = realNow.call(performance) + HOLD_MS + 500;
|
|
303
|
+
performance.now = () => later;
|
|
304
|
+
try {
|
|
305
|
+
hookLayer.state(scene, { t: 3 }, system);
|
|
306
|
+
} finally {
|
|
307
|
+
performance.now = realNow;
|
|
308
|
+
}
|
|
309
|
+
// p4 is drawn as Bolt, and with nobody needing a 2 any more, p3 as Hop:
|
|
310
|
+
// 4, 10, 6 and the 1 of the others, four in all.
|
|
311
|
+
assert.deepEqual(ids(State.hub.avatarStandIns), ['p0', 'p1', 'p2']);
|
|
312
|
+
place('p4', 1);
|
|
313
|
+
place('p0', D + 30);
|
|
314
|
+
place('p3', D + 8);
|
|
315
|
+
assert.equal(drawnAs('p4'), 10);
|
|
316
|
+
assert.equal(drawnAs('p0'), 1);
|
|
317
|
+
assert.equal(drawnAs('p3'), 6);
|
|
318
|
+
// A stand-in fading out (they left) when the cap lets them go is taken
|
|
319
|
+
// down, as an avatar change does, so they cannot come back as the stand-in.
|
|
320
|
+
Avatars.retire(system.avatars, scene, 'p2');
|
|
321
|
+
const fading = system.avatars.leaving.get('p2').actorId;
|
|
322
|
+
AvatarCap.setCapEnv({ location: { search: '?hubAvDistinct=99' } });
|
|
323
|
+
performance.now = () => later + HOLD_MS + 500;
|
|
324
|
+
try {
|
|
325
|
+
hookLayer.state(scene, { t: 4 }, system);
|
|
326
|
+
} finally {
|
|
327
|
+
performance.now = realNow;
|
|
328
|
+
}
|
|
329
|
+
assert.equal(State.hub.avatarStandIns.size, 0);
|
|
330
|
+
assert.equal(actors.has(fading), false);
|
|
331
|
+
assert.equal(system.avatars.retired.has(fading), true);
|
|
332
|
+
assert.equal(system.avatars.leaving.has('p2'), false);
|
|
333
|
+
AvatarCap.setCapEnv(null);
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
test('colour capping redraws a body as the same character without colour, then restores it nearby', () => {
|
|
337
|
+
Avatar.resetPlatformForTests(null);
|
|
338
|
+
Avatar.resetStyleForTests({ experiment: () => 'toon' });
|
|
339
|
+
AvatarCap.setCapEnv({ location: { search: '?hubAvDistinct=2' } });
|
|
340
|
+
const { scene, system, others, place, actors } = client();
|
|
341
|
+
scene.files['imports/castle.hub-game/blueprints/avatar-4.scene'] = JSON.stringify({ actors: [{ components: { Model: { file: 'models/avatar-4.pxmodel' } } }] });
|
|
342
|
+
scene.files['imports/castle.hub-game/models/avatar-4.pxmodel'] = JSON.stringify({ parts: [{ id: 'torso', color: '#aaa' }] });
|
|
343
|
+
others.set('a', 'a');
|
|
344
|
+
others.set('b', 'b');
|
|
345
|
+
hookLayer.state(scene, { hubPlace: { id: 'main' }, hubAv: { a: 0, b: 0 }, hubAv2: { a: 4, b: 4 }, hubAvC: { a: 1, b: 2 } }, null);
|
|
346
|
+
place('a', D);
|
|
347
|
+
const before = place('b', D + 1);
|
|
348
|
+
const realNow = performance.now;
|
|
349
|
+
performance.now = () => 1000;
|
|
350
|
+
try {
|
|
351
|
+
hookLayer.state(scene, { t: 1 }, system);
|
|
352
|
+
assert.deepEqual(ids(State.hub.avatarColorStandIns), ['b']);
|
|
353
|
+
assert.deepEqual(ids(State.hub.avatarStandIns), []);
|
|
354
|
+
assert.equal(actors.has(before.id), false);
|
|
355
|
+
assert.equal(AvatarCap.shown('b'), 4);
|
|
356
|
+
assert.equal(AvatarCap.shownColor('b'), 0);
|
|
357
|
+
const plain = place('b', D + 1);
|
|
358
|
+
assert.equal(plain.blueprint, 'imports/castle.hub-game/blueprints/avatar-4.scene');
|
|
359
|
+
plain.components.Transform.x = 1;
|
|
360
|
+
performance.now = () => 1000 + AvatarCap.EVERY_MS;
|
|
361
|
+
hookLayer.state(scene, { t: 2 }, system);
|
|
362
|
+
assert.equal(AvatarCap.shownColor('b'), 2);
|
|
363
|
+
assert.equal(actors.has(plain.id), false);
|
|
364
|
+
assert.equal(place('b', 1).blueprint, 'imports/castle.hub-game/.colors/avatar-4-c2.scene');
|
|
365
|
+
} finally {
|
|
366
|
+
performance.now = realNow;
|
|
367
|
+
AvatarCap.setCapEnv(null);
|
|
368
|
+
Avatar.resetStyleForTests(undefined);
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
test('without the local player or the bodies, nothing is decided', () => {
|
|
373
|
+
const { system } = client();
|
|
374
|
+
assert.deepEqual(AvatarCap.frame({}, system, 1e9), []);
|
|
375
|
+
assert.deepEqual(AvatarCap.frame({ actorWith: () => null }, null, 1e9), []);
|
|
376
|
+
assert.equal(Avatar.DEFAULT_AVATARS, 4);
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
console.log(`hub-game avatar cap: ${n} tests passed`);
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { register } from 'node:module';
|
|
4
|
+
import { AVATAR_COLORS, COLORS, known, recolored } from '../code/client/avatarColors.js';
|
|
5
|
+
|
|
6
|
+
register('data:text/javascript,' + encodeURIComponent(`
|
|
7
|
+
export async function resolve(specifier, context, next) {
|
|
8
|
+
if (specifier === 'castle-web-sdk') {
|
|
9
|
+
return { url: ${JSON.stringify(new URL('./fixtures/sdk-stub.mjs', import.meta.url).href)}, shortCircuit: true };
|
|
10
|
+
}
|
|
11
|
+
return next(specifier, context);
|
|
12
|
+
}
|
|
13
|
+
`));
|
|
14
|
+
const Avatar = await import('../code/client/avatar.js');
|
|
15
|
+
assert.equal(COLORS, 6);
|
|
16
|
+
assert.equal(AVATAR_COLORS.length, 16);
|
|
17
|
+
for (let i = 0; i < 16; i += 1) {
|
|
18
|
+
const text = await readFile(new URL(`../models/avatar-${i}.pxmodel`, import.meta.url), 'utf8');
|
|
19
|
+
const model = JSON.parse(text);
|
|
20
|
+
const palette = AVATAR_COLORS[i];
|
|
21
|
+
const ids = [...palette.main, ...(palette.shade ?? [])];
|
|
22
|
+
for (const id of ids) {
|
|
23
|
+
assert.ok(model.parts.some((part) => part.id === id), `${i}: missing ${id}`);
|
|
24
|
+
}
|
|
25
|
+
assert.equal(recolored(text, i, 0), text);
|
|
26
|
+
for (const bad of [undefined, null, '1', 1.5, -1, COLORS, 16, NaN, Infinity]) {
|
|
27
|
+
assert.equal(known(i, bad), 0);
|
|
28
|
+
assert.equal(recolored(text, i, bad), text);
|
|
29
|
+
}
|
|
30
|
+
for (let c = 1; c < COLORS; c += 1) {
|
|
31
|
+
assert.equal(known(i, c), c);
|
|
32
|
+
const colored = JSON.parse(recolored(text, i, c));
|
|
33
|
+
colored.parts.forEach((part, at) => {
|
|
34
|
+
const before = model.parts[at];
|
|
35
|
+
const [main, shade = main] = palette.colors[c - 1];
|
|
36
|
+
if (palette.main.includes(part.id)) {
|
|
37
|
+
assert.equal(part.color, main);
|
|
38
|
+
} else if (palette.shade?.includes(part.id)) {
|
|
39
|
+
assert.equal(part.color, shade);
|
|
40
|
+
} else {
|
|
41
|
+
assert.deepEqual(part, before, `${i}: ${part.id} (faces included) stays unchanged`);
|
|
42
|
+
}
|
|
43
|
+
assert.deepEqual({ ...part, color: before.color }, before, 'only colour changes');
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
for (const root of ['', 'imports/castle.hub-game/']) {
|
|
47
|
+
const blueprint = `${root}blueprints/avatar-${i}.scene`;
|
|
48
|
+
const file = `${root}models/avatar-${i}.pxmodel`;
|
|
49
|
+
const source = await readFile(new URL(`../blueprints/avatar-${i}.scene`, import.meta.url), 'utf8');
|
|
50
|
+
const files = { [blueprint]: source, [file]: text };
|
|
51
|
+
const original = { ...files };
|
|
52
|
+
assert.equal(Avatar.blueprint(files, i, 'toon', 0), blueprint);
|
|
53
|
+
assert.deepEqual(files, original, 'colour zero creates nothing');
|
|
54
|
+
const path = Avatar.blueprint(files, i, 'toon', 2);
|
|
55
|
+
const colored = `${root}.colors/avatar-${i}-c2.pxmodel`;
|
|
56
|
+
assert.equal(path, `${root}.colors/avatar-${i}-c2.scene`);
|
|
57
|
+
assert.equal(Avatar.model(files, i, 'toon', 2), colored);
|
|
58
|
+
assert.equal(files[colored], recolored(text, i, 2));
|
|
59
|
+
assert.equal(Avatar.blueprint(files, i, 'toon', 2), path);
|
|
60
|
+
assert.equal(Object.keys(files).length, 4, 'the variant is cached');
|
|
61
|
+
assert.equal(files[blueprint], source);
|
|
62
|
+
assert.equal(files[file], text);
|
|
63
|
+
assert.equal(Avatar.blueprint(files, i, 'bean', 2), blueprint, 'other styles keep today’s path even when falling back to toon');
|
|
64
|
+
const missing = { [blueprint]: source };
|
|
65
|
+
assert.equal(Avatar.blueprint(missing, i, 'toon', 2), blueprint);
|
|
66
|
+
assert.deepEqual(missing, { [blueprint]: source });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
for (const i of [-1, 16, 255, 0.5]) {
|
|
70
|
+
assert.equal(known(i, 1), 0);
|
|
71
|
+
}
|
|
72
|
+
console.log('hub-game avatar colours: palettes, untouched faces, paths and cache passed');
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// The toon avatars' models (contract §11, scripts/gen-avatars.mjs): the files
|
|
2
|
+
// in models/ and code/client/avatarFaces.js are the generator's output, every
|
|
3
|
+
// model keeps what the kit and the phone budget depend on, and each costs what
|
|
4
|
+
// the generator's header says it may: at most 1,500 triangles with the outline
|
|
5
|
+
// pass and 8 draw calls, counted by the engine's own `modelCost` over the
|
|
6
|
+
// model built as a game builds it (castle.physics-3d `engine3d/optimize.js`).
|
|
7
|
+
// The engine is the checkout's kits/physics-3d, or this kit's import of it.
|
|
8
|
+
// `npm run check` runs this.
|
|
9
|
+
|
|
10
|
+
import assert from 'node:assert/strict';
|
|
11
|
+
import { execFileSync } from 'node:child_process';
|
|
12
|
+
import fs from 'node:fs';
|
|
13
|
+
import { register } from 'node:module';
|
|
14
|
+
import os from 'node:os';
|
|
15
|
+
import path from 'node:path';
|
|
16
|
+
import { fileURLToPath } from 'node:url';
|
|
17
|
+
|
|
18
|
+
const KIT = fileURLToPath(new URL('..', import.meta.url));
|
|
19
|
+
const ENGINES = [
|
|
20
|
+
{ engine: path.join(KIT, '..', 'physics-3d'), art: path.join(KIT, '..', 'physics-2d') },
|
|
21
|
+
{ engine: path.join(KIT, 'imports', 'castle.physics-3d'), art: path.join(KIT, 'imports', 'castle.physics-2d') },
|
|
22
|
+
];
|
|
23
|
+
const found = ENGINES.find(({ engine }) => fs.existsSync(path.join(engine, 'engine3d', 'pxmodel.js')));
|
|
24
|
+
|
|
25
|
+
// The engine's modules are written for the bundler: imports without
|
|
26
|
+
// extensions, and the 2d kit by its alias. The SDK is stubbed for avatar.js.
|
|
27
|
+
register(
|
|
28
|
+
'data:text/javascript,' +
|
|
29
|
+
encodeURIComponent(`
|
|
30
|
+
import { existsSync } from 'node:fs';
|
|
31
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
32
|
+
const ART = ${JSON.stringify(found ? found.art : '')};
|
|
33
|
+
export async function resolve(specifier, context, next) {
|
|
34
|
+
if (specifier === 'castle-web-sdk') {
|
|
35
|
+
return { url: ${JSON.stringify(new URL('./fixtures/sdk-stub.mjs', import.meta.url).href)}, shortCircuit: true };
|
|
36
|
+
}
|
|
37
|
+
const parent = context.parentURL ?? '';
|
|
38
|
+
if (specifier.startsWith('@imports/castle.physics-2d/')) {
|
|
39
|
+
specifier = pathToFileURL(ART + '/' + specifier.slice(27)).href;
|
|
40
|
+
}
|
|
41
|
+
if ((specifier.startsWith('.') || specifier.startsWith('file:')) && parent.startsWith('file:') && !/\\.(m?js|jsx|json)$/.test(specifier)) {
|
|
42
|
+
const base = new URL(specifier, parent).href;
|
|
43
|
+
for (const ext of ['.js', '.jsx']) {
|
|
44
|
+
if (existsSync(fileURLToPath(base + ext))) {
|
|
45
|
+
return next(base + ext, context);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return next(specifier, context);
|
|
50
|
+
}`),
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const Avatar = await import('../code/client/avatar.js');
|
|
54
|
+
const { AVATAR_FACES } = await import('../code/client/avatarFaces.js');
|
|
55
|
+
|
|
56
|
+
let n = 0;
|
|
57
|
+
async function test(name, fn) {
|
|
58
|
+
await fn();
|
|
59
|
+
n += 1;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const NAMES = ['Castle', 'Petal', 'Beat', 'Star', 'Biscuit', 'Mochi', 'Hop', 'Pip', 'Ribbit', 'Ember', 'Bolt', 'Gloop', 'Cap', 'Toast', 'Scoop', 'Zest'];
|
|
63
|
+
const TRIANGLES = 1500;
|
|
64
|
+
const DRAW_CALLS = 8;
|
|
65
|
+
const ANCHORS = ['torso', 'head', 'legL', 'legR', 'armL', 'armR'];
|
|
66
|
+
const modelPath = (i) => path.join(KIT, 'models', `avatar-${i}.pxmodel`);
|
|
67
|
+
const models = NAMES.map((_, i) => JSON.parse(fs.readFileSync(modelPath(i), 'utf8')));
|
|
68
|
+
|
|
69
|
+
await test('the models and the faces are what the generator writes', () => {
|
|
70
|
+
const out = fs.mkdtempSync(path.join(os.tmpdir(), 'hub-avatars-'));
|
|
71
|
+
try {
|
|
72
|
+
execFileSync(process.execPath, [path.join(KIT, 'scripts', 'gen-avatars.mjs'), out], { stdio: 'pipe' });
|
|
73
|
+
assert.deepEqual(fs.readdirSync(out).sort(), [...NAMES.map((_, i) => `avatar-${i}.pxmodel`), 'avatarFaces.js'].sort());
|
|
74
|
+
for (let i = 0; i < NAMES.length; i += 1) {
|
|
75
|
+
assert.equal(fs.readFileSync(path.join(out, `avatar-${i}.pxmodel`), 'utf8'), fs.readFileSync(modelPath(i), 'utf8'), `models/avatar-${i}.pxmodel is not the generator's output: run node scripts/gen-avatars.mjs`);
|
|
76
|
+
}
|
|
77
|
+
assert.equal(fs.readFileSync(path.join(out, 'avatarFaces.js'), 'utf8'), fs.readFileSync(path.join(KIT, 'code', 'client', 'avatarFaces.js'), 'utf8'), "code/client/avatarFaces.js is not the generator's output");
|
|
78
|
+
} finally {
|
|
79
|
+
fs.rmSync(out, { recursive: true, force: true });
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
await test('sixteen characters, each with a name and a face of its own', () => {
|
|
84
|
+
assert.equal(Avatar.AVATARS, NAMES.length);
|
|
85
|
+
assert.equal(models.length, Avatar.AVATARS);
|
|
86
|
+
assert.deepEqual(models.map((model) => model.name), NAMES);
|
|
87
|
+
assert.deepEqual(AVATAR_FACES.map(([name]) => name), NAMES);
|
|
88
|
+
assert.equal(new Set(AVATAR_FACES.map(([, face]) => face)).size, NAMES.length);
|
|
89
|
+
for (const [name, face] of AVATAR_FACES) {
|
|
90
|
+
// The inside of an SVG and nothing else: shapes, no script, no link, no text.
|
|
91
|
+
assert.match(face, /^(<(circle|ellipse|path|rect|g)( [a-z-]+="[#\w .,-]*")*\/?>|<\/g>)+$/, name);
|
|
92
|
+
assert.ok(!/href|url\(|on[a-z]+=|<script|style=/i.test(face), name);
|
|
93
|
+
assert.ok(face.length < 700, `${name}: ${face.length} bytes`);
|
|
94
|
+
}
|
|
95
|
+
// No file for a seventeenth.
|
|
96
|
+
assert.equal(fs.existsSync(modelPath(NAMES.length)), false);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
await test('every model keeps the parts, the pivots and the flat look the kit depends on', () => {
|
|
100
|
+
models.forEach((model, i) => {
|
|
101
|
+
const where = `avatar-${i} (${model.name})`;
|
|
102
|
+
assert.equal(model.format, 'pxmodel', where);
|
|
103
|
+
assert.equal(model.triangles, TRIANGLES, where);
|
|
104
|
+
const byId = new Map(model.parts.map((part) => [part.id, part]));
|
|
105
|
+
assert.equal(byId.size, model.parts.length, `${where}: a part id is used twice`);
|
|
106
|
+
for (const id of ANCHORS) {
|
|
107
|
+
assert.ok(byId.has(id), `${where} has no ${id}`);
|
|
108
|
+
}
|
|
109
|
+
// Head and arms hang from the torso; the torso and the legs from nothing.
|
|
110
|
+
for (const id of ['head', 'armL', 'armR']) {
|
|
111
|
+
assert.equal(byId.get(id).parent, 'torso', `${where}: ${id}`);
|
|
112
|
+
}
|
|
113
|
+
for (const id of ['torso', 'legL', 'legR']) {
|
|
114
|
+
assert.equal(byId.get(id).parent ?? '', '', `${where}: ${id}`);
|
|
115
|
+
}
|
|
116
|
+
const anchorOf = (part) => {
|
|
117
|
+
let at = part;
|
|
118
|
+
while (!ANCHORS.includes(at.id)) {
|
|
119
|
+
at = byId.get(at.parent);
|
|
120
|
+
assert.ok(at, `${where}: ${part.id} hangs from nothing`);
|
|
121
|
+
}
|
|
122
|
+
return at.id;
|
|
123
|
+
};
|
|
124
|
+
// The ink line, on the torso and the head only: an outline on a limb is a
|
|
125
|
+
// draw call more.
|
|
126
|
+
assert.ok(model.look.outline > 0 && model.look.rim === 0, where);
|
|
127
|
+
for (const part of model.parts) {
|
|
128
|
+
const anchor = anchorOf(part);
|
|
129
|
+
const limb = anchor !== 'torso' && anchor !== 'head';
|
|
130
|
+
assert.deepEqual(part.look ?? null, limb ? { outline: 0 } : null, `${where}: ${part.id} look`);
|
|
131
|
+
// Flat colours: no textures, no glow, nothing see-through.
|
|
132
|
+
for (const key of ['art', 'tint', 'emissive', 'emissiveIntensity', 'opacity', 'paint', 'material', 'keep']) {
|
|
133
|
+
assert.equal(key in part, false, `${where}: ${part.id} has ${key}`);
|
|
134
|
+
}
|
|
135
|
+
assert.match(part.color, /^#[0-9a-f]{6}$/, `${where}: ${part.id}`);
|
|
136
|
+
// Names the engine moves by itself, each in a batch of its own.
|
|
137
|
+
assert.ok(!['tail', 'wingL', 'wingR', 'legFL', 'legFR', 'legBL', 'legBR'].includes(part.id), `${where}: ${part.id}`);
|
|
138
|
+
// One batch draws one side or both.
|
|
139
|
+
if (part.kind !== 'lathe' && part.kind !== 'extrude') {
|
|
140
|
+
const both = model.parts.some((other) => anchorOf(other) === anchor && (other.kind === 'lathe' || other.kind === 'extrude'));
|
|
141
|
+
assert.equal(part.doubleSided === true, both, `${where}: ${part.id} sides`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
await test('every model is at most 1,500 triangles with its outline and 8 draw calls, stands on y = 0 and is as tall as avatar.js says', async () => {
|
|
148
|
+
if (!found) {
|
|
149
|
+
// A kit unpacked without its imports and outside the repo has no engine to count with.
|
|
150
|
+
console.log('hub-game avatar models: NOT COUNTED, no castle.physics-3d engine beside this kit or in its imports');
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const { buildModelNode, parseModel, visibleBounds } = await import(path.join(found.engine, 'engine3d', 'pxmodel.js'));
|
|
154
|
+
const { modelCost } = await import(path.join(found.engine, 'engine3d', 'optimize.js'));
|
|
155
|
+
const rows = [];
|
|
156
|
+
for (let i = 0; i < NAMES.length; i += 1) {
|
|
157
|
+
const where = `avatar-${i} (${NAMES[i]})`;
|
|
158
|
+
const file = `models/avatar-${i}.pxmodel`;
|
|
159
|
+
const text = fs.readFileSync(modelPath(i), 'utf8');
|
|
160
|
+
const node = buildModelNode(parseModel(text), {}, {}, file, [file], { optimize: true });
|
|
161
|
+
node.updateMatrixWorld(true);
|
|
162
|
+
const cost = modelCost(node);
|
|
163
|
+
const triangles = cost.triangles + cost.outlineTriangles;
|
|
164
|
+
assert.ok(triangles <= TRIANGLES, `${where}: ${triangles} triangles (${cost.triangles} and ${cost.outlineTriangles} of outline)`);
|
|
165
|
+
// Six batches (torso, head, two legs, two arms) and an outline on two.
|
|
166
|
+
assert.equal(cost.drawCalls, DRAW_CALLS, `${where}: ${cost.drawCalls} draw calls`);
|
|
167
|
+
// Nothing was built coarser to fit: the model is what the generator drew.
|
|
168
|
+
const roomy = buildModelNode({ ...parseModel(text), triangles: 100000 }, {}, {}, file, [file], { optimize: true });
|
|
169
|
+
assert.equal(modelCost(roomy).triangles, cost.triangles, `${where}: coarsened to fit its budget`);
|
|
170
|
+
const bounds = visibleBounds(node);
|
|
171
|
+
assert.ok(Math.abs(bounds.min.y) < 0.01, `${where}: feet at ${bounds.min.y}`);
|
|
172
|
+
assert.ok(Math.abs(bounds.max.y - Avatar.top(i, 'toon')) <= 0.01, `${where}: stands ${bounds.max.y.toFixed(3)}, avatar.js says ${Avatar.top(i, 'toon')}`);
|
|
173
|
+
// A hat's seat is on the model, under its top, and a hat on it stays under the name tag.
|
|
174
|
+
const [seat, , rise] = Avatar.hatFit(i, 'toon');
|
|
175
|
+
assert.ok(seat + rise <= bounds.max.y + 0.01, `${where}: the crown is over the model`);
|
|
176
|
+
rows.push(`${i} ${NAMES[i]} ${triangles}/${cost.drawCalls}`);
|
|
177
|
+
}
|
|
178
|
+
console.log(`hub-game avatar models: triangles/draw calls ${rows.join(', ')}`);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
console.log(`hub-game avatar models: ${n} tests passed`);
|