@haiyue/extensions 0.1.0

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 (293) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +30 -0
  3. package/dist/animation/Animation2DComponent.d.ts +46 -0
  4. package/dist/animation/Animation2DExtensionRegistry.d.ts +27 -0
  5. package/dist/animation/Animation2DRenderSystem.d.ts +89 -0
  6. package/dist/animation/Animation2DRuntime.d.ts +99 -0
  7. package/dist/animation/Animation2DStateMachine.d.ts +13 -0
  8. package/dist/animation/Animation2DStateMachineComponent.d.ts +54 -0
  9. package/dist/animation/Animation2DStateMachineRuntime.d.ts +30 -0
  10. package/dist/animation/Animation2DStateMachineSystem.d.ts +14 -0
  11. package/dist/animation/Animation2DStateMachineVisualRuntime.d.ts +27 -0
  12. package/dist/animation/Animation2DSystem.d.ts +14 -0
  13. package/dist/animation/AnimationAssetLoader.d.ts +9 -0
  14. package/dist/animation/AnimationAudioClip.d.ts +26 -0
  15. package/dist/animation/AnimationPathTessellator.d.ts +52 -0
  16. package/dist/animation/AnimationTextRasterizer.d.ts +21 -0
  17. package/dist/animation/AnimationVisual2D.d.ts +68 -0
  18. package/dist/animation/HyaAnimation2DClipAdapter.d.ts +16 -0
  19. package/dist/animation/Particle2DDescriptorAdapter.d.ts +5 -0
  20. package/dist/animation/runtime/mixer/Action.d.ts +150 -0
  21. package/dist/animation/runtime/mixer/Mixer.d.ts +54 -0
  22. package/dist/animation/runtime/mixer/PoseBuffer.d.ts +23 -0
  23. package/dist/animation/runtime/mixer/Sampler.d.ts +17 -0
  24. package/dist/animation/runtime/mixer/Types.d.ts +101 -0
  25. package/dist/animation/runtime/mixer/index.d.ts +6 -0
  26. package/dist/animation-state-machine/AnimationStateMachine.d.ts +111 -0
  27. package/dist/animation-state-machine/AnimationStateMachineChannels.d.ts +23 -0
  28. package/dist/animation-state-machine/runtime/Animation2DStateMachineMixerAdapter.d.ts +51 -0
  29. package/dist/animation-state-machine/runtime/AnimationStateMachineBlendTreeWeights.d.ts +14 -0
  30. package/dist/animation-state-machine/runtime/AnimationStateMachineCompiler.d.ts +109 -0
  31. package/dist/animation-state-machine/runtime/AnimationStateMachineController.d.ts +103 -0
  32. package/dist/animation-state-machine/runtime/AnimationStateMachineMixerPort.d.ts +35 -0
  33. package/dist/animation-state-machine/runtime/index.d.ts +7 -0
  34. package/dist/animation.d.ts +15 -0
  35. package/dist/animation.js +1171 -0
  36. package/dist/animation3d/Animation3DAction.d.ts +46 -0
  37. package/dist/animation3d/Animation3DBinding.d.ts +85 -0
  38. package/dist/animation3d/Animation3DClip.d.ts +20 -0
  39. package/dist/animation3d/Animation3DError.d.ts +13 -0
  40. package/dist/animation3d/Animation3DMixer.d.ts +27 -0
  41. package/dist/animation3d/Animation3DPose.d.ts +40 -0
  42. package/dist/animation3d/Animation3DPoseBuffer.d.ts +24 -0
  43. package/dist/animation3d/Animation3DResource.d.ts +28 -0
  44. package/dist/animation3d/Animation3DStateMachine.d.ts +95 -0
  45. package/dist/animation3d/Animation3DStateMachineRuntime.d.ts +70 -0
  46. package/dist/animation3d/Animation3DTrack.d.ts +19 -0
  47. package/dist/animation3d/hya/HyaAnimation3DRuntime.d.ts +73 -0
  48. package/dist/animation3d/hya/HyaAnimation3DStateMachineRuntime.d.ts +65 -0
  49. package/dist/animation3d/hya/HyaAnimation3DTypes.d.ts +170 -0
  50. package/dist/animation3d/hya/index.d.ts +4 -0
  51. package/dist/animation3d/index.d.ts +14 -0
  52. package/dist/animation3d/runtime/integration/Animation3DStateMachineMixerAdapter.d.ts +81 -0
  53. package/dist/animation3d/runtime/integration/Animation3DStateMachineMixerIntegration.d.ts +39 -0
  54. package/dist/animation3d/runtime/integration/index.d.ts +2 -0
  55. package/dist/animation3d/runtime/mixer/Action.d.ts +150 -0
  56. package/dist/animation3d/runtime/mixer/Animation3DMixerRuntimeStore.d.ts +6 -0
  57. package/dist/animation3d/runtime/mixer/Mixer.d.ts +59 -0
  58. package/dist/animation3d/runtime/mixer/PoseBuffer.d.ts +1 -0
  59. package/dist/animation3d/runtime/mixer/TrackSampler.d.ts +24 -0
  60. package/dist/animation3d/runtime/mixer/index.d.ts +4 -0
  61. package/dist/animation3d/runtime/state-machine/Animation3DBlendTreeWeights.d.ts +1 -0
  62. package/dist/animation3d/runtime/state-machine/Animation3DStateMachineCompiler.d.ts +1 -0
  63. package/dist/animation3d/runtime/state-machine/Animation3DStateMachineController.d.ts +1 -0
  64. package/dist/animation3d/runtime/state-machine/Animation3DStateMachineMixerPort.d.ts +1 -0
  65. package/dist/animation3d/runtime/state-machine/index.d.ts +6 -0
  66. package/dist/animation3d.d.ts +5 -0
  67. package/dist/animation3d.js +1708 -0
  68. package/dist/benchmark.d.ts +30 -0
  69. package/dist/benchmark.js +119 -0
  70. package/dist/canvas-text/CanvasText2DRenderSystem.d.ts +24 -0
  71. package/dist/canvas-text/CanvasTextComponent.d.ts +18 -0
  72. package/dist/canvas-text.d.ts +4 -0
  73. package/dist/canvas-text.js +276 -0
  74. package/dist/chunks/2d-ui-animation-2d.generated-D4aHzFU2.js +4 -0
  75. package/dist/chunks/2d-ui-canvas-text-2d.generated-C0Eaej2m.js +4 -0
  76. package/dist/chunks/2d-ui-spine2d.generated-CUUi8xjl.js +4 -0
  77. package/dist/chunks/2d-ui-tilemap2d.generated-gebw4mX7.js +4 -0
  78. package/dist/chunks/Animation2DStateMachine-9IonguNa.js +3245 -0
  79. package/dist/chunks/AnimationStateMachineController-BIcAh-sT.js +1438 -0
  80. package/dist/chunks/GltfAnimation3DAdapter-Cu3rQQsW.js +2240 -0
  81. package/dist/chunks/GltfAnimationRuntime-CRHsLycN.js +631 -0
  82. package/dist/chunks/RenderSystem2DBase-DDT61dAu.js +227 -0
  83. package/dist/chunks/Spine2DRuntime-D9M9LAQR.js +3056 -0
  84. package/dist/chunks/SpineAssetParser-BSDmPge1.js +378 -0
  85. package/dist/chunks/gltfLoader-Dm22jLYB.js +2085 -0
  86. package/dist/chunks/pluginUtils-CvwroRMd.js +33 -0
  87. package/dist/experimental-gltf-worker.d.ts +4 -0
  88. package/dist/experimental-gltf-worker.js +138 -0
  89. package/dist/experimental-spine-worker.d.ts +4 -0
  90. package/dist/experimental-spine-worker.js +110 -0
  91. package/dist/gltf/GltfAccessorReader.d.ts +7 -0
  92. package/dist/gltf/GltfAnimation3DAdapter.d.ts +47 -0
  93. package/dist/gltf/GltfAnimationRuntime.d.ts +10 -0
  94. package/dist/gltf/GltfAssetWorkerClient.d.ts +20 -0
  95. package/dist/gltf/GltfCompatibilityReport.d.ts +70 -0
  96. package/dist/gltf/GltfConservativeBounds.d.ts +18 -0
  97. package/dist/gltf/GltfDracoDecoder.d.ts +4 -0
  98. package/dist/gltf/GltfExtensionAdapter.d.ts +54 -0
  99. package/dist/gltf/GltfLoaderContract.d.ts +249 -0
  100. package/dist/gltf/GltfLoaderErrors.d.ts +4 -0
  101. package/dist/gltf/GltfMaterialDescriptor.d.ts +23 -0
  102. package/dist/gltf/GltfMaterialEncoder.d.ts +20 -0
  103. package/dist/gltf/GltfMaterialLoader.d.ts +6 -0
  104. package/dist/gltf/GltfModelComponent.d.ts +72 -0
  105. package/dist/gltf/GltfModelSystem.d.ts +37 -0
  106. package/dist/gltf/GltfPlugin.d.ts +6 -0
  107. package/dist/gltf/GltfSchema.d.ts +225 -0
  108. package/dist/gltf/GltfUvSemanticPlanner.d.ts +33 -0
  109. package/dist/gltf/gltfLoader.d.ts +9 -0
  110. package/dist/gltf-animation3d.d.ts +3 -0
  111. package/dist/gltf-animation3d.js +8 -0
  112. package/dist/gltf-worker-runtime.d.ts +7 -0
  113. package/dist/gltf-worker-runtime.js +6981 -0
  114. package/dist/gltf.d.ts +12 -0
  115. package/dist/gltf.js +517 -0
  116. package/dist/grid/Grid2DComponent.d.ts +25 -0
  117. package/dist/grid.d.ts +2 -0
  118. package/dist/grid.js +56 -0
  119. package/dist/hya-state-machine.d.ts +7 -0
  120. package/dist/hya-state-machine.js +2934 -0
  121. package/dist/index.d.ts +2 -0
  122. package/dist/index.js +7 -0
  123. package/dist/internal/2d-ui-shader-artifact.js +870 -0
  124. package/dist/plugins/pluginUtils.d.ts +20 -0
  125. package/dist/plugins.d.ts +6 -0
  126. package/dist/shaders/generated/2d-ui-artifact.generated.d.ts +658 -0
  127. package/dist/spine/Spine2DComponent.d.ts +116 -0
  128. package/dist/spine/Spine2DGpuRenderer.d.ts +65 -0
  129. package/dist/spine/Spine2DRenderSystem.d.ts +27 -0
  130. package/dist/spine/Spine2DRuntime.d.ts +103 -0
  131. package/dist/spine/SpineAnimationBoneTimelines.d.ts +8 -0
  132. package/dist/spine/SpineAssetParser.d.ts +18 -0
  133. package/dist/spine/SpineAssetWorkerClient.d.ts +19 -0
  134. package/dist/spine/SpineAssetWorkerContract.d.ts +6 -0
  135. package/dist/spine/SpineAtlasParser.d.ts +21 -0
  136. package/dist/spine/SpineFloatBuilder.d.ts +15 -0
  137. package/dist/spine/SpinePathConstraintSolver.d.ts +32 -0
  138. package/dist/spine/SpinePlugin.d.ts +8 -0
  139. package/dist/spine/SpineSkeletonRuntime.d.ts +185 -0
  140. package/dist/spine/SpineSlotAnimation.d.ts +17 -0
  141. package/dist/spine/SpineTimelineRuntime.d.ts +25 -0
  142. package/dist/spine/SpineVertexBuilder.d.ts +61 -0
  143. package/dist/spine.d.ts +7 -0
  144. package/dist/spine.js +578 -0
  145. package/dist/tilemap/Tilemap2DComponent.d.ts +110 -0
  146. package/dist/tilemap/Tilemap2DRenderSystem.d.ts +11 -0
  147. package/dist/tilemap/Tilemap2DRenderer.d.ts +24 -0
  148. package/dist/tilemap/TilemapPlugin.d.ts +8 -0
  149. package/dist/tilemap.d.ts +6 -0
  150. package/dist/tilemap.js +535 -0
  151. package/dist/tween/Tween2DComponent.d.ts +70 -0
  152. package/dist/tween/Tween2DSystem.d.ts +12 -0
  153. package/dist/tween.d.ts +4 -0
  154. package/dist/tween.js +138 -0
  155. package/dist/utils/RenderSystem2DBase.d.ts +42 -0
  156. package/dist/utils/arrayAccess.d.ts +4 -0
  157. package/dist/utils/camera2d.d.ts +12 -0
  158. package/dist/utils/render2dGpu.d.ts +32 -0
  159. package/package.json +124 -0
  160. package/src/animation/Animation2DComponent.ts +135 -0
  161. package/src/animation/Animation2DExtensionRegistry.ts +52 -0
  162. package/src/animation/Animation2DRenderSystem.ts +1026 -0
  163. package/src/animation/Animation2DRuntime.ts +1326 -0
  164. package/src/animation/Animation2DStateMachine.ts +39 -0
  165. package/src/animation/Animation2DStateMachineComponent.ts +228 -0
  166. package/src/animation/Animation2DStateMachineRuntime.ts +141 -0
  167. package/src/animation/Animation2DStateMachineSystem.ts +60 -0
  168. package/src/animation/Animation2DStateMachineVisualRuntime.ts +282 -0
  169. package/src/animation/Animation2DSystem.ts +72 -0
  170. package/src/animation/AnimationAssetLoader.ts +84 -0
  171. package/src/animation/AnimationAudioClip.ts +140 -0
  172. package/src/animation/AnimationPathTessellator.ts +691 -0
  173. package/src/animation/AnimationTextRasterizer.ts +340 -0
  174. package/src/animation/AnimationVisual2D.ts +153 -0
  175. package/src/animation/HyaAnimation2DClipAdapter.ts +845 -0
  176. package/src/animation/Particle2DDescriptorAdapter.ts +35 -0
  177. package/src/animation/runtime/mixer/Action.ts +876 -0
  178. package/src/animation/runtime/mixer/Mixer.ts +505 -0
  179. package/src/animation/runtime/mixer/PoseBuffer.ts +105 -0
  180. package/src/animation/runtime/mixer/Sampler.ts +252 -0
  181. package/src/animation/runtime/mixer/Types.ts +138 -0
  182. package/src/animation/runtime/mixer/index.ts +31 -0
  183. package/src/animation-state-machine/AnimationStateMachine.ts +146 -0
  184. package/src/animation-state-machine/AnimationStateMachineChannels.ts +116 -0
  185. package/src/animation-state-machine/runtime/Animation2DStateMachineMixerAdapter.ts +197 -0
  186. package/src/animation-state-machine/runtime/AnimationStateMachineBlendTreeWeights.ts +503 -0
  187. package/src/animation-state-machine/runtime/AnimationStateMachineCompiler.ts +763 -0
  188. package/src/animation-state-machine/runtime/AnimationStateMachineController.ts +987 -0
  189. package/src/animation-state-machine/runtime/AnimationStateMachineMixerPort.ts +54 -0
  190. package/src/animation-state-machine/runtime/index.ts +47 -0
  191. package/src/animation.ts +33 -0
  192. package/src/animation3d/Animation3DAction.ts +73 -0
  193. package/src/animation3d/Animation3DBinding.ts +116 -0
  194. package/src/animation3d/Animation3DClip.ts +22 -0
  195. package/src/animation3d/Animation3DError.ts +34 -0
  196. package/src/animation3d/Animation3DMixer.ts +82 -0
  197. package/src/animation3d/Animation3DPose.ts +100 -0
  198. package/src/animation3d/Animation3DPoseBuffer.ts +85 -0
  199. package/src/animation3d/Animation3DResource.ts +49 -0
  200. package/src/animation3d/Animation3DStateMachine.ts +126 -0
  201. package/src/animation3d/Animation3DStateMachineRuntime.ts +191 -0
  202. package/src/animation3d/Animation3DTrack.ts +29 -0
  203. package/src/animation3d/hya/HyaAnimation3DRuntime.ts +756 -0
  204. package/src/animation3d/hya/HyaAnimation3DStateMachineRuntime.ts +618 -0
  205. package/src/animation3d/hya/HyaAnimation3DTypes.ts +168 -0
  206. package/src/animation3d/hya/index.ts +10 -0
  207. package/src/animation3d/index.ts +76 -0
  208. package/src/animation3d/runtime/integration/Animation3DStateMachineMixerAdapter.ts +325 -0
  209. package/src/animation3d/runtime/integration/Animation3DStateMachineMixerIntegration.ts +158 -0
  210. package/src/animation3d/runtime/integration/index.ts +9 -0
  211. package/src/animation3d/runtime/mixer/Action.ts +833 -0
  212. package/src/animation3d/runtime/mixer/Animation3DMixerRuntimeStore.ts +26 -0
  213. package/src/animation3d/runtime/mixer/Mixer.ts +562 -0
  214. package/src/animation3d/runtime/mixer/PoseBuffer.ts +1 -0
  215. package/src/animation3d/runtime/mixer/TrackSampler.ts +399 -0
  216. package/src/animation3d/runtime/mixer/index.ts +8 -0
  217. package/src/animation3d/runtime/state-machine/Animation3DBlendTreeWeights.ts +4 -0
  218. package/src/animation3d/runtime/state-machine/Animation3DStateMachineCompiler.ts +1 -0
  219. package/src/animation3d/runtime/state-machine/Animation3DStateMachineController.ts +1 -0
  220. package/src/animation3d/runtime/state-machine/Animation3DStateMachineMixerPort.ts +1 -0
  221. package/src/animation3d/runtime/state-machine/index.ts +45 -0
  222. package/src/animation3d.ts +5 -0
  223. package/src/benchmark.ts +168 -0
  224. package/src/canvas-text/CanvasText2DRenderSystem.ts +292 -0
  225. package/src/canvas-text/CanvasTextComponent.ts +47 -0
  226. package/src/canvas-text.ts +4 -0
  227. package/src/experimental-gltf-worker.ts +18 -0
  228. package/src/experimental-spine-worker.ts +9 -0
  229. package/src/gltf/GltfAccessorReader.ts +271 -0
  230. package/src/gltf/GltfAnimation3DAdapter.ts +680 -0
  231. package/src/gltf/GltfAnimationRuntime.ts +392 -0
  232. package/src/gltf/GltfAssetWorkerClient.ts +136 -0
  233. package/src/gltf/GltfCompatibilityReport.ts +214 -0
  234. package/src/gltf/GltfConservativeBounds.ts +219 -0
  235. package/src/gltf/GltfDracoDecoder.ts +251 -0
  236. package/src/gltf/GltfExtensionAdapter.ts +340 -0
  237. package/src/gltf/GltfLoaderContract.ts +333 -0
  238. package/src/gltf/GltfLoaderErrors.ts +59 -0
  239. package/src/gltf/GltfMaterialDescriptor.ts +134 -0
  240. package/src/gltf/GltfMaterialEncoder.ts +173 -0
  241. package/src/gltf/GltfMaterialLoader.ts +293 -0
  242. package/src/gltf/GltfModelComponent.ts +115 -0
  243. package/src/gltf/GltfModelSystem.ts +208 -0
  244. package/src/gltf/GltfPlugin.ts +84 -0
  245. package/src/gltf/GltfSchema.ts +229 -0
  246. package/src/gltf/GltfUvSemanticPlanner.ts +166 -0
  247. package/src/gltf/gltfLoader.ts +910 -0
  248. package/src/gltf-animation3d.ts +10 -0
  249. package/src/gltf-worker-runtime.ts +10 -0
  250. package/src/gltf.ts +56 -0
  251. package/src/grid/Grid2DComponent.ts +69 -0
  252. package/src/grid.ts +2 -0
  253. package/src/hya-state-machine.ts +19 -0
  254. package/src/index.ts +2 -0
  255. package/src/plugins/pluginUtils.ts +50 -0
  256. package/src/plugins.ts +6 -0
  257. package/src/shaders/generated/2d-ui-animation-2d.generated.wgsl +242 -0
  258. package/src/shaders/generated/2d-ui-artifact.generated.ts +867 -0
  259. package/src/shaders/generated/2d-ui-canvas-text-2d.generated.wgsl +38 -0
  260. package/src/shaders/generated/2d-ui-spine2d.generated.wgsl +41 -0
  261. package/src/shaders/generated/2d-ui-tilemap2d.generated.wgsl +36 -0
  262. package/src/spine/Spine2DComponent.ts +168 -0
  263. package/src/spine/Spine2DGpuRenderer.ts +449 -0
  264. package/src/spine/Spine2DRenderSystem.ts +199 -0
  265. package/src/spine/Spine2DRuntime.ts +1529 -0
  266. package/src/spine/SpineAnimationBoneTimelines.ts +30 -0
  267. package/src/spine/SpineAssetParser.ts +20 -0
  268. package/src/spine/SpineAssetWorkerClient.ts +112 -0
  269. package/src/spine/SpineAssetWorkerContract.ts +4 -0
  270. package/src/spine/SpineAtlasParser.ts +127 -0
  271. package/src/spine/SpineFloatBuilder.ts +66 -0
  272. package/src/spine/SpinePathConstraintSolver.ts +582 -0
  273. package/src/spine/SpinePlugin.ts +76 -0
  274. package/src/spine/SpineSkeletonRuntime.ts +521 -0
  275. package/src/spine/SpineSlotAnimation.ts +195 -0
  276. package/src/spine/SpineTimelineRuntime.ts +453 -0
  277. package/src/spine/SpineVertexBuilder.ts +686 -0
  278. package/src/spine.ts +7 -0
  279. package/src/tilemap/Tilemap2DComponent.ts +232 -0
  280. package/src/tilemap/Tilemap2DRenderSystem.ts +58 -0
  281. package/src/tilemap/Tilemap2DRenderer.ts +289 -0
  282. package/src/tilemap/TilemapPlugin.ts +75 -0
  283. package/src/tilemap.ts +6 -0
  284. package/src/tween/Tween2DComponent.ts +83 -0
  285. package/src/tween/Tween2DSystem.ts +78 -0
  286. package/src/tween.ts +4 -0
  287. package/src/types/earcut.d.ts +7 -0
  288. package/src/types/wgsl.d.ts +4 -0
  289. package/src/utils/RenderSystem2DBase.ts +164 -0
  290. package/src/utils/arrayAccess.ts +17 -0
  291. package/src/utils/camera2d.ts +68 -0
  292. package/src/utils/render2dGpu.ts +132 -0
  293. package/test/fixtures/gltf/animation-characterization.gltf +344 -0
