@zylem/game-lib 0.3.14
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.
- package/LICENSE +21 -0
- package/README.md +65 -0
- package/dist/.vite/manifest.json +8 -0
- package/dist/assets/bounce.wav +0 -0
- package/dist/assets/coin-sound.mp3 +0 -0
- package/dist/assets/zylem-logo.png +0 -0
- package/dist/lib/actions/behaviors/actions.d.ts +10 -0
- package/dist/lib/actions/behaviors/behavior.d.ts +5 -0
- package/dist/lib/actions/behaviors/boundaries/boundary.d.ts +36 -0
- package/dist/lib/actions/behaviors/character-controller.d.ts +5 -0
- package/dist/lib/actions/behaviors/debug/debug-collision.d.ts +5 -0
- package/dist/lib/actions/behaviors/debug/debug-update.d.ts +4 -0
- package/dist/lib/actions/behaviors/debug/debug.d.ts +9 -0
- package/dist/lib/actions/behaviors/index.d.ts +1 -0
- package/dist/lib/actions/behaviors/movement/movement-sequence-2d.d.ts +23 -0
- package/dist/lib/actions/behaviors/ricochet/ricochet-2d-collision.d.ts +10 -0
- package/dist/lib/actions/behaviors/ricochet/ricochet-2d-in-bounds.d.ts +11 -0
- package/dist/lib/actions/behaviors/ricochet/ricochet.d.ts +41 -0
- package/dist/lib/actions/behaviors/zylem-behavior.d.ts +1 -0
- package/dist/lib/actions/capabilities/moveable.d.ts +124 -0
- package/dist/lib/actions/capabilities/rotatable.d.ts +110 -0
- package/dist/lib/actions/capabilities/transformable.d.ts +6 -0
- package/dist/lib/actions/global-change.d.ts +12 -0
- package/dist/lib/camera/camera.d.ts +15 -0
- package/dist/lib/camera/fixed-2d.d.ts +31 -0
- package/dist/lib/camera/perspective.d.ts +8 -0
- package/dist/lib/camera/third-person.d.ts +39 -0
- package/dist/lib/camera/zylem-camera.d.ts +68 -0
- package/dist/lib/collision/collision-builder.d.ts +23 -0
- package/dist/lib/collision/collision-delegate.d.ts +11 -0
- package/dist/lib/collision/collision-group.d.ts +27 -0
- package/dist/lib/collision/collision-mask.d.ts +17 -0
- package/dist/lib/collision/collision.d.ts +27 -0
- package/dist/lib/collision/physics.d.ts +4 -0
- package/dist/lib/collision/utils.d.ts +14 -0
- package/dist/lib/collision/world.d.ts +22 -0
- package/dist/lib/core/asset-manager.d.ts +1 -0
- package/dist/lib/core/base-node-life-cycle.d.ts +53 -0
- package/dist/lib/core/base-node.d.ts +32 -0
- package/dist/lib/core/entity-asset-loader.d.ts +29 -0
- package/dist/lib/core/errors.d.ts +4 -0
- package/dist/lib/core/flags.d.ts +2 -0
- package/dist/lib/core/game-canvas.d.ts +4 -0
- package/dist/lib/core/index.d.ts +4 -0
- package/dist/lib/core/lazy-loader.d.ts +81 -0
- package/dist/lib/core/lifecycle-base.d.ts +16 -0
- package/dist/lib/core/preset-shader.d.ts +10 -0
- package/dist/lib/core/three-addons/Timer.d.ts +106 -0
- package/dist/lib/core/utility.d.ts +15 -0
- package/dist/lib/core/vector.d.ts +3 -0
- package/dist/lib/core/vessel.d.ts +11 -0
- package/dist/lib/debug/console/console-state.d.ts +19 -0
- package/dist/lib/debug/console/console-store.d.ts +5 -0
- package/dist/lib/debug/debug-state.d.ts +43 -0
- package/dist/lib/debug/debug-store.d.ts +14 -0
- package/dist/lib/debug/state-based-debug-loader.d.ts +7 -0
- package/dist/lib/device/desktop.d.ts +1 -0
- package/dist/lib/device/mobile.d.ts +1 -0
- package/dist/lib/device/tablet.d.ts +1 -0
- package/dist/lib/entities/actor.d.ts +57 -0
- package/dist/lib/entities/box.d.ts +26 -0
- package/dist/lib/entities/builder.d.ts +27 -0
- package/dist/lib/entities/create.d.ts +14 -0
- package/dist/lib/entities/delegates/animation.d.ts +32 -0
- package/dist/lib/entities/delegates/debug.d.ts +37 -0
- package/dist/lib/entities/delegates/loader.d.ts +11 -0
- package/dist/lib/entities/destroy.d.ts +3 -0
- package/dist/lib/entities/entity.d.ts +100 -0
- package/dist/lib/entities/index.d.ts +11 -0
- package/dist/lib/entities/object.d.ts +1 -0
- package/dist/lib/entities/plane.d.ts +35 -0
- package/dist/lib/entities/rect.d.ts +62 -0
- package/dist/lib/entities/sphere.d.ts +28 -0
- package/dist/lib/entities/sprite.d.ts +52 -0
- package/dist/lib/entities/text.d.ts +41 -0
- package/dist/lib/entities/zone.d.ts +53 -0
- package/dist/lib/game/game-interfaces.d.ts +28 -0
- package/dist/lib/game/game-state.d.ts +10 -0
- package/dist/lib/game/game.d.ts +41 -0
- package/dist/lib/game/zylem-game.d.ts +44 -0
- package/dist/lib/graphics/geometries/XZPlaneGeometry.d.ts +7 -0
- package/dist/lib/graphics/material.d.ts +28 -0
- package/dist/lib/graphics/mesh.d.ts +18 -0
- package/dist/lib/graphics/render-pass.d.ts +16 -0
- package/dist/lib/graphics/zylem-scene.d.ts +49 -0
- package/dist/lib/input/gamepad-provider.d.ts +13 -0
- package/dist/lib/input/input-manager.d.ts +14 -0
- package/dist/lib/input/input-provider.d.ts +6 -0
- package/dist/lib/input/input.d.ts +51 -0
- package/dist/lib/input/keyboard-provider.d.ts +20 -0
- package/dist/lib/interfaces/entity.d.ts +31 -0
- package/dist/lib/interfaces/game.d.ts +19 -0
- package/dist/lib/sounds/index.d.ts +2 -0
- package/dist/lib/sounds/ping-pong-sound.d.ts +4 -0
- package/dist/lib/sounds/ricochet-sound.d.ts +4 -0
- package/dist/lib/stage/debug-entity-cursor.d.ts +23 -0
- package/dist/lib/stage/entity-spawner.d.ts +8 -0
- package/dist/lib/stage/stage-debug-delegate.d.ts +25 -0
- package/dist/lib/stage/stage-state.d.ts +12 -0
- package/dist/lib/stage/stage.d.ts +33 -0
- package/dist/lib/stage/zylem-stage.d.ts +127 -0
- package/dist/lib/systems/test-system.d.ts +1 -0
- package/dist/lib/systems/transformable.system.d.ts +24 -0
- package/dist/lib/types/entity-types.d.ts +38 -0
- package/dist/lib/types/index.d.ts +2 -0
- package/dist/lib/types/stage-types.d.ts +34 -0
- package/dist/lib/ui/Debug.d.ts +1 -0
- package/dist/lib/ui/console/Console.d.ts +6 -0
- package/dist/lib/ui/debug-panel/AccordionMenu.d.ts +6 -0
- package/dist/lib/ui/debug-panel/Menu.d.ts +5 -0
- package/dist/lib/ui/debug-panel/sections/EntitiesSection.d.ts +11 -0
- package/dist/lib/ui/debug-panel/sections/GameSection.d.ts +2 -0
- package/dist/lib/ui/debug-panel/sections/StagesSection.d.ts +2 -0
- package/dist/lib/ui/debug-panel/sections/all.d.ts +3 -0
- package/dist/lib/ui/toolbar/Toolbar.d.ts +5 -0
- package/dist/main.cjs +3980 -0
- package/dist/main.d.ts +40 -0
- package/dist/main.js +35583 -0
- package/dist/tests/collision/collision.spec.d.ts +1 -0
- package/dist/tests/core/game.spec.d.ts +1 -0
- package/dist/tests/core/stage.spec.d.ts +1 -0
- package/dist/tests/core/vessel.spec.d.ts +1 -0
- package/package.json +127 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Color, Vector3 } from 'three';
|
|
2
|
+
import { ZylemWorld } from '../collision/world';
|
|
3
|
+
import { ZylemScene } from '../graphics/zylem-scene';
|
|
4
|
+
import { Conditions } from '../interfaces/game';
|
|
5
|
+
import { GameEntityInterface } from '../types/entity-types';
|
|
6
|
+
import { SetupContext, UpdateContext, DestroyContext } from '../core/base-node-life-cycle';
|
|
7
|
+
import { LifeCycleBase } from '../core/lifecycle-base';
|
|
8
|
+
import { BaseNode } from '../core/base-node';
|
|
9
|
+
import { Stage } from './stage';
|
|
10
|
+
import { ZylemCamera } from '../camera/zylem-camera';
|
|
11
|
+
import { CameraWrapper } from '../camera/camera';
|
|
12
|
+
import { StageDebugDelegate } from './stage-debug-delegate';
|
|
13
|
+
import { BaseEntityInterface } from '../types/entity-types';
|
|
14
|
+
export interface ZylemStageConfig {
|
|
15
|
+
inputs: Record<string, string[]>;
|
|
16
|
+
backgroundColor: Color;
|
|
17
|
+
backgroundImage: string | null;
|
|
18
|
+
gravity: Vector3;
|
|
19
|
+
variables: Record<string, any>;
|
|
20
|
+
conditions?: Conditions<any>[];
|
|
21
|
+
stageRef?: Stage;
|
|
22
|
+
}
|
|
23
|
+
type NodeLike = {
|
|
24
|
+
create: Function;
|
|
25
|
+
};
|
|
26
|
+
type StageEntityInput = NodeLike | Promise<any> | (() => NodeLike | Promise<any>);
|
|
27
|
+
export type StageOptions = Array<Partial<ZylemStageConfig> | CameraWrapper | StageEntityInput>;
|
|
28
|
+
export type StageState = ZylemStageConfig & {
|
|
29
|
+
entities: GameEntityInterface[];
|
|
30
|
+
};
|
|
31
|
+
export declare const STAGE_TYPE = "Stage";
|
|
32
|
+
/**
|
|
33
|
+
* ZylemStage orchestrates scene, physics world, entities, and lifecycle.
|
|
34
|
+
*
|
|
35
|
+
* Responsibilities:
|
|
36
|
+
* - Manage stage configuration (background, inputs, gravity, variables)
|
|
37
|
+
* - Initialize and own `ZylemScene` and `ZylemWorld`
|
|
38
|
+
* - Spawn, track, and remove entities; emit entity-added events
|
|
39
|
+
* - Drive per-frame updates and transform system
|
|
40
|
+
*/
|
|
41
|
+
export declare class ZylemStage extends LifeCycleBase<ZylemStage> {
|
|
42
|
+
type: string;
|
|
43
|
+
state: StageState;
|
|
44
|
+
gravity: Vector3;
|
|
45
|
+
world: ZylemWorld | null;
|
|
46
|
+
scene: ZylemScene | null;
|
|
47
|
+
conditions: Conditions<any>[];
|
|
48
|
+
children: Array<BaseNode>;
|
|
49
|
+
_childrenMap: Map<number, BaseNode>;
|
|
50
|
+
_removalMap: Map<number, BaseNode>;
|
|
51
|
+
private pendingEntities;
|
|
52
|
+
private pendingPromises;
|
|
53
|
+
private isLoaded;
|
|
54
|
+
_debugMap: Map<string, BaseNode>;
|
|
55
|
+
private entityAddedHandlers;
|
|
56
|
+
ecs: import("bitecs").IWorld;
|
|
57
|
+
testSystem: any;
|
|
58
|
+
transformSystem: any;
|
|
59
|
+
debugDelegate: StageDebugDelegate | null;
|
|
60
|
+
uuid: string;
|
|
61
|
+
wrapperRef: Stage | null;
|
|
62
|
+
camera?: CameraWrapper;
|
|
63
|
+
cameraRef?: ZylemCamera | null;
|
|
64
|
+
/**
|
|
65
|
+
* Create a new stage.
|
|
66
|
+
* @param options Stage options: partial config, camera, and initial entities or factories
|
|
67
|
+
*/
|
|
68
|
+
constructor(options?: StageOptions);
|
|
69
|
+
private parseOptions;
|
|
70
|
+
private isZylemStageConfig;
|
|
71
|
+
private isBaseNode;
|
|
72
|
+
private isCameraWrapper;
|
|
73
|
+
private isEntityInput;
|
|
74
|
+
private isThenable;
|
|
75
|
+
private handleEntityImmediatelyOrQueue;
|
|
76
|
+
private handlePromiseWithSpawnOnResolve;
|
|
77
|
+
private saveState;
|
|
78
|
+
private setState;
|
|
79
|
+
/**
|
|
80
|
+
* Load and initialize the stage's scene and world.
|
|
81
|
+
* @param id DOM element id for the renderer container
|
|
82
|
+
* @param camera Optional camera override
|
|
83
|
+
*/
|
|
84
|
+
load(id: string, camera?: ZylemCamera | null): Promise<void>;
|
|
85
|
+
private createDefaultCamera;
|
|
86
|
+
protected _setup(params: SetupContext<ZylemStage>): void;
|
|
87
|
+
protected _update(params: UpdateContext<ZylemStage>): void;
|
|
88
|
+
/** Update debug overlays and helpers if enabled. */
|
|
89
|
+
debugUpdate(): void;
|
|
90
|
+
/** Cleanup owned resources when the stage is destroyed. */
|
|
91
|
+
protected _destroy(params: DestroyContext<ZylemStage>): void;
|
|
92
|
+
/**
|
|
93
|
+
* Create, register, and add an entity to the scene/world.
|
|
94
|
+
* Safe to call only after `load` when scene/world exist.
|
|
95
|
+
*/
|
|
96
|
+
spawnEntity(child: BaseNode): Promise<void>;
|
|
97
|
+
buildEntityState(child: BaseNode): Partial<BaseEntityInterface>;
|
|
98
|
+
/** Add the entity to internal maps and notify listeners. */
|
|
99
|
+
addEntityToStage(entity: BaseNode): void;
|
|
100
|
+
/**
|
|
101
|
+
* Subscribe to entity-added events.
|
|
102
|
+
* @param callback Invoked for each entity when added
|
|
103
|
+
* @param options.replayExisting If true and stage already loaded, replays existing entities
|
|
104
|
+
* @returns Unsubscribe function
|
|
105
|
+
*/
|
|
106
|
+
onEntityAdded(callback: (entity: BaseNode) => void, options?: {
|
|
107
|
+
replayExisting?: boolean;
|
|
108
|
+
}): () => void;
|
|
109
|
+
/**
|
|
110
|
+
* Remove an entity and its resources by its UUID.
|
|
111
|
+
* @returns true if removed, false if not found or stage not ready
|
|
112
|
+
*/
|
|
113
|
+
removeEntityByUuid(uuid: string): boolean;
|
|
114
|
+
/** Get an entity by its name; returns null if not found. */
|
|
115
|
+
getEntityByName(name: string): BaseNode<any, any> | null;
|
|
116
|
+
logMissingEntities(): void;
|
|
117
|
+
/** Resize renderer viewport. */
|
|
118
|
+
resize(width: number, height: number): void;
|
|
119
|
+
/**
|
|
120
|
+
* Enqueue items to be spawned. Items can be:
|
|
121
|
+
* - BaseNode instances (immediate or deferred until load)
|
|
122
|
+
* - Factory functions returning BaseNode or Promise<BaseNode>
|
|
123
|
+
* - Promises resolving to BaseNode
|
|
124
|
+
*/
|
|
125
|
+
enqueue(...items: StageEntityInput[]): void;
|
|
126
|
+
}
|
|
127
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { StageEntity } from '../interfaces/entity';
|
|
2
|
+
import RAPIER from '@dimforge/rapier3d-compat';
|
|
3
|
+
export type StageSystem = {
|
|
4
|
+
_childrenMap: Map<number, StageEntity & {
|
|
5
|
+
body: RAPIER.RigidBody;
|
|
6
|
+
}>;
|
|
7
|
+
};
|
|
8
|
+
export declare const position: import("bitecs").ComponentType<{
|
|
9
|
+
x: "f32";
|
|
10
|
+
y: "f32";
|
|
11
|
+
z: "f32";
|
|
12
|
+
}>;
|
|
13
|
+
export declare const rotation: import("bitecs").ComponentType<{
|
|
14
|
+
x: "f32";
|
|
15
|
+
y: "f32";
|
|
16
|
+
z: "f32";
|
|
17
|
+
w: "f32";
|
|
18
|
+
}>;
|
|
19
|
+
export declare const scale: import("bitecs").ComponentType<{
|
|
20
|
+
x: "f32";
|
|
21
|
+
y: "f32";
|
|
22
|
+
z: "f32";
|
|
23
|
+
}>;
|
|
24
|
+
export default function createTransformSystem(stage: StageSystem): import("bitecs").System<[], import("bitecs").IWorld>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Group } from 'three';
|
|
2
|
+
import { RigidBody, Collider } from '@dimforge/rapier3d-compat';
|
|
3
|
+
/**
|
|
4
|
+
* Base entity interface - shared across modules to prevent circular dependencies
|
|
5
|
+
*/
|
|
6
|
+
export interface BaseEntityInterface {
|
|
7
|
+
uuid: string;
|
|
8
|
+
name: string;
|
|
9
|
+
eid: number;
|
|
10
|
+
group: Group | null;
|
|
11
|
+
body: RigidBody | null;
|
|
12
|
+
collider: Collider | null;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Game entity interface - minimal interface to break circular dependencies
|
|
16
|
+
*/
|
|
17
|
+
export interface GameEntityInterface extends BaseEntityInterface {
|
|
18
|
+
type: string;
|
|
19
|
+
isStatic: boolean;
|
|
20
|
+
setPosition(x: number, y: number, z: number): void;
|
|
21
|
+
setRotation(x: number, y: number, z: number): void;
|
|
22
|
+
setScale(x: number, y: number, z: number): void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Stage entity interface - for entities that can be part of a stage
|
|
26
|
+
*/
|
|
27
|
+
export interface StageEntityInterface extends GameEntityInterface {
|
|
28
|
+
stageId?: string;
|
|
29
|
+
isActive: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Entity with collision capabilities
|
|
33
|
+
*/
|
|
34
|
+
export interface CollisionEntityInterface extends GameEntityInterface {
|
|
35
|
+
onCollision?: (other: GameEntityInterface) => void;
|
|
36
|
+
onEnter?: (other: GameEntityInterface) => void;
|
|
37
|
+
onExit?: (other: GameEntityInterface) => void;
|
|
38
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Color, Vector3 } from 'three';
|
|
2
|
+
import { BaseEntityInterface } from './entity-types';
|
|
3
|
+
/**
|
|
4
|
+
* Stage state interface - minimal to prevent circular dependencies
|
|
5
|
+
*/
|
|
6
|
+
export interface StageStateInterface {
|
|
7
|
+
backgroundColor: Color;
|
|
8
|
+
backgroundImage: string | null;
|
|
9
|
+
inputs: {
|
|
10
|
+
p1: string[];
|
|
11
|
+
p2: string[];
|
|
12
|
+
};
|
|
13
|
+
variables: Record<string, any>;
|
|
14
|
+
gravity: Vector3;
|
|
15
|
+
entities: Partial<BaseEntityInterface>[];
|
|
16
|
+
stageRef?: any;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Stage configuration interface
|
|
20
|
+
*/
|
|
21
|
+
export interface StageConfigInterface {
|
|
22
|
+
id?: string;
|
|
23
|
+
backgroundColor?: Color;
|
|
24
|
+
backgroundImage?: string;
|
|
25
|
+
gravity?: Vector3;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Minimal stage interface to break circular dependencies
|
|
29
|
+
*/
|
|
30
|
+
export interface StageInterface {
|
|
31
|
+
uuid: string;
|
|
32
|
+
children: any[];
|
|
33
|
+
state: StageStateInterface;
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './Debug.css';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Component } from 'solid-js';
|
|
2
|
+
import './EntitiesSection.css';
|
|
3
|
+
import { BaseEntityInterface } from '~/lib/types';
|
|
4
|
+
interface EntityRowProps {
|
|
5
|
+
entity: Partial<BaseEntityInterface>;
|
|
6
|
+
index: number;
|
|
7
|
+
hoveredUuid: string | null;
|
|
8
|
+
}
|
|
9
|
+
export declare const EntityRow: Component<EntityRowProps>;
|
|
10
|
+
export declare const EntitiesSection: Component;
|
|
11
|
+
export {};
|