@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.
Files changed (123) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +65 -0
  3. package/dist/.vite/manifest.json +8 -0
  4. package/dist/assets/bounce.wav +0 -0
  5. package/dist/assets/coin-sound.mp3 +0 -0
  6. package/dist/assets/zylem-logo.png +0 -0
  7. package/dist/lib/actions/behaviors/actions.d.ts +10 -0
  8. package/dist/lib/actions/behaviors/behavior.d.ts +5 -0
  9. package/dist/lib/actions/behaviors/boundaries/boundary.d.ts +36 -0
  10. package/dist/lib/actions/behaviors/character-controller.d.ts +5 -0
  11. package/dist/lib/actions/behaviors/debug/debug-collision.d.ts +5 -0
  12. package/dist/lib/actions/behaviors/debug/debug-update.d.ts +4 -0
  13. package/dist/lib/actions/behaviors/debug/debug.d.ts +9 -0
  14. package/dist/lib/actions/behaviors/index.d.ts +1 -0
  15. package/dist/lib/actions/behaviors/movement/movement-sequence-2d.d.ts +23 -0
  16. package/dist/lib/actions/behaviors/ricochet/ricochet-2d-collision.d.ts +10 -0
  17. package/dist/lib/actions/behaviors/ricochet/ricochet-2d-in-bounds.d.ts +11 -0
  18. package/dist/lib/actions/behaviors/ricochet/ricochet.d.ts +41 -0
  19. package/dist/lib/actions/behaviors/zylem-behavior.d.ts +1 -0
  20. package/dist/lib/actions/capabilities/moveable.d.ts +124 -0
  21. package/dist/lib/actions/capabilities/rotatable.d.ts +110 -0
  22. package/dist/lib/actions/capabilities/transformable.d.ts +6 -0
  23. package/dist/lib/actions/global-change.d.ts +12 -0
  24. package/dist/lib/camera/camera.d.ts +15 -0
  25. package/dist/lib/camera/fixed-2d.d.ts +31 -0
  26. package/dist/lib/camera/perspective.d.ts +8 -0
  27. package/dist/lib/camera/third-person.d.ts +39 -0
  28. package/dist/lib/camera/zylem-camera.d.ts +68 -0
  29. package/dist/lib/collision/collision-builder.d.ts +23 -0
  30. package/dist/lib/collision/collision-delegate.d.ts +11 -0
  31. package/dist/lib/collision/collision-group.d.ts +27 -0
  32. package/dist/lib/collision/collision-mask.d.ts +17 -0
  33. package/dist/lib/collision/collision.d.ts +27 -0
  34. package/dist/lib/collision/physics.d.ts +4 -0
  35. package/dist/lib/collision/utils.d.ts +14 -0
  36. package/dist/lib/collision/world.d.ts +22 -0
  37. package/dist/lib/core/asset-manager.d.ts +1 -0
  38. package/dist/lib/core/base-node-life-cycle.d.ts +53 -0
  39. package/dist/lib/core/base-node.d.ts +32 -0
  40. package/dist/lib/core/entity-asset-loader.d.ts +29 -0
  41. package/dist/lib/core/errors.d.ts +4 -0
  42. package/dist/lib/core/flags.d.ts +2 -0
  43. package/dist/lib/core/game-canvas.d.ts +4 -0
  44. package/dist/lib/core/index.d.ts +4 -0
  45. package/dist/lib/core/lazy-loader.d.ts +81 -0
  46. package/dist/lib/core/lifecycle-base.d.ts +16 -0
  47. package/dist/lib/core/preset-shader.d.ts +10 -0
  48. package/dist/lib/core/three-addons/Timer.d.ts +106 -0
  49. package/dist/lib/core/utility.d.ts +15 -0
  50. package/dist/lib/core/vector.d.ts +3 -0
  51. package/dist/lib/core/vessel.d.ts +11 -0
  52. package/dist/lib/debug/console/console-state.d.ts +19 -0
  53. package/dist/lib/debug/console/console-store.d.ts +5 -0
  54. package/dist/lib/debug/debug-state.d.ts +43 -0
  55. package/dist/lib/debug/debug-store.d.ts +14 -0
  56. package/dist/lib/debug/state-based-debug-loader.d.ts +7 -0
  57. package/dist/lib/device/desktop.d.ts +1 -0
  58. package/dist/lib/device/mobile.d.ts +1 -0
  59. package/dist/lib/device/tablet.d.ts +1 -0
  60. package/dist/lib/entities/actor.d.ts +57 -0
  61. package/dist/lib/entities/box.d.ts +26 -0
  62. package/dist/lib/entities/builder.d.ts +27 -0
  63. package/dist/lib/entities/create.d.ts +14 -0
  64. package/dist/lib/entities/delegates/animation.d.ts +32 -0
  65. package/dist/lib/entities/delegates/debug.d.ts +37 -0
  66. package/dist/lib/entities/delegates/loader.d.ts +11 -0
  67. package/dist/lib/entities/destroy.d.ts +3 -0
  68. package/dist/lib/entities/entity.d.ts +100 -0
  69. package/dist/lib/entities/index.d.ts +11 -0
  70. package/dist/lib/entities/object.d.ts +1 -0
  71. package/dist/lib/entities/plane.d.ts +35 -0
  72. package/dist/lib/entities/rect.d.ts +62 -0
  73. package/dist/lib/entities/sphere.d.ts +28 -0
  74. package/dist/lib/entities/sprite.d.ts +52 -0
  75. package/dist/lib/entities/text.d.ts +41 -0
  76. package/dist/lib/entities/zone.d.ts +53 -0
  77. package/dist/lib/game/game-interfaces.d.ts +28 -0
  78. package/dist/lib/game/game-state.d.ts +10 -0
  79. package/dist/lib/game/game.d.ts +41 -0
  80. package/dist/lib/game/zylem-game.d.ts +44 -0
  81. package/dist/lib/graphics/geometries/XZPlaneGeometry.d.ts +7 -0
  82. package/dist/lib/graphics/material.d.ts +28 -0
  83. package/dist/lib/graphics/mesh.d.ts +18 -0
  84. package/dist/lib/graphics/render-pass.d.ts +16 -0
  85. package/dist/lib/graphics/zylem-scene.d.ts +49 -0
  86. package/dist/lib/input/gamepad-provider.d.ts +13 -0
  87. package/dist/lib/input/input-manager.d.ts +14 -0
  88. package/dist/lib/input/input-provider.d.ts +6 -0
  89. package/dist/lib/input/input.d.ts +51 -0
  90. package/dist/lib/input/keyboard-provider.d.ts +20 -0
  91. package/dist/lib/interfaces/entity.d.ts +31 -0
  92. package/dist/lib/interfaces/game.d.ts +19 -0
  93. package/dist/lib/sounds/index.d.ts +2 -0
  94. package/dist/lib/sounds/ping-pong-sound.d.ts +4 -0
  95. package/dist/lib/sounds/ricochet-sound.d.ts +4 -0
  96. package/dist/lib/stage/debug-entity-cursor.d.ts +23 -0
  97. package/dist/lib/stage/entity-spawner.d.ts +8 -0
  98. package/dist/lib/stage/stage-debug-delegate.d.ts +25 -0
  99. package/dist/lib/stage/stage-state.d.ts +12 -0
  100. package/dist/lib/stage/stage.d.ts +33 -0
  101. package/dist/lib/stage/zylem-stage.d.ts +127 -0
  102. package/dist/lib/systems/test-system.d.ts +1 -0
  103. package/dist/lib/systems/transformable.system.d.ts +24 -0
  104. package/dist/lib/types/entity-types.d.ts +38 -0
  105. package/dist/lib/types/index.d.ts +2 -0
  106. package/dist/lib/types/stage-types.d.ts +34 -0
  107. package/dist/lib/ui/Debug.d.ts +1 -0
  108. package/dist/lib/ui/console/Console.d.ts +6 -0
  109. package/dist/lib/ui/debug-panel/AccordionMenu.d.ts +6 -0
  110. package/dist/lib/ui/debug-panel/Menu.d.ts +5 -0
  111. package/dist/lib/ui/debug-panel/sections/EntitiesSection.d.ts +11 -0
  112. package/dist/lib/ui/debug-panel/sections/GameSection.d.ts +2 -0
  113. package/dist/lib/ui/debug-panel/sections/StagesSection.d.ts +2 -0
  114. package/dist/lib/ui/debug-panel/sections/all.d.ts +3 -0
  115. package/dist/lib/ui/toolbar/Toolbar.d.ts +5 -0
  116. package/dist/main.cjs +3980 -0
  117. package/dist/main.d.ts +40 -0
  118. package/dist/main.js +35583 -0
  119. package/dist/tests/collision/collision.spec.d.ts +1 -0
  120. package/dist/tests/core/game.spec.d.ts +1 -0
  121. package/dist/tests/core/stage.spec.d.ts +1 -0
  122. package/dist/tests/core/vessel.spec.d.ts +1 -0
  123. package/package.json +127 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Timothy Cool
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # Zylem
2
+
3
+ A powerful and easy-to-use framework for creating simple 3D digital interactive applications using TypeScript.
4
+
5
+ >Note: This project is still in alpha. There are unfinished features and some APIs that may change.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pnpm install
11
+ ```
12
+
13
+ ```bash
14
+ npm run dev
15
+ ```
16
+
17
+ ## Examples
18
+
19
+ >Note: The examples are not up to date with the latest version of Zylem.
20
+ [Check out the examples repo here](https://github.com/tcool86/zylem-examples/tree/master)
21
+
22
+ ## Basic Usage
23
+
24
+ [Basic usage repo here](https://github.com/tcool86/zylem-basic)
25
+
26
+ ```html
27
+ <!DOCTYPE html>
28
+ <html lang="en">
29
+ <head>
30
+ <meta charset="UTF-8" />
31
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
32
+ <title>Zylem - Basic Usage</title>
33
+ <link rel="stylesheet" href="./index.css" />
34
+ </head>
35
+ <body>
36
+ <script src="./src/index.ts" type="module"></script>
37
+ </body>
38
+ </html>
39
+ ```
40
+
41
+ ```typescript
42
+ import { game, sphere, makeMoveable } from '@tcool86/zylem';
43
+
44
+ const ball = await sphere();
45
+ makeMoveable(ball).onUpdate(({ entity, inputs }) => {
46
+ const { Horizontal, Vertical } = inputs.p1.axes;
47
+ entity.moveXY(Horizontal.value * 5, -Vertical.value * 5);
48
+ });
49
+
50
+ game(ball).start();
51
+ ```
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)
@@ -0,0 +1,8 @@
1
+ {
2
+ "src/main.ts": {
3
+ "file": "main.cjs",
4
+ "name": "main",
5
+ "src": "src/main.ts",
6
+ "isEntry": true
7
+ }
8
+ }
Binary file
Binary file
Binary file
@@ -0,0 +1,10 @@
1
+ export declare function wait(delay: number, callback: Function): void;
2
+ export declare const actionOnPress: (isPressed: boolean, callback: Function) => void;
3
+ export declare const actionOnRelease: (isPressed: boolean, callback: Function) => void;
4
+ type CooldownOptions = {
5
+ timer: number;
6
+ immediate?: boolean;
7
+ };
8
+ export declare const actionWithCooldown: ({ timer, immediate }: CooldownOptions, callback: Function, update: Function) => void;
9
+ export declare const actionWithThrottle: (timer: number, callback: Function) => void;
10
+ export {};
@@ -0,0 +1,5 @@
1
+ import { IComponent } from 'bitecs';
2
+ export interface Behavior {
3
+ component: IComponent;
4
+ values: any;
5
+ }
@@ -0,0 +1,36 @@
1
+ import { UpdateContext } from "../../../core/base-node-life-cycle";
2
+ import { MoveableEntity } from "../../capabilities/moveable";
3
+ import { Vector } from "@dimforge/rapier3d-compat";
4
+ import { BehaviorCallbackType } from "../../../entities/entity";
5
+ export interface BoundaryEvent {
6
+ me: MoveableEntity;
7
+ boundary: BoundaryHits;
8
+ position: Vector;
9
+ updateContext: UpdateContext<MoveableEntity>;
10
+ }
11
+ export interface BoundaryOptions {
12
+ boundaries: {
13
+ top: number;
14
+ bottom: number;
15
+ left: number;
16
+ right: number;
17
+ };
18
+ onBoundary?: (event: BoundaryEvent) => void;
19
+ stopMovement?: boolean;
20
+ }
21
+ /**
22
+ * Checks if the entity has hit a boundary and stops its movement if it has
23
+ *
24
+ * @param options Configuration options for the boundary behavior
25
+ * @param options.boundaries The boundaries of the stage
26
+ * @param options.onBoundary A callback function that is called when the entity hits a boundary
27
+ * @param options.stopMovement Whether to stop the entity's movement when it hits a boundary
28
+ * @returns A behavior callback with type 'update' and a handler function
29
+ */
30
+ export declare function boundary(options?: Partial<BoundaryOptions>): {
31
+ type: BehaviorCallbackType;
32
+ handler: (ctx: UpdateContext<MoveableEntity>) => void;
33
+ };
34
+ type BoundaryHit = 'top' | 'bottom' | 'left' | 'right';
35
+ type BoundaryHits = Record<BoundaryHit, boolean>;
36
+ export {};
@@ -0,0 +1,5 @@
1
+ export declare class ZylemCharacterController {
2
+ inputs: any;
3
+ constructor(inputs: any);
4
+ }
5
+ export declare function CharacterController(inputs: any): ZylemCharacterController;
@@ -0,0 +1,5 @@
1
+ import { DebugBehaviorOptions } from "~/lib/actions/behaviors/debug/debug";
2
+ import { BaseNode } from "~/lib/core/base-node";
3
+ import { CollisionContext } from "~/lib/entities/entity";
4
+ export type DebugBehaviorCollisionCallback = (ctx: CollisionContext<BaseNode, BaseNode<any>>) => void;
5
+ export declare function debugBehaviorCollision(options?: Partial<DebugBehaviorOptions>, ...callbacks: DebugBehaviorCollisionCallback[]): (collisionContext: CollisionContext<any, any>) => void;
@@ -0,0 +1,4 @@
1
+ import { BaseNode } from "~/lib/core/base-node";
2
+ import { UpdateContext } from "~/lib/core/base-node-life-cycle";
3
+ import { DebugBehaviorOptions } from "~/lib/actions/behaviors/debug/debug";
4
+ export declare function debugUpdateBehavior(options?: Partial<DebugBehaviorOptions>): (updateContext: UpdateContext<BaseNode>) => void;
@@ -0,0 +1,9 @@
1
+ import { BaseNode } from "../../../core/base-node";
2
+ import { BehaviorCallback } from "../../../entities/entity";
3
+ export interface DebugBehaviorOptions {
4
+ message: string;
5
+ }
6
+ export declare function debugBehavior(options?: Partial<DebugBehaviorOptions>): {
7
+ type: 'update';
8
+ handler: BehaviorCallback<BaseNode, any>;
9
+ };
@@ -0,0 +1 @@
1
+ export * from './ricochet/ricochet';
@@ -0,0 +1,23 @@
1
+ import { UpdateContext } from "../../../core/base-node-life-cycle";
2
+ import { MoveableEntity } from "../../capabilities/moveable";
3
+ import { BehaviorCallbackType } from "../../../entities/entity";
4
+ export interface MovementSequence2DStep {
5
+ name: string;
6
+ moveX?: number;
7
+ moveY?: number;
8
+ timeInSeconds: number;
9
+ }
10
+ export interface MovementSequence2DOptions {
11
+ sequence: MovementSequence2DStep[];
12
+ loop?: boolean;
13
+ }
14
+ export type MovementSequence2DCallback = (current: MovementSequence2DStep, index: number, ctx: UpdateContext<MoveableEntity>) => void;
15
+ /**
16
+ * Behavior that sequences 2D movements over time.
17
+ * Each step sets linear velocity via `moveXY` for a duration, then advances.
18
+ * Defaults to looping when the end is reached.
19
+ */
20
+ export declare function movementSequence2D(opts: MovementSequence2DOptions, onStep?: MovementSequence2DCallback): {
21
+ type: BehaviorCallbackType;
22
+ handler: (ctx: UpdateContext<MoveableEntity>) => void;
23
+ };
@@ -0,0 +1,10 @@
1
+ import { CollisionContext, GameEntity } from '../../../entities/entity';
2
+ import { MoveableEntity } from '../../capabilities/moveable';
3
+ import { Ricochet2DCollisionOptions, Ricochet2DCollisionCallback } from './ricochet';
4
+ /**
5
+ * Behavior for ricocheting an entity off other objects in 2D
6
+ */
7
+ export declare function ricochet2DCollision(options?: Partial<Ricochet2DCollisionOptions>, callback?: Ricochet2DCollisionCallback): {
8
+ type: 'collision';
9
+ handler: (ctx: CollisionContext<MoveableEntity, GameEntity<any>>) => void;
10
+ };
@@ -0,0 +1,11 @@
1
+ import { UpdateContext } from '../../../core/base-node-life-cycle';
2
+ import { MoveableEntity } from '../../capabilities/moveable';
3
+ import { Ricochet2DInBoundsOptions, Ricochet2DCallback } from './ricochet';
4
+ import { BehaviorCallbackType } from '../../../entities/entity';
5
+ /**
6
+ * Behavior for ricocheting an entity within fixed 2D boundaries
7
+ */
8
+ export declare function ricochet2DInBounds(options?: Partial<Ricochet2DInBoundsOptions>, callback?: Ricochet2DCallback): {
9
+ type: BehaviorCallbackType;
10
+ handler: (ctx: UpdateContext<MoveableEntity>) => void;
11
+ };
@@ -0,0 +1,41 @@
1
+ import { Vector } from '@dimforge/rapier3d-compat';
2
+ import { MoveableEntity } from '../../capabilities/moveable';
3
+ import { CollisionContext, GameEntity } from '../../../entities/entity';
4
+ import { UpdateContext } from '../../../core/base-node-life-cycle';
5
+ import { CollisionSelector } from '../../../collision/utils';
6
+ export interface RicochetEvent extends Partial<UpdateContext<MoveableEntity>> {
7
+ boundary?: 'top' | 'bottom' | 'left' | 'right';
8
+ position: Vector;
9
+ velocityBefore: Vector;
10
+ velocityAfter: Vector;
11
+ }
12
+ export interface RicochetCollisionEvent extends CollisionContext<MoveableEntity, GameEntity<any>> {
13
+ position: Vector;
14
+ }
15
+ export interface Ricochet2DInBoundsOptions {
16
+ restitution?: number;
17
+ minSpeed?: number;
18
+ maxSpeed?: number;
19
+ boundaries: {
20
+ top: number;
21
+ bottom: number;
22
+ left: number;
23
+ right: number;
24
+ };
25
+ separation?: number;
26
+ }
27
+ export interface Ricochet2DCollisionOptions {
28
+ restitution?: number;
29
+ minSpeed?: number;
30
+ maxSpeed?: number;
31
+ separation?: number;
32
+ collisionWith?: CollisionSelector;
33
+ /**
34
+ * Choose between simple axis inversion or angled (paddle-style) reflection.
35
+ * Defaults to 'angled'.
36
+ */
37
+ reflectionMode?: 'simple' | 'angled';
38
+ }
39
+ export type Ricochet2DCallback = (event: RicochetEvent) => void;
40
+ export type Ricochet2DCollisionCallback = (event: RicochetCollisionEvent) => void;
41
+ export declare function clamp(value: number, min: number, max: number): number;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,124 @@
1
+ import { Vector3 } from 'three';
2
+ import { RigidBody, Vector } from '@dimforge/rapier3d-compat';
3
+ export interface EntityWithBody {
4
+ body: RigidBody | null;
5
+ }
6
+ /**
7
+ * Move an entity along the X axis, preserving other velocities
8
+ */
9
+ export declare function moveX(entity: EntityWithBody, delta: number): void;
10
+ /**
11
+ * Move an entity along the Y axis, preserving other velocities
12
+ */
13
+ export declare function moveY(entity: EntityWithBody, delta: number): void;
14
+ /**
15
+ * Move an entity along the Z axis, preserving other velocities
16
+ */
17
+ export declare function moveZ(entity: EntityWithBody, delta: number): void;
18
+ /**
19
+ * Move an entity along the X and Y axis, preserving Z velocity
20
+ */
21
+ export declare function moveXY(entity: EntityWithBody, deltaX: number, deltaY: number): void;
22
+ /**
23
+ * Move an entity along the X and Z axis, preserving Y velocity
24
+ */
25
+ export declare function moveXZ(entity: EntityWithBody, deltaX: number, deltaZ: number): void;
26
+ /**
27
+ * Move entity based on a vector, adding to existing velocities
28
+ */
29
+ export declare function move(entity: EntityWithBody, vector: Vector3): void;
30
+ /**
31
+ * Reset entity velocity
32
+ */
33
+ export declare function resetVelocity(entity: EntityWithBody): void;
34
+ /**
35
+ * Move entity forward in 2D space, preserving Z velocity
36
+ */
37
+ export declare function moveForwardXY(entity: EntityWithBody, delta: number, rotation2DAngle: number): void;
38
+ /**
39
+ * Get entity position
40
+ */
41
+ export declare function getPosition(entity: EntityWithBody): Vector | null;
42
+ /**
43
+ * Get entity velocity
44
+ */
45
+ export declare function getVelocity(entity: EntityWithBody): Vector | null;
46
+ /**
47
+ * Set entity position
48
+ */
49
+ export declare function setPosition(entity: EntityWithBody, x: number, y: number, z: number): void;
50
+ /**
51
+ * Set entity X position
52
+ */
53
+ export declare function setPositionX(entity: EntityWithBody, x: number): void;
54
+ /**
55
+ * Set entity Y position
56
+ */
57
+ export declare function setPositionY(entity: EntityWithBody, y: number): void;
58
+ /**
59
+ * Set entity Z position
60
+ */
61
+ export declare function setPositionZ(entity: EntityWithBody, z: number): void;
62
+ /**
63
+ * Wrap entity around 2D bounds
64
+ */
65
+ export declare function wrapAroundXY(entity: EntityWithBody, boundsX: number, boundsY: number): void;
66
+ /**
67
+ * Wrap entity around 3D bounds
68
+ */
69
+ export declare function wrapAround3D(entity: EntityWithBody, boundsX: number, boundsY: number, boundsZ: number): void;
70
+ /**
71
+ * Enhanced moveable entity with bound methods
72
+ */
73
+ export interface MoveableEntity extends EntityWithBody {
74
+ moveX(delta: number): void;
75
+ moveY(delta: number): void;
76
+ moveZ(delta: number): void;
77
+ moveXY(deltaX: number, deltaY: number): void;
78
+ moveXZ(deltaX: number, deltaZ: number): void;
79
+ move(vector: Vector3): void;
80
+ resetVelocity(): void;
81
+ moveForwardXY(delta: number, rotation2DAngle: number): void;
82
+ getPosition(): Vector | null;
83
+ getVelocity(): Vector | null;
84
+ setPosition(x: number, y: number, z: number): void;
85
+ setPositionX(x: number): void;
86
+ setPositionY(y: number): void;
87
+ setPositionZ(z: number): void;
88
+ wrapAroundXY(boundsX: number, boundsY: number): void;
89
+ wrapAround3D(boundsX: number, boundsY: number, boundsZ: number): void;
90
+ }
91
+ /**
92
+ * Class decorator to enhance an entity with additive movement methods
93
+ */
94
+ export declare function moveable<T extends {
95
+ new (...args: any[]): EntityWithBody;
96
+ }>(constructor: T): {
97
+ new (...args: any[]): {
98
+ moveX(delta: number): void;
99
+ moveY(delta: number): void;
100
+ moveZ(delta: number): void;
101
+ moveXY(deltaX: number, deltaY: number): void;
102
+ moveXZ(deltaX: number, deltaZ: number): void;
103
+ move(vector: Vector3): void;
104
+ resetVelocity(): void;
105
+ moveForwardXY(delta: number, rotation2DAngle: number): void;
106
+ getPosition(): Vector | null;
107
+ getVelocity(): Vector | null;
108
+ setPosition(x: number, y: number, z: number): void;
109
+ setPositionX(x: number): void;
110
+ setPositionY(y: number): void;
111
+ setPositionZ(z: number): void;
112
+ wrapAroundXY(boundsX: number, boundsY: number): void;
113
+ wrapAround3D(boundsX: number, boundsY: number, boundsZ: number): void;
114
+ body: RigidBody | null;
115
+ };
116
+ } & T;
117
+ /**
118
+ * Enhance an entity with additive movement methods (retained for compatibility)
119
+ */
120
+ export declare function makeMoveable<T extends EntityWithBody>(entity: T): T & MoveableEntity;
121
+ /**
122
+ * Wrap a standalone function with movement capabilities
123
+ */
124
+ export declare function withMovement<T extends (...args: any[]) => any>(fn: T, entity: EntityWithBody): (...args: Parameters<T>) => ReturnType<T> & MoveableEntity;
@@ -0,0 +1,110 @@
1
+ import { Vector3 } from 'three';
2
+ import { RigidBody } from '@dimforge/rapier3d-compat';
3
+ export interface RotatableEntity {
4
+ body: RigidBody | null;
5
+ group: any;
6
+ }
7
+ /**
8
+ * Rotate an entity in the direction of a movement vector
9
+ */
10
+ export declare function rotateInDirection(entity: RotatableEntity, moveVector: Vector3): void;
11
+ /**
12
+ * Rotate an entity around the Y axis using Euler angles
13
+ */
14
+ export declare function rotateYEuler(entity: RotatableEntity, amount: number): void;
15
+ /**
16
+ * Rotate an entity using Euler angles
17
+ */
18
+ export declare function rotateEuler(entity: RotatableEntity, rotation: Vector3): void;
19
+ /**
20
+ * Rotate an entity around the Y axis
21
+ */
22
+ export declare function rotateY(entity: RotatableEntity, delta: number): void;
23
+ /**
24
+ * Rotate an entity around the Z axis
25
+ */
26
+ export declare function rotateZ(entity: RotatableEntity, delta: number): void;
27
+ /**
28
+ * Set rotation around Y axis
29
+ */
30
+ export declare function setRotationY(entity: RotatableEntity, y: number): void;
31
+ /**
32
+ * Set rotation around Y axis
33
+ */
34
+ export declare function setRotationDegreesY(entity: RotatableEntity, y: number): void;
35
+ /**
36
+ * Set rotation around X axis
37
+ */
38
+ export declare function setRotationX(entity: RotatableEntity, x: number): void;
39
+ /**
40
+ * Set rotation around X axis
41
+ */
42
+ export declare function setRotationDegreesX(entity: RotatableEntity, x: number): void;
43
+ /**
44
+ * Set rotation around Z axis
45
+ */
46
+ export declare function setRotationZ(entity: RotatableEntity, z: number): void;
47
+ /**
48
+ * Set rotation around Z axis
49
+ */
50
+ export declare function setRotationDegreesZ(entity: RotatableEntity, z: number): void;
51
+ /**
52
+ * Set rotation for all axes
53
+ */
54
+ export declare function setRotation(entity: RotatableEntity, x: number, y: number, z: number): void;
55
+ /**
56
+ * Set rotation for all axes
57
+ */
58
+ export declare function setRotationDegrees(entity: RotatableEntity, x: number, y: number, z: number): void;
59
+ /**
60
+ * Get current rotation
61
+ */
62
+ export declare function getRotation(entity: RotatableEntity): any;
63
+ /**
64
+ * Rotatable entity API with bound methods
65
+ */
66
+ export interface RotatableEntityAPI extends RotatableEntity {
67
+ rotateInDirection(moveVector: Vector3): void;
68
+ rotateYEuler(amount: number): void;
69
+ rotateEuler(rotation: Vector3): void;
70
+ rotateY(delta: number): void;
71
+ rotateZ(delta: number): void;
72
+ setRotationY(y: number): void;
73
+ setRotationX(x: number): void;
74
+ setRotationZ(z: number): void;
75
+ setRotationDegrees(x: number, y: number, z: number): void;
76
+ setRotationDegreesY(y: number): void;
77
+ setRotationDegreesX(x: number): void;
78
+ setRotationDegreesZ(z: number): void;
79
+ setRotation(x: number, y: number, z: number): void;
80
+ getRotation(): any;
81
+ }
82
+ /**
83
+ * Class decorator to enhance an entity with rotatable methods
84
+ */
85
+ export declare function rotatable<T extends {
86
+ new (...args: any[]): RotatableEntity;
87
+ }>(constructor: T): {
88
+ new (...args: any[]): {
89
+ rotateInDirection(moveVector: Vector3): void;
90
+ rotateYEuler(amount: number): void;
91
+ rotateEuler(rotation: Vector3): void;
92
+ rotateY(delta: number): void;
93
+ rotateZ(delta: number): void;
94
+ setRotationY(y: number): void;
95
+ setRotationX(x: number): void;
96
+ setRotationZ(z: number): void;
97
+ setRotationDegrees(x: number, y: number, z: number): void;
98
+ setRotationDegreesY(y: number): void;
99
+ setRotationDegreesX(x: number): void;
100
+ setRotationDegreesZ(z: number): void;
101
+ setRotation(x: number, y: number, z: number): void;
102
+ getRotation(): any;
103
+ body: RigidBody | null;
104
+ group: any;
105
+ };
106
+ } & T;
107
+ /**
108
+ * Enhance an entity instance with rotatable methods
109
+ */
110
+ export declare function makeRotatable<T extends RotatableEntity>(entity: T): T & RotatableEntityAPI;
@@ -0,0 +1,6 @@
1
+ import { EntityWithBody, MoveableEntity } from './moveable';
2
+ import { RotatableEntity, RotatableEntityAPI } from './rotatable';
3
+ /**
4
+ * Enhance an entity with both movement and rotation capabilities.
5
+ */
6
+ export declare function makeTransformable<T extends RotatableEntity & EntityWithBody>(entity: T): T & MoveableEntity & RotatableEntityAPI;
@@ -0,0 +1,12 @@
1
+ import { UpdateContext } from "../core/base-node-life-cycle";
2
+ /**
3
+ * Listen for a single global key change inside an onUpdate pipeline.
4
+ * Usage: onUpdate(globalChange('p1Score', (value) => { ... }))
5
+ */
6
+ export declare function globalChange<T = any>(key: string, callback: (value: T, ctx: UpdateContext<any>) => void): (ctx: UpdateContext<any>) => void;
7
+ /**
8
+ * Listen for multiple global key changes inside an onUpdate pipeline.
9
+ * Calls back when any of the provided keys changes.
10
+ * Usage: onUpdate(globalChanges(['p1Score','p2Score'], ([p1,p2]) => { ... }))
11
+ */
12
+ export declare function globalChanges<T = any>(keys: string[], callback: (values: T[], ctx: UpdateContext<any>) => void): (ctx: UpdateContext<any>) => void;
@@ -0,0 +1,15 @@
1
+ import { Vector2, Vector3 } from "three";
2
+ import { PerspectiveType } from "./perspective";
3
+ import { ZylemCamera } from "./zylem-camera";
4
+ export interface CameraOptions {
5
+ perspective?: PerspectiveType;
6
+ position?: Vector3;
7
+ target?: Vector3;
8
+ zoom?: number;
9
+ screenResolution?: Vector2;
10
+ }
11
+ export declare class CameraWrapper {
12
+ cameraRef: ZylemCamera;
13
+ constructor(camera: ZylemCamera);
14
+ }
15
+ export declare function camera(options: CameraOptions): CameraWrapper;
@@ -0,0 +1,31 @@
1
+ import { Scene, Vector2, WebGLRenderer } from 'three';
2
+ import { PerspectiveController, ZylemCamera } from './zylem-camera';
3
+ /**
4
+ * Fixed 2D Camera Controller
5
+ * Maintains a static 2D camera view with no automatic following or movement
6
+ */
7
+ export declare class Fixed2DCamera implements PerspectiveController {
8
+ screenResolution: Vector2 | null;
9
+ renderer: WebGLRenderer | null;
10
+ scene: Scene | null;
11
+ cameraRef: ZylemCamera | null;
12
+ constructor();
13
+ /**
14
+ * Setup the fixed 2D camera controller
15
+ */
16
+ setup(params: {
17
+ screenResolution: Vector2;
18
+ renderer: WebGLRenderer;
19
+ scene: Scene;
20
+ camera: ZylemCamera;
21
+ }): void;
22
+ /**
23
+ * Update the fixed 2D camera
24
+ * Fixed cameras don't need to update position/rotation automatically
25
+ */
26
+ update(delta: number): void;
27
+ /**
28
+ * Handle resize events for 2D camera
29
+ */
30
+ resize(width: number, height: number): void;
31
+ }
@@ -0,0 +1,8 @@
1
+ export declare const Perspectives: {
2
+ readonly FirstPerson: "first-person";
3
+ readonly ThirdPerson: "third-person";
4
+ readonly Isometric: "isometric";
5
+ readonly Flat2D: "flat-2d";
6
+ readonly Fixed2D: "fixed-2d";
7
+ };
8
+ export type PerspectiveType = (typeof Perspectives)[keyof typeof Perspectives];
@@ -0,0 +1,39 @@
1
+ import { Scene, Vector2, Vector3, WebGLRenderer } from 'three';
2
+ import { PerspectiveController, ZylemCamera } from './zylem-camera';
3
+ import { StageEntity } from '../interfaces/entity';
4
+ export interface ThirdPersonCameraOptions {
5
+ target: StageEntity;
6
+ distance: Vector3;
7
+ screenResolution: Vector2;
8
+ renderer: WebGLRenderer;
9
+ scene: Scene;
10
+ }
11
+ export declare class ThirdPersonCamera implements PerspectiveController {
12
+ distance: Vector3;
13
+ screenResolution: Vector2 | null;
14
+ renderer: WebGLRenderer | null;
15
+ scene: Scene | null;
16
+ cameraRef: ZylemCamera | null;
17
+ constructor();
18
+ /**
19
+ * Setup the third person camera controller
20
+ */
21
+ setup(params: {
22
+ screenResolution: Vector2;
23
+ renderer: WebGLRenderer;
24
+ scene: Scene;
25
+ camera: ZylemCamera;
26
+ }): void;
27
+ /**
28
+ * Update the third person camera
29
+ */
30
+ update(delta: number): void;
31
+ /**
32
+ * Handle resize events
33
+ */
34
+ resize(width: number, height: number): void;
35
+ /**
36
+ * Set the distance from the target
37
+ */
38
+ setDistance(distance: Vector3): void;
39
+ }