@playcraft/skills 0.0.2

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 (479) hide show
  1. package/README.md +333 -0
  2. package/dist/src/index.d.ts +3 -0
  3. package/dist/src/index.d.ts.map +1 -0
  4. package/dist/src/index.js +2 -0
  5. package/dist/src/index.js.map +1 -0
  6. package/dist/src/skills.loader.d.ts +31 -0
  7. package/dist/src/skills.loader.d.ts.map +1 -0
  8. package/dist/src/skills.loader.js +200 -0
  9. package/dist/src/skills.loader.js.map +1 -0
  10. package/dist/src/skills.types.d.ts +44 -0
  11. package/dist/src/skills.types.d.ts.map +1 -0
  12. package/dist/src/skills.types.js +9 -0
  13. package/dist/src/skills.types.js.map +1 -0
  14. package/package.json +35 -0
  15. package/skills/2048_core.aigameplay/SKILL.md +123 -0
  16. package/skills/2048_core.aigameplay/manifest.json +159 -0
  17. package/skills/2048_core.aigameplay/ref/pgs-schema.json +194 -0
  18. package/skills/2048_core.aigameplay/ref/reducer.template.ts +189 -0
  19. package/skills/SKILL.md +46 -0
  20. package/skills/ad_compliance_rules.aiconfig/SKILL.md +85 -0
  21. package/skills/ad_compliance_rules.aiconfig/manifest.json +60 -0
  22. package/skills/agent_remix_orchestrator.aicomponent/SKILL.md +257 -0
  23. package/skills/agent_remix_orchestrator.aicomponent/manifest.json +12 -0
  24. package/skills/app_metadata.aiconfig/SKILL.md +53 -0
  25. package/skills/app_metadata.aiconfig/manifest.json +32 -0
  26. package/skills/appear_sfx.aiaudio/SKILL.md +59 -0
  27. package/skills/appear_sfx.aiaudio/manifest.json +45 -0
  28. package/skills/appear_sfx.aiaudio/ref/appear.mp3 +0 -0
  29. package/skills/arrow_move_error_sfx.aiaudio/SKILL.md +59 -0
  30. package/skills/arrow_move_error_sfx.aiaudio/manifest.json +45 -0
  31. package/skills/arrow_move_error_sfx.aiaudio/ref/arrow_move_error.mp3 +0 -0
  32. package/skills/arrow_path_data_format.aicomponent/SKILL.md +152 -0
  33. package/skills/arrow_path_data_format.aicomponent/manifest.json +57 -0
  34. package/skills/arrow_path_data_format.aicomponent/ref/LevelParser.ts +188 -0
  35. package/skills/arrow_path_data_format.aicomponent/ref/LevelTypes.ts +131 -0
  36. package/skills/arrow_pick_match_rules.aigameplay/SKILL.md +117 -0
  37. package/skills/arrow_pick_match_rules.aigameplay/manifest.json +105 -0
  38. package/skills/arrow_pick_match_rules.aigameplay/ref/pgs-schema.json +180 -0
  39. package/skills/asset_pipeline_scripts.aicomponent/SKILL.md +117 -0
  40. package/skills/asset_pipeline_scripts.aicomponent/manifest.json +17 -0
  41. package/skills/asset_pipeline_scripts.aicomponent/ref/gen-sprite.sh +105 -0
  42. package/skills/ball_sort.aigameplay/SKILL.md +109 -0
  43. package/skills/ball_sort.aigameplay/manifest.json +155 -0
  44. package/skills/ball_sort.aigameplay/ref/pgs-schema.json +192 -0
  45. package/skills/ball_sort.aigameplay/ref/reducer.template.ts +156 -0
  46. package/skills/basketball_shot.aigameplay/SKILL.md +94 -0
  47. package/skills/basketball_shot.aigameplay/manifest.json +150 -0
  48. package/skills/basketball_shot.aigameplay/ref/pgs-schema.json +229 -0
  49. package/skills/basketball_shot.aigameplay/ref/reducer.template.ts +189 -0
  50. package/skills/bg_music.aiaudio/SKILL.md +61 -0
  51. package/skills/bg_music.aiaudio/manifest.json +48 -0
  52. package/skills/bg_music.aiaudio/ref/bg.mp3 +0 -0
  53. package/skills/big_watermelon.aigameplay/SKILL.md +94 -0
  54. package/skills/big_watermelon.aigameplay/manifest.json +155 -0
  55. package/skills/big_watermelon.aigameplay/ref/pgs-schema.json +191 -0
  56. package/skills/big_watermelon.aigameplay/ref/reducer.template.ts +202 -0
  57. package/skills/block_puzzle.aigameplay/SKILL.md +121 -0
  58. package/skills/block_puzzle.aigameplay/manifest.json +154 -0
  59. package/skills/block_puzzle.aigameplay/ref/pgs-schema.json +170 -0
  60. package/skills/block_puzzle.aigameplay/ref/reducer.template.ts +182 -0
  61. package/skills/board_entity_sprite.aiimage/SKILL.md +255 -0
  62. package/skills/board_entity_sprite.aiimage/manifest.json +153 -0
  63. package/skills/board_entity_sprite.aiimage/ref/ProceduralCar.ts +357 -0
  64. package/skills/board_entity_sprite.aiimage/ref/car.png +0 -0
  65. package/skills/board_entity_sprite.aiimage/ref/car.webp +0 -0
  66. package/skills/bottom_ui_bar.aicomponent/SKILL.md +50 -0
  67. package/skills/bottom_ui_bar.aicomponent/manifest.json +31 -0
  68. package/skills/bottom_ui_bar.aicomponent/ref/GameBottomUI.ts +27 -0
  69. package/skills/bubble_shooter.aigameplay/SKILL.md +129 -0
  70. package/skills/bubble_shooter.aigameplay/manifest.json +181 -0
  71. package/skills/bubble_shooter.aigameplay/ref/pgs-schema.json +226 -0
  72. package/skills/bubble_shooter.aigameplay/ref/reducer.template.ts +228 -0
  73. package/skills/button_click_sfx.aiaudio/SKILL.md +59 -0
  74. package/skills/button_click_sfx.aiaudio/manifest.json +45 -0
  75. package/skills/button_click_sfx.aiaudio/ref/button_click.mp3 +0 -0
  76. package/skills/calm_piano.aiaudio/SKILL.md +68 -0
  77. package/skills/calm_piano.aiaudio/manifest.json +50 -0
  78. package/skills/camera_controller_3d.aicomponent/SKILL.md +100 -0
  79. package/skills/camera_controller_3d.aicomponent/manifest.json +52 -0
  80. package/skills/camera_controller_3d.aicomponent/ref/CameraController.ts +199 -0
  81. package/skills/camera_controller_3d.aicomponent/ref/OrbitControlsAdapter.ts +152 -0
  82. package/skills/candy_tile.aiimage/SKILL.md +62 -0
  83. package/skills/candy_tile.aiimage/manifest.json +49 -0
  84. package/skills/car_parking.aigameplay/SKILL.md +105 -0
  85. package/skills/car_parking.aigameplay/manifest.json +164 -0
  86. package/skills/car_parking.aigameplay/ref/pgs-schema.json +163 -0
  87. package/skills/car_parking.aigameplay/ref/reducer.template.ts +166 -0
  88. package/skills/castle.aiimage/SKILL.md +64 -0
  89. package/skills/castle.aiimage/manifest.json +48 -0
  90. package/skills/cheerful_ukulele.aiaudio/SKILL.md +72 -0
  91. package/skills/cheerful_ukulele.aiaudio/manifest.json +50 -0
  92. package/skills/click_sfx.aiaudio/SKILL.md +59 -0
  93. package/skills/click_sfx.aiaudio/manifest.json +45 -0
  94. package/skills/click_sfx.aiaudio/ref/click.mp3 +0 -0
  95. package/skills/combo_display.aicomponent/SKILL.md +45 -0
  96. package/skills/combo_display.aicomponent/manifest.json +31 -0
  97. package/skills/combo_display.aicomponent/ref/ComboManager.ts +362 -0
  98. package/skills/combo_display.aicomponent/ref/ComboSmallUI.ts +232 -0
  99. package/skills/combo_praise_text.aicomponent/SKILL.md +56 -0
  100. package/skills/combo_praise_text.aicomponent/manifest.json +34 -0
  101. package/skills/combo_praise_text.aicomponent/ref/ComboManager.ts +362 -0
  102. package/skills/countdown_timer.aicomponent/SKILL.md +44 -0
  103. package/skills/countdown_timer.aicomponent/manifest.json +35 -0
  104. package/skills/countdown_timer.aicomponent/ref/CountdownDisplay.ts +213 -0
  105. package/skills/cta_platform_config.aiconfig/SKILL.md +72 -0
  106. package/skills/cta_platform_config.aiconfig/manifest.json +56 -0
  107. package/skills/debug_overlay.aicomponent/SKILL.md +75 -0
  108. package/skills/debug_overlay.aicomponent/manifest.json +17 -0
  109. package/skills/debug_overlay.aicomponent/ref/DebugOverlay.ts +144 -0
  110. package/skills/desert.aiimage/SKILL.md +63 -0
  111. package/skills/desert.aiimage/manifest.json +49 -0
  112. package/skills/difficulty_curve_designer.aiconfig/SKILL.md +68 -0
  113. package/skills/difficulty_curve_designer.aiconfig/manifest.json +36 -0
  114. package/skills/digit_renderer.aicomponent/SKILL.md +43 -0
  115. package/skills/digit_renderer.aicomponent/manifest.json +25 -0
  116. package/skills/digit_renderer.aicomponent/ref/DigitRenderer.ts +237 -0
  117. package/skills/download_button.aicomponent/SKILL.md +44 -0
  118. package/skills/download_button.aicomponent/manifest.json +25 -0
  119. package/skills/download_button.aicomponent/ref/DownloadButton.ts +137 -0
  120. package/skills/draw_line_puzzle.aigameplay/SKILL.md +84 -0
  121. package/skills/draw_line_puzzle.aigameplay/manifest.json +152 -0
  122. package/skills/draw_line_puzzle.aigameplay/ref/pgs-schema.json +189 -0
  123. package/skills/draw_line_puzzle.aigameplay/ref/reducer.template.ts +194 -0
  124. package/skills/easy_to_hard.aiconfig/SKILL.md +52 -0
  125. package/skills/easy_to_hard.aiconfig/manifest.json +33 -0
  126. package/skills/eight_ball_pool.aigameplay/SKILL.md +104 -0
  127. package/skills/eight_ball_pool.aigameplay/manifest.json +152 -0
  128. package/skills/eight_ball_pool.aigameplay/ref/pgs-schema.json +205 -0
  129. package/skills/eight_ball_pool.aigameplay/ref/reducer.template.ts +198 -0
  130. package/skills/energetic_electronic.aiaudio/SKILL.md +69 -0
  131. package/skills/energetic_electronic.aiaudio/manifest.json +51 -0
  132. package/skills/fail_sfx.aiaudio/SKILL.md +59 -0
  133. package/skills/fail_sfx.aiaudio/manifest.json +44 -0
  134. package/skills/fail_sfx.aiaudio/ref/fail.mp3 +0 -0
  135. package/skills/figer_icon.aiimage/SKILL.md +58 -0
  136. package/skills/figer_icon.aiimage/manifest.json +48 -0
  137. package/skills/figer_icon.aiimage/ref/figer.png +0 -0
  138. package/skills/figer_icon.aiimage/ref/figer.webp +0 -0
  139. package/skills/forest.aiimage/SKILL.md +74 -0
  140. package/skills/forest.aiimage/manifest.json +48 -0
  141. package/skills/fruit_tile.aiimage/SKILL.md +68 -0
  142. package/skills/fruit_tile.aiimage/manifest.json +48 -0
  143. package/skills/game_over_panel.aicomponent/SKILL.md +47 -0
  144. package/skills/game_over_panel.aicomponent/manifest.json +61 -0
  145. package/skills/game_over_panel.aicomponent/ref/GameOverPanel.ts +74 -0
  146. package/skills/game_scene.aicomponent/SKILL.md +57 -0
  147. package/skills/game_scene.aicomponent/manifest.json +36 -0
  148. package/skills/game_scene.aicomponent/ref/Game.ts +748 -0
  149. package/skills/gameplay_balance_check.aivalidator/SKILL.md +69 -0
  150. package/skills/gameplay_balance_check.aivalidator/manifest.json +21 -0
  151. package/skills/gameplay_unit_test.aivalidator/SKILL.md +89 -0
  152. package/skills/gameplay_unit_test.aivalidator/manifest.json +17 -0
  153. package/skills/gameplay_unit_test.aivalidator/ref/gameplay.test.ts +202 -0
  154. package/skills/gameplay_unit_test.aivalidator/ref/vitest.config.ts +13 -0
  155. package/skills/grid_board_layout.aicomponent/SKILL.md +85 -0
  156. package/skills/grid_board_layout.aicomponent/manifest.json +69 -0
  157. package/skills/grid_board_layout.aicomponent/ref/BoardLayout.ts +416 -0
  158. package/skills/grid_board_layout.aicomponent/ref/BoardLayout3D.ts +125 -0
  159. package/skills/grid_board_layout.aicomponent/ref/BoardLayoutMath.ts +85 -0
  160. package/skills/grid_board_layout.aicomponent/ref/BoardRenderer3D.ts +298 -0
  161. package/skills/heart_lives.aicomponent/SKILL.md +42 -0
  162. package/skills/heart_lives.aicomponent/manifest.json +25 -0
  163. package/skills/heart_lives.aicomponent/ref/HeartDisplay.ts +96 -0
  164. package/skills/idle-breathe.aicomponent/SKILL.md +27 -0
  165. package/skills/idle-breathe.aicomponent/manifest.json +20 -0
  166. package/skills/idle-breathe.aicomponent/ref/phaser.js +25 -0
  167. package/skills/idle-breathe.aicomponent/ref/playcanvas.js +29 -0
  168. package/skills/jewel_tile.aiimage/SKILL.md +63 -0
  169. package/skills/jewel_tile.aiimage/manifest.json +49 -0
  170. package/skills/knife_hit.aigameplay/SKILL.md +103 -0
  171. package/skills/knife_hit.aigameplay/manifest.json +151 -0
  172. package/skills/knife_hit.aigameplay/ref/pgs-schema.json +202 -0
  173. package/skills/knife_hit.aigameplay/ref/reducer.template.ts +196 -0
  174. package/skills/left_right_parkour.aigameplay/SKILL.md +120 -0
  175. package/skills/left_right_parkour.aigameplay/manifest.json +165 -0
  176. package/skills/left_right_parkour.aigameplay/ref/pgs-schema.json +200 -0
  177. package/skills/left_right_parkour.aigameplay/ref/reducer.template.ts +194 -0
  178. package/skills/level_data_pack.aiconfig/SKILL.md +64 -0
  179. package/skills/level_data_pack.aiconfig/manifest.json +37 -0
  180. package/skills/level_data_validator.aivalidator/SKILL.md +85 -0
  181. package/skills/level_data_validator.aivalidator/manifest.json +17 -0
  182. package/skills/level_data_validator.aivalidator/ref/LevelValidator.ts +113 -0
  183. package/skills/level_lifecycle.aicomponent/SKILL.md +81 -0
  184. package/skills/level_lifecycle.aicomponent/manifest.json +87 -0
  185. package/skills/level_lifecycle.aicomponent/ref/LevelLifecycle.ts +235 -0
  186. package/skills/level_solvability_validator.aivalidator/SKILL.md +74 -0
  187. package/skills/level_solvability_validator.aivalidator/manifest.json +23 -0
  188. package/skills/level_solvability_validator.aivalidator/ref/LevelValidator.ts +186 -0
  189. package/skills/level_state.aicomponent/SKILL.md +55 -0
  190. package/skills/level_state.aicomponent/manifest.json +34 -0
  191. package/skills/level_state.aicomponent/ref/LevelDataManager.ts +26 -0
  192. package/skills/level_state.aicomponent/ref/LevelManager.ts +26 -0
  193. package/skills/loading_screen.aicomponent/SKILL.md +57 -0
  194. package/skills/loading_screen.aicomponent/manifest.json +43 -0
  195. package/skills/loading_screen.aicomponent/ref/LoadingUI.ts +339 -0
  196. package/skills/lose_result_panel.aiimage/SKILL.md +58 -0
  197. package/skills/lose_result_panel.aiimage/manifest.json +47 -0
  198. package/skills/lose_result_panel.aiimage/ref/lose.png +0 -0
  199. package/skills/lose_result_panel.aiimage/ref/lose.webp +0 -0
  200. package/skills/lose_sfx.aiaudio/SKILL.md +59 -0
  201. package/skills/lose_sfx.aiaudio/manifest.json +45 -0
  202. package/skills/lose_sfx.aiaudio/ref/lose.mp3 +0 -0
  203. package/skills/match-pop.aicomponent/SKILL.md +29 -0
  204. package/skills/match-pop.aicomponent/manifest.json +19 -0
  205. package/skills/match-pop.aicomponent/ref/phaser.js +30 -0
  206. package/skills/match-pop.aicomponent/ref/playcanvas.js +22 -0
  207. package/skills/match3_core.aigameplay/SKILL.md +125 -0
  208. package/skills/match3_core.aigameplay/manifest.json +107 -0
  209. package/skills/match3_core.aigameplay/ref/pgs-schema.json +154 -0
  210. package/skills/match3_core.aigameplay/ref/reducer.template.ts +191 -0
  211. package/skills/match_engine.aicomponent/SKILL.md +84 -0
  212. package/skills/match_engine.aicomponent/manifest.json +23 -0
  213. package/skills/match_engine.aicomponent/ref/MatchEngine.ts +75 -0
  214. package/skills/memory_match.aigameplay/SKILL.md +111 -0
  215. package/skills/memory_match.aigameplay/manifest.json +164 -0
  216. package/skills/memory_match.aigameplay/ref/pgs-schema.json +190 -0
  217. package/skills/memory_match.aigameplay/ref/reducer.template.ts +162 -0
  218. package/skills/merge_core.aigameplay/SKILL.md +112 -0
  219. package/skills/merge_core.aigameplay/manifest.json +154 -0
  220. package/skills/merge_core.aigameplay/ref/pgs-schema.json +202 -0
  221. package/skills/merge_core.aigameplay/ref/reducer.template.ts +179 -0
  222. package/skills/mistake_sfx.aiaudio/SKILL.md +59 -0
  223. package/skills/mistake_sfx.aiaudio/manifest.json +45 -0
  224. package/skills/mistake_sfx.aiaudio/ref/mistake.mp3 +0 -0
  225. package/skills/nomove_hint_overlay.aiimage/SKILL.md +58 -0
  226. package/skills/nomove_hint_overlay.aiimage/manifest.json +48 -0
  227. package/skills/nomove_hint_overlay.aiimage/ref/nomove_hint.png +0 -0
  228. package/skills/nomove_hint_overlay.aiimage/ref/nomove_hint.webp +0 -0
  229. package/skills/normal_dot.aiimage/SKILL.md +58 -0
  230. package/skills/normal_dot.aiimage/manifest.json +46 -0
  231. package/skills/normal_dot.aiimage/ref/normal_dot.png +0 -0
  232. package/skills/normal_dot.aiimage/ref/normal_dot.webp +0 -0
  233. package/skills/ocean.aiimage/SKILL.md +71 -0
  234. package/skills/ocean.aiimage/manifest.json +49 -0
  235. package/skills/particle-confetti.aicomponent/SKILL.md +32 -0
  236. package/skills/particle-confetti.aicomponent/manifest.json +21 -0
  237. package/skills/particle-confetti.aicomponent/ref/html5-spritesheet.js +17 -0
  238. package/skills/particle-confetti.aicomponent/ref/phaser.js +38 -0
  239. package/skills/particle-explosion.aicomponent/SKILL.md +37 -0
  240. package/skills/particle-explosion.aicomponent/manifest.json +24 -0
  241. package/skills/particle-explosion.aicomponent/ref/html5-spritesheet.js +40 -0
  242. package/skills/particle-explosion.aicomponent/ref/phaser.js +46 -0
  243. package/skills/particle-explosion.aicomponent/ref/playcanvas.js +33 -0
  244. package/skills/particle-trail.aicomponent/SKILL.md +25 -0
  245. package/skills/particle-trail.aicomponent/manifest.json +22 -0
  246. package/skills/particle-trail.aicomponent/ref/phaser.js +31 -0
  247. package/skills/path_animation.aicomponent/SKILL.md +82 -0
  248. package/skills/path_animation.aicomponent/manifest.json +77 -0
  249. package/skills/path_animation.aicomponent/ref/AnimationManager.ts +694 -0
  250. package/skills/path_animation.aicomponent/ref/AnimationManager3D.ts +317 -0
  251. package/skills/path_elimination_rules.aigameplay/SKILL.md +88 -0
  252. package/skills/path_elimination_rules.aigameplay/manifest.json +119 -0
  253. package/skills/path_elimination_rules.aigameplay/ref/pgs-schema.json +227 -0
  254. package/skills/path_input_handler.aicomponent/SKILL.md +87 -0
  255. package/skills/path_input_handler.aicomponent/manifest.json +97 -0
  256. package/skills/path_input_handler.aicomponent/ref/InputHandler.ts +714 -0
  257. package/skills/path_input_handler.aicomponent/ref/InputHandler3D.ts +204 -0
  258. package/skills/path_renderer.aicomponent/SKILL.md +101 -0
  259. package/skills/path_renderer.aicomponent/manifest.json +69 -0
  260. package/skills/path_renderer.aicomponent/ref/PathRenderer.ts +509 -0
  261. package/skills/path_renderer.aicomponent/ref/PathRenderer3D.ts +176 -0
  262. package/skills/path_renderer.aicomponent/ref/PathRenderers.ts +640 -0
  263. package/skills/phaser.aicomponent/SKILL.md +315 -0
  264. package/skills/phaser.aicomponent/manifest.json +156 -0
  265. package/skills/phaser.aicomponent/ref/BootScene.ts +29 -0
  266. package/skills/phaser.aicomponent/ref/GameConfig.ts +29 -0
  267. package/skills/phaser.aicomponent/ref/GameScene.ts +88 -0
  268. package/skills/phaser.aicomponent/ref/PreloaderScene.ts +78 -0
  269. package/skills/phaser.aicomponent/ref/SceneKeys.ts +7 -0
  270. package/skills/phaser.aicomponent/ref/SoundUtils.ts +21 -0
  271. package/skills/phaser.aicomponent/ref/UiLayout.ts +74 -0
  272. package/skills/phaser.aicomponent/ref/globals.d.ts +52 -0
  273. package/skills/phaser.aicomponent/ref/index.css +40 -0
  274. package/skills/phaser.aicomponent/ref/index.html +14 -0
  275. package/skills/phaser.aicomponent/ref/index.ts +48 -0
  276. package/skills/phaser.aicomponent/ref/main.ts +16 -0
  277. package/skills/phaser.aicomponent/ref/package.json +22 -0
  278. package/skills/phaser.aicomponent/ref/tsconfig.json +25 -0
  279. package/skills/phaser.aicomponent/ref/webpack.config.js +57 -0
  280. package/skills/phaser_scene_lifecycle.aicomponent/SKILL.md +63 -0
  281. package/skills/phaser_scene_lifecycle.aicomponent/manifest.json +33 -0
  282. package/skills/pick_and_match_rules.aigameplay/SKILL.md +113 -0
  283. package/skills/pick_and_match_rules.aigameplay/manifest.json +121 -0
  284. package/skills/pick_and_match_rules.aigameplay/ref/pgs-schema.json +354 -0
  285. package/skills/pin_pull.aigameplay/SKILL.md +110 -0
  286. package/skills/pin_pull.aigameplay/manifest.json +164 -0
  287. package/skills/pin_pull.aigameplay/ref/pgs-schema.json +201 -0
  288. package/skills/pin_pull.aigameplay/ref/reducer.template.ts +216 -0
  289. package/skills/playable_app_logo.aiimage/SKILL.md +58 -0
  290. package/skills/playable_app_logo.aiimage/manifest.json +47 -0
  291. package/skills/playable_app_logo.aiimage/ref/logo.png +0 -0
  292. package/skills/playable_app_logo.aiimage/ref/logo.webp +0 -0
  293. package/skills/playable_end_screen_layout.aicomponent/SKILL.md +75 -0
  294. package/skills/playable_end_screen_layout.aicomponent/manifest.json +24 -0
  295. package/skills/playable_guidance_layer.aicomponent/SKILL.md +89 -0
  296. package/skills/playable_guidance_layer.aicomponent/manifest.json +24 -0
  297. package/skills/playable_hud_layout.aicomponent/SKILL.md +96 -0
  298. package/skills/playable_hud_layout.aicomponent/manifest.json +24 -0
  299. package/skills/playable_scripts_build.aicomponent/SKILL.md +69 -0
  300. package/skills/playable_scripts_build.aicomponent/manifest.json +53 -0
  301. package/skills/playable_scripts_build.aicomponent/ref/builds.config.js +257 -0
  302. package/skills/playcraft-3d-flip-sprite/SKILL.md +336 -0
  303. package/skills/playcraft-3d-flip-sprite/renderer/flatten_glb.mjs +62 -0
  304. package/skills/playcraft-3d-flip-sprite/renderer/render.mjs +325 -0
  305. package/skills/playcraft-3d-flip-sprite/renderer/render_single.mjs +138 -0
  306. package/skills/playcraft-asset-management/SKILL.md +73 -0
  307. package/skills/playcraft-audio-generation/SKILL.md +126 -0
  308. package/skills/playcraft-build/SKILL.md +44 -0
  309. package/skills/playcraft-code-editor/SKILL.md +71 -0
  310. package/skills/playcraft-create-remix/SKILL.md +62 -0
  311. package/skills/playcraft-deploy/SKILL.md +59 -0
  312. package/skills/playcraft-image-generation/SKILL.md +148 -0
  313. package/skills/playcraft-image-processing/SKILL.md +216 -0
  314. package/skills/playcraft-platform-intro/SKILL.md +41 -0
  315. package/skills/playcraft-prefab/SKILL.md +98 -0
  316. package/skills/playcraft-project-management/SKILL.md +57 -0
  317. package/skills/playcraft-remix-workflow/SKILL.md +119 -0
  318. package/skills/playcraft-remix-workflow/references/xplatform.schema.json5 +31 -0
  319. package/skills/playcraft-save/SKILL.md +46 -0
  320. package/skills/playcraft-skill-recommender/SKILL.md +152 -0
  321. package/skills/playcraft-sprite-generation/SKILL.md +534 -0
  322. package/skills/playcraft-sprite-remix/SKILL.md +155 -0
  323. package/skills/playcraft-sprite-sheet/SKILL.md +97 -0
  324. package/skills/playtest_report.aivalidator/SKILL.md +103 -0
  325. package/skills/playtest_report.aivalidator/manifest.json +21 -0
  326. package/skills/preloader_scene.aicomponent/SKILL.md +58 -0
  327. package/skills/preloader_scene.aicomponent/manifest.json +43 -0
  328. package/skills/preloader_scene.aicomponent/ref/Preloader.ts +339 -0
  329. package/skills/progress_bar.aicomponent/SKILL.md +38 -0
  330. package/skills/progress_bar.aicomponent/manifest.json +25 -0
  331. package/skills/progress_bar.aicomponent/ref/ProgressDisplay.ts +140 -0
  332. package/skills/references/xplatform.schema.json5 +31 -0
  333. package/skills/responsive_2d_layout.aicomponent/SKILL.md +161 -0
  334. package/skills/responsive_2d_layout.aicomponent/manifest.json +43 -0
  335. package/skills/responsive_2d_layout.aicomponent/ref/UiLayout.ts +56 -0
  336. package/skills/run_context_state.aicomponent/SKILL.md +54 -0
  337. package/skills/run_context_state.aicomponent/manifest.json +40 -0
  338. package/skills/run_context_state.aicomponent/ref/RunContextRuntime.ts +30 -0
  339. package/skills/score-fly.aicomponent/SKILL.md +31 -0
  340. package/skills/score-fly.aicomponent/manifest.json +21 -0
  341. package/skills/score-fly.aicomponent/ref/phaser.js +26 -0
  342. package/skills/score-fly.aicomponent/ref/playcanvas.js +28 -0
  343. package/skills/score_goal.aiconfig/SKILL.md +46 -0
  344. package/skills/score_goal.aiconfig/manifest.json +33 -0
  345. package/skills/screen-flash.aicomponent/SKILL.md +30 -0
  346. package/skills/screen-flash.aicomponent/manifest.json +20 -0
  347. package/skills/screen-flash.aicomponent/ref/phaser.js +48 -0
  348. package/skills/screen-shake.aicomponent/SKILL.md +30 -0
  349. package/skills/screen-shake.aicomponent/manifest.json +19 -0
  350. package/skills/screen-shake.aicomponent/ref/phaser.js +23 -0
  351. package/skills/screen-shake.aicomponent/ref/playcanvas.js +44 -0
  352. package/skills/screw_puzzle.aigameplay/SKILL.md +116 -0
  353. package/skills/screw_puzzle.aigameplay/manifest.json +164 -0
  354. package/skills/screw_puzzle.aigameplay/ref/pgs-schema.json +235 -0
  355. package/skills/screw_puzzle.aigameplay/ref/reducer.template.ts +213 -0
  356. package/skills/settings_state.aicomponent/SKILL.md +61 -0
  357. package/skills/settings_state.aicomponent/manifest.json +33 -0
  358. package/skills/settings_state.aicomponent/ref/SettingsManager.ts +130 -0
  359. package/skills/slide_out_to_tray_animation.aicomponent/SKILL.md +64 -0
  360. package/skills/slide_out_to_tray_animation.aicomponent/manifest.json +58 -0
  361. package/skills/slide_out_to_tray_animation.aicomponent/ref/AnimationManager.ts +164 -0
  362. package/skills/slide_out_to_tray_animation.aicomponent/ref/AnimationManager3D.ts +198 -0
  363. package/skills/slide_out_to_tray_animation.aicomponent/ref/BezierUtils.ts +59 -0
  364. package/skills/slot_machine.aigameplay/SKILL.md +119 -0
  365. package/skills/slot_machine.aigameplay/manifest.json +166 -0
  366. package/skills/slot_machine.aigameplay/ref/pgs-schema.json +212 -0
  367. package/skills/slot_machine.aigameplay/ref/reducer.template.ts +212 -0
  368. package/skills/sniper_shot.aigameplay/SKILL.md +84 -0
  369. package/skills/sniper_shot.aigameplay/manifest.json +153 -0
  370. package/skills/sniper_shot.aigameplay/ref/pgs-schema.json +211 -0
  371. package/skills/sniper_shot.aigameplay/ref/reducer.template.ts +211 -0
  372. package/skills/solitaire.aigameplay/SKILL.md +101 -0
  373. package/skills/solitaire.aigameplay/manifest.json +151 -0
  374. package/skills/solitaire.aigameplay/ref/pgs-schema.json +200 -0
  375. package/skills/solitaire.aigameplay/ref/reducer.template.ts +176 -0
  376. package/skills/sound-effects/SKILL.md +46 -0
  377. package/skills/sound_utils.aicomponent/SKILL.md +52 -0
  378. package/skills/sound_utils.aicomponent/manifest.json +30 -0
  379. package/skills/sound_utils.aicomponent/ref/SoundUtils.ts +29 -0
  380. package/skills/sprite-animation-2d.aicomponent/SKILL.md +45 -0
  381. package/skills/sprite-animation-2d.aicomponent/manifest.json +28 -0
  382. package/skills/sprite-animation-2d.aicomponent/ref/html5.js +83 -0
  383. package/skills/sprite-animation-2d.aicomponent/ref/phaser.js +38 -0
  384. package/skills/sprite-animation-2d.aicomponent/ref/playcanvas.js +67 -0
  385. package/skills/sprite_entity_renderer.aicomponent/SKILL.md +148 -0
  386. package/skills/sprite_entity_renderer.aicomponent/manifest.json +17 -0
  387. package/skills/sprite_entity_renderer.aicomponent/ref/SpriteEntityRenderer.ts +126 -0
  388. package/skills/success_sfx.aiaudio/SKILL.md +59 -0
  389. package/skills/success_sfx.aiaudio/manifest.json +45 -0
  390. package/skills/success_sfx.aiaudio/ref/success.mp3 +0 -0
  391. package/skills/tap_blast.aigameplay/SKILL.md +116 -0
  392. package/skills/tap_blast.aigameplay/manifest.json +153 -0
  393. package/skills/tap_blast.aigameplay/ref/pgs-schema.json +208 -0
  394. package/skills/tap_blast.aigameplay/ref/reducer.template.ts +202 -0
  395. package/skills/theme_state.aicomponent/SKILL.md +53 -0
  396. package/skills/theme_state.aicomponent/manifest.json +33 -0
  397. package/skills/theme_state.aicomponent/ref/ThemeManager.ts +174 -0
  398. package/skills/theme_switcher_build.aicomponent/SKILL.md +62 -0
  399. package/skills/theme_switcher_build.aicomponent/manifest.json +38 -0
  400. package/skills/theme_switcher_build.aicomponent/ref/theme-index.ts +8 -0
  401. package/skills/theme_variant.aiconfig/SKILL.md +78 -0
  402. package/skills/theme_variant.aiconfig/manifest.json +39 -0
  403. package/skills/theme_variant.aiconfig/ref/ExampleTheme/index.ts +16 -0
  404. package/skills/theme_variant.aiconfig/ref/ExampleTheme/levelEasy.json +141 -0
  405. package/skills/threejs.aicomponent/SKILL.md +422 -0
  406. package/skills/threejs.aicomponent/manifest.json +166 -0
  407. package/skills/threejs.aicomponent/ref/AssetLoader.ts +158 -0
  408. package/skills/threejs.aicomponent/ref/BaseScene.ts +88 -0
  409. package/skills/threejs.aicomponent/ref/GameConfig.ts +47 -0
  410. package/skills/threejs.aicomponent/ref/MainScene.ts +170 -0
  411. package/skills/threejs.aicomponent/ref/PreloaderScene.ts +93 -0
  412. package/skills/threejs.aicomponent/ref/SceneKeys.ts +6 -0
  413. package/skills/threejs.aicomponent/ref/SceneManager.ts +69 -0
  414. package/skills/threejs.aicomponent/ref/ViewportManager.ts +62 -0
  415. package/skills/threejs.aicomponent/ref/globals.d.ts +74 -0
  416. package/skills/threejs.aicomponent/ref/index.css +80 -0
  417. package/skills/threejs.aicomponent/ref/index.html +20 -0
  418. package/skills/threejs.aicomponent/ref/index.ts +117 -0
  419. package/skills/threejs.aicomponent/ref/main.ts +10 -0
  420. package/skills/threejs.aicomponent/ref/package.json +23 -0
  421. package/skills/threejs.aicomponent/ref/tsconfig.json +24 -0
  422. package/skills/threejs.aicomponent/ref/webpack.config.js +61 -0
  423. package/skills/time_clear_goal.aiconfig/SKILL.md +46 -0
  424. package/skills/time_clear_goal.aiconfig/manifest.json +32 -0
  425. package/skills/time_icon.aiimage/SKILL.md +58 -0
  426. package/skills/time_icon.aiimage/manifest.json +47 -0
  427. package/skills/time_icon.aiimage/ref/time.png +0 -0
  428. package/skills/time_icon.aiimage/ref/time.webp +0 -0
  429. package/skills/top_ui_bar.aicomponent/SKILL.md +45 -0
  430. package/skills/top_ui_bar.aicomponent/manifest.json +27 -0
  431. package/skills/top_ui_bar.aicomponent/ref/GameTopUI.ts +229 -0
  432. package/skills/tower_defence.aigameplay/SKILL.md +117 -0
  433. package/skills/tower_defence.aigameplay/manifest.json +175 -0
  434. package/skills/tower_defence.aigameplay/ref/pgs-schema.json +247 -0
  435. package/skills/tower_defence.aigameplay/ref/reducer.template.ts +239 -0
  436. package/skills/tray_container.aicomponent/SKILL.md +143 -0
  437. package/skills/tray_container.aicomponent/manifest.json +58 -0
  438. package/skills/tray_container.aicomponent/ref/TrayRenderer.ts +155 -0
  439. package/skills/tray_container.aicomponent/ref/TrayRenderer3D.ts +281 -0
  440. package/skills/tray_container.aicomponent/ref/TrayRendererHtmlOverlay.ts +228 -0
  441. package/skills/tutorial_overlay.aicomponent/SKILL.md +46 -0
  442. package/skills/tutorial_overlay.aicomponent/manifest.json +34 -0
  443. package/skills/tutorial_overlay.aicomponent/ref/TutorialManager.ts +367 -0
  444. package/skills/tween-animation-2d.aicomponent/SKILL.md +35 -0
  445. package/skills/tween-animation-2d.aicomponent/manifest.json +28 -0
  446. package/skills/tween-animation-2d.aicomponent/ref/phaser.js +49 -0
  447. package/skills/tween-animation-2d.aicomponent/ref/playcanvas.js +36 -0
  448. package/skills/typescript_module_patterns.aicomponent/SKILL.md +209 -0
  449. package/skills/typescript_module_patterns.aicomponent/manifest.json +28 -0
  450. package/skills/typescript_module_patterns.aicomponent/ref/globals.d.ts +31 -0
  451. package/skills/ui-transition.aicomponent/SKILL.md +33 -0
  452. package/skills/ui-transition.aicomponent/manifest.json +19 -0
  453. package/skills/ui-transition.aicomponent/ref/phaser.js +45 -0
  454. package/skills/ux_flow_spec.aiconfig/SKILL.md +82 -0
  455. package/skills/ux_flow_spec.aiconfig/manifest.json +39 -0
  456. package/skills/wave_difficulty.aiconfig/SKILL.md +46 -0
  457. package/skills/wave_difficulty.aiconfig/manifest.json +33 -0
  458. package/skills/webpack_build.aicomponent/SKILL.md +204 -0
  459. package/skills/webpack_build.aicomponent/manifest.json +29 -0
  460. package/skills/webpack_build.aicomponent/ref/package.json +16 -0
  461. package/skills/webpack_build.aicomponent/ref/webpack.config.js +53 -0
  462. package/skills/win_anim_sfx.aiaudio/SKILL.md +59 -0
  463. package/skills/win_anim_sfx.aiaudio/manifest.json +46 -0
  464. package/skills/win_anim_sfx.aiaudio/ref/win_anim.mp3 +0 -0
  465. package/skills/win_dot.aiimage/SKILL.md +58 -0
  466. package/skills/win_dot.aiimage/manifest.json +47 -0
  467. package/skills/win_dot.aiimage/ref/win_dot.png +0 -0
  468. package/skills/win_dot.aiimage/ref/win_dot.webp +0 -0
  469. package/skills/win_result_panel.aiimage/SKILL.md +58 -0
  470. package/skills/win_result_panel.aiimage/manifest.json +47 -0
  471. package/skills/win_result_panel.aiimage/ref/win.png +0 -0
  472. package/skills/win_result_panel.aiimage/ref/win.webp +0 -0
  473. package/skills/word_connect.aigameplay/SKILL.md +86 -0
  474. package/skills/word_connect.aigameplay/manifest.json +154 -0
  475. package/skills/word_connect.aigameplay/ref/pgs-schema.json +212 -0
  476. package/skills/word_connect.aigameplay/ref/reducer.template.ts +186 -0
  477. package/src/index.ts +10 -0
  478. package/src/skills.loader.ts +225 -0
  479. package/src/skills.types.ts +42 -0
