@zylem/behaviors 0.5.8 → 0.5.11

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.
@@ -854,6 +854,12 @@ interface BehaviorSystem {
854
854
  attach?(link: BehaviorEntityLink): void;
855
855
  /** Called once per frame. The first argument is always `undefined` (reserved legacy slot). */
856
856
  update(ecs: unknown, delta: number): void;
857
+ /**
858
+ * Called once per frame after the simulation has stepped and before the
859
+ * host syncs render poses. Systems that need this frame's post-step state
860
+ * (e.g. wasm-side teleports) run here instead of in `update`.
861
+ */
862
+ postUpdate?(ecs: unknown, delta: number): void;
857
863
  /** Optional cleanup when a behavior link is detached from a live entity */
858
864
  detach?(link: BehaviorEntityLink): void;
859
865
  /** Optional cleanup when stage is destroyed */
@@ -131,22 +131,49 @@ var ScreenWrapSystem = class {
131
131
  const handle = gameEntity.runtimeHandle ?? -1;
132
132
  if (!this.wasmStage || handle < 0) continue;
133
133
  this.ensureWasmAttached(handle, options);
134
+ }
135
+ }
136
+ /**
137
+ * Runs after the simulation step so the queried wrap state describes this
138
+ * frame's step rather than the previous one.
139
+ *
140
+ * The runtime wraps by teleporting the rigid body, which the host's render
141
+ * interpolation cannot see: it would blend the pre-wrap edge pose with the
142
+ * post-wrap opposite edge and sweep the entity across the screen. Flagging
143
+ * the discontinuity here — before render poses are synced — suppresses that
144
+ * blend for the frames where the buffers straddle the wrap.
145
+ */
146
+ postUpdate(_ecs, _delta) {
147
+ const links = this.getBehaviorLinks?.(SCREEN_WRAP_BEHAVIOR_KEY);
148
+ if (!links) return;
149
+ for (const link of links) {
150
+ const gameEntity = link.entity;
151
+ const wrapRef = link.ref;
152
+ const options = wrapRef.options;
153
+ if (!wrapRef.fsm) {
154
+ wrapRef.fsm = new ScreenWrapFSM();
155
+ }
156
+ const handle = gameEntity.runtimeHandle ?? -1;
157
+ if (!this.wasmStage || handle < 0) continue;
134
158
  const pose = this.wasmStage.getPose(handle);
135
159
  const query = this.wasmStage.queryScreenWrap(handle);
136
- if (pose && query) {
137
- const bounds = createBounds2DRect(options);
138
- wrapRef.fsm.update(
139
- { x: pose.position[0], y: pose.position[1] },
140
- {
141
- minX: bounds.minX,
142
- maxX: bounds.maxX,
143
- minY: bounds.minY,
144
- maxY: bounds.maxY,
145
- edgeThreshold: options.edgeThreshold
146
- },
147
- query.lastWrappedAxes !== 0
148
- );
160
+ if (!pose || !query) continue;
161
+ const wrapped = query.lastWrappedAxes !== 0;
162
+ if (wrapped) {
163
+ gameEntity.body?.markPoseDiscontinuity?.();
149
164
  }
165
+ const bounds = createBounds2DRect(options);
166
+ wrapRef.fsm.update(
167
+ { x: pose.position[0], y: pose.position[1] },
168
+ {
169
+ minX: bounds.minX,
170
+ maxX: bounds.maxX,
171
+ minY: bounds.minY,
172
+ maxY: bounds.maxY,
173
+ edgeThreshold: options.edgeThreshold
174
+ },
175
+ wrapped
176
+ );
150
177
  }
151
178
  }
152
179
  ensureWasmAttached(handle, options) {
@@ -176,4 +203,4 @@ export {
176
203
  ScreenWrapFSM,
177
204
  ScreenWrapBehavior
178
205
  };
179
- //# sourceMappingURL=chunk-2PAHQZZD.js.map
206
+ //# sourceMappingURL=chunk-MUBU2DIB.js.map
@@ -1 +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 } from '../shared/bounds-2d';\nimport type { BehaviorRuntime } 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 * The Rust `screen_wrap` Stage behavior owns the wrap; this system attaches\n * it and mirrors the queried state into the local FSM so handles can observe\n * edge/wrap states.\n */\nclass ScreenWrapSystem implements BehaviorSystem {\n\tprivate attachedRuntimeSlots = new Set<number>();\n\n\tconstructor(\n\t\tprivate wasmStage: BehaviorRuntime | 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) continue;\n\n\t\t\tthis.ensureWasmAttached(handle, options);\n\t\t\tconst pose = this.wasmStage.getPose(handle);\n\t\t\tconst query = this.wasmStage.queryScreenWrap(handle);\n\t\t\tif (pose && query) {\n\t\t\t\tconst bounds = createBounds2DRect(options);\n\t\t\t\twrapRef.fsm.update(\n\t\t\t\t\t{ x: pose.position[0], y: pose.position[1] },\n\t\t\t\t\t{\n\t\t\t\t\t\tminX: bounds.minX,\n\t\t\t\t\t\tmaxX: bounds.maxX,\n\t\t\t\t\t\tminY: bounds.minY,\n\t\t\t\t\t\tmaxY: bounds.maxY,\n\t\t\t\t\t\tedgeThreshold: options.edgeThreshold,\n\t\t\t\t\t},\n\t\t\t\t\tquery.lastWrappedAxes !== 0,\n\t\t\t\t);\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\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.wasmStage ?? null, ctx.getBehaviorLinks),\n});\n"],"mappings":";;;;;;;;;;;;AAaO,IAAK,kBAAL,kBAAKA,qBAAL;AACN,EAAAA,iBAAA,YAAS;AACT,EAAAA,iBAAA,kBAAe;AACf,EAAAA,iBAAA,mBAAgB;AAChB,EAAAA,iBAAA,iBAAc;AACd,EAAAA,iBAAA,oBAAiB;AACjB,EAAAA,iBAAA,aAAU;AANC,SAAAA;AAAA,GAAA;AAaL,IAAK,kBAAL,kBAAKC,qBAAL;AACN,EAAAA,iBAAA,iBAAc;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M;AAAA,EACN;AAAA,EACA,eAAe,CAAC,QACf,IAAI,iBAAiB,IAAI,aAAa,MAAM,IAAI,gBAAgB;AAClE,CAAC;","names":["ScreenWrapState","ScreenWrapEvent"]}
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 } from '../shared/bounds-2d';\nimport type { BehaviorRuntime } 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 * The Rust `screen_wrap` Stage behavior owns the wrap; this system attaches\n * it and mirrors the queried state into the local FSM so handles can observe\n * edge/wrap states.\n */\nclass ScreenWrapSystem implements BehaviorSystem {\n\tprivate attachedRuntimeSlots = new Set<number>();\n\n\tconstructor(\n\t\tprivate wasmStage: BehaviorRuntime | 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) continue;\n\n\t\t\tthis.ensureWasmAttached(handle, options);\n\t\t}\n\t}\n\n\t/**\n\t * Runs after the simulation step so the queried wrap state describes this\n\t * frame's step rather than the previous one.\n\t *\n\t * The runtime wraps by teleporting the rigid body, which the host's render\n\t * interpolation cannot see: it would blend the pre-wrap edge pose with the\n\t * post-wrap opposite edge and sweep the entity across the screen. Flagging\n\t * the discontinuity here — before render poses are synced — suppresses that\n\t * blend for the frames where the buffers straddle the wrap.\n\t */\n\tpostUpdate(_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) continue;\n\n\t\t\tconst pose = this.wasmStage.getPose(handle);\n\t\t\tconst query = this.wasmStage.queryScreenWrap(handle);\n\t\t\tif (!pose || !query) continue;\n\n\t\t\tconst wrapped = query.lastWrappedAxes !== 0;\n\t\t\tif (wrapped) {\n\t\t\t\tgameEntity.body?.markPoseDiscontinuity?.();\n\t\t\t}\n\n\t\t\tconst bounds = createBounds2DRect(options);\n\t\t\twrapRef.fsm.update(\n\t\t\t\t{ x: pose.position[0], y: pose.position[1] },\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\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.wasmStage ?? null, ctx.getBehaviorLinks),\n});\n"],"mappings":";;;;;;;;;;;;AAaO,IAAK,kBAAL,kBAAKA,qBAAL;AACN,EAAAA,iBAAA,YAAS;AACT,EAAAA,iBAAA,kBAAe;AACf,EAAAA,iBAAA,mBAAgB;AAChB,EAAAA,iBAAA,iBAAc;AACd,EAAAA,iBAAA,oBAAiB;AACjB,EAAAA,iBAAA,aAAU;AANC,SAAAA;AAAA,GAAA;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AAM,OAAO;AAAA,UACb,MAAM,OAAO;AAAA,UACb,MAAM,OAAO;AAAA,UACb,eAAe,QAAQ;AAAA,QACxB;AAAA,QACA;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAAA,EAEQ,mBAAmB,QAAgB,SAAkC;AAC5E,QAAI,CAAC,KAAK,aAAa,KAAK,qBAAqB,IAAI,MAAM,EAAG;AAC9D,SAAK,UAAU,iBAAiB,QAAQ;AAAA,MACvC,OAAO,QAAQ;AAAA,MACf,QAAQ,QAAQ;AAAA,MAChB,SAAS,QAAQ;AAAA,MACjB,SAAS,QAAQ;AAAA,MACjB,eAAe,QAAQ;AAAA,IACxB,CAAC;AACD,SAAK,qBAAqB,IAAI,MAAM;AAAA,EACrC;AAAA,EAEA,QAAQ,MAAqB;AAC5B,SAAK,qBAAqB,MAAM;AAAA,EACjC;AACD;AAiBO,IAAM,qBAAqB,eAAe;AAAA,EAChD,MAAM;AAAA,EACN;AAAA,EACA,eAAe,CAAC,QACf,IAAI,iBAAiB,IAAI,aAAa,MAAM,IAAI,gBAAgB;AAClE,CAAC;","names":["ScreenWrapState","ScreenWrapEvent"]}
@@ -1,4 +1,4 @@
1
- import { G as GameEntity, a as BehaviorDescriptor } from './behavior-system-HEt67el5.js';
1
+ import { G as GameEntity, a as BehaviorDescriptor } from './behavior-system-DkFAwLb_.js';
2
2
  import { Vector3, Quaternion } from 'three';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { a as BehaviorDescriptor } from './behavior-system-HEt67el5.js';
