@craft_eco/craft-mcp 0.1.18 → 0.1.21

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.
Files changed (886) hide show
  1. package/README.md +45 -8
  2. package/bin/craft-mcp.mjs +14 -1
  3. package/dist-server/core/connector-auth.mjs +3 -3
  4. package/dist-server/game-workflow/asset-formats.mjs +25 -64
  5. package/dist-server/game-workflow/asset-import.mjs +83 -67
  6. package/dist-server/game-workflow/assets.mjs +81 -9
  7. package/dist-server/game-workflow/capture-worker.mjs +1 -1
  8. package/dist-server/game-workflow/check.mjs +1 -1
  9. package/dist-server/game-workflow/draft-archive.mjs +53 -53
  10. package/dist-server/game-workflow/draft-bindings.mjs +35 -35
  11. package/dist-server/game-workflow/draft-uploads.mjs +207 -207
  12. package/dist-server/game-workflow/engines.mjs +2 -2
  13. package/dist-server/game-workflow/library-assets.mjs +16 -5
  14. package/dist-server/game-workflow/library-candidates.mjs +2 -1
  15. package/dist-server/game-workflow/library-catalog.mjs +2 -2
  16. package/dist-server/game-workflow/publication-materials.mjs +67 -67
  17. package/dist-server/game-workflow/publications.mjs +148 -148
  18. package/dist-server/game-workflow/publish-capture-worker.mjs +57 -57
  19. package/dist-server/game-workflow/publish-capture.mjs +75 -75
  20. package/dist-server/game-workflow/resource-catalog.mjs +16 -13
  21. package/dist-server/mcp/control-panel.html +2 -2
  22. package/dist-server/mcp/control-panel.mjs +59 -59
  23. package/dist-server/mcp/publication-page.html +85 -86
  24. package/dist-server/mcp/publication-page.mjs +346 -347
  25. package/dist-server/mcp/publication-preview.mjs +62 -48
  26. package/dist-server/mcp/publication-tools.mjs +22 -22
  27. package/dist-server/mcp/publish-panel.mjs +191 -191
  28. package/dist-server/mcp/server.mjs +312 -312
  29. package/dist-server/upstream/craft-aigc.mjs +182 -169
  30. package/dist-server/upstream/library-url.mjs +3 -5
  31. package/dist-server/upstream/publication-transport.mjs +81 -81
  32. package/dist-server/upstream/resource-path.mjs +17 -0
  33. package/package.json +2 -2
  34. package/resources/craft-game-maker/SKILL.md +71 -69
  35. package/resources/craft-game-maker/js.md +6 -5
  36. package/resources/craft-game-maker/js3d.md +6 -5
  37. package/resources/game_visual_qa.mjs +9 -3
  38. package/resources/js/context/.role/AGENTS_DESIGN.md +9 -0
  39. package/resources/js/context/AGENTS.md +112 -0
  40. package/resources/js/context/agents/aigc-asset.md +168 -0
  41. package/resources/js/context/hooks/hooks.json +14 -20
  42. package/resources/js/context/knowledge/AigcEnabled.md +49 -41
  43. package/resources/js/context/knowledge/AigcWiring.md +200 -200
  44. package/resources/js/context/knowledge/AssetUrl.md +24 -24
  45. package/resources/js/context/knowledge/FrontendComponents.md +17 -23
  46. package/resources/js/context/knowledge/Lifecycle.md +32 -27
  47. package/resources/js/context/knowledge/MobileAdaptation.md +73 -0
  48. package/resources/js/context/knowledge/MobileAdapted.md +36 -0
  49. package/resources/js/context/knowledge/Multiplayer/GameplaySystemKnowledge.md +114 -114
  50. package/resources/js/context/knowledge/Multiplayer/OverviewKnowledge.md +115 -115
  51. package/resources/js/context/knowledge/Multiplayer/StateSyncKnowledge.md +392 -392
  52. package/resources/js/context/knowledge/PlatformServices.md +190 -184
  53. package/resources/js/context/knowledge/ProjectDisplayConfig.md +35 -0
  54. package/resources/js/context/knowledge/Subsystems/Optional/MultiplayerManagerKnowledge.md +242 -242
  55. package/resources/js/context/knowledge/Ui.md +11 -11
  56. package/resources/js/context/knowledge/UiEditorCompat.md +21 -21
  57. package/resources/js/context/rules/MultiplayerCapability.md +23 -23
  58. package/resources/js/context/rules/MultiplayerRoomEntryUX.md +63 -63
  59. package/resources/js/context/rules/PlatformBoundaryModules.md +44 -43
  60. package/resources/js/context/rules/preview_ready.md +8 -0
  61. package/resources/js/context/skills/aigc-generate/SKILL.md +149 -301
  62. package/resources/js/context/skills/aigc-generate/knowledge/audio.md +39 -39
  63. package/resources/js/context/skills/aigc-generate/knowledge/batch-replace.md +26 -14
  64. package/resources/js/context/skills/aigc-generate/knowledge/character2d.md +132 -129
  65. package/resources/js/context/skills/aigc-generate/knowledge/non-stepwise-aigc.md +53 -54
  66. package/resources/js/context/skills/aigc-generate/knowledge/texture-prop.md +52 -50
  67. package/resources/js/context/skills/aigc-generate/knowledge/texture-scene.md +191 -201
  68. package/resources/js/context/skills/aigc-generate/knowledge/texture-ui.md +55 -53
  69. package/resources/js/context/skills/asset-search/SKILL.md +69 -73
  70. package/resources/js/context/skills/asset-search/scripts/asset_display.mjs +62 -62
  71. package/resources/js/context/skills/asset-search/scripts/config.json +5 -5
  72. package/resources/js/context/skills/asset-search/scripts/provided_assets.mjs +125 -125
  73. package/resources/js/context/skills/asset-search/scripts/search.mjs +760 -749
  74. package/resources/js/context/skills/asset-search/scripts/sprite_source_materializer.mjs +657 -723
  75. package/resources/js/context/skills/asset-search/strategies/anim2d.md +42 -0
  76. package/resources/js/context/skills/asset-search/strategies/audio.md +34 -34
  77. package/resources/js/context/skills/asset-search/strategies/effect2d.md +31 -31
  78. package/resources/js/context/skills/asset-search/strategies/texture-prop.md +22 -22
  79. package/resources/js/context/skills/asset-search/strategies/ui-common.md +40 -40
  80. package/resources/js/context/skills/asset-search/strategies/ui-style.md +28 -28
  81. package/resources/js/context/skills/export-config/SKILL.md +28 -20
  82. package/resources/js/context/skills/export-config/assets/tooling/cli.mjs +20 -0
  83. package/resources/js/context/skills/{lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/platform → export-config/assets/tooling}/config.d.mts +19 -19
  84. package/resources/js/context/skills/{lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/platform → export-config/assets/tooling}/config.mjs +1 -1
  85. package/resources/js/context/skills/export-config/assets/tooling/project.d.mts +6 -0
  86. package/resources/js/context/skills/export-config/assets/tooling/project.mjs +77 -0
  87. package/resources/js/context/skills/export-config/assets/tooling/vite.d.mts +2 -0
  88. package/resources/js/context/skills/export-config/assets/tooling/vite.mjs +34 -0
  89. package/resources/js/context/skills/export-config/scripts/assert-asset-wiring.mjs +72 -72
  90. package/resources/js/context/skills/export-config/scripts/export-config.mjs +46 -43
  91. package/resources/js/context/skills/export-config/scripts/install.mjs +89 -0
  92. package/resources/js/context/skills/export-config/scripts/panel-resource-path.mjs +106 -106
  93. package/resources/js/context/skills/export-config/scripts/sync-asset-controls.mjs +352 -351
  94. package/resources/js/context/skills/export-config/scripts/translate-asset-titles.mjs +161 -163
  95. package/resources/js/context/skills/lightgame-runtime-adapt/SKILL.md +93 -92
  96. package/resources/js/context/skills/lightgame-runtime-adapt/project/game-runtime.json +7 -7
  97. package/resources/js/context/skills/lightgame-runtime-adapt/project/package.json +22 -22
  98. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.1.0/platform/identity/qq-ai-game-sdk.min.js +5 -0
  99. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.1.0/platform/identity/qq-session.mjs +208 -0
  100. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.1.0/platform/identity/shared.mjs +37 -0
  101. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/{1.0.0 → 1.1.0}/platform/platform-capture-video.mjs +227 -227
  102. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/{1.0.0 → 1.1.0}/platform/platform-service.d.mts +31 -25
  103. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.1.0/platform/platform-service.mjs +272 -0
  104. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/{1.0.0 → 1.1.0}/platform/platform.d.mts +79 -79
  105. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/{1.0.0 → 1.1.0}/platform/platform.mjs +29 -29
  106. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.1.0/release.json +22 -0
  107. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.1.0/tooling/cli.mjs +16 -0
  108. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.1.0/tooling/project.d.mts +4 -0
  109. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.1.0/tooling/project.mjs +50 -0
  110. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.1.0/tooling/vite.d.mts +3 -0
  111. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.1.0/tooling/vite.mjs +72 -0
  112. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/{1.0.0 → 1.1.0}/tools/assets.d.mts +24 -24
  113. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/{1.0.0 → 1.1.0}/tools/assets.mjs +2 -2
  114. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/{1.0.0 → 1.1.0}/tools/astc.d.mts +10 -10
  115. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/{1.0.0 → 1.1.0}/tools/astc.mjs +1 -1
  116. package/resources/js/context/skills/lightgame-runtime-adapt/project/scripts/config-export.mjs +37 -32
  117. package/resources/js/context/skills/lightgame-runtime-adapt/project/scripts/refresh-runtime.mjs +50 -50
  118. package/resources/js/context/skills/lightgame-runtime-adapt/project/scripts/skill-modules/export-config/cli.mjs +20 -0
  119. package/resources/js/context/skills/lightgame-runtime-adapt/project/scripts/skill-modules/export-config/config.d.mts +19 -0
  120. package/resources/js/context/skills/lightgame-runtime-adapt/project/scripts/skill-modules/export-config/config.mjs +1 -0
  121. package/resources/js/context/skills/lightgame-runtime-adapt/project/scripts/skill-modules/export-config/installed.json +6 -0
  122. package/resources/js/context/skills/lightgame-runtime-adapt/project/scripts/skill-modules/export-config/project.d.mts +6 -0
  123. package/resources/js/context/skills/lightgame-runtime-adapt/project/scripts/skill-modules/export-config/project.mjs +77 -0
  124. package/resources/js/context/skills/lightgame-runtime-adapt/project/scripts/skill-modules/export-config/vite.d.mts +2 -0
  125. package/resources/js/context/skills/lightgame-runtime-adapt/project/scripts/skill-modules/export-config/vite.mjs +34 -0
  126. package/resources/js/context/skills/lightgame-runtime-adapt/project/src/display/ui-stage.ts +156 -121
  127. package/resources/js/context/skills/lightgame-runtime-adapt/project/src/display/viewport.ts +249 -254
  128. package/resources/js/context/skills/lightgame-runtime-adapt/project/src/main.ts +87 -99
  129. package/resources/js/context/skills/lightgame-runtime-adapt/project/src/platform.ts +2 -14
  130. package/resources/js/context/skills/lightgame-runtime-adapt/project/src/screenUi.ts +185 -172
  131. package/resources/js/context/skills/lightgame-runtime-adapt/project/src/style.css +294 -165
  132. package/resources/js/context/skills/lightgame-runtime-adapt/project/tsconfig.json +20 -20
  133. package/resources/js/context/skills/lightgame-runtime-adapt/project/vite.config.ts +5 -4
  134. package/resources/js/context/skills/lightgame-runtime-adapt/scripts/install-template.mjs +159 -109
  135. package/resources/js/context/skills/mobile-adaptation/SKILL.md +277 -260
  136. package/resources/js/context/skills/mobile-adaptation/assets/example/src/input/input-config.json +50 -50
  137. package/resources/js/context/skills/mobile-adaptation/assets/example/src/input/input-layer.ts +862 -881
  138. package/resources/js/context/skills/mobile-adaptation/assets/example/src/input/input-platform.ts +92 -92
  139. package/resources/js/context/skills/mobile-adaptation/assets/example/src/input/input-primitives.ts +254 -0
  140. package/resources/js/context/skills/mobile-adaptation/assets/example/src/input/look-pad.ts +245 -245
  141. package/resources/js/context/skills/mobile-adaptation/assets/example/src/ui/touch-controls.css +135 -134
  142. package/resources/js/context/skills/mobile-adaptation/references/input-config.md +342 -311
  143. package/resources/js/context/skills/mobile-adaptation/references/verification.md +140 -106
  144. package/resources/js/context/skills/mobile-adaptation/references/web-audio.md +11 -0
  145. package/resources/js/context/skills/mobile-compat-qa/SKILL.md +53 -0
  146. package/resources/js/context/skills/mobile-compat-qa/references/startup-diagnosis.md +23 -0
  147. package/resources/js/context/skills/mobile-compat-qa/references/web-lifecycle.md +20 -0
  148. package/resources/js/context/skills/mobile-compat-qa/references/web-performance.md +19 -0
  149. package/resources/js/context/skills/optimization-suggestions/SKILL.md +89 -89
  150. package/resources/js/context/skills/platform-services/SKILL.md +101 -94
  151. package/resources/js/context/skills/platform-services/assets/modules/MultiplayerManager.ts +465 -783
  152. package/resources/js/context/skills/platform-services/assets/modules/eventBus.ts +57 -57
  153. package/resources/js/context/skills/platform-services/assets/modules/identity/qq-ai-game-sdk.min.js +5 -0
  154. package/resources/js/context/skills/platform-services/assets/modules/identity/qq-session.mjs +208 -0
  155. package/resources/js/context/skills/platform-services/assets/modules/identity/shared.mjs +37 -0
  156. package/resources/js/context/skills/platform-services/assets/modules/leaderboard.d.mts +39 -39
  157. package/resources/js/context/skills/platform-services/assets/modules/leaderboard.mjs +1 -1
  158. package/resources/js/context/skills/platform-services/assets/modules/log.ts +35 -35
  159. package/resources/js/context/skills/platform-services/assets/modules/multiplayer/clockSync.ts +61 -0
  160. package/resources/js/context/skills/platform-services/assets/modules/multiplayer/dsClient.ts +52 -0
  161. package/resources/js/context/skills/platform-services/assets/modules/multiplayer/payloadCodec.ts +30 -0
  162. package/resources/js/context/skills/platform-services/assets/modules/multiplayer/roomHttp.ts +89 -0
  163. package/resources/js/context/skills/platform-services/assets/modules/multiplayer/types.ts +47 -0
  164. package/resources/js/context/skills/platform-services/assets/modules/platform-service.d.mts +31 -25
  165. package/resources/js/context/skills/platform-services/assets/modules/platform-service.mjs +272 -1
  166. package/resources/js/context/skills/platform-services/assets/modules/save.d.mts +49 -49
  167. package/resources/js/context/skills/platform-services/assets/modules/save.mjs +1 -1
  168. package/resources/js/context/skills/platform-services/assets/scaffold/ds/main.mjs +7 -7
  169. package/resources/js/context/skills/platform-services/assets/scaffold/ds/rooms/SyncRoom.mjs +264 -264
  170. package/resources/js/context/skills/platform-services/assets/scaffold/ds/rooms/syncSchema.mjs +39 -39
  171. package/resources/js/context/skills/platform-services/references/SERVER_GUIDE.md +139 -139
  172. package/resources/js/context/skills/platform-services/references/api_reference.md +18 -18
  173. package/resources/js/context/skills/platform-services/references/leaderboard_playbook.md +96 -0
  174. package/resources/js/context/skills/platform-services/scripts/install.mjs +148 -134
  175. package/resources/js/context/skills/resolution-adaptation/SKILL.md +47 -202
  176. package/resources/js/context/skills/resolution-adaptation/assets/display/ui-stage.ts +156 -121
  177. package/resources/js/context/skills/resolution-adaptation/assets/display/viewport.ts +249 -254
  178. package/resources/js/context/skills/resolution-adaptation/assets/example/main.ts +98 -98
  179. package/resources/js/context/skills/resolution-adaptation/assets/example/ui-tokens.css +200 -200
  180. package/resources/js/context/skills/resolution-adaptation/references/audit.md +31 -0
  181. package/resources/js/context/skills/resolution-adaptation/references/device-safe-area.md +40 -0
  182. package/resources/js/context/skills/resolution-adaptation/references/game-ui-occlusion.md +18 -0
  183. package/resources/js/context/skills/resolution-adaptation/references/layout-rules.md +15 -134
  184. package/resources/js/context/skills/resolution-adaptation/references/troubleshooting.md +34 -0
  185. package/resources/js/context/skills/resolution-adaptation/references/viewport-api.md +38 -119
  186. package/resources/js/context/skills/resolution-adaptation/references/world-resize.md +55 -0
  187. package/resources/js/context/skills/resolution-adaptation/scripts/aspect_audit.mjs +448 -338
  188. package/resources/js/context/skills/scene-editor-compat/SKILL.md +94 -94
  189. package/resources/js/context/skills/scene-editor-compat/assets/example/localcraft.assets.json +13 -13
  190. package/resources/js/context/skills/scene-editor-compat/assets/example/localcraft.scene-editor.json +6 -6
  191. package/resources/js/context/skills/scene-editor-compat/assets/example/src/game/sceneAdapter.ts +25 -25
  192. package/resources/js/context/skills/scene-editor-compat/assets/example/src/scenes/main.scene.json +18 -18
  193. package/resources/js/context/skills/scene-editor-compat/assets/runtime/release.json +7 -7
  194. package/resources/js/context/skills/scene-editor-compat/assets/runtime/scene.d.mts +42 -42
  195. package/resources/js/context/skills/scene-editor-compat/assets/runtime/scene.mjs +144 -144
  196. package/resources/js/context/skills/scene-editor-compat/docs/contract.md +330 -330
  197. package/resources/js/context/skills/scene-editor-compat/docs/resource-sync.md +64 -64
  198. package/resources/js/context/skills/scene-editor-compat/docs/runtime-state.md +28 -28
  199. package/resources/js/context/skills/scene-editor-compat/docs/terrain-contract.md +47 -47
  200. package/resources/js/context/skills/scene-editor-compat/docs/visual-contract.md +64 -64
  201. package/resources/js/context/skills/scene-editor-compat/examples/platformer-ts/localcraft.assets.json +38 -38
  202. package/resources/js/context/skills/scene-editor-compat/examples/platformer-ts/localcraft.scene-editor.json +9 -9
  203. package/resources/js/context/skills/scene-editor-compat/examples/platformer-ts/src/game/sceneAdapter.ts +59 -59
  204. package/resources/js/context/skills/scene-editor-compat/examples/platformer-ts/src/game/sceneBlockers.ts +30 -30
  205. package/resources/js/context/skills/scene-editor-compat/examples/platformer-ts/src/game/sceneFileAssets.ts +66 -66
  206. package/resources/js/context/skills/scene-editor-compat/examples/platformer-ts/src/scenes/Main.Scene.ts +20 -20
  207. package/resources/js/context/skills/scene-editor-compat/examples/platformer-ts/src/scenes/SceneTypes.ts +26 -26
  208. package/resources/js/context/skills/scene-editor-compat/references/contract.md +73 -73
  209. package/resources/js/context/skills/scene-editor-compat/scripts/apply_scene_marker.py +162 -162
  210. package/resources/js/context/skills/scene-editor-compat/scripts/check_scene_contract.py +853 -853
  211. package/resources/js/context/skills/scene-editor-compat/scripts/check_scene_resource_urls.py +173 -173
  212. package/resources/js/context/skills/scene-editor-compat/scripts/scene-editor.mjs +427 -427
  213. package/resources/js/context/skills/scene-editor-compat/version.json +1 -1
  214. package/resources/js/context/skills/ui-editor-compat/SKILL.md +48 -48
  215. package/resources/js/context/skills/ui-editor-compat/assets/example/hud/WidgetLayout_Hud.ts +35 -35
  216. package/resources/js/context/skills/ui-editor-compat/assets/example/hud/WidgetLogic_Hud.ts +74 -74
  217. package/resources/js/context/skills/ui-editor-compat/assets/example/hud/hud.css +60 -60
  218. package/resources/js/context/skills/ui-editor-compat/assets/runtime/dom-ui.d.mts +45 -45
  219. package/resources/js/context/skills/ui-editor-compat/assets/runtime/dom-ui.mjs +265 -265
  220. package/resources/js/context/skills/ui-editor-compat/assets/runtime/release.json +7 -7
  221. package/resources/js/context/skills/ui-editor-compat/references/contract.md +132 -132
  222. package/resources/js/context/skills/ui-editor-compat/scripts/editor-contract.mjs +327 -327
  223. package/resources/js/context/skills/ui-editor-compat/scripts/project-files.mjs +80 -80
  224. package/resources/js/context/skills/ui-editor-compat/scripts/ui-editor.mjs +84 -84
  225. package/resources/js/context/skills/version-update/SKILL.md +192 -192
  226. package/resources/js/context/skills/version-update/scripts/check_runtime_refs.mjs +129 -129
  227. package/resources/js/context/skills/version-update/scripts/feature_snapshot.mjs +159 -159
  228. package/resources/js/context/skills/version-update/scripts/update_feature_version.mjs +157 -157
  229. package/resources/js/context/skills/visual-qa/SKILL.md +36 -36
  230. package/resources/js/context/version/version.json +1 -1
  231. package/resources/js/project/README.md +99 -99
  232. package/resources/js/project/SPEC/readme.md +6 -6
  233. package/resources/js/project/configs/assets.json +1 -1
  234. package/resources/js/project/configs/game.controls.json +3 -3
  235. package/resources/js/project/configs/game.json +3 -3
  236. package/resources/js/project/game-runtime.json +2 -2
  237. package/resources/js/project/{projectDisplayInfo.json → game.config.json} +7 -7
  238. package/resources/js/project/index.html +20 -20
  239. package/resources/js/project/package.json +23 -23
  240. package/resources/js/project/runtime/lightgame/1.1.0/platform/identity/qq-ai-game-sdk.min.js +5 -0
  241. package/resources/js/project/runtime/lightgame/1.1.0/platform/identity/qq-session.mjs +208 -0
  242. package/resources/js/project/runtime/lightgame/1.1.0/platform/identity/shared.mjs +37 -0
  243. package/resources/js/project/runtime/lightgame/1.1.0/platform/platform-capture-video.mjs +227 -0
  244. package/resources/js/project/runtime/lightgame/1.1.0/platform/platform-service.d.mts +31 -0
  245. package/resources/js/project/runtime/lightgame/1.1.0/platform/platform-service.mjs +272 -0
  246. package/resources/js/project/runtime/lightgame/1.1.0/platform/platform.d.mts +79 -0
  247. package/resources/js/project/runtime/lightgame/1.1.0/platform/platform.mjs +29 -0
  248. package/resources/js/project/runtime/lightgame/1.1.0/release.json +22 -0
  249. package/resources/js/project/runtime/lightgame/1.1.0/tooling/cli.mjs +16 -0
  250. package/resources/js/project/runtime/lightgame/1.1.0/tooling/project.d.mts +4 -0
  251. package/resources/js/project/runtime/lightgame/1.1.0/tooling/project.mjs +50 -0
  252. package/resources/js/project/runtime/lightgame/1.1.0/tooling/vite.d.mts +3 -0
  253. package/resources/js/project/runtime/lightgame/1.1.0/tooling/vite.mjs +72 -0
  254. package/resources/js/project/runtime/lightgame/1.1.0/tools/assets.d.mts +24 -0
  255. package/resources/js/project/runtime/lightgame/1.1.0/tools/assets.mjs +2 -0
  256. package/resources/js/project/runtime/lightgame/1.1.0/tools/astc.d.mts +10 -0
  257. package/resources/js/project/runtime/lightgame/1.1.0/tools/astc.mjs +1 -0
  258. package/resources/js/project/scripts/config-export.mjs +37 -32
  259. package/resources/js/project/scripts/refresh-runtime.mjs +50 -50
  260. package/resources/js/project/scripts/skill-modules/export-config/cli.mjs +20 -0
  261. package/resources/js/project/scripts/skill-modules/export-config/config.d.mts +19 -0
  262. package/resources/js/project/scripts/skill-modules/export-config/config.mjs +1 -0
  263. package/resources/js/project/scripts/skill-modules/export-config/installed.json +6 -0
  264. package/resources/js/project/scripts/skill-modules/export-config/project.d.mts +6 -0
  265. package/resources/js/project/scripts/skill-modules/export-config/project.mjs +77 -0
  266. package/resources/js/project/scripts/skill-modules/export-config/vite.d.mts +2 -0
  267. package/resources/js/project/scripts/skill-modules/export-config/vite.mjs +34 -0
  268. package/resources/js/project/scripts/write-preview-ready.mjs +22 -0
  269. package/resources/js/project/src/display/ui-stage.ts +156 -121
  270. package/resources/js/project/src/display/viewport.ts +249 -254
  271. package/resources/js/project/src/main.ts +87 -99
  272. package/resources/js/project/src/platform.ts +2 -14
  273. package/resources/js/project/src/scenes/LoadScene.ts +89 -89
  274. package/resources/js/project/src/scenes/PlayScene.ts +17 -17
  275. package/resources/js/project/src/screenUi.ts +185 -172
  276. package/resources/js/project/src/style.css +294 -165
  277. package/resources/js/project/tsconfig.json +20 -20
  278. package/resources/js/project/unified_data_control_config.json +20 -20
  279. package/resources/js/project/vendor/core-manager-js/src/.versions.json +42 -42
  280. package/resources/js/project/vendor/core-manager-js/src/CoreManagerPlugin.ts +41 -41
  281. package/resources/js/project/vendor/core-manager-js/src/assetManager/AssetRef.ts +93 -90
  282. package/resources/js/project/vendor/core-manager-js/src/assetManager/AstcFirstImageFile.ts +203 -203
  283. package/resources/js/project/vendor/core-manager-js/src/assetManager/AstcTextureLoader.ts +106 -106
  284. package/resources/js/project/vendor/core-manager-js/src/assetManager/resolveAssetUrl.test.ts +25 -25
  285. package/resources/js/project/vendor/core-manager-js/src/assetManager/resolveAssetUrl.ts +21 -21
  286. package/resources/js/project/vendor/core-manager-js/src/audioManager/AudioManager.test.ts +65 -65
  287. package/resources/js/project/vendor/core-manager-js/src/audioManager/AudioManager.ts +340 -340
  288. package/resources/js/project/vendor/core-manager-js/src/configManager/FeatureConfig.ts +87 -87
  289. package/resources/js/project/vendor/core-manager-js/src/configManager/tuneRuntime.d.mts +92 -92
  290. package/resources/js/project/vendor/core-manager-js/src/configManager/tuneRuntime.mjs +271 -271
  291. package/resources/js/project/vendor/core-manager-js/src/index.ts +31 -31
  292. package/resources/js/project/vendor/core-manager-js/src/inputManager/InputConfig.ts +81 -81
  293. package/resources/js/project/vendor/core-manager-js/src/inputManager/InputManager.test.ts +43 -43
  294. package/resources/js/project/vendor/core-manager-js/src/inputManager/InputManager.ts +32 -32
  295. package/resources/js/project/vendor/core-manager-js/src/inputManager/InputRuntime.test.ts +141 -141
  296. package/resources/js/project/vendor/core-manager-js/src/inputManager/InputRuntime.ts +20 -20
  297. package/resources/js/project/vendor/core-manager-js/src/inputManager/KeyboardProvider.ts +183 -183
  298. package/resources/js/project/vendor/core-manager-js/src/inputManager/TouchProvider.ts +304 -304
  299. package/resources/js/project/vendor/core-manager-js/src/inputManager/VirtualJoystick.ts +351 -351
  300. package/resources/js/project/vendor/core-manager-js/src/inputManager/_internal/InputManagerImpl.ts +180 -180
  301. package/resources/js/project/vendor/core-manager-js/src/inputManager/icons.b64 +13 -13
  302. package/resources/js/project/vendor/core-manager-js/src/inputManager/icons.b64.d.ts +14 -14
  303. package/resources/js/project/vendor/core-manager-js/src/inputManager/input_config.example.json +68 -68
  304. package/resources/js/project/vendor/core-manager-js/src/logManager/DebugConsole.ts +433 -433
  305. package/resources/js/project/vendor/core-manager-js/src/logManager/LogCapture.ts +118 -118
  306. package/resources/js/project/vendor/core-manager-js/src/logManager/LogManager.ts +444 -444
  307. package/resources/js/project/vendor/core-manager-js/src/logManager/ScreenCapture.ts +485 -485
  308. package/resources/js/project/vendor/core-manager-js/src/logManager/ScreenCaptureVideo.test.ts +66 -66
  309. package/resources/js/project/vendor/core-manager-js/src/logManager/ScreenCaptureVideo.ts +149 -149
  310. package/resources/js/project/vendor/core-manager-js/src/logManager/icons.b64 +9 -9
  311. package/resources/js/project/vendor/core-manager-js/src/resourceManager/AssetUrlResolver.ts +29 -29
  312. package/resources/js/project/vendor/core-manager-js/src/resourceManager/ResourceManager.test.ts +88 -88
  313. package/resources/js/project/vendor/core-manager-js/src/resourceManager/ResourceManager.ts +122 -122
  314. package/resources/js/project/vendor/core-manager-js/src/runtime.ts +24 -24
  315. package/resources/js/project/vendor/core-manager-js/src/spriteAnimManager/CharacterEntity.ts +318 -318
  316. package/resources/js/project/vendor/core-manager-js/src/spriteAnimManager/CharacterPhysicsBinding.test.ts +151 -151
  317. package/resources/js/project/vendor/core-manager-js/src/spriteAnimManager/CharacterPhysicsBinding.ts +235 -235
  318. package/resources/js/project/vendor/core-manager-js/src/spriteAnimManager/EffectComposite.test.ts +98 -98
  319. package/resources/js/project/vendor/core-manager-js/src/spriteAnimManager/EffectComposite.ts +94 -94
  320. package/resources/js/project/vendor/core-manager-js/src/spriteAnimManager/EffectEntity.ts +209 -209
  321. package/resources/js/project/vendor/core-manager-js/src/spriteAnimManager/FxManager.test.ts +106 -106
  322. package/resources/js/project/vendor/core-manager-js/src/spriteAnimManager/FxManager.ts +341 -341
  323. package/resources/js/project/vendor/core-manager-js/src/spriteAnimManager/FxRecipe.test.ts +68 -68
  324. package/resources/js/project/vendor/core-manager-js/src/spriteAnimManager/FxRecipe.ts +236 -236
  325. package/resources/js/project/vendor/core-manager-js/src/spriteAnimManager/SpriteAnimManager.test.ts +22 -22
  326. package/resources/js/project/vendor/core-manager-js/src/spriteAnimManager/SpriteAnimManager.ts +29 -29
  327. package/resources/js/project/vendor/core-manager-js/src/spriteAnimManager/SpriteEntity.test.ts +197 -197
  328. package/resources/js/project/vendor/core-manager-js/src/uiManager/DomUiContracts.ts +9 -9
  329. package/resources/js/project/vendor/core-manager-js/src/uiManager/DomUiKit.ts +555 -555
  330. package/resources/js/project/vendor/core-manager-js/src/uiManager/UIFacadePlugin.test.ts +112 -112
  331. package/resources/js/project/vendor/core-manager-js/src/uiManager/UIFacadePlugin.ts +178 -178
  332. package/resources/js/project/vendor/core-manager-js/src/uiManager/ui-base.css +246 -246
  333. package/resources/js/project/vendor/core-manager-js/src/videoManager/VideoManager.ts +139 -139
  334. package/resources/js/project/vendor/core-manager-js/tsconfig.json +15 -15
  335. package/resources/js/project/vendor/run.sh +4 -107
  336. package/resources/js/project/version/craft_feature_version.json +42 -42
  337. package/resources/js/project/version/project_feature_version.json +11 -11
  338. package/resources/js/project/vite.config.ts +5 -4
  339. package/resources/js3d/context/.role/AGENTS_DESIGN.md +9 -0
  340. package/resources/js3d/context/AGENTS.md +95 -0
  341. package/resources/js3d/context/hooks/hooks.json +14 -20
  342. package/resources/js3d/context/knowledge/3D/PoseInterpolationKnowledge.md +75 -87
  343. package/resources/js3d/context/knowledge/CodingGuide/Pitfalls.md +69 -69
  344. package/resources/js3d/context/knowledge/CodingGuide/SceneEditableGuide.md +42 -42
  345. package/resources/js3d/context/knowledge/FrontendComponents.md +19 -23
  346. package/resources/js3d/context/knowledge/MobileAdaptation.md +73 -0
  347. package/resources/js3d/context/knowledge/MobileAdapted.md +36 -0
  348. package/resources/js3d/context/knowledge/Multiplayer/GameplaySystemKnowledge.md +114 -114
  349. package/resources/js3d/context/knowledge/Multiplayer/OverviewKnowledge.md +117 -117
  350. package/resources/js3d/context/knowledge/Multiplayer/StateSyncKnowledge.md +430 -430
  351. package/resources/js3d/context/knowledge/PlatformServices.md +190 -162
  352. package/resources/js3d/context/knowledge/ProjectDisplayConfig.md +35 -0
  353. package/resources/js3d/context/knowledge/Runtime.md +34 -30
  354. package/resources/js3d/context/knowledge/SceneEditorCompat.md +35 -34
  355. package/resources/js3d/context/knowledge/StepByStep.md +21 -21
  356. package/resources/js3d/context/knowledge/Subsystems/Optional/MultiplayerManagerKnowledge.md +242 -242
  357. package/resources/js3d/context/knowledge/UiEditorCompat.md +21 -21
  358. package/resources/js3d/context/rules/MultiplayerCapability.md +27 -27
  359. package/resources/js3d/context/rules/MultiplayerRoomEntryUX.md +63 -63
  360. package/resources/js3d/context/rules/PlatformBoundaryModules.md +44 -43
  361. package/resources/js3d/context/rules/preview_ready.md +8 -0
  362. package/resources/js3d/context/skills/aigc-integration/SKILL.md +172 -176
  363. package/resources/js3d/context/skills/aigc-integration/assets/sprite-sheet-player.mjs +70 -0
  364. package/resources/js3d/context/skills/aigc-integration/callback.md +77 -56
  365. package/resources/js3d/context/skills/aigc-integration/knowledge/aigc/README.md +23 -22
  366. package/resources/js3d/context/skills/aigc-integration/knowledge/aigc/audio-aigc-knowledge.md +38 -38
  367. package/resources/js3d/context/skills/aigc-integration/knowledge/aigc/character2d-aigc-knowledge.md +72 -0
  368. package/resources/js3d/context/skills/aigc-integration/knowledge/aigc/staticmesh-aigc-knowledge.md +33 -33
  369. package/resources/js3d/context/skills/aigc-integration/knowledge/aigc/texture-prop-aigc-knowledge.md +36 -36
  370. package/resources/js3d/context/skills/aigc-integration/knowledge/aigc/texture-scene-aigc-knowledge.md +37 -37
  371. package/resources/js3d/context/skills/aigc-integration/knowledge/aigc/texture-ui-aigc-knowledge.md +35 -35
  372. package/resources/js3d/context/skills/asset-search/SKILL.md +178 -159
  373. package/resources/js3d/context/skills/asset-search/references/resource-config.md +99 -56
  374. package/resources/js3d/context/skills/asset-search/references/sprite-sheets.md +58 -0
  375. package/resources/js3d/context/skills/asset-search/scripts/asset_display.mjs +62 -62
  376. package/resources/js3d/context/skills/asset-search/scripts/config.json +235 -213
  377. package/resources/js3d/context/skills/asset-search/scripts/manifest_pipeline.mjs +905 -885
  378. package/resources/js3d/context/skills/asset-search/scripts/preflight.mjs +79 -79
  379. package/resources/js3d/context/skills/asset-search/scripts/provided_assets.mjs +74 -74
  380. package/resources/js3d/context/skills/asset-search/scripts/search.mjs +637 -597
  381. package/resources/js3d/context/skills/asset-search/scripts/sprite_source_materializer.mjs +667 -0
  382. package/resources/js3d/context/skills/asset-search/strategies/anim2d.md +42 -0
  383. package/resources/js3d/context/skills/asset-search/strategies/effect2d.md +31 -0
  384. package/resources/js3d/context/skills/asset-usage-audit/SKILL.md +92 -0
  385. package/resources/js3d/context/skills/asset-usage-audit/references/case-tidewater-zoo.md +89 -0
  386. package/resources/js3d/context/skills/asset-usage-audit/references/optimization-playbook.md +143 -0
  387. package/resources/js3d/context/skills/asset-usage-audit/references/usage-model.md +90 -0
  388. package/resources/js3d/context/skills/asset-usage-audit/scripts/compare-animations.mjs +48 -0
  389. package/resources/js3d/context/skills/asset-usage-audit/scripts/lib/anim.mjs +266 -0
  390. package/resources/js3d/context/skills/asset-usage-audit/scripts/lib/glb.mjs +241 -0
  391. package/resources/js3d/context/skills/asset-usage-audit/scripts/lib/scan.mjs +455 -0
  392. package/resources/js3d/context/skills/asset-usage-audit/scripts/scan-assets.mjs +77 -0
  393. package/resources/js3d/context/skills/export-config/SKILL.md +20 -0
  394. package/resources/js3d/context/skills/export-config/assets/tooling/cli.mjs +20 -0
  395. package/resources/js3d/context/skills/export-config/assets/tooling/config.d.mts +19 -0
  396. package/resources/js3d/context/skills/export-config/assets/tooling/config.mjs +1 -0
  397. package/resources/js3d/context/skills/export-config/assets/tooling/project.d.mts +6 -0
  398. package/resources/js3d/context/skills/export-config/assets/tooling/project.mjs +77 -0
  399. package/resources/js3d/context/skills/export-config/assets/tooling/vite.d.mts +2 -0
  400. package/resources/js3d/context/skills/export-config/assets/tooling/vite.mjs +34 -0
  401. package/resources/js3d/context/skills/export-config/scripts/assert-asset-wiring.mjs +97 -83
  402. package/resources/js3d/context/skills/export-config/scripts/export-config.mjs +56 -53
  403. package/resources/js3d/context/skills/export-config/scripts/install.mjs +89 -0
  404. package/resources/js3d/context/skills/export-config/scripts/panel-resource-path.mjs +106 -106
  405. package/resources/js3d/context/skills/export-config/scripts/sync-asset-controls.mjs +327 -325
  406. package/resources/js3d/context/skills/export-config/scripts/sync-scene-assets.mjs +216 -181
  407. package/resources/js3d/context/skills/export-config/scripts/translate-asset-titles.mjs +161 -163
  408. package/resources/js3d/context/skills/game-art-style/SKILL.md +60 -60
  409. package/resources/js3d/context/skills/game-art-style/references/art-parameters-lite.md +38 -38
  410. package/resources/js3d/context/skills/game-art-style/references/construction.md +111 -111
  411. package/resources/js3d/context/skills/game-art-style/references/materials-textures.md +105 -105
  412. package/resources/js3d/context/skills/game-art-style/references/sources.md +25 -25
  413. package/resources/js3d/context/skills/game-art-style/references/styles/cartoon.md +175 -175
  414. package/resources/js3d/context/skills/game-art-style/references/styles/comic.md +168 -168
  415. package/resources/js3d/context/skills/game-art-style/references/styles/cozy.md +191 -191
  416. package/resources/js3d/context/skills/game-art-style/references/styles/cyber.md +165 -165
  417. package/resources/js3d/context/skills/game-art-style/references/styles/horror.md +173 -173
  418. package/resources/js3d/context/skills/game-art-style/references/styles/lowpoly.md +185 -185
  419. package/resources/js3d/context/skills/game-art-style/references/styles/paper.md +181 -181
  420. package/resources/js3d/context/skills/game-art-style/references/styles/voxel.md +189 -189
  421. package/resources/js3d/context/skills/game-art-style/references/user-style-document.md +88 -88
  422. package/resources/js3d/context/skills/mobile-adaptation/SKILL.md +301 -284
  423. package/resources/js3d/context/skills/mobile-adaptation/assets/example/src/input/input-config.json +104 -104
  424. package/resources/js3d/context/skills/mobile-adaptation/assets/example/src/input/input-layer.ts +933 -952
  425. package/resources/js3d/context/skills/mobile-adaptation/assets/example/src/input/input-platform.ts +92 -92
  426. package/resources/js3d/context/skills/mobile-adaptation/assets/example/src/input/input-primitives.ts +254 -0
  427. package/resources/js3d/context/skills/mobile-adaptation/assets/example/src/input/look-pad.ts +245 -245
  428. package/resources/js3d/context/skills/mobile-adaptation/assets/example/src/ui/touch-controls.css +257 -256
  429. package/resources/js3d/context/skills/mobile-adaptation/references/input-config.md +342 -311
  430. package/resources/js3d/context/skills/mobile-adaptation/references/verification.md +140 -106
  431. package/resources/js3d/context/skills/mobile-adaptation/references/web-audio.md +11 -0
  432. package/resources/js3d/context/skills/mobile-compat-qa/SKILL.md +53 -0
  433. package/resources/js3d/context/skills/mobile-compat-qa/references/startup-diagnosis.md +23 -0
  434. package/resources/js3d/context/skills/mobile-compat-qa/references/web-form-input.md +10 -0
  435. package/resources/js3d/context/skills/mobile-compat-qa/references/web-lifecycle.md +20 -0
  436. package/resources/js3d/context/skills/mobile-compat-qa/references/web-performance.md +19 -0
  437. package/resources/js3d/context/skills/optimization-suggestions/SKILL.md +74 -74
  438. package/resources/js3d/context/skills/performance-audit/SKILL.md +166 -0
  439. package/resources/js3d/context/skills/performance-audit/references/case-notes.md +93 -0
  440. package/resources/js3d/context/skills/performance-audit/references/rules.md +183 -0
  441. package/resources/js3d/context/skills/performance-audit/scripts/lib/rules.mjs +470 -0
  442. package/resources/js3d/context/skills/performance-audit/scripts/lib/scan.mjs +387 -0
  443. package/resources/js3d/context/skills/performance-audit/scripts/lib/source.mjs +398 -0
  444. package/resources/js3d/context/skills/performance-audit/scripts/scan-perf.mjs +130 -0
  445. package/resources/js3d/context/skills/platform-services/SKILL.md +101 -94
  446. package/resources/js3d/context/skills/platform-services/assets/modules/MultiplayerManager.ts +465 -783
  447. package/resources/js3d/context/skills/platform-services/assets/modules/eventBus.ts +57 -57
  448. package/resources/js3d/context/skills/platform-services/assets/modules/identity/qq-ai-game-sdk.min.js +5 -0
  449. package/resources/js3d/context/skills/platform-services/assets/modules/identity/qq-session.mjs +208 -0
  450. package/resources/js3d/context/skills/platform-services/assets/modules/identity/shared.mjs +37 -0
  451. package/resources/js3d/context/skills/platform-services/assets/modules/leaderboard.d.mts +39 -39
  452. package/resources/js3d/context/skills/platform-services/assets/modules/leaderboard.mjs +1 -1
  453. package/resources/js3d/context/skills/platform-services/assets/modules/log.ts +35 -35
  454. package/resources/js3d/context/skills/platform-services/assets/modules/multiplayer/clockSync.ts +61 -0
  455. package/resources/js3d/context/skills/platform-services/assets/modules/multiplayer/dsClient.ts +52 -0
  456. package/resources/js3d/context/skills/platform-services/assets/modules/multiplayer/payloadCodec.ts +30 -0
  457. package/resources/js3d/context/skills/platform-services/assets/modules/multiplayer/roomHttp.ts +89 -0
  458. package/resources/js3d/context/skills/platform-services/assets/modules/multiplayer/types.ts +47 -0
  459. package/resources/js3d/context/skills/platform-services/assets/modules/platform-service.d.mts +31 -25
  460. package/resources/js3d/context/skills/platform-services/assets/modules/platform-service.mjs +272 -1
  461. package/resources/js3d/context/skills/platform-services/assets/modules/save.d.mts +49 -49
  462. package/resources/js3d/context/skills/platform-services/assets/modules/save.mjs +1 -1
  463. package/resources/js3d/context/skills/platform-services/assets/scaffold/ds/main.mjs +7 -7
  464. package/resources/js3d/context/skills/platform-services/assets/scaffold/ds/rooms/SyncRoom.mjs +264 -264
  465. package/resources/js3d/context/skills/platform-services/assets/scaffold/ds/rooms/syncSchema.mjs +39 -39
  466. package/resources/js3d/context/skills/platform-services/references/SERVER_GUIDE.md +139 -139
  467. package/resources/js3d/context/skills/platform-services/references/api_reference.md +18 -18
  468. package/resources/js3d/context/skills/platform-services/references/leaderboard_playbook.md +96 -0
  469. package/resources/js3d/context/skills/platform-services/scripts/install.mjs +148 -134
  470. package/resources/js3d/context/skills/resolution-adaptation/SKILL.md +46 -170
  471. package/resources/js3d/context/skills/resolution-adaptation/assets/display/ui-stage.ts +156 -121
  472. package/resources/js3d/context/skills/resolution-adaptation/assets/display/viewport.ts +239 -244
  473. package/resources/js3d/context/skills/resolution-adaptation/assets/example/main.ts +129 -127
  474. package/resources/js3d/context/skills/resolution-adaptation/assets/example/ui-tokens.css +188 -188
  475. package/resources/js3d/context/skills/resolution-adaptation/references/audit.md +31 -0
  476. package/resources/js3d/context/skills/resolution-adaptation/references/device-safe-area.md +40 -0
  477. package/resources/js3d/context/skills/resolution-adaptation/references/game-ui-occlusion.md +18 -0
  478. package/resources/js3d/context/skills/resolution-adaptation/references/layout-rules.md +15 -124
  479. package/resources/js3d/context/skills/resolution-adaptation/references/troubleshooting.md +34 -0
  480. package/resources/js3d/context/skills/resolution-adaptation/references/viewport-api.md +38 -117
  481. package/resources/js3d/context/skills/resolution-adaptation/scripts/aspect_audit.mjs +448 -338
  482. package/resources/js3d/context/skills/scene-editor-compat/SKILL.md +599 -599
  483. package/resources/js3d/context/skills/scene-editor-compat/references/bundle-contract.md +141 -141
  484. package/resources/js3d/context/skills/scene-editor-compat/references/editor-integration.md +92 -92
  485. package/resources/js3d/context/skills/scene-editor-compat/references/scene-data-format.md +125 -125
  486. package/resources/js3d/context/skills/scene-editor-compat/references/slots-rules.md +113 -113
  487. package/resources/js3d/context/skills/scene-editor-compat/scripts/scene-editor.mjs +1187 -1187
  488. package/resources/js3d/context/skills/threejs-game-quality/SKILL.md +53 -52
  489. package/resources/js3d/context/skills/threejs-game-quality/agents/openai.yaml +4 -4
  490. package/resources/js3d/context/skills/threejs-game-quality/references/01-build.md +94 -94
  491. package/resources/js3d/context/skills/threejs-game-quality/references/02-avoid.md +50 -50
  492. package/resources/js3d/context/skills/threejs-game-quality/references/03-detect.md +105 -105
  493. package/resources/js3d/context/skills/threejs-game-quality/references/camera-by-genre.md +147 -147
  494. package/resources/js3d/context/skills/threejs-game-quality/references/camera-distance.md +79 -79
  495. package/resources/js3d/context/skills/threejs-game-quality/references/camera-sources.md +56 -56
  496. package/resources/js3d/context/skills/threejs-game-quality/references/character-motion-face.md +51 -51
  497. package/resources/js3d/context/skills/threejs-game-quality/references/parameter-contract.md +55 -55
  498. package/resources/js3d/context/skills/threejs-game-quality/references/refine-existing.md +78 -78
  499. package/resources/js3d/context/skills/threejs-game-quality/references/rendering-stability.md +84 -84
  500. package/resources/js3d/context/skills/threejs-game-quality/references/runtime-tools.md +117 -117
  501. package/resources/js3d/context/skills/threejs-game-quality/scripts/package.json +4 -4
  502. package/resources/js3d/context/skills/threejs-game-quality/scripts/runtime-audit.js +238 -238
  503. package/resources/js3d/context/skills/ui-editor-compat/SKILL.md +59 -59
  504. package/resources/js3d/context/skills/ui-editor-compat/assets/example/hud/WidgetLayout_Hud.ts +35 -35
  505. package/resources/js3d/context/skills/ui-editor-compat/assets/example/hud/WidgetLogic_Hud.ts +61 -61
  506. package/resources/js3d/context/skills/ui-editor-compat/assets/example/hud/hud.css +60 -60
  507. package/resources/js3d/context/skills/ui-editor-compat/assets/runtime/dom-ui.d.mts +45 -45
  508. package/resources/js3d/context/skills/ui-editor-compat/assets/runtime/dom-ui.mjs +265 -265
  509. package/resources/js3d/context/skills/ui-editor-compat/assets/runtime/release.json +7 -7
  510. package/resources/js3d/context/skills/ui-editor-compat/references/contract.md +110 -110
  511. package/resources/js3d/context/skills/ui-editor-compat/scripts/editor-contract.mjs +327 -327
  512. package/resources/js3d/context/skills/ui-editor-compat/scripts/project-files.mjs +80 -80
  513. package/resources/js3d/context/skills/ui-editor-compat/scripts/ui-editor.mjs +84 -84
  514. package/resources/js3d/context/skills/version-update/SKILL.md +191 -191
  515. package/resources/js3d/context/skills/version-update/scripts/check_runtime_refs.mjs +129 -129
  516. package/resources/js3d/context/skills/version-update/scripts/feature_snapshot.mjs +159 -159
  517. package/resources/js3d/context/skills/version-update/scripts/update_feature_version.mjs +157 -157
  518. package/resources/js3d/context/version/version.json +1 -1
  519. package/resources/js3d/project/README.md +106 -100
  520. package/resources/js3d/project/configs/game.controls.json +3 -3
  521. package/resources/js3d/project/configs/game.json +3 -3
  522. package/resources/js3d/project/game-runtime.json +2 -2
  523. package/resources/js3d/project/{projectDisplayInfo.json → game.config.json} +7 -7
  524. package/resources/js3d/project/index.html +12 -12
  525. package/resources/js3d/project/package.json +24 -24
  526. package/resources/js3d/project/runtime/lightgame/1.0.0/release.json +2 -2
  527. package/resources/js3d/project/runtime/lightgame/1.0.0/tools/glb.d.mts +2 -12
  528. package/resources/js3d/project/runtime/lightgame/1.0.0/tools/glb.mjs +21 -29
  529. package/resources/js3d/project/runtime/lightgame/1.1.0/platform/identity/qq-ai-game-sdk.min.js +5 -0
  530. package/resources/js3d/project/runtime/lightgame/1.1.0/platform/identity/qq-session.mjs +208 -0
  531. package/resources/js3d/project/runtime/lightgame/1.1.0/platform/identity/shared.mjs +37 -0
  532. package/resources/js3d/project/runtime/lightgame/1.1.0/platform/platform-capture-video.mjs +227 -0
  533. package/resources/js3d/project/runtime/lightgame/1.1.0/platform/platform-service.d.mts +31 -0
  534. package/resources/js3d/project/runtime/lightgame/1.1.0/platform/platform-service.mjs +272 -0
  535. package/resources/js3d/project/runtime/lightgame/1.1.0/platform/platform.d.mts +79 -0
  536. package/resources/js3d/project/runtime/lightgame/1.1.0/platform/platform.mjs +30 -0
  537. package/resources/js3d/project/runtime/lightgame/1.1.0/release.json +24 -0
  538. package/resources/js3d/project/runtime/lightgame/1.1.0/tooling/cli.mjs +16 -0
  539. package/resources/js3d/project/runtime/lightgame/1.1.0/tooling/project.d.mts +4 -0
  540. package/resources/js3d/project/runtime/lightgame/1.1.0/tooling/project.mjs +50 -0
  541. package/resources/js3d/project/runtime/lightgame/1.1.0/tooling/vite.d.mts +3 -0
  542. package/resources/js3d/project/runtime/lightgame/1.1.0/tooling/vite.mjs +72 -0
  543. package/resources/js3d/project/runtime/lightgame/1.1.0/tools/assets.d.mts +24 -0
  544. package/resources/js3d/project/runtime/lightgame/1.1.0/tools/assets.mjs +2 -0
  545. package/resources/js3d/project/runtime/lightgame/1.1.0/tools/astc.d.mts +10 -0
  546. package/resources/js3d/project/runtime/lightgame/1.1.0/tools/astc.mjs +1 -0
  547. package/resources/js3d/project/runtime/lightgame/1.1.0/tools/glb.d.mts +26 -0
  548. package/resources/js3d/project/runtime/lightgame/1.1.0/tools/glb.mjs +351 -0
  549. package/resources/js3d/project/scripts/config-export.mjs +37 -32
  550. package/resources/js3d/project/scripts/refresh-runtime.mjs +50 -50
  551. package/resources/js3d/project/scripts/skill-modules/export-config/cli.mjs +20 -0
  552. package/resources/js3d/project/scripts/skill-modules/export-config/config.d.mts +19 -0
  553. package/resources/js3d/project/scripts/skill-modules/export-config/config.mjs +1 -0
  554. package/resources/js3d/project/scripts/skill-modules/export-config/installed.json +6 -0
  555. package/resources/js3d/project/scripts/skill-modules/export-config/project.d.mts +6 -0
  556. package/resources/js3d/project/scripts/skill-modules/export-config/project.mjs +77 -0
  557. package/resources/js3d/project/scripts/skill-modules/export-config/vite.d.mts +2 -0
  558. package/resources/js3d/project/scripts/skill-modules/export-config/vite.mjs +34 -0
  559. package/resources/js3d/project/scripts/write-preview-ready.mjs +22 -0
  560. package/resources/js3d/project/src/display/ui-stage.ts +156 -121
  561. package/resources/js3d/project/src/display/viewport.ts +239 -244
  562. package/resources/js3d/project/src/main.ts +85 -83
  563. package/resources/js3d/project/src/platform.ts +2 -14
  564. package/resources/js3d/project/src/style.css +83 -17
  565. package/resources/js3d/project/tsconfig.json +20 -20
  566. package/resources/js3d/project/unified_data_control_config.json +20 -20
  567. package/resources/js3d/project/vendor/core-manager-three/package.json +12 -12
  568. package/resources/js3d/project/vendor/core-manager-three/src/index.ts +2 -2
  569. package/resources/js3d/project/vendor/run.sh +4 -4
  570. package/resources/js3d/project/version/craft_feature_version.json +42 -42
  571. package/resources/js3d/project/version/project_feature_version.json +11 -11
  572. package/resources/js3d/project/vite.config.ts +5 -4
  573. package/vendor/agent-cli/dist/runtime-tools/ue/blender-cook-assets.cjs +19 -19
  574. package/vendor/agent-cli/dist/runtime-tools/ue/tool-manifest.json +1 -1
  575. package/vendor/agent-cli/dist/src/artifacts/context-finalize.d.ts +1 -1
  576. package/vendor/agent-cli/dist/src/artifacts/context-finalize.d.ts.map +1 -1
  577. package/vendor/agent-cli/dist/src/artifacts/context-finalize.js +15 -6
  578. package/vendor/agent-cli/dist/src/artifacts/context-finalize.js.map +1 -1
  579. package/vendor/agent-cli/dist/src/artifacts/native-source.d.ts +3 -0
  580. package/vendor/agent-cli/dist/src/artifacts/native-source.d.ts.map +1 -0
  581. package/vendor/agent-cli/dist/src/artifacts/native-source.js +13 -0
  582. package/vendor/agent-cli/dist/src/artifacts/native-source.js.map +1 -0
  583. package/vendor/agent-cli/dist/src/artifacts/preinstalled-dependencies.d.ts +13 -0
  584. package/vendor/agent-cli/dist/src/artifacts/preinstalled-dependencies.d.ts.map +1 -0
  585. package/vendor/agent-cli/dist/src/artifacts/preinstalled-dependencies.js +300 -0
  586. package/vendor/agent-cli/dist/src/artifacts/preinstalled-dependencies.js.map +1 -0
  587. package/vendor/agent-cli/dist/src/artifacts/prepare.d.ts +4 -0
  588. package/vendor/agent-cli/dist/src/artifacts/prepare.d.ts.map +1 -1
  589. package/vendor/agent-cli/dist/src/artifacts/prepare.js +20 -7
  590. package/vendor/agent-cli/dist/src/artifacts/prepare.js.map +1 -1
  591. package/vendor/agent-cli/dist/src/artifacts/process-artifacts.d.ts +8 -1
  592. package/vendor/agent-cli/dist/src/artifacts/process-artifacts.d.ts.map +1 -1
  593. package/vendor/agent-cli/dist/src/artifacts/process-artifacts.js +59 -37
  594. package/vendor/agent-cli/dist/src/artifacts/process-artifacts.js.map +1 -1
  595. package/vendor/agent-cli/dist/src/artifacts/restore-permissions.d.ts +27 -0
  596. package/vendor/agent-cli/dist/src/artifacts/restore-permissions.d.ts.map +1 -0
  597. package/vendor/agent-cli/dist/src/artifacts/restore-permissions.js +112 -0
  598. package/vendor/agent-cli/dist/src/artifacts/restore-permissions.js.map +1 -0
  599. package/vendor/agent-cli/dist/src/artifacts/restore.d.ts +9 -0
  600. package/vendor/agent-cli/dist/src/artifacts/restore.d.ts.map +1 -1
  601. package/vendor/agent-cli/dist/src/artifacts/restore.js +137 -57
  602. package/vendor/agent-cli/dist/src/artifacts/restore.js.map +1 -1
  603. package/vendor/agent-cli/dist/src/artifacts/static.d.ts +6 -2
  604. package/vendor/agent-cli/dist/src/artifacts/static.d.ts.map +1 -1
  605. package/vendor/agent-cli/dist/src/artifacts/static.js +100 -28
  606. package/vendor/agent-cli/dist/src/artifacts/static.js.map +1 -1
  607. package/vendor/agent-cli/dist/src/cli/process-protocol.d.ts.map +1 -1
  608. package/vendor/agent-cli/dist/src/cli/process-protocol.js +6 -3
  609. package/vendor/agent-cli/dist/src/cli/process-protocol.js.map +1 -1
  610. package/vendor/agent-cli/dist/src/component/browser-queue.d.ts +55 -0
  611. package/vendor/agent-cli/dist/src/component/browser-queue.d.ts.map +1 -0
  612. package/vendor/agent-cli/dist/src/component/browser-queue.js +63 -0
  613. package/vendor/agent-cli/dist/src/component/browser-queue.js.map +1 -0
  614. package/vendor/agent-cli/dist/src/component/execution.d.ts +4 -0
  615. package/vendor/agent-cli/dist/src/component/execution.d.ts.map +1 -1
  616. package/vendor/agent-cli/dist/src/component/execution.js +16 -4
  617. package/vendor/agent-cli/dist/src/component/execution.js.map +1 -1
  618. package/vendor/agent-cli/dist/src/component/isolated-launcher.d.ts +2 -0
  619. package/vendor/agent-cli/dist/src/component/isolated-launcher.d.ts.map +1 -0
  620. package/vendor/agent-cli/dist/src/component/isolated-launcher.js +76 -0
  621. package/vendor/agent-cli/dist/src/component/isolated-launcher.js.map +1 -0
  622. package/vendor/agent-cli/dist/src/component/isolated-preload.d.ts +2 -0
  623. package/vendor/agent-cli/dist/src/component/isolated-preload.d.ts.map +1 -0
  624. package/vendor/agent-cli/dist/src/component/isolated-preload.js +27 -0
  625. package/vendor/agent-cli/dist/src/component/isolated-preload.js.map +1 -0
  626. package/vendor/agent-cli/dist/src/component/platform-access/server.d.ts +0 -5
  627. package/vendor/agent-cli/dist/src/component/platform-access/server.d.ts.map +1 -1
  628. package/vendor/agent-cli/dist/src/component/platform-access/server.js +9 -3
  629. package/vendor/agent-cli/dist/src/component/platform-access/server.js.map +1 -1
  630. package/vendor/agent-cli/dist/src/component/preparation-diagnostics.d.ts.map +1 -1
  631. package/vendor/agent-cli/dist/src/component/preparation-diagnostics.js +5 -0
  632. package/vendor/agent-cli/dist/src/component/preparation-diagnostics.js.map +1 -1
  633. package/vendor/agent-cli/dist/src/component/process-diagnostics.d.ts +25 -0
  634. package/vendor/agent-cli/dist/src/component/process-diagnostics.d.ts.map +1 -0
  635. package/vendor/agent-cli/dist/src/component/process-diagnostics.js +137 -0
  636. package/vendor/agent-cli/dist/src/component/process-diagnostics.js.map +1 -0
  637. package/vendor/agent-cli/dist/src/component/process-isolation.d.ts +10 -0
  638. package/vendor/agent-cli/dist/src/component/process-isolation.d.ts.map +1 -0
  639. package/vendor/agent-cli/dist/src/component/process-isolation.js +59 -0
  640. package/vendor/agent-cli/dist/src/component/process-isolation.js.map +1 -0
  641. package/vendor/agent-cli/dist/src/component/proxied-fetch.d.ts +2 -0
  642. package/vendor/agent-cli/dist/src/component/proxied-fetch.d.ts.map +1 -0
  643. package/vendor/agent-cli/dist/src/component/proxied-fetch.js +46 -0
  644. package/vendor/agent-cli/dist/src/component/proxied-fetch.js.map +1 -0
  645. package/vendor/agent-cli/dist/src/component/public-egress.d.ts +17 -0
  646. package/vendor/agent-cli/dist/src/component/public-egress.d.ts.map +1 -0
  647. package/vendor/agent-cli/dist/src/component/public-egress.js +246 -0
  648. package/vendor/agent-cli/dist/src/component/public-egress.js.map +1 -0
  649. package/vendor/agent-cli/dist/src/context/cache-publication-lock.d.ts +3 -0
  650. package/vendor/agent-cli/dist/src/context/cache-publication-lock.d.ts.map +1 -0
  651. package/vendor/agent-cli/dist/src/context/cache-publication-lock.js +68 -0
  652. package/vendor/agent-cli/dist/src/context/cache-publication-lock.js.map +1 -0
  653. package/vendor/agent-cli/dist/src/context/cache-publication.d.ts +1 -1
  654. package/vendor/agent-cli/dist/src/context/cache-publication.d.ts.map +1 -1
  655. package/vendor/agent-cli/dist/src/context/cache-publication.js +8 -4
  656. package/vendor/agent-cli/dist/src/context/cache-publication.js.map +1 -1
  657. package/vendor/agent-cli/dist/src/context/context-cache.d.ts.map +1 -1
  658. package/vendor/agent-cli/dist/src/context/context-cache.js +5 -2
  659. package/vendor/agent-cli/dist/src/context/context-cache.js.map +1 -1
  660. package/vendor/agent-cli/dist/src/context/context-project.d.ts +45 -4
  661. package/vendor/agent-cli/dist/src/context/context-project.d.ts.map +1 -1
  662. package/vendor/agent-cli/dist/src/context/context-project.js +157 -16
  663. package/vendor/agent-cli/dist/src/context/context-project.js.map +1 -1
  664. package/vendor/agent-cli/dist/src/context/context-scoped-source.d.ts +13 -0
  665. package/vendor/agent-cli/dist/src/context/context-scoped-source.d.ts.map +1 -0
  666. package/vendor/agent-cli/dist/src/context/context-scoped-source.js +78 -0
  667. package/vendor/agent-cli/dist/src/context/context-scoped-source.js.map +1 -0
  668. package/vendor/agent-cli/dist/src/context/context-snapshot-cache.d.ts +14 -0
  669. package/vendor/agent-cli/dist/src/context/context-snapshot-cache.d.ts.map +1 -1
  670. package/vendor/agent-cli/dist/src/context/context-snapshot-cache.js +110 -44
  671. package/vendor/agent-cli/dist/src/context/context-snapshot-cache.js.map +1 -1
  672. package/vendor/agent-cli/dist/src/context/local-skills.d.ts +2 -0
  673. package/vendor/agent-cli/dist/src/context/local-skills.d.ts.map +1 -1
  674. package/vendor/agent-cli/dist/src/context/local-skills.js +36 -19
  675. package/vendor/agent-cli/dist/src/context/local-skills.js.map +1 -1
  676. package/vendor/agent-cli/dist/src/context/member-context.d.ts +2 -1
  677. package/vendor/agent-cli/dist/src/context/member-context.d.ts.map +1 -1
  678. package/vendor/agent-cli/dist/src/context/member-context.js +17 -9
  679. package/vendor/agent-cli/dist/src/context/member-context.js.map +1 -1
  680. package/vendor/agent-cli/dist/src/context/script-dependencies.d.ts +9 -1
  681. package/vendor/agent-cli/dist/src/context/script-dependencies.d.ts.map +1 -1
  682. package/vendor/agent-cli/dist/src/context/script-dependencies.js +22 -6
  683. package/vendor/agent-cli/dist/src/context/script-dependencies.js.map +1 -1
  684. package/vendor/agent-cli/dist/src/context/shared-cache-build.d.ts +1 -1
  685. package/vendor/agent-cli/dist/src/context/shared-cache-build.d.ts.map +1 -1
  686. package/vendor/agent-cli/dist/src/context/shared-cache-build.js +1 -0
  687. package/vendor/agent-cli/dist/src/context/shared-cache-build.js.map +1 -1
  688. package/vendor/agent-cli/dist/src/context/team-knowledge.d.ts.map +1 -1
  689. package/vendor/agent-cli/dist/src/context/team-knowledge.js +11 -2
  690. package/vendor/agent-cli/dist/src/context/team-knowledge.js.map +1 -1
  691. package/vendor/agent-cli/dist/src/context/template-cache.js +2 -2
  692. package/vendor/agent-cli/dist/src/context/template-cache.js.map +1 -1
  693. package/vendor/agent-cli/dist/src/context/template-seed.d.ts +3 -0
  694. package/vendor/agent-cli/dist/src/context/template-seed.d.ts.map +1 -1
  695. package/vendor/agent-cli/dist/src/context/template-seed.js +50 -16
  696. package/vendor/agent-cli/dist/src/context/template-seed.js.map +1 -1
  697. package/vendor/agent-cli/dist/src/context/user-skill-context.d.ts +3 -1
  698. package/vendor/agent-cli/dist/src/context/user-skill-context.d.ts.map +1 -1
  699. package/vendor/agent-cli/dist/src/context/user-skill-context.js +41 -2
  700. package/vendor/agent-cli/dist/src/context/user-skill-context.js.map +1 -1
  701. package/vendor/agent-cli/dist/src/index.d.ts +4 -1
  702. package/vendor/agent-cli/dist/src/index.d.ts.map +1 -1
  703. package/vendor/agent-cli/dist/src/index.js +4 -1
  704. package/vendor/agent-cli/dist/src/index.js.map +1 -1
  705. package/vendor/agent-cli/dist/src/lifecycle/engine-hooks.d.ts +2 -2
  706. package/vendor/agent-cli/dist/src/lifecycle/engine-hooks.js +4 -2
  707. package/vendor/agent-cli/dist/src/lifecycle/engine-hooks.js.map +1 -1
  708. package/vendor/agent-cli/dist/src/lifecycle/hook-command.js +1 -1
  709. package/vendor/agent-cli/dist/src/lifecycle/hook-command.js.map +1 -1
  710. package/vendor/agent-cli/dist/src/protocol/messages/errors.gen.d.ts +24 -0
  711. package/vendor/agent-cli/dist/src/protocol/messages/errors.gen.d.ts.map +1 -1
  712. package/vendor/agent-cli/dist/src/protocol/messages/errors.gen.js +6 -0
  713. package/vendor/agent-cli/dist/src/protocol/messages/errors.gen.js.map +1 -1
  714. package/vendor/agent-cli/dist/src/protocol/messages/messages.gen.d.ts +71 -4
  715. package/vendor/agent-cli/dist/src/protocol/messages/messages.gen.d.ts.map +1 -1
  716. package/vendor/agent-cli/dist/src/protocol/messages/messages.gen.js +13 -1
  717. package/vendor/agent-cli/dist/src/protocol/messages/messages.gen.js.map +1 -1
  718. package/vendor/agent-cli/dist/src/security/command-translate.d.ts.map +1 -1
  719. package/vendor/agent-cli/dist/src/security/command-translate.js +4 -0
  720. package/vendor/agent-cli/dist/src/security/command-translate.js.map +1 -1
  721. package/vendor/agent-cli/dist/src/security/guard.d.ts +4 -0
  722. package/vendor/agent-cli/dist/src/security/guard.d.ts.map +1 -1
  723. package/vendor/agent-cli/dist/src/security/guard.js +17 -5
  724. package/vendor/agent-cli/dist/src/security/guard.js.map +1 -1
  725. package/vendor/agent-cli/dist/src/security/mount-table.d.ts +11 -2
  726. package/vendor/agent-cli/dist/src/security/mount-table.d.ts.map +1 -1
  727. package/vendor/agent-cli/dist/src/security/mount-table.js +92 -5
  728. package/vendor/agent-cli/dist/src/security/mount-table.js.map +1 -1
  729. package/vendor/agent-cli/dist/src/security/tool-scope.d.ts +4 -1
  730. package/vendor/agent-cli/dist/src/security/tool-scope.d.ts.map +1 -1
  731. package/vendor/agent-cli/dist/src/security/tool-scope.js +38 -4
  732. package/vendor/agent-cli/dist/src/security/tool-scope.js.map +1 -1
  733. package/vendor/agent-cli/dist/src/session/client.d.ts +20 -0
  734. package/vendor/agent-cli/dist/src/session/client.d.ts.map +1 -1
  735. package/vendor/agent-cli/dist/src/session/client.js +26 -4
  736. package/vendor/agent-cli/dist/src/session/client.js.map +1 -1
  737. package/vendor/agent-cli/dist/src/session/custom-context.d.ts.map +1 -1
  738. package/vendor/agent-cli/dist/src/session/custom-context.js +12 -6
  739. package/vendor/agent-cli/dist/src/session/custom-context.js.map +1 -1
  740. package/vendor/agent-cli/dist/src/session/execution-recovery.d.ts +9 -0
  741. package/vendor/agent-cli/dist/src/session/execution-recovery.d.ts.map +1 -0
  742. package/vendor/agent-cli/dist/src/session/execution-recovery.js +49 -0
  743. package/vendor/agent-cli/dist/src/session/execution-recovery.js.map +1 -0
  744. package/vendor/agent-cli/dist/src/session/expert-definition.d.ts +4 -0
  745. package/vendor/agent-cli/dist/src/session/expert-definition.d.ts.map +1 -0
  746. package/vendor/agent-cli/dist/src/session/expert-definition.js +20 -0
  747. package/vendor/agent-cli/dist/src/session/expert-definition.js.map +1 -0
  748. package/vendor/agent-cli/dist/src/session/link-config.js +1 -1
  749. package/vendor/agent-cli/dist/src/session/link-config.js.map +1 -1
  750. package/vendor/agent-cli/dist/src/session/link-session.d.ts +1 -0
  751. package/vendor/agent-cli/dist/src/session/link-session.d.ts.map +1 -1
  752. package/vendor/agent-cli/dist/src/session/link-session.js +19 -2
  753. package/vendor/agent-cli/dist/src/session/link-session.js.map +1 -1
  754. package/vendor/agent-cli/dist/src/session/process-lifecycle.d.ts +5 -0
  755. package/vendor/agent-cli/dist/src/session/process-lifecycle.d.ts.map +1 -0
  756. package/vendor/agent-cli/dist/src/session/process-lifecycle.js +18 -0
  757. package/vendor/agent-cli/dist/src/session/process-lifecycle.js.map +1 -0
  758. package/vendor/agent-cli/dist/src/session/process-observability.d.ts +4 -0
  759. package/vendor/agent-cli/dist/src/session/process-observability.d.ts.map +1 -0
  760. package/vendor/agent-cli/dist/src/session/process-observability.js +14 -0
  761. package/vendor/agent-cli/dist/src/session/process-observability.js.map +1 -0
  762. package/vendor/agent-cli/dist/src/session/process-request.d.ts +6 -6
  763. package/vendor/agent-cli/dist/src/session/process-request.d.ts.map +1 -1
  764. package/vendor/agent-cli/dist/src/session/process-request.js +55 -60
  765. package/vendor/agent-cli/dist/src/session/process-request.js.map +1 -1
  766. package/vendor/agent-cli/dist/src/session/process-restore.d.ts +4 -0
  767. package/vendor/agent-cli/dist/src/session/process-restore.d.ts.map +1 -0
  768. package/vendor/agent-cli/dist/src/session/process-restore.js +21 -0
  769. package/vendor/agent-cli/dist/src/session/process-restore.js.map +1 -0
  770. package/vendor/agent-cli/dist/src/session/process-workspace.d.ts +3 -0
  771. package/vendor/agent-cli/dist/src/session/process-workspace.d.ts.map +1 -0
  772. package/vendor/agent-cli/dist/src/session/process-workspace.js +21 -0
  773. package/vendor/agent-cli/dist/src/session/process-workspace.js.map +1 -0
  774. package/vendor/agent-cli/dist/src/session/reference-tools.d.ts.map +1 -1
  775. package/vendor/agent-cli/dist/src/session/reference-tools.js +3 -2
  776. package/vendor/agent-cli/dist/src/session/reference-tools.js.map +1 -1
  777. package/vendor/agent-cli/dist/src/session/run-setup.d.ts.map +1 -1
  778. package/vendor/agent-cli/dist/src/session/run-setup.js +33 -14
  779. package/vendor/agent-cli/dist/src/session/run-setup.js.map +1 -1
  780. package/vendor/agent-cli/dist/src/session/run-start-body.d.ts +5 -0
  781. package/vendor/agent-cli/dist/src/session/run-start-body.d.ts.map +1 -1
  782. package/vendor/agent-cli/dist/src/session/run-start-body.js +13 -1
  783. package/vendor/agent-cli/dist/src/session/run-start-body.js.map +1 -1
  784. package/vendor/agent-cli/dist/src/session/team-persistence.js +1 -1
  785. package/vendor/agent-cli/dist/src/session/team-persistence.js.map +1 -1
  786. package/vendor/agent-cli/dist/src/session/tool-scheduler.d.ts.map +1 -1
  787. package/vendor/agent-cli/dist/src/session/tool-scheduler.js +32 -23
  788. package/vendor/agent-cli/dist/src/session/tool-scheduler.js.map +1 -1
  789. package/vendor/agent-cli/dist/src/session/user-skill-compatibility.d.ts +4 -0
  790. package/vendor/agent-cli/dist/src/session/user-skill-compatibility.d.ts.map +1 -0
  791. package/vendor/agent-cli/dist/src/session/user-skill-compatibility.js +25 -0
  792. package/vendor/agent-cli/dist/src/session/user-skill-compatibility.js.map +1 -0
  793. package/vendor/agent-cli/dist/src/session/user-skill-loaded.d.ts.map +1 -1
  794. package/vendor/agent-cli/dist/src/session/user-skill-loaded.js +2 -1
  795. package/vendor/agent-cli/dist/src/session/user-skill-loaded.js.map +1 -1
  796. package/vendor/agent-cli/dist/src/session/user-skill-prompt.d.ts +4 -0
  797. package/vendor/agent-cli/dist/src/session/user-skill-prompt.d.ts.map +1 -0
  798. package/vendor/agent-cli/dist/src/session/user-skill-prompt.js +15 -0
  799. package/vendor/agent-cli/dist/src/session/user-skill-prompt.js.map +1 -0
  800. package/vendor/agent-cli/dist/src/shared/types.d.ts +50 -3
  801. package/vendor/agent-cli/dist/src/shared/types.d.ts.map +1 -1
  802. package/vendor/agent-cli/dist/src/tools/command-executor.d.ts +3 -0
  803. package/vendor/agent-cli/dist/src/tools/command-executor.d.ts.map +1 -1
  804. package/vendor/agent-cli/dist/src/tools/command-executor.js +42 -5
  805. package/vendor/agent-cli/dist/src/tools/command-executor.js.map +1 -1
  806. package/vendor/agent-cli/dist/src/tools/context-program.d.ts.map +1 -1
  807. package/vendor/agent-cli/dist/src/tools/context-program.js +46 -20
  808. package/vendor/agent-cli/dist/src/tools/context-program.js.map +1 -1
  809. package/vendor/agent-cli/dist/src/tools/file-ops.d.ts +10 -19
  810. package/vendor/agent-cli/dist/src/tools/file-ops.d.ts.map +1 -1
  811. package/vendor/agent-cli/dist/src/tools/file-ops.js +11 -85
  812. package/vendor/agent-cli/dist/src/tools/file-ops.js.map +1 -1
  813. package/vendor/agent-cli/dist/src/tools/file-search.d.ts +29 -0
  814. package/vendor/agent-cli/dist/src/tools/file-search.d.ts.map +1 -0
  815. package/vendor/agent-cli/dist/src/tools/file-search.js +98 -0
  816. package/vendor/agent-cli/dist/src/tools/file-search.js.map +1 -0
  817. package/vendor/agent-cli/dist/src/tools/file-stat.d.ts +9 -0
  818. package/vendor/agent-cli/dist/src/tools/file-stat.d.ts.map +1 -0
  819. package/vendor/agent-cli/dist/src/tools/file-stat.js +29 -0
  820. package/vendor/agent-cli/dist/src/tools/file-stat.js.map +1 -0
  821. package/vendor/agent-cli/dist/src/tools/local-hands.d.ts.map +1 -1
  822. package/vendor/agent-cli/dist/src/tools/local-hands.js +10 -2
  823. package/vendor/agent-cli/dist/src/tools/local-hands.js.map +1 -1
  824. package/vendor/agent-cli/dist/src/tools/tool-contract.gen.d.ts +3 -0
  825. package/vendor/agent-cli/dist/src/tools/tool-contract.gen.d.ts.map +1 -1
  826. package/vendor/agent-cli/dist/src/tools/tool-contract.gen.js +3 -0
  827. package/vendor/agent-cli/dist/src/tools/tool-contract.gen.js.map +1 -1
  828. package/resources/js/context/CLAUDE.md +0 -54
  829. package/resources/js/context/agents/aigc-manager.md +0 -91
  830. package/resources/js/context/knowledge/GameProbe.md +0 -74
  831. package/resources/js/context/skills/aigc-generate/scripts/apply-results.mjs +0 -83
  832. package/resources/js/context/skills/aigc-generate/scripts/config.json +0 -29
  833. package/resources/js/context/skills/aigc-generate/scripts/generate.mjs +0 -1016
  834. package/resources/js/context/skills/aigc-generate/scripts/lib/client.mjs +0 -228
  835. package/resources/js/context/skills/aigc-generate/scripts/lib/ledger.mjs +0 -119
  836. package/resources/js/context/skills/aigc-generate/scripts/lib/nstep-handoff.mjs +0 -100
  837. package/resources/js/context/skills/aigc-generate/scripts/lib/pipelines.mjs +0 -441
  838. package/resources/js/context/skills/aigc-generate/scripts/lib/queue.mjs +0 -283
  839. package/resources/js/context/skills/aigc-generate/scripts/lib/submit.mjs +0 -122
  840. package/resources/js/context/skills/aigc-generate/scripts/worker.mjs +0 -171
  841. package/resources/js/context/skills/asset-search/scripts/recalled_sprite_paths.mjs +0 -47
  842. package/resources/js/context/skills/asset-search/strategies/character2d.md +0 -33
  843. package/resources/js/context/skills/asset-search/strategies/texture-ui.md +0 -35
  844. package/resources/js/context/skills/display-info-setup/SKILL.md +0 -32
  845. package/resources/js/context/skills/display-info-setup/scripts/init_project.mjs +0 -38
  846. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/platform/leaderboard.d.mts +0 -39
  847. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/platform/leaderboard.mjs +0 -1
  848. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/platform/platform-service.mjs +0 -1
  849. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/platform/save.d.mts +0 -49
  850. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/platform/save.mjs +0 -1
  851. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/release.json +0 -37
  852. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tooling/cli.mjs +0 -2
  853. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tooling/project.d.mts +0 -8
  854. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tooling/project.mjs +0 -2
  855. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tooling/vite.d.mts +0 -3
  856. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tooling/vite.mjs +0 -8
  857. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tools/audio.d.mts +0 -20
  858. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tools/audio.mjs +0 -1
  859. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tools/canvas.d.mts +0 -21
  860. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tools/canvas.mjs +0 -1
  861. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tools/input.d.mts +0 -17
  862. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tools/input.mjs +0 -1
  863. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tools/three.d.mts +0 -40
  864. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tools/three.mjs +0 -1
  865. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tools/ui.d.mts +0 -10
  866. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tools/ui.mjs +0 -1
  867. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tools/video.d.mts +0 -8
  868. package/resources/js/context/skills/lightgame-runtime-adapt/project/runtime/lightgame/1.0.0/tools/video.mjs +0 -1
  869. package/resources/js/context/skills/platform-services/assets/release.json +0 -44
  870. package/resources/js/project/.gitattributes +0 -2
  871. package/resources/js/project/gameplay-probe.json +0 -37
  872. package/resources/js/project/package-lock.json +0 -1155
  873. package/resources/js3d/context/CLAUDE.md +0 -50
  874. package/resources/js3d/context/skills/aigc-integration/scripts/config.json +0 -3
  875. package/resources/js3d/context/skills/aigc-integration/scripts/lib/submit.mjs +0 -344
  876. package/resources/js3d/context/skills/aigc-integration/scripts/query-music.mjs +0 -53
  877. package/resources/js3d/context/skills/aigc-integration/scripts/query-results.mjs +0 -53
  878. package/resources/js3d/context/skills/aigc-integration/scripts/submit-cover.mjs +0 -44
  879. package/resources/js3d/context/skills/aigc-integration/scripts/submit-image.mjs +0 -48
  880. package/resources/js3d/context/skills/aigc-integration/scripts/submit-music.mjs +0 -34
  881. package/resources/js3d/context/skills/aigc-integration/scripts/submit-staticmesh.mjs +0 -39
  882. package/resources/js3d/context/skills/platform-services/assets/release.json +0 -44
  883. package/resources/js3d/project/.gitattributes +0 -2
  884. package/resources/js3d/project/gameplay-probe.json +0 -38
  885. package/resources/js3d/project/package-lock.json +0 -1204
  886. package/resources/js3d/project/runtime/lightgame/1.0.0/tools/glb.test.mjs +0 -25