@@ -0,0 +1,640 @@
1
+ import * as Phaser from "phaser";
2
+ import { PATH_CORNER_RADIUS } from "../DebugConfig";
3
+
4
+ /** 路径轨迹中的单元格坐标 */
5
+ export type PathTrackCell = { x: number; y: number };
6
+
7
+ /** 路径渲染所需的参数集合 */
8
+ export type PathRenderParams = {
9
+ g: Phaser.GameObjects.Graphics;
10
+ track: PathTrackCell[];
11
+ startSegmentIndex: number;
12
+ endSegmentIndexExclusive: number;
13
+ cellSize: number;
14
+ lineWidth: number;
15
+ headCell?: PathTrackCell;
16
+ cellCenter: (col: number, row: number) => { x: number; y: number };
17
+ fillAxisAlignedSegmentRect: (
18
+ g: Phaser.GameObjects.Graphics,
19
+ x1: number,
20
+ y1: number,
21
+ x2: number,
22
+ y2: number,
23
+ lineWidth: number,
24
+ ) => void;
25
+ };
26
+
27
+ /** 路径渲染器接口,定义统一的渲染方法 */
28
+ export interface PathRenderer {
29
+ render(params: PathRenderParams): void;
30
+ }
31
+
32
+ /**
33
+ * 判断三个相邻单元格是否构成一个轴对齐的拐弯(即90度直角转弯)
34
+ * @param prev 前一个单元格
35
+ * @param cur 当前单元格(拐角处)
36
+ * @param next 下一个单元格
37
+ * @returns 如果是轴对齐的90度转弯则返回 true
38
+ */
39
+ export function isAxisAlignedTurn(
40
+ prev: PathTrackCell,
41
+ cur: PathTrackCell,
42
+ next: PathTrackCell,
43
+ ): boolean {
44
+ const dx1 = cur.x - prev.x;
45
+ const dy1 = cur.y - prev.y;
46
+ const dx2 = next.x - cur.x;
47
+ const dy2 = next.y - cur.y;
48
+ const inAxis = (dx1 === 0 && dy1 !== 0) || (dy1 === 0 && dx1 !== 0);
49
+ const outAxis = (dx2 === 0 && dy2 !== 0) || (dy2 === 0 && dx2 !== 0);
50
+ if (!inAxis || !outAxis) return false;
51
+ return dx1 * dx2 + dy1 * dy2 === 0;
52
+ }
53
+
54
+ /**
55
+ * 计算从一个单元格到另一个单元格的轴对齐单位方向向量
56
+ * @param from 起始单元格
57
+ * @param to 目标单元格
58
+ * @returns 单位方向向量,仅在水平或垂直方向上为 ±1,否则为 {0, 0}
59
+ */
60
+ export function axisUnitDir(
61
+ from: PathTrackCell,
62
+ to: PathTrackCell,
63
+ ): { x: number; y: number } {
64
+ const dx = to.x - from.x;
65
+ const dy = to.y - from.y;
66
+ if (dx !== 0) return { x: dx > 0 ? 1 : -1, y: 0 };
67
+ if (dy !== 0) return { x: 0, y: dy > 0 ? 1 : -1 };
68
+ return { x: 0, y: 0 };
69
+ }
70
+
71
+ /**
72
+ * 绘制一段环形弧(甜甜圈形状的弧形区域)
73
+ * 通过外弧和内弧围成的封闭区域来填充,用于绘制有宽度的圆角路径
74
+ * @param g Phaser 图形对象
75
+ * @param cx 弧心 X 坐标
76
+ * @param cy 弧心 Y 坐标
77
+ * @param innerR 内圆半径
78
+ * @param outerR 外圆半径
79
+ * @param startAngle 起始角度(弧度)
80
+ * @param endAngle 结束角度(弧度)
81
+ * @param anticlockwise 是否逆时针绘制
82
+ */
83
+ function fillDonutArc(
84
+ g: Phaser.GameObjects.Graphics,
85
+ cx: number,
86
+ cy: number,
87
+ innerR: number,
88
+ outerR: number,
89
+ startAngle: number,
90
+ endAngle: number,
91
+ anticlockwise: boolean,
92
+ ): void {
93
+ const TAU = Math.PI * 2;
94
+ const r = Math.max(1, outerR);
95
+
96
+ let delta = endAngle - startAngle;
97
+ delta = ((delta % TAU) + TAU) % TAU;
98
+ if (anticlockwise) {
99
+ if (delta > 0) delta -= TAU;
100
+ } else {
101
+ if (delta < 0) delta += TAU;
102
+ }
103
+
104
+ const sweep = Math.max(0.0001, Math.abs(delta));
105
+ const smallRadius = r < 10;
106
+ const targetArcLenPerSeg = smallRadius ? 0.85 : 1.15;
107
+ const minSeg = smallRadius ? 8 : 6;
108
+ const maxSeg = smallRadius ? 16 : 12;
109
+ const segments = Phaser.Math.Clamp(
110
+ Math.ceil((sweep * r) / targetArcLenPerSeg),
111
+ minSeg,
112
+ maxSeg,
113
+ );
114
+
115
+ const step = delta / segments;
116
+
117
+ g.beginPath();
118
+ for (let i = 0; i <= segments; i++) {
119
+ const a = startAngle + step * i;
120
+ const x = cx + Math.cos(a) * outerR;
121
+ const y = cy + Math.sin(a) * outerR;
122
+ if (i === 0) g.moveTo(x, y);
123
+ else g.lineTo(x, y);
124
+ }
125
+
126
+ if (innerR > 0.5) {
127
+ for (let i = segments; i >= 0; i--) {
128
+ const a = startAngle + step * i;
129
+ const x = cx + Math.cos(a) * innerR;
130
+ const y = cy + Math.sin(a) * innerR;
131
+ g.lineTo(x, y);
132
+ }
133
+ } else {
134
+ g.lineTo(cx, cy);
135
+ }
136
+
137
+ g.closePath();
138
+ g.fillPath();
139
+ }
140
+
141
+ /** 缓存四分之一弧的单位向量(cos/sin 值),避免重复三角函数计算 */
142
+ const quarterArcUnitCache = new Map<string, { cos: number[]; sin: number[] }>();
143
+
144
+ /**
145
+ * 将轴对齐的单位向量转换为对应的标准角度
146
+ * @param v 单位方向向量(仅支持四个轴方向)
147
+ * @returns 对应角度(弧度),非轴方向返回 null
148
+ */
149
+ function axisAngle(v: { x: number; y: number }): number | null {
150
+ if (v.x === 1 && v.y === 0) return 0;
151
+ if (v.x === 0 && v.y === 1) return Math.PI / 2;
152
+ if (v.x === -1 && v.y === 0) return Math.PI;
153
+ if (v.x === 0 && v.y === -1) return -Math.PI / 2;
154
+ return null;
155
+ }
156
+
157
+ /**
158
+ * 获取四分之一圆弧上各采样点的单位向量(cos/sin),带缓存优化
159
+ * @param startAngle 起始角度(弧度)
160
+ * @param anticlockwise 是否逆时针
161
+ * @param segments 弧线分段数
162
+ * @returns 包含 cos 和 sin 数组的对象
163
+ */
164
+ function getQuarterArcUnitVectors(
165
+ startAngle: number,
166
+ anticlockwise: boolean,
167
+ segments: number,
168
+ ): {
169
+ cos: number[];
170
+ sin: number[];
171
+ } {
172
+ const key = `${segments}:${startAngle}:${anticlockwise ? 1 : 0}`;
173
+ const cached = quarterArcUnitCache.get(key);
174
+ if (cached) {
175
+ return cached;
176
+ }
177
+
178
+ const cos: number[] = [];
179
+ const sin: number[] = [];
180
+ const delta = (anticlockwise ? -1 : 1) * (Math.PI / 2);
181
+ for (let i = 0; i <= segments; i++) {
182
+ const a = startAngle + (delta * i) / segments;
183
+ cos.push(Math.cos(a));
184
+ sin.push(Math.sin(a));
185
+ }
186
+ const built = { cos, sin };
187
+ quarterArcUnitCache.set(key, built);
188
+ return built;
189
+ }
190
+
191
+ /**
192
+ * 使用缓存的单位向量绘制四分之一环形弧(性能优化版本)
193
+ * @param g Phaser 图形对象
194
+ * @param cx 弧心 X 坐标
195
+ * @param cy 弧心 Y 坐标
196
+ * @param innerR 内圆半径
197
+ * @param outerR 外圆半径
198
+ * @param startAngle 起始角度(弧度)
199
+ * @param anticlockwise 是否逆时针绘制
200
+ * @param segments 弧线分段数
201
+ */
202
+ function fillQuarterDonutArcCached(
203
+ g: Phaser.GameObjects.Graphics,
204
+ cx: number,
205
+ cy: number,
206
+ innerR: number,
207
+ outerR: number,
208
+ startAngle: number,
209
+ anticlockwise: boolean,
210
+ segments: number,
211
+ ): void {
212
+ const u = getQuarterArcUnitVectors(startAngle, anticlockwise, segments);
213
+ g.beginPath();
214
+ for (let i = 0; i <= segments; i++) {
215
+ const x = cx + (u.cos[i] ?? 0) * outerR;
216
+ const y = cy + (u.sin[i] ?? 0) * outerR;
217
+ if (i === 0) g.moveTo(x, y);
218
+ else g.lineTo(x, y);
219
+ }
220
+
221
+ if (innerR > 0.5) {
222
+ for (let i = segments; i >= 0; i--) {
223
+ g.lineTo(cx + (u.cos[i] ?? 0) * innerR, cy + (u.sin[i] ?? 0) * innerR);
224
+ }
225
+ } else {
226
+ g.lineTo(cx, cy);
227
+ }
228
+
229
+ g.closePath();
230
+ g.fillPath();
231
+ }
232
+
233
+ /**
234
+ * 方形路径渲染器:使用直角矩形绘制路径段,拐角处用方形填充
235
+ * 适用于不需要圆角的简洁路径样式
236
+ */
237
+ export const SquarePathRenderer: PathRenderer = {
238
+ render: (params) => {
239
+ const {
240
+ g,
241
+ track,
242
+ startSegmentIndex,
243
+ endSegmentIndexExclusive,
244
+ cellSize,
245
+ lineWidth,
246
+ headCell,
247
+ cellCenter,
248
+ fillAxisAlignedSegmentRect,
249
+ } = params;
250
+
251
+ for (let i = startSegmentIndex; i < endSegmentIndexExclusive; i++) {
252
+ const a = track[i];
253
+ const b = track[i + 1];
254
+ if (!a || !b) continue;
255
+ const ca = cellCenter(a.x, a.y);
256
+ const cb = cellCenter(b.x, b.y);
257
+
258
+ const x1 = ca.x;
259
+ const y1 = ca.y;
260
+ let x2 = cb.x;
261
+ let y2 = cb.y;
262
+
263
+ const isHeadSegment =
264
+ !!headCell && b.x === headCell.x && b.y === headCell.y;
265
+ if (isHeadSegment) {
266
+ const len = Math.abs(x2 - x1) + Math.abs(y2 - y1);
267
+ if (len > 0.0001) {
268
+ const shrink = Math.min(cellSize * 0.22, len * 0.5);
269
+ const sx = x2 === x1 ? 0 : x2 > x1 ? 1 : -1;
270
+ const sy = y2 === y1 ? 0 : y2 > y1 ? 1 : -1;
271
+ x2 -= sx * shrink;
272
+ y2 -= sy * shrink;
273
+ }
274
+ }
275
+
276
+ if (Math.abs(x1 - x2) < 0.0001 || Math.abs(y1 - y2) < 0.0001) {
277
+ fillAxisAlignedSegmentRect(g, x1, y1, x2, y2, lineWidth);
278
+ }
279
+ }
280
+
281
+ for (let i = 1; i + 1 < track.length; i++) {
282
+ const prev = track[i - 1];
283
+ const cur = track[i];
284
+ const next = track[i + 1];
285
+ if (!prev || !cur || !next) continue;
286
+
287
+ const prevSegIndex = i - 1;
288
+ const nextSegIndex = i;
289
+ if (
290
+ prevSegIndex < startSegmentIndex ||
291
+ nextSegIndex >= endSegmentIndexExclusive
292
+ ) {
293
+ continue;
294
+ }
295
+
296
+ if (!isAxisAlignedTurn(prev, cur, next)) {
297
+ continue;
298
+ }
299
+
300
+ if (headCell && cur.x === headCell.x && cur.y === headCell.y) {
301
+ continue;
302
+ }
303
+
304
+ const cc = cellCenter(cur.x, cur.y);
305
+ fillAxisAlignedSegmentRect(g, cc.x, cc.y, cc.x, cc.y, lineWidth);
306
+ }
307
+ },
308
+ };
309
+
310
+ /**
311
+ * 绘制一个带圆角的填充三角形(用于箭头等图形)
312
+ * 每个顶点处用二次贝塞尔曲线平滑过渡,近似圆弧效果
313
+ * @param g Phaser 图形对象
314
+ * @param p0 顶点 0(箭头尖端)
315
+ * @param p1 顶点 1(左下角)
316
+ * @param p2 顶点 2(右下角)
317
+ * @param radius 圆角半径(会自动限制在安全最大值内)
318
+ */
319
+ export function fillRoundedTriangle(
320
+ g: Phaser.GameObjects.Graphics,
321
+ p0: { x: number; y: number },
322
+ p1: { x: number; y: number },
323
+ p2: { x: number; y: number },
324
+ radius: number,
325
+ ) {
326
+ const pts = [p0, p1, p2];
327
+
328
+ // 限制圆角半径,使其不超过最短边的安全比例
329
+ const edgeLen = (a: { x: number; y: number }, b: { x: number; y: number }) =>
330
+ Math.sqrt((b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y));
331
+ const minEdge = Math.min(edgeLen(p0, p1), edgeLen(p1, p2), edgeLen(p2, p0));
332
+ const r = Math.min(radius, minEdge * 0.35);
333
+
334
+ if (r < 0.5) {
335
+ // 半径过小,回退为尖角三角形
336
+ g.beginPath();
337
+ g.moveTo(p0.x, p0.y);
338
+ g.lineTo(p1.x, p1.y);
339
+ g.lineTo(p2.x, p2.y);
340
+ g.closePath();
341
+ g.fillPath();
342
+ return;
343
+ }
344
+
345
+ // 用于近似每个圆角弧的线段数量
346
+ const arcSegments = 8;
347
+
348
+ g.beginPath();
349
+
350
+ for (let i = 0; i < 3; i++) {
351
+ const prev = pts[(i + 2) % 3]!;
352
+ const curr = pts[i]!;
353
+ const next = pts[(i + 1) % 3]!;
354
+
355
+ // 从当前顶点指向相邻顶点的单位方向向量
356
+ let dPrevX = prev.x - curr.x;
357
+ let dPrevY = prev.y - curr.y;
358
+ const lenPrev = Math.sqrt(dPrevX * dPrevX + dPrevY * dPrevY);
359
+ dPrevX /= lenPrev;
360
+ dPrevY /= lenPrev;
361
+
362
+ let dNextX = next.x - curr.x;
363
+ let dNextY = next.y - curr.y;
364
+ const lenNext = Math.sqrt(dNextX * dNextX + dNextY * dNextY);
365
+ dNextX /= lenNext;
366
+ dNextY /= lenNext;
367
+
368
+ // 圆角起点和终点(沿每条边向内缩进 r 的位置)
369
+ const startX = curr.x + dPrevX * r;
370
+ const startY = curr.y + dPrevY * r;
371
+ const endX = curr.x + dNextX * r;
372
+ const endY = curr.y + dNextY * r;
373
+
374
+ if (i === 0) {
375
+ g.moveTo(startX, startY);
376
+ } else {
377
+ g.lineTo(startX, startY);
378
+ }
379
+
380
+ // 使用二次贝塞尔曲线插值(控制点为原始顶点)来用线段近似该角的弧线
381
+ for (let s = 1; s <= arcSegments; s++) {
382
+ const t = s / arcSegments;
383
+ const mt = 1 - t;
384
+ // 二次贝塞尔曲线: B(t) = (1-t)^2 * start + 2*(1-t)*t * ctrl + t^2 * end
385
+ const bx = mt * mt * startX + 2 * mt * t * curr.x + t * t * endX;
386
+ const by = mt * mt * startY + 2 * mt * t * curr.y + t * t * endY;
387
+ g.lineTo(bx, by);
388
+ }
389
+ }
390
+
391
+ g.closePath();
392
+ g.fillPath();
393
+ }
394
+
395
+ /**
396
+ * 圆角路径渲染器:路径直线段之间的拐角使用平滑圆弧过渡
397
+ * 通过环形弧(donut arc)实现有宽度的圆角效果,视觉更加美观
398
+ */
399
+ export const RoundedCornerPathRenderer: PathRenderer = {
400
+ render: (params) => {
401
+ const {
402
+ g,
403
+ track,
404
+ startSegmentIndex,
405
+ endSegmentIndexExclusive,
406
+ cellSize,
407
+ lineWidth,
408
+ headCell,
409
+ cellCenter,
410
+ fillAxisAlignedSegmentRect,
411
+ } = params;
412
+
413
+ if (endSegmentIndexExclusive <= startSegmentIndex) {
414
+ return;
415
+ }
416
+
417
+ const useSubpixelAA = cellSize < 18;
418
+ const w = Math.max(1, useSubpixelAA ? lineWidth : Math.round(lineWidth));
419
+ const halfW = w * 0.5;
420
+ const maxR = cellSize * PATH_CORNER_RADIUS;
421
+ const desiredR = Math.max(
422
+ halfW + (useSubpixelAA ? 0.75 : 1),
423
+ useSubpixelAA
424
+ ? Math.max(w * 1.25, cellSize * 0.32)
425
+ : Math.round(Math.max(w * 1.25, cellSize * 0.32)),
426
+ );
427
+ const r = Math.min(maxR, desiredR);
428
+ const innerR = Math.max(0, r - halfW);
429
+ const outerR = r + halfW;
430
+ const TAU = Math.PI * 2;
431
+ // 在非亚像素模式下,fillAxisAlignedSegmentRect 通过 floor/ceil
432
+ // 将端点扩展了 `half` 的距离,导致几个像素突入圆角弧区域。
433
+ // 通过额外裁剪 `halfW` 来补偿,使直线段恰好在弧线起点处停止。
434
+ const cornerTrim = useSubpixelAA ? r : r + halfW;
435
+ // Trim amount for the tail cap: retract the rectangle starting end so
436
+ // the semicircle cap is visible. In subpixel mode the rect does NOT
437
+ // extend past the endpoint, so no trim is needed; in non-subpixel mode
438
+ // floor/ceil extend the rect by ~halfW, which would cover the cap.
439
+ const tailCapTrim = useSubpixelAA ? 0 : halfW;
440
+
441
+ const arcR = Math.max(1, outerR);
442
+ const sweep = Math.PI / 2;
443
+ const smallRadius = arcR < 10;
444
+ const targetArcLenPerSeg = smallRadius ? 0.85 : 1.15;
445
+ const minSeg = smallRadius ? 8 : 6;
446
+ const maxSeg = smallRadius ? 16 : 12;
447
+ const arcSegments = Phaser.Math.Clamp(
448
+ Math.ceil((sweep * arcR) / targetArcLenPerSeg),
449
+ minSeg,
450
+ maxSeg,
451
+ );
452
+
453
+ const snap = (v: number) => {
454
+ if (useSubpixelAA) {
455
+ return v;
456
+ }
457
+ if (w % 2 === 0) {
458
+ return Math.round(v);
459
+ }
460
+ return Math.round(v - 0.5) + 0.5;
461
+ };
462
+
463
+ for (let i = startSegmentIndex; i < endSegmentIndexExclusive; ) {
464
+ const a0 = track[i];
465
+ const b0 = track[i + 1];
466
+ if (!a0 || !b0) {
467
+ i += 1;
468
+ continue;
469
+ }
470
+
471
+ const dir0 = axisUnitDir(a0, b0);
472
+ if (dir0.x === 0 && dir0.y === 0) {
473
+ i += 1;
474
+ continue;
475
+ }
476
+
477
+ let j = i;
478
+ while (j + 1 < endSegmentIndexExclusive) {
479
+ const aj = track[j + 1];
480
+ const bj = track[j + 2];
481
+ if (!aj || !bj) break;
482
+ const dirj = axisUnitDir(aj, bj);
483
+ if (dirj.x !== dir0.x || dirj.y !== dir0.y) break;
484
+ j += 1;
485
+ }
486
+
487
+ const a = track[i];
488
+ const b = track[j + 1];
489
+ if (!a || !b) {
490
+ i = j + 1;
491
+ continue;
492
+ }
493
+
494
+ const ca0 = cellCenter(a.x, a.y);
495
+ const cb0 = cellCenter(b.x, b.y);
496
+ const ca = { x: snap(ca0.x), y: snap(ca0.y) };
497
+ const cb = { x: snap(cb0.x), y: snap(cb0.y) };
498
+ const isAxisAligned =
499
+ Math.abs(ca.x - cb.x) < 0.0001 || Math.abs(ca.y - cb.y) < 0.0001;
500
+ if (!isAxisAligned) {
501
+ i = j + 1;
502
+ continue;
503
+ }
504
+
505
+ let trimStart = 0;
506
+ let trimEnd = 0;
507
+
508
+ // Tail cap: retract the first segment so the semicircle is visible
509
+ const isTailSegment = i === startSegmentIndex;
510
+ if (isTailSegment) {
511
+ trimStart = tailCapTrim;
512
+ }
513
+
514
+ if (i > startSegmentIndex && i - 1 >= 0 && i + 1 < track.length) {
515
+ const prev = track[i - 1];
516
+ const cur = track[i];
517
+ const next = track[i + 1];
518
+ if (prev && cur && next && isAxisAlignedTurn(prev, cur, next)) {
519
+ trimStart = cornerTrim;
520
+ }
521
+ }
522
+
523
+ if (j + 1 < endSegmentIndexExclusive && j + 2 < track.length) {
524
+ const prev = track[j];
525
+ const cur = track[j + 1];
526
+ const next = track[j + 2];
527
+ if (prev && cur && next && isAxisAlignedTurn(prev, cur, next)) {
528
+ trimEnd = cornerTrim;
529
+ }
530
+ }
531
+
532
+ const isHeadSegment =
533
+ !!headCell && b.x === headCell.x && b.y === headCell.y;
534
+ if (isHeadSegment) {
535
+ const len = Math.abs(cb.x - ca.x) + Math.abs(cb.y - ca.y);
536
+ trimEnd += Math.min(cellSize * 0.22, len * 0.5);
537
+ }
538
+
539
+ const len = Math.abs(cb.x - ca.x) + Math.abs(cb.y - ca.y);
540
+ const maxTotal = Math.max(0, len - 0.0001);
541
+ const total = trimStart + trimEnd;
542
+ if (total > maxTotal && total > 0.0001) {
543
+ const s = maxTotal / total;
544
+ trimStart *= s;
545
+ trimEnd *= s;
546
+ }
547
+
548
+ let x1 = ca.x;
549
+ let y1 = ca.y;
550
+ let x2 = cb.x;
551
+ let y2 = cb.y;
552
+
553
+ if (Math.abs(x1 - x2) < 0.0001) {
554
+ const s = y2 > y1 ? 1 : -1;
555
+ y1 += s * trimStart;
556
+ y2 -= s * trimEnd;
557
+ } else {
558
+ const s = x2 > x1 ? 1 : -1;
559
+ x1 += s * trimStart;
560
+ x2 -= s * trimEnd;
561
+ }
562
+
563
+ if (Math.abs(x2 - x1) + Math.abs(y2 - y1) >= 0.5) {
564
+ fillAxisAlignedSegmentRect(g, x1, y1, x2, y2, w);
565
+ }
566
+
567
+ i = j + 1;
568
+ }
569
+
570
+ // ── Tail rounded cap ──
571
+ // Draw a semicircle at the tail end (track[startSegmentIndex]) so the
572
+ // tail looks rounded instead of flat.
573
+ {
574
+ const tailCell = track[startSegmentIndex];
575
+ const nextCell = track[startSegmentIndex + 1];
576
+ if (tailCell && nextCell) {
577
+ const tc0 = cellCenter(tailCell.x, tailCell.y);
578
+ const tc = { x: snap(tc0.x), y: snap(tc0.y) };
579
+ const tailDir = axisUnitDir(tailCell, nextCell);
580
+ // The cap faces opposite to the path direction (outward from tail)
581
+ // startAngle: perpendicular to path dir, sweep π (semicircle)
582
+ // For dir (1,0) -> cap faces left -> arc from -π/2 to π/2 (centered at angle π)
583
+ // For dir (-1,0)-> cap faces right -> arc from π/2 to -π/2 (centered at angle 0)
584
+ // For dir (0,1) -> cap faces up -> arc from π to 0 (centered at angle -π/2)
585
+ // For dir (0,-1)-> cap faces down -> arc from 0 to π (centered at angle π/2)
586
+ if (tailDir.x !== 0 || tailDir.y !== 0) {
587
+ // Angle of the outward direction (opposite to path direction)
588
+ const outAngle = Math.atan2(-tailDir.y, -tailDir.x);
589
+ const capStart = outAngle - Math.PI / 2;
590
+ const capEnd = outAngle + Math.PI / 2;
591
+ fillDonutArc(g, tc.x, tc.y, 0, halfW, capStart, capEnd, false);
592
+ }
593
+ }
594
+ }
595
+
596
+ for (let k = startSegmentIndex + 1; k < endSegmentIndexExclusive; k++) {
597
+ const prev = track[k - 1];
598
+ const cur = track[k];
599
+ const next = track[k + 1];
600
+ if (!prev || !cur || !next) continue;
601
+ if (!isAxisAlignedTurn(prev, cur, next)) continue;
602
+
603
+ const corner0 = cellCenter(cur.x, cur.y);
604
+ const corner = { x: snap(corner0.x), y: snap(corner0.y) };
605
+ const uPrev = axisUnitDir(cur, prev);
606
+ const uNext = axisUnitDir(cur, next);
607
+
608
+ const cx = corner.x + (uPrev.x + uNext.x) * r;
609
+ const cy = corner.y + (uPrev.y + uNext.y) * r;
610
+
611
+ const vStart = { x: -uNext.x, y: -uNext.y };
612
+ const vEnd = { x: -uPrev.x, y: -uPrev.y };
613
+
614
+ const aStartAxis = axisAngle(vStart);
615
+ const aEndAxis = axisAngle(vEnd);
616
+ if (aStartAxis === null || aEndAxis === null) {
617
+ const aStart = Math.atan2(vStart.y, vStart.x);
618
+ const aEnd = Math.atan2(vEnd.y, vEnd.x);
619
+ const deltaCW = (((aEnd - aStart) % TAU) + TAU) % TAU;
620
+ const anticlockwise = TAU - deltaCW < deltaCW;
621
+
622
+ fillDonutArc(g, cx, cy, innerR, outerR, aStart, aEnd, anticlockwise);
623
+ continue;
624
+ }
625
+
626
+ const deltaCW = (((aEndAxis - aStartAxis) % TAU) + TAU) % TAU;
627
+ const anticlockwise = TAU - deltaCW < deltaCW;
628
+ fillQuarterDonutArcCached(
629
+ g,
630
+ cx,
631
+ cy,
632
+ innerR,
633
+ outerR,
634
+ aStartAxis,
635
+ anticlockwise,
636
+ arcSegments,
637
+ );
638
+ }
639
+ },
640
+ };