@@ -0,0 +1,110 @@
1
+ import { Component } from '@haiyue/engine';
2
+ export type TilemapCellValue = number;
3
+ export type TilemapPaletteColor = [number, number, number, number];
4
+ export interface Tilemap2DComponentOptions {
5
+ columns?: number;
6
+ rows?: number;
7
+ cellWidth?: number;
8
+ cellHeight?: number;
9
+ originX?: number;
10
+ originY?: number;
11
+ gap?: number;
12
+ cells?: ArrayLike<TilemapCellValue>;
13
+ palette?: TilemapPaletteColor[];
14
+ }
15
+ export declare class Tilemap2DComponent extends Component {
16
+ static UniqueCheckType: number;
17
+ static UniqueSymbol: symbol;
18
+ static editor: {
19
+ fields: {
20
+ columns: {
21
+ type: string;
22
+ label: string;
23
+ min: number;
24
+ step: number;
25
+ };
26
+ rows: {
27
+ type: string;
28
+ label: string;
29
+ min: number;
30
+ step: number;
31
+ };
32
+ cellWidth: {
33
+ type: string;
34
+ label: string;
35
+ min: number;
36
+ step: number;
37
+ };
38
+ cellHeight: {
39
+ type: string;
40
+ label: string;
41
+ min: number;
42
+ step: number;
43
+ };
44
+ gap: {
45
+ type: string;
46
+ label: string;
47
+ min: number;
48
+ step: number;
49
+ };
50
+ originX: {
51
+ type: string;
52
+ label: string;
53
+ step: number;
54
+ };
55
+ originY: {
56
+ type: string;
57
+ label: string;
58
+ step: number;
59
+ };
60
+ palette: {
61
+ type: string;
62
+ label: string;
63
+ rows: number;
64
+ };
65
+ cells: {
66
+ type: string;
67
+ label: string;
68
+ rows: number;
69
+ };
70
+ };
71
+ };
72
+ private _columns;
73
+ private _rows;
74
+ private _cellWidth;
75
+ private _cellHeight;
76
+ private _originX;
77
+ private _originY;
78
+ private _gap;
79
+ private _cells;
80
+ private _palette;
81
+ private _version;
82
+ constructor(options?: Tilemap2DComponentOptions);
83
+ get columns(): number;
84
+ set columns(value: number);
85
+ get rows(): number;
86
+ set rows(value: number);
87
+ get cellWidth(): number;
88
+ set cellWidth(value: number);
89
+ get cellHeight(): number;
90
+ set cellHeight(value: number);
91
+ get originX(): number;
92
+ set originX(value: number);
93
+ get originY(): number;
94
+ set originY(value: number);
95
+ get gap(): number;
96
+ set gap(value: number);
97
+ get cells(): Int16Array;
98
+ set cells(value: Int16Array);
99
+ get palette(): TilemapPaletteColor[];
100
+ set palette(value: TilemapPaletteColor[]);
101
+ get version(): number;
102
+ markDirty(): this;
103
+ index(column: number, row: number): number;
104
+ contains(column: number, row: number): boolean;
105
+ getCell(column: number, row: number): TilemapCellValue;
106
+ setCell(column: number, row: number, value: TilemapCellValue): this;
107
+ clear(value?: number): this;
108
+ resize(columns: number, rows: number): this;
109
+ clone(): Tilemap2DComponent;
110
+ }
@@ -0,0 +1,11 @@
1
+ import { type IEngine, type RenderCommandContext } from '@haiyue/engine/extension-authoring';
2
+ import { Entity, World } from '@haiyue/engine/ecs';
3
+ import { RenderSystem2DBase, type RenderSystem2DBaseOptions } from '../utils/RenderSystem2DBase';
4
+ export type Tilemap2DRenderSystemOptions = RenderSystem2DBaseOptions;
5
+ export declare class Tilemap2DRenderSystem extends RenderSystem2DBase {
6
+ private renderer;
7
+ constructor(engine: IEngine, cameraEntity: Entity, options?: Tilemap2DRenderSystemOptions);
8
+ record(world: World, context: RenderCommandContext): this;
9
+ destroy(): this;
10
+ protected releaseGpuResourcesForRecovery(): void;
11
+ }
@@ -0,0 +1,24 @@
1
+ import { type IEngine } from '@haiyue/engine/extension-authoring';
2
+ import type { Tilemap2DComponent } from './Tilemap2DComponent';
3
+ export declare class Tilemap2DRenderer {
4
+ reverseZ: boolean;
5
+ msaaSamples: 1 | 4;
6
+ private engine;
7
+ private cameraGpu;
8
+ private objectLayout;
9
+ private shaderModule;
10
+ private pipelineLayout;
11
+ private sharedGpu;
12
+ private entityCache;
13
+ private signatureCache;
14
+ private initialized;
15
+ prepare(engine: IEngine): void;
16
+ updateCamera(viewProj: Float32Array): void;
17
+ releaseEntitiesNotIn(liveEntities: ReadonlySet<number>): void;
18
+ render(passEncoder: GPURenderPassEncoder, entityId: number, tilemap: Tilemap2DComponent, worldMatrix: Float32Array): void;
19
+ private computeSignature;
20
+ private buildVertices;
21
+ private getPipeline;
22
+ destroy(): void;
23
+ private destroyEntityGpu;
24
+ }
@@ -0,0 +1,8 @@
1
+ import type { EnginePlugin } from '@haiyue/engine/core';
2
+ import type { RenderPipelineEntryOptions } from '@haiyue/engine/extension-authoring';
3
+ import { type Tilemap2DRenderSystemOptions } from './Tilemap2DRenderSystem';
4
+ export interface TilemapPluginOptions {
5
+ system?: Tilemap2DRenderSystemOptions;
6
+ render?: RenderPipelineEntryOptions | false | null;
7
+ }
8
+ export declare function createTilemapPlugin(options?: TilemapPluginOptions): EnginePlugin;
@@ -0,0 +1,6 @@
1
+ export { Tilemap2DComponent } from './tilemap/Tilemap2DComponent';
2
+ export type { Tilemap2DComponentOptions, TilemapCellValue, TilemapPaletteColor } from './tilemap/Tilemap2DComponent';
3
+ export { Tilemap2DRenderSystem } from './tilemap/Tilemap2DRenderSystem';
4
+ export type { Tilemap2DRenderSystemOptions } from './tilemap/Tilemap2DRenderSystem';
5
+ export { createTilemapPlugin } from './tilemap/TilemapPlugin';
6
+ export type { TilemapPluginOptions } from './tilemap/TilemapPlugin';
@@ -0,0 +1,535 @@
1
+ import { Component } from '@haiyue/engine';
2
+ import { UniqueCheckType } from '@haiyue/engine/ecs';
3
+ import { requireEngineDevice, getExtensionGPUResourceTracker, beginRenderCommandPass } from '@haiyue/engine/extension-authoring';
4
+ import { c as createCamera2DGpu, f as writeFloatBuffer, g as createObject2DGpu, w as writeObjectMatrixIfChanged, d as destroyCamera2DGpu, h as destroyObject2DGpu, i as createCamera2DLayout, b as createObject2DLayout, R as RenderSystem2DBase } from './chunks/RenderSystem2DBase-DDT61dAu.js';
5
+ import { t as tilemap2dWgsl } from './chunks/2d-ui-tilemap2d.generated-gebw4mX7.js';
6
+ import { E as EXTENSIONS_PLUGIN_VERSION, i as installEditorRenderSystem, r as removeSystem } from './chunks/pluginUtils-CvwroRMd.js';
7
+ import '@haiyue/engine/components';
8
+ import 'wgpu-matrix';
9
+
10
+ class Tilemap2DComponent extends Component {
11
+ static UniqueCheckType = UniqueCheckType.SYMBOL | UniqueCheckType.REPLACE;
12
+ static UniqueSymbol = Symbol.for('Tilemap2DComponent');
13
+ static editor = {
14
+ fields: {
15
+ columns: { type: 'number', label: 'Columns', min: 1, step: 1 },
16
+ rows: { type: 'number', label: 'Rows', min: 1, step: 1 },
17
+ cellWidth: { type: 'number', label: 'Cell Width', min: 0.001, step: 1 },
18
+ cellHeight: { type: 'number', label: 'Cell Height', min: 0.001, step: 1 },
19
+ gap: { type: 'number', label: 'Gap', min: 0, step: 1 },
20
+ originX: { type: 'number', label: 'Origin X', step: 1 },
21
+ originY: { type: 'number', label: 'Origin Y', step: 1 },
22
+ palette: { type: 'json', label: 'Palette JSON', rows: 7 },
23
+ cells: { type: 'int-array', label: 'Cells JSON', rows: 8 },
24
+ },
25
+ };
26
+ _columns;
27
+ _rows;
28
+ _cellWidth;
29
+ _cellHeight;
30
+ _originX;
31
+ _originY;
32
+ _gap;
33
+ _cells;
34
+ _palette;
35
+ _version = 0;
36
+ constructor(options = {}) {
37
+ super('Tilemap2DComponent');
38
+ this._columns = Math.max(1, Math.floor(options.columns ?? 10));
39
+ this._rows = Math.max(1, Math.floor(options.rows ?? 20));
40
+ this._cellWidth = options.cellWidth ?? 32;
41
+ this._cellHeight = options.cellHeight ?? 32;
42
+ this._originX = options.originX ?? 0;
43
+ this._originY = options.originY ?? 0;
44
+ this._gap = Math.max(0, options.gap ?? 1);
45
+ this._cells = new Int16Array(this.columns * this.rows);
46
+ if (options.cells)
47
+ this._cells.set(Array.from(options.cells).slice(0, this._cells.length));
48
+ this._palette = options.palette?.length
49
+ ? options.palette.map(color => [...color])
50
+ : [
51
+ [0, 0, 0, 0],
52
+ [0.18, 0.62, 1, 1],
53
+ [0.96, 0.72, 0.18, 1],
54
+ [0.35, 0.86, 0.48, 1],
55
+ [0.92, 0.28, 0.36, 1],
56
+ ];
57
+ }
58
+ get columns() {
59
+ return this._columns;
60
+ }
61
+ set columns(value) {
62
+ const next = Math.max(1, Math.floor(value));
63
+ if (this._columns === next)
64
+ return;
65
+ this._columns = next;
66
+ this.markDirty();
67
+ }
68
+ get rows() {
69
+ return this._rows;
70
+ }
71
+ set rows(value) {
72
+ const next = Math.max(1, Math.floor(value));
73
+ if (this._rows === next)
74
+ return;
75
+ this._rows = next;
76
+ this.markDirty();
77
+ }
78
+ get cellWidth() {
79
+ return this._cellWidth;
80
+ }
81
+ set cellWidth(value) {
82
+ if (this._cellWidth === value)
83
+ return;
84
+ this._cellWidth = value;
85
+ this.markDirty();
86
+ }
87
+ get cellHeight() {
88
+ return this._cellHeight;
89
+ }
90
+ set cellHeight(value) {
91
+ if (this._cellHeight === value)
92
+ return;
93
+ this._cellHeight = value;
94
+ this.markDirty();
95
+ }
96
+ get originX() {
97
+ return this._originX;
98
+ }
99
+ set originX(value) {
100
+ if (this._originX === value)
101
+ return;
102
+ this._originX = value;
103
+ this.markDirty();
104
+ }
105
+ get originY() {
106
+ return this._originY;
107
+ }
108
+ set originY(value) {
109
+ if (this._originY === value)
110
+ return;
111
+ this._originY = value;
112
+ this.markDirty();
113
+ }
114
+ get gap() {
115
+ return this._gap;
116
+ }
117
+ set gap(value) {
118
+ const next = Math.max(0, value);
119
+ if (this._gap === next)
120
+ return;
121
+ this._gap = next;
122
+ this.markDirty();
123
+ }
124
+ get cells() {
125
+ return this._cells;
126
+ }
127
+ set cells(value) {
128
+ this._cells = value;
129
+ this.markDirty();
130
+ }
131
+ get palette() {
132
+ return this._palette;
133
+ }
134
+ set palette(value) {
135
+ this._palette = value;
136
+ this.markDirty();
137
+ }
138
+ get version() {
139
+ return this._version;
140
+ }
141
+ markDirty() {
142
+ this._version++;
143
+ return this;
144
+ }
145
+ index(column, row) {
146
+ return row * this.columns + column;
147
+ }
148
+ contains(column, row) {
149
+ return column >= 0 && row >= 0 && column < this.columns && row < this.rows;
150
+ }
151
+ getCell(column, row) {
152
+ if (!this.contains(column, row))
153
+ return 0;
154
+ return this.cells[this.index(column, row)] ?? 0;
155
+ }
156
+ setCell(column, row, value) {
157
+ if (this.contains(column, row)) {
158
+ const index = this.index(column, row);
159
+ if (this._cells[index] !== value) {
160
+ this._cells[index] = value;
161
+ this.markDirty();
162
+ }
163
+ }
164
+ return this;
165
+ }
166
+ clear(value = 0) {
167
+ this._cells.fill(value);
168
+ this.markDirty();
169
+ return this;
170
+ }
171
+ resize(columns, rows) {
172
+ const nextColumns = Math.max(1, Math.floor(columns));
173
+ const nextRows = Math.max(1, Math.floor(rows));
174
+ if (nextColumns === this.columns && nextRows === this.rows)
175
+ return this;
176
+ const next = new Int16Array(nextColumns * nextRows);
177
+ const copyColumns = Math.min(this.columns, nextColumns);
178
+ const copyRows = Math.min(this.rows, nextRows);
179
+ for (let row = 0; row < copyRows; row++) {
180
+ for (let column = 0; column < copyColumns; column++) {
181
+ next[row * nextColumns + column] = this.getCell(column, row);
182
+ }
183
+ }
184
+ this._columns = nextColumns;
185
+ this._rows = nextRows;
186
+ this._cells = next;
187
+ this.markDirty();
188
+ return this;
189
+ }
190
+ clone() {
191
+ return new Tilemap2DComponent({
192
+ columns: this.columns,
193
+ rows: this.rows,
194
+ cellWidth: this.cellWidth,
195
+ cellHeight: this.cellHeight,
196
+ originX: this.originX,
197
+ originY: this.originY,
198
+ gap: this.gap,
199
+ cells: this.cells,
200
+ palette: this.palette,
201
+ });
202
+ }
203
+ }
204
+
205
+ const TILEMAP_WGSL = tilemap2dWgsl;
206
+ const TILEMAP_INITIAL_VERTEX_FLOATS = 36;
207
+ const TILEMAP_INITIAL_VERTEX_BYTES = TILEMAP_INITIAL_VERTEX_FLOATS * 4;
208
+ const tilemapSharedGpuCache = new WeakMap();
209
+ function getTilemapSharedGpu(device) {
210
+ let shared = tilemapSharedGpuCache.get(device);
211
+ if (shared)
212
+ return shared;
213
+ const cameraLayout = createCamera2DLayout(device);
214
+ const objectLayout = createObject2DLayout(device);
215
+ const shaderModule = device.createShaderModule({ code: TILEMAP_WGSL });
216
+ const pipelineLayout = device.createPipelineLayout({
217
+ bindGroupLayouts: [cameraLayout, objectLayout],
218
+ });
219
+ shared = {
220
+ cameraLayout,
221
+ objectLayout,
222
+ shaderModule,
223
+ pipelineLayout,
224
+ pipelineCache: new Map(),
225
+ };
226
+ tilemapSharedGpuCache.set(device, shared);
227
+ return shared;
228
+ }
229
+ class Tilemap2DRenderer {
230
+ reverseZ = false;
231
+ msaaSamples = 1;
232
+ engine;
233
+ cameraGpu;
234
+ objectLayout;
235
+ shaderModule;
236
+ pipelineLayout;
237
+ sharedGpu;
238
+ entityCache = new Map();
239
+ signatureCache = new WeakMap();
240
+ initialized = false;
241
+ prepare(engine) {
242
+ if (this.initialized)
243
+ return;
244
+ this.initialized = true;
245
+ this.engine = engine;
246
+ const device = requireEngineDevice(engine);
247
+ this.sharedGpu = getTilemapSharedGpu(device);
248
+ this.cameraGpu = createCamera2DGpu(device, getExtensionGPUResourceTracker(engine), this.sharedGpu.cameraLayout);
249
+ this.objectLayout = this.sharedGpu.objectLayout;
250
+ this.shaderModule = this.sharedGpu.shaderModule;
251
+ this.pipelineLayout = this.sharedGpu.pipelineLayout;
252
+ }
253
+ updateCamera(viewProj) {
254
+ writeFloatBuffer(requireEngineDevice(this.engine).queue, this.cameraGpu.buffer, viewProj);
255
+ }
256
+ releaseEntitiesNotIn(liveEntities) {
257
+ for (const [entityId, entityGpu] of this.entityCache) {
258
+ if (!liveEntities.has(entityId)) {
259
+ this.destroyEntityGpu(entityGpu);
260
+ this.entityCache.delete(entityId);
261
+ }
262
+ }
263
+ }
264
+ render(passEncoder, entityId, tilemap, worldMatrix) {
265
+ const device = requireEngineDevice(this.engine);
266
+ const signature = this.computeSignature(tilemap);
267
+ let entityGpu = this.entityCache.get(entityId);
268
+ if (!entityGpu) {
269
+ entityGpu = {
270
+ objectGpu: createObject2DGpu(device, this.objectLayout, getExtensionGPUResourceTracker(this.engine)),
271
+ vertexBuffer: device.createBuffer({
272
+ size: TILEMAP_INITIAL_VERTEX_BYTES,
273
+ usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,
274
+ }),
275
+ vertexBufferSize: TILEMAP_INITIAL_VERTEX_BYTES,
276
+ vertexData: new Float32Array(TILEMAP_INITIAL_VERTEX_FLOATS),
277
+ vertexByteLength: 0,
278
+ vertexCount: 0,
279
+ tilemapSignature: '',
280
+ };
281
+ getExtensionGPUResourceTracker(this.engine)?.trackBuffer(entityGpu.vertexBuffer, 'Tilemap2DRenderer.vertexBuffer', entityGpu.vertexBufferSize);
282
+ this.entityCache.set(entityId, entityGpu);
283
+ }
284
+ if (entityGpu.tilemapSignature !== signature) {
285
+ this.buildVertices(tilemap, entityGpu);
286
+ entityGpu.tilemapSignature = signature;
287
+ if (entityGpu.vertexByteLength > entityGpu.vertexBufferSize) {
288
+ getExtensionGPUResourceTracker(this.engine)?.untrackBuffer(entityGpu.vertexBuffer);
289
+ entityGpu.vertexBuffer.destroy();
290
+ entityGpu.vertexBufferSize = Math.max(entityGpu.vertexByteLength, entityGpu.vertexBufferSize * 2);
291
+ entityGpu.vertexBuffer = device.createBuffer({
292
+ size: entityGpu.vertexBufferSize,
293
+ usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,
294
+ });
295
+ getExtensionGPUResourceTracker(this.engine)?.trackBuffer(entityGpu.vertexBuffer, 'Tilemap2DRenderer.vertexBuffer', entityGpu.vertexBufferSize);
296
+ }
297
+ if (entityGpu.vertexByteLength > 0) {
298
+ device.queue.writeBuffer(entityGpu.vertexBuffer, 0, entityGpu.vertexData.buffer, entityGpu.vertexData.byteOffset, entityGpu.vertexByteLength);
299
+ }
300
+ }
301
+ if (entityGpu.vertexCount === 0)
302
+ return;
303
+ writeObjectMatrixIfChanged(device.queue, entityGpu.objectGpu, worldMatrix);
304
+ passEncoder.setPipeline(this.getPipeline());
305
+ passEncoder.setBindGroup(0, this.cameraGpu.bindGroup);
306
+ passEncoder.setBindGroup(1, entityGpu.objectGpu.bindGroup);
307
+ passEncoder.setVertexBuffer(0, entityGpu.vertexBuffer);
308
+ passEncoder.draw(entityGpu.vertexCount);
309
+ }
310
+ computeSignature(tilemap) {
311
+ const cached = this.signatureCache.get(tilemap);
312
+ if (cached && cached.version === tilemap.version) {
313
+ return cached.signature;
314
+ }
315
+ const signature = String(tilemap.version);
316
+ this.signatureCache.set(tilemap, {
317
+ version: tilemap.version,
318
+ signature,
319
+ });
320
+ return signature;
321
+ }
322
+ buildVertices(tilemap, entityGpu) {
323
+ let count = 0;
324
+ for (const cell of tilemap.cells) {
325
+ if (cell > 0)
326
+ count++;
327
+ }
328
+ if (count === 0) {
329
+ entityGpu.vertexByteLength = 0;
330
+ entityGpu.vertexCount = 0;
331
+ return;
332
+ }
333
+ const requiredFloats = count * 6 * 6;
334
+ if (entityGpu.vertexData.length < requiredFloats) {
335
+ entityGpu.vertexData = new Float32Array(Math.max(requiredFloats, entityGpu.vertexData.length * 2, 36));
336
+ }
337
+ const vertices = entityGpu.vertexData;
338
+ let offset = 0;
339
+ const gap = tilemap.gap;
340
+ const w = Math.max(0, tilemap.cellWidth - gap);
341
+ const h = Math.max(0, tilemap.cellHeight - gap);
342
+ const push = (x, y, color) => {
343
+ vertices[offset++] = x;
344
+ vertices[offset++] = y;
345
+ vertices[offset++] = color[0] ?? 1;
346
+ vertices[offset++] = color[1] ?? 1;
347
+ vertices[offset++] = color[2] ?? 1;
348
+ vertices[offset++] = color[3] ?? 1;
349
+ };
350
+ for (let row = 0; row < tilemap.rows; row++) {
351
+ for (let column = 0; column < tilemap.columns; column++) {
352
+ const value = tilemap.getCell(column, row);
353
+ if (value <= 0)
354
+ continue;
355
+ const color = tilemap.palette[value] ?? tilemap.palette[1] ?? [1, 1, 1, 1];
356
+ const x0 = tilemap.originX + column * tilemap.cellWidth + gap * 0.5;
357
+ const y0 = tilemap.originY + row * tilemap.cellHeight + gap * 0.5;
358
+ const x1 = x0 + w;
359
+ const y1 = y0 + h;
360
+ push(x0, y0, color);
361
+ push(x1, y0, color);
362
+ push(x1, y1, color);
363
+ push(x0, y0, color);
364
+ push(x1, y1, color);
365
+ push(x0, y1, color);
366
+ }
367
+ }
368
+ entityGpu.vertexByteLength = requiredFloats * 4;
369
+ entityGpu.vertexCount = count * 6;
370
+ }
371
+ getPipeline() {
372
+ const depthFormat = this.engine.getDepthFormat(this.reverseZ);
373
+ const key = (this.reverseZ ? 1 : 0) | ((this.msaaSamples > 1 ? 1 : 0) << 1);
374
+ let pipeline = this.sharedGpu.pipelineCache.get(key);
375
+ if (pipeline)
376
+ return pipeline;
377
+ const device = requireEngineDevice(this.engine);
378
+ const { format } = this.engine;
379
+ const created = device.createRenderPipeline({
380
+ layout: this.pipelineLayout,
381
+ vertex: {
382
+ module: this.shaderModule,
383
+ entryPoint: 'vs_main',
384
+ buffers: [{
385
+ arrayStride: 24,
386
+ attributes: [
387
+ { shaderLocation: 0, offset: 0, format: 'float32x2' },
388
+ { shaderLocation: 1, offset: 8, format: 'float32x4' },
389
+ ],
390
+ }],
391
+ },
392
+ fragment: {
393
+ module: this.shaderModule,
394
+ entryPoint: 'fs_main',
395
+ targets: [{
396
+ format,
397
+ blend: {
398
+ color: { srcFactor: 'src-alpha', dstFactor: 'one-minus-src-alpha', operation: 'add' },
399
+ alpha: { srcFactor: 'one', dstFactor: 'one-minus-src-alpha', operation: 'add' },
400
+ },
401
+ }],
402
+ },
403
+ primitive: { topology: 'triangle-list', cullMode: 'none' },
404
+ depthStencil: {
405
+ format: depthFormat,
406
+ depthWriteEnabled: false,
407
+ depthCompare: 'always',
408
+ },
409
+ multisample: { count: this.msaaSamples },
410
+ });
411
+ this.sharedGpu.pipelineCache.set(key, created);
412
+ return created;
413
+ }
414
+ destroy() {
415
+ if (this.cameraGpu)
416
+ destroyCamera2DGpu(this.cameraGpu);
417
+ for (const entity of this.entityCache.values())
418
+ this.destroyEntityGpu(entity);
419
+ this.entityCache.clear();
420
+ }
421
+ destroyEntityGpu(entity) {
422
+ destroyObject2DGpu(entity.objectGpu);
423
+ getExtensionGPUResourceTracker(this.engine)?.untrackBuffer(entity.vertexBuffer);
424
+ entity.vertexBuffer.destroy();
425
+ }
426
+ }
427
+
428
+ class Tilemap2DRenderSystem extends RenderSystem2DBase {
429
+ renderer = null;
430
+ constructor(engine, cameraEntity, options = {}) {
431
+ super({ all: [Tilemap2DComponent] }, engine, cameraEntity, options, 'Tilemap2DRenderSystem');
432
+ }
433
+ record(world, context) {
434
+ if (this.disabled)
435
+ return this;
436
+ if (!this.renderer) {
437
+ this.renderer = new Tilemap2DRenderer();
438
+ this.renderer.prepare(this.engine);
439
+ }
440
+ this.renderer.reverseZ = context.view?.reverseZ ?? this.engine.reverseZ;
441
+ this.renderer.msaaSamples = context.view?.sampleCount ?? this.engine.msaaSamples;
442
+ const liveEntities = this.beginLiveEntityTracking();
443
+ const camera = this.getCamera2D(context);
444
+ if (!camera)
445
+ return this;
446
+ this.renderer.updateCamera(this.computeCameraViewProjection(camera, context));
447
+ const { passEncoder, ownsPass } = beginRenderCommandPass(context);
448
+ const entities = this.entitySet.get(world);
449
+ if (entities)
450
+ for (const entity of entities) {
451
+ if (!this.isEntityRenderable(entity))
452
+ continue;
453
+ const tilemap = entity.getComponent(Tilemap2DComponent);
454
+ if (!tilemap)
455
+ continue;
456
+ this.renderer.render(passEncoder, entity.id, tilemap, this.getWorldMatrix2D(entity, context));
457
+ this.markEntityLive(entity);
458
+ }
459
+ if (ownsPass)
460
+ passEncoder.end();
461
+ this.renderer.releaseEntitiesNotIn(liveEntities);
462
+ return this;
463
+ }
464
+ destroy() {
465
+ this.releaseGpuResourcesForRecovery();
466
+ return super.destroy();
467
+ }
468
+ releaseGpuResourcesForRecovery() {
469
+ this.renderer?.destroy();
470
+ this.renderer = null;
471
+ }
472
+ }
473
+
474
+ function createTilemapPlugin(options = {}) {
475
+ let system = null;
476
+ return {
477
+ name: '@haiyue/extensions/tilemap',
478
+ version: EXTENSIONS_PLUGIN_VERSION,
479
+ installEngine(context) {
480
+ context.registerComponent({ type: 'Tilemap2DComponent', component: Tilemap2DComponent });
481
+ },
482
+ installScene(context) {
483
+ context.registerComponent({ type: 'Tilemap2DComponent', component: Tilemap2DComponent });
484
+ system = new Tilemap2DRenderSystem(context.engine, context.cameraEntity, options.system);
485
+ context.addSystem(system, options.render ?? { pass: 'shared', loadOp: system.loadOp });
486
+ },
487
+ uninstallScene(context) {
488
+ removeSystem(context, system);
489
+ system = null;
490
+ },
491
+ installEditor(context) {
492
+ context.registerContribution({ components: [{
493
+ type: 'Tilemap2DComponent',
494
+ create: () => new Tilemap2DComponent({ columns: 10, rows: 20, cellWidth: 32, cellHeight: 32, gap: 1 }),
495
+ inspector: Tilemap2DComponent.editor,
496
+ serialize(component) {
497
+ return {
498
+ type: 'Tilemap2DComponent',
499
+ columns: component.columns,
500
+ rows: component.rows,
501
+ cellWidth: component.cellWidth,
502
+ cellHeight: component.cellHeight,
503
+ originX: component.originX,
504
+ originY: component.originY,
505
+ gap: component.gap,
506
+ cells: Array.from(component.cells),
507
+ palette: component.palette.map(color => [...color]),
508
+ };
509
+ },
510
+ deserialize(data) {
511
+ const value = data;
512
+ return value.type === 'Tilemap2DComponent' ? new Tilemap2DComponent(value) : null;
513
+ },
514
+ clone: (component) => component.clone(),
515
+ installViewport(viewport) {
516
+ return installEditorRenderSystem(viewport, Tilemap2DRenderSystem, () => new Tilemap2DRenderSystem(viewport.engine, viewport.camera2DEntity, options.system));
517
+ },
518
+ runtimeExport: {
519
+ imports: [{ from: '@haiyue/extensions/tilemap', names: ['Tilemap2DComponent', 'Tilemap2DRenderSystem'] }],
520
+ systems: ['Tilemap2DRenderSystem'],
521
+ deserializeExpression: 'new Tilemap2DComponent(data)',
522
+ installSystems: ` const tilemapCamera = findCamera2DEntity(world);
523
+ if (tilemapCamera && hasComponentType(world, Tilemap2DComponent)) {
524
+ applyViewportSettingsToCamera2D(tilemapCamera, scene.globals);
525
+ addRenderSystem(new Tilemap2DRenderSystem(engine, tilemapCamera, { loadOp: 'load', priority: 2 }), { pass: 'shared', loadOp: 'load' });
526
+ }`,
527
+ has2D: true,
528
+ },
529
+ }] });
530
+ },
531
+ };
532
+ }
533
+
534
+ export { Tilemap2DComponent, Tilemap2DRenderSystem, createTilemapPlugin };
535
+ //# sourceMappingURL=tilemap.js.map