@zylem/game-lib 0.6.0 → 0.6.2

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.
@@ -0,0 +1,26 @@
1
+ import { Group } from 'three';
2
+ import { RigidBody, Collider } from '@dimforge/rapier3d-compat';
3
+
4
+ /**
5
+ * Base entity interface - shared across modules to prevent circular dependencies
6
+ */
7
+ interface BaseEntityInterface {
8
+ uuid: string;
9
+ name: string;
10
+ eid: number;
11
+ group: Group | null | undefined;
12
+ body: RigidBody | null | undefined;
13
+ collider: Collider | null | undefined;
14
+ }
15
+ /**
16
+ * Game entity interface - minimal interface to break circular dependencies
17
+ */
18
+ interface GameEntityInterface extends BaseEntityInterface {
19
+ type: string;
20
+ isStatic: boolean;
21
+ setPosition(x: number, y: number, z: number): void;
22
+ setRotation(x: number, y: number, z: number): void;
23
+ setScale(x: number, y: number, z: number): void;
24
+ }
25
+
26
+ export type { BaseEntityInterface as B, GameEntityInterface as G };
package/dist/main.d.ts CHANGED
@@ -1,14 +1,13 @@
1
- import { G as Game } from './core-CZhozNRH.js';
2
- export { V as Vect3, Z as ZylemGameConfig, c as createGame, g as gameConfig, a as globalChange, b as globalChanges, d as variableChange, e as variableChanges, v as vessel } from './core-CZhozNRH.js';
3
- export { a as StageOptions, c as createStage } from './stage-types-CD21XoIU.js';
4
- import { S as StageBlueprint } from './blueprints-BOCc3Wve.js';
5
- export { e as entitySpawner } from './blueprints-BOCc3Wve.js';
6
- export { P as PerspectiveType, a as Perspectives, c as camera } from './camera-CpbDr4-V.js';
7
- export { A as ACTOR_TYPE, B as BOX_TYPE, P as PLANE_TYPE, R as RECT_TYPE, d as SPHERE_TYPE, S as SPRITE_TYPE, T as TEXT_TYPE, e as ZONE_TYPE, Z as ZylemBox, c as actor, b as box, p as plane, r as rect, s as sphere, a as sprite, t as text, z as zone } from './entities-BAxfJOkk.js';
8
- import { U as UpdateContext, B as BehaviorCallbackType, G as GameEntity } from './entity-COvRtFNG.js';
9
- export { a as Behavior, L as LoadingEvent, S as SetupContext } from './entity-COvRtFNG.js';
10
- export { boundary2d, ricochet2DCollision, ricochet2DInBounds } from './behaviors.js';
11
- import { M as MoveableEntity } from './moveable-B_vyA6cw.js';
1
+ import { G as Game } from './core-bO8TzV7u.js';
2
+ export { V as Vect3, Z as ZylemGameConfig, c as createGame, g as gameConfig, a as globalChange, b as globalChanges, d as variableChange, e as variableChanges, v as vessel } from './core-bO8TzV7u.js';
3
+ export { a as StageOptions, d as createDisk, c as createStage } from './stage-types-Bd-KtcYT.js';
4
+ import { S as StageBlueprint } from './blueprints-Cq3Ko6_G.js';
5
+ export { e as entitySpawner } from './blueprints-Cq3Ko6_G.js';
6
+ export { P as PerspectiveType, d as Perspectives, c as createCamera } from './camera-CeJPAgGg.js';
7
+ export { A as ACTOR_TYPE, B as BOX_TYPE, P as PLANE_TYPE, R as RECT_TYPE, a as SPHERE_TYPE, S as SPRITE_TYPE, T as TEXT_TYPE, g as ZONE_TYPE, e as ZylemBox, o as createActor, j as createBox, m as createPlane, q as createRect, k as createSphere, l as createSprite, p as createText, n as createZone } from './entities-DvByhMGU.js';
8
+ import { G as GameEntity, g as GameEntityOptions } from './world-C8tQ7Plj.js';
9
+ export { q as BehaviorDescriptor, s as BehaviorHandle, r as BehaviorRef, e as BehaviorSystem, f as BehaviorSystemFactory, t as DefineBehaviorConfig, o as EntityConfigPayload, k as EntityEvents, E as EventEmitterDelegate, j as GameEvents, l as GameLoadingPayload, L as LoadingEvent, a as SetupContext, n as StageConfigPayload, h as StageEvents, m as StateDispatchPayload, b as UpdateContext, i as ZylemEvents, Z as ZylemShaderObject, p as defineBehavior, z as zylemEventBus } from './world-C8tQ7Plj.js';
10
+ export { Behavior, BoundaryRicochetCoordinator, MovementSequence2DBehavior, MovementSequence2DCurrentStep, MovementSequence2DEvent, MovementSequence2DFSM, MovementSequence2DHandle, MovementSequence2DMovement, MovementSequence2DOptions, MovementSequence2DProgress, MovementSequence2DState, MovementSequence2DStep, PhysicsBodyComponent, PhysicsStepBehavior, PhysicsSyncBehavior, PlayerInput, Ricochet2DBehavior, Ricochet2DCollisionContext, Ricochet2DEvent, Ricochet2DFSM, Ricochet2DHandle, Ricochet2DOptions, Ricochet2DResult, Ricochet2DState, ScreenWrapBehavior, ScreenWrapEvent, ScreenWrapFSM, ScreenWrapOptions, ScreenWrapState, ThrusterBehavior, ThrusterBehaviorOptions, ThrusterEntity, ThrusterEvent, ThrusterFSM, ThrusterFSMContext, ThrusterInputComponent, ThrusterMovementBehavior, ThrusterMovementComponent, ThrusterState, ThrusterStateComponent, TransformComponent, WorldBoundary2DBehavior, WorldBoundary2DBounds, WorldBoundary2DEvent, WorldBoundary2DFSM, WorldBoundary2DHandle, WorldBoundary2DHit, WorldBoundary2DHits, WorldBoundary2DOptions, WorldBoundary2DPosition, WorldBoundary2DState, computeWorldBoundary2DHits, createPhysicsBodyComponent, createThrusterInputComponent, createThrusterMovementComponent, createThrusterStateComponent, createTransformComponent, hasAnyWorldBoundary2DHit, useBehavior } from './behaviors.js';
12
11
  export { m as makeMoveable, b as move, a as moveable, r as resetVelocity } from './moveable-B_vyA6cw.js';