@@ -1,881 +1,862 @@
1
- /**
2
- * 统一输入层:把 PC 键鼠与移动端虚拟控件收敛到**同一套语义接口**。
3
- *
4
- * 落盘位置:`${CLAUDE_PROJECT_DIR}/src/input/input-layer.ts`
5
- *
6
- * Phaser 侧的用法:入口 `main.ts` 建一次(`canvas` 传 `game.canvas`),拿到 `input` 后挂到
7
- * `game.registry` 或模块单例上;Scene 在 `update()` 里读语义接口。
8
- * **不要用 `this.input.on('pointerdown')` 处理同一批玩法动作** —— 那是另一条输入通路,
9
- * 会在 PC 与移动端上各触发一次。Phaser 的指针事件只保留给「世界内点选 / 拖拽世界物体」,
10
- * 且这类交互要按 SKILL.md「四、触点仲裁」确认触点没有被虚拟控件消费。
11
- *
12
- * 三层职责,不要混:
13
- * ① 语义层(本文件的对外接口):`isDown('jump')` / `horizontal()` / `lookDelta()`。
14
- * **业务只认这一层**,因此 PC 与移动端是同一条代码路径,不需要 `if (mobile)`。
15
- * ② 映射层:`input-config.json` 里每个条目同时给出 `pc`(按键名)与 `mobile`(控件描述)。
16
- * 两者映射到同一个语义 key;缺一边等于该平台玩不了。
17
- * ③ 控件层:PC 用键盘事件;移动端用 DOM 虚拟控件(摇杆 / 动作按钮 / 视角滑动区)。
18
- *
19
- * 触点仲裁:**button > joystick > look**。这里靠 DOM 命中测试天然成立 ——
20
- * 动作按钮是滑动区**之后**插入的兄弟节点(同 z-index 下后插入者优先命中),
21
- * 摇杆区与滑动区是互不重叠的左右半屏。一次 pointerdown 只可能落在其中一个元素上,
22
- * 且 `setPointerCapture` 之后该指针的后续事件只发给它 —— 等价于「一根手指自 down 起归属唯一控件」。
23
- * 由此得到两条可以直接依赖的性质:
24
- * - 落在动作按钮上的触点**不会**驱动视角,无需给滑动区配排除区;
25
- * - 拖摇杆时手指划过按钮**不会**误触发按钮(触点已被摇杆捕获)。
26
- */
27
- import {
28
- createActionInput,
29
- createJoystick,
30
- createKeyboard,
31
- } from '../../runtime/lightgame/1.0.0/input.mjs';
32
- import { applyPlatformAttr } from './input-platform';
33
- import type { InputPlatform } from './input-platform';
34
- import { createLookPad } from './look-pad';
35
- import type { LookPad } from './look-pad';
36
- import type { UiStageHandle } from '../display/ui-stage';
37
- import inputConfig from './input-config.json';
38
-
39
- // ─────────────────────── 配置结构(与 input-config.json 一一对应) ───────────────────────
40
-
41
- export interface InputAxisConfig {
42
- pc: {
43
- /** 键位名见 SKILL.md「PC 键位名」 */
44
- horizontal: { negative: readonly string[]; positive: readonly string[] };
45
- vertical: { negative: readonly string[]; positive: readonly string[] };
46
- };
47
- mobile: {
48
- type: 'joystick';
49
- /** 有效拖动半径(设计像素)。**不得小于 40** */
50
- radius: number;
51
- /** 死区比例 [0,1),默认 0.12 */
52
- deadZone?: number;
53
- };
54
- }
55
-
56
- export interface InputActionConfig {
57
- /**
58
- * PC 触发源。两类 token,可混写:
59
- * - 键盘:逐字的 `KeyboardEvent.code`(`KeyJ` / `Space` / `ArrowUp`);
60
- * - 鼠标键:`Mouse0`(左)/ `Mouse1`(中)/ `Mouse2`(右)。
61
- * 鼠标键**不是** `event.code`,由本文件转成 `createActionInput({ buttons })` 回调,
62
- * 与键盘是 OR 关系、边沿检测同一条路径。写错的键名会打 warn(见 `warnSuspectKeyNames`)。
63
- */
64
- pc: readonly string[];
65
- /**
66
- * 触发语义,默认 `'hold'`。
67
- * - `'hold'`:`isDown()` 跟随物理按下(开火、加速、格挡);
68
- * - `'toggle'`:**按一次翻转一次**,`isDown()` 返回锁存态(瞄准镜、自动奔跑、静步)。
69
- * 此时 `wasPressed()` / `wasReleased()` 报的是**锁存开 / 关**的那一帧,
70
- * 不是手指按下 / 抬起 —— 业务不需要自己存 boolean 做翻转。
71
- *
72
- * **写在 action 级而不是 `mobile` 里**:PC 与移动端必须同为 toggle,
73
- * 否则 `isDown()` 在一个平台是瞬时、另一个平台是锁存,业务被迫分平台写两套。
74
- */
75
- mode?: 'hold' | 'toggle';
76
- mobile: {
77
- type: 'button';
78
- /** 按钮文字(图标走 CSS background,见 touch-controls.css) */
79
- label: string;
80
- /** 中心 X。**负数从右边缘算起** */
81
- x: number;
82
- /** 中心 Y。**负数从下边缘算起** */
83
- y: number;
84
- /** 触控半径(设计像素)。**不得小于 40** */
85
- radius: number;
86
- /**
87
- * 建出来就先隐藏。**上下文交互按钮**(靠近才出现的「开门 / 拾取 / 对话」)写 `true`,
88
- * 之后由业务用 `setActionButtonVisible(action, true)` 放出来。
89
- * 不写的话开局会先闪一下按钮,再被业务第一帧的 `setActionButtonVisible(false)` 收掉。
90
- */
91
- hidden?: boolean;
92
- /**
93
- * 按住本按钮拖动时,把指针位移并入 look 通道 ——
94
- * 需求形态是「开火按钮按下即持续开火,拖拽可控制方向」。不写则拖动不影响视角。
95
- *
96
- * 前提是同名 look 通道已在 `looks` 里声明;缺失会打 warn 并忽略。
97
- */
98
- drag?: {
99
- /** 注入哪个 look 通道,默认 `'look'` */
100
- look?: string;
101
- /**
102
- * **相对该 look 通道 `mobile.sensitivity` 的倍率**,默认 1。
103
- * 位移先乘这里、再进 LookPad 乘通道灵敏度,所以两条路的 `invertY` 天然一致。
104
- * 按钮拖拽通常要比滑动区更钝(拇指还要兼顾按住),建议 0.5~0.8。
105
- */
106
- sensitivity?: number;
107
- /**
108
- * 起手死区(CSS 像素),默认 0。
109
- * 按钮本身已是明确的按下意图,一般不需要再过滤;只有按钮很小、按下时容易带位移才调大。
110
- */
111
- deadZonePx?: number;
112
- };
113
- };
114
- }
115
-
116
- export interface InputLookConfig {
117
- /**
118
- * PC:鼠标位移。`requireButton=2` 按住右键拖动转向(**字段缺省时的默认值**);
119
- * `0`=左键;**显式写 `null` = 不限制**,移动鼠标即转向(FPS 标准操作)。
120
- * `null` 与「不写」语义不同,读取一律走 `pcLookRequireButton()`,不要用 `??`。
121
- */
122
- pc: { requireButton?: number | null; sensitivity?: number; invertY?: boolean };
123
- /** 移动端:滑动区几何由 CSS 决定(默认右半屏),不在配置里写坐标 */
124
- mobile: { sensitivity?: number; invertY?: boolean; deadZonePx?: number };
125
- }
126
-
127
- export interface InputConfigFile {
128
- axes: Record<string, InputAxisConfig>;
129
- actions: Record<string, InputActionConfig>;
130
- /** 视角通道:**只在玩家需要主动控制镜头(FPS/TPS)时声明**,其它品类整段不写 */
131
- looks?: Record<string, InputLookConfig>;
132
- }
133
-
134
- // ─────────────────────── 对外接口 ───────────────────────
135
-
136
- /** 轴上两根键的极性统一为「右正 X、下正 Y」,与键盘一致;世界方向转换在消费侧统一做 */
137
- export interface GameInput {
138
- readonly platform: InputPlatform;
139
- /** 每帧一次,**必须在所有消费者之前**调用 */
140
- sample(): void;
141
- /**
142
- * 直接读键盘边沿时需要,在所有消费者之后调用。
143
- * 只用本接口的 `wasPressed/wasReleased` 时,可在 `sample()` 之后立即调用。
144
- */
145
- endFrame(): void;
146
- /** `mode: 'toggle'` 的动作返回**锁存态**(按一次开、再按一次关),不是物理按下 */
147
- isDown(action: string): boolean;
148
- /** toggle 型动作报的是**锁存打开**的那一帧,不是手指按下 */
149
- wasPressed(action: string): boolean;
150
- /** toggle 型动作报的是**锁存关闭**的那一帧,不是手指抬起 */
151
- wasReleased(action: string): boolean;
152
- /**
153
- * 手动设置 `mode: 'toggle'` 动作的锁存态:死亡 / 换弹 / 切武器时强制退出瞄准。
154
- * 在 `sample()` 之后调用 —— 本帧的 `wasPressed` / `wasReleased` 会反映这次变化,
155
- * 下一次 `sample()` 清掉。对 `'hold'` 型动作调用会打 warn 并忽略。
156
- */
157
- setToggle(action: string, on: boolean): void;
158
- /** 语义轴(`move` / …):右正 X、下正的 [-1,1] */
159
- horizontal(axis?: string): number;
160
- vertical(axis?: string): number;
161
- /** 消费型:读一次即清零,**每帧只能读一次** */
162
- lookDelta(look?: string): { x: number; y: number };
163
- isLookActive(look?: string): boolean;
164
- /** 把外部位移并入 look 通道(如「开火按钮按住拖拽也能控向」) */
165
- feedLookDelta(dx: number, dy: number, look?: string): void;
166
- /**
167
- * 显隐**单个**移动端虚拟按钮 —— 上下文交互按钮(靠近宝箱才出现的「开门 / 拾取」)用这个。
168
- * 可以每帧无脑调用,值没变时不做任何事。
169
- *
170
- * **只管移动端 UI,不屏蔽 PC 键位。** PC 上没有虚拟控件,这里是 no-op;
171
- * 业务照常自己判上下文 —— `if (target && input.wasPressed('interact'))` ——
172
- * 这一条判断两端共用,不构成平台分支。
173
- *
174
- * **不要自己去改 `.touch-btn` 的 DOM**:隐藏时必须同时清掉按钮上残留的触点,
175
- * 否则 `display: none` 不保证释放指针捕获(元素仍在文档里),`pointerup` 可能永远收不到,
176
- * `isDown()` 会永久为真(表现为「按钮消失了却一直在开火」)。
177
- *
178
- * 对 `mode: 'toggle'` 的按钮**不清锁存**:`latched` 是两端共享的语义状态,
179
- * 单端的 UI 可见性不该改它。需要退出锁存时显式调 `setToggle(action, false)`。
180
- */
181
- setActionButtonVisible(action: string, visible: boolean): void;
182
- /**
183
- * 改移动端按钮文案:同一个 `interact` 按钮在门前显示「开门」、在 NPC 前显示「对话」。
184
- * PC 上是 no-op —— PC 的操作提示(「按 E 开门」)属于业务 HUD,不在输入层。
185
- */
186
- setActionLabel(action: string, label: string): void;
187
- /** 模态面板打开 / 暂停时隐藏并复位**全部**虚拟控件,避免触点残留与按键卡住 */
188
- setControlsVisible(visible: boolean): void;
189
- dispose(): void;
190
- }
191
-
192
- export interface InputLayerOptions {
193
- /** 游戏容器(模板 `#game`);`data-platform` 写在它上面 */
194
- container: HTMLElement;
195
- /**
196
- * 分辨率适配 skill 的 UI stage 句柄(`src/display/ui-stage.ts`)。
197
- * 虚拟控件按设计像素摆放,尺寸换算取这里的 `scale`(= 短边锁定模型解出的
198
- * viewport 短边 / 1080),**不要取 runtime `createUiStage()` 返回对象的 `scale`** ——
199
- * 那个按构造期设计尺寸算,长边伸缩下会与 stage 实际缩放不一致。
200
- */
201
- ui: UiStageHandle;
202
- /** PC 鼠标视角的监听目标(canvas);键盘监听目标是 window —— canvas 默认不可聚焦,收不到 keydown */
203
- canvas: HTMLCanvasElement;
204
- config?: InputConfigFile;
205
- }
206
-
207
- const DEFAULT_AXIS = 'move';
208
- const DEFAULT_LOOK = 'look';
209
-
210
- export function createInputLayer(options: InputLayerOptions): GameInput {
211
- const { container, ui, canvas } = options;
212
- const config = options.config ?? (inputConfig as unknown as InputConfigFile);
213
- const platform = applyPlatformAttr(container);
214
-
215
- // ── ② 映射层 ──
216
- const pcActions: Record<string, readonly string[]> = {};
217
- const pcAxes: Record<string, { negative?: readonly string[]; positive?: readonly string[] }> = {};
218
- const analog: Record<string, () => number> = {};
219
- /** 动作 → 「当前是否按下」。PC 鼠标键与移动端虚拟按钮都汇到这里,两个平台互斥不会打架 */
220
- const buttons: Record<string, () => boolean> = {};
221
- const heldPointers = new Map<string, Set<number>>();
222
- /** 动作 → 需要的鼠标键(`event.button` 值)。空数组表示该动作只用键盘 */
223
- const pcMouse = new Map<string, number[]>();
224
- /**
225
- * `mode: 'toggle'` 动作的**锁存态**。键的存在与否就是「这个动作是不是 toggle 型」的判据,
226
- * 所以 `latched.has(name)` 与 `latched.get(name)` 分别承担类型判定与取值,不要再存一份 Set。
227
- */
228
- const latched = new Map<string, boolean>();
229
- /** 本帧锁存的翻转方向(`true` = 刚打开)。用来合成 toggle 的 wasPressed / wasReleased */
230
- const latchEdge = new Map<string, boolean>();
231
- /** 动作 → 同步移动端按钮的锁存视觉。PC 无虚拟控件时为空 */
232
- const latchVisuals = new Map<string, (on: boolean) => void>();
233
- /** 按钮拖拽状态的复位钩子(隐藏控件 / dispose 时调用) */
234
- const dragResets: Array<() => void> = [];
235
- /** 动作 → 移动端按钮句柄。**PC 上为空**,所以两个 setter 在 PC 上天然是 no-op */
236
- const mobileButtons = new Map<string, MobileButtonHandle>();
237
- /** 已经报过的未知动作名。两个 setter 通常每帧调用,不去重会刷屏 */
238
- const warnedUnknownActions = new Set<string>();
239
-
240
- /** 动作名写错时两个 setter 会静默失效(PC 上本来就是 no-op,更难发现),这里报一次 */
241
- const isUnknownAction = (api: string, action: string): boolean => {
242
- if (config.actions?.[action]) return false;
243
- if (!warnedUnknownActions.has(action)) {
244
- warnedUnknownActions.add(action);
245
- console.warn(`[input] ${api}("${action}"):该动作不在 input-config.json 的 actions 里`);
246
- }
247
- return true;
248
- };
249
-
250
- for (const [name, action] of Object.entries(config.actions ?? {})) {
251
- // 鼠标键不能交给 keyboard(它只认 KeyboardEvent.code),必须在这里分流
252
- const split = splitPcBinding(action.pc);
253
- pcActions[name] = split.codes;
254
- if (split.mouseButtons.length > 0) pcMouse.set(name, split.mouseButtons);
255
- if (action.mode === 'toggle') latched.set(name, false);
256
- }
257
-
258
- for (const [name, axis] of Object.entries(config.axes ?? {})) {
259
- // createActionInput 的轴 key 是「一个轴一个条目」,与本配置的 h/v 双键结构对齐
260
- pcAxes[`${name}.h`] = axis.pc.horizontal;
261
- pcAxes[`${name}.v`] = axis.pc.vertical;
262
- }
263
-
264
- // 键名写错不会有任何运行时报错(isDown 恒 false),这里把它变成显式 warn。
265
- // **两个平台都校验**:移动端预览时也能发现 PC 配置的拼写错误。
266
- warnSuspectKeyNames(config);
267
-
268
- // ── ③ PC:键盘 + 鼠标视角 ──
269
- // 只在 PC 装配键盘;移动端不装,避免两套输入同时改同一份状态
270
- // (触屏笔记本按 (pointer: coarse) 判为 pc,用键鼠,符合「主要指针是鼠标」的直觉)。
271
- const keyboard =
272
- platform === 'pc'
273
- ? createKeyboard(window, {
274
- blurTarget: window,
275
- visibilityTarget: document,
276
- // 阻止方向键 / 空格滚动页面,否则浏览器会吃掉按键
277
- preventDefault: collectPreventDefault(config),
278
- })
279
- : null;
280
-
281
- /**
282
- * PC 鼠标键。**右键一旦参与输入就必须吃掉 contextmenu**,否则按下右键先弹出系统菜单
283
- * (`looks.*.pc.requireButton` 默认就是右键,所以有 look 通道时基本一定要吃)。
284
- */
285
- const needsRightButton =
286
- [...pcMouse.values()].some((list) => list.includes(2)) ||
287
- Object.values(config.looks ?? {}).some((look) => pcLookRequireButton(look) === 2);
288
- const mouse =
289
- platform === 'pc' && (pcMouse.size > 0 || needsRightButton)
290
- ? createMouseButtons(canvas, { suppressContextMenu: needsRightButton })
291
- : null;
292
- if (mouse) {
293
- for (const [action, list] of pcMouse) {
294
- buttons[action] = () => list.some((button) => mouse.isDown(button));
295
- }
296
- }
297
-
298
- const lookPads = new Map<string, LookPad>();
299
- if (platform === 'pc') {
300
- for (const [name, look] of Object.entries(config.looks ?? {})) {
301
- lookPads.set(
302
- name,
303
- createLookPad(canvas, {
304
- pointerTypes: ['mouse'],
305
- requireButton: pcLookRequireButton(look),
306
- sensitivity: look.pc?.sensitivity,
307
- invertY: look.pc?.invertY,
308
- }),
309
- );
310
- }
311
- }
312
-
313
- // ── ③ 移动端:虚拟控件 ──
314
- // 控件建在 UI stage 的 hud 层里:坐标即设计像素,缩放由 stage 的 transform 承担,
315
- // 因此「半径 72 设计像素」在任何设备上的物理大小都一致。
316
- let controls: HTMLElement | null = null;
317
-
318
- if (platform === 'mobile') {
319
- const root = document.createElement('div');
320
- root.id = 'touch-controls';
321
-
322
- // 视角滑动区先插入(先插入 = 命中优先级低)
323
- for (const [name, look] of Object.entries(config.looks ?? {})) {
324
- const zone = document.createElement('div');
325
- zone.className = 'touch-look-zone';
326
- zone.dataset.look = name;
327
- root.appendChild(zone);
328
- lookPads.set(
329
- name,
330
- createLookPad(zone, {
331
- /**
332
- * **必须带上 `'mouse'`**:桌面浏览器用 `?launchPlatform=mobile` 验收时,
333
- * 指针类型仍然是 mouse。只写 `['touch', 'pen']` 会让滑动区在验收环境里完全不响应 ——
334
- * 而同一形态下摇杆(`createJoystick` 认鼠标左键)和动作按钮(不筛 pointerType)都能用,
335
- * 于是表现为「摇杆能推、按钮能按,唯独视角拖不动」,很容易被误判成 look 区没实现。
336
- * 真机不会产生 mouse 事件,这一项对真机无影响。
337
- *
338
- * `requireButton: 0` 让鼠标只认左键,与 `createJoystick` 的门槛逐字一致;
339
- * touch / pen 不受它约束(见 look-pad.ts 的 `allowed()`:非 mouse 直接放行)。
340
- */
341
- pointerTypes: ['touch', 'pen', 'mouse'],
342
- requireButton: 0,
343
- sensitivity: look.mobile?.sensitivity,
344
- invertY: look.mobile?.invertY,
345
- deadZonePx: look.mobile?.deadZonePx,
346
- }),
347
- );
348
- }
349
-
350
- // 摇杆区(CSS 定为左半屏)。范式实现为**浮动摇杆**(手指落点即圆心):
351
- // 移动端推荐形态,不需要玩家去找固定摇杆的位置。
352
- for (const [name, axis] of Object.entries(config.axes ?? {})) {
353
- if (axis.mobile?.type !== 'joystick') {
354
- console.warn(`[input] 轴 ${name} 的 mobile.type 不是 'joystick',已跳过`);
355
- continue;
356
- }
357
- const zone = document.createElement('div');
358
- zone.className = 'touch-stick-zone';
359
- zone.dataset.axis = name;
360
- const base = document.createElement('div');
361
- base.className = 'touch-stick__base';
362
- const thumb = document.createElement('div');
363
- thumb.className = 'touch-stick__thumb';
364
- base.appendChild(thumb);
365
- zone.appendChild(base);
366
- root.appendChild(zone);
367
-
368
- const radius = axis.mobile.radius;
369
- // 尺寸在配置里(设计像素),这里落到内联样式;CSS 只管居中与配色
370
- base.style.width = `${radius * 2}px`;
371
- base.style.height = `${radius * 2}px`;
372
- thumb.style.width = `${radius}px`;
373
- thumb.style.height = `${radius}px`;
374
- const joystick = createJoystick(zone, {
375
- radius,
376
- deadZone: axis.mobile.deadZone ?? 0.12,
377
- floating: true,
378
- // radius 按设计像素给,这里换算成实际 CSS 像素
379
- scale: () => ui.scale,
380
- blurTarget: window,
381
- onChange: (value) => {
382
- // 居中位移与摇杆位移写进同一个 transform,避免两处争抢(CSS 里不再写 thumb 的 transform)
383
- thumb.style.transform =
384
- `translate(calc(-50% + ${value.x * radius * 0.6}px), calc(-50% + ${value.y * radius * 0.6}px))`;
385
- base.classList.toggle('is-active', value.active);
386
- },
387
- });
388
-
389
- followFloatingStick(zone, base, () => ui.scale);
390
-
391
- analog[`${name}.h`] = () => joystick.value().x;
392
- // 摇杆「下正 Y」与键盘 vertical(负向=W/上)极性一致,**不要在移动端单独取反**
393
- analog[`${name}.v`] = () => joystick.value().y;
394
- }
395
-
396
- // 动作按钮最后插入:同 z-index 下后插入者优先命中 → **button > look** 成立
397
- for (const [action, definition] of Object.entries(config.actions ?? {})) {
398
- const mobile = definition.mobile;
399
- if (mobile?.type !== 'button') {
400
- console.warn(`[input] 动作 ${action} 的 mobile.type 不是 'button',已跳过`);
401
- continue;
402
- }
403
- const button = document.createElement('button');
404
- button.type = 'button';
405
- button.className = 'touch-btn';
406
- button.dataset.action = action;
407
- button.textContent = mobile.label;
408
- // 负值从右 / 下边缘算起:用 right / bottom 表达,转屏与改比例后**不需要重算**
409
- applyEdgeAnchors(button, mobile);
410
- root.appendChild(button);
411
-
412
- const pointers = new Set<number>();
413
- heldPointers.set(action, pointers);
414
- const sync = (): void => {
415
- button.classList.toggle('is-pressed', pointers.size > 0);
416
- };
417
-
418
- if (latched.has(action)) {
419
- // toggle 按钮的「亮」= 锁存开启,与手指是否还按着无关,所以是独立的 class。
420
- // `.is-latched` 在 CSS 里必须排在 `.is-pressed` 之后才能赢样式(同特异度后来者胜)。
421
- button.classList.add('is-toggle');
422
- latchVisuals.set(action, (on) => button.classList.toggle('is-latched', on));
423
- }
424
-
425
- // 「按住持续开火 + 拖拽控向」:拖拽量并入 look 通道,业务侧仍只读一个 lookDelta()
426
- const drag = mobile.drag
427
- ? createButtonDrag(button, action, mobile.drag, () =>
428
- lookPads.get(mobile.drag?.look ?? DEFAULT_LOOK),
429
- )
430
- : null;
431
- if (drag) dragResets.push(drag.reset);
432
-
433
- button.addEventListener('pointerdown', (event) => {
434
- // 捕获失败(指针已失效)不致命:后续 move 由元素自身命中的事件兜底
435
- try {
436
- button.setPointerCapture(event.pointerId);
437
- } catch {
438
- /* ignore */
439
- }
440
- pointers.add(event.pointerId);
441
- // 捕获之后手指拖出按钮外仍归属本按钮:这既让「按住不放继续开火」成立,
442
- // 也让 pointermove 继续发给按钮,拖拽控向才有事件可用
443
- drag?.begin(event);
444
- sync();
445
- event.preventDefault();
446
- });
447
- const release = (event: PointerEvent): void => {
448
- drag?.end(event);
449
- if (!pointers.delete(event.pointerId)) return;
450
- sync();
451
- };
452
- button.addEventListener('pointerup', release);
453
- button.addEventListener('pointercancel', release);
454
- button.addEventListener('lostpointercapture', release);
455
-
456
- buttons[action] = () => pointers.size > 0;
457
-
458
- // 上下文交互按钮:建好即隐藏,等业务判定「够得着」时再放出来
459
- if (mobile.hidden) button.classList.add('is-hidden');
460
- mobileButtons.set(action, {
461
- setVisible(visible) {
462
- // toggle 的第二个参数是「是否加上」,返回值是加完之后 token 在不在 —— 即「现在是否隐藏」
463
- const nowHidden = button.classList.toggle('is-hidden', !visible);
464
- if (!nowHidden) return;
465
- // 隐藏瞬间必须自己清触点:`display: none` 的元素**仍在文档里**,
466
- // 规范不保证释放指针捕获,`pointerup` / `lostpointercapture` 可能永远收不到,
467
- // `pointers` 会残留 → `isDown()` 永久为真。
468
- pointers.clear();
469
- sync();
470
- drag?.reset();
471
- },
472
- setLabel(label) {
473
- button.textContent = label;
474
- },
475
- });
476
- }
477
-
478
- ui.layer('hud').appendChild(root);
479
- controls = root;
480
- }
481
-
482
- // ── ① 语义层:按键与控件的边沿统一由 createActionInput 维护 ──
483
- const actionInput = createActionInput({
484
- keyboard: keyboard ?? undefined,
485
- actions: pcActions,
486
- axes: pcAxes,
487
- buttons,
488
- analog,
489
- });
490
-
491
- return {
492
- platform,
493
- sample() {
494
- actionInput.sample();
495
- // toggle:用**物理按下沿**翻转锁存。合成的边沿只在本帧有效,下一次 sample 清掉。
496
- // 注意只改既有 key 的值,不新增 key,因此边遍历边 set 是安全的。
497
- latchEdge.clear();
498
- for (const [action, on] of latched) {
499
- if (!actionInput.wasPressed(action)) continue;
500
- const next = !on;
501
- latched.set(action, next);
502
- latchEdge.set(action, next);
503
- latchVisuals.get(action)?.(next);
504
- }
505
- },
506
- endFrame() {
507
- keyboard?.endFrame();
508
- },
509
- // toggle 型返回锁存态:`latched.get()` 为 false 时 `??` 不会退化到物理状态(只有 undefined 才会)
510
- isDown: (action) => latched.get(action) ?? actionInput.isDown(action),
511
- wasPressed: (action) =>
512
- latched.has(action) ? latchEdge.get(action) === true : actionInput.wasPressed(action),
513
- wasReleased: (action) =>
514
- latched.has(action) ? latchEdge.get(action) === false : actionInput.wasReleased(action),
515
- setToggle(action, on) {
516
- if (!latched.has(action)) {
517
- console.warn(`[input] 动作 ${action} 不是 mode: 'toggle',setToggle 无效`);
518
- return;
519
- }
520
- if (latched.get(action) === on) return;
521
- latched.set(action, on);
522
- latchEdge.set(action, on);
523
- latchVisuals.get(action)?.(on);
524
- },
525
- horizontal: (axis = DEFAULT_AXIS) => actionInput.axis(`${axis}.h`),
526
- vertical: (axis = DEFAULT_AXIS) => actionInput.axis(`${axis}.v`),
527
- lookDelta: (look = DEFAULT_LOOK) => lookPads.get(look)?.consumeDelta() ?? { x: 0, y: 0 },
528
- isLookActive: (look = DEFAULT_LOOK) => lookPads.get(look)?.isActive() ?? false,
529
- feedLookDelta: (dx, dy, look = DEFAULT_LOOK) => lookPads.get(look)?.feedDelta(dx, dy),
530
- setActionButtonVisible(action, visible) {
531
- if (isUnknownAction('setActionButtonVisible', action)) return;
532
- mobileButtons.get(action)?.setVisible(visible);
533
- },
534
- setActionLabel(action, label) {
535
- if (isUnknownAction('setActionLabel', action)) return;
536
- mobileButtons.get(action)?.setLabel(label);
537
- },
538
- setControlsVisible(visible) {
539
- if (controls) {
540
- controls.style.display = visible ? '' : 'none';
541
- if (!visible) {
542
- // 关闭时复位:否则手指抬起前切走会留下「一直在按」的残留状态
543
- for (const pad of lookPads.values()) pad.reset();
544
- for (const reset of dragResets) reset();
545
- for (const pointers of heldPointers.values()) pointers.clear();
546
- for (const button of controls.querySelectorAll<HTMLElement>('.touch-btn')) {
547
- // 只清按下态:`is-hidden` 是单个按钮的**上下文可用性**,由业务用
548
- // `setActionButtonVisible` 维护,恢复控件时不能把它一起抹掉
549
- // (否则关掉暂停面板,所有上下文按钮会一起冒出来)
550
- button.classList.remove('is-pressed');
551
- }
552
- }
553
- }
554
- // PC 上没有虚拟控件,但同样要清掉按键与鼠标键状态:
555
- // 模态面板打开时不应该角色还在走,也不应该「一直在开火」
556
- if (!visible) {
557
- keyboard?.clear();
558
- mouse?.clear();
559
- }
560
- },
561
- dispose() {
562
- for (const reset of dragResets) reset();
563
- dragResets.length = 0;
564
- latched.clear();
565
- latchEdge.clear();
566
- latchVisuals.clear();
567
- mobileButtons.clear();
568
- warnedUnknownActions.clear();
569
- for (const pad of lookPads.values()) pad.dispose();
570
- lookPads.clear();
571
- keyboard?.dispose();
572
- mouse?.dispose();
573
- actionInput.reset();
574
- controls?.remove();
575
- controls = null;
576
- },
577
- };
578
- }
579
-
580
- // ─────────────────────── 内部工具 ───────────────────────
581
-
582
- /** 单个移动端按钮的运行时句柄。只有移动端会建,PC 上这张表是空的 */
583
- interface MobileButtonHandle {
584
- setVisible(visible: boolean): void;
585
- setLabel(label: string): void;
586
- }
587
-
588
- /**
589
- * PC look 通道的鼠标键门槛。**不要改成 `?? 2`** —— `??` 对 `null` 也生效,
590
- * 会把配置里显式写的 `"requireButton": null`(语义:不限制,移动鼠标即转向,
591
- * FPS/TPS 在 PC 上的标准操作)强制成右键,表现为「视角必须按住右键才能转」。
592
- * 只有「字段缺省」(`undefined`) 才落到默认的右键。
593
- * 这个函数是该语义的唯一出口,`needsRightButton` 的 contextmenu 判断也必须走它,
594
- * 否则配 `null` 时会误判成「用了右键」而多抑制一次右键菜单。
595
- */
596
- function pcLookRequireButton(look: InputLookConfig): number | null {
597
- const required = look.pc?.requireButton;
598
- return required === undefined ? 2 : required;
599
- }
600
-
601
- /** 鼠标键 token:`Mouse0` = 左键、`Mouse1` = 中键、`Mouse2` = 右键(对应 `event.button`) */
602
- const MOUSE_TOKEN = /^Mouse([0-4])$/;
603
-
604
- /** 把 `pc` 数组拆成键盘 code 与鼠标键两组。鼠标键不能进 keyboard,它只认 `event.code` */
605
- function splitPcBinding(names: readonly string[]): { codes: string[]; mouseButtons: number[] } {
606
- const codes: string[] = [];
607
- const mouseButtons: number[] = [];
608
- for (const name of names) {
609
- const matched = MOUSE_TOKEN.exec(name);
610
- if (matched) mouseButtons.push(Number(matched[1]));
611
- else codes.push(name);
612
- }
613
- return { codes, mouseButtons };
614
- }
615
-
616
- export interface MouseButtons {
617
- isDown(button: number): boolean;
618
- clear(): void;
619
- dispose(): void;
620
- }
621
-
622
- /**
623
- * PC 鼠标键状态。只产出**状态量**,边沿(`wasPressed` / `wasReleased`)仍由
624
- * `createActionInput` 统一算 —— 与键盘、移动端虚拟按钮走同一条路径,业务不需要区分来源。
625
- *
626
- * 两个必须这么写的点:
627
- * 1. **抬起监听挂在 window 上**:鼠标按住后移出 canvas 再松开,canvas 收不到 `pointerup`,
628
- * 状态会永久卡在「按下」(表现为松手后还在持续开火)。
629
- * 2. **失焦 / 切标签页一律清空**:期间的抬起事件收不到,回来时状态不可信。
630
- */
631
- function createMouseButtons(
632
- canvas: HTMLElement,
633
- options: { suppressContextMenu: boolean },
634
- ): MouseButtons {
635
- const held = new Set<number>();
636
-
637
- const onDown = (event: PointerEvent): void => {
638
- if (event.pointerType !== 'mouse') return;
639
- held.add(event.button);
640
- };
641
- const onUp = (event: PointerEvent): void => {
642
- if (event.pointerType !== 'mouse') return;
643
- held.delete(event.button);
644
- };
645
- const clear = (): void => held.clear();
646
- const onContextMenu = (event: MouseEvent): void => event.preventDefault();
647
-
648
- canvas.addEventListener('pointerdown', onDown);
649
- window.addEventListener('pointerup', onUp);
650
- window.addEventListener('pointercancel', onUp);
651
- window.addEventListener('blur', clear);
652
- document.addEventListener('visibilitychange', clear);
653
- if (options.suppressContextMenu) canvas.addEventListener('contextmenu', onContextMenu);
654
-
655
- return {
656
- isDown: (button) => held.has(button),
657
- clear,
658
- dispose() {
659
- clear();
660
- canvas.removeEventListener('pointerdown', onDown);
661
- window.removeEventListener('pointerup', onUp);
662
- window.removeEventListener('pointercancel', onUp);
663
- window.removeEventListener('blur', clear);
664
- document.removeEventListener('visibilitychange', clear);
665
- canvas.removeEventListener('contextmenu', onContextMenu);
666
- },
667
- };
668
- }
669
-
670
- /** 旧键名 / 常见笔误 → 正确写法。**只用于 warn 文案,不参与实际匹配** */
671
- const KEY_NAME_HINTS: Record<string, string> = {
672
- UP: 'ArrowUp',
673
- DOWN: 'ArrowDown',
674
- LEFT: 'ArrowLeft',
675
- RIGHT: 'ArrowRight',
676
- SPACE: 'Space',
677
- ENTER: 'Enter',
678
- SHIFT: 'ShiftLeft',
679
- CTRL: 'ControlLeft',
680
- ALT: 'AltLeft',
681
- TAB: 'Tab',
682
- ESC: 'Escape',
683
- MOUSE_LEFT: 'Mouse0',
684
- MOUSE_MIDDLE: 'Mouse1',
685
- MOUSE_RIGHT: 'Mouse2',
686
- };
687
-
688
- /** 能明确判定写错的给出建议;形态合法但不认识的名字放过(无法穷举所有 code) */
689
- function keyNameHint(name: string): string | null {
690
- if (MOUSE_TOKEN.test(name)) return null;
691
- if (KEY_NAME_HINTS[name]) return KEY_NAME_HINTS[name];
692
- if (/^[A-Za-z]$/.test(name)) return `Key${name.toUpperCase()}`;
693
- if (/^[0-9]$/.test(name)) return `Digit${name}`;
694
- if (name !== name.trim()) return `"${name.trim()}"(去掉首尾空格)`;
695
- if (/^[a-z]/.test(name)) return name.charAt(0).toUpperCase() + name.slice(1);
696
- return null;
697
- }
698
-
699
- /**
700
- * 键名写错不会有任何运行时报错 —— `keyboard.isDown()` 逐字比较,不匹配就恒为 `false`,
701
- * 表现是「这个键完全没反应」。这里把静默失效变成一条 warn。
702
- */
703
- function warnSuspectKeyNames(config: InputConfigFile): void {
704
- const names = new Set<string>();
705
- for (const axis of Object.values(config.axes ?? {})) {
706
- for (const group of [axis.pc.horizontal, axis.pc.vertical]) {
707
- group.negative.forEach((name) => names.add(name));
708
- group.positive.forEach((name) => names.add(name));
709
- }
710
- }
711
- for (const action of Object.values(config.actions ?? {})) {
712
- action.pc.forEach((name) => names.add(name));
713
- }
714
- for (const name of names) {
715
- const hint = keyNameHint(name);
716
- if (hint) {
717
- console.warn(
718
- `[input] 键名 "${name}" 不是 KeyboardEvent.code,永远不会触发;应写成 ${hint}`,
719
- );
720
- }
721
- }
722
- }
723
-
724
- /**
725
- * 收集需要 preventDefault 的键,避免方向键滚动页面 / 空格滚动。
726
- *
727
- * **逐字使用配置里的名字,不做任何别名或大小写转换。** 这里转换过一次就会出现
728
- * 「preventDefault 生效、`isDown` 永假」的静默失效 —— `keyboard.isDown()` 用的是配置原值。
729
- * 写错的名字在 `warnSuspectKeyNames` 里报出来,不在这里悄悄纠正。
730
- */
731
- function collectPreventDefault(config: InputConfigFile): string[] {
732
- const codes = new Set<string>();
733
- const add = (name: string): void => {
734
- // 鼠标键不走 keyboard,别塞进它的 preventDefault 名单
735
- if (!MOUSE_TOKEN.test(name)) codes.add(name);
736
- };
737
- for (const axis of Object.values(config.axes ?? {})) {
738
- axis.pc.horizontal.negative.forEach(add);
739
- axis.pc.horizontal.positive.forEach(add);
740
- axis.pc.vertical.negative.forEach(add);
741
- axis.pc.vertical.positive.forEach(add);
742
- }
743
- for (const action of Object.values(config.actions ?? {})) action.pc.forEach(add);
744
- for (const code of ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Space']) codes.add(code);
745
- return [...codes];
746
- }
747
-
748
- interface ButtonDrag {
749
- /** pointerdown 时登记拖拽起点 */
750
- begin(event: PointerEvent): void;
751
- /** pointerup / cancel / lostcapture 时结束 */
752
- end(event: PointerEvent): void;
753
- reset(): void;
754
- }
755
-
756
- /**
757
- * 动作按钮的「按住拖拽 → 并入 look 通道」。
758
- *
759
- * 为什么能直接监听按钮自己的 `pointermove`:按钮在 pointerdown 时做了
760
- * `setPointerCapture`,该指针的后续事件**只**发给按钮,手指拖出按钮外仍然收得到。
761
- * 这同时保证了按住拖出去 `isDown` 不掉(需求里的「按下即持续开火」)。
762
- *
763
- * 三条不能省的性质:
764
- * 1. **只跟随第一根手指。** 同一按钮上的第二根手指不参与转向,否则两指微抖会互相叠加。
765
- * 2. **滑动区已有活跃指针时让位。** 玩家已经有专职转向手指时,按钮的抖动只会给镜头加噪。
766
- * 让位期间**仍然更新 last**,否则恢复瞬间会把攒下的位移一次性灌进去(镜头猛甩)。
767
- * 3. **传原始 CSS 像素位移,不按 `ui.scale` 换算。** LookPad 的量纲就是 CSS 像素
768
- * (滑动区也是直接用 `clientX` 差值),换算会让两条路的速度不一致。
769
- */
770
- function createButtonDrag(
771
- button: HTMLElement,
772
- action: string,
773
- config: NonNullable<InputActionConfig['mobile']['drag']>,
774
- getPad: () => LookPad | undefined,
775
- ): ButtonDrag {
776
- const factor = config.sensitivity ?? 1;
777
- const deadZonePx = Math.max(0, config.deadZonePx ?? 0);
778
- let pointerId: number | null = null;
779
- let startX = 0;
780
- let startY = 0;
781
- let lastX = 0;
782
- let lastY = 0;
783
- /** 是否已越过起手死区 */
784
- let crossed = false;
785
- let warnedMissingLook = false;
786
-
787
- const onMove = (event: PointerEvent): void => {
788
- if (event.pointerId !== pointerId) return;
789
- event.preventDefault();
790
-
791
- if (!crossed) {
792
- // 与 LookPad 一致:越界瞬间把基准挪到当前点,丢弃死区那一小段,避免起手时镜头跳一下
793
- if (Math.hypot(event.clientX - startX, event.clientY - startY) < deadZonePx) return;
794
- crossed = true;
795
- lastX = event.clientX;
796
- lastY = event.clientY;
797
- return;
798
- }
799
-
800
- const dx = event.clientX - lastX;
801
- const dy = event.clientY - lastY;
802
- lastX = event.clientX;
803
- lastY = event.clientY;
804
-
805
- const pad = getPad();
806
- if (!pad) {
807
- if (!warnedMissingLook) {
808
- warnedMissingLook = true;
809
- console.warn(
810
- `[input] 动作 ${action} 配了 mobile.drag 但 look 通道 ` +
811
- `"${config.look ?? 'look'}" 不存在(looks 里没声明),拖拽已忽略`,
812
- );
813
- }
814
- return;
815
- }
816
- // 让位判断放在更新 last 之后 —— 顺序反了会攒出一次猛甩
817
- if (pad.isActive()) return;
818
- pad.feedDelta(dx * factor, dy * factor);
819
- };
820
-
821
- button.addEventListener('pointermove', onMove);
822
-
823
- return {
824
- begin(event) {
825
- if (pointerId !== null) return;
826
- pointerId = event.pointerId;
827
- startX = event.clientX;
828
- startY = event.clientY;
829
- lastX = startX;
830
- lastY = startY;
831
- // 死区为 0 时不能走「丢弃首段」分支,否则第一次 move 的位移会被吞掉
832
- crossed = deadZonePx === 0;
833
- },
834
- end(event) {
835
- if (event.pointerId === pointerId) pointerId = null;
836
- },
837
- reset() {
838
- pointerId = null;
839
- crossed = deadZonePx === 0;
840
- },
841
- };
842
- }
843
-
844
- /** 负值 = 从右 / 下边缘算起。用 right / bottom 表达,尺寸变化时无需重算 */
845
- function applyEdgeAnchors(
846
- element: HTMLElement,
847
- mobile: { x: number; y: number; radius: number },
848
- ): void {
849
- const size = mobile.radius * 2;
850
- element.style.position = 'absolute';
851
- element.style.width = `${size}px`;
852
- element.style.height = `${size}px`;
853
- if (mobile.x < 0) element.style.right = `${-mobile.x - mobile.radius}px`;
854
- else element.style.left = `${mobile.x - mobile.radius}px`;
855
- if (mobile.y < 0) element.style.bottom = `${-mobile.y - mobile.radius}px`;
856
- else element.style.top = `${mobile.y - mobile.radius}px`;
857
- }
858
-
859
- /**
860
- * 浮动摇杆的可视底盘跟随手指落点出现(.is-active 控制显隐,见 touch-controls.css)。
861
- * 落点从 CSS 像素换算回设计像素:除以 stage 的 scale —— 每次读实时值,不要缓存。
862
- *
863
- * **接收门槛必须与 runtime `createJoystick` 的 `down` 逐字一致**(见下面那行)。
864
- * 这两个 handler 挂在同一个元素的同一个 `pointerdown` 上:joystick 负责算轴、
865
- * 本函数负责摆底盘。门槛一旦不同,就会出现「摇杆能推但底盘不跟手」——
866
- * 曾经这里写成 `pointerType === 'mouse'` 就 return,而 joystick 接受鼠标左键,
867
- * 于是桌面用 `?launchPlatform=mobile` 验收时底盘的 left/top 从不写入,
868
- * `position: absolute` 退化为静态位置 + `translate(-50%, -50%)`,
869
- * **整个底盘卡在摇杆区左上角只露出右下 1/4**。这类劈叉不报错,只表现为「一半功能正常」。
870
- */
871
- function followFloatingStick(zone: HTMLElement, base: HTMLElement, getScale: () => number): void {
872
- zone.addEventListener('pointerdown', (event) => {
873
- // 与 createJoystick 同款门槛:鼠标只认左键,touch / pen 一律接收
874
- if (event.pointerType === 'mouse' && event.button !== 0) return;
875
- const stage = zone.closest<HTMLElement>('#ui-stage') ?? zone;
876
- const rect = stage.getBoundingClientRect();
877
- const scale = getScale() || 1;
878
- base.style.left = `${(event.clientX - rect.left) / scale}px`;
879
- base.style.top = `${(event.clientY - rect.top) / scale}px`;
880
- });
881
- }
1
+ /**
2
+ * 统一输入层:把 PC 键鼠与移动端虚拟控件收敛到**同一套语义接口**。
3
+ *
4
+ * 落盘位置:`${CRAFT_PROJECT_DIR}/src/input/input-layer.ts`
5
+ *
6
+ * Phaser 侧的用法:入口 `main.ts` 建一次(`canvas` 传 `game.canvas`),拿到 `input` 后挂到
7
+ * `game.registry` 或模块单例上;Scene 在 `update()` 里读语义接口。
8
+ * **不要用 `this.input.on('pointerdown')` 处理同一批玩法动作** —— 那是另一条输入通路,
9
+ * 会在 PC 与移动端上各触发一次。Phaser 的指针事件只保留给「世界内点选 / 拖拽世界物体」,
10
+ * 且这类交互要按 SKILL.md「四、触点仲裁」确认触点没有被虚拟控件消费。
11
+ *
12
+ * 三层职责,不要混:
13
+ * ① 语义层(本文件的对外接口):`isDown('jump')` / `horizontal()` / `lookDelta()`。
14
+ * **业务只认这一层**,因此 PC 与移动端是同一条代码路径,不需要 `if (mobile)`。
15
+ * ② 映射层:`input-config.json` 里每个条目同时给出 `pc`(按键名)与 `mobile`(控件描述)。
16
+ * 两者映射到同一个语义 key;缺一边等于该平台玩不了。
17
+ * ③ 控件层:PC 用键盘事件;移动端用 DOM 虚拟控件(摇杆 / 动作按钮 / 视角滑动区)。
18
+ *
19
+ * 触点仲裁:**button > joystick > look**。这里靠 DOM 命中测试天然成立 ——
20
+ * 动作按钮是滑动区**之后**插入的兄弟节点(同 z-index 下后插入者优先命中),
21
+ * 摇杆区与滑动区是互不重叠的左下区域与右半屏。一次 pointerdown 只可能落在其中一个元素上,
22
+ * 且 `setPointerCapture` 之后该指针的后续事件只发给它 —— 等价于「一根手指自 down 起归属唯一控件」。
23
+ * 由此得到两条可以直接依赖的性质:
24
+ * - 落在动作按钮上的触点**不会**驱动视角,无需给滑动区配排除区;
25
+ * - 拖摇杆时手指划过按钮**不会**误触发按钮(触点已被摇杆捕获)。
26
+ */
27
+ import {
28
+ createActionInput,
29
+ createJoystick,
30
+ createKeyboard,
31
+ } from './input-primitives';
32
+ import { applyPlatformAttr } from './input-platform';
33
+ import type { InputPlatform } from './input-platform';
34
+ import { createLookPad } from './look-pad';
35
+ import type { LookPad } from './look-pad';
36
+ import type { UiStageHandle } from '../display/ui-stage';
37
+ import inputConfig from './input-config.json';
38
+
39
+ // ─────────────────────── 配置结构(与 input-config.json 一一对应) ───────────────────────
40
+
41
+ export interface InputAxisConfig {
42
+ pc: {
43
+ /** 键位名见 SKILL.md「PC 键位名」 */
44
+ horizontal: { negative: readonly string[]; positive: readonly string[] };
45
+ vertical: { negative: readonly string[]; positive: readonly string[] };
46
+ };
47
+ mobile: {
48
+ type: 'joystick';
49
+ /** 有效拖动半径(设计像素)。**不得小于 40** */
50
+ radius: number;
51
+ /** 死区比例 [0,1),默认 0.12 */
52
+ deadZone?: number;
53
+ };
54
+ }
55
+
56
+ export interface InputActionConfig {
57
+ /**
58
+ * PC 触发源。两类 token,可混写:
59
+ * - 键盘:逐字的 `KeyboardEvent.code`(`KeyJ` / `Space` / `ArrowUp`);
60
+ * - 鼠标键:`Mouse0`(左)/ `Mouse1`(中)/ `Mouse2`(右)。
61
+ * 鼠标键**不是** `event.code`,由本文件转成 `createActionInput({ buttons })` 回调,
62
+ * 与键盘是 OR 关系、边沿检测同一条路径。写错的键名会打 warn(见 `warnSuspectKeyNames`)。
63
+ */
64
+ pc: readonly string[];
65
+ /**
66
+ * 触发语义,默认 `'hold'`。
67
+ * - `'hold'`:`isDown()` 跟随物理按下(开火、加速、格挡);
68
+ * - `'toggle'`:**按一次翻转一次**,`isDown()` 返回锁存态(瞄准镜、自动奔跑、静步)。
69
+ * 此时 `wasPressed()` / `wasReleased()` 报的是**锁存开 / 关**的那一帧,
70
+ * 不是手指按下 / 抬起 —— 业务不需要自己存 boolean 做翻转。
71
+ *
72
+ * **写在 action 级而不是 `mobile` 里**:PC 与移动端必须同为 toggle,
73
+ * 否则 `isDown()` 在一个平台是瞬时、另一个平台是锁存,业务被迫分平台写两套。
74
+ */
75
+ mode?: 'hold' | 'toggle';
76
+ mobile: {
77
+ type: 'button';
78
+ /** 按钮文字(图标走 CSS background,见 touch-controls.css) */
79
+ label: string;
80
+ /** 中心 X。**负数从右边缘算起** */
81
+ x: number;
82
+ /** 中心 Y。**负数从下边缘算起** */
83
+ y: number;
84
+ /** 触控半径(设计像素)。**不得小于 40** */
85
+ radius: number;
86
+ /**
87
+ * 建出来就先隐藏。**上下文交互按钮**(靠近才出现的「开门 / 拾取 / 对话」)写 `true`,
88
+ * 之后由业务用 `setActionButtonVisible(action, true)` 放出来。
89
+ * 不写的话开局会先闪一下按钮,再被业务第一帧的 `setActionButtonVisible(false)` 收掉。
90
+ */
91
+ hidden?: boolean;
92
+ /**
93
+ * 按住本按钮拖动时,把指针位移并入 look 通道 ——
94
+ * 需求形态是「开火按钮按下即持续开火,拖拽可控制方向」。不写则拖动不影响视角。
95
+ *
96
+ * 前提是同名 look 通道已在 `looks` 里声明;缺失会打 warn 并忽略。
97
+ */
98
+ drag?: {
99
+ /** 注入哪个 look 通道,默认 `'look'` */
100
+ look?: string;
101
+ /**
102
+ * **相对该 look 通道 `mobile.sensitivity` 的倍率**,默认 1。
103
+ * 位移先乘这里、再进 LookPad 乘通道灵敏度,所以两条路的 `invertY` 天然一致。
104
+ * 按钮拖拽通常要比滑动区更钝(拇指还要兼顾按住),建议 0.5~0.8。
105
+ */
106
+ sensitivity?: number;
107
+ /**
108
+ * 起手死区(CSS 像素),默认 0。
109
+ * 按钮本身已是明确的按下意图,一般不需要再过滤;只有按钮很小、按下时容易带位移才调大。
110
+ */
111
+ deadZonePx?: number;
112
+ };
113
+ };
114
+ }
115
+
116
+ export interface InputLookConfig {
117
+ /**
118
+ * PC:鼠标位移。`requireButton=2` 按住右键拖动转向(**字段缺省时的默认值**);
119
+ * `0`=左键;**显式写 `null` = 不限制**,移动鼠标即转向(FPS 标准操作)。
120
+ * `null` 与「不写」语义不同,读取一律走 `pcLookRequireButton()`,不要用 `??`。
121
+ */
122
+ pc: { requireButton?: number | null; sensitivity?: number; invertY?: boolean };
123
+ /** 移动端:滑动区几何由 CSS 决定(默认右半屏),不在配置里写坐标 */
124
+ mobile: { sensitivity?: number; invertY?: boolean; deadZonePx?: number };
125
+ }
126
+
127
+ export interface InputConfigFile {
128
+ axes: Record<string, InputAxisConfig>;
129
+ actions: Record<string, InputActionConfig>;
130
+ /** 视角通道:**只在玩家需要主动控制镜头(FPS/TPS)时声明**,其它品类整段不写 */
131
+ looks?: Record<string, InputLookConfig>;
132
+ }
133
+
134
+ // ─────────────────────── 对外接口 ───────────────────────
135
+
136
+ /** 轴上两根键的极性统一为「右正 X、下正 Y」,与键盘一致;世界方向转换在消费侧统一做 */
137
+ export interface GameInput {
138
+ readonly platform: InputPlatform;
139
+ /** 每帧一次,**必须在所有消费者之前**调用 */
140
+ sample(): void;
141
+ /**
142
+ * 直接读键盘边沿时需要,在所有消费者之后调用。
143
+ * 只用本接口的 `wasPressed/wasReleased` 时,可在 `sample()` 之后立即调用。
144
+ */
145
+ endFrame(): void;
146
+ /** `mode: 'toggle'` 的动作返回**锁存态**(按一次开、再按一次关),不是物理按下 */
147
+ isDown(action: string): boolean;
148
+ /** toggle 型动作报的是**锁存打开**的那一帧,不是手指按下 */
149
+ wasPressed(action: string): boolean;
150
+ /** toggle 型动作报的是**锁存关闭**的那一帧,不是手指抬起 */
151
+ wasReleased(action: string): boolean;
152
+ /**
153
+ * 手动设置 `mode: 'toggle'` 动作的锁存态:死亡 / 换弹 / 切武器时强制退出瞄准。
154
+ * 在 `sample()` 之后调用 —— 本帧的 `wasPressed` / `wasReleased` 会反映这次变化,
155
+ * 下一次 `sample()` 清掉。对 `'hold'` 型动作调用会打 warn 并忽略。
156
+ */
157
+ setToggle(action: string, on: boolean): void;
158
+ /** 语义轴(`move` / …):右正 X、下正的 [-1,1] */
159
+ horizontal(axis?: string): number;
160
+ vertical(axis?: string): number;
161
+ /** 消费型:读一次即清零,**每帧只能读一次** */
162
+ lookDelta(look?: string): { x: number; y: number };
163
+ isLookActive(look?: string): boolean;
164
+ /** 把外部位移并入 look 通道(如「开火按钮按住拖拽也能控向」) */
165
+ feedLookDelta(dx: number, dy: number, look?: string): void;
166
+ /**
167
+ * 显隐**单个**移动端虚拟按钮 —— 上下文交互按钮(靠近宝箱才出现的「开门 / 拾取」)用这个。
168
+ * 可以每帧无脑调用,值没变时不做任何事。
169
+ *
170
+ * **只管移动端 UI,不屏蔽 PC 键位。** PC 上没有虚拟控件,这里是 no-op;
171
+ * 业务照常自己判上下文 —— `if (target && input.wasPressed('interact'))` ——
172
+ * 这一条判断两端共用,不构成平台分支。
173
+ *
174
+ * **不要自己去改 `.touch-btn` 的 DOM**:隐藏时必须同时清掉按钮上残留的触点,
175
+ * 否则 `display: none` 不保证释放指针捕获(元素仍在文档里),`pointerup` 可能永远收不到,
176
+ * `isDown()` 会永久为真(表现为「按钮消失了却一直在开火」)。
177
+ *
178
+ * 对 `mode: 'toggle'` 的按钮**不清锁存**:`latched` 是两端共享的语义状态,
179
+ * 单端的 UI 可见性不该改它。需要退出锁存时显式调 `setToggle(action, false)`。
180
+ */
181
+ setActionButtonVisible(action: string, visible: boolean): void;
182
+ /**
183
+ * 改移动端按钮文案:同一个 `interact` 按钮在门前显示「开门」、在 NPC 前显示「对话」。
184
+ * PC 上是 no-op —— PC 的操作提示(「按 E 开门」)属于业务 HUD,不在输入层。
185
+ */
186
+ setActionLabel(action: string, label: string): void;
187
+ /** 模态面板打开 / 暂停时隐藏并复位**全部**虚拟控件,避免触点残留与按键卡住 */
188
+ setControlsVisible(visible: boolean): void;
189
+ dispose(): void;
190
+ }
191
+
192
+ export interface InputLayerOptions {
193
+ /** 游戏容器(模板 `#game`);`data-platform` 写在它上面 */
194
+ container: HTMLElement;
195
+ /**
196
+ * 分辨率适配 skill 的 UI stage 句柄(`src/display/ui-stage.ts`)。
197
+ * 虚拟控件按设计像素摆放,尺寸换算取这里的 `scale`(= 短边锁定模型解出的
198
+ * viewport 短边 / 1080),**不要按固定设计尺寸另算 contain 缩放** ——
199
+ * 长边伸缩下会与 stage 实际缩放不一致。
200
+ */
201
+ ui: UiStageHandle;
202
+ /** PC 鼠标视角的监听目标(canvas);键盘监听目标是 window —— canvas 默认不可聚焦,收不到 keydown */
203
+ canvas: HTMLCanvasElement;
204
+ config?: InputConfigFile;
205
+ }
206
+
207
+ const DEFAULT_AXIS = 'move';
208
+ const DEFAULT_LOOK = 'look';
209
+
210
+ export function createInputLayer(options: InputLayerOptions): GameInput {
211
+ const { container, ui, canvas } = options;
212
+ const config = options.config ?? (inputConfig as unknown as InputConfigFile);
213
+ const platform = applyPlatformAttr(container);
214
+
215
+ // ── ② 映射层 ──
216
+ const pcActions: Record<string, readonly string[]> = {};
217
+ const pcAxes: Record<string, { negative?: readonly string[]; positive?: readonly string[] }> = {};
218
+ const analog: Record<string, () => number> = {};
219
+ /** 动作 → 「当前是否按下」。PC 鼠标键与移动端虚拟按钮都汇到这里,两个平台互斥不会打架 */
220
+ const buttons: Record<string, () => boolean> = {};
221
+ const heldPointers = new Map<string, Set<number>>();
222
+ /** 动作 → 需要的鼠标键(`event.button` 值)。空数组表示该动作只用键盘 */
223
+ const pcMouse = new Map<string, number[]>();
224
+ /**
225
+ * `mode: 'toggle'` 动作的**锁存态**。键的存在与否就是「这个动作是不是 toggle 型」的判据,
226
+ * 所以 `latched.has(name)` 与 `latched.get(name)` 分别承担类型判定与取值,不要再存一份 Set。
227
+ */
228
+ const latched = new Map<string, boolean>();
229
+ /** 本帧锁存的翻转方向(`true` = 刚打开)。用来合成 toggle 的 wasPressed / wasReleased */
230
+ const latchEdge = new Map<string, boolean>();
231
+ /** 动作 → 同步移动端按钮的锁存视觉。PC 无虚拟控件时为空 */
232
+ const latchVisuals = new Map<string, (on: boolean) => void>();
233
+ /** 按钮拖拽状态的复位钩子(隐藏控件 / dispose 时调用) */
234
+ const dragResets: Array<() => void> = [];
235
+ /** 动作 → 移动端按钮句柄。**PC 上为空**,所以两个 setter 在 PC 上天然是 no-op */
236
+ const mobileButtons = new Map<string, MobileButtonHandle>();
237
+ /** 已经报过的未知动作名。两个 setter 通常每帧调用,不去重会刷屏 */
238
+ const warnedUnknownActions = new Set<string>();
239
+
240
+ /** 动作名写错时两个 setter 会静默失效(PC 上本来就是 no-op,更难发现),这里报一次 */
241
+ const isUnknownAction = (api: string, action: string): boolean => {
242
+ if (config.actions?.[action]) return false;
243
+ if (!warnedUnknownActions.has(action)) {
244
+ warnedUnknownActions.add(action);
245
+ console.warn(`[input] ${api}("${action}"):该动作不在 input-config.json 的 actions 里`);
246
+ }
247
+ return true;
248
+ };
249
+
250
+ for (const [name, action] of Object.entries(config.actions ?? {})) {
251
+ // 鼠标键不能交给 keyboard(它只认 KeyboardEvent.code),必须在这里分流
252
+ const split = splitPcBinding(action.pc);
253
+ pcActions[name] = split.codes;
254
+ if (split.mouseButtons.length > 0) pcMouse.set(name, split.mouseButtons);
255
+ if (action.mode === 'toggle') latched.set(name, false);
256
+ }
257
+
258
+ for (const [name, axis] of Object.entries(config.axes ?? {})) {
259
+ // createActionInput 的轴 key 是「一个轴一个条目」,与本配置的 h/v 双键结构对齐
260
+ pcAxes[`${name}.h`] = axis.pc.horizontal;
261
+ pcAxes[`${name}.v`] = axis.pc.vertical;
262
+ }
263
+
264
+ // 键名写错不会有任何运行时报错(isDown 恒 false),这里把它变成显式 warn。
265
+ // **两个平台都校验**:移动端预览时也能发现 PC 配置的拼写错误。
266
+ warnSuspectKeyNames(config);
267
+
268
+ // ── ③ PC:键盘 + 鼠标视角 ──
269
+ // 只在 PC 装配键盘;移动端不装,避免两套输入同时改同一份状态
270
+ // (触屏笔记本按 (pointer: coarse) 判为 pc,用键鼠,符合「主要指针是鼠标」的直觉)。
271
+ const keyboard =
272
+ platform === 'pc'
273
+ ? createKeyboard(window, {
274
+ blurTarget: window,
275
+ visibilityTarget: document,
276
+ // 阻止方向键 / 空格滚动页面,否则浏览器会吃掉按键
277
+ preventDefault: collectPreventDefault(config),
278
+ })
279
+ : null;
280
+
281
+ /**
282
+ * PC 鼠标键。**右键一旦参与输入就必须吃掉 contextmenu**,否则按下右键先弹出系统菜单
283
+ * (`looks.*.pc.requireButton` 默认就是右键,所以有 look 通道时基本一定要吃)。
284
+ */
285
+ const needsRightButton =
286
+ [...pcMouse.values()].some((list) => list.includes(2)) ||
287
+ Object.values(config.looks ?? {}).some((look) => pcLookRequireButton(look) === 2);
288
+ const mouse =
289
+ platform === 'pc' && (pcMouse.size > 0 || needsRightButton)
290
+ ? createMouseButtons(canvas, { suppressContextMenu: needsRightButton })
291
+ : null;
292
+ if (mouse) {
293
+ for (const [action, list] of pcMouse) {
294
+ buttons[action] = () => list.some((button) => mouse.isDown(button));
295
+ }
296
+ }
297
+
298
+ const lookPads = new Map<string, LookPad>();
299
+ if (platform === 'pc') {
300
+ for (const [name, look] of Object.entries(config.looks ?? {})) {
301
+ lookPads.set(
302
+ name,
303
+ createLookPad(canvas, {
304
+ pointerTypes: ['mouse'],
305
+ requireButton: pcLookRequireButton(look),
306
+ sensitivity: look.pc?.sensitivity,
307
+ invertY: look.pc?.invertY,
308
+ }),
309
+ );
310
+ }
311
+ }
312
+
313
+ // ── ③ 移动端:虚拟控件 ──
314
+ // 控件建在 UI stage 的 hud 层里:坐标即设计像素,缩放由 stage 的 transform 承担,
315
+ // 因此「半径 72 设计像素」在任何设备上的物理大小都一致。
316
+ let controls: HTMLElement | null = null;
317
+
318
+ if (platform === 'mobile') {
319
+ const root = document.createElement('div');
320
+ root.id = 'touch-controls';
321
+
322
+ // 视角滑动区先插入(先插入 = 命中优先级低)
323
+ for (const [name, look] of Object.entries(config.looks ?? {})) {
324
+ const zone = document.createElement('div');
325
+ zone.className = 'touch-look-zone';
326
+ zone.dataset.look = name;
327
+ root.appendChild(zone);
328
+ lookPads.set(
329
+ name,
330
+ createLookPad(zone, {
331
+ /**
332
+ * **必须带上 `'mouse'`**:桌面浏览器用 `?launchPlatform=mobile` 验收时,
333
+ * 指针类型仍然是 mouse。只写 `['touch', 'pen']` 会让滑动区在验收环境里完全不响应 ——
334
+ * 而同一形态下摇杆(`createJoystick` 认鼠标左键)和动作按钮(不筛 pointerType)都能用,
335
+ * 于是表现为「摇杆能推、按钮能按,唯独视角拖不动」,很容易被误判成 look 区没实现。
336
+ * 真机不会产生 mouse 事件,这一项对真机无影响。
337
+ *
338
+ * `requireButton: 0` 让鼠标只认左键,与 `createJoystick` 的门槛逐字一致;
339
+ * touch / pen 不受它约束(见 look-pad.ts 的 `allowed()`:非 mouse 直接放行)。
340
+ */
341
+ pointerTypes: ['touch', 'pen', 'mouse'],
342
+ requireButton: 0,
343
+ sensitivity: look.mobile?.sensitivity,
344
+ invertY: look.mobile?.invertY,
345
+ deadZonePx: look.mobile?.deadZonePx,
346
+ }),
347
+ );
348
+ }
349
+
350
+ // 摇杆区(CSS 定为左侧 50% 宽、下方 65% 高)。范式实现为**浮动摇杆**(手指落点即圆心):
351
+ // 移动端推荐形态,不需要玩家去找固定摇杆的位置。
352
+ for (const [name, axis] of Object.entries(config.axes ?? {})) {
353
+ if (axis.mobile?.type !== 'joystick') {
354
+ console.warn(`[input] 轴 ${name} 的 mobile.type 不是 'joystick',已跳过`);
355
+ continue;
356
+ }
357
+ const zone = document.createElement('div');
358
+ zone.className = 'touch-stick-zone';
359
+ zone.dataset.axis = name;
360
+ const base = document.createElement('div');
361
+ base.className = 'touch-stick__base';
362
+ const thumb = document.createElement('div');
363
+ thumb.className = 'touch-stick__thumb';
364
+ base.appendChild(thumb);
365
+ zone.appendChild(base);
366
+ root.appendChild(zone);
367
+
368
+ const radius = axis.mobile.radius;
369
+ // 尺寸在配置里(设计像素),这里落到内联样式;CSS 只管居中与配色
370
+ base.style.width = `${radius * 2}px`;
371
+ base.style.height = `${radius * 2}px`;
372
+ thumb.style.width = `${radius}px`;
373
+ thumb.style.height = `${radius}px`;
374
+ const joystick = createJoystick(zone, {
375
+ radius,
376
+ deadZone: axis.mobile.deadZone ?? 0.12,
377
+ floating: true,
378
+ onStart: (origin) => {
379
+ // base 相对 zone 定位;不能用 stage 原点,否则区域下移会产生偏移。
380
+ const rect = zone.getBoundingClientRect();
381
+ base.style.left = `${(origin.x - rect.left) / ui.scale}px`;
382
+ base.style.top = `${(origin.y - rect.top) / ui.scale}px`;
383
+ },
384
+ // radius 按设计像素给,这里换算成实际 CSS 像素
385
+ scale: () => ui.scale,
386
+ blurTarget: window,
387
+ onChange: (value) => {
388
+ // 居中位移与摇杆位移写进同一个 transform,避免两处争抢(CSS 里不再写 thumb 的 transform)
389
+ thumb.style.transform =
390
+ `translate(calc(-50% + ${value.x * radius * 0.6}px), calc(-50% + ${value.y * radius * 0.6}px))`;
391
+ base.classList.toggle('is-active', value.active);
392
+ },
393
+ });
394
+
395
+
396
+ analog[`${name}.h`] = () => joystick.value().x;
397
+ // 摇杆「下正 Y」与键盘 vertical(负向=W/上)极性一致,**不要在移动端单独取反**
398
+ analog[`${name}.v`] = () => joystick.value().y;
399
+ }
400
+
401
+ // 动作按钮最后插入:同 z-index 下后插入者优先命中 → **button > look** 成立
402
+ for (const [action, definition] of Object.entries(config.actions ?? {})) {
403
+ const mobile = definition.mobile;
404
+ if (mobile?.type !== 'button') {
405
+ console.warn(`[input] 动作 ${action} 的 mobile.type 不是 'button',已跳过`);
406
+ continue;
407
+ }
408
+ const button = document.createElement('button');
409
+ button.type = 'button';
410
+ button.className = 'touch-btn';
411
+ button.dataset.action = action;
412
+ button.textContent = mobile.label;
413
+ // 负值从右 / 下边缘算起:用 right / bottom 表达,转屏与改比例后**不需要重算**
414
+ applyEdgeAnchors(button, mobile);
415
+ root.appendChild(button);
416
+
417
+ const pointers = new Set<number>();
418
+ heldPointers.set(action, pointers);
419
+ const sync = (): void => {
420
+ button.classList.toggle('is-pressed', pointers.size > 0);
421
+ };
422
+
423
+ if (latched.has(action)) {
424
+ // toggle 按钮的「亮」= 锁存开启,与手指是否还按着无关,所以是独立的 class。
425
+ // `.is-latched` 在 CSS 里必须排在 `.is-pressed` 之后才能赢样式(同特异度后来者胜)。
426
+ button.classList.add('is-toggle');
427
+ latchVisuals.set(action, (on) => button.classList.toggle('is-latched', on));
428
+ }
429
+
430
+ // 「按住持续开火 + 拖拽控向」:拖拽量并入 look 通道,业务侧仍只读一个 lookDelta()
431
+ const drag = mobile.drag
432
+ ? createButtonDrag(button, action, mobile.drag, () =>
433
+ lookPads.get(mobile.drag?.look ?? DEFAULT_LOOK),
434
+ )
435
+ : null;
436
+ if (drag) dragResets.push(drag.reset);
437
+
438
+ button.addEventListener('pointerdown', (event) => {
439
+ // 捕获失败(指针已失效)不致命:后续 move 由元素自身命中的事件兜底
440
+ try {
441
+ button.setPointerCapture(event.pointerId);
442
+ } catch {
443
+ /* ignore */
444
+ }
445
+ pointers.add(event.pointerId);
446
+ // 捕获之后手指拖出按钮外仍归属本按钮:这既让「按住不放继续开火」成立,
447
+ // 也让 pointermove 继续发给按钮,拖拽控向才有事件可用
448
+ drag?.begin(event);
449
+ sync();
450
+ event.preventDefault();
451
+ });
452
+ const release = (event: PointerEvent): void => {
453
+ drag?.end(event);
454
+ if (!pointers.delete(event.pointerId)) return;
455
+ sync();
456
+ };
457
+ button.addEventListener('pointerup', release);
458
+ button.addEventListener('pointercancel', release);
459
+ button.addEventListener('lostpointercapture', release);
460
+
461
+ buttons[action] = () => pointers.size > 0;
462
+
463
+ // 上下文交互按钮:建好即隐藏,等业务判定「够得着」时再放出来
464
+ if (mobile.hidden) button.classList.add('is-hidden');
465
+ mobileButtons.set(action, {
466
+ setVisible(visible) {
467
+ // toggle 的第二个参数是「是否加上」,返回值是加完之后 token 在不在 —— 即「现在是否隐藏」
468
+ const nowHidden = button.classList.toggle('is-hidden', !visible);
469
+ if (!nowHidden) return;
470
+ // 隐藏瞬间必须自己清触点:`display: none` 的元素**仍在文档里**,
471
+ // 规范不保证释放指针捕获,`pointerup` / `lostpointercapture` 可能永远收不到,
472
+ // `pointers` 会残留 → `isDown()` 永久为真。
473
+ pointers.clear();
474
+ sync();
475
+ drag?.reset();
476
+ },
477
+ setLabel(label) {
478
+ button.textContent = label;
479
+ },
480
+ });
481
+ }
482
+
483
+ ui.layer('hud').appendChild(root);
484
+ controls = root;
485
+ }
486
+
487
+ // ── ① 语义层:按键与控件的边沿统一由 createActionInput 维护 ──
488
+ const actionInput = createActionInput({
489
+ keyboard: keyboard ?? undefined,
490
+ actions: pcActions,
491
+ axes: pcAxes,
492
+ buttons,
493
+ analog,
494
+ });
495
+
496
+ return {
497
+ platform,
498
+ sample() {
499
+ actionInput.sample();
500
+ // toggle:用**物理按下沿**翻转锁存。合成的边沿只在本帧有效,下一次 sample 清掉。
501
+ // 注意只改既有 key 的值,不新增 key,因此边遍历边 set 是安全的。
502
+ latchEdge.clear();
503
+ for (const [action, on] of latched) {
504
+ if (!actionInput.wasPressed(action)) continue;
505
+ const next = !on;
506
+ latched.set(action, next);
507
+ latchEdge.set(action, next);
508
+ latchVisuals.get(action)?.(next);
509
+ }
510
+ },
511
+ endFrame() {
512
+ keyboard?.endFrame();
513
+ },
514
+ // toggle 型返回锁存态:`latched.get()` 为 false 时 `??` 不会退化到物理状态(只有 undefined 才会)
515
+ isDown: (action) => latched.get(action) ?? actionInput.isDown(action),
516
+ wasPressed: (action) =>
517
+ latched.has(action) ? latchEdge.get(action) === true : actionInput.wasPressed(action),
518
+ wasReleased: (action) =>
519
+ latched.has(action) ? latchEdge.get(action) === false : actionInput.wasReleased(action),
520
+ setToggle(action, on) {
521
+ if (!latched.has(action)) {
522
+ console.warn(`[input] 动作 ${action} 不是 mode: 'toggle',setToggle 无效`);
523
+ return;
524
+ }
525
+ if (latched.get(action) === on) return;
526
+ latched.set(action, on);
527
+ latchEdge.set(action, on);
528
+ latchVisuals.get(action)?.(on);
529
+ },
530
+ horizontal: (axis = DEFAULT_AXIS) => actionInput.axis(`${axis}.h`),
531
+ vertical: (axis = DEFAULT_AXIS) => actionInput.axis(`${axis}.v`),
532
+ lookDelta: (look = DEFAULT_LOOK) => lookPads.get(look)?.consumeDelta() ?? { x: 0, y: 0 },
533
+ isLookActive: (look = DEFAULT_LOOK) => lookPads.get(look)?.isActive() ?? false,
534
+ feedLookDelta: (dx, dy, look = DEFAULT_LOOK) => lookPads.get(look)?.feedDelta(dx, dy),
535
+ setActionButtonVisible(action, visible) {
536
+ if (isUnknownAction('setActionButtonVisible', action)) return;
537
+ mobileButtons.get(action)?.setVisible(visible);
538
+ },
539
+ setActionLabel(action, label) {
540
+ if (isUnknownAction('setActionLabel', action)) return;
541
+ mobileButtons.get(action)?.setLabel(label);
542
+ },
543
+ setControlsVisible(visible) {
544
+ if (controls) {
545
+ controls.style.display = visible ? '' : 'none';
546
+ if (!visible) {
547
+ // 关闭时复位:否则手指抬起前切走会留下「一直在按」的残留状态
548
+ for (const pad of lookPads.values()) pad.reset();
549
+ for (const reset of dragResets) reset();
550
+ for (const pointers of heldPointers.values()) pointers.clear();
551
+ for (const button of controls.querySelectorAll<HTMLElement>('.touch-btn')) {
552
+ // 只清按下态:`is-hidden` 是单个按钮的**上下文可用性**,由业务用
553
+ // `setActionButtonVisible` 维护,恢复控件时不能把它一起抹掉
554
+ // (否则关掉暂停面板,所有上下文按钮会一起冒出来)
555
+ button.classList.remove('is-pressed');
556
+ }
557
+ }
558
+ }
559
+ // PC 上没有虚拟控件,但同样要清掉按键与鼠标键状态:
560
+ // 模态面板打开时不应该角色还在走,也不应该「一直在开火」
561
+ if (!visible) {
562
+ keyboard?.clear();
563
+ mouse?.clear();
564
+ }
565
+ },
566
+ dispose() {
567
+ for (const reset of dragResets) reset();
568
+ dragResets.length = 0;
569
+ latched.clear();
570
+ latchEdge.clear();
571
+ latchVisuals.clear();
572
+ mobileButtons.clear();
573
+ warnedUnknownActions.clear();
574
+ for (const pad of lookPads.values()) pad.dispose();
575
+ lookPads.clear();
576
+ keyboard?.dispose();
577
+ mouse?.dispose();
578
+ actionInput.reset();
579
+ controls?.remove();
580
+ controls = null;
581
+ },
582
+ };
583
+ }
584
+
585
+ // ─────────────────────── 内部工具 ───────────────────────
586
+
587
+ /** 单个移动端按钮的运行时句柄。只有移动端会建,PC 上这张表是空的 */
588
+ interface MobileButtonHandle {
589
+ setVisible(visible: boolean): void;
590
+ setLabel(label: string): void;
591
+ }
592
+
593
+ /**
594
+ * PC look 通道的鼠标键门槛。**不要改成 `?? 2`** —— `??` 对 `null` 也生效,
595
+ * 会把配置里显式写的 `"requireButton": null`(语义:不限制,移动鼠标即转向,
596
+ * FPS/TPS 在 PC 上的标准操作)强制成右键,表现为「视角必须按住右键才能转」。
597
+ * 只有「字段缺省」(`undefined`) 才落到默认的右键。
598
+ * 这个函数是该语义的唯一出口,`needsRightButton` 的 contextmenu 判断也必须走它,
599
+ * 否则配 `null` 时会误判成「用了右键」而多抑制一次右键菜单。
600
+ */
601
+ function pcLookRequireButton(look: InputLookConfig): number | null {
602
+ const required = look.pc?.requireButton;
603
+ return required === undefined ? 2 : required;
604
+ }
605
+
606
+ /** 鼠标键 token:`Mouse0` = 左键、`Mouse1` = 中键、`Mouse2` = 右键(对应 `event.button`) */
607
+ const MOUSE_TOKEN = /^Mouse([0-4])$/;
608
+
609
+ /** 把 `pc` 数组拆成键盘 code 与鼠标键两组。鼠标键不能进 keyboard,它只认 `event.code` */
610
+ function splitPcBinding(names: readonly string[]): { codes: string[]; mouseButtons: number[] } {
611
+ const codes: string[] = [];
612
+ const mouseButtons: number[] = [];
613
+ for (const name of names) {
614
+ const matched = MOUSE_TOKEN.exec(name);
615
+ if (matched) mouseButtons.push(Number(matched[1]));
616
+ else codes.push(name);
617
+ }
618
+ return { codes, mouseButtons };
619
+ }
620
+
621
+ export interface MouseButtons {
622
+ isDown(button: number): boolean;
623
+ clear(): void;
624
+ dispose(): void;
625
+ }
626
+
627
+ /**
628
+ * PC 鼠标键状态。只产出**状态量**,边沿(`wasPressed` / `wasReleased`)仍由
629
+ * `createActionInput` 统一算 —— 与键盘、移动端虚拟按钮走同一条路径,业务不需要区分来源。
630
+ *
631
+ * 两个必须这么写的点:
632
+ * 1. **抬起监听挂在 window 上**:鼠标按住后移出 canvas 再松开,canvas 收不到 `pointerup`,
633
+ * 状态会永久卡在「按下」(表现为松手后还在持续开火)。
634
+ * 2. **失焦 / 切标签页一律清空**:期间的抬起事件收不到,回来时状态不可信。
635
+ */
636
+ function createMouseButtons(
637
+ canvas: HTMLElement,
638
+ options: { suppressContextMenu: boolean },
639
+ ): MouseButtons {
640
+ const held = new Set<number>();
641
+
642
+ const onDown = (event: PointerEvent): void => {
643
+ if (event.pointerType !== 'mouse') return;
644
+ held.add(event.button);
645
+ };
646
+ const onUp = (event: PointerEvent): void => {
647
+ if (event.pointerType !== 'mouse') return;
648
+ held.delete(event.button);
649
+ };
650
+ const clear = (): void => held.clear();
651
+ const onContextMenu = (event: MouseEvent): void => event.preventDefault();
652
+
653
+ canvas.addEventListener('pointerdown', onDown);
654
+ window.addEventListener('pointerup', onUp);
655
+ window.addEventListener('pointercancel', onUp);
656
+ window.addEventListener('blur', clear);
657
+ document.addEventListener('visibilitychange', clear);
658
+ if (options.suppressContextMenu) canvas.addEventListener('contextmenu', onContextMenu);
659
+
660
+ return {
661
+ isDown: (button) => held.has(button),
662
+ clear,
663
+ dispose() {
664
+ clear();
665
+ canvas.removeEventListener('pointerdown', onDown);
666
+ window.removeEventListener('pointerup', onUp);
667
+ window.removeEventListener('pointercancel', onUp);
668
+ window.removeEventListener('blur', clear);
669
+ document.removeEventListener('visibilitychange', clear);
670
+ canvas.removeEventListener('contextmenu', onContextMenu);
671
+ },
672
+ };
673
+ }
674
+
675
+ /** 旧键名 / 常见笔误 → 正确写法。**只用于 warn 文案,不参与实际匹配** */
676
+ const KEY_NAME_HINTS: Record<string, string> = {
677
+ UP: 'ArrowUp',
678
+ DOWN: 'ArrowDown',
679
+ LEFT: 'ArrowLeft',
680
+ RIGHT: 'ArrowRight',
681
+ SPACE: 'Space',
682
+ ENTER: 'Enter',
683
+ SHIFT: 'ShiftLeft',
684
+ CTRL: 'ControlLeft',
685
+ ALT: 'AltLeft',
686
+ TAB: 'Tab',
687
+ ESC: 'Escape',
688
+ MOUSE_LEFT: 'Mouse0',
689
+ MOUSE_MIDDLE: 'Mouse1',
690
+ MOUSE_RIGHT: 'Mouse2',
691
+ };
692
+
693
+ /** 能明确判定写错的给出建议;形态合法但不认识的名字放过(无法穷举所有 code) */
694
+ function keyNameHint(name: string): string | null {
695
+ if (MOUSE_TOKEN.test(name)) return null;
696
+ if (KEY_NAME_HINTS[name]) return KEY_NAME_HINTS[name];
697
+ if (/^[A-Za-z]$/.test(name)) return `Key${name.toUpperCase()}`;
698
+ if (/^[0-9]$/.test(name)) return `Digit${name}`;
699
+ if (name !== name.trim()) return `"${name.trim()}"(去掉首尾空格)`;
700
+ if (/^[a-z]/.test(name)) return name.charAt(0).toUpperCase() + name.slice(1);
701
+ return null;
702
+ }
703
+
704
+ /**
705
+ * 键名写错不会有任何运行时报错 —— `keyboard.isDown()` 逐字比较,不匹配就恒为 `false`,
706
+ * 表现是「这个键完全没反应」。这里把静默失效变成一条 warn。
707
+ */
708
+ function warnSuspectKeyNames(config: InputConfigFile): void {
709
+ const names = new Set<string>();
710
+ for (const axis of Object.values(config.axes ?? {})) {
711
+ for (const group of [axis.pc.horizontal, axis.pc.vertical]) {
712
+ group.negative.forEach((name) => names.add(name));
713
+ group.positive.forEach((name) => names.add(name));
714
+ }
715
+ }
716
+ for (const action of Object.values(config.actions ?? {})) {
717
+ action.pc.forEach((name) => names.add(name));
718
+ }
719
+ for (const name of names) {
720
+ const hint = keyNameHint(name);
721
+ if (hint) {
722
+ console.warn(
723
+ `[input] 键名 "${name}" 不是 KeyboardEvent.code,永远不会触发;应写成 ${hint}`,
724
+ );
725
+ }
726
+ }
727
+ }
728
+
729
+ /**
730
+ * 收集需要 preventDefault 的键,避免方向键滚动页面 / 空格滚动。
731
+ *
732
+ * **逐字使用配置里的名字,不做任何别名或大小写转换。** 这里转换过一次就会出现
733
+ * 「preventDefault 生效、`isDown` 永假」的静默失效 —— `keyboard.isDown()` 用的是配置原值。
734
+ * 写错的名字在 `warnSuspectKeyNames` 里报出来,不在这里悄悄纠正。
735
+ */
736
+ function collectPreventDefault(config: InputConfigFile): string[] {
737
+ const codes = new Set<string>();
738
+ const add = (name: string): void => {
739
+ // 鼠标键不走 keyboard,别塞进它的 preventDefault 名单
740
+ if (!MOUSE_TOKEN.test(name)) codes.add(name);
741
+ };
742
+ for (const axis of Object.values(config.axes ?? {})) {
743
+ axis.pc.horizontal.negative.forEach(add);
744
+ axis.pc.horizontal.positive.forEach(add);
745
+ axis.pc.vertical.negative.forEach(add);
746
+ axis.pc.vertical.positive.forEach(add);
747
+ }
748
+ for (const action of Object.values(config.actions ?? {})) action.pc.forEach(add);
749
+ for (const code of ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Space']) codes.add(code);
750
+ return [...codes];
751
+ }
752
+
753
+ interface ButtonDrag {
754
+ /** pointerdown 时登记拖拽起点 */
755
+ begin(event: PointerEvent): void;
756
+ /** pointerup / cancel / lostcapture 时结束 */
757
+ end(event: PointerEvent): void;
758
+ reset(): void;
759
+ }
760
+
761
+ /**
762
+ * 动作按钮的「按住拖拽 → 并入 look 通道」。
763
+ *
764
+ * 为什么能直接监听按钮自己的 `pointermove`:按钮在 pointerdown 时做了
765
+ * `setPointerCapture`,该指针的后续事件**只**发给按钮,手指拖出按钮外仍然收得到。
766
+ * 这同时保证了按住拖出去 `isDown` 不掉(需求里的「按下即持续开火」)。
767
+ *
768
+ * 三条不能省的性质:
769
+ * 1. **只跟随第一根手指。** 同一按钮上的第二根手指不参与转向,否则两指微抖会互相叠加。
770
+ * 2. **滑动区已有活跃指针时让位。** 玩家已经有专职转向手指时,按钮的抖动只会给镜头加噪。
771
+ * 让位期间**仍然更新 last**,否则恢复瞬间会把攒下的位移一次性灌进去(镜头猛甩)。
772
+ * 3. **传原始 CSS 像素位移,不按 `ui.scale` 换算。** LookPad 的量纲就是 CSS 像素
773
+ * (滑动区也是直接用 `clientX` 差值),换算会让两条路的速度不一致。
774
+ */
775
+ function createButtonDrag(
776
+ button: HTMLElement,
777
+ action: string,
778
+ config: NonNullable<InputActionConfig['mobile']['drag']>,
779
+ getPad: () => LookPad | undefined,
780
+ ): ButtonDrag {
781
+ const factor = config.sensitivity ?? 1;
782
+ const deadZonePx = Math.max(0, config.deadZonePx ?? 0);
783
+ let pointerId: number | null = null;
784
+ let startX = 0;
785
+ let startY = 0;
786
+ let lastX = 0;
787
+ let lastY = 0;
788
+ /** 是否已越过起手死区 */
789
+ let crossed = false;
790
+ let warnedMissingLook = false;
791
+
792
+ const onMove = (event: PointerEvent): void => {
793
+ if (event.pointerId !== pointerId) return;
794
+ event.preventDefault();
795
+
796
+ if (!crossed) {
797
+ // 与 LookPad 一致:越界瞬间把基准挪到当前点,丢弃死区那一小段,避免起手时镜头跳一下
798
+ if (Math.hypot(event.clientX - startX, event.clientY - startY) < deadZonePx) return;
799
+ crossed = true;
800
+ lastX = event.clientX;
801
+ lastY = event.clientY;
802
+ return;
803
+ }
804
+
805
+ const dx = event.clientX - lastX;
806
+ const dy = event.clientY - lastY;
807
+ lastX = event.clientX;
808
+ lastY = event.clientY;
809
+
810
+ const pad = getPad();
811
+ if (!pad) {
812
+ if (!warnedMissingLook) {
813
+ warnedMissingLook = true;
814
+ console.warn(
815
+ `[input] 动作 ${action} 配了 mobile.drag 但 look 通道 ` +
816
+ `"${config.look ?? 'look'}" 不存在(looks 里没声明),拖拽已忽略`,
817
+ );
818
+ }
819
+ return;
820
+ }
821
+ // 让位判断放在更新 last 之后 —— 顺序反了会攒出一次猛甩
822
+ if (pad.isActive()) return;
823
+ pad.feedDelta(dx * factor, dy * factor);
824
+ };
825
+
826
+ button.addEventListener('pointermove', onMove);
827
+
828
+ return {
829
+ begin(event) {
830
+ if (pointerId !== null) return;
831
+ pointerId = event.pointerId;
832
+ startX = event.clientX;
833
+ startY = event.clientY;
834
+ lastX = startX;
835
+ lastY = startY;
836
+ // 死区为 0 时不能走「丢弃首段」分支,否则第一次 move 的位移会被吞掉
837
+ crossed = deadZonePx === 0;
838
+ },
839
+ end(event) {
840
+ if (event.pointerId === pointerId) pointerId = null;
841
+ },
842
+ reset() {
843
+ pointerId = null;
844
+ crossed = deadZonePx === 0;
845
+ },
846
+ };
847
+ }
848
+
849
+ /** 负值 = 从右 / 下边缘算起。用 right / bottom 表达,尺寸变化时无需重算 */
850
+ function applyEdgeAnchors(
851
+ element: HTMLElement,
852
+ mobile: { x: number; y: number; radius: number },
853
+ ): void {
854
+ const size = mobile.radius * 2;
855
+ element.style.position = 'absolute';
856
+ element.style.width = `${size}px`;
857
+ element.style.height = `${size}px`;
858
+ if (mobile.x < 0) element.style.right = `${-mobile.x - mobile.radius}px`;
859
+ else element.style.left = `${mobile.x - mobile.radius}px`;
860
+ if (mobile.y < 0) element.style.bottom = `${-mobile.y - mobile.radius}px`;
861
+ else element.style.top = `${mobile.y - mobile.radius}px`;
862
+ }