1
+ import { a as BehaviorDescriptor } from './behavior-system-DkFAwLb_.js';
2
2
  import '@zylem/runtime';
3
3
 
4
4
  /**
@@ -1,9 +1,9 @@
1
- import { a as MoveableEntity } from '../moveable-BdFmI3s1.js';
1
+ import { a as MoveableEntity } from '../moveable-CFOHmblC.js';
2
2
  import { B as BaseEntityInterface } from '../entity-types-DhfsZbSK.js';
3
3
  import { Ricochet3DHandle } from '../ricochet-3d.js';
4
4
  import { WorldBoundary3DHandle } from '../world-boundary-3d.js';
5
5
  import 'three';
6
- import '../behavior-system-HEt67el5.js';
6
+ import '../behavior-system-DkFAwLb_.js';
7
7
  import '@zylem/runtime';
8
8
  import '../sync-state-machine-CZyspBpj.js';
9
9
  import 'typescript-fsm';
@@ -1,10 +1,10 @@
1
1
  import { Ricochet2DHandle } from '../ricochet-2d.js';
2
2
  import { WorldBoundary2DHandle } from '../world-boundary-2d.js';
3
- import { a as MoveableEntity } from '../moveable-BdFmI3s1.js';
3
+ import { a as MoveableEntity } from '../moveable-CFOHmblC.js';
4
4
  import { B as BaseEntityInterface } from '../entity-types-DhfsZbSK.js';
5
5
  import '../sync-state-machine-CZyspBpj.js';
6
6
  import 'typescript-fsm';
7
- import '../behavior-system-HEt67el5.js';
7
+ import '../behavior-system-DkFAwLb_.js';
8
8
  import '@zylem/runtime';
9
9
  import 'three';
10
10
 
@@ -1,7 +1,7 @@
1
1
  import { T as ThrusterInputComponent } from '../components-B29WHGQN.js';
2
2
  import { Shooter2DSourceEntity, Shooter2DHandle, Shooter2DStageLike } from '../shooter-2d.js';
3
3
  import { S as Shooter2DAimFireInput } from '../shooter-fire-DGripl0z.js';
4
- import '../behavior-system-HEt67el5.js';
4
+ import '../behavior-system-DkFAwLb_.js';
5
5
  import '@zylem/runtime';
6
6
  import '../vector-DjhLUrak.js';
7
7
  import 'three';
@@ -1,7 +1,7 @@
1
1
  import { a as TopDownMovementInputComponent } from '../components-XCpL6IYt.js';
2
2
  import { Shooter2DSourceEntity, Shooter2DHandle, Shooter2DStageLike } from '../shooter-2d.js';
3
3
  import { S as Shooter2DAimFireInput } from '../shooter-fire-DGripl0z.js';
4
- import '../behavior-system-HEt67el5.js';
4
+ import '../behavior-system-DkFAwLb_.js';
5
5
  import '@zylem/runtime';
6
6
  import '../vector-DjhLUrak.js';
7
7
  import 'three';
package/dist/core.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { $ as VelocityIntentMode, Z as TransformState, e as BehaviorRuntime, J as StagePose, l as StageBehaviorSnapshot, U as StageThrusterOptions, V as StageTopDownOptions, T as StageShooter2DOptions, R as StageScreenWrapOptions, r as StageBoundaryDimValue, Y as StageWorldBoundaryOptions, N as StageRicochetDimValue, O as StageRicochetOptions, H as StagePlatformer3DOptions, F as StagePlatformer2DOptions, z as StageFirstPersonOptions, y as StageFirstPersonInput, A as StageJumper2DOptions, E as StageJumper3DOptions, a1 as WasmStageRuntime, a2 as WasmStageRuntimeOptions, p as StageBodyKindValue, t as StageColliderShape, L as StageRenderSlot, K as StageRaycastHit, n as StageBodyInfo, u as StageDebugRender } from './behavior-system-HEt67el5.js';
2
- export { B as BaseBehaviorHandle, a as BehaviorDescriptor, b as BehaviorEntityLink, c as BehaviorHandle, d as BehaviorRef, f as BehaviorSystem, g as BehaviorSystemContext, h as BehaviorSystemFactory, C as CreateEntityFn, D as DefineBehaviorConfig, G as GameEntity, i as GameEntityOptions, S as STAGE_INPUT_BUTTON_JUMP, j as STAGE_INPUT_BUTTON_RUN, k as STAGE_INVALID_SLOT, m as StageBodyConfig, o as StageBodyKind, q as StageBoundaryDim, s as StageColliderConfig, v as StageEvent, w as StageEventType, x as StageEventTypeValue, I as StagePlatformerShapeSource, M as StageRicochetDim, P as StageRicochetReflection, Q as StageRicochetReflectionValue, W as StageTopDownPlane, X as StageTopDownPlaneValue, _ as VelocityIntent, a0 as WasmSnapshotBackref, a3 as createTransformStore, a4 as createWasmStageRuntime, a5 as defineBehavior, a6 as readBehaviorSnapshot, a7 as readStageRenderSlot } from './behavior-system-HEt67el5.js';
3
- export { P as PhysicsBodyComponent, T as TransformComponent, c as createPhysicsBodyComponent, a as createTransformComponent, u as useBehavior } from './components-JZQoO2sU.js';
4
- export { E as EntityWithBody, M as MoveableBodyLike, a as MoveableEntity, V as Vector, g as getPosition, b as getVelocity, m as makeMoveable, c as move, d as moveForwardXY, e as moveX, f as moveXY, h as moveXZ, i as moveY, j as moveZ, r as resetVelocity, s as setPosition, k as setPositionX, l as setPositionY, n as setPositionZ, w as wrapAround3D, o as wrapAroundXY } from './moveable-BdFmI3s1.js';
1
+ import { $ as VelocityIntentMode, Z as TransformState, e as BehaviorRuntime, J as StagePose, l as StageBehaviorSnapshot, U as StageThrusterOptions, V as StageTopDownOptions, T as StageShooter2DOptions, R as StageScreenWrapOptions, r as StageBoundaryDimValue, Y as StageWorldBoundaryOptions, N as StageRicochetDimValue, O as StageRicochetOptions, H as StagePlatformer3DOptions, F as StagePlatformer2DOptions, z as StageFirstPersonOptions, y as StageFirstPersonInput, A as StageJumper2DOptions, E as StageJumper3DOptions, a1 as WasmStageRuntime, a2 as WasmStageRuntimeOptions, p as StageBodyKindValue, t as StageColliderShape, L as StageRenderSlot, K as StageRaycastHit, n as StageBodyInfo, u as StageDebugRender } from './behavior-system-DkFAwLb_.js';
2
+ export { B as BaseBehaviorHandle, a as BehaviorDescriptor, b as BehaviorEntityLink, c as BehaviorHandle, d as BehaviorRef, f as BehaviorSystem, g as BehaviorSystemContext, h as BehaviorSystemFactory, C as CreateEntityFn, D as DefineBehaviorConfig, G as GameEntity, i as GameEntityOptions, S as STAGE_INPUT_BUTTON_JUMP, j as STAGE_INPUT_BUTTON_RUN, k as STAGE_INVALID_SLOT, m as StageBodyConfig, o as StageBodyKind, q as StageBoundaryDim, s as StageColliderConfig, v as StageEvent, w as StageEventType, x as StageEventTypeValue, I as StagePlatformerShapeSource, M as StageRicochetDim, P as StageRicochetReflection, Q as StageRicochetReflectionValue, W as StageTopDownPlane, X as StageTopDownPlaneValue, _ as VelocityIntent, a0 as WasmSnapshotBackref, a3 as createTransformStore, a4 as createWasmStageRuntime, a5 as defineBehavior, a6 as readBehaviorSnapshot, a7 as readStageRenderSlot } from './behavior-system-DkFAwLb_.js';
3
+ export { P as PhysicsBodyComponent, T as TransformComponent, c as createPhysicsBodyComponent, a as createTransformComponent, u as useBehavior } from './components--RTwuT4S.js';
4
+ export { E as EntityWithBody, M as MoveableBodyLike, a as MoveableEntity, V as Vector, g as getPosition, b as getVelocity, m as makeMoveable, c as move, d as moveForwardXY, e as moveX, f as moveXY, h as moveXZ, i as moveY, j as moveZ, r as resetVelocity, s as setPosition, k as setPositionX, l as setPositionY, n as setPositionZ, w as wrapAround3D, o as wrapAroundXY } from './moveable-CFOHmblC.js';
5
5
  export { V as VEC2_ONE, a as VEC2_ZERO, b as VEC3_ONE, c as VEC3_ZERO, d as Vec2, e as Vec2Components, f as Vec2Input, g as Vec3, h as Vec3Components, i as Vec3Input, j as isVec2Input, k as isVec3Input, n as normalizeVec2, l as normalizeVec3, t as toThreeVector2, m as toThreeVector3 } from './vector-DjhLUrak.js';
6
6
  export { S as SyncStateMachine } from './sync-state-machine-CZyspBpj.js';
7
7
  export { F as FirstPersonPerspective } from './first-person-perspective-BxFHgFln.js';
@@ -1,4 +1,4 @@
1
- import { a as BehaviorDescriptor } from './behavior-system-HEt67el5.js';
1
+ import { a as BehaviorDescriptor } from './behavior-system-DkFAwLb_.js';
2
2
  import { Material } from 'three';
3
3
  import { FractureOptions, DestructibleMesh } from '@dgreenheck/three-pinata';
4
4
  export { DestructibleMesh, FractureOptions, VoronoiOptions } from '@dgreenheck/three-pinata';
@@ -3,7 +3,7 @@ export { c as createFirstPersonInputComponent, d as createFirstPersonMovementCom
3
3
  import { S as SyncStateMachine } from './sync-state-machine-CZyspBpj.js';
4
4
  import { Vector3, Euler, Object3D } from 'three';
5
5
  import { F as FirstPersonPerspective } from './first-person-perspective-BxFHgFln.js';
6
- import { Z as TransformState, e as BehaviorRuntime, a as BehaviorDescriptor } from './behavior-system-HEt67el5.js';
6
+ import { Z as TransformState, e as BehaviorRuntime, a as BehaviorDescriptor } from './behavior-system-DkFAwLb_.js';
7
7
  import { i as Vec3Input } from './vector-DjhLUrak.js';
8
8
  import 'typescript-fsm';
9
9
  import '@zylem/runtime';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export { a as BehaviorDescriptor, c as BehaviorHandle, d as BehaviorRef, f as BehaviorSystem, h as BehaviorSystemFactory, D as DefineBehaviorConfig, a5 as defineBehavior } from './behavior-system-HEt67el5.js';
2
- export { P as PhysicsBodyComponent, T as TransformComponent, c as createPhysicsBodyComponent, a as createTransformComponent, u as useBehavior } from './components-JZQoO2sU.js';
1
+ export { a as BehaviorDescriptor, c as BehaviorHandle, d as BehaviorRef, f as BehaviorSystem, h as BehaviorSystemFactory, D as DefineBehaviorConfig, a5 as defineBehavior } from './behavior-system-DkFAwLb_.js';
2
+ export { P as PhysicsBodyComponent, T as TransformComponent, c as createPhysicsBodyComponent, a as createTransformComponent, u as useBehavior } from './components--RTwuT4S.js';
3
3
  export { T as ThrusterInputComponent, a as ThrusterMovementComponent, b as ThrusterStateComponent, c as createThrusterInputComponent, d as createThrusterMovementComponent, e as createThrusterStateComponent } from './components-B29WHGQN.js';
4
4
  export { PlayerInput, ThrusterBehavior, ThrusterBehaviorOptions, ThrusterEntity, ThrusterEvent, ThrusterFSM, ThrusterFSMContext, ThrusterState } from './thruster.js';
5
5
  export { T as TopDownMovementComponent, a as TopDownMovementInputComponent, b as TopDownMovementStateComponent, c as createTopDownMovementComponent, d as createTopDownMovementInputComponent, e as createTopDownMovementStateComponent } from './components-XCpL6IYt.js';
@@ -37,7 +37,7 @@ import 'typescript-fsm';
37
37
  import './vector-DjhLUrak.js';
38
38
  import './entity-types-DhfsZbSK.js';
39
39
  import './first-person-perspective-BxFHgFln.js';
40
- import './moveable-BdFmI3s1.js';
40
+ import './moveable-CFOHmblC.js';
41
41
  import 'three/webgpu';
42
42
 
43
43
  /**
package/dist/index.js CHANGED
@@ -15,7 +15,7 @@ import {
15
15
  ScreenWrapEvent,
16
16
  ScreenWrapFSM,
17
17
  ScreenWrapState
18
- } from "./chunk-2PAHQZZD.js";
18
+ } from "./chunk-MUBU2DIB.js";
19
19
  import {
20
20
  Shooter2DBehavior,
21
21
  createShooter2DStateComponent
@@ -1,5 +1,5 @@
1
1
  import { S as SyncStateMachine } from './sync-state-machine-CZyspBpj.js';
2
- import { a as BehaviorDescriptor, Z as TransformState } from './behavior-system-HEt67el5.js';
2
+ import { a as BehaviorDescriptor, Z as TransformState } from './behavior-system-DkFAwLb_.js';
3
3
  import 'typescript-fsm';
4
4
  import '@zylem/runtime';
5
5
 
@@ -1,7 +1,7 @@
1
1
  import { c as JumpState3D, J as JumpConfig3D, b as JumpInput3D } from './components--hjBMTnz.js';
2
2
  export { a as JumpContext3D, V as Vec3Like, d as createJumpConfig3D, e as createJumpInput3D, f as createJumpState3D } from './components--hjBMTnz.js';
3
3
  import { S as SyncStateMachine } from './sync-state-machine-CZyspBpj.js';
4
- import { a as BehaviorDescriptor, Z as TransformState } from './behavior-system-HEt67el5.js';
4
+ import { a as BehaviorDescriptor, Z as TransformState } from './behavior-system-DkFAwLb_.js';
5
5
  import 'typescript-fsm';
6
6
  import '@zylem/runtime';
7
7
 
@@ -1,5 +1,5 @@
1
1
  import { Vector3 } from 'three';
2
- import { Z as TransformState } from './behavior-system-HEt67el5.js';
2
+ import { Z as TransformState } from './behavior-system-DkFAwLb_.js';
3
3
 
4
4
  /** Plain `{ x, y, z }` vector returned by pose/velocity reads. */