13
12
  export { m as makeRotatable, a as makeTransformable, r as rotatable, b as rotateInDirection } from './transformable-CUhvyuYO.js';
14
13
  export { Howl } from 'howler';
@@ -18,8 +17,11 @@ import * as RAPIER from '@dimforge/rapier3d-compat';
18
17
  export { RAPIER };
19
18
  export { S as StageEntity } from './entity-Bq_eNEDI.js';
20
19
  import 'bitecs';
20
+ import './entity-types-DAu8sGJH.js';
21
21
  import '@sinclair/typebox';
22
22
  import 'three/examples/jsm/postprocessing/EffectComposer.js';
23
+ import 'mitt';
24
+ import 'typescript-fsm';
23
25
 
24
26
  declare const stageState: {
25
27
  previous: StageBlueprint | null;
@@ -37,8 +39,8 @@ declare const StageManager: {
37
39
  data?: {
38
40
  [x: string]: any;
39
41
  } | undefined;
40
- id: string;
41
42
  type: string;
43
+ id: string;
42
44
  }[];
43
45
  }>;
44
46
  registerStaticStage(id: string, blueprint: StageBlueprint): void;
@@ -50,26 +52,38 @@ declare const StageManager: {
50
52
  preloadNext(stageId: string, loadStaticStage?: (id: string) => Promise<StageBlueprint>): Promise<void>;
51
53
  };
52
54
 
53
- interface MovementSequence2DStep {
54
- name: string;
55
- moveX?: number;
56
- moveY?: number;
57
- timeInSeconds: number;
58
- }
59
- interface MovementSequence2DOptions {
60
- sequence: MovementSequence2DStep[];
61
- loop?: boolean;
62
- }
63
- type MovementSequence2DCallback = (current: MovementSequence2DStep, index: number, ctx: UpdateContext<MoveableEntity>) => void;
64
55
  /**
65
- * Behavior that sequences 2D movements over time.
66
- * Each step sets linear velocity via `moveXY` for a duration, then advances.
67
- * Defaults to looping when the end is reached.
56
+ * Factory interface for generating entity copies
68
57
  */
