@zylem/game-lib 0.3.14 → 0.3.15
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/README.md +17 -14
- package/dist/lib/actions/global-change.d.ts +10 -0
- package/dist/lib/collision/collision-builder.d.ts +0 -2
- package/dist/lib/collision/collision-group.d.ts +0 -17
- package/dist/lib/core/lazy-loader.d.ts +0 -2
- package/dist/lib/core/preset-shader.d.ts +2 -1
- package/dist/lib/entities/entity.d.ts +0 -2
- package/dist/lib/game/zylem-game.d.ts +2 -0
- package/dist/lib/graphics/zylem-scene.d.ts +2 -2
- package/dist/lib/stage/stage-state.d.ts +5 -1
- package/dist/lib/stage/stage.d.ts +0 -1
- package/dist/lib/stage/zylem-stage.d.ts +1 -3
- package/dist/main.cjs +236 -193
- package/dist/main.d.ts +1 -1
- package/dist/main.js +23966 -13614
- package/package.json +17 -17
- package/dist/assets/bounce.wav +0 -0
- package/dist/assets/coin-sound.mp3 +0 -0
- package/dist/lib/collision/physics.d.ts +0 -4
- package/dist/lib/entities/object.d.ts +0 -1
- package/dist/lib/interfaces/game.d.ts +0 -19
package/README.md
CHANGED
|
@@ -2,6 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
A powerful and easy-to-use framework for creating simple 3D digital interactive applications using TypeScript.
|
|
4
4
|
|
|
5
|
+
**Why Zylem?**
|
|
6
|
+
|
|
7
|
+
I wanted to build something easy to jump into and deploy while still only writing code (no complex game IDEs).
|
|
8
|
+
|
|
9
|
+
**Who should use Zylem?**
|
|
10
|
+
|
|
11
|
+
This library is intended for hobbyist developers who want to play with 3D web technologies to build a game.
|
|
12
|
+
|
|
13
|
+
**What does Zylem do?**
|
|
14
|
+
|
|
15
|
+
The goal is to give you tools to build simple 3D games. It's basically comprised of:
|
|
16
|
+
|
|
17
|
+
- Rendering via ThreeJS with some capability to handle postprocessing built-in. [ThreeJS](https://threejs.org/)
|
|
18
|
+
- Collision handling, triggers, and rigid body physics via RapierRS [RapierRS](https://rapier.rs/)
|
|
19
|
+
- Game state management with Valtio [Valtio](https://valtio.dev/)
|
|
20
|
+
- Simplified input handling (gamepad, keyboard, mouse)
|
|
21
|
+
|
|
5
22
|
>Note: This project is still in alpha. There are unfinished features and some APIs that may change.
|
|
6
23
|
|
|
7
24
|
## Installation
|
|
@@ -49,17 +66,3 @@ makeMoveable(ball).onUpdate(({ entity, inputs }) => {
|
|
|
49
66
|
|
|
50
67
|
game(ball).start();
|
|
51
68
|
```
|
|
52
|
-
|
|
53
|
-
## Repository Governance
|
|
54
|
-
|
|
55
|
-
### Conventional commits
|
|
56
|
-
|
|
57
|
-
- `feat`: A new feature
|
|
58
|
-
- `fix`: A bug fix
|
|
59
|
-
- `docs`: Documentation only changes
|
|
60
|
-
- `style`: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
|
|
61
|
-
- `refactor`: A code change that neither fixes a bug nor adds a feature
|
|
62
|
-
- `cleanup`: Removal of dead code, unused functionality, or code changes involving renaming
|
|
63
|
-
- `perf`: A code change that improves performance
|
|
64
|
-
- `test`: Adding missing or correcting existing tests
|
|
65
|
-
- `build`: Changes that affect the build system or external dependencies (example scopes: vite, npm, typescript, etc)
|
|
@@ -10,3 +10,13 @@ export declare function globalChange<T = any>(key: string, callback: (value: T,
|
|
|
10
10
|
* Usage: onUpdate(globalChanges(['p1Score','p2Score'], ([p1,p2]) => { ... }))
|
|
11
11
|
*/
|
|
12
12
|
export declare function globalChanges<T = any>(keys: string[], callback: (values: T[], ctx: UpdateContext<any>) => void): (ctx: UpdateContext<any>) => void;
|
|
13
|
+
/**
|
|
14
|
+
* Listen for a single stage variable change inside an onUpdate pipeline.
|
|
15
|
+
* Usage: onUpdate(variableChange('score', (value, ctx) => { ... }))
|
|
16
|
+
*/
|
|
17
|
+
export declare function variableChange<T = any>(key: string, callback: (value: T, ctx: UpdateContext<any>) => void): (ctx: UpdateContext<any>) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Listen for multiple stage variable changes; fires when any changes.
|
|
20
|
+
* Usage: onUpdate(variableChanges(['a','b'], ([a,b], ctx) => { ... }))
|
|
21
|
+
*/
|
|
22
|
+
export declare function variableChanges<T = any>(keys: string[], callback: (values: T[], ctx: UpdateContext<any>) => void): (ctx: UpdateContext<any>) => void;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ColliderDesc, RigidBodyDesc } from "@dimforge/rapier3d-compat";
|
|
2
|
-
import { PhysicsOptions } from "./physics";
|
|
3
2
|
import { Vec3 } from "../core/vector";
|
|
4
3
|
import { CollisionOptions } from "./collision";
|
|
5
4
|
export declare function getOrCreateCollisionGroupId(type: string): number;
|
|
@@ -15,7 +14,6 @@ export declare class CollisionBuilder {
|
|
|
15
14
|
gravity: Vec3;
|
|
16
15
|
build(options: Partial<CollisionOptions>): [RigidBodyDesc, ColliderDesc];
|
|
17
16
|
withCollision(collisionOptions: Partial<CollisionOptions>): this;
|
|
18
|
-
withPhysics(physicsOptions: Partial<PhysicsOptions>): this;
|
|
19
17
|
collider(options: CollisionOptions): ColliderDesc;
|
|
20
18
|
bodyDesc({ isDynamicBody }: {
|
|
21
19
|
isDynamicBody?: boolean | undefined;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { GameEntity } from '../entities/entity';
|
|
2
|
-
import { CollisionContext } from '../entities/entity';
|
|
3
2
|
/**
|
|
4
3
|
* Configure an entity's collision groups to only collide with the specified types.
|
|
5
4
|
* This uses Rapier's built-in collision group system for efficient filtering.
|
|
@@ -9,19 +8,3 @@ import { CollisionContext } from '../entities/entity';
|
|
|
9
8
|
* @returns The entity for method chaining
|
|
10
9
|
*/
|
|
11
10
|
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;
|
|
@@ -24,7 +24,6 @@ export declare const loadGraphics: () => Promise<{
|
|
|
24
24
|
mesh: typeof import("../graphics/mesh");
|
|
25
25
|
}>;
|
|
26
26
|
export declare const loadPhysics: () => Promise<{
|
|
27
|
-
physics: typeof import("../collision/physics");
|
|
28
27
|
collision: typeof import("../collision/collision");
|
|
29
28
|
collisionBuilder: typeof import("../collision/collision-builder");
|
|
30
29
|
}>;
|
|
@@ -59,7 +58,6 @@ export declare const loadFullGame: () => Promise<{
|
|
|
59
58
|
mesh: typeof import("../graphics/mesh");
|
|
60
59
|
};
|
|
61
60
|
physics: {
|
|
62
|
-
physics: typeof import("../collision/physics");
|
|
63
61
|
collision: typeof import("../collision/collision");
|
|
64
62
|
collisionBuilder: typeof import("../collision/collision-builder");
|
|
65
63
|
};
|
|
@@ -5,6 +5,7 @@ export type ZylemShaderObject = {
|
|
|
5
5
|
export declare const starShader: ZylemShaderObject;
|
|
6
6
|
export declare const fireShader: ZylemShaderObject;
|
|
7
7
|
export declare const standardShader: ZylemShaderObject;
|
|
8
|
-
export
|
|
8
|
+
export declare const debugShader: ZylemShaderObject;
|
|
9
|
+
export type ZylemShaderType = 'standard' | 'fire' | 'star' | 'debug';
|
|
9
10
|
declare const shaderMap: Map<ZylemShaderType, ZylemShaderObject>;
|
|
10
11
|
export default shaderMap;
|
|
@@ -2,7 +2,6 @@ import { Mesh, Material, ShaderMaterial, Group, Color } from "three";
|
|
|
2
2
|
import { Collider, ColliderDesc, RigidBody, RigidBodyDesc } from "@dimforge/rapier3d-compat";
|
|
3
3
|
import { Vec3 } from "../core/vector";
|
|
4
4
|
import { MaterialBuilder, MaterialOptions } from "../graphics/material";
|
|
5
|
-
import { PhysicsOptions } from "../collision/physics";
|
|
6
5
|
import { CollisionOptions } from "../collision/collision";
|
|
7
6
|
import { BaseNode } from "../core/base-node";
|
|
8
7
|
import { DestroyContext, SetupContext, UpdateContext } from "../core/base-node-life-cycle";
|
|
@@ -39,7 +38,6 @@ export type GameEntityOptions = {
|
|
|
39
38
|
position?: Vec3;
|
|
40
39
|
batched?: boolean;
|
|
41
40
|
collision?: Partial<CollisionOptions>;
|
|
42
|
-
physics?: Partial<PhysicsOptions>;
|
|
43
41
|
material?: Partial<MaterialOptions>;
|
|
44
42
|
custom?: {
|
|
45
43
|
[key: string]: any;
|
|
@@ -22,6 +22,8 @@ export declare class ZylemGame<TGlobals extends Record<string, BasicTypes> = Glo
|
|
|
22
22
|
statsRef: {
|
|
23
23
|
begin: () => void;
|
|
24
24
|
end: () => void;
|
|
25
|
+
showPanel: (panel: number) => void;
|
|
26
|
+
dom: HTMLElement;
|
|
25
27
|
} | null;
|
|
26
28
|
defaultCamera: ZylemCamera | null;
|
|
27
29
|
static FRAME_LIMIT: number;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { Scene, Color, Object3D, Vector3 } from 'three';
|
|
2
2
|
import { Entity } from '../interfaces/entity';
|
|
3
|
-
import { SetupCallback } from '~/lib/interfaces/game';
|
|
4
3
|
import { GameEntity } from '../entities/entity';
|
|
5
4
|
import { ZylemCamera } from '../camera/zylem-camera';
|
|
5
|
+
import { SetupFunction } from '../core/base-node-life-cycle';
|
|
6
6
|
interface SceneState {
|
|
7
7
|
backgroundColor: Color;
|
|
8
8
|
backgroundImage: string | null;
|
|
9
9
|
}
|
|
10
10
|
export declare class ZylemScene implements Entity<ZylemScene> {
|
|
11
11
|
type: string;
|
|
12
|
-
_setup?:
|
|
12
|
+
_setup?: SetupFunction<ZylemScene>;
|
|
13
13
|
scene: Scene;
|
|
14
14
|
zylemCamera: ZylemCamera;
|
|
15
15
|
containerElement: HTMLElement | null;
|
|
@@ -8,5 +8,9 @@ declare const setStageBackgroundImage: (value: string | null) => void;
|
|
|
8
8
|
declare const setEntitiesToStage: (entities: Partial<BaseEntityInterface>[]) => void;
|
|
9
9
|
declare const setStageVariable: (key: string, value: any) => void;
|
|
10
10
|
declare const getStageVariable: (key: string) => any;
|
|
11
|
+
/** Replace the entire stage variables object (used on stage load). */
|
|
12
|
+
declare const setStageVariables: (variables: Record<string, any>) => void;
|
|
13
|
+
/** Reset all stage variables (used on stage unload). */
|
|
14
|
+
declare const resetStageVariables: () => void;
|
|
11
15
|
declare const stageStateToString: (state: StageStateInterface) => string;
|
|
12
|
-
export { stageState, setStageState, setStageBackgroundColor, setStageBackgroundImage, setEntitiesToStage, stageStateToString, setStageVariable, getStageVariable, };
|
|
16
|
+
export { stageState, setStageState, setStageBackgroundColor, setStageBackgroundImage, setEntitiesToStage, stageStateToString, setStageVariable, getStageVariable, setStageVariables, resetStageVariables, };
|
|
@@ -24,7 +24,6 @@ export declare class Stage {
|
|
|
24
24
|
onDestroy(callback: DestroyFunction<ZylemStage>): void;
|
|
25
25
|
setVariable(key: string, value: any): void;
|
|
26
26
|
getVariable(key: string): any;
|
|
27
|
-
watchVariable(key: string, callback: (value: any) => void): void;
|
|
28
27
|
}
|
|
29
28
|
/**
|
|
30
29
|
* Create a stage with optional camera
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Color, Vector3 } from 'three';
|
|
2
2
|
import { ZylemWorld } from '../collision/world';
|
|
3
3
|
import { ZylemScene } from '../graphics/zylem-scene';
|
|
4
|
-
import { Conditions } from '../interfaces/game';
|
|
5
4
|
import { GameEntityInterface } from '../types/entity-types';
|
|
6
5
|
import { SetupContext, UpdateContext, DestroyContext } from '../core/base-node-life-cycle';
|
|
7
6
|
import { LifeCycleBase } from '../core/lifecycle-base';
|
|
@@ -17,7 +16,6 @@ export interface ZylemStageConfig {
|
|
|
17
16
|
backgroundImage: string | null;
|
|
18
17
|
gravity: Vector3;
|
|
19
18
|
variables: Record<string, any>;
|
|
20
|
-
conditions?: Conditions<any>[];
|
|
21
19
|
stageRef?: Stage;
|
|
22
20
|
}
|
|
23
21
|
type NodeLike = {
|
|
@@ -44,7 +42,6 @@ export declare class ZylemStage extends LifeCycleBase<ZylemStage> {
|
|
|
44
42
|
gravity: Vector3;
|
|
45
43
|
world: ZylemWorld | null;
|
|
46
44
|
scene: ZylemScene | null;
|
|
47
|
-
conditions: Conditions<any>[];
|
|
48
45
|
children: Array<BaseNode>;
|
|
49
46
|
_childrenMap: Map<number, BaseNode>;
|
|
50
47
|
_removalMap: Map<number, BaseNode>;
|
|
@@ -85,6 +82,7 @@ export declare class ZylemStage extends LifeCycleBase<ZylemStage> {
|
|
|
85
82
|
private createDefaultCamera;
|
|
86
83
|
protected _setup(params: SetupContext<ZylemStage>): void;
|
|
87
84
|
protected _update(params: UpdateContext<ZylemStage>): void;
|
|
85
|
+
outOfLoop(): void;
|
|
88
86
|
/** Update debug overlays and helpers if enabled. */
|
|
89
87
|
debugUpdate(): void;
|
|
90
88
|
/** Cleanup owned resources when the stage is destroyed. */
|