@zylem/behaviors 0.2.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 (175) hide show
  1. package/README.md +26 -0
  2. package/dist/behavior-system-DYbx-x_-.d.ts +307 -0
  3. package/dist/chunk-2C3Z5GE7.js +176 -0
  4. package/dist/chunk-2C3Z5GE7.js.map +1 -0
  5. package/dist/chunk-2CLT36VB.js +241 -0
  6. package/dist/chunk-2CLT36VB.js.map +1 -0
  7. package/dist/chunk-3PYGRHAL.js +35 -0
  8. package/dist/chunk-3PYGRHAL.js.map +1 -0
  9. package/dist/chunk-4I6E6DGV.js +212 -0
  10. package/dist/chunk-4I6E6DGV.js.map +1 -0
  11. package/dist/chunk-4URF65BR.js +44 -0
  12. package/dist/chunk-4URF65BR.js.map +1 -0
  13. package/dist/chunk-6C6NXNEW.js +38 -0
  14. package/dist/chunk-6C6NXNEW.js.map +1 -0
  15. package/dist/chunk-ARJWUNRE.js +431 -0
  16. package/dist/chunk-ARJWUNRE.js.map +1 -0
  17. package/dist/chunk-BXP4K7RF.js +1205 -0
  18. package/dist/chunk-BXP4K7RF.js.map +1 -0
  19. package/dist/chunk-DYLH6K7B.js +44 -0
  20. package/dist/chunk-DYLH6K7B.js.map +1 -0
  21. package/dist/chunk-EIWQM6U3.js +27 -0
  22. package/dist/chunk-EIWQM6U3.js.map +1 -0
  23. package/dist/chunk-EZNCCO4L.js +14 -0
  24. package/dist/chunk-EZNCCO4L.js.map +1 -0
  25. package/dist/chunk-F3KRX2V4.js +457 -0
  26. package/dist/chunk-F3KRX2V4.js.map +1 -0
  27. package/dist/chunk-FPTWVCPN.js +53 -0
  28. package/dist/chunk-FPTWVCPN.js.map +1 -0
  29. package/dist/chunk-GCNRXAKH.js +37 -0
  30. package/dist/chunk-GCNRXAKH.js.map +1 -0
  31. package/dist/chunk-GYURWCIQ.js +1985 -0
  32. package/dist/chunk-GYURWCIQ.js.map +1 -0
  33. package/dist/chunk-HZMY3TT4.js +244 -0
  34. package/dist/chunk-HZMY3TT4.js.map +1 -0
  35. package/dist/chunk-ID5QJYF5.js +50 -0
  36. package/dist/chunk-ID5QJYF5.js.map +1 -0
  37. package/dist/chunk-JAN34G6S.js +552 -0
  38. package/dist/chunk-JAN34G6S.js.map +1 -0
  39. package/dist/chunk-K3UNLQ7W.js +118 -0
  40. package/dist/chunk-K3UNLQ7W.js.map +1 -0
  41. package/dist/chunk-KDY5N6J4.js +82 -0
  42. package/dist/chunk-KDY5N6J4.js.map +1 -0
  43. package/dist/chunk-KOZUNIIE.js +413 -0
  44. package/dist/chunk-KOZUNIIE.js.map +1 -0
  45. package/dist/chunk-KS72RZHX.js +30 -0
  46. package/dist/chunk-KS72RZHX.js.map +1 -0
  47. package/dist/chunk-LD5SMIB3.js +32 -0
  48. package/dist/chunk-LD5SMIB3.js.map +1 -0
  49. package/dist/chunk-OHCPV2NT.js +86 -0
  50. package/dist/chunk-OHCPV2NT.js.map +1 -0
  51. package/dist/chunk-OYWFPIHF.js +115 -0
  52. package/dist/chunk-OYWFPIHF.js.map +1 -0
  53. package/dist/chunk-POZER3MQ.js +407 -0
  54. package/dist/chunk-POZER3MQ.js.map +1 -0
  55. package/dist/chunk-RTRVBEIB.js +56 -0
  56. package/dist/chunk-RTRVBEIB.js.map +1 -0
  57. package/dist/chunk-RTVRUNYR.js +29 -0
  58. package/dist/chunk-RTVRUNYR.js.map +1 -0
  59. package/dist/chunk-SS7ELMJ7.js +406 -0
  60. package/dist/chunk-SS7ELMJ7.js.map +1 -0
  61. package/dist/chunk-STCCNLPC.js +160 -0
  62. package/dist/chunk-STCCNLPC.js.map +1 -0
  63. package/dist/chunk-SVLNF434.js +261 -0
  64. package/dist/chunk-SVLNF434.js.map +1 -0
  65. package/dist/chunk-UYFOLI2X.js +24 -0
  66. package/dist/chunk-UYFOLI2X.js.map +1 -0
  67. package/dist/chunk-VAN4WW3F.js +67 -0
  68. package/dist/chunk-VAN4WW3F.js.map +1 -0
  69. package/dist/chunk-WOMHL23C.js +369 -0
  70. package/dist/chunk-WOMHL23C.js.map +1 -0
  71. package/dist/chunk-WWVD5DR5.js +120 -0
  72. package/dist/chunk-WWVD5DR5.js.map +1 -0
  73. package/dist/chunk-XG2YMCJW.js +201 -0
  74. package/dist/chunk-XG2YMCJW.js.map +1 -0
  75. package/dist/chunk-XIJNE67Y.js +210 -0
  76. package/dist/chunk-XIJNE67Y.js.map +1 -0
  77. package/dist/chunk-Y6UJOUE5.js +44 -0
  78. package/dist/chunk-Y6UJOUE5.js.map +1 -0
  79. package/dist/chunk-YUO6SKJD.js +348 -0
  80. package/dist/chunk-YUO6SKJD.js.map +1 -0
  81. package/dist/components--hjBMTnz.d.ts +120 -0
  82. package/dist/components-B29WHGQN.d.ts +39 -0
  83. package/dist/components-BWG1GkZA.d.ts +20 -0
  84. package/dist/components-XCpL6IYt.d.ts +18 -0
  85. package/dist/components-qWwOsvwh.d.ts +43 -0
  86. package/dist/cooldown.d.ts +116 -0
  87. package/dist/cooldown.js +20 -0
  88. package/dist/cooldown.js.map +1 -0
  89. package/dist/coordinators/boundary-ricochet-3d.d.ts +19 -0
  90. package/dist/coordinators/boundary-ricochet-3d.js +8 -0
  91. package/dist/coordinators/boundary-ricochet-3d.js.map +1 -0
  92. package/dist/coordinators/boundary-ricochet.d.ts +34 -0
  93. package/dist/coordinators/boundary-ricochet.js +8 -0
  94. package/dist/coordinators/boundary-ricochet.js.map +1 -0
  95. package/dist/coordinators/first-person-shooter.d.ts +35 -0
  96. package/dist/coordinators/first-person-shooter.js +9 -0
  97. package/dist/coordinators/first-person-shooter.js.map +1 -0
  98. package/dist/coordinators/multidirectional-space-shooter.d.ts +27 -0
  99. package/dist/coordinators/multidirectional-space-shooter.js +10 -0
  100. package/dist/coordinators/multidirectional-space-shooter.js.map +1 -0
  101. package/dist/coordinators/top-down-shooter.d.ts +27 -0
  102. package/dist/coordinators/top-down-shooter.js +10 -0
  103. package/dist/coordinators/top-down-shooter.js.map +1 -0
  104. package/dist/core.d.ts +25 -0
  105. package/dist/core.js +327 -0
  106. package/dist/core.js.map +1 -0
  107. package/dist/destructible-3d.d.ts +42 -0
  108. package/dist/destructible-3d.js +13 -0
  109. package/dist/destructible-3d.js.map +1 -0
  110. package/dist/destructible-prebake.d.ts +28 -0
  111. package/dist/destructible-prebake.js +23 -0
  112. package/dist/destructible-prebake.js.map +1 -0
  113. package/dist/entity-types-CmtQ-IBp.d.ts +15 -0
  114. package/dist/first-person-perspective-C9Mptl0-.d.ts +23 -0
  115. package/dist/first-person.d.ts +204 -0
  116. package/dist/first-person.js +27 -0
  117. package/dist/first-person.js.map +1 -0
  118. package/dist/index.d.ts +40 -0
  119. package/dist/index.js +263 -0
  120. package/dist/index.js.map +1 -0
  121. package/dist/jumper-2d.d.ts +113 -0
  122. package/dist/jumper-2d.js +27 -0
  123. package/dist/jumper-2d.js.map +1 -0
  124. package/dist/jumper-3d.d.ts +164 -0
  125. package/dist/jumper-3d.js +29 -0
  126. package/dist/jumper-3d.js.map +1 -0
  127. package/dist/moveable-BCRpjAQb.d.ts +176 -0
  128. package/dist/particle-emitter/presets.d.ts +46 -0
  129. package/dist/particle-emitter/presets.js +15 -0
  130. package/dist/particle-emitter/presets.js.map +1 -0
  131. package/dist/particle-emitter.d.ts +78 -0
  132. package/dist/particle-emitter.js +15 -0
  133. package/dist/particle-emitter.js.map +1 -0
  134. package/dist/payload-BQzu-oY_.d.ts +89 -0
  135. package/dist/platformer-3d.d.ts +347 -0
  136. package/dist/platformer-3d.js +23 -0
  137. package/dist/platformer-3d.js.map +1 -0
  138. package/dist/ricochet-2d.d.ts +274 -0
  139. package/dist/ricochet-2d.js +16 -0
  140. package/dist/ricochet-2d.js.map +1 -0
  141. package/dist/ricochet-3d.d.ts +116 -0
  142. package/dist/ricochet-3d.js +16 -0
  143. package/dist/ricochet-3d.js.map +1 -0
  144. package/dist/runtime-2d.d.ts +2 -0
  145. package/dist/runtime-2d.js +32 -0
  146. package/dist/runtime-2d.js.map +1 -0
  147. package/dist/runtime-pong.d.ts +92 -0
  148. package/dist/runtime-pong.js +38 -0
  149. package/dist/runtime-pong.js.map +1 -0
  150. package/dist/screen-visibility.d.ts +74 -0
  151. package/dist/screen-visibility.js +10 -0
  152. package/dist/screen-visibility.js.map +1 -0
  153. package/dist/screen-wrap.d.ts +86 -0
  154. package/dist/screen-wrap.js +16 -0
  155. package/dist/screen-wrap.js.map +1 -0
  156. package/dist/shooter-2d.d.ts +77 -0
  157. package/dist/shooter-2d.js +12 -0
  158. package/dist/shooter-2d.js.map +1 -0
  159. package/dist/spark-DDlIg1nM.d.ts +148 -0
  160. package/dist/sync-state-machine-CZyspBpj.d.ts +16 -0
  161. package/dist/thruster.d.ts +132 -0
  162. package/dist/thruster.js +26 -0
  163. package/dist/thruster.js.map +1 -0
  164. package/dist/top-down-movement.d.ts +40 -0
  165. package/dist/top-down-movement.js +20 -0
  166. package/dist/top-down-movement.js.map +1 -0
  167. package/dist/use-behavior-D_82jAL3.d.ts +13 -0
  168. package/dist/vector-Bm65-FOG.d.ts +45 -0
  169. package/dist/world-boundary-2d.d.ts +141 -0
  170. package/dist/world-boundary-2d.js +21 -0
  171. package/dist/world-boundary-2d.js.map +1 -0
  172. package/dist/world-boundary-3d.d.ts +75 -0
  173. package/dist/world-boundary-3d.js +21 -0
  174. package/dist/world-boundary-3d.js.map +1 -0
  175. package/package.json +161 -0