69
- declare function movementSequence2D(opts: MovementSequence2DOptions, onStep?: MovementSequence2DCallback): {
70
- type: BehaviorCallbackType;
71
- handler: (ctx: UpdateContext<MoveableEntity>) => void;
72
- };
58
+ interface TemplateFactory<E extends GameEntity<O>, O extends GameEntityOptions = GameEntityOptions> {
59
+ /** The template entity used for cloning */
60
+ readonly template: E;
61
+ /**
62
+ * Generate multiple copies of the template entity
63
+ * @param count Number of copies to generate
64
+ * @returns Array of new entity instances
65
+ */
66
+ generate(count: number): E[];
67
+ }
68
+ /**
69
+ * Create an entity factory from a template entity.
70
+ *
71
+ * @param template The entity to use as a template for cloning
72
+ * @returns Factory object with generate() method
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * const asteroidTemplate = createSprite({ images: [{ name: 'asteroid', file: asteroidImg }] });
77
+ * const asteroidFactory = createEntityFactory(asteroidTemplate);
78
+ * const asteroids = asteroidFactory.generate(10);
79
+ *
80
+ * asteroids.forEach((asteroid, i) => {
81
+ * asteroid.setPosition(Math.random() * 20 - 10, Math.random() * 15 - 7.5, 0);
82
+ * stage.add(asteroid);
83
+ * });
84
+ * ```
85
+ */
86
+ declare function createEntityFactory<E extends GameEntity<O>, O extends GameEntityOptions = GameEntityOptions>(template: E): TemplateFactory<E, O>;
73
87
 
74
88
  declare function destroy(entity: any, globals?: any): void;
75
89
 
@@ -193,6 +207,10 @@ declare class ZylemGameElement extends HTMLElement {
193
207
  private _state;
194
208
  private container;
195
209
  constructor();
210
+ /**
211
+ * Focus the game container for keyboard input
212
+ */
213
+ focus(): void;
196
214
  set game(game: Game<any>);
197
215
  get game(): Game<any> | null;
198
216
  set state(value: ZylemGameState);
@@ -208,4 +226,26 @@ declare class ZylemGameElement extends HTMLElement {
208
226
  disconnectedCallback(): void;
209
227
  }
210
228
 
211
- export { type DebugTools, Game, StageBlueprint, StageManager, UpdateContext, ZylemGameElement, type ZylemGameState, clearGlobalSubscriptions, createGlobal, createVariable, debugState, destroy, getGlobal, getGlobals, getVariable, movementSequence2D, onGlobalChange, onGlobalChanges, onVariableChange, onVariableChanges, pingPongBeep, ricochetSound, setDebugTool, setGlobal, setPaused, setVariable, stageState };
229
+ declare const fireShader: {
230
+ vertex: string;
231
+ fragment: string;
232
+ };
233
+
234
+ declare const starShader: {
235
+ vertex: string;
236
+ fragment: string;
237
+ };
238
+
239
+ declare const standardShader: {
240
+ vertex: string;
241
+ fragment: string;
242
+ };
243
+
244
+ declare const debugShader: {
245
+ vertex: string;
246
+ fragment: string;
247
+ };
248
+
249
+ declare const objectVertexShader = "\nuniform vec2 uvScale;\nvarying vec2 vUv;\n\nvoid main() {\n\tvUv = uv;\n\tvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n\tgl_Position = projectionMatrix * mvPosition;\n}\n";
250
+
251
+ export { type DebugTools, Game, StageBlueprint, StageManager, type TemplateFactory, ZylemGameElement, type ZylemGameState, clearGlobalSubscriptions, createEntityFactory, createGlobal, createVariable, debugShader, debugState, destroy, fireShader, getGlobal, getGlobals, getVariable, objectVertexShader, onGlobalChange, onGlobalChanges, onVariableChange, onVariableChanges, pingPongBeep, ricochetSound, setDebugTool, setGlobal, setPaused, setVariable, stageState, standardShader, starShader };