lecodes-cli 0.3.0 → 0.5.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 (48) hide show
  1. package/README.md +3 -0
  2. package/dist/index.js +883 -507
  3. package/package.json +9 -4
  4. package/runtime/sdk/canvas/Canvas.ts +86 -0
  5. package/runtime/sdk/compile/aspectMacro.ts +42 -0
  6. package/runtime/sdk/compile/assetMacro.ts +44 -0
  7. package/runtime/sdk/compile/bundler.ts +173 -0
  8. package/runtime/sdk/compile/compileProject.ts +84 -0
  9. package/runtime/sdk/compile/header.ts +46 -0
  10. package/runtime/sdk/compile/index.ts +12 -0
  11. package/runtime/sdk/compile/sourcemap.ts +25 -0
  12. package/runtime/sdk/core/Aspect.ts +2 -2
  13. package/runtime/sdk/core/signals.ts +277 -0
  14. package/runtime/sdk/g2/CharacterController2D.ts +5 -4
  15. package/runtime/sdk/g2/Node2D.ts +1 -1
  16. package/runtime/sdk/g2/Physics2D.ts +22 -12
  17. package/runtime/sdk/g2/Scene2D.ts +12 -0
  18. package/runtime/sdk/g2/{Shape.ts → Shape2D.ts} +10 -10
  19. package/runtime/sdk/g2/Sprite.ts +7 -2
  20. package/runtime/sdk/g2/Texture2D.ts +4 -2
  21. package/runtime/sdk/g2/{Trigger.ts → Trigger2D.ts} +9 -9
  22. package/runtime/sdk/gl/CharacterController.ts +101 -0
  23. package/runtime/sdk/gl/Node.ts +11 -2
  24. package/runtime/sdk/gl/Physics.ts +65 -41
  25. package/runtime/sdk/gl/Scene.ts +18 -0
  26. package/runtime/sdk/gl/Shape.ts +98 -0
  27. package/runtime/sdk/gl/Texture.ts +2 -2
  28. package/runtime/sdk/gl/Trigger.ts +46 -0
  29. package/runtime/sdk/gl/physicsEvents.ts +20 -0
  30. package/runtime/sdk/inject.ts +12 -5
  31. package/runtime/sdk/runtime/camera.ts +31 -0
  32. package/runtime/sdk/runtime/device.ts +26 -0
  33. package/runtime/sdk/runtime/share.ts +9 -0
  34. package/runtime/sdk/ui/UI.ts +5 -1
  35. package/runtime/sdk/ui/UIButton.ts +11 -5
  36. package/runtime/sdk/ui/UIContainer.ts +28 -13
  37. package/runtime/sdk/ui/UIImage.ts +5 -0
  38. package/runtime/sdk/ui/UIInput.ts +10 -0
  39. package/runtime/sdk/ui/UINode.ts +206 -8
  40. package/runtime/sdk/ui/UIScreen.ts +10 -5
  41. package/runtime/sdk/ui/UIScrollable.ts +10 -5
  42. package/runtime/sdk/ui/UISpacer.ts +4 -0
  43. package/runtime/sdk/ui/UIText.ts +21 -5
  44. package/runtime/sdk/ui/UIVideo.ts +5 -0
  45. package/runtime/sdk/ui/UIVirtualizedList.ts +5 -0
  46. package/runtime/sdk/ui/UIWidget.ts +10 -5
  47. package/runtime/sdk/canvas/Label.ts +0 -57
  48. package/runtime/sdk/gl/Collider.ts +0 -29