@@ -0,0 +1,201 @@
1
+ import {
2
+ computeBounds2DHits,
3
+ constrainMovementToBounds2D,
4
+ hasAnyBounds2DHit
5
+ } from "./chunk-KDY5N6J4.js";
6
+ import {
7
+ StageBoundaryDim
8
+ } from "./chunk-Y6UJOUE5.js";
9
+ import {
10
+ SyncStateMachine,
11
+ t
12
+ } from "./chunk-4URF65BR.js";
13
+ import {
14
+ defineBehavior
15
+ } from "./chunk-EZNCCO4L.js";
16
+
17
+ // src/lib/behaviors/world-boundary-2d/world-boundary-2d-fsm.ts
18
+ var WorldBoundary2DState = /* @__PURE__ */ ((WorldBoundary2DState2) => {
19
+ WorldBoundary2DState2["Inside"] = "inside";
20
+ WorldBoundary2DState2["Touching"] = "touching";
21
+ return WorldBoundary2DState2;
22
+ })(WorldBoundary2DState || {});
23
+ var WorldBoundary2DEvent = /* @__PURE__ */ ((WorldBoundary2DEvent2) => {
24
+ WorldBoundary2DEvent2["EnterInside"] = "enter-inside";
25
+ WorldBoundary2DEvent2["TouchBoundary"] = "touch-boundary";
26
+ return WorldBoundary2DEvent2;
27
+ })(WorldBoundary2DEvent || {});
28
+ function computeWorldBoundary2DHits(position, bounds) {
29
+ return computeBounds2DHits(position, {
30
+ minX: bounds.left,
31
+ maxX: bounds.right,
32
+ minY: bounds.bottom,
33
+ maxY: bounds.top
34
+ });
35
+ }
36
+ function hasAnyWorldBoundary2DHit(hits) {
37
+ return hasAnyBounds2DHit(hits);
38
+ }
39
+ var WorldBoundary2DFSM = class {
40
+ machine;
41
+ lastHits = { top: false, bottom: false, left: false, right: false };
42
+ lastPosition = null;
43
+ lastUpdatedAtMs = null;
44
+ constructor() {
45
+ this.machine = new SyncStateMachine(
46
+ "inside" /* Inside */,
47
+ [
48
+ t("inside" /* Inside */, "touch-boundary" /* TouchBoundary */, "touching" /* Touching */),
49
+ t("touching" /* Touching */, "enter-inside" /* EnterInside */, "inside" /* Inside */),
50
+ // Self transitions (no-ops)
51
+ t("inside" /* Inside */, "enter-inside" /* EnterInside */, "inside" /* Inside */),
52
+ t("touching" /* Touching */, "touch-boundary" /* TouchBoundary */, "touching" /* Touching */)
53
+ ]
54
+ );
55
+ }
56
+ getState() {
57
+ return this.machine.getState();
58
+ }
59
+ /**
60
+ * Returns the last computed hits (always available after first update call).
61
+ */
62
+ getLastHits() {
63
+ return this.lastHits;
64
+ }
65
+ /**
66
+ * Returns adjusted movement values based on boundary hits.
67
+ * If the entity is touching a boundary and trying to move further into it,
68
+ * that axis component is zeroed out.
69
+ *
70
+ * @param moveX - The desired X movement
71
+ * @param moveY - The desired Y movement
72
+ * @returns Adjusted { moveX, moveY } with boundary-blocked axes zeroed
73
+ */
74
+ getMovement(moveX, moveY) {
75
+ return constrainMovementToBounds2D(this.lastHits, moveX, moveY);
76
+ }
77
+ /**
78
+ * Returns the last position passed to `update`, if any.
79
+ */
80
+ getLastPosition() {
81
+ return this.lastPosition;
82
+ }
83
+ /**
84
+ * Best-effort timestamp (ms) of the last `update(...)` call.
85
+ * This is optional metadata; systems can ignore it.
86
+ */
87
+ getLastUpdatedAtMs() {
88
+ return this.lastUpdatedAtMs;
89
+ }
90
+ /**
91
+ * Update FSM + extended state based on current position and bounds.
92
+ * Returns the computed hits for convenience.
93
+ */
94
+ update(position, bounds) {
95
+ const hits = computeWorldBoundary2DHits(position, bounds);
96
+ this.lastHits = hits;
97
+ this.lastPosition = { x: position.x, y: position.y };
98
+ this.lastUpdatedAtMs = Date.now();
99
+ if (hasAnyWorldBoundary2DHit(hits)) {
100
+ this.dispatch("touch-boundary" /* TouchBoundary */);
101
+ } else {
102
+ this.dispatch("enter-inside" /* EnterInside */);
103
+ }
104
+ return hits;
105
+ }
106
+ dispatch(event) {
107
+ if (this.machine.can(event)) {
108
+ this.machine.syncDispatch(event);
109
+ }
110
+ }
111
+ };
112
+
113
+ // src/lib/behaviors/world-boundary-2d/world-boundary-2d.descriptor.ts
114
+ var defaultOptions = {
115
+ boundaries: { top: 0, bottom: 0, left: 0, right: 0 }
116
+ };
117
+ var WORLD_BOUNDARY_BEHAVIOR_KEY = /* @__PURE__ */ Symbol.for(
118
+ "zylem:behavior:world-boundary-2d"
119
+ );
120
+ function createWorldBoundary2DHandle(ref) {
121
+ return {
122
+ getLastHits: () => {
123
+ const fsm = ref.fsm;
124
+ return fsm?.getLastHits() ?? null;
125
+ },
126
+ getMovement: (moveX, moveY) => {
127
+ const fsm = ref.fsm;
128
+ return fsm?.getMovement(moveX, moveY) ?? { moveX, moveY };
129
+ }
130
+ };
131
+ }
132
+ var WorldBoundary2DSystem = class {
133
+ constructor(world, wasmStage, getBehaviorLinks) {
134
+ this.world = world;
135
+ this.wasmStage = wasmStage;
136
+ this.getBehaviorLinks = getBehaviorLinks;
137
+ }
138
+ world;
139
+ wasmStage;
140
+ getBehaviorLinks;
141
+ attachedRuntimeSlots = /* @__PURE__ */ new Set();
142
+ update(_ecs, _delta) {
143
+ const links = this.getBehaviorLinks?.(WORLD_BOUNDARY_BEHAVIOR_KEY);
144
+ if (!links) return;
145
+ for (const link of links) {
146
+ const gameEntity = link.entity;
147
+ const boundaryRef = link.ref;
148
+ const options = boundaryRef.options;
149
+ if (!boundaryRef.fsm) {
150
+ boundaryRef.fsm = new WorldBoundary2DFSM();
151
+ }
152
+ const handle = gameEntity.runtimeHandle ?? -1;
153
+ if (this.wasmStage && handle >= 0) {
154
+ this.ensureWasmAttached(handle, options.boundaries);
155
+ const query = this.wasmStage.queryWorldBoundary(handle);
156
+ if (query) {
157
+ boundaryRef.fsm.update(
158
+ { x: query.clamped[0], y: query.clamped[1] },
159
+ options.boundaries
160
+ );
161
+ continue;
162
+ }
163
+ }
164
+ if (!gameEntity.body) continue;
165
+ const body = gameEntity.body;
166
+ const pos = body.translation();
167
+ boundaryRef.fsm.update({ x: pos.x, y: pos.y }, options.boundaries);
168
+ }
169
+ }
170
+ ensureWasmAttached(handle, bounds) {
171
+ if (!this.wasmStage || this.attachedRuntimeSlots.has(handle)) return;
172
+ this.wasmStage.attachWorldBoundary(handle, StageBoundaryDim.Two, {
173
+ top: bounds.top,
174
+ bottom: bounds.bottom,
175
+ left: bounds.left,
176
+ right: bounds.right,
177
+ front: 0,
178
+ back: 0
179
+ });
180
+ this.attachedRuntimeSlots.add(handle);
181
+ }
182
+ destroy(_ecs) {
183
+ this.attachedRuntimeSlots.clear();
184
+ }
185
+ };
186
+ var WorldBoundary2DBehavior = defineBehavior({
187
+ name: "world-boundary-2d",
188
+ defaultOptions,
189
+ systemFactory: (ctx) => new WorldBoundary2DSystem(ctx.world, ctx.wasmStage ?? null, ctx.getBehaviorLinks),
190
+ createHandle: createWorldBoundary2DHandle
191
+ });
192
+
193
+ export {
194
+ WorldBoundary2DState,
195
+ WorldBoundary2DEvent,
196
+ computeWorldBoundary2DHits,
197
+ hasAnyWorldBoundary2DHit,
198
+ WorldBoundary2DFSM,
199
+ WorldBoundary2DBehavior
200
+ };
201
+ //# sourceMappingURL=chunk-XG2YMCJW.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/behaviors/world-boundary-2d/world-boundary-2d-fsm.ts","../src/lib/behaviors/world-boundary-2d/world-boundary-2d.descriptor.ts"],"sourcesContent":["/**\n * WorldBoundary2DFSM\n *\n * Minimal FSM + extended state to track which world boundaries were hit.\n *\n * Notes:\n * - \"Hit boundaries\" is inherently a *set* (can hit left+bottom in one frame),\n * so we store it as extended state (`lastHits`) rather than a single FSM state.\n * - The FSM state is still useful for coarse status like \"inside\" vs \"touching\".\n */\n\nimport { SyncStateMachine, t } from '../../core/utility/sync-state-machine';\nimport {\n\tcomputeBounds2DHits,\n\tconstrainMovementToBounds2D,\n\thasAnyBounds2DHit,\n} from '../shared/bounds-2d';\n\nexport type WorldBoundary2DHit = 'top' | 'bottom' | 'left' | 'right';\nexport type WorldBoundary2DHits = Record<WorldBoundary2DHit, boolean>;\n\nexport interface WorldBoundary2DPosition {\n\tx: number;\n\ty: number;\n}\n\nexport interface WorldBoundary2DBounds {\n\ttop: number;\n\tbottom: number;\n\tleft: number;\n\tright: number;\n}\n\nexport enum WorldBoundary2DState {\n\tInside = 'inside',\n\tTouching = 'touching',\n}\n\nexport enum WorldBoundary2DEvent {\n\tEnterInside = 'enter-inside',\n\tTouchBoundary = 'touch-boundary',\n}\n\n/**\n * Compute which boundaries are being hit for a position and bounds.\n * This matches the semantics of the legacy `boundary2d` behavior:\n * - left hit if x <= left\n * - right hit if x >= right\n * - bottom hit if y <= bottom\n * - top hit if y >= top\n */\nexport function computeWorldBoundary2DHits(\n\tposition: WorldBoundary2DPosition,\n\tbounds: WorldBoundary2DBounds\n): WorldBoundary2DHits {\n\treturn computeBounds2DHits(position, {\n\t\tminX: bounds.left,\n\t\tmaxX: bounds.right,\n\t\tminY: bounds.bottom,\n\t\tmaxY: bounds.top,\n\t});\n}\n\nexport function hasAnyWorldBoundary2DHit(hits: WorldBoundary2DHits): boolean {\n\treturn hasAnyBounds2DHit(hits);\n}\n\n/**\n * FSM wrapper with \"extended state\" (lastHits / lastPosition).\n * Systems should call `update(...)` once per frame.\n */\nexport class WorldBoundary2DFSM {\n\tpublic readonly machine: SyncStateMachine<WorldBoundary2DState, WorldBoundary2DEvent, never>;\n\n\tprivate lastHits: WorldBoundary2DHits = { top: false, bottom: false, left: false, right: false };\n\tprivate lastPosition: WorldBoundary2DPosition | null = null;\n\tprivate lastUpdatedAtMs: number | null = null;\n\n\tconstructor() {\n\t\tthis.machine = new SyncStateMachine<WorldBoundary2DState, WorldBoundary2DEvent, never>(\n\t\t\tWorldBoundary2DState.Inside,\n\t\t\t[\n\t\t\t\tt(WorldBoundary2DState.Inside, WorldBoundary2DEvent.TouchBoundary, WorldBoundary2DState.Touching),\n\t\t\t\tt(WorldBoundary2DState.Touching, WorldBoundary2DEvent.EnterInside, WorldBoundary2DState.Inside),\n\n\t\t\t\t// Self transitions (no-ops)\n\t\t\t\tt(WorldBoundary2DState.Inside, WorldBoundary2DEvent.EnterInside, WorldBoundary2DState.Inside),\n\t\t\t\tt(WorldBoundary2DState.Touching, WorldBoundary2DEvent.TouchBoundary, WorldBoundary2DState.Touching),\n\t\t\t]\n\t\t);\n\t}\n\n\tgetState(): WorldBoundary2DState {\n\t\treturn this.machine.getState();\n\t}\n\n\t/**\n\t * Returns the last computed hits (always available after first update call).\n\t */\n\tgetLastHits(): WorldBoundary2DHits {\n\t\treturn this.lastHits;\n\t}\n\n\t/**\n\t * Returns adjusted movement values based on boundary hits.\n\t * If the entity is touching a boundary and trying to move further into it,\n\t * that axis component is zeroed out.\n\t *\n\t * @param moveX - The desired X movement\n\t * @param moveY - The desired Y movement\n\t * @returns Adjusted { moveX, moveY } with boundary-blocked axes zeroed\n\t */\n\tgetMovement(moveX: number, moveY: number): { moveX: number; moveY: number } {\n\t\treturn constrainMovementToBounds2D(this.lastHits, moveX, moveY);\n\t}\n\n\t/**\n\t * Returns the last position passed to `update`, if any.\n\t */\n\tgetLastPosition(): WorldBoundary2DPosition | null {\n\t\treturn this.lastPosition;\n\t}\n\n\t/**\n\t * Best-effort timestamp (ms) of the last `update(...)` call.\n\t * This is optional metadata; systems can ignore it.\n\t */\n\tgetLastUpdatedAtMs(): number | null {\n\t\treturn this.lastUpdatedAtMs;\n\t}\n\n\t/**\n\t * Update FSM + extended state based on current position and bounds.\n\t * Returns the computed hits for convenience.\n\t */\n\tupdate(position: WorldBoundary2DPosition, bounds: WorldBoundary2DBounds): WorldBoundary2DHits {\n\t\tconst hits = computeWorldBoundary2DHits(position, bounds);\n\n\t\tthis.lastHits = hits;\n\t\tthis.lastPosition = { x: position.x, y: position.y };\n\t\tthis.lastUpdatedAtMs = Date.now();\n\n\t\tif (hasAnyWorldBoundary2DHit(hits)) {\n\t\t\tthis.dispatch(WorldBoundary2DEvent.TouchBoundary);\n\t\t} else {\n\t\t\tthis.dispatch(WorldBoundary2DEvent.EnterInside);\n\t\t}\n\n\t\treturn hits;\n\t}\n\n\tprivate dispatch(event: WorldBoundary2DEvent): void {\n\t\tif (this.machine.can(event)) {\n\t\t\tthis.machine.syncDispatch(event);\n\t\t}\n\t}\n}\n","/**\n * WorldBoundary2DBehavior\n *\n * Tracks which 2D world boundaries an entity is touching.\n * Use `getMovement()` on the behavior handle to adjust movement based on hits.\n *\n * Source of truth: `entity.body` (Rapier rigid body), consistent with other new behaviors.\n */\n\nimport { defineBehavior, type BehaviorRef } from '../behavior-descriptor';\nimport type { BehaviorEntityLink, BehaviorSystem } from '../behavior-system';\nimport {\n\tWorldBoundary2DFSM,\n\ttype WorldBoundary2DBounds,\n\ttype WorldBoundary2DHits,\n} from './world-boundary-2d-fsm';\nimport {\n\tStageBoundaryDim,\n\ttype WasmStageRuntime,\n} from '../../runtime/wasm-stage-runtime';\n\nexport interface WorldBoundary2DOptions {\n\t/**\n\t * World boundaries (in world units).\n\t * - left hit if x <= left\n\t * - right hit if x >= right\n\t * - bottom hit if y <= bottom\n\t * - top hit if y >= top\n\t */\n\tboundaries: WorldBoundary2DBounds;\n}\n\n/**\n * Handle methods provided by WorldBoundary2DBehavior\n */\nexport interface WorldBoundary2DHandle {\n\t/**\n\t * Get the last computed boundary hits.\n\t * Returns null until entity is spawned and FSM is initialized.\n\t */\n\tgetLastHits(): WorldBoundary2DHits | null;\n\n\t/**\n\t * Get adjusted movement values based on boundary hits.\n\t * Zeros out movement into boundaries the entity is touching.\n\t */\n\tgetMovement(moveX: number, moveY: number): { moveX: number; moveY: number };\n}\n\nconst defaultOptions: WorldBoundary2DOptions = {\n\tboundaries: { top: 0, bottom: 0, left: 0, right: 0 },\n};\n\nconst WORLD_BOUNDARY_BEHAVIOR_KEY = Symbol.for(\n\t'zylem:behavior:world-boundary-2d',\n);\n\n/**\n * Creates behavior-specific handle methods for WorldBoundary2DBehavior.\n */\nfunction createWorldBoundary2DHandle(\n\tref: BehaviorRef<WorldBoundary2DOptions>\n): WorldBoundary2DHandle {\n\treturn {\n\t\tgetLastHits: () => {\n\t\t\tconst fsm = ref.fsm as WorldBoundary2DFSM | undefined;\n\t\t\treturn fsm?.getLastHits() ?? null;\n\t\t},\n\t\tgetMovement: (moveX: number, moveY: number) => {\n\t\t\tconst fsm = ref.fsm as WorldBoundary2DFSM | undefined;\n\t\t\treturn fsm?.getMovement(moveX, moveY) ?? { moveX, moveY };\n\t\t},\n\t};\n}\n\n/**\n * WorldBoundary2DSystem\n *\n * Stage-level system that:\n * - finds entities with this behavior attached\n * - computes and tracks boundary hits using the FSM\n *\n * When a {@link WasmStageRuntime} is present in `BehaviorSystemContext` and the\n * entity has been registered with the unified Stage (`runtimeHandle >= 0`), the\n * system uses the Rust `world_boundary` behavior as the source of truth and\n * mirrors its query into the local FSM so handle methods (`getLastHits`,\n * `getMovement`) return the same shape as the legacy code path.\n */\nclass WorldBoundary2DSystem implements BehaviorSystem {\n\tprivate attachedRuntimeSlots = new Set<number>();\n\n\tconstructor(\n\t\tprivate world: any,\n\t\tprivate wasmStage: WasmStageRuntime | null,\n\t\tprivate getBehaviorLinks?: (key: symbol) => Iterable<BehaviorEntityLink>,\n\t) {}\n\n\tupdate(_ecs: unknown, _delta: number): void {\n\t\tconst links = this.getBehaviorLinks?.(WORLD_BOUNDARY_BEHAVIOR_KEY);\n\t\tif (!links) return;\n\n\t\tfor (const link of links) {\n\t\t\tconst gameEntity = link.entity as any;\n\t\t\tconst boundaryRef = link.ref as any;\n\t\t\tconst options = boundaryRef.options as WorldBoundary2DOptions;\n\n\t\t\tif (!boundaryRef.fsm) {\n\t\t\t\tboundaryRef.fsm = new WorldBoundary2DFSM();\n\t\t\t}\n\n\t\t\tconst handle = (gameEntity.runtimeHandle ?? -1) as number;\n\t\t\tif (this.wasmStage && handle >= 0) {\n\t\t\t\tthis.ensureWasmAttached(handle, options.boundaries);\n\t\t\t\tconst query = this.wasmStage.queryWorldBoundary(handle);\n\t\t\t\tif (query) {\n\t\t\t\t\tboundaryRef.fsm.update(\n\t\t\t\t\t\t{ x: query.clamped[0], y: query.clamped[1] },\n\t\t\t\t\t\toptions.boundaries,\n\t\t\t\t\t);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!gameEntity.body) continue;\n\t\t\tconst body = gameEntity.body;\n\t\t\tconst pos = body.translation();\n\t\t\tboundaryRef.fsm.update({ x: pos.x, y: pos.y }, options.boundaries);\n\t\t}\n\t}\n\n\tprivate ensureWasmAttached(handle: number, bounds: WorldBoundary2DBounds): void {\n\t\tif (!this.wasmStage || this.attachedRuntimeSlots.has(handle)) return;\n\t\tthis.wasmStage.attachWorldBoundary(handle, StageBoundaryDim.Two, {\n\t\t\ttop: bounds.top,\n\t\t\tbottom: bounds.bottom,\n\t\t\tleft: bounds.left,\n\t\t\tright: bounds.right,\n\t\t\tfront: 0,\n\t\t\tback: 0,\n\t\t});\n\t\tthis.attachedRuntimeSlots.add(handle);\n\t}\n\n\tdestroy(_ecs: unknown): void {\n\t\tthis.attachedRuntimeSlots.clear();\n\t}\n}\n\n/**\n * WorldBoundary2DBehavior\n *\n * @example\n * ```ts\n * import { WorldBoundary2DBehavior } from \"@zylem/game-lib/behavior\";\n *\n * const ship = createSprite({ ... });\n * const boundary = ship.use(WorldBoundary2DBehavior, {\n * boundaries: { left: -10, right: 10, bottom: -7.5, top: 7.5 },\n * });\n *\n * ship.onUpdate(({ me }) => {\n * let moveX = ..., moveY = ...;\n * const hits = boundary.getLastHits(); // Fully typed!\n * ({ moveX, moveY } = boundary.getMovement(moveX, moveY));\n * me.moveXY(moveX, moveY);\n * });\n * ```\n */\nexport const WorldBoundary2DBehavior = defineBehavior({\n\tname: 'world-boundary-2d',\n\tdefaultOptions,\n\tsystemFactory: (ctx) =>\n\t\tnew WorldBoundary2DSystem(ctx.world, ctx.wasmStage ?? null, ctx.getBehaviorLinks),\n\tcreateHandle: createWorldBoundary2DHandle,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;AAiCO,IAAK,uBAAL,kBAAKA,0BAAL;AACN,EAAAA,sBAAA,YAAS;AACT,EAAAA,sBAAA,cAAW;AAFA,SAAAA;AAAA,GAAA;AAKL,IAAK,uBAAL,kBAAKC,0BAAL;AACN,EAAAA,sBAAA,iBAAc;AACd,EAAAA,sBAAA,mBAAgB;AAFL,SAAAA;AAAA,GAAA;AAaL,SAAS,2BACf,UACA,QACsB;AACtB,SAAO,oBAAoB,UAAU;AAAA,IACpC,MAAM,OAAO;AAAA,IACb,MAAM,OAAO;AAAA,IACb,MAAM,OAAO;AAAA,IACb,MAAM,OAAO;AAAA,EACd,CAAC;AACF;AAEO,SAAS,yBAAyB,MAAoC;AAC5E,SAAO,kBAAkB,IAAI;AAC9B;AAMO,IAAM,qBAAN,MAAyB;AAAA,EACf;AAAA,EA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AEA,UAAI,CAAC,WAAW,KAAM;AACtB,YAAM,OAAO,WAAW;AACxB,YAAM,MAAM,KAAK,YAAY;AAC7B,kBAAY,IAAI,OAAO,EAAE,GAAG,IAAI,GAAG,GAAG,IAAI,EAAE,GAAG,QAAQ,UAAU;AAAA,IAClE;AAAA,EACD;AAAA,EAEQ,mBAAmB,QAAgB,QAAqC;AAC/E,QAAI,CAAC,KAAK,aAAa,KAAK,qBAAqB,IAAI,MAAM,EAAG;AAC9D,SAAK,UAAU,oBAAoB,QAAQ,iBAAiB,KAAK;AAAA,MAChE,KAAK,OAAO;AAAA,MACZ,QAAQ,OAAO;AAAA,MACf,MAAM,OAAO;AAAA,MACb,OAAO,OAAO;AAAA,MACd,OAAO;AAAA,MACP,MAAM;AAAA,IACP,CAAC;AACD,SAAK,qBAAqB,IAAI,MAAM;AAAA,EACrC;AAAA,EAEA,QAAQ,MAAqB;AAC5B,SAAK,qBAAqB,MAAM;AAAA,EACjC;AACD;AAsBO,IAAM,0BAA0B,eAAe;AAAA,EACrD,MAAM;AAAA,EACN;AAAA,EACA,eAAe,CAAC,QACf,IAAI,sBAAsB,IAAI,OAAO,IAAI,aAAa,MAAM,IAAI,gBAAgB;AAAA,EACjF,cAAc;AACf,CAAC;","names":["WorldBoundary2DState","WorldBoundary2DEvent"]}
@@ -0,0 +1,210 @@
1
+ import {
2
+ createBounds2DRect,
3
+ wrapPoint2D
4
+ } from "./chunk-KDY5N6J4.js";
5
+ import {
6
+ SyncStateMachine,
7
+ t
8
+ } from "./chunk-4URF65BR.js";
9
+ import {
10
+ defineBehavior
11
+ } from "./chunk-EZNCCO4L.js";
12
+
13
+ // src/lib/behaviors/screen-wrap/screen-wrap-fsm.ts
14
+ var ScreenWrapState = /* @__PURE__ */ ((ScreenWrapState2) => {
15
+ ScreenWrapState2["Center"] = "center";
16
+ ScreenWrapState2["NearEdgeLeft"] = "near-edge-left";
17
+ ScreenWrapState2["NearEdgeRight"] = "near-edge-right";
18
+ ScreenWrapState2["NearEdgeTop"] = "near-edge-top";
19
+ ScreenWrapState2["NearEdgeBottom"] = "near-edge-bottom";
20
+ ScreenWrapState2["Wrapped"] = "wrapped";
21
+ return ScreenWrapState2;
22
+ })(ScreenWrapState || {});
23
+ var ScreenWrapEvent = /* @__PURE__ */ ((ScreenWrapEvent2) => {
24
+ ScreenWrapEvent2["EnterCenter"] = "enter-center";
25
+ ScreenWrapEvent2["ApproachLeft"] = "approach-left";
26
+ ScreenWrapEvent2["ApproachRight"] = "approach-right";
27
+ ScreenWrapEvent2["ApproachTop"] = "approach-top";
28
+ ScreenWrapEvent2["ApproachBottom"] = "approach-bottom";
29
+ ScreenWrapEvent2["Wrap"] = "wrap";
30
+ return ScreenWrapEvent2;
31
+ })(ScreenWrapEvent || {});
32
+ var ScreenWrapFSM = class {
33
+ machine;
34
+ constructor() {
35
+ this.machine = new SyncStateMachine(
36
+ "center" /* Center */,
37
+ [
38
+ // From Center
39
+ t("center" /* Center */, "approach-left" /* ApproachLeft */, "near-edge-left" /* NearEdgeLeft */),
40
+ t("center" /* Center */, "approach-right" /* ApproachRight */, "near-edge-right" /* NearEdgeRight */),
41
+ t("center" /* Center */, "approach-top" /* ApproachTop */, "near-edge-top" /* NearEdgeTop */),
42
+ t("center" /* Center */, "approach-bottom" /* ApproachBottom */, "near-edge-bottom" /* NearEdgeBottom */),
43
+ // From NearEdge to Wrapped
44
+ t("near-edge-left" /* NearEdgeLeft */, "wrap" /* Wrap */, "wrapped" /* Wrapped */),
45
+ t("near-edge-right" /* NearEdgeRight */, "wrap" /* Wrap */, "wrapped" /* Wrapped */),
46
+ t("near-edge-top" /* NearEdgeTop */, "wrap" /* Wrap */, "wrapped" /* Wrapped */),
47
+ t("near-edge-bottom" /* NearEdgeBottom */, "wrap" /* Wrap */, "wrapped" /* Wrapped */),
48
+ // From NearEdge back to Center
49
+ t("near-edge-left" /* NearEdgeLeft */, "enter-center" /* EnterCenter */, "center" /* Center */),
50
+ t("near-edge-right" /* NearEdgeRight */, "enter-center" /* EnterCenter */, "center" /* Center */),
51
+ t("near-edge-top" /* NearEdgeTop */, "enter-center" /* EnterCenter */, "center" /* Center */),
52
+ t("near-edge-bottom" /* NearEdgeBottom */, "enter-center" /* EnterCenter */, "center" /* Center */),
53
+ // From Wrapped back to Center
54
+ t("wrapped" /* Wrapped */, "enter-center" /* EnterCenter */, "center" /* Center */),
55
+ // From Wrapped to NearEdge (landed near opposite edge)
56
+ t("wrapped" /* Wrapped */, "approach-left" /* ApproachLeft */, "near-edge-left" /* NearEdgeLeft */),
57
+ t("wrapped" /* Wrapped */, "approach-right" /* ApproachRight */, "near-edge-right" /* NearEdgeRight */),
58
+ t("wrapped" /* Wrapped */, "approach-top" /* ApproachTop */, "near-edge-top" /* NearEdgeTop */),
59
+ t("wrapped" /* Wrapped */, "approach-bottom" /* ApproachBottom */, "near-edge-bottom" /* NearEdgeBottom */),
60
+ // Self-transitions (no-ops for redundant events)
61
+ t("center" /* Center */, "enter-center" /* EnterCenter */, "center" /* Center */),
62
+ t("near-edge-left" /* NearEdgeLeft */, "approach-left" /* ApproachLeft */, "near-edge-left" /* NearEdgeLeft */),
63
+ t("near-edge-right" /* NearEdgeRight */, "approach-right" /* ApproachRight */, "near-edge-right" /* NearEdgeRight */),
64
+ t("near-edge-top" /* NearEdgeTop */, "approach-top" /* ApproachTop */, "near-edge-top" /* NearEdgeTop */),
65
+ t("near-edge-bottom" /* NearEdgeBottom */, "approach-bottom" /* ApproachBottom */, "near-edge-bottom" /* NearEdgeBottom */)
66
+ ]
67
+ );
68
+ }
69
+ getState() {
70
+ return this.machine.getState();
71
+ }
72
+ dispatch(event) {
73
+ if (this.machine.can(event)) {
74
+ this.machine.syncDispatch(event);
75
+ }
76
+ }
77
+ /**
78
+ * Update FSM based on entity position relative to bounds
79
+ */
80
+ update(position, bounds, wrapped) {
81
+ const { x, y } = position;
82
+ const { minX, maxX, minY, maxY, edgeThreshold } = bounds;
83
+ if (wrapped) {
84
+ this.dispatch("wrap" /* Wrap */);
85
+ return;
86
+ }
87
+ const nearLeft = x < minX + edgeThreshold;
88
+ const nearRight = x > maxX - edgeThreshold;
89
+ const nearBottom = y < minY + edgeThreshold;
90
+ const nearTop = y > maxY - edgeThreshold;
91
+ if (nearLeft) {
92
+ this.dispatch("approach-left" /* ApproachLeft */);
93
+ } else if (nearRight) {
94
+ this.dispatch("approach-right" /* ApproachRight */);
95
+ } else if (nearTop) {
96
+ this.dispatch("approach-top" /* ApproachTop */);
97
+ } else if (nearBottom) {
98
+ this.dispatch("approach-bottom" /* ApproachBottom */);
99
+ } else {
100
+ this.dispatch("enter-center" /* EnterCenter */);
101
+ }
102
+ }
103
+ };
104
+
105
+ // src/lib/behaviors/screen-wrap/screen-wrap.descriptor.ts
106
+ var defaultOptions = {
107
+ width: 20,
108
+ height: 15,
109
+ centerX: 0,
110
+ centerY: 0,
111
+ edgeThreshold: 2
112
+ };
113
+ var SCREEN_WRAP_BEHAVIOR_KEY = /* @__PURE__ */ Symbol.for("zylem:behavior:screen-wrap");
114
+ var ScreenWrapSystem = class {
115
+ constructor(world, wasmStage, getBehaviorLinks) {
116
+ this.world = world;
117
+ this.wasmStage = wasmStage;
118
+ this.getBehaviorLinks = getBehaviorLinks;
119
+ }
120
+ world;
121
+ wasmStage;
122
+ getBehaviorLinks;
123
+ attachedRuntimeSlots = /* @__PURE__ */ new Set();
124
+ update(_ecs, _delta) {
125
+ const links = this.getBehaviorLinks?.(SCREEN_WRAP_BEHAVIOR_KEY);
126
+ if (!links) return;
127
+ for (const link of links) {
128
+ const gameEntity = link.entity;
129
+ const wrapRef = link.ref;
130
+ const options = wrapRef.options;
131
+ if (!wrapRef.fsm) {
132
+ wrapRef.fsm = new ScreenWrapFSM();
133
+ }
134
+ const handle = gameEntity.runtimeHandle ?? -1;
135
+ if (this.wasmStage && handle >= 0) {
136
+ this.ensureWasmAttached(handle, options);
137
+ const pose = this.wasmStage.getPose(handle);
138
+ const query = this.wasmStage.queryScreenWrap(handle);
139
+ if (pose && query) {
140
+ const bounds2 = createBounds2DRect(options);
141
+ wrapRef.fsm.update(
142
+ { x: pose.position[0], y: pose.position[1] },
143
+ {
144
+ minX: bounds2.minX,
145
+ maxX: bounds2.maxX,
146
+ minY: bounds2.minY,
147
+ maxY: bounds2.maxY,
148
+ edgeThreshold: options.edgeThreshold
149
+ },
150
+ query.lastWrappedAxes !== 0
151
+ );
152
+ continue;
153
+ }
154
+ }
155
+ if (!gameEntity.body) continue;
156
+ const wrapped = this.wrapEntity(gameEntity, options);
157
+ const pos = gameEntity.body.translation();
158
+ const bounds = createBounds2DRect(options);
159
+ wrapRef.fsm.update(
160
+ { x: pos.x, y: pos.y },
161
+ {
162
+ minX: bounds.minX,
163
+ maxX: bounds.maxX,
164
+ minY: bounds.minY,
165
+ maxY: bounds.maxY,
166
+ edgeThreshold: options.edgeThreshold
167
+ },
168
+ wrapped
169
+ );
170
+ }
171
+ }
172
+ ensureWasmAttached(handle, options) {
173
+ if (!this.wasmStage || this.attachedRuntimeSlots.has(handle)) return;
174
+ this.wasmStage.attachScreenWrap(handle, {
175
+ width: options.width,
176
+ height: options.height,
177
+ centerX: options.centerX,
178
+ centerY: options.centerY,
179
+ edgeThreshold: options.edgeThreshold
180
+ });
181
+ this.attachedRuntimeSlots.add(handle);
182
+ }
183
+ wrapEntity(entity, options) {
184
+ const body = entity.body;
185
+ if (!body) return false;
186
+ const pos = body.translation();
187
+ const bounds = createBounds2DRect(options);
188
+ const result = wrapPoint2D({ x: pos.x, y: pos.y }, bounds);
189
+ if (result.wrapped) {
190
+ body.setTranslation({ x: result.x, y: result.y, z: pos.z }, true);
191
+ }
192
+ return result.wrapped;
193
+ }
194
+ destroy(_ecs) {
195
+ this.attachedRuntimeSlots.clear();
196
+ }
197
+ };
198
+ var ScreenWrapBehavior = defineBehavior({
199
+ name: "screen-wrap",
200
+ defaultOptions,
201
+ systemFactory: (ctx) => new ScreenWrapSystem(ctx.world, ctx.wasmStage ?? null, ctx.getBehaviorLinks)
202
+ });
203
+
204
+ export {
205
+ ScreenWrapState,
206
+ ScreenWrapEvent,
207
+ ScreenWrapFSM,
208
+ ScreenWrapBehavior
209
+ };
210
+ //# sourceMappingURL=chunk-XIJNE67Y.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/behaviors/screen-wrap/screen-wrap-fsm.ts","../src/lib/behaviors/screen-wrap/screen-wrap.descriptor.ts"],"sourcesContent":["/**\n * ScreenWrapFSM\n * \n * State machine for screen wrap behavior.\n * Reports position relative to bounds edges.\n */\n\nimport { SyncStateMachine, t } from '../../core/utility/sync-state-machine';\n\n// ─────────────────────────────────────────────────────────────────────────────\n// FSM State Model\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport enum ScreenWrapState {\n\tCenter = 'center',\n\tNearEdgeLeft = 'near-edge-left',\n\tNearEdgeRight = 'near-edge-right',\n\tNearEdgeTop = 'near-edge-top',\n\tNearEdgeBottom = 'near-edge-bottom',\n\tWrapped = 'wrapped',\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// FSM Events\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport enum ScreenWrapEvent {\n\tEnterCenter = 'enter-center',\n\tApproachLeft = 'approach-left',\n\tApproachRight = 'approach-right',\n\tApproachTop = 'approach-top',\n\tApproachBottom = 'approach-bottom',\n\tWrap = 'wrap',\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// ScreenWrapFSM\n// ─────────────────────────────────────────────────────────────────────────────\n\nexport class ScreenWrapFSM {\n\tmachine: SyncStateMachine<ScreenWrapState, ScreenWrapEvent, never>;\n\n\tconstructor() {\n\t\tthis.machine = new SyncStateMachine<ScreenWrapState, ScreenWrapEvent, never>(\n\t\t\tScreenWrapState.Center,\n\t\t\t[\n\t\t\t\t// From Center\n\t\t\t\tt(ScreenWrapState.Center, ScreenWrapEvent.ApproachLeft, ScreenWrapState.NearEdgeLeft),\n\t\t\t\tt(ScreenWrapState.Center, ScreenWrapEvent.ApproachRight, ScreenWrapState.NearEdgeRight),\n\t\t\t\tt(ScreenWrapState.Center, ScreenWrapEvent.ApproachTop, ScreenWrapState.NearEdgeTop),\n\t\t\t\tt(ScreenWrapState.Center, ScreenWrapEvent.ApproachBottom, ScreenWrapState.NearEdgeBottom),\n\t\t\t\t\n\t\t\t\t// From NearEdge to Wrapped\n\t\t\t\tt(ScreenWrapState.NearEdgeLeft, ScreenWrapEvent.Wrap, ScreenWrapState.Wrapped),\n\t\t\t\tt(ScreenWrapState.NearEdgeRight, ScreenWrapEvent.Wrap, ScreenWrapState.Wrapped),\n\t\t\t\tt(ScreenWrapState.NearEdgeTop, ScreenWrapEvent.Wrap, ScreenWrapState.Wrapped),\n\t\t\t\tt(ScreenWrapState.NearEdgeBottom, ScreenWrapEvent.Wrap, ScreenWrapState.Wrapped),\n\n\t\t\t\t// From NearEdge back to Center\n\t\t\t\tt(ScreenWrapState.NearEdgeLeft, ScreenWrapEvent.EnterCenter, ScreenWrapState.Center),\n\t\t\t\tt(ScreenWrapState.NearEdgeRight, ScreenWrapEvent.EnterCenter, ScreenWrapState.Center),\n\t\t\t\tt(ScreenWrapState.NearEdgeTop, ScreenWrapEvent.EnterCenter, ScreenWrapState.Center),\n\t\t\t\tt(ScreenWrapState.NearEdgeBottom, ScreenWrapEvent.EnterCenter, ScreenWrapState.Center),\n\n\t\t\t\t// From Wrapped back to Center\n\t\t\t\tt(ScreenWrapState.Wrapped, ScreenWrapEvent.EnterCenter, ScreenWrapState.Center),\n\n\t\t\t\t// From Wrapped to NearEdge (landed near opposite edge)\n\t\t\t\tt(ScreenWrapState.Wrapped, ScreenWrapEvent.ApproachLeft, ScreenWrapState.NearEdgeLeft),\n\t\t\t\tt(ScreenWrapState.Wrapped, ScreenWrapEvent.ApproachRight, ScreenWrapState.NearEdgeRight),\n\t\t\t\tt(ScreenWrapState.Wrapped, ScreenWrapEvent.ApproachTop, ScreenWrapState.NearEdgeTop),\n\t\t\t\tt(ScreenWrapState.Wrapped, ScreenWrapEvent.ApproachBottom, ScreenWrapState.NearEdgeBottom),\n\n\t\t\t\t// Self-transitions (no-ops for redundant events)\n\t\t\t\tt(ScreenWrapState.Center, ScreenWrapEvent.EnterCenter, ScreenWrapState.Center),\n\t\t\t\tt(ScreenWrapState.NearEdgeLeft, ScreenWrapEvent.ApproachLeft, ScreenWrapState.NearEdgeLeft),\n\t\t\t\tt(ScreenWrapState.NearEdgeRight, ScreenWrapEvent.ApproachRight, ScreenWrapState.NearEdgeRight),\n\t\t\t\tt(ScreenWrapState.NearEdgeTop, ScreenWrapEvent.ApproachTop, ScreenWrapState.NearEdgeTop),\n\t\t\t\tt(ScreenWrapState.NearEdgeBottom, ScreenWrapEvent.ApproachBottom, ScreenWrapState.NearEdgeBottom),\n\t\t\t]\n\t\t);\n\t}\n\n\tgetState(): ScreenWrapState {\n\t\treturn this.machine.getState();\n\t}\n\n\tdispatch(event: ScreenWrapEvent): void {\n\t\tif (this.machine.can(event)) {\n\t\t\tthis.machine.syncDispatch(event);\n\t\t}\n\t}\n\n\t/**\n\t * Update FSM based on entity position relative to bounds\n\t */\n\tupdate(position: { x: number; y: number }, bounds: {\n\t\tminX: number; maxX: number; minY: number; maxY: number;\n\t\tedgeThreshold: number;\n\t}, wrapped: boolean): void {\n\t\tconst { x, y } = position;\n\t\tconst { minX, maxX, minY, maxY, edgeThreshold } = bounds;\n\n\t\tif (wrapped) {\n\t\t\tthis.dispatch(ScreenWrapEvent.Wrap);\n\t\t\treturn;\n\t\t}\n\n\t\t// Check if near edges\n\t\tconst nearLeft = x < minX + edgeThreshold;\n\t\tconst nearRight = x > maxX - edgeThreshold;\n\t\tconst nearBottom = y < minY + edgeThreshold;\n\t\tconst nearTop = y > maxY - edgeThreshold;\n\n\t\tif (nearLeft) {\n\t\t\tthis.dispatch(ScreenWrapEvent.ApproachLeft);\n\t\t} else if (nearRight) {\n\t\t\tthis.dispatch(ScreenWrapEvent.ApproachRight);\n\t\t} else if (nearTop) {\n\t\t\tthis.dispatch(ScreenWrapEvent.ApproachTop);\n\t\t} else if (nearBottom) {\n\t\t\tthis.dispatch(ScreenWrapEvent.ApproachBottom);\n\t\t} else {\n\t\t\tthis.dispatch(ScreenWrapEvent.EnterCenter);\n\t\t}\n\t}\n}\n","/**\n * ScreenWrapBehavior\n * \n * When an entity exits the defined 2D bounds, it wraps around to the opposite edge.\n * Asteroids-style screen wrapping with FSM for edge detection.\n */\n\nimport { defineBehavior } from '../behavior-descriptor';\nimport type { BehaviorEntityLink, BehaviorSystem } from '../behavior-system';\nimport { ScreenWrapFSM } from './screen-wrap-fsm';\nimport { createBounds2DRect, wrapPoint2D } from '../shared/bounds-2d';\nimport type { WasmStageRuntime } from '../../runtime/wasm-stage-runtime';\n\n/**\n * Screen wrap options (typed for entity.use() autocomplete)\n */\nexport interface ScreenWrapOptions {\n\t/** Width of the wrapping area (default: 20) */\n\twidth: number;\n\t/** Height of the wrapping area (default: 15) */\n\theight: number;\n\t/** Center X position (default: 0) */\n\tcenterX: number;\n\t/** Center Y position (default: 0) */\n\tcenterY: number;\n\t/** Distance from edge to trigger NearEdge state (default: 2) */\n\tedgeThreshold: number;\n}\n\nconst defaultOptions: ScreenWrapOptions = {\n\twidth: 20,\n\theight: 15,\n\tcenterX: 0,\n\tcenterY: 0,\n\tedgeThreshold: 2,\n};\n\nconst SCREEN_WRAP_BEHAVIOR_KEY = Symbol.for('zylem:behavior:screen-wrap');\n\n/**\n * ScreenWrapSystem - Wraps entities around 2D bounds\n *\n * Mirrors the Rust `screen_wrap` Stage behavior: when `wasmStage` is present\n * and the entity has a `runtimeHandle`, the wasm runtime owns the wrap and\n * this system only mirrors the queried state into the local FSM. Otherwise\n * the legacy TS path runs against the Rapier `RigidBody` translation.\n */\nclass ScreenWrapSystem implements BehaviorSystem {\n\tprivate attachedRuntimeSlots = new Set<number>();\n\n\tconstructor(\n\t\tprivate world: any,\n\t\tprivate wasmStage: WasmStageRuntime | null,\n\t\tprivate getBehaviorLinks?: (key: symbol) => Iterable<BehaviorEntityLink>,\n\t) {}\n\n\tupdate(_ecs: unknown, _delta: number): void {\n\t\tconst links = this.getBehaviorLinks?.(SCREEN_WRAP_BEHAVIOR_KEY);\n\t\tif (!links) return;\n\n\t\tfor (const link of links) {\n\t\t\tconst gameEntity = link.entity as any;\n\t\t\tconst wrapRef = link.ref as any;\n\t\t\tconst options = wrapRef.options as ScreenWrapOptions;\n\n\t\t\tif (!wrapRef.fsm) {\n\t\t\t\twrapRef.fsm = new ScreenWrapFSM();\n\t\t\t}\n\n\t\t\tconst handle = (gameEntity.runtimeHandle ?? -1) as number;\n\t\t\tif (this.wasmStage && handle >= 0) {\n\t\t\t\tthis.ensureWasmAttached(handle, options);\n\t\t\t\tconst pose = this.wasmStage.getPose(handle);\n\t\t\t\tconst query = this.wasmStage.queryScreenWrap(handle);\n\t\t\t\tif (pose && query) {\n\t\t\t\t\tconst bounds = createBounds2DRect(options);\n\t\t\t\t\twrapRef.fsm.update(\n\t\t\t\t\t\t{ x: pose.position[0], y: pose.position[1] },\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tminX: bounds.minX,\n\t\t\t\t\t\t\tmaxX: bounds.maxX,\n\t\t\t\t\t\t\tminY: bounds.minY,\n\t\t\t\t\t\t\tmaxY: bounds.maxY,\n\t\t\t\t\t\t\tedgeThreshold: options.edgeThreshold,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tquery.lastWrappedAxes !== 0,\n\t\t\t\t\t);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!gameEntity.body) continue;\n\t\t\tconst wrapped = this.wrapEntity(gameEntity, options);\n\t\t\tconst pos = gameEntity.body.translation();\n\t\t\tconst bounds = createBounds2DRect(options);\n\t\t\twrapRef.fsm.update(\n\t\t\t\t{ x: pos.x, y: pos.y },\n\t\t\t\t{\n\t\t\t\t\tminX: bounds.minX,\n\t\t\t\t\tmaxX: bounds.maxX,\n\t\t\t\t\tminY: bounds.minY,\n\t\t\t\t\tmaxY: bounds.maxY,\n\t\t\t\t\tedgeThreshold: options.edgeThreshold,\n\t\t\t\t},\n\t\t\t\twrapped,\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate ensureWasmAttached(handle: number, options: ScreenWrapOptions): void {\n\t\tif (!this.wasmStage || this.attachedRuntimeSlots.has(handle)) return;\n\t\tthis.wasmStage.attachScreenWrap(handle, {\n\t\t\twidth: options.width,\n\t\t\theight: options.height,\n\t\t\tcenterX: options.centerX,\n\t\t\tcenterY: options.centerY,\n\t\t\tedgeThreshold: options.edgeThreshold,\n\t\t});\n\t\tthis.attachedRuntimeSlots.add(handle);\n\t}\n\n\tprivate wrapEntity(entity: any, options: ScreenWrapOptions): boolean {\n\t\tconst body = entity.body;\n\t\tif (!body) return false;\n\n\t\tconst pos = body.translation();\n\t\tconst bounds = createBounds2DRect(options);\n\t\tconst result = wrapPoint2D({ x: pos.x, y: pos.y }, bounds);\n\n\t\tif (result.wrapped) {\n\t\t\tbody.setTranslation({ x: result.x, y: result.y, z: pos.z }, true);\n\t\t}\n\n\t\treturn result.wrapped;\n\t}\n\n\tdestroy(_ecs: unknown): void {\n\t\tthis.attachedRuntimeSlots.clear();\n\t}\n}\n\n/**\n * ScreenWrapBehavior - Wraps entities around 2D bounds\n * \n * @example\n * ```typescript\n * import { ScreenWrapBehavior } from \"@zylem/game-lib/behavior\";\n * \n * const ship = createSprite({ ... });\n * const wrapRef = ship.use(ScreenWrapBehavior, { width: 20, height: 15 });\n * \n * // Access FSM to observe edge state\n * const fsm = wrapRef.getFSM();\n * console.log(fsm?.getState()); // 'center', 'near-edge-left', 'wrapped', etc.\n * ```\n */\nexport const ScreenWrapBehavior = defineBehavior({\n\tname: 'screen-wrap',\n\tdefaultOptions,\n\tsystemFactory: (ctx) =>\n\t\tnew ScreenWrapSystem(ctx.world, ctx.wasmStage ?? null, ctx.getBehaviorLinks),\n});\n"],"mappings":";;;;;;;;;;;;;AAaO,IAAK,kBAAL,kBAAKA,qBAAL;AACN,EAAAA,iBAAA,YAAS;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+ Static: 1,
5
+ KinematicPosition: 2,
6
+ KinematicVelocity: 3
7
+ };
8
+ var StageBoundaryDim = {
9
+ Two: 2,
10
+ Three: 3
11
+ };
12
+ var StageRicochetDim = {
13
+ Two: 2,
14
+ Three: 3
15
+ };
16
+ var StageRicochetReflection = {
17
+ Mirror: 0,
18
+ Angled: 1
19
+ };
20
+ var StageTopDownPlane = {
21
+ Xy: 0,
22
+ Xz: 1
23
+ };
24
+ var StageEventType = {
25
+ CollisionStarted: 1,
26
+ CollisionStopped: 2,
27
+ BoundaryHit: 3,
28
+ Ricochet: 4,
29
+ RegionEntered: 5,
30
+ JumpStarted: 6,
31
+ Landed: 7,
32
+ Wrapped: 8,
33
+ CooldownFired: 9
34
+ };
35
+
36
+ export {
37
+ StageBodyKind,
38
+ StageBoundaryDim,
39
+ StageRicochetDim,
40
+ StageRicochetReflection,
41
+ StageTopDownPlane,
42
+ StageEventType
43
+ };
44
+ //# sourceMappingURL=chunk-Y6UJOUE5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/runtime/wasm-stage-runtime.ts"],"sourcesContent":["export const StageBodyKind = {\n\tDynamic: 0,\n\tStatic: 1,\n\tKinematicPosition: 2,\n\tKinematicVelocity: 3,\n} as const;\n\nexport const StageBoundaryDim = {\n\tTwo: 2,\n\tThree: 3,\n} as const;\n\nexport const StageRicochetDim = {\n\tTwo: 2,\n\tThree: 3,\n} as const;\n\nexport const StageRicochetReflection = {\n\tMirror: 0,\n\tAngled: 1,\n} as const;\n\nexport const StageTopDownPlane = {\n\tXy: 0,\n\tXz: 1,\n} as const;\n\nexport const StageEventType = {\n\tCollisionStarted: 1,\n\tCollisionStopped: 2,\n\tBoundaryHit: 3,\n\tRicochet: 4,\n\tRegionEntered: 5,\n\tJumpStarted: 6,\n\tLanded: 7,\n\tWrapped: 8,\n\tCooldownFired: 9,\n} as const;\n\nexport interface WasmStageRuntime {\n\tgetPose(handle: number): any;\n\tattachThruster(handle: number, opts: any): boolean;\n\tsetThrusterInput(handle: number, thrust: number, rotate: number): void;\n\tattachTopDown(handle: number, opts: { plane: number; speed: number; faceMovement?: boolean }): boolean;\n\tsetTopDownInput(handle: number, moveX: number, moveY: number): void;\n\tattachShooter2D(handle: number, opts: any): boolean;\n\tattachScreenWrap(handle: number, opts: any): boolean;\n\tqueryScreenWrap(handle: number): any;\n\tattachWorldBoundary(handle: number, dim: number, opts: any): boolean;\n\tqueryWorldBoundary(handle: number): any;\n\tattachRicochet(handle: number, dim: number, opts: any): boolean;\n\tattachPlatformer3D(handle: number, opts: any): boolean;\n\tsetPlatformer3DInputAxes(handle: number, moveX: number, moveZ: number): void;\n\tsetPlatformer3DInputButtons(handle: number, jump: boolean, run: boolean): void;\n\tattachFirstPerson(handle: number, opts: any): boolean;\n\tsetFirstPersonInput(handle: number, input: any): void;\n\tattachJumper2D(handle: number, opts: any): boolean;\n\tsetJumper2DInput(handle: number, jumpPressed: boolean): void;\n\tattachJumper3D(handle: number, opts: any): boolean;\n\tsetJumper3DInput(handle: number, jumpPressed: boolean): void;\n}\n\n/** Default options used when constructing a wasm-backed Stage runtime. */\nexport interface WasmStageRuntimeOptions {\n\tinitialCapacity?: number;\n\tgravity?: readonly [number, number, number];\n\timports?: WebAssembly.Imports;\n}\n"],"mappings":";AAAO,IAAM,gBAAgB;AAAA,EAC5B,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,mBAAmB;AAAA,EACnB,mBAAmB;AACpB;AAEO,IAAM,mBAAmB;AAAA,EAC/B,KAAK;AAAA,EACL,OAAO;AACR;AAEO,IAAM,mBAAmB;AAAA,EAC/B,KAAK;AAAA,EACL,OAAO;AACR;AAEO,IAAM,0BAA0B;AAAA,EACtC,QAAQ;AAAA,EACR,QAAQ;AACT;AAEO,IAAM,oBAAoB;AAAA,EAChC,IAAI;AAAA,EACJ,IAAI;AACL;AAEO,IAAM,iBAAiB;AAAA,EAC7B,kBAAkB;AAAA,EAClB,kBAAkB;AAAA,EAClB,aAAa;AAAA,EACb,UAAU;AAAA,EACV,eAAe;AAAA,EACf,aAAa;AAAA,EACb,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,eAAe;AAChB;","names":[]}