lecodes-sdk 0.19.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 (367) hide show
  1. package/README.md +114 -0
  2. package/dist/global.d.ts +503 -0
  3. package/dist/host.d.ts +61 -0
  4. package/dist/inject.js +4730 -0
  5. package/dist/types/animate/animate.d.ts +20 -0
  6. package/dist/types/animate/bezier.d.ts +2 -0
  7. package/dist/types/animate/easings.d.ts +21 -0
  8. package/dist/types/canvas/Canvas.d.ts +168 -0
  9. package/dist/types/core/Aspect.d.ts +171 -0
  10. package/dist/types/core/InspectorUI.d.ts +88 -0
  11. package/dist/types/core/StateMachine.d.ts +81 -0
  12. package/dist/types/core/color.d.ts +13 -0
  13. package/dist/types/core/compWrite.d.ts +11 -0
  14. package/dist/types/core/events.d.ts +11 -0
  15. package/dist/types/core/fields.d.ts +58 -0
  16. package/dist/types/core/registry.d.ts +7 -0
  17. package/dist/types/core/signals.d.ts +29 -0
  18. package/dist/types/core/time.d.ts +31 -0
  19. package/dist/types/g2/Camera2D.d.ts +19 -0
  20. package/dist/types/g2/CharacterController2D.d.ts +134 -0
  21. package/dist/types/g2/Node2D.d.ts +91 -0
  22. package/dist/types/g2/OneWay2D.d.ts +24 -0
  23. package/dist/types/g2/Physics2D.d.ts +147 -0
  24. package/dist/types/g2/Scene2D.d.ts +72 -0
  25. package/dist/types/g2/Shape2D.d.ts +58 -0
  26. package/dist/types/g2/Sprite.d.ts +51 -0
  27. package/dist/types/g2/SpriteAnimation.d.ts +50 -0
  28. package/dist/types/g2/SpriteSheet.d.ts +69 -0
  29. package/dist/types/g2/Texture2D.d.ts +16 -0
  30. package/dist/types/g2/Tilemap.d.ts +20 -0
  31. package/dist/types/g2/Tileset.d.ts +32 -0
  32. package/dist/types/g2/Trigger2D.d.ts +20 -0
  33. package/dist/types/g2/autotile.d.ts +133 -0
  34. package/dist/types/g2/cells.d.ts +14 -0
  35. package/dist/types/g2/defineScene2d.d.ts +141 -0
  36. package/dist/types/g2/groups2d.d.ts +16 -0
  37. package/dist/types/g2/loop.d.ts +4 -0
  38. package/dist/types/g2/scenarios2d.d.ts +30 -0
  39. package/dist/types/g2/touch.d.ts +2 -0
  40. package/dist/types/gl/Camera.d.ts +79 -0
  41. package/dist/types/gl/CameraPlace.d.ts +26 -0
  42. package/dist/types/gl/CharacterController.d.ts +98 -0
  43. package/dist/types/gl/Gearbox.d.ts +86 -0
  44. package/dist/types/gl/Geometry.d.ts +39 -0
  45. package/dist/types/gl/IK.d.ts +53 -0
  46. package/dist/types/gl/InstancedMesh.d.ts +46 -0
  47. package/dist/types/gl/Light.d.ts +73 -0
  48. package/dist/types/gl/Lightmap.d.ts +85 -0
  49. package/dist/types/gl/Locomotion.d.ts +279 -0
  50. package/dist/types/gl/Material.d.ts +100 -0
  51. package/dist/types/gl/Mesh.d.ts +33 -0
  52. package/dist/types/gl/Model.d.ts +53 -0
  53. package/dist/types/gl/NavAgent.d.ts +99 -0
  54. package/dist/types/gl/NavMesh.d.ts +169 -0
  55. package/dist/types/gl/Node.d.ts +99 -0
  56. package/dist/types/gl/Noise.d.ts +20 -0
  57. package/dist/types/gl/Particles.d.ts +277 -0
  58. package/dist/types/gl/Physics.d.ts +91 -0
  59. package/dist/types/gl/Plane.d.ts +19 -0
  60. package/dist/types/gl/Ragdoll.d.ts +86 -0
  61. package/dist/types/gl/Ray.d.ts +8 -0
  62. package/dist/types/gl/Scene.d.ts +221 -0
  63. package/dist/types/gl/Shape.d.ts +122 -0
  64. package/dist/types/gl/Terrain.d.ts +280 -0
  65. package/dist/types/gl/Texture.d.ts +27 -0
  66. package/dist/types/gl/Trigger.d.ts +10 -0
  67. package/dist/types/gl/Vehicle.d.ts +191 -0
  68. package/dist/types/gl/Wheel.d.ts +95 -0
  69. package/dist/types/gl/animation/AnimationClip.d.ts +60 -0
  70. package/dist/types/gl/animation/Animator.d.ts +219 -0
  71. package/dist/types/gl/animation/Layer.d.ts +31 -0
  72. package/dist/types/gl/animation/Loop.d.ts +17 -0
  73. package/dist/types/gl/animation/Playback.d.ts +36 -0
  74. package/dist/types/gl/animation/core.d.ts +367 -0
  75. package/dist/types/gl/controls.d.ts +19 -0
  76. package/dist/types/gl/physicsEvents.d.ts +1 -0
  77. package/dist/types/gl/scenarios.d.ts +98 -0
  78. package/dist/types/gl/state.d.ts +5 -0
  79. package/dist/types/gl/terrainMesh.d.ts +46 -0
  80. package/dist/types/gl/touch.d.ts +2 -0
  81. package/dist/types/inject.d.ts +123 -0
  82. package/dist/types/math/Mathf.d.ts +39 -0
  83. package/dist/types/math/mat4.d.ts +66 -0
  84. package/dist/types/math/quat.d.ts +53 -0
  85. package/dist/types/math/vec.d.ts +129 -0
  86. package/dist/types/net/codec.d.ts +25 -0
  87. package/dist/types/net/core.d.ts +106 -0
  88. package/dist/types/net/index.d.ts +80 -0
  89. package/dist/types/net/replication.d.ts +101 -0
  90. package/dist/types/plugins/camera.d.ts +25 -0
  91. package/dist/types/plugins/geolocation.d.ts +39 -0
  92. package/dist/types/plugins/oauth.d.ts +25 -0
  93. package/dist/types/plugins/permission.d.ts +1 -0
  94. package/dist/types/plugins/push.d.ts +46 -0
  95. package/dist/types/plugins/qr.d.ts +21 -0
  96. package/dist/types/plugins/service.d.ts +33 -0
  97. package/dist/types/runtime/app.d.ts +67 -0
  98. package/dist/types/runtime/appEvents.d.ts +7 -0
  99. package/dist/types/runtime/channel.d.ts +1 -0
  100. package/dist/types/runtime/clipboard.d.ts +7 -0
  101. package/dist/types/runtime/datetime.d.ts +80 -0
  102. package/dist/types/runtime/device.d.ts +126 -0
  103. package/dist/types/runtime/fetch.d.ts +31 -0
  104. package/dist/types/runtime/files.d.ts +33 -0
  105. package/dist/types/runtime/input.d.ts +121 -0
  106. package/dist/types/runtime/media.d.ts +46 -0
  107. package/dist/types/runtime/misc.d.ts +11 -0
  108. package/dist/types/runtime/net.d.ts +15 -0
  109. package/dist/types/runtime/rpc.d.ts +44 -0
  110. package/dist/types/runtime/service.d.ts +1 -0
  111. package/dist/types/runtime/share.d.ts +2 -0
  112. package/dist/types/runtime/storage.d.ts +5 -0
  113. package/dist/types/runtime/touch.d.ts +56 -0
  114. package/dist/types/scene/defineScene.d.ts +296 -0
  115. package/dist/types/scene/editorPlugins.d.ts +82 -0
  116. package/dist/types/scene/gizmos.d.ts +56 -0
  117. package/dist/types/scene/grammar.d.ts +56 -0
  118. package/dist/types/scene/level.d.ts +98 -0
  119. package/dist/types/scene/material.d.ts +76 -0
  120. package/dist/types/server/auth/appConfig.d.ts +16 -0
  121. package/dist/types/server/auth/global.d.ts +56 -0
  122. package/dist/types/server/auth/models.d.ts +164 -0
  123. package/dist/types/server/auth/types.d.ts +56 -0
  124. package/dist/types/server/channel.d.ts +28 -0
  125. package/dist/types/server/context.d.ts +27 -0
  126. package/dist/types/server/db/defineDb.d.ts +36 -0
  127. package/dist/types/server/db/fields.d.ts +146 -0
  128. package/dist/types/server/db/index.d.ts +6 -0
  129. package/dist/types/server/db/marci/query.d.ts +326 -0
  130. package/dist/types/server/db/types.d.ts +163 -0
  131. package/dist/types/server/errors.d.ts +8 -0
  132. package/dist/types/server/inject.d.ts +5 -0
  133. package/dist/types/ui/NativeView.d.ts +38 -0
  134. package/dist/types/ui/UI.d.ts +27 -0
  135. package/dist/types/ui/UIBottomSheet.d.ts +71 -0
  136. package/dist/types/ui/UIButton.d.ts +30 -0
  137. package/dist/types/ui/UIContainer.d.ts +33 -0
  138. package/dist/types/ui/UIImage.d.ts +35 -0
  139. package/dist/types/ui/UIInput.d.ts +110 -0
  140. package/dist/types/ui/UIModal.d.ts +70 -0
  141. package/dist/types/ui/UINode.d.ts +363 -0
  142. package/dist/types/ui/UIPager.d.ts +123 -0
  143. package/dist/types/ui/UIPopover.d.ts +39 -0
  144. package/dist/types/ui/UIScreen.d.ts +57 -0
  145. package/dist/types/ui/UIScrollable.d.ts +40 -0
  146. package/dist/types/ui/UISpacer.d.ts +9 -0
  147. package/dist/types/ui/UITabs.d.ts +96 -0
  148. package/dist/types/ui/UIText.d.ts +19 -0
  149. package/dist/types/ui/UIVideo.d.ts +28 -0
  150. package/dist/types/ui/UIVirtualizedList.d.ts +97 -0
  151. package/dist/types/ui/UIWidget.d.ts +65 -0
  152. package/dist/types/ui/fonts.d.ts +9 -0
  153. package/dist/types/ui/presentable.d.ts +68 -0
  154. package/dist/types/ui/router.d.ts +40 -0
  155. package/dist/types/ui/theme.d.ts +26 -0
  156. package/dist/types.json +1 -0
  157. package/package.json +46 -0
  158. package/prompts/2d.md +395 -0
  159. package/prompts/3d-scene-files.md +113 -0
  160. package/prompts/3d-scene.md +119 -0
  161. package/prompts/3d.md +303 -0
  162. package/prompts/README.md +142 -0
  163. package/prompts/ar.md +109 -0
  164. package/prompts/canvas.md +27 -0
  165. package/prompts/compose.ts +46 -0
  166. package/prompts/concept.md +49 -0
  167. package/prompts/core-design.md +75 -0
  168. package/prompts/core.md +264 -0
  169. package/prompts/design.md +218 -0
  170. package/prompts/dist/2d-game.md +1530 -0
  171. package/prompts/dist/3d-app.md +1672 -0
  172. package/prompts/dist/ar-app.md +1548 -0
  173. package/prompts/dist/concept.md +49 -0
  174. package/prompts/dist/design.md +498 -0
  175. package/prompts/dist/ui-app.md +1134 -0
  176. package/prompts/index.md +37 -0
  177. package/prompts/intake-prompt.md +33 -0
  178. package/prompts/namer-prompt.md +12 -0
  179. package/prompts/router-prompt.md +50 -0
  180. package/prompts/select.ts +111 -0
  181. package/prompts/ui-design.md +203 -0
  182. package/prompts/ui.md +803 -0
  183. package/src/animate/animate.ts +238 -0
  184. package/src/animate/bezier.ts +138 -0
  185. package/src/animate/easings.ts +126 -0
  186. package/src/bridges.d.ts +1345 -0
  187. package/src/canvas/Canvas.ts +305 -0
  188. package/src/compile/__tests__/assetIconMacro.test.ts +219 -0
  189. package/src/compile/__tests__/assetMacro.test.ts +74 -0
  190. package/src/compile/__tests__/assetName.test.ts +55 -0
  191. package/src/compile/__tests__/compile.test.ts +287 -0
  192. package/src/compile/__tests__/detectEntry.test.ts +132 -0
  193. package/src/compile/__tests__/fontMacro.test.ts +199 -0
  194. package/src/compile/aspectMacro.ts +86 -0
  195. package/src/compile/assetIconMacro.ts +384 -0
  196. package/src/compile/assetMacro.ts +146 -0
  197. package/src/compile/assetName.ts +50 -0
  198. package/src/compile/bundler.ts +287 -0
  199. package/src/compile/compileProject.ts +127 -0
  200. package/src/compile/detectEntry.ts +128 -0
  201. package/src/compile/fontMacro.ts +459 -0
  202. package/src/compile/fontRegistry.ts +78 -0
  203. package/src/compile/header.ts +67 -0
  204. package/src/compile/index.ts +100 -0
  205. package/src/compile/libraryImports.ts +52 -0
  206. package/src/compile/liteMaterial.ts +247 -0
  207. package/src/compile/sceneEditor.ts +88 -0
  208. package/src/compile/serverSplit.ts +233 -0
  209. package/src/compile/serverTypes.ts +227 -0
  210. package/src/compile/sfnt.ts +98 -0
  211. package/src/compile/shaderSchema.ts +202 -0
  212. package/src/compile/shaderTargets.ts +77 -0
  213. package/src/compile/sourcemap.ts +25 -0
  214. package/src/core/Aspect.ts +568 -0
  215. package/src/core/InspectorUI.ts +212 -0
  216. package/src/core/StateMachine.ts +308 -0
  217. package/src/core/__tests__/stateMachine.test.ts +132 -0
  218. package/src/core/color.ts +66 -0
  219. package/src/core/compWrite.ts +42 -0
  220. package/src/core/events.ts +38 -0
  221. package/src/core/fields.ts +120 -0
  222. package/src/core/registry.ts +23 -0
  223. package/src/core/signals.ts +277 -0
  224. package/src/core/time.ts +84 -0
  225. package/src/g2/Camera2D.ts +40 -0
  226. package/src/g2/CharacterController2D.ts +276 -0
  227. package/src/g2/Node2D.ts +267 -0
  228. package/src/g2/OneWay2D.ts +66 -0
  229. package/src/g2/Physics2D.ts +346 -0
  230. package/src/g2/Scene2D.ts +209 -0
  231. package/src/g2/Shape2D.ts +259 -0
  232. package/src/g2/Sprite.ts +89 -0
  233. package/src/g2/SpriteAnimation.ts +171 -0
  234. package/src/g2/SpriteSheet.ts +166 -0
  235. package/src/g2/Texture2D.ts +47 -0
  236. package/src/g2/Tilemap.ts +41 -0
  237. package/src/g2/Tileset.ts +71 -0
  238. package/src/g2/Trigger2D.ts +77 -0
  239. package/src/g2/autotile.ts +433 -0
  240. package/src/g2/cells.ts +91 -0
  241. package/src/g2/defineScene2d.ts +381 -0
  242. package/src/g2/groups2d.ts +106 -0
  243. package/src/g2/loop.ts +50 -0
  244. package/src/g2/scenarios2d.ts +69 -0
  245. package/src/g2/touch.ts +83 -0
  246. package/src/gl/Camera.ts +160 -0
  247. package/src/gl/CameraPlace.ts +52 -0
  248. package/src/gl/CharacterController.ts +238 -0
  249. package/src/gl/Gearbox.ts +212 -0
  250. package/src/gl/Geometry.ts +279 -0
  251. package/src/gl/IK.ts +193 -0
  252. package/src/gl/InstancedMesh.ts +132 -0
  253. package/src/gl/Light.ts +135 -0
  254. package/src/gl/Lightmap.ts +402 -0
  255. package/src/gl/Locomotion.ts +498 -0
  256. package/src/gl/Material.ts +279 -0
  257. package/src/gl/Mesh.ts +83 -0
  258. package/src/gl/Model.ts +124 -0
  259. package/src/gl/NavAgent.ts +337 -0
  260. package/src/gl/NavMesh.ts +397 -0
  261. package/src/gl/Node.ts +350 -0
  262. package/src/gl/Noise.ts +30 -0
  263. package/src/gl/Particles.ts +676 -0
  264. package/src/gl/Physics.ts +222 -0
  265. package/src/gl/Plane.ts +53 -0
  266. package/src/gl/Ragdoll.ts +270 -0
  267. package/src/gl/Ray.ts +16 -0
  268. package/src/gl/Scene.ts +505 -0
  269. package/src/gl/Shape.ts +409 -0
  270. package/src/gl/Terrain.ts +1092 -0
  271. package/src/gl/Texture.ts +63 -0
  272. package/src/gl/Trigger.ts +45 -0
  273. package/src/gl/Vehicle.ts +473 -0
  274. package/src/gl/Wheel.ts +240 -0
  275. package/src/gl/animation/AnimationClip.ts +204 -0
  276. package/src/gl/animation/Animator.ts +329 -0
  277. package/src/gl/animation/Layer.ts +39 -0
  278. package/src/gl/animation/Loop.ts +31 -0
  279. package/src/gl/animation/Playback.ts +52 -0
  280. package/src/gl/animation/core.ts +670 -0
  281. package/src/gl/controls.ts +95 -0
  282. package/src/gl/physicsEvents.ts +20 -0
  283. package/src/gl/scenarios.ts +291 -0
  284. package/src/gl/state.ts +6 -0
  285. package/src/gl/terrainMesh.ts +219 -0
  286. package/src/gl/touch.ts +68 -0
  287. package/src/host.d.ts +61 -0
  288. package/src/inject.ts +203 -0
  289. package/src/math/Mathf.ts +118 -0
  290. package/src/math/mat4.ts +278 -0
  291. package/src/math/quat.ts +232 -0
  292. package/src/math/vec.ts +255 -0
  293. package/src/net/codec.ts +119 -0
  294. package/src/net/core.ts +384 -0
  295. package/src/net/index.ts +181 -0
  296. package/src/net/replication.ts +622 -0
  297. package/src/plugins/camera.ts +81 -0
  298. package/src/plugins/geolocation.ts +123 -0
  299. package/src/plugins/oauth.ts +61 -0
  300. package/src/plugins/permission.ts +7 -0
  301. package/src/plugins/push.ts +132 -0
  302. package/src/plugins/qr.ts +73 -0
  303. package/src/plugins/service.ts +47 -0
  304. package/src/runtime/app.ts +101 -0
  305. package/src/runtime/appEvents.ts +54 -0
  306. package/src/runtime/channel.ts +61 -0
  307. package/src/runtime/clipboard.ts +20 -0
  308. package/src/runtime/datetime.ts +329 -0
  309. package/src/runtime/device.ts +293 -0
  310. package/src/runtime/fetch.ts +77 -0
  311. package/src/runtime/files.ts +108 -0
  312. package/src/runtime/input.ts +175 -0
  313. package/src/runtime/media.ts +111 -0
  314. package/src/runtime/misc.ts +16 -0
  315. package/src/runtime/net.ts +36 -0
  316. package/src/runtime/rpc.ts +218 -0
  317. package/src/runtime/service.ts +83 -0
  318. package/src/runtime/share.ts +9 -0
  319. package/src/runtime/storage.ts +13 -0
  320. package/src/runtime/touch.ts +76 -0
  321. package/src/scene/defineScene.ts +1396 -0
  322. package/src/scene/editorPlugins.ts +110 -0
  323. package/src/scene/gizmos.ts +148 -0
  324. package/src/scene/grammar.ts +120 -0
  325. package/src/scene/level.ts +296 -0
  326. package/src/scene/material.ts +188 -0
  327. package/src/server/auth/appConfig.ts +12 -0
  328. package/src/server/auth/global.ts +80 -0
  329. package/src/server/auth/host.ts +318 -0
  330. package/src/server/auth/models.ts +83 -0
  331. package/src/server/auth/types.ts +50 -0
  332. package/src/server/channel.ts +56 -0
  333. package/src/server/context.ts +36 -0
  334. package/src/server/db/defineDb.ts +237 -0
  335. package/src/server/db/fields.ts +132 -0
  336. package/src/server/db/httpTransport.ts +93 -0
  337. package/src/server/db/index.ts +7 -0
  338. package/src/server/db/marci/query.ts +412 -0
  339. package/src/server/db/types.ts +202 -0
  340. package/src/server/errors.ts +12 -0
  341. package/src/server/host.ts +74 -0
  342. package/src/server/inject.ts +13 -0
  343. package/src/server/runtime.ts +133 -0
  344. package/src/server/validate.ts +87 -0
  345. package/src/ui/NativeView.ts +142 -0
  346. package/src/ui/UI.ts +39 -0
  347. package/src/ui/UIBottomSheet.ts +139 -0
  348. package/src/ui/UIButton.ts +101 -0
  349. package/src/ui/UIContainer.ts +60 -0
  350. package/src/ui/UIImage.ts +83 -0
  351. package/src/ui/UIInput.ts +185 -0
  352. package/src/ui/UIModal.ts +139 -0
  353. package/src/ui/UINode.ts +830 -0
  354. package/src/ui/UIPager.ts +362 -0
  355. package/src/ui/UIPopover.ts +100 -0
  356. package/src/ui/UIScreen.ts +123 -0
  357. package/src/ui/UIScrollable.ts +87 -0
  358. package/src/ui/UISpacer.ts +14 -0
  359. package/src/ui/UITabs.ts +236 -0
  360. package/src/ui/UIText.ts +51 -0
  361. package/src/ui/UIVideo.ts +88 -0
  362. package/src/ui/UIVirtualizedList.ts +241 -0
  363. package/src/ui/UIWidget.ts +127 -0
  364. package/src/ui/fonts.ts +13 -0
  365. package/src/ui/presentable.ts +117 -0
  366. package/src/ui/router.ts +132 -0
  367. package/src/ui/theme.ts +84 -0
