@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,68 @@
|
|
|
1
|
+
import { Vector2, Camera, Vector3, Object3D, WebGLRenderer, Scene } from 'three';
|
|
2
|
+
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
|
3
|
+
import { PerspectiveType } from './perspective';
|
|
4
|
+
import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer.js';
|
|
5
|
+
import { StageEntity } from '../interfaces/entity';
|
|
6
|
+
/**
|
|
7
|
+
* Interface for perspective-specific camera controllers
|
|
8
|
+
*/
|
|
9
|
+
export interface PerspectiveController {
|
|
10
|
+
setup(params: {
|
|
11
|
+
screenResolution: Vector2;
|
|
12
|
+
renderer: WebGLRenderer;
|
|
13
|
+
scene: Scene;
|
|
14
|
+
camera: ZylemCamera;
|
|
15
|
+
}): void;
|
|
16
|
+
update(delta: number): void;
|
|
17
|
+
resize(width: number, height: number): void;
|
|
18
|
+
}
|
|
19
|
+
export declare class ZylemCamera {
|
|
20
|
+
cameraRig: Object3D;
|
|
21
|
+
camera: Camera;
|
|
22
|
+
screenResolution: Vector2;
|
|
23
|
+
renderer: WebGLRenderer;
|
|
24
|
+
composer: EffectComposer;
|
|
25
|
+
_perspective: PerspectiveType;
|
|
26
|
+
orbitControls: OrbitControls | null;
|
|
27
|
+
target: StageEntity | null;
|
|
28
|
+
sceneRef: Scene | null;
|
|
29
|
+
frustumSize: number;
|
|
30
|
+
perspectiveController: PerspectiveController | null;
|
|
31
|
+
constructor(perspective: PerspectiveType, screenResolution: Vector2, frustumSize?: number);
|
|
32
|
+
/**
|
|
33
|
+
* Setup the camera with a scene
|
|
34
|
+
*/
|
|
35
|
+
setup(scene: Scene): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Update camera and render
|
|
38
|
+
*/
|
|
39
|
+
update(delta: number): void;
|
|
40
|
+
/**
|
|
41
|
+
* Dispose renderer, composer, controls, and detach from scene
|
|
42
|
+
*/
|
|
43
|
+
destroy(): void;
|
|
44
|
+
/**
|
|
45
|
+
* Resize camera and renderer
|
|
46
|
+
*/
|
|
47
|
+
resize(width: number, height: number): void;
|
|
48
|
+
/**
|
|
49
|
+
* Create camera based on perspective type
|
|
50
|
+
*/
|
|
51
|
+
private createCameraForPerspective;
|
|
52
|
+
/**
|
|
53
|
+
* Initialize perspective-specific controller
|
|
54
|
+
*/
|
|
55
|
+
private initializePerspectiveController;
|
|
56
|
+
private createThirdPersonCamera;
|
|
57
|
+
private createFirstPersonCamera;
|
|
58
|
+
private createIsometricCamera;
|
|
59
|
+
private createFlat2DCamera;
|
|
60
|
+
private createFixed2DCamera;
|
|
61
|
+
private moveCamera;
|
|
62
|
+
move(position: Vector3): void;
|
|
63
|
+
rotate(pitch: number, yaw: number, roll: number): void;
|
|
64
|
+
/**
|
|
65
|
+
* Get the DOM element for the renderer
|
|
66
|
+
*/
|
|
67
|
+
getDomElement(): HTMLCanvasElement;
|
|
68
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ColliderDesc, RigidBodyDesc } from "@dimforge/rapier3d-compat";
|
|
2
|
+
import { PhysicsOptions } from "./physics";
|
|
3
|
+
import { Vec3 } from "../core/vector";
|
|
4
|
+
import { CollisionOptions } from "./collision";
|
|
5
|
+
export declare function getOrCreateCollisionGroupId(type: string): number;
|
|
6
|
+
export declare function createCollisionFilter(allowedTypes: string[]): number;
|
|
7
|
+
export declare function setCollisionGroups(collider: ColliderDesc, entityType: string, allowedTypes: string[]): void;
|
|
8
|
+
export type ColliderFunction = () => ColliderDesc;
|
|
9
|
+
export type RigidBodyFunction = ({ isDynamicBody }: {
|
|
10
|
+
isDynamicBody: boolean;
|
|
11
|
+
}) => RigidBodyDesc;
|
|
12
|
+
export declare class CollisionBuilder {
|
|
13
|
+
static: boolean;
|
|
14
|
+
sensor: boolean;
|
|
15
|
+
gravity: Vec3;
|
|
16
|
+
build(options: Partial<CollisionOptions>): [RigidBodyDesc, ColliderDesc];
|
|
17
|
+
withCollision(collisionOptions: Partial<CollisionOptions>): this;
|
|
18
|
+
withPhysics(physicsOptions: Partial<PhysicsOptions>): this;
|
|
19
|
+
collider(options: CollisionOptions): ColliderDesc;
|
|
20
|
+
bodyDesc({ isDynamicBody }: {
|
|
21
|
+
isDynamicBody?: boolean | undefined;
|
|
22
|
+
}): RigidBodyDesc;
|
|
23
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function isCollisionHandlerDelegate(obj: any): obj is CollisionHandlerDelegate;
|
|
2
|
+
export interface CollisionHandlerDelegate {
|
|
3
|
+
handlePostCollision(params: any): boolean;
|
|
4
|
+
handleIntersectionEvent(params: any): void;
|
|
5
|
+
}
|
|
6
|
+
export declare class CollisionHandler {
|
|
7
|
+
entityReference: CollisionHandlerDelegate;
|
|
8
|
+
constructor(entity: CollisionHandlerDelegate);
|
|
9
|
+
handlePostCollision(params: any): boolean;
|
|
10
|
+
handleIntersectionEvent(params: any): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { GameEntity } from '../entities/entity';
|
|
2
|
+
import { CollisionContext } from '../entities/entity';
|
|
3
|
+
/**
|
|
4
|
+
* Configure an entity's collision groups to only collide with the specified types.
|
|
5
|
+
* This uses Rapier's built-in collision group system for efficient filtering.
|
|
6
|
+
*
|
|
7
|
+
* @param entity - The entity to configure collision groups for
|
|
8
|
+
* @param allowedTypes - Array of collision types this entity should collide with
|
|
9
|
+
* @returns The entity for method chaining
|
|
10
|
+
*/
|
|
11
|
+
export declare function collisionGroup<T extends GameEntity<any>>(entity: T, allowedTypes: string[]): T;
|
|
12
|
+
/**
|
|
13
|
+
* Legacy type definitions for backward compatibility
|
|
14
|
+
* @deprecated Use the new collisionGroup function instead
|
|
15
|
+
*/
|
|
16
|
+
export type CollisionCallback = (ctx: CollisionContext<any, any>) => void;
|
|
17
|
+
export type CollisionGroupWrapper = (...actions: CollisionCallback[]) => CollisionCallback;
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated This function is deprecated. Use the new collisionGroup function instead.
|
|
20
|
+
*/
|
|
21
|
+
export declare function legacyCollisionGroup(...args: (string | GameEntity<any> | {
|
|
22
|
+
includeSameType?: boolean;
|
|
23
|
+
})[]): CollisionGroupWrapper;
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated This function is deprecated.
|
|
26
|
+
*/
|
|
27
|
+
export declare function combineCollisionGroups(...wrappers: CollisionGroupWrapper[]): CollisionGroupWrapper;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { GameEntity } from "../entities/entity";
|
|
2
|
+
/**
|
|
3
|
+
* A branded bitmask representing a set of collision types.
|
|
4
|
+
* Construct with {@link buildCollisionMask}.
|
|
5
|
+
*/
|
|
6
|
+
export type CollisionMask = number & {
|
|
7
|
+
readonly __brand: "CollisionMask";
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Builds a bitmask from one or more collision type names.
|
|
11
|
+
* The type names should match the values set on `GameEntity.collisionType`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function buildCollisionMask(...types: string[]): CollisionMask;
|
|
14
|
+
/**
|
|
15
|
+
* Tests whether the given entity's collision type is included in the mask.
|
|
16
|
+
*/
|
|
17
|
+
export declare function entityMatchesMask(entity: GameEntity<any>, mask: CollisionMask): boolean;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { RigidBodyDesc } from '@dimforge/rapier3d-compat';
|
|
2
|
+
import { Vector3 } from 'three';
|
|
3
|
+
export declare class BaseCollision {
|
|
4
|
+
static: boolean;
|
|
5
|
+
isSensor: boolean;
|
|
6
|
+
bodyDescription: RigidBodyDesc;
|
|
7
|
+
constructor({ isDynamicBody }: {
|
|
8
|
+
isDynamicBody?: boolean | undefined;
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
export declare const CollisionComponent: import("bitecs").ComponentType<{
|
|
12
|
+
static: "i8";
|
|
13
|
+
isSensor: "i8";
|
|
14
|
+
bodyDescription: "i8";
|
|
15
|
+
}>;
|
|
16
|
+
export declare const CollisionDebugComponent: import("bitecs").ComponentType<{
|
|
17
|
+
active: "i8";
|
|
18
|
+
color: "f32";
|
|
19
|
+
}>;
|
|
20
|
+
export interface CollisionOptions {
|
|
21
|
+
static?: boolean;
|
|
22
|
+
sensor?: boolean;
|
|
23
|
+
size?: Vector3;
|
|
24
|
+
position?: Vector3;
|
|
25
|
+
collisionType?: string;
|
|
26
|
+
collisionFilter?: string[];
|
|
27
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { GameEntity } from "../entities/entity";
|
|
2
|
+
import type { CollisionMask } from "./collision-mask";
|
|
3
|
+
export type NameSelector = string | string[] | RegExp;
|
|
4
|
+
export type CollisionSelector = {
|
|
5
|
+
name: NameSelector;
|
|
6
|
+
} | {
|
|
7
|
+
mask: CollisionMask | RegExp;
|
|
8
|
+
} | {
|
|
9
|
+
test: (other: GameEntity<any>) => boolean;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Returns true if the `other` entity matches the provided selector.
|
|
13
|
+
*/
|
|
14
|
+
export declare function matchesCollisionSelector(other: GameEntity<any>, selector?: CollisionSelector): boolean;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Vector3 } from 'three';
|
|
2
|
+
import RAPIER, { World } from '@dimforge/rapier3d-compat';
|
|
3
|
+
import { Entity } from '../interfaces/entity';
|
|
4
|
+
import { UpdateContext } from '../core/base-node-life-cycle';
|
|
5
|
+
import { GameEntity } from '../entities/entity';
|
|
6
|
+
export declare class ZylemWorld implements Entity<ZylemWorld> {
|
|
7
|
+
type: string;
|
|
8
|
+
world: World;
|
|
9
|
+
collisionMap: Map<string, GameEntity<any>>;
|
|
10
|
+
collisionBehaviorMap: Map<string, GameEntity<any>>;
|
|
11
|
+
_removalMap: Map<string, GameEntity<any>>;
|
|
12
|
+
static loadPhysics(gravity: Vector3): Promise<RAPIER.World>;
|
|
13
|
+
constructor(world: World);
|
|
14
|
+
addEntity(entity: any): void;
|
|
15
|
+
setForRemoval(entity: any): void;
|
|
16
|
+
destroyEntity(entity: GameEntity<any>): void;
|
|
17
|
+
setup(): void;
|
|
18
|
+
update(params: UpdateContext<any>): void;
|
|
19
|
+
updatePostCollisionBehaviors(delta: number): void;
|
|
20
|
+
updateColliders(delta: number): void;
|
|
21
|
+
destroy(): void;
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Vector3 } from 'three';
|
|
2
|
+
import { Inputs } from '../input/input';
|
|
3
|
+
export interface IGame<TGlobals extends Record<string, unknown> = any> {
|
|
4
|
+
start: () => Promise<this>;
|
|
5
|
+
nextStage: () => Promise<void>;
|
|
6
|
+
previousStage: () => Promise<void>;
|
|
7
|
+
reset: () => Promise<void>;
|
|
8
|
+
pause: () => Promise<void>;
|
|
9
|
+
resume: () => Promise<void>;
|
|
10
|
+
end: () => Promise<void>;
|
|
11
|
+
goToStage: () => void;
|
|
12
|
+
getGlobal: <K extends keyof TGlobals>(key: K) => TGlobals[K];
|
|
13
|
+
setGlobal: <K extends keyof TGlobals>(key: K, value: TGlobals[K]) => void;
|
|
14
|
+
}
|
|
15
|
+
export interface IStage {
|
|
16
|
+
onUpdate: (callback: UpdateFunction<IStage>) => void;
|
|
17
|
+
onSetup: (callback: SetupFunction<IStage>) => void;
|
|
18
|
+
onDestroy: (callback: DestroyFunction<IStage>) => void;
|
|
19
|
+
}
|
|
20
|
+
export interface ICamera {
|
|
21
|
+
move: (position: Vector3) => void;
|
|
22
|
+
rotate: (pitch: number, yaw: number, roll: number) => void;
|
|
23
|
+
}
|
|
24
|
+
export interface SetupContext<T, TGlobals extends Record<string, unknown> = any> {
|
|
25
|
+
me: T;
|
|
26
|
+
globals: TGlobals;
|
|
27
|
+
inputs?: Inputs;
|
|
28
|
+
camera?: ICamera;
|
|
29
|
+
stage?: IStage;
|
|
30
|
+
game?: IGame<TGlobals>;
|
|
31
|
+
}
|
|
32
|
+
export interface SetupFunction<T, TGlobals extends Record<string, unknown> = any> {
|
|
33
|
+
(context: SetupContext<T, TGlobals>): void;
|
|
34
|
+
}
|
|
35
|
+
export type UpdateContext<T, TGlobals extends Record<string, unknown> = any> = {
|
|
36
|
+
me: T;
|
|
37
|
+
delta: number;
|
|
38
|
+
inputs: Inputs;
|
|
39
|
+
globals: TGlobals;
|
|
40
|
+
camera: ICamera;
|
|
41
|
+
stage?: IStage;
|
|
42
|
+
game?: IGame<TGlobals>;
|
|
43
|
+
};
|
|
44
|
+
export interface UpdateFunction<T, TGlobals extends Record<string, unknown> = any> {
|
|
45
|
+
(context: UpdateContext<T, TGlobals>): void;
|
|
46
|
+
}
|
|
47
|
+
export interface DestroyContext<T, TGlobals extends Record<string, unknown> = any> {
|
|
48
|
+
me: T;
|
|
49
|
+
globals: TGlobals;
|
|
50
|
+
}
|
|
51
|
+
export interface DestroyFunction<T, TGlobals extends Record<string, unknown> = any> {
|
|
52
|
+
(context: DestroyContext<T, TGlobals>): void;
|
|
53
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Behavior } from "~/lib/actions/behaviors/behavior";
|
|
2
|
+
import { DestroyContext, DestroyFunction, SetupContext, SetupFunction, UpdateContext, UpdateFunction } from "./base-node-life-cycle";
|
|
3
|
+
export type BaseNodeOptions<T = any> = BaseNode | Partial<T>;
|
|
4
|
+
export declare abstract class BaseNode<Options = any, T = any> {
|
|
5
|
+
protected parent: BaseNode | null;
|
|
6
|
+
protected children: BaseNode[];
|
|
7
|
+
behaviors: Behavior[];
|
|
8
|
+
options: Options;
|
|
9
|
+
eid: number;
|
|
10
|
+
uuid: string;
|
|
11
|
+
name: string;
|
|
12
|
+
markedForRemoval: boolean;
|
|
13
|
+
update: UpdateFunction<this>;
|
|
14
|
+
setup: SetupFunction<this>;
|
|
15
|
+
destroy: DestroyFunction<this>;
|
|
16
|
+
constructor(args?: BaseNodeOptions[]);
|
|
17
|
+
setParent(parent: BaseNode | null): void;
|
|
18
|
+
getParent(): BaseNode | null;
|
|
19
|
+
add(baseNode: BaseNode): void;
|
|
20
|
+
remove(baseNode: BaseNode): void;
|
|
21
|
+
getChildren(): BaseNode[];
|
|
22
|
+
isComposite(): boolean;
|
|
23
|
+
abstract create(): T;
|
|
24
|
+
protected abstract _setup(params: SetupContext<this>): void;
|
|
25
|
+
protected abstract _update(params: UpdateContext<this>): void;
|
|
26
|
+
protected abstract _destroy(params: DestroyContext<this>): void;
|
|
27
|
+
nodeSetup(params: SetupContext<this>): void;
|
|
28
|
+
nodeUpdate(params: UpdateContext<this>): void;
|
|
29
|
+
nodeDestroy(params: DestroyContext<this>): void;
|
|
30
|
+
getOptions(): Options;
|
|
31
|
+
setOptions(options: Partial<Options>): void;
|
|
32
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AnimationClip, Object3D } from 'three';
|
|
2
|
+
import { GLTF } from 'three/addons/loaders/GLTFLoader.js';
|
|
3
|
+
export declare enum FileExtensionTypes {
|
|
4
|
+
FBX = "fbx",
|
|
5
|
+
GLTF = "gltf"
|
|
6
|
+
}
|
|
7
|
+
export interface AssetLoaderResult {
|
|
8
|
+
object?: Object3D;
|
|
9
|
+
animation?: AnimationClip;
|
|
10
|
+
gltf?: GLTF;
|
|
11
|
+
}
|
|
12
|
+
export interface IAssetLoader {
|
|
13
|
+
load(file: string): Promise<AssetLoaderResult>;
|
|
14
|
+
isSupported(file: string): boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare class FBXAssetLoader implements IAssetLoader {
|
|
17
|
+
private loader;
|
|
18
|
+
isSupported(file: string): boolean;
|
|
19
|
+
load(file: string): Promise<AssetLoaderResult>;
|
|
20
|
+
}
|
|
21
|
+
export declare class GLTFAssetLoader implements IAssetLoader {
|
|
22
|
+
private loader;
|
|
23
|
+
isSupported(file: string): boolean;
|
|
24
|
+
load(file: string): Promise<AssetLoaderResult>;
|
|
25
|
+
}
|
|
26
|
+
export declare class EntityAssetLoader {
|
|
27
|
+
private loaders;
|
|
28
|
+
loadFile(file: string): Promise<AssetLoaderResult>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazy loading utilities for Zylem components
|
|
3
|
+
* Use these functions to load parts of the library only when needed
|
|
4
|
+
*
|
|
5
|
+
* Loading order follows dependency hierarchy:
|
|
6
|
+
* 1. Foundation (core utilities, types)
|
|
7
|
+
* 2. State, Input, Graphics, Physics (parallel)
|
|
8
|
+
* 3. Camera (depends on graphics)
|
|
9
|
+
* 4. Entities (depends on foundation, graphics, physics)
|
|
10
|
+
* 5. Behaviors (depends on entities)
|
|
11
|
+
* 6. Core game systems (depends on most others)
|
|
12
|
+
* 7. Stage (depends on everything)
|
|
13
|
+
*/
|
|
14
|
+
export declare const loadFoundation: () => Promise<{
|
|
15
|
+
baseNode: typeof import("./base-node");
|
|
16
|
+
lifeCycle: typeof import("./base-node-life-cycle");
|
|
17
|
+
utility: typeof import("./utility");
|
|
18
|
+
vector: typeof import("./vector");
|
|
19
|
+
}>;
|
|
20
|
+
export declare const loadState: () => Promise<typeof import("../game/game-state")>;
|
|
21
|
+
export declare const loadInput: () => Promise<typeof import("../input/input-manager")>;
|
|
22
|
+
export declare const loadGraphics: () => Promise<{
|
|
23
|
+
material: typeof import("../graphics/material");
|
|
24
|
+
mesh: typeof import("../graphics/mesh");
|
|
25
|
+
}>;
|
|
26
|
+
export declare const loadPhysics: () => Promise<{
|
|
27
|
+
physics: typeof import("../collision/physics");
|
|
28
|
+
collision: typeof import("../collision/collision");
|
|
29
|
+
collisionBuilder: typeof import("../collision/collision-builder");
|
|
30
|
+
}>;
|
|
31
|
+
export declare const loadCamera: () => Promise<{
|
|
32
|
+
camera: typeof import("../camera/camera");
|
|
33
|
+
perspectives: typeof import("../camera/perspective");
|
|
34
|
+
}>;
|
|
35
|
+
export declare const loadAllEntities: () => Promise<typeof import("../entities/entity")>;
|
|
36
|
+
export declare const loadEntity: (entityType: "box" | "sphere" | "sprite" | "plane" | "zone" | "actor") => Promise<typeof import("../entities/box") | typeof import("../entities/sphere") | typeof import("../entities/sprite") | typeof import("../entities/plane") | typeof import("../entities/zone") | typeof import("../entities/actor")>;
|
|
37
|
+
export declare const loadBehaviors: () => Promise<typeof import("../actions/behaviors/actions")>;
|
|
38
|
+
export declare const loadGameCore: () => Promise<{
|
|
39
|
+
game: typeof import("../game/game");
|
|
40
|
+
vessel: typeof import("./vessel");
|
|
41
|
+
}>;
|
|
42
|
+
export declare const loadStage: () => Promise<{
|
|
43
|
+
stage: typeof import("../stage/stage");
|
|
44
|
+
world: typeof import("../collision/world");
|
|
45
|
+
scene: typeof import("../graphics/zylem-scene");
|
|
46
|
+
}>;
|
|
47
|
+
export declare const loadDebugTools: () => Promise<typeof import("../ui/Debug")>;
|
|
48
|
+
export declare const loadFullGame: () => Promise<{
|
|
49
|
+
foundation: {
|
|
50
|
+
baseNode: typeof import("./base-node");
|
|
51
|
+
lifeCycle: typeof import("./base-node-life-cycle");
|
|
52
|
+
utility: typeof import("./utility");
|
|
53
|
+
vector: typeof import("./vector");
|
|
54
|
+
};
|
|
55
|
+
state: typeof import("../game/game-state");
|
|
56
|
+
input: typeof import("../input/input-manager");
|
|
57
|
+
graphics: {
|
|
58
|
+
material: typeof import("../graphics/material");
|
|
59
|
+
mesh: typeof import("../graphics/mesh");
|
|
60
|
+
};
|
|
61
|
+
physics: {
|
|
62
|
+
physics: typeof import("../collision/physics");
|
|
63
|
+
collision: typeof import("../collision/collision");
|
|
64
|
+
collisionBuilder: typeof import("../collision/collision-builder");
|
|
65
|
+
};
|
|
66
|
+
camera: {
|
|
67
|
+
camera: typeof import("../camera/camera");
|
|
68
|
+
perspectives: typeof import("../camera/perspective");
|
|
69
|
+
};
|
|
70
|
+
entities: typeof import("../entities/entity");
|
|
71
|
+
behaviors: typeof import("../actions/behaviors/actions");
|
|
72
|
+
gameCore: {
|
|
73
|
+
game: typeof import("../game/game");
|
|
74
|
+
vessel: typeof import("./vessel");
|
|
75
|
+
};
|
|
76
|
+
stage: {
|
|
77
|
+
stage: typeof import("../stage/stage");
|
|
78
|
+
world: typeof import("../collision/world");
|
|
79
|
+
scene: typeof import("../graphics/zylem-scene");
|
|
80
|
+
};
|
|
81
|
+
}>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DestroyContext, DestroyFunction, SetupContext, SetupFunction, UpdateContext, UpdateFunction } from './base-node-life-cycle';
|
|
2
|
+
/**
|
|
3
|
+
* Provides BaseNode-like lifecycle without ECS/children. Consumers implement
|
|
4
|
+
* the protected hooks and may assign public setup/update/destroy callbacks.
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class LifeCycleBase<TSelf> {
|
|
7
|
+
update: UpdateFunction<TSelf>;
|
|
8
|
+
setup: SetupFunction<TSelf>;
|
|
9
|
+
destroy: DestroyFunction<TSelf>;
|
|
10
|
+
protected abstract _setup(context: SetupContext<TSelf>): void;
|
|
11
|
+
protected abstract _update(context: UpdateContext<TSelf>): void;
|
|
12
|
+
protected abstract _destroy(context: DestroyContext<TSelf>): void;
|
|
13
|
+
nodeSetup(context: SetupContext<TSelf>): void;
|
|
14
|
+
nodeUpdate(context: UpdateContext<TSelf>): void;
|
|
15
|
+
nodeDestroy(context: DestroyContext<TSelf>): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type ZylemShaderObject = {
|
|
2
|
+
fragment: string;
|
|
3
|
+
vertex: string;
|
|
4
|
+
};
|
|
5
|
+
export declare const starShader: ZylemShaderObject;
|
|
6
|
+
export declare const fireShader: ZylemShaderObject;
|
|
7
|
+
export declare const standardShader: ZylemShaderObject;
|
|
8
|
+
export type ZylemShaderType = 'standard' | 'fire' | 'star';
|
|
9
|
+
declare const shaderMap: Map<ZylemShaderType, ZylemShaderObject>;
|
|
10
|
+
export default shaderMap;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This class is an alternative to {@link Clock} with a different API design and behavior.
|
|
3
|
+
* The goal is to avoid the conceptual flaws that became apparent in `Clock` over time.
|
|
4
|
+
*
|
|
5
|
+
* - `Timer` has an `update()` method that updates its internal state. That makes it possible to
|
|
6
|
+
* call `getDelta()` and `getElapsed()` multiple times per simulation step without getting different values.
|
|
7
|
+
* - The class can make use of the Page Visibility API to avoid large time delta values when the app
|
|
8
|
+
* is inactive (e.g. tab switched or browser hidden).
|
|
9
|
+
*
|
|
10
|
+
* ```js
|
|
11
|
+
* const timer = new Timer();
|
|
12
|
+
* timer.connect( document ); // use Page Visibility API
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @three_import import { Timer } from 'three/addons/misc/Timer.js';
|
|
16
|
+
*/
|
|
17
|
+
declare class Timer {
|
|
18
|
+
protected _previousTime: number;
|
|
19
|
+
protected _currentTime: number;
|
|
20
|
+
protected _startTime: number;
|
|
21
|
+
protected _delta: number;
|
|
22
|
+
protected _elapsed: number;
|
|
23
|
+
protected _timescale: number;
|
|
24
|
+
protected _document: Document | null;
|
|
25
|
+
protected _pageVisibilityHandler: (() => void) | null;
|
|
26
|
+
/**
|
|
27
|
+
* Constructs a new timer.
|
|
28
|
+
*/
|
|
29
|
+
constructor();
|
|
30
|
+
/**
|
|
31
|
+
* Connect the timer to the given document.Calling this method is not mandatory to
|
|
32
|
+
* use the timer but enables the usage of the Page Visibility API to avoid large time
|
|
33
|
+
* delta values.
|
|
34
|
+
*
|
|
35
|
+
* @param {Document} document - The document.
|
|
36
|
+
*/
|
|
37
|
+
connect(document: Document): void;
|
|
38
|
+
/**
|
|
39
|
+
* Disconnects the timer from the DOM and also disables the usage of the Page Visibility API.
|
|
40
|
+
*/
|
|
41
|
+
disconnect(): void;
|
|
42
|
+
/**
|
|
43
|
+
* Returns the time delta in seconds.
|
|
44
|
+
*
|
|
45
|
+
* @return {number} The time delta in second.
|
|
46
|
+
*/
|
|
47
|
+
getDelta(): number;
|
|
48
|
+
/**
|
|
49
|
+
* Returns the elapsed time in seconds.
|
|
50
|
+
*
|
|
51
|
+
* @return {number} The elapsed time in second.
|
|
52
|
+
*/
|
|
53
|
+
getElapsed(): number;
|
|
54
|
+
/**
|
|
55
|
+
* Returns the timescale.
|
|
56
|
+
*
|
|
57
|
+
* @return {number} The timescale.
|
|
58
|
+
*/
|
|
59
|
+
getTimescale(): number;
|
|
60
|
+
/**
|
|
61
|
+
* Sets the given timescale which scale the time delta computation
|
|
62
|
+
* in `update()`.
|
|
63
|
+
*
|
|
64
|
+
* @param {number} timescale - The timescale to set.
|
|
65
|
+
* @return {Timer} A reference to this timer.
|
|
66
|
+
*/
|
|
67
|
+
setTimescale(timescale: number): Timer;
|
|
68
|
+
/**
|
|
69
|
+
* Resets the time computation for the current simulation step.
|
|
70
|
+
*
|
|
71
|
+
* @return {Timer} A reference to this timer.
|
|
72
|
+
*/
|
|
73
|
+
reset(): Timer;
|
|
74
|
+
/**
|
|
75
|
+
* Can be used to free all internal resources. Usually called when
|
|
76
|
+
* the timer instance isn't required anymore.
|
|
77
|
+
*/
|
|
78
|
+
dispose(): void;
|
|
79
|
+
/**
|
|
80
|
+
* Updates the internal state of the timer. This method should be called
|
|
81
|
+
* once per simulation step and before you perform queries against the timer
|
|
82
|
+
* (e.g. via `getDelta()`).
|
|
83
|
+
*
|
|
84
|
+
* @param {number} timestamp - The current time in milliseconds. Can be obtained
|
|
85
|
+
* from the `requestAnimationFrame` callback argument. If not provided, the current
|
|
86
|
+
* time will be determined with `performance.now`.
|
|
87
|
+
* @return {Timer} A reference to this timer.
|
|
88
|
+
*/
|
|
89
|
+
update(timestamp?: number): Timer;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* A special version of a timer with a fixed time delta value.
|
|
93
|
+
* Can be useful for testing and debugging purposes.
|
|
94
|
+
*
|
|
95
|
+
* @augments Timer
|
|
96
|
+
*/
|
|
97
|
+
declare class FixedTimer extends Timer {
|
|
98
|
+
/**
|
|
99
|
+
* Constructs a new timer.
|
|
100
|
+
*
|
|
101
|
+
* @param {number} [fps=60] - The fixed FPS of this timer.
|
|
102
|
+
*/
|
|
103
|
+
constructor(fps?: number);
|
|
104
|
+
update(): FixedTimer;
|
|
105
|
+
}
|
|
106
|
+
export { Timer, FixedTimer };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Color, Vector3 as ThreeVector3 } from 'three';
|
|
2
|
+
import { Vector3 } from '@dimforge/rapier3d-compat';
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated This type is deprecated.
|
|
5
|
+
*/
|
|
6
|
+
export type Vect3 = ThreeVector3 | Vector3;
|
|
7
|
+
export declare const ZylemBlueColor: Color;
|
|
8
|
+
export declare const ZylemBlue = "#0333EC";
|
|
9
|
+
export declare const ZylemBlueTransparent = "#0333ECA0";
|
|
10
|
+
export declare const ZylemGoldText = "#DAA420";
|
|
11
|
+
export type SizeVector = Vect3 | null;
|
|
12
|
+
export declare function sortedStringify(obj: Record<string, any>): string;
|
|
13
|
+
export declare function shortHash(objString: string): string;
|
|
14
|
+
export declare const Vec0: Vector3;
|
|
15
|
+
export declare const Vec1: Vector3;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseNode } from './base-node';
|
|
2
|
+
import { SetupContext, UpdateContext, DestroyContext } from './base-node-life-cycle';
|
|
3
|
+
export declare const VESSEL_TYPE: unique symbol;
|
|
4
|
+
export declare class Vessel extends BaseNode<{}, Vessel> {
|
|
5
|
+
static type: symbol;
|
|
6
|
+
protected _setup(_params: SetupContext<this>): void;
|
|
7
|
+
protected _update(_params: UpdateContext<this>): void;
|
|
8
|
+
protected _destroy(_params: DestroyContext<this>): void;
|
|
9
|
+
create(): this;
|
|
10
|
+
}
|
|
11
|
+
export declare function vessel(...args: Array<BaseNode>): BaseNode<{}, Vessel>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Console state for managing debug console messages
|
|
3
|
+
*/
|
|
4
|
+
export declare const consoleState: {
|
|
5
|
+
messages: string[];
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Append a message to the debug console
|
|
9
|
+
* @param message The message to append to the console
|
|
10
|
+
*/
|
|
11
|
+
export declare const printToConsole: (message: string) => void;
|
|
12
|
+
/**
|
|
13
|
+
* Clear all messages from the debug console
|
|
14
|
+
*/
|
|
15
|
+
export declare const clearConsole: () => void;
|
|
16
|
+
/**
|
|
17
|
+
* Get all console messages as a single string
|
|
18
|
+
*/
|
|
19
|
+
export declare const getConsoleContent: () => string;
|