@@ -1,57 +0,0 @@
1
- // Convenience recipe (userland-style TS, not a native primitive): draw a text pill into a Canvas and
2
- // hand back a Sprite you can drop over an NPC / actor. The same Canvas texture also works as a 3D
3
- // billboard or a UIImage — Label just wraps the common 2D case.
4
- //
5
- // const tag = Label('Alice')
6
- // tag.position = npc.worldPosition // float it above the NPC (offset in y as needed)
7
- //
8
- // Fonts must be registered first: `await registerFont('Inter', url)` before Label(...).
9
-
10
- import { Canvas } from "./Canvas"
11
- import { Sprite } from "../g2/Sprite"
12
-
13
- export interface LabelOptions {
14
- /** CSS font shorthand. Default 'bold 24px sans-serif'. */
15
- font?: string
16
- /** Text color. Default '#fff'. */
17
- color?: string
18
- /** Pill background; null for no pill (bare text). Default '#000a'. */
19
- background?: string | null
20
- /** Horizontal / vertical padding around the text (logical px). Default 12 / 6. */
21
- padX?: number
22
- padY?: number
23
- /** Corner radius of the pill. Default 10. */
24
- radius?: number
25
- /** Device-pixel multiplier for crisp text. Default 2. */
26
- pixelRatio?: number
27
- /** Sprite draw layer. */
28
- layer?: number
29
- }
30
-
31
- export function Label(text: string, opts: LabelOptions = {}): Sprite {
32
- const font = opts.font ?? "bold 24px sans-serif"
33
- const color = opts.color ?? "#fff"
34
- const bg = opts.background === undefined ? "#000a" : opts.background
35
- const padX = opts.padX ?? 12
36
- const padY = opts.padY ?? 6
37
- const radius = opts.radius ?? 10
38
- const pixelRatio = opts.pixelRatio ?? 2
39
-
40
- // measure first (native metrics) to size the pill to the text
41
- const c = new Canvas(1, 1, { pixelRatio })
42
- c.font = font
43
- const m = c.measureText(text)
44
- const lineH = m.ascent + m.descent
45
- const w = Math.ceil(m.width + padX * 2)
46
- const h = Math.ceil(lineH + padY * 2)
47
- c.reset().resize(w, h)
48
- c.font = font // reset() cleared the buffer — re-record the font for the actual draw
49
-
50
- if (bg !== null) { c.fillStyle = bg; c.roundRect(0, 0, w, h, radius).fill() }
51
- c.fillStyle = color
52
- c.textAlign = "center"
53
- c.textBaseline = "middle"
54
- c.fillText(text, w / 2, h / 2)
55
-
56
- return new Sprite({ texture: c, anchor: [0.5, 1], layer: opts.layer })
57
- }
@@ -1,29 +0,0 @@
1
- // A 3D collider for click/touch hit-testing, as an aspect. Derives a box from the mesh by default.
2
- // (3D is the default engine, so this is the unsuffixed Collider; the 2D one is Collider2D.)
3
- // node.aspect(Collider, { shape: 'box' })
4
- // node.aspect(Collider, { shape: 'box', center: [0,1,0], size: [2,2,2] })
5
-
6
- import { Aspect } from "../core/Aspect"
7
- import { cx, cy, cz, type Vec3Like } from "../math/vec"
8
- import type { Node } from "./Node"
9
-
10
- export class Collider extends Aspect<"collider", Node> {
11
- static readonly aspect = "collider"
12
- shape: "box" | "sphere" = "box"
13
- /** Explicit box: center + full size. */
14
- center?: Vec3Like
15
- size?: Vec3Like
16
- /** Explicit sphere: center + radius. */
17
- radius?: number
18
-
19
- onAttach(): void {
20
- const id = this.node.id
21
- if (this.shape === "box" && this.center && this.size) {
22
- _creator.setColliderBox(id, cx(this.center), cy(this.center), cz(this.center), cx(this.size), cy(this.size), cz(this.size))
23
- } else if (this.shape === "sphere" && this.center && this.radius !== undefined) {
24
- _creator.setColliderSphere(id, cx(this.center), cy(this.center), cz(this.center), this.radius)
25
- } else {
26
- _creator.setColliderFromMesh(id, id, this.shape === "sphere" ? 1 : 0)
27
- }
28
- }
29
- }