@@ -0,0 +1,7 @@
1
+ export declare class Registry<T> {
2
+ private map;
3
+ set(id: number, value: T): void;
4
+ get(id: number): T | undefined;
5
+ delete(id: number): void;
6
+ has(id: number): boolean;
7
+ }
@@ -0,0 +1,29 @@
1
+ /** Runs every pending effect now instead of waiting for the microtask (test/host hook). */
2
+ export declare const flushEffects: () => void;
3
+ export interface Signal<T> {
4
+ value: T;
5
+ /** Read without subscribing the current effect/computed. */
6
+ peek(): T;
7
+ }
8
+ export interface Computed<T> {
9
+ readonly value: T;
10
+ /** Read without subscribing the current effect/computed (still recomputes if stale). */
11
+ peek(): T;
12
+ }
13
+ /**
14
+ * A reactive value. Reading `.value` inside an `effect`/`computed` (or a function-valued style
15
+ * prop / `UIText` content) subscribes it; writing `.value` re-runs subscribers (batched — once
16
+ * per microtask).
17
+ */
18
+ export declare function signal<T>(initialValue: T): Signal<T>;
19
+ export declare function signal<T = undefined>(): Signal<T | undefined>;
20
+ /** A lazily-cached derived value: recomputes on read after any of its dependencies changed. */
21
+ export declare function computed<T>(fn: () => T): Computed<T>;
22
+ /**
23
+ * Runs `fn` now and again whenever any signal/computed it read changes (batched per microtask).
24
+ * Returns a dispose function; an undisposed effect lives for the rest of the app run.
25
+ */
26
+ export declare function effect(fn: () => void): () => void;
27
+ /** The shape UINode's Element exposes for binding ownership. */
28
+ export interface BindingHost {
29
+ }
@@ -0,0 +1,31 @@
1
+ declare class TimeClock {
2
+ private _scale;
3
+ private _paused;
4
+ /** The fixed step: what `updateFixed(dt)` receives, every time, on every machine (1/60). Under
5
+ * `scale` the NUMBER of fixed steps per frame changes, never this value. */
6
+ readonly fixedDt: number;
7
+ /** Seconds of GAME time since the app started (scaled; stops while paused). */
8
+ now: number;
9
+ /** Seconds of wall-clock time since the app started (never stops). */
10
+ unscaledNow: number;
11
+ /** This frame's delta in game seconds — what `update(dt)` receives. 0 while paused. */
12
+ dt: number;
13
+ /** This frame's wall-clock delta in seconds (the host's frame time, clamped by the engine). */
14
+ unscaledDt: number;
15
+ /** Frames dispatched since the app started (counts paused frames too). */
16
+ frame: number;
17
+ /** Speed of the game relative to wall-clock: 1 normal, 0.5 half speed, 2 double. Applied to
18
+ * `dt`, `now` AND the engines' physics / animation / particle clocks. Negative or NaN → 0. */
19
+ get scale(): number;
20
+ set scale(v: number);
21
+ /** Freeze the game: `dt` reads 0, aspects without `updateWhilePaused` are skipped, the engines'
22
+ * simulations stop. `scale` is remembered and restored on resume. */
23
+ get paused(): boolean;
24
+ set paused(v: boolean);
25
+ /** The scale the engines currently run at (0 while paused). */
26
+ get effectiveScale(): number;
27
+ private _push;
28
+ }
29
+ /** The game clock — scale / pause the whole game, read `dt` / `now` anywhere. */
30
+ export declare const Time: TimeClock;
31
+ export {};
@@ -0,0 +1,19 @@
1
+ import { Vec2, type Vec2Like } from "../math/vec";
2
+ import type { CompAxis, CompWriter } from "../core/compWrite";
3
+ export declare class Camera2D implements CompWriter {
4
+ private _x;
5
+ private _y;
6
+ private _zoom;
7
+ private _rotation;
8
+ private readonly sceneId;
9
+ constructor(sceneId: number);
10
+ get position(): Vec2;
11
+ set position(v: Vec2Like);
12
+ _writeComp(_prop: string, axis: CompAxis, v: number): void;
13
+ get zoom(): number;
14
+ set zoom(z: number);
15
+ get rotation(): number;
16
+ set rotation(deg: number);
17
+ screenToWorld(screenX: number, screenY: number): Vec2;
18
+ worldToScreen(worldX: number, worldY: number): Vec2;
19
+ }
@@ -0,0 +1,134 @@
1
+ import { Aspect } from "../core/Aspect";
2
+ import type { FieldMeta } from "../core/fields";
3
+ import { Vec2, type Vec2Like } from "../math/vec";
4
+ import type { CompWriter } from "../core/compWrite";
5
+ import { PhysicsGroup2D } from "./groups2d";
6
+ import { type Node2D } from "./Node2D";
7
+ /** Where the character's feet are, as reported by the solver after the last step. */
8
+ export type GroundState2D = "ground" | "slope" | "air";
9
+ /** One surface the mover pushed out of this step. `normal` points back at the character. */
10
+ export type Collision2D = {
11
+ node: Node2D | null;
12
+ normal: Vec2;
13
+ };
14
+ export declare class CharacterController2D extends Aspect<"controller", Node2D> implements CompWriter {
15
+ static readonly aspect = "controller";
16
+ static fields: FieldMeta<CharacterController2D>;
17
+ private _id;
18
+ private _gravityScale;
19
+ private _maxSlope;
20
+ private _group;
21
+ private _dropThrough;
22
+ private _repush;
23
+ onAttach(): void;
24
+ onDetach(): void;
25
+ /** Native character id (0 until attached / no physics support). */
26
+ get id(): number;
27
+ /**
28
+ * This frame's movement command, in world units/s — NOT normalized, NOT a per-frame displacement
29
+ * (that is what Unity's `Move` takes; passing `v * dt` here gives a character 60× too slow).
30
+ *
31
+ * ONE component = horizontal, the everyday platformer call. TWO = the whole velocity, for free mode
32
+ * (`gravityScale = 0`); with gravity on, a two-component call fights the ballistic vertical and the
33
+ * character hangs in the air, so that combination warns once.
34
+ *
35
+ * Sticky only within the frame: the command expires once the engine consumes it. It also **takes the
36
+ * axis back from a latched `velocity`** — commanding is claiming ownership, which is what keeps the
37
+ * two horizontal sources from ever fighting.
38
+ */
39
+ move(x: number): void;
40
+ move(x: number, y: number): void;
41
+ move(v: Vec2Like): void;
42
+ private _warnFree;
43
+ /** Vertical velocity (world units/s) — LATCHED: gravity works on it, you seed it. `= 700` to jump,
44
+ * `+= 300` to stack an explosion on top of the current motion. No ground check: guard it yourself
45
+ * with `grounded` (or don't, for a double jump). Does nothing in free mode. `velocity.y = 700` is
46
+ * the same channel — pick whichever reads better. */
47
+ get velocityY(): number;
48
+ set velocityY(v: number);
49
+ /**
50
+ * READ — the velocity the solver ended up with after the most recent step (world units/s, fresh
51
+ * Vec2): what HAPPENED, not what you asked for. Walking into a wall reads ~0, sliding along one
52
+ * reads the tangent.
53
+ *
54
+ * WRITE — LATCH the whole velocity: a knockback, a wall jump, a launch pad. Unlike `move()` it does
55
+ * not expire, so the character keeps flying, and gravity still pulls the vertical down into a real
56
+ * ballistic arc. It stays until `move()` takes the axis back — so a game simply doesn't call
57
+ * `move()` while the throw lasts, and ends it on its own terms:
58
+ *
59
+ * hero.controller.velocity = [dir.x * 600, 400] // hit by the blast
60
+ * if (thrown) { if (hero.controller.grounded) thrown = false } // landing ends it
61
+ * else hero.controller.move(ix * SPEED) // …and this reclaims the axis
62
+ *
63
+ * Nothing clears the latch by itself, landing included — a kinematic controller has no friction.
64
+ * Reading is not the inverse of writing: against a wall the read is ~0 and would cancel the throw.
65
+ *
66
+ * `c.velocity.y = 700` (the direct spelling) is a jump — the compiler routes it to the exact
67
+ * `velocityY` channel via `_writeComp` below — and `c.velocity.x = 300` latches the whole vector
68
+ * with the measured vertical filling in. A STORED copy is still a copy (`const v = c.velocity`).
69
+ */
70
+ get velocity(): Vec2;
71
+ set velocity(v: Vec2Like);
72
+ /** Compile-time list (chisel reads it, then strips it) — see CharacterController / core/compWrite.ts. */
73
+ static _comps: string[];
74
+ /** True while standing on walkable ground. */
75
+ get grounded(): boolean;
76
+ /** Where the feet are after the last step: walkable ground, too-steep ground, or the air. */
77
+ get groundState(): GroundState2D;
78
+ /** The surface normal under the feet — for orienting a sprite to a slope, or deciding a slide. */
79
+ get groundNormal(): Vec2;
80
+ /** What the character is standing on: a moving platform, a hazard, an ice patch whose `friction`
81
+ * the game can read. The engine already carries the character along a kinematic platform. */
82
+ get groundNode(): Node2D | null;
83
+ /**
84
+ * Every surface the mover pushed out of during the last step, with the normal pointing back at the
85
+ * character. This is what wall jumps and box pushing are written against — a kinematic mover is not
86
+ * a body, so those contacts do not arrive as 'enter' events.
87
+ *
88
+ * const wall = c.collisions.find(h => Math.abs(h.normal.x) > 0.7)
89
+ * if (wall && jumpPressed) c.velocity = [-wall.normal.x * KICK, JUMP]
90
+ *
91
+ * for (const h of c.collisions) h.node?.physics?.applyImpulse([-h.normal.x * PUSH, 0])
92
+ */
93
+ get collisions(): Collision2D[];
94
+ /** Multiplier over the world gravity; default 1. **0 = free mode**: no gravity, no ground, no
95
+ * stick-to-floor — a swimmer, a drone, a ladder climber, or a top-down hero, driven by the
96
+ * two-component `move()`. */
97
+ get gravityScale(): number;
98
+ set gravityScale(v: number);
99
+ /** Max ground slope (degrees) the character treats as walkable; default 45. Live. */
100
+ get maxSlope(): number;
101
+ set maxSlope(v: number);
102
+ /** Which collision group the character belongs to. Live. */
103
+ get group(): PhysicsGroup2D | undefined;
104
+ set group(g: PhysicsGroup2D | undefined);
105
+ /**
106
+ * While this names a node, that node's `OneWay2D` surfaces are not solid for this character — how
107
+ * you drop off a semisolid platform. A plain latch: whoever sets it clears it.
108
+ *
109
+ * if (downPressed && jumpPressed && c.grounded) {
110
+ * const platform = c.groundNode
111
+ * c.dropThrough = platform
112
+ * setTimeout(() => { if (c.dropThrough === platform) c.dropThrough = null }, 200)
113
+ * }
114
+ *
115
+ * Because it names ONE node, the timeout is not delicate: too long merely means you could have
116
+ * re-landed on that platform for a moment, and the platform below stays solid either way.
117
+ */
118
+ get dropThrough(): Node2D | null;
119
+ set dropThrough(n: Node2D | null);
120
+ /**
121
+ * True while a requested collider resize hasn't taken — you asked to stand up and there is something
122
+ * overhead. Resizing goes through the `Shape2D` aspect itself:
123
+ *
124
+ * hero.aspect(Shape2D, { capsule: CROUCHED }) // always fits — you are shrinking
125
+ * hero.aspect(Shape2D, { capsule: STANDING }) // may be refused under a low ceiling
126
+ * if (hero.controller.resizing) … // still crouched; call it again next frame
127
+ *
128
+ * A refusal changes nothing, so the retry is just the same call again — and it is an exact headroom
129
+ * test against the real capsule, unlike a hand-rolled raycast (a ray is a line; a capsule has
130
+ * girth). The FEET stay planted across a resize, so the character neither hovers nor sinks.
131
+ */
132
+ get resizing(): boolean;
133
+ private _state;
134
+ }
@@ -0,0 +1,91 @@
1
+ import { AspectHost } from "../core/Aspect";
2
+ import type { CompAxis, CompWriter } from "../core/compWrite";
3
+ import { Registry } from "../core/registry";
4
+ import { Vec2, type Vec2Like } from "../math/vec";
5
+ import type { ClickEvent, TouchStartEvent } from "../runtime/touch";
6
+ export { Vec2, type Vec2Like };
7
+ export type Node2DEvents = {
8
+ /** A looping animation clip wrapped around (fires each loop). */
9
+ loopReached: (clip: string) => void;
10
+ /** A non-looping animation clip finished. */
11
+ completed: (clip: string) => void;
12
+ /** A physics contact / sensor overlap began (the other node, plus where and how hard). The
13
+ * contact's `normal` points AWAY from the other node, so `normal.y > 0.7` reads as "I landed on
14
+ * top of it". Sensor overlaps and `exit` carry zeros. */
15
+ enter: (other: Node2D, contact: Contact2D) => void;
16
+ exit: (other: Node2D, contact: Contact2D) => void;
17
+ /** Pointer up over this node's Physics2D shape (a tap/click). */
18
+ click: (ev: ClickEvent<Node2D | null>) => void;
19
+ /** Pointer down on this node's Physics2D shape. Call ev.track(...) to capture the drag. */
20
+ touchstart: (ev: TouchStartEvent<Node2D | null>) => void;
21
+ };
22
+ /** Where a contact happened, delivered as the second argument of 'enter'. `speed` is the approach
23
+ * speed at impact (world units/s) — scale an impact sound with it. Zeros on sensor and 'exit'
24
+ * events, which have no manifold. */
25
+ export type Contact2D = {
26
+ point: Vec2;
27
+ normal: Vec2;
28
+ speed: number;
29
+ };
30
+ /** id → Node2D, so host callbacks (animation events) route back to the owning JS object. */
31
+ export declare const node2dRegistry: Registry<Node2D>;
32
+ export declare class Node2D extends AspectHost<Node2DEvents> implements CompWriter {
33
+ /** Native entity handle. */
34
+ readonly id: number;
35
+ /** Optional debug/editor name (plain JS data — scene2d files stamp their node names here). */
36
+ name?: string;
37
+ protected _x: number;
38
+ protected _y: number;
39
+ protected _rotation: number;
40
+ protected _sx: number;
41
+ protected _sy: number;
42
+ protected _layer: number;
43
+ protected _z: number;
44
+ protected _visible: boolean;
45
+ private _pushXf;
46
+ private _parent;
47
+ private _children;
48
+ constructor(internalId?: number);
49
+ private _pull;
50
+ get x(): number;
51
+ set x(v: number);
52
+ get y(): number;
53
+ set y(v: number);
54
+ _writeComp(_prop: string, axis: CompAxis, v: number): void;
55
+ get position(): Vec2;
56
+ set position(v: Vec2Like);
57
+ /** Rotation in degrees (CCW). */
58
+ get rotation(): number;
59
+ set rotation(deg: number);
60
+ get scale(): Vec2;
61
+ set scale(v: Vec2Like | number);
62
+ /** Draw layer (int). Higher layers render on top. */
63
+ get layer(): number;
64
+ set layer(v: number);
65
+ /** Intra-layer depth for non-Y-sorted layers (higher z = on top). */
66
+ get z(): number;
67
+ set z(v: number);
68
+ get visible(): boolean;
69
+ set visible(v: boolean);
70
+ get parent(): Node2D | null;
71
+ set parent(p: Node2D | null);
72
+ get children(): readonly Node2D[];
73
+ /** Attach children to this node (each keeps its current world transform). Returns this. */
74
+ add(...children: Node2D[]): this;
75
+ /** Detach a direct child (reparents it to root, keeping its world transform). Returns this. */
76
+ remove(child: Node2D): this;
77
+ /**
78
+ * Reparent this node. `keepWorld` (default true) recomputes the local transform so the on-screen
79
+ * position/rotation/scale is unchanged; pass false to keep the local transform and move with the
80
+ * new parent. Self/descendant parents are rejected natively (no cycles).
81
+ */
82
+ setParent(parent: Node2D | null, keepWorld?: boolean): this;
83
+ /** World-space position (composes all ancestors). */
84
+ get worldPosition(): Vec2;
85
+ /** Convert a world-space point into this node's local space (and back). */
86
+ worldToLocal(p: Vec2Like): Vec2;
87
+ localToWorld(p: Vec2Like): Vec2;
88
+ private _syncLocalFromNative;
89
+ addEventListener<K extends keyof Node2DEvents>(channel: K, callback: Node2DEvents[K]): void;
90
+ destroy(): void;
91
+ }
@@ -0,0 +1,24 @@
1
+ import { Aspect } from "../core/Aspect";
2
+ import { type Vec2Like } from "../math/vec";
3
+ import type { Node2D } from "./Node2D";
4
+ export declare class OneWay2D extends Aspect<"oneWay", Node2D> {
5
+ static readonly aspect = "oneWay";
6
+ private _normal;
7
+ private _arc;
8
+ private _enabled;
9
+ /** Which side is solid. Default `[0, 1]` — solid from above, i.e. a floor you pass through from
10
+ * below. `[1, 0]` is a wall you can only enter from the left. */
11
+ get normal(): Vec2Like;
12
+ set normal(v: Vec2Like);
13
+ /** How far off `normal` an approach still counts as coming from the solid side, in degrees.
14
+ * Default 90 — the whole half-plane, which is what a platform wants. */
15
+ get arc(): number;
16
+ set arc(v: number);
17
+ /** Turn the one-way behaviour off, making the surface solid from both sides again. */
18
+ get enabled(): boolean;
19
+ set enabled(v: boolean);
20
+ onAttach(): void;
21
+ onDetach(): void;
22
+ onReconfigure(): void;
23
+ private _push;
24
+ }
@@ -0,0 +1,147 @@
1
+ import { Aspect } from "../core/Aspect";
2
+ import { Vec2, type Vec2Like } from "../math/vec";
3
+ import { type Node2D } from "./Node2D";
4
+ import { PhysicsGroup2D } from "./groups2d";
5
+ export type MotionType = "static" | "kinematic" | "dynamic";
6
+ /** A neutral solid surface. Deliberately the same default as 3D `Physics.friction`. */
7
+ export declare const DEFAULT_FRICTION = 0.6;
8
+ export interface PhysicsConfig {
9
+ /** Gravity in world units/s² (Y-up: down is negative). Default [0, -980]. */
10
+ gravity?: Vec2Like;
11
+ /** Pixels per meter — tunes Box2D's internal tolerances; you still author in world units. Default 64.
12
+ * Only applies before the world exists (it is a global solver tolerance). */
13
+ pixelsPerMeter?: number;
14
+ /** Solver sub-steps per fixed step. Default 4. */
15
+ subSteps?: number;
16
+ }
17
+ /** Closest raycast hit. */
18
+ export interface RayHit {
19
+ node: Node2D | null;
20
+ point: Vec2;
21
+ normal: Vec2;
22
+ fraction: number;
23
+ }
24
+ export declare class Physics2D extends Aspect<"physics", Node2D> {
25
+ static readonly aspect = "physics";
26
+ private _motion;
27
+ /** Static (walls, floors), kinematic (script-driven platforms), or dynamic (fully simulated).
28
+ * Default "dynamic", and LIVE: freeze a crate into `'static'`, hand a ragdoll to `'dynamic'`. */
29
+ get motion(): MotionType;
30
+ set motion(m: MotionType);
31
+ /** Lock rotation (essential for platformer characters). */
32
+ fixedRotation: boolean;
33
+ /** Continuous collision for fast-moving bodies (projectiles). */
34
+ bullet: boolean;
35
+ private _mass;
36
+ private _friction;
37
+ private _bounce;
38
+ private _gravityScale;
39
+ private _linearDamping;
40
+ private _angularDamping;
41
+ private _group;
42
+ private _repush;
43
+ private _h;
44
+ /** Which collision group this body belongs to (see Physics2D.addGroup). Live. */
45
+ get group(): PhysicsGroup2D | undefined;
46
+ set group(g: PhysicsGroup2D | undefined);
47
+ /** Mass in world units. Omitted (or 0) = derived from the collider's AREA, so a big crate really is
48
+ * heavier than a small one. Setting it scales the shape-derived mass data, keeping the rotational
49
+ * inertia in the same ratio — a lopsided collider still tips the way its geometry says. */
50
+ get mass(): number;
51
+ set mass(v: number);
52
+ /** Surface friction. 0 is frictionless, ~1 grippy; two bodies COMBINE as sqrt(a×b), so the lower
53
+ * value wins the argument. Default 0.6 — a neutral solid, matching 3D. */
54
+ get friction(): number;
55
+ set friction(v: number);
56
+ /** Bounciness, 0..1 — the fraction of the approach speed returned on impact. Two bodies combine as
57
+ * MAX (the bouncier one wins — the opposite of friction), and below ~64 units/s no bounce is
58
+ * applied at all, which is what stops a ball jittering on the floor forever. */
59
+ get bounce(): number;
60
+ set bounce(v: number);
61
+ private _pushMaterial;
62
+ /** Native physics body id. 0 until attached, or if the build has no physics support. Mirrors 3D `Physics.id`. */
63
+ get id(): number;
64
+ onAttach(): void;
65
+ onDetach(): void;
66
+ /** Re-applying options (`node.aspect(Physics2D, {…})`) pushes the live ones through. */
67
+ onReconfigure(): void;
68
+ /** Linear velocity in world units/second (fresh Vec2 on read). */
69
+ get velocity(): Vec2;
70
+ set velocity(v: Vec2Like);
71
+ /** Angular velocity in degrees/second. */
72
+ get angularVelocity(): number;
73
+ set angularVelocity(degPerSec: number);
74
+ /** Per-body gravity multiplier: 1 = full world gravity, 0 = floats, <0 = repelled. */
75
+ get gravityScale(): number;
76
+ set gravityScale(scale: number);
77
+ get linearDamping(): number;
78
+ set linearDamping(d: number);
79
+ get angularDamping(): number;
80
+ set angularDamping(d: number);
81
+ /** Pause this body — it stops simulating and stops colliding until re-enabled. */
82
+ set enabled(v: boolean);
83
+ /** Box2D puts resting bodies to sleep; wake one to make it react to a change you made by hand. */
84
+ set awake(v: boolean);
85
+ /** Apply an instantaneous impulse at the centre of mass (never spins the body) and wake it. */
86
+ applyImpulse(v: Vec2Like): this;
87
+ /** Apply an impulse at a WORLD point — the lever arm becomes spin. Use this when the push has a real
88
+ * point of contact: a bullet's hit point, a blast pushing a prop at its base. */
89
+ applyImpulseAt(v: Vec2Like, worldPoint: Vec2Like): this;
90
+ /** Apply a continuous force (world units) and wake the body. */
91
+ applyForce(v: Vec2Like): this;
92
+ /** Set the world's gravity / solver settings. OPTIONAL: the world is created on the first body with
93
+ * gravity [0, -980], 64 px/m and 4 sub-steps. Calling this later changes gravity LIVE and leaves
94
+ * bodies alone. */
95
+ static configure(config?: PhysicsConfig): void;
96
+ /** World gravity, live. */
97
+ static get gravity(): Vec2;
98
+ static set gravity(g: Vec2Like);
99
+ private static _gravity;
100
+ /** Whether this build has physics support (CREATOR_2D_PHYSICS). NOTE: this reports the BUILD, not
101
+ * the world — there is nothing else to guard, since the world creates itself. */
102
+ static get supported(): boolean;
103
+ /** Render interpolation of body transforms between the fixed 60 Hz steps (global; default on). Turn
104
+ * off to save per-frame transform writes when you have many moving bodies / don't need >60 Hz
105
+ * smoothness — bodies then advance in discrete steps. */
106
+ private static _interpolation;
107
+ static get interpolation(): boolean;
108
+ static set interpolation(on: boolean);
109
+ /**
110
+ * Register a collision group. Groups are SUBTRACTIVE and SYMMETRIC (see groups2d.ts):
111
+ *
112
+ * const player = Physics2D.addGroup()
113
+ * const bullets = Physics2D.addGroup().ignoreSelf().ignore(player)
114
+ */
115
+ static addGroup(label?: string): PhysicsGroup2D;
116
+ /** The implicit group of every body that never named one - name it to exclude "everything else". */
117
+ static get defaultGroup(): PhysicsGroup2D;
118
+ /** Closest body hit by the segment, or null. `node` resolves the hit entity. */
119
+ static raycast(from: Vec2Like, to: Vec2Like, q?: Query2D): RayHit | null;
120
+ /** Every body along the segment, NEAREST FIRST - a piercing bullet, a laser, "how many walls are
121
+ * between us". Capped at 32 hits. */
122
+ static raycastAll(from: Vec2Like, to: Vec2Like, q?: Query2D): RayHit[];
123
+ /** Topmost body (solid or sensor) whose shape contains the world point, or null. "Topmost" means
124
+ * by DRAW order - layer, then z - so picking agrees with what the player sees. */
125
+ static overlapPoint(p: Vec2Like, q?: Query2D): Node2D | null;
126
+ /** Everything within `radius` of a point - an explosion, an aura, an aggro range. */
127
+ static overlapCircle(centre: Vec2Like, radius: number, q?: Query2D): Node2D[];
128
+ /** Everything inside an axis-aligned box (centre + HALF-extents) - a room, a camera bound. */
129
+ static overlapBox(centre: Vec2Like, half: Vec2Like, q?: Query2D): Node2D[];
130
+ /**
131
+ * Everything touching a capsule from-to of the given radius. A capsule is the shape a DIRECTED
132
+ * question has: a beam with width, a sword arc, "does my radius fit through this gap" - none of
133
+ * which an axis-aligned box can express.
134
+ *
135
+ * It is also the SWEPT test: a circle of radius r moving from A to B during a frame sweeps exactly
136
+ * this capsule, so a fast projectile checked this way cannot tunnel through a thin wall the way two
137
+ * separate position checks do.
138
+ */
139
+ static overlapCapsule(from: Vec2Like, to: Vec2Like, radius: number, q?: Query2D): Node2D[];
140
+ }
141
+ /** Which groups a query may hit, and what to skip. */
142
+ export type Query2D = {
143
+ /** Only hit bodies in these groups. Omitted = everything. */
144
+ groups?: PhysicsGroup2D[];
145
+ /** Skip these nodes - the "don't hit myself" case a ray fired from inside its own body needs. */
146
+ ignore?: Node2D | Node2D[];
147
+ };
@@ -0,0 +1,72 @@
1
+ import { type ColorInput } from "../core/color";
2
+ import { type Aspect, type AspectCtor, type FieldOf, type TargetOf } from "../core/Aspect";
3
+ import { Presentable, type PresentOptions } from "../ui/presentable";
4
+ import { type Vec2Like } from "../math/vec";
5
+ import type { ClickEvent, TouchStartEvent } from "../runtime/touch";
6
+ import { Camera2D } from "./Camera2D";
7
+ import { type Node2D } from "./Node2D";
8
+ export type Scene2DOptions = {
9
+ /** Background color — '#10131a', 0x10131a, or [r,g,b]/[r,g,b,a] in 0..1. */
10
+ background?: ColorInput;
11
+ /** Texture sampling for the 2D renderer: `'nearest'` (default — crisp pixel art) or `'linear'`
12
+ * (smooth — for hi-res / non-pixel-art assets). Applied when the scene is opened, so switching
13
+ * scenes restores the active scene's choice. NOTE: this is a GLOBAL renderer setting (one sampler
14
+ * for ALL textures, not per-texture), so the currently-open scene's filter wins. Omit to leave the
15
+ * current setting (engine default is nearest). */
16
+ filter?: 'nearest' | 'linear';
17
+ };
18
+ /** Returned by scene2d.layer(n); chain .ySort() to enable top-down depth sorting for that layer. */
19
+ declare class LayerHandle {
20
+ private readonly sceneId;
21
+ private readonly layer;
22
+ constructor(sceneId: number, layer: number);
23
+ /** In this layer, lower-on-screen sprites overlap higher ones (top-down feet sorting). */
24
+ ySort(enabled?: boolean): this;
25
+ }
26
+ export declare class Scene2D implements Presentable {
27
+ /** Native scene handle. */
28
+ readonly id: number;
29
+ readonly camera: Camera2D;
30
+ private static _active;
31
+ static get active(): Scene2D | null;
32
+ readonly _touchStartListeners: Array<(ev: TouchStartEvent<Node2D | null>) => void>;
33
+ /** Texture filter to (re)assert on open(); the sampler is global, so each scene reclaims it. */
34
+ private readonly _filter?;
35
+ constructor(options?: Scene2DOptions);
36
+ set background(color: ColorInput);
37
+ /** Address a draw layer to configure it, e.g. scene2d.layer(1).ySort(). */
38
+ layer(n: number): LayerHandle;
39
+ /** Topmost visible sprite whose world bounds contain the world point, or null. Body-free
40
+ * hit-test for tap/click picking — pair with camera.screenToWorld(). */
41
+ pick(worldPoint: Vec2Like): Node2D | null;
42
+ /** Scene-level pointer events. The handler fires for every tap/press in the scene, with
43
+ * `ev.target` = the hit Physics2D node (or null). On 'touchstart' you can ev.track(...) a drag. */
44
+ addEventListener(channel: "click", callback: (ev: ClickEvent<Node2D | null>) => void): void;
45
+ addEventListener(channel: "touchstart", callback: (ev: TouchStartEvent<Node2D | null>) => void): void;
46
+ removeEventListener(channel: "click" | "touchstart", callback: (ev: any) => void): void;
47
+ add(...nodes: Node2D[]): this;
48
+ remove(...nodes: Node2D[]): this;
49
+ /** Attach (and configure) a system, or reconfigure it if already present. Returns the scene typed
50
+ * as now-having it (`scene.system(Hud).hud`). A 3D `System<'x'>` (target Scene) is rejected here. */
51
+ system<Self extends TargetOf<A>, A extends Aspect<any, any, any>>(this: Self, ctor: AspectCtor<A>, opts?: Partial<A>): Self & FieldOf<A>;
52
+ /** Safe access — undefined if the system isn't attached. */
53
+ get<A extends Aspect<any, any, any>>(ctor: AspectCtor<A>): A | undefined;
54
+ /** Existence check AND type guard: inside `if (scene.has(Hud))`, `scene.hud` is present. */
55
+ has<A extends Aspect<any, any, any>>(ctor: AspectCtor<A>): this is this & FieldOf<A>;
56
+ /** Detach a system (runs its onDetach). Chainable. */
57
+ removeSystem<A extends Aspect<any, any, any>>(ctor: AspectCtor<A>): this;
58
+ readonly cl: (() => void)[];
59
+ _backButtonCallback?: () => void;
60
+ private _vd?;
61
+ /** Fires when the scene becomes the visible destination (incl. a pop revealing it). */
62
+ onOpen(callback: () => void): this;
63
+ /** Fires when the scene stops being visible (closed, replaced, or covered by a push). */
64
+ onClose(callback: () => void): this;
65
+ onBackPressed(callback: () => void): this;
66
+ /** Make this the active scene — shows it as the current destination (replaces a screen /
67
+ * another scene; only the active scene renders). */
68
+ open(options?: PresentOptions): this;
69
+ close(): this;
70
+ destroy(): void;
71
+ }
72
+ export {};
@@ -0,0 +1,58 @@
1
+ import { Aspect } from "../core/Aspect";
2
+ import { type Vec2Like } from "../math/vec";
3
+ import type { Node2D } from "./Node2D";
4
+ export declare class Shape2D extends Aspect<"shape", Node2D> {
5
+ static readonly aspect = "shape";
6
+ /** Box half-extents [hw, hh] (world units). */
7
+ box?: Vec2Like;
8
+ /** Circle radius. */
9
+ circle?: number;
10
+ /** Capsule between two local points, with a radius. */
11
+ capsule?: {
12
+ from: Vec2Like;
13
+ to: Vec2Like;
14
+ radius: number;
15
+ };
16
+ /** Thin segment (an edge) between two local points. */
17
+ segment?: {
18
+ from: Vec2Like;
19
+ to: Vec2Like;
20
+ };
21
+ /** Convex polygon, up to 8 local points (a convex hull is computed — a CONCAVE outline silently
22
+ * becomes its hull; use `chain` for those). */
23
+ polygon?: Vec2Like[];
24
+ /**
25
+ * A polyline of connected segments — the one shape that expresses a long CONCAVE surface (rolling
26
+ * terrain, a cave wall) in one piece, seam-free. Pass only the points that should be solid; the
27
+ * tangent points Box2D needs at the ends are synthesised here.
28
+ *
29
+ * STATIC bodies only (a polyline has no area, so no mass), at least 2 points (4 with `loop`), and it
30
+ * must not self-intersect. It is ONE-SIDED: solid on the right of the point order — walk the points
31
+ * so that the solid material is on your right, or set `flip`.
32
+ */
33
+ chain?: Vec2Like[];
34
+ /** `chain`: close the contour (an island / a room boundary). Needs at least 4 points. */
35
+ loop?: boolean;
36
+ /** `chain`: put the solid side on the other side of the line. */
37
+ flip?: boolean;
38
+ /** The collider's centre relative to the node, in world units. Applies to EVERY kind — it
39
+ * translates a capsule's / segment's / polygon's / chain's points too, unlike the old `offset`. */
40
+ origin?: Vec2Like;
41
+ private _handle;
42
+ onDetach(): void;
43
+ /**
44
+ * Re-configuring the aspect swaps the fixture in place — same body, same id, same velocity, same
45
+ * position. Nothing happens when the geometry is unchanged, so re-applying the same options in a
46
+ * loop is free.
47
+ */
48
+ onReconfigure(): void;
49
+ private _create;
50
+ /**
51
+ * Box2D's chain wants the two TANGENT points as extra entries and does not collide on its first or
52
+ * last edge — pass it your outline verbatim and you lose both end segments (four points give ONE).
53
+ * So the caller passes only the solid points and the ends are extrapolated here: `p0 + (p0 - p1)`.
54
+ * A loop needs none of that (every point is interior) but does need 4 of them.
55
+ */
56
+ private _createChain;
57
+ private _signature;
58
+ }