5
5
  interface Vector {
@@ -1,4 +1,4 @@
1
- import { a as BehaviorDescriptor } from './behavior-system-HEt67el5.js';
1
+ import { a as BehaviorDescriptor } from './behavior-system-DkFAwLb_.js';
2
2
  import { i as Vec3Input } from './vector-DjhLUrak.js';
3
3
  import { h as ParticlePresetMaterialOptions, P as ParticleEffectDefinition, C as spark, o as ember, p as flamelet, l as blaze, A as smolder, t as mist, E as spray, D as splash, n as drizzle, H as torrent, I as vapor, z as smoke, q as haze, w as plume, s as miasma, B as spark$1, j as arc, G as surge, y as pulse, F as storm, k as arcane, r as holy, m as corrupted, u as nature, J as voidMagic, x as psychic, i as Particles } from './spark-C4Tp-52_.js';
4
4
  export { a as ParticleMagicAgency, b as ParticleMagicAlignment, c as ParticleMagicModifierInput, d as ParticleMagicModifierOptions, e as ParticleMagicOrder, f as ParticleMagicRealityEffect, g as ParticleMagicTemperament, S as SemanticParticlePresetOptions, v as particleEffect } from './spark-C4Tp-52_.js';
@@ -1,5 +1,5 @@
1
1
  import { S as SyncStateMachine } from './sync-state-machine-CZyspBpj.js';
2
- import { a as BehaviorDescriptor } from './behavior-system-HEt67el5.js';
2
+ import { a as BehaviorDescriptor } from './behavior-system-DkFAwLb_.js';
3
3
  import 'typescript-fsm';
4
4
  import '@zylem/runtime';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { S as SyncStateMachine } from './sync-state-machine-CZyspBpj.js';
2
- import { a as BehaviorDescriptor } from './behavior-system-HEt67el5.js';
2
+ import { a as BehaviorDescriptor } from './behavior-system-DkFAwLb_.js';
3
3
  import 'typescript-fsm';
4
4
  import '@zylem/runtime';
5
5
 
@@ -1,6 +1,6 @@
1
1
  import { B as BaseEntityInterface } from './entity-types-DhfsZbSK.js';
2
2
  import { S as SyncStateMachine } from './sync-state-machine-CZyspBpj.js';
3
- import { a as BehaviorDescriptor } from './behavior-system-HEt67el5.js';
3
+ import { a as BehaviorDescriptor } from './behavior-system-DkFAwLb_.js';
4
4
  import 'three';
5
5
  import 'typescript-fsm';
6
6
  import '@zylem/runtime';
@@ -1,6 +1,6 @@
1
1
  import { S as SyncStateMachine } from './sync-state-machine-CZyspBpj.js';
2
2
  import { B as BaseEntityInterface } from './entity-types-DhfsZbSK.js';
3
- import { a as BehaviorDescriptor } from './behavior-system-HEt67el5.js';
3
+ import { a as BehaviorDescriptor } from './behavior-system-DkFAwLb_.js';
4
4
  import 'typescript-fsm';
5
5
  import 'three';
6
6
  import '@zylem/runtime';
@@ -1,4 +1,4 @@
1
- import { a as BehaviorDescriptor, d as BehaviorRef } from './behavior-system-HEt67el5.js';
1
+ import { a as BehaviorDescriptor, d as BehaviorRef } from './behavior-system-DkFAwLb_.js';
2
2
  import '@zylem/runtime';
3
3
 
4
4
  interface RuntimeDynamicCircleBody2DOptions {
@@ -1,4 +1,4 @@
1
- import { a as BehaviorDescriptor, G as GameEntity } from './behavior-system-HEt67el5.js';
1
+ import { a as BehaviorDescriptor, G as GameEntity } from './behavior-system-DkFAwLb_.js';
2
2
  import '@zylem/runtime';
3
3
 
4
4
  interface ScreenVisibilitySnapshot {
@@ -1,4 +1,4 @@
1
- import { a as BehaviorDescriptor } from './behavior-system-HEt67el5.js';
1
+ import { a as BehaviorDescriptor } from './behavior-system-DkFAwLb_.js';
2
2
  import { S as SyncStateMachine } from './sync-state-machine-CZyspBpj.js';
3
3
  import '@zylem/runtime';
4
4
  import 'typescript-fsm';
@@ -3,7 +3,7 @@ import {
3
3
  ScreenWrapEvent,
4
4
  ScreenWrapFSM,
5
5
  ScreenWrapState
6
- } from "./chunk-2PAHQZZD.js";
6
+ } from "./chunk-MUBU2DIB.js";
7
7
  import "./chunk-OPZ2LVS2.js";
8
8
  import "./chunk-AS3HR7AS.js";
9
9
  import "./chunk-EZNCCO4L.js";
@@ -1,4 +1,4 @@
1
- import { a as BehaviorDescriptor } from './behavior-system-HEt67el5.js';
1
+ import { a as BehaviorDescriptor } from './behavior-system-DkFAwLb_.js';
2
2
  import { i as Vec3Input } from './vector-DjhLUrak.js';
3
3
  import '@zylem/runtime';
4
4
  import 'three';
@@ -1,7 +1,7 @@
1
1
  import { T as ThrusterInputComponent, a as ThrusterMovementComponent } from './components-B29WHGQN.js';
2
2
  export { b as ThrusterStateComponent, c as createThrusterInputComponent, d as createThrusterMovementComponent, e as createThrusterStateComponent } from './components-B29WHGQN.js';
3
3
  import { S as SyncStateMachine } from './sync-state-machine-CZyspBpj.js';
4
- import { a as BehaviorDescriptor } from './behavior-system-HEt67el5.js';
4
+ import { a as BehaviorDescriptor } from './behavior-system-DkFAwLb_.js';
5
5
  import 'typescript-fsm';
6
6
  import '@zylem/runtime';
7
7
 
@@ -1,6 +1,6 @@
1
1
  import { T as TopDownMovementComponent, a as TopDownMovementInputComponent, b as TopDownMovementStateComponent } from './components-XCpL6IYt.js';
2
2
  export { c as createTopDownMovementComponent, d as createTopDownMovementInputComponent, e as createTopDownMovementStateComponent } from './components-XCpL6IYt.js';
3
- import { a as BehaviorDescriptor } from './behavior-system-HEt67el5.js';
3
+ import { a as BehaviorDescriptor } from './behavior-system-DkFAwLb_.js';
4
4
  import '@zylem/runtime';
5
5
 
6
6
  /**
@@ -1,4 +1,4 @@
1
- import { a as BehaviorDescriptor } from './behavior-system-HEt67el5.js';
1
+ import { a as BehaviorDescriptor } from './behavior-system-DkFAwLb_.js';
2
2
  import { S as SyncStateMachine } from './sync-state-machine-CZyspBpj.js';
3
3
  import '@zylem/runtime';
4
4
  import 'typescript-fsm';
@@ -1,4 +1,4 @@
1
- import { a as BehaviorDescriptor } from './behavior-system-HEt67el5.js';
1
+ import { a as BehaviorDescriptor } from './behavior-system-DkFAwLb_.js';
2
2
  import { S as SyncStateMachine } from './sync-state-machine-CZyspBpj.js';
3
3
  import '@zylem/runtime';
4
4
  import 'typescript-fsm';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zylem/behaviors",
3
- "version": "0.5.8",
3
+ "version": "0.5.11",
4
4
  "type": "module",
5
5
  "description": "Tree-shakable Zylem behavior descriptors, systems, coordinators, and runtime-agnostic behavior helpers.",
6
6
  "license": "MIT",
@@ -128,7 +128,6 @@
128
128
  "./package.json": "./package.json"
129
129
  },
130
130
  "scripts": {
131
- "zylem": "node --experimental-strip-types ./scripts/zylem-runner.ts",
132
131
  "build": "tsup",
133
132
  "dev": "tsup --watch",
134
133
  "typecheck": "tsc --noEmit",
@@ -137,7 +136,7 @@
137
136
  },
138
137
  "dependencies": {
139
138
  "@dgreenheck/three-pinata": "^2.0.1",
140
- "@zylem/runtime": "^0.2.5",
139
+ "@zylem/runtime": "link:../runtime",
141
140
  "comlink": "^4.4.2",
142
141
  "typescript-fsm": "^1.6.0",
143
142
  "valtio": "^2.1.7"