@zylem/game-lib 0.3.15 → 0.3.17
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 +38 -13
- package/dist/.vite/manifest.json +665 -2
- package/dist/actions.d.ts +4 -0
- package/dist/actions.js +10 -0
- package/dist/behaviors.d.ts +3 -0
- package/dist/behaviors.js +8 -0
- package/dist/camera.d.ts +3 -0
- package/dist/camera.js +6 -0
- package/dist/core.d.ts +5 -0
- package/dist/core.js +11 -0
- package/dist/entities.d.ts +8 -0
- package/dist/entities.js +19 -0
- package/dist/lib/actions/behaviors/actions.js +35 -0
- package/dist/lib/actions/behaviors/boundaries/boundary.d.ts +1 -1
- package/dist/lib/actions/behaviors/boundaries/boundary.js +40 -0
- package/dist/lib/actions/behaviors/ricochet/ricochet-2d-collision.js +100 -0
- package/dist/lib/actions/behaviors/ricochet/ricochet-2d-in-bounds.js +37 -0
- package/dist/lib/actions/behaviors/ricochet/ricochet.d.ts +2 -0
- package/dist/lib/actions/behaviors/ricochet/ricochet.js +6 -0
- package/dist/lib/actions/capabilities/moveable.js +108 -0
- package/dist/lib/actions/capabilities/rotatable.js +82 -0
- package/dist/lib/actions/capabilities/transformable.js +9 -0
- package/dist/lib/actions/global-change.js +40 -0
- package/dist/lib/camera/camera.js +19 -0
- package/dist/lib/camera/fixed-2d.js +30 -0
- package/dist/lib/camera/perspective.js +10 -0
- package/dist/lib/camera/third-person.js +42 -0
- package/dist/lib/camera/zylem-camera.js +145 -0
- package/dist/lib/collision/collision-builder.js +46 -0
- package/dist/lib/collision/collision-delegate.js +6 -0
- package/dist/lib/collision/utils.js +24 -0
- package/dist/lib/collision/world.js +77 -0
- package/dist/lib/core/base-node-life-cycle.d.ts +14 -0
- package/dist/lib/core/base-node.d.ts +6 -2
- package/dist/lib/core/base-node.js +62 -0
- package/dist/lib/core/entity-asset-loader.js +57 -0
- package/dist/lib/core/lazy-loader.d.ts +2 -2
- package/dist/lib/core/lifecycle-base.js +20 -0
- package/dist/lib/core/preset-shader.js +30 -0
- package/dist/lib/core/three-addons/Timer.js +103 -0
- package/dist/lib/core/utility/nodes.d.ts +11 -0
- package/dist/lib/core/utility/nodes.js +27 -0
- package/dist/lib/core/utility/strings.d.ts +2 -0
- package/dist/lib/core/utility/strings.js +14 -0
- package/dist/lib/core/{utility.d.ts → utility/vector.d.ts} +0 -2
- package/dist/lib/core/utility/vector.js +8 -0
- package/dist/lib/core/vessel.d.ts +3 -1
- package/dist/lib/core/vessel.js +27 -0
- package/dist/lib/debug/console/console-state.js +11 -0
- package/dist/lib/debug/debug-state.js +40 -0
- package/dist/lib/device/aspect-ratio.d.ts +37 -0
- package/dist/lib/device/aspect-ratio.js +44 -0
- package/dist/lib/entities/actor.js +125 -0
- package/dist/lib/entities/box.js +68 -0
- package/dist/lib/entities/builder.js +79 -0
- package/dist/lib/entities/create.js +31 -0
- package/dist/lib/entities/delegates/animation.js +58 -0
- package/dist/lib/entities/delegates/debug.js +72 -0
- package/dist/lib/entities/delegates/loader.js +19 -0
- package/dist/lib/entities/destroy.js +15 -0
- package/dist/lib/entities/entity.d.ts +3 -1
- package/dist/lib/entities/entity.js +120 -0
- package/dist/lib/entities/plane.js +81 -0
- package/dist/lib/entities/rect.js +160 -0
- package/dist/lib/entities/sphere.js +68 -0
- package/dist/lib/entities/sprite.js +118 -0
- package/dist/lib/entities/text.js +111 -0
- package/dist/lib/entities/zone.js +103 -0
- package/dist/lib/game/game-blueprint.d.ts +44 -0
- package/dist/lib/game/game-canvas.d.ts +34 -0
- package/dist/lib/game/game-canvas.js +57 -0
- package/dist/lib/game/game-config.d.ts +47 -0
- package/dist/lib/game/game-config.js +53 -0
- package/dist/lib/game/game-default.d.ts +18 -0
- package/dist/lib/game/game-default.js +24 -0
- package/dist/lib/game/game-state.js +17 -0
- package/dist/lib/game/game.d.ts +2 -5
- package/dist/lib/game/game.js +133 -0
- package/dist/lib/game/zylem-game.d.ts +12 -1
- package/dist/lib/game/zylem-game.js +133 -0
- package/dist/lib/graphics/geometries/XZPlaneGeometry.js +34 -0
- package/dist/lib/graphics/material.d.ts +1 -1
- package/dist/lib/graphics/material.js +64 -0
- package/dist/lib/graphics/mesh.js +14 -0
- package/dist/lib/graphics/render-pass.js +56 -0
- package/dist/lib/graphics/shaders/fragment/debug.glsl.js +23 -0
- package/dist/lib/graphics/shaders/fragment/fire.glsl.js +52 -0
- package/dist/lib/graphics/shaders/fragment/standard.glsl.js +11 -0
- package/dist/lib/graphics/shaders/fragment/stars.glsl.js +44 -0
- package/dist/lib/graphics/shaders/vertex/debug.glsl.js +15 -0
- package/dist/lib/graphics/shaders/vertex/object-shader.glsl.js +11 -0
- package/dist/lib/graphics/shaders/vertex/standard.glsl.js +9 -0
- package/dist/lib/graphics/zylem-scene.d.ts +7 -7
- package/dist/lib/graphics/zylem-scene.js +75 -0
- package/dist/lib/input/gamepad-provider.js +58 -0
- package/dist/lib/input/input-manager.js +70 -0
- package/dist/lib/input/keyboard-provider.js +120 -0
- package/dist/lib/stage/debug-entity-cursor.js +53 -0
- package/dist/lib/stage/entity-spawner.js +27 -0
- package/dist/lib/stage/stage-blueprint.d.ts +44 -0
- package/dist/lib/stage/stage-blueprint.js +56 -0
- package/dist/lib/stage/stage-debug-delegate.js +100 -0
- package/dist/lib/stage/stage-default.d.ts +9 -0
- package/dist/lib/stage/stage-default.js +42 -0
- package/dist/lib/stage/stage-state.js +36 -0
- package/dist/lib/stage/stage.d.ts +2 -2
- package/dist/lib/stage/stage.js +60 -0
- package/dist/lib/stage/zylem-stage.d.ts +4 -3
- package/dist/lib/stage/zylem-stage.js +268 -0
- package/dist/lib/systems/transformable.system.js +43 -0
- package/dist/main.d.ts +6 -15
- package/dist/main.js +56 -45933
- package/dist/stage.d.ts +6 -0
- package/dist/stage.js +22 -0
- package/dist/tests/stage/stage-blueprint.spec.d.ts +1 -0
- package/package.json +35 -1
- package/dist/lib/actions/behaviors/index.d.ts +0 -1
- package/dist/lib/core/game-canvas.d.ts +0 -4
- package/dist/main.cjs +0 -4023
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { WebGLRenderer as c, Object3D as m, Vector3 as h, PerspectiveCamera as a, OrthographicCamera as o } from "three";
|
|
2
|
+
import { OrbitControls as l } from "three/addons/controls/OrbitControls.js";
|
|
3
|
+
import { Perspectives as t } from "./perspective.js";
|
|
4
|
+
import { ThirdPersonCamera as n } from "./third-person.js";
|
|
5
|
+
import { Fixed2DCamera as p } from "./fixed-2d.js";
|
|
6
|
+
import { EffectComposer as u } from "three/examples/jsm/postprocessing/EffectComposer.js";
|
|
7
|
+
import d from "../graphics/render-pass.js";
|
|
8
|
+
class S {
|
|
9
|
+
cameraRig;
|
|
10
|
+
camera;
|
|
11
|
+
screenResolution;
|
|
12
|
+
renderer;
|
|
13
|
+
composer;
|
|
14
|
+
_perspective;
|
|
15
|
+
orbitControls = null;
|
|
16
|
+
target = null;
|
|
17
|
+
sceneRef = null;
|
|
18
|
+
frustumSize = 10;
|
|
19
|
+
// Perspective controller delegation
|
|
20
|
+
perspectiveController = null;
|
|
21
|
+
constructor(e, r, s = 10) {
|
|
22
|
+
this._perspective = e, this.screenResolution = r, this.frustumSize = s, this.renderer = new c({ antialias: !1, alpha: !0 }), this.renderer.setSize(r.x, r.y), this.renderer.shadowMap.enabled = !0, this.composer = new u(this.renderer);
|
|
23
|
+
const i = r.x / r.y;
|
|
24
|
+
this.camera = this.createCameraForPerspective(i), this.cameraRig = new m(), this.cameraRig.position.set(0, 3, 10), this.cameraRig.add(this.camera), this.camera.lookAt(new h(0, 2, 0)), this.initializePerspectiveController();
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Setup the camera with a scene
|
|
28
|
+
*/
|
|
29
|
+
async setup(e) {
|
|
30
|
+
this.sceneRef = e, this.orbitControls === null && (this.orbitControls = new l(this.camera, this.renderer.domElement), this.orbitControls.enableDamping = !0, this.orbitControls.dampingFactor = 0.05, this.orbitControls.screenSpacePanning = !1, this.orbitControls.minDistance = 1, this.orbitControls.maxDistance = 500, this.orbitControls.maxPolarAngle = Math.PI / 2);
|
|
31
|
+
let r = this.screenResolution.clone().divideScalar(2);
|
|
32
|
+
r.x |= 0, r.y |= 0;
|
|
33
|
+
const s = new d(r, e, this.camera);
|
|
34
|
+
this.composer.addPass(s), this.perspectiveController && this.perspectiveController.setup({
|
|
35
|
+
screenResolution: this.screenResolution,
|
|
36
|
+
renderer: this.renderer,
|
|
37
|
+
scene: e,
|
|
38
|
+
camera: this
|
|
39
|
+
}), this.renderer.setAnimationLoop((i) => {
|
|
40
|
+
this.update(i || 0);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Update camera and render
|
|
45
|
+
*/
|
|
46
|
+
update(e) {
|
|
47
|
+
this.orbitControls?.update(), this.perspectiveController && this.perspectiveController.update(e), this.composer.render(e);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Dispose renderer, composer, controls, and detach from scene
|
|
51
|
+
*/
|
|
52
|
+
destroy() {
|
|
53
|
+
try {
|
|
54
|
+
this.renderer.setAnimationLoop(null);
|
|
55
|
+
} catch {
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
this.orbitControls?.dispose(), this.orbitControls = null;
|
|
59
|
+
} catch {
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
this.composer?.passes?.forEach((e) => e.dispose?.()), this.composer?.dispose?.();
|
|
63
|
+
} catch {
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
this.renderer.dispose();
|
|
67
|
+
} catch {
|
|
68
|
+
}
|
|
69
|
+
this.sceneRef = null;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Resize camera and renderer
|
|
73
|
+
*/
|
|
74
|
+
resize(e, r) {
|
|
75
|
+
this.screenResolution.set(e, r), this.renderer.setSize(e, r, !0), this.composer.setSize(e, r), this.camera instanceof a && (this.camera.aspect = e / r, this.camera.updateProjectionMatrix()), this.perspectiveController && this.perspectiveController.resize(e, r);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Create camera based on perspective type
|
|
79
|
+
*/
|
|
80
|
+
createCameraForPerspective(e) {
|
|
81
|
+
switch (this._perspective) {
|
|
82
|
+
case t.ThirdPerson:
|
|
83
|
+
return this.createThirdPersonCamera(e);
|
|
84
|
+
case t.FirstPerson:
|
|
85
|
+
return this.createFirstPersonCamera(e);
|
|
86
|
+
case t.Isometric:
|
|
87
|
+
return this.createIsometricCamera(e);
|
|
88
|
+
case t.Flat2D:
|
|
89
|
+
return this.createFlat2DCamera(e);
|
|
90
|
+
case t.Fixed2D:
|
|
91
|
+
return this.createFixed2DCamera(e);
|
|
92
|
+
default:
|
|
93
|
+
return this.createThirdPersonCamera(e);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Initialize perspective-specific controller
|
|
98
|
+
*/
|
|
99
|
+
initializePerspectiveController() {
|
|
100
|
+
switch (this._perspective) {
|
|
101
|
+
case t.ThirdPerson:
|
|
102
|
+
this.perspectiveController = new n();
|
|
103
|
+
break;
|
|
104
|
+
case t.Fixed2D:
|
|
105
|
+
this.perspectiveController = new p();
|
|
106
|
+
break;
|
|
107
|
+
default:
|
|
108
|
+
this.perspectiveController = new n();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
createThirdPersonCamera(e) {
|
|
112
|
+
return new a(75, e, 0.1, 1e3);
|
|
113
|
+
}
|
|
114
|
+
createFirstPersonCamera(e) {
|
|
115
|
+
return new a(75, e, 0.1, 1e3);
|
|
116
|
+
}
|
|
117
|
+
createIsometricCamera(e) {
|
|
118
|
+
return new o(this.frustumSize * e / -2, this.frustumSize * e / 2, this.frustumSize / 2, this.frustumSize / -2, 1, 1e3);
|
|
119
|
+
}
|
|
120
|
+
createFlat2DCamera(e) {
|
|
121
|
+
return new o(this.frustumSize * e / -2, this.frustumSize * e / 2, this.frustumSize / 2, this.frustumSize / -2, 1, 1e3);
|
|
122
|
+
}
|
|
123
|
+
createFixed2DCamera(e) {
|
|
124
|
+
return this.createFlat2DCamera(e);
|
|
125
|
+
}
|
|
126
|
+
// Movement methods
|
|
127
|
+
moveCamera(e) {
|
|
128
|
+
(this._perspective === t.Flat2D || this._perspective === t.Fixed2D) && (this.frustumSize = e.z), this.cameraRig.position.set(e.x, e.y, e.z);
|
|
129
|
+
}
|
|
130
|
+
move(e) {
|
|
131
|
+
this.moveCamera(e);
|
|
132
|
+
}
|
|
133
|
+
rotate(e, r, s) {
|
|
134
|
+
this.cameraRig.rotateX(e), this.cameraRig.rotateY(r), this.cameraRig.rotateZ(s);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get the DOM element for the renderer
|
|
138
|
+
*/
|
|
139
|
+
getDomElement() {
|
|
140
|
+
return this.renderer.domElement;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
export {
|
|
144
|
+
S as ZylemCamera
|
|
145
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Vector3 as r, ActiveCollisionTypes as f, ColliderDesc as p, RigidBodyType as c, RigidBodyDesc as D } from "@dimforge/rapier3d-compat";
|
|
2
|
+
const n = /* @__PURE__ */ new Map();
|
|
3
|
+
let h = 0;
|
|
4
|
+
function d(i) {
|
|
5
|
+
let e = n.get(i);
|
|
6
|
+
return e === void 0 && (e = h++ % 16, n.set(i, e)), e;
|
|
7
|
+
}
|
|
8
|
+
function C(i) {
|
|
9
|
+
let e = 0;
|
|
10
|
+
return i.forEach((s) => {
|
|
11
|
+
const t = d(s);
|
|
12
|
+
e |= 1 << t;
|
|
13
|
+
}), e;
|
|
14
|
+
}
|
|
15
|
+
class g {
|
|
16
|
+
static = !1;
|
|
17
|
+
sensor = !1;
|
|
18
|
+
gravity = new r(0, 0, 0);
|
|
19
|
+
build(e) {
|
|
20
|
+
const s = this.bodyDesc({
|
|
21
|
+
isDynamicBody: !this.static
|
|
22
|
+
}), t = this.collider(e), o = e.collisionType;
|
|
23
|
+
if (o) {
|
|
24
|
+
let u = d(o), l = 65535;
|
|
25
|
+
e.collisionFilter && (l = C(e.collisionFilter)), t.setCollisionGroups(u << 16 | l);
|
|
26
|
+
}
|
|
27
|
+
const { KINEMATIC_FIXED: a, DEFAULT: y } = f;
|
|
28
|
+
return t.activeCollisionTypes = this.sensor ? a : y, [s, t];
|
|
29
|
+
}
|
|
30
|
+
withCollision(e) {
|
|
31
|
+
return this.sensor = e?.sensor ?? this.sensor, this.static = e?.static ?? this.static, this;
|
|
32
|
+
}
|
|
33
|
+
collider(e) {
|
|
34
|
+
const s = e.size ?? new r(1, 1, 1), t = { x: s.x / 2, y: s.y / 2, z: s.z / 2 };
|
|
35
|
+
return p.cuboid(t.x, t.y, t.z);
|
|
36
|
+
}
|
|
37
|
+
bodyDesc({ isDynamicBody: e = !0 }) {
|
|
38
|
+
const s = e ? c.Dynamic : c.Fixed;
|
|
39
|
+
return new D(s).setTranslation(0, 0, 0).setGravityScale(1).setCanSleep(!1).setCcdEnabled(!0);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
g as CollisionBuilder,
|
|
44
|
+
C as createCollisionFilter,
|
|
45
|
+
d as getOrCreateCollisionGroupId
|
|
46
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { getOrCreateCollisionGroupId as o } from "./collision-builder.js";
|
|
2
|
+
function u(i, n) {
|
|
3
|
+
if (!n)
|
|
4
|
+
return !0;
|
|
5
|
+
const r = i.name ?? "";
|
|
6
|
+
if ("name" in n) {
|
|
7
|
+
const e = n.name;
|
|
8
|
+
return e instanceof RegExp ? e.test(r) : Array.isArray(e) ? e.some((t) => t === r) : r === e;
|
|
9
|
+
} else if ("mask" in n) {
|
|
10
|
+
const e = n.mask;
|
|
11
|
+
if (e instanceof RegExp) {
|
|
12
|
+
const t = i.collisionType ?? "";
|
|
13
|
+
return e.test(t);
|
|
14
|
+
} else {
|
|
15
|
+
const t = i.collisionType ?? "", s = o(t);
|
|
16
|
+
return (e & 1 << s) !== 0;
|
|
17
|
+
}
|
|
18
|
+
} else if ("test" in n)
|
|
19
|
+
return !!n.test(i);
|
|
20
|
+
return !0;
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
u as matchesCollisionSelector
|
|
24
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import d from "@dimforge/rapier3d-compat";
|
|
2
|
+
import { state as c } from "../game/game-state.js";
|
|
3
|
+
import { ZylemActor as h } from "../entities/actor.js";
|
|
4
|
+
import { isCollisionHandlerDelegate as n } from "./collision-delegate.js";
|
|
5
|
+
class v {
|
|
6
|
+
type = "World";
|
|
7
|
+
world;
|
|
8
|
+
collisionMap = /* @__PURE__ */ new Map();
|
|
9
|
+
collisionBehaviorMap = /* @__PURE__ */ new Map();
|
|
10
|
+
_removalMap = /* @__PURE__ */ new Map();
|
|
11
|
+
static async loadPhysics(o) {
|
|
12
|
+
return await d.init(), new d.World(o);
|
|
13
|
+
}
|
|
14
|
+
constructor(o) {
|
|
15
|
+
this.world = o;
|
|
16
|
+
}
|
|
17
|
+
addEntity(o) {
|
|
18
|
+
const i = this.world.createRigidBody(o.bodyDesc);
|
|
19
|
+
o.body = i, o.body.userData = { uuid: o.uuid, ref: o }, this.world.gravity.x === 0 && this.world.gravity.y === 0 && this.world.gravity.z === 0 && (o.body.lockTranslations(!0, !0), o.body.lockRotations(!0, !0));
|
|
20
|
+
const e = this.world.createCollider(o.colliderDesc, o.body);
|
|
21
|
+
o.collider = e, (o.controlledRotation || o instanceof h) && (o.body.lockRotations(!0, !0), o.characterController = this.world.createCharacterController(0.01), o.characterController.setMaxSlopeClimbAngle(45 * Math.PI / 180), o.characterController.setMinSlopeSlideAngle(30 * Math.PI / 180), o.characterController.enableSnapToGround(0.01), o.characterController.setSlideEnabled(!0), o.characterController.setApplyImpulsesToDynamicBodies(!0), o.characterController.setCharacterMass(1)), this.collisionMap.set(o.uuid, o);
|
|
22
|
+
}
|
|
23
|
+
setForRemoval(o) {
|
|
24
|
+
o.body && this._removalMap.set(o.uuid, o);
|
|
25
|
+
}
|
|
26
|
+
destroyEntity(o) {
|
|
27
|
+
o.collider && this.world.removeCollider(o.collider, !0), o.body && (this.world.removeRigidBody(o.body), this.collisionMap.delete(o.uuid), this._removalMap.delete(o.uuid));
|
|
28
|
+
}
|
|
29
|
+
setup() {
|
|
30
|
+
}
|
|
31
|
+
update(o) {
|
|
32
|
+
const { delta: i } = o;
|
|
33
|
+
this.world && (this.updateColliders(i), this.updatePostCollisionBehaviors(i), this.world.step());
|
|
34
|
+
}
|
|
35
|
+
updatePostCollisionBehaviors(o) {
|
|
36
|
+
const i = this.collisionBehaviorMap;
|
|
37
|
+
for (let [e, a] of i) {
|
|
38
|
+
const r = a;
|
|
39
|
+
if (!n(r))
|
|
40
|
+
return;
|
|
41
|
+
r.handlePostCollision({ entity: r, delta: o }) || this.collisionBehaviorMap.delete(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
updateColliders(o) {
|
|
45
|
+
const i = this.collisionMap;
|
|
46
|
+
for (let [e, a] of i) {
|
|
47
|
+
const r = a;
|
|
48
|
+
if (r.body) {
|
|
49
|
+
if (this._removalMap.get(r.uuid)) {
|
|
50
|
+
this.destroyEntity(r);
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
this.world.contactsWith(r.body.collider(0), (t) => {
|
|
54
|
+
const s = t._parent.userData.uuid, l = i.get(s);
|
|
55
|
+
l && r._collision && r._collision(l, c.globals);
|
|
56
|
+
}), this.world.intersectionsWith(r.body.collider(0), (t) => {
|
|
57
|
+
const s = t._parent.userData.uuid, l = i.get(s);
|
|
58
|
+
l && (r._collision && r._collision(l, c.globals), n(l) && (l.handleIntersectionEvent({ entity: l, other: r, delta: o }), this.collisionBehaviorMap.set(s, l)));
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
destroy() {
|
|
64
|
+
try {
|
|
65
|
+
for (const [, o] of this.collisionMap)
|
|
66
|
+
try {
|
|
67
|
+
this.destroyEntity(o);
|
|
68
|
+
} catch {
|
|
69
|
+
}
|
|
70
|
+
this.collisionMap.clear(), this.collisionBehaviorMap.clear(), this._removalMap.clear(), this.world = void 0;
|
|
71
|
+
} catch {
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export {
|
|
76
|
+
v as ZylemWorld
|
|
77
|
+
};
|
|
@@ -32,6 +32,13 @@ export interface SetupContext<T, TGlobals extends Record<string, unknown> = any>
|
|
|
32
32
|
export interface SetupFunction<T, TGlobals extends Record<string, unknown> = any> {
|
|
33
33
|
(context: SetupContext<T, TGlobals>): void;
|
|
34
34
|
}
|
|
35
|
+
export interface LoadedFunction<T, TGlobals extends Record<string, unknown> = any> {
|
|
36
|
+
(context: LoadedContext<T, TGlobals>): void;
|
|
37
|
+
}
|
|
38
|
+
export interface LoadedContext<T, TGlobals extends Record<string, unknown> = any> {
|
|
39
|
+
me: T;
|
|
40
|
+
globals: TGlobals;
|
|
41
|
+
}
|
|
35
42
|
export type UpdateContext<T, TGlobals extends Record<string, unknown> = any> = {
|
|
36
43
|
me: T;
|
|
37
44
|
delta: number;
|
|
@@ -51,3 +58,10 @@ export interface DestroyContext<T, TGlobals extends Record<string, unknown> = an
|
|
|
51
58
|
export interface DestroyFunction<T, TGlobals extends Record<string, unknown> = any> {
|
|
52
59
|
(context: DestroyContext<T, TGlobals>): void;
|
|
53
60
|
}
|
|
61
|
+
export interface CleanupFunction<T, TGlobals extends Record<string, unknown> = any> {
|
|
62
|
+
(context: CleanupContext<T, TGlobals>): void;
|
|
63
|
+
}
|
|
64
|
+
export interface CleanupContext<T, TGlobals extends Record<string, unknown> = any> {
|
|
65
|
+
me: T;
|
|
66
|
+
globals: TGlobals;
|
|
67
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Behavior } from "~/lib/actions/behaviors/behavior";
|
|
2
|
-
import { DestroyContext, DestroyFunction, SetupContext, SetupFunction, UpdateContext, UpdateFunction } from "./base-node-life-cycle";
|
|
2
|
+
import { CleanupContext, CleanupFunction, DestroyContext, DestroyFunction, LoadedContext, LoadedFunction, SetupContext, SetupFunction, UpdateContext, UpdateFunction } from "./base-node-life-cycle";
|
|
3
3
|
export type BaseNodeOptions<T = any> = BaseNode | Partial<T>;
|
|
4
4
|
export declare abstract class BaseNode<Options = any, T = any> {
|
|
5
5
|
protected parent: BaseNode | null;
|
|
@@ -10,9 +10,11 @@ export declare abstract class BaseNode<Options = any, T = any> {
|
|
|
10
10
|
uuid: string;
|
|
11
11
|
name: string;
|
|
12
12
|
markedForRemoval: boolean;
|
|
13
|
-
update: UpdateFunction<this>;
|
|
14
13
|
setup: SetupFunction<this>;
|
|
14
|
+
loaded: LoadedFunction<this>;
|
|
15
|
+
update: UpdateFunction<this>;
|
|
15
16
|
destroy: DestroyFunction<this>;
|
|
17
|
+
cleanup: CleanupFunction<this>;
|
|
16
18
|
constructor(args?: BaseNodeOptions[]);
|
|
17
19
|
setParent(parent: BaseNode | null): void;
|
|
18
20
|
getParent(): BaseNode | null;
|
|
@@ -22,8 +24,10 @@ export declare abstract class BaseNode<Options = any, T = any> {
|
|
|
22
24
|
isComposite(): boolean;
|
|
23
25
|
abstract create(): T;
|
|
24
26
|
protected abstract _setup(params: SetupContext<this>): void;
|
|
27
|
+
protected abstract _loaded(params: LoadedContext<this>): Promise<void>;
|
|
25
28
|
protected abstract _update(params: UpdateContext<this>): void;
|
|
26
29
|
protected abstract _destroy(params: DestroyContext<this>): void;
|
|
30
|
+
protected abstract _cleanup(params: CleanupContext<this>): Promise<void>;
|
|
27
31
|
nodeSetup(params: SetupContext<this>): void;
|
|
28
32
|
nodeUpdate(params: UpdateContext<this>): void;
|
|
29
33
|
nodeDestroy(params: DestroyContext<this>): void;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { nanoid as o } from "nanoid";
|
|
2
|
+
class s {
|
|
3
|
+
parent = null;
|
|
4
|
+
children = [];
|
|
5
|
+
behaviors = [];
|
|
6
|
+
options;
|
|
7
|
+
eid = 0;
|
|
8
|
+
uuid = "";
|
|
9
|
+
name = "";
|
|
10
|
+
markedForRemoval = !1;
|
|
11
|
+
setup = () => {
|
|
12
|
+
};
|
|
13
|
+
loaded = () => {
|
|
14
|
+
};
|
|
15
|
+
update = () => {
|
|
16
|
+
};
|
|
17
|
+
destroy = () => {
|
|
18
|
+
};
|
|
19
|
+
cleanup = () => {
|
|
20
|
+
};
|
|
21
|
+
constructor(t = []) {
|
|
22
|
+
const e = t.filter((i) => !(i instanceof s)).reduce((i, n) => ({ ...i, ...n }), {});
|
|
23
|
+
this.options = e, this.uuid = o();
|
|
24
|
+
}
|
|
25
|
+
setParent(t) {
|
|
26
|
+
this.parent = t;
|
|
27
|
+
}
|
|
28
|
+
getParent() {
|
|
29
|
+
return this.parent;
|
|
30
|
+
}
|
|
31
|
+
add(t) {
|
|
32
|
+
this.children.push(t), t.setParent(this);
|
|
33
|
+
}
|
|
34
|
+
remove(t) {
|
|
35
|
+
const e = this.children.indexOf(t);
|
|
36
|
+
e !== -1 && (this.children.splice(e, 1), t.setParent(null));
|
|
37
|
+
}
|
|
38
|
+
getChildren() {
|
|
39
|
+
return this.children;
|
|
40
|
+
}
|
|
41
|
+
isComposite() {
|
|
42
|
+
return this.children.length > 0;
|
|
43
|
+
}
|
|
44
|
+
nodeSetup(t) {
|
|
45
|
+
typeof this._setup == "function" && this._setup(t), this.setup && this.setup(t), this.children.forEach((e) => e.nodeSetup(t));
|
|
46
|
+
}
|
|
47
|
+
nodeUpdate(t) {
|
|
48
|
+
this.markedForRemoval || (typeof this._update == "function" && this._update(t), this.update && this.update(t), this.children.forEach((e) => e.nodeUpdate(t)));
|
|
49
|
+
}
|
|
50
|
+
nodeDestroy(t) {
|
|
51
|
+
this.children.forEach((e) => e.nodeDestroy(t)), this.destroy && this.destroy(t), typeof this._destroy == "function" && this._destroy(t), this.markedForRemoval = !0;
|
|
52
|
+
}
|
|
53
|
+
getOptions() {
|
|
54
|
+
return this.options;
|
|
55
|
+
}
|
|
56
|
+
setOptions(t) {
|
|
57
|
+
this.options = { ...this.options, ...t };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export {
|
|
61
|
+
s as BaseNode
|
|
62
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { FBXLoader as d } from "three/addons/loaders/FBXLoader.js";
|
|
2
|
+
import { GLTFLoader as i } from "three/addons/loaders/GLTFLoader.js";
|
|
3
|
+
var t;
|
|
4
|
+
(function(r) {
|
|
5
|
+
r.FBX = "fbx", r.GLTF = "gltf";
|
|
6
|
+
})(t || (t = {}));
|
|
7
|
+
class l {
|
|
8
|
+
loader = new d();
|
|
9
|
+
isSupported(e) {
|
|
10
|
+
return e.toLowerCase().endsWith(t.FBX);
|
|
11
|
+
}
|
|
12
|
+
async load(e) {
|
|
13
|
+
return new Promise((o, s) => {
|
|
14
|
+
this.loader.load(e, (a) => {
|
|
15
|
+
const n = a.animations[0];
|
|
16
|
+
o({
|
|
17
|
+
object: a,
|
|
18
|
+
animation: n
|
|
19
|
+
});
|
|
20
|
+
}, void 0, s);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
class p {
|
|
25
|
+
loader = new i();
|
|
26
|
+
isSupported(e) {
|
|
27
|
+
return e.toLowerCase().endsWith(t.GLTF);
|
|
28
|
+
}
|
|
29
|
+
async load(e) {
|
|
30
|
+
return new Promise((o, s) => {
|
|
31
|
+
this.loader.load(e, (a) => {
|
|
32
|
+
o({
|
|
33
|
+
object: a.scene,
|
|
34
|
+
gltf: a
|
|
35
|
+
});
|
|
36
|
+
}, void 0, s);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
class u {
|
|
41
|
+
loaders = [
|
|
42
|
+
new l(),
|
|
43
|
+
new p()
|
|
44
|
+
];
|
|
45
|
+
async loadFile(e) {
|
|
46
|
+
const o = this.loaders.find((s) => s.isSupported(e));
|
|
47
|
+
if (!o)
|
|
48
|
+
throw new Error(`Unsupported file type: ${e}`);
|
|
49
|
+
return o.load(e);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
u as EntityAssetLoader,
|
|
54
|
+
l as FBXAssetLoader,
|
|
55
|
+
t as FileExtensionTypes,
|
|
56
|
+
p as GLTFAssetLoader
|
|
57
|
+
};
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
export declare const loadFoundation: () => Promise<{
|
|
15
15
|
baseNode: typeof import("./base-node");
|
|
16
16
|
lifeCycle: typeof import("./base-node-life-cycle");
|
|
17
|
-
utility: typeof import("./utility");
|
|
17
|
+
utility: typeof import("./utility/vector");
|
|
18
18
|
vector: typeof import("./vector");
|
|
19
19
|
}>;
|
|
20
20
|
export declare const loadState: () => Promise<typeof import("../game/game-state")>;
|
|
@@ -48,7 +48,7 @@ export declare const loadFullGame: () => Promise<{
|
|
|
48
48
|
foundation: {
|
|
49
49
|
baseNode: typeof import("./base-node");
|
|
50
50
|
lifeCycle: typeof import("./base-node-life-cycle");
|
|
51
|
-
utility: typeof import("./utility");
|
|
51
|
+
utility: typeof import("./utility/vector");
|
|
52
52
|
vector: typeof import("./vector");
|
|
53
53
|
};
|
|
54
54
|
state: typeof import("../game/game-state");
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
class e {
|
|
2
|
+
update = () => {
|
|
3
|
+
};
|
|
4
|
+
setup = () => {
|
|
5
|
+
};
|
|
6
|
+
destroy = () => {
|
|
7
|
+
};
|
|
8
|
+
nodeSetup(t) {
|
|
9
|
+
typeof this._setup == "function" && this._setup(t), this.setup && this.setup(t);
|
|
10
|
+
}
|
|
11
|
+
nodeUpdate(t) {
|
|
12
|
+
typeof this._update == "function" && this._update(t), this.update && this.update(t);
|
|
13
|
+
}
|
|
14
|
+
nodeDestroy(t) {
|
|
15
|
+
this.destroy && this.destroy(t), typeof this._destroy == "function" && this._destroy(t);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
e as LifeCycleBase
|
|
20
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import r from "../graphics/shaders/fragment/stars.glsl.js";
|
|
2
|
+
import a from "../graphics/shaders/fragment/fire.glsl.js";
|
|
3
|
+
import d from "../graphics/shaders/fragment/standard.glsl.js";
|
|
4
|
+
import f from "../graphics/shaders/fragment/debug.glsl.js";
|
|
5
|
+
import t from "../graphics/shaders/vertex/object-shader.glsl.js";
|
|
6
|
+
import o from "../graphics/shaders/vertex/debug.glsl.js";
|
|
7
|
+
const s = {
|
|
8
|
+
fragment: r,
|
|
9
|
+
vertex: t
|
|
10
|
+
}, m = {
|
|
11
|
+
fragment: a,
|
|
12
|
+
vertex: t
|
|
13
|
+
}, n = {
|
|
14
|
+
fragment: d,
|
|
15
|
+
vertex: t
|
|
16
|
+
}, u = {
|
|
17
|
+
fragment: f,
|
|
18
|
+
vertex: o
|
|
19
|
+
}, e = /* @__PURE__ */ new Map();
|
|
20
|
+
e.set("standard", n);
|
|
21
|
+
e.set("fire", m);
|
|
22
|
+
e.set("star", s);
|
|
23
|
+
e.set("debug", u);
|
|
24
|
+
export {
|
|
25
|
+
u as debugShader,
|
|
26
|
+
e as default,
|
|
27
|
+
m as fireShader,
|
|
28
|
+
n as standardShader,
|
|
29
|
+
s as starShader
|
|
30
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
class n {
|
|
2
|
+
_previousTime;
|
|
3
|
+
_currentTime;
|
|
4
|
+
_startTime;
|
|
5
|
+
_delta;
|
|
6
|
+
_elapsed;
|
|
7
|
+
_timescale;
|
|
8
|
+
_document;
|
|
9
|
+
_pageVisibilityHandler;
|
|
10
|
+
/**
|
|
11
|
+
* Constructs a new timer.
|
|
12
|
+
*/
|
|
13
|
+
constructor() {
|
|
14
|
+
this._previousTime = 0, this._currentTime = 0, this._startTime = e(), this._delta = 0, this._elapsed = 0, this._timescale = 1, this._document = null, this._pageVisibilityHandler = null;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Connect the timer to the given document.Calling this method is not mandatory to
|
|
18
|
+
* use the timer but enables the usage of the Page Visibility API to avoid large time
|
|
19
|
+
* delta values.
|
|
20
|
+
*
|
|
21
|
+
* @param {Document} document - The document.
|
|
22
|
+
*/
|
|
23
|
+
connect(i) {
|
|
24
|
+
this._document = i, i.hidden !== void 0 && (this._pageVisibilityHandler = t.bind(this), i.addEventListener("visibilitychange", this._pageVisibilityHandler, !1));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Disconnects the timer from the DOM and also disables the usage of the Page Visibility API.
|
|
28
|
+
*/
|
|
29
|
+
disconnect() {
|
|
30
|
+
this._pageVisibilityHandler !== null && (this._document.removeEventListener("visibilitychange", this._pageVisibilityHandler), this._pageVisibilityHandler = null), this._document = null;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Returns the time delta in seconds.
|
|
34
|
+
*
|
|
35
|
+
* @return {number} The time delta in second.
|
|
36
|
+
*/
|
|
37
|
+
getDelta() {
|
|
38
|
+
return this._delta / 1e3;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Returns the elapsed time in seconds.
|
|
42
|
+
*
|
|
43
|
+
* @return {number} The elapsed time in second.
|
|
44
|
+
*/
|
|
45
|
+
getElapsed() {
|
|
46
|
+
return this._elapsed / 1e3;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Returns the timescale.
|
|
50
|
+
*
|
|
51
|
+
* @return {number} The timescale.
|
|
52
|
+
*/
|
|
53
|
+
getTimescale() {
|
|
54
|
+
return this._timescale;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Sets the given timescale which scale the time delta computation
|
|
58
|
+
* in `update()`.
|
|
59
|
+
*
|
|
60
|
+
* @param {number} timescale - The timescale to set.
|
|
61
|
+
* @return {Timer} A reference to this timer.
|
|
62
|
+
*/
|
|
63
|
+
setTimescale(i) {
|
|
64
|
+
return this._timescale = i, this;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Resets the time computation for the current simulation step.
|
|
68
|
+
*
|
|
69
|
+
* @return {Timer} A reference to this timer.
|
|
70
|
+
*/
|
|
71
|
+
reset() {
|
|
72
|
+
return this._currentTime = e() - this._startTime, this;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Can be used to free all internal resources. Usually called when
|
|
76
|
+
* the timer instance isn't required anymore.
|
|
77
|
+
*/
|
|
78
|
+
dispose() {
|
|
79
|
+
this.disconnect();
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Updates the internal state of the timer. This method should be called
|
|
83
|
+
* once per simulation step and before you perform queries against the timer
|
|
84
|
+
* (e.g. via `getDelta()`).
|
|
85
|
+
*
|
|
86
|
+
* @param {number} timestamp - The current time in milliseconds. Can be obtained
|
|
87
|
+
* from the `requestAnimationFrame` callback argument. If not provided, the current
|
|
88
|
+
* time will be determined with `performance.now`.
|
|
89
|
+
* @return {Timer} A reference to this timer.
|
|
90
|
+
*/
|
|
91
|
+
update(i) {
|
|
92
|
+
return this._pageVisibilityHandler !== null && this._document.hidden === !0 ? this._delta = 0 : (this._previousTime = this._currentTime, this._currentTime = (i !== void 0 ? i : e()) - this._startTime, this._delta = (this._currentTime - this._previousTime) * this._timescale, this._elapsed += this._delta), this;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function e() {
|
|
96
|
+
return performance.now();
|
|
97
|
+
}
|
|
98
|
+
function t() {
|
|
99
|
+
this._document.hidden === !1 && this.reset();
|
|
100
|
+
}
|
|
101
|
+
export {
|
|
102
|
+
n as Timer
|
|
103
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseNode } from '../base-node';
|
|
2
|
+
import { Stage } from '../../stage/stage';
|
|
3
|
+
import { GameEntityLifeCycle } from '../../entities/entity';
|
|
4
|
+
import { BasicTypes, GlobalVariablesType, ZylemGameConfig } from '../../game/game-interfaces';
|
|
5
|
+
import { GameConfigLike } from '~/lib/game/game-config';
|
|
6
|
+
export type GameOptions<TGlobals extends Record<string, BasicTypes> = GlobalVariablesType> = Array<ZylemGameConfig<Stage, any, TGlobals> | GameConfigLike | Stage | GameEntityLifeCycle | BaseNode>;
|
|
7
|
+
export declare function convertNodes<TGlobals extends Record<string, BasicTypes> = GlobalVariablesType>(_options: GameOptions<TGlobals>): Promise<{
|
|
8
|
+
id: string;
|
|
9
|
+
globals: TGlobals;
|
|
10
|
+
stages: Stage[];
|
|
11
|
+
}>;
|