@zylem/game-lib 0.3.15 → 0.3.16
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/dist/.vite/manifest.json +595 -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.js +58 -0
- package/dist/lib/core/entity-asset-loader.js +57 -0
- 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.js +20 -0
- package/dist/lib/core/vessel.js +23 -0
- package/dist/lib/debug/console/console-state.js +11 -0
- package/dist/lib/debug/debug-state.js +40 -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.js +116 -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-state.js +17 -0
- package/dist/lib/game/game.js +157 -0
- package/dist/lib/game/zylem-game.js +107 -0
- package/dist/lib/graphics/geometries/XZPlaneGeometry.js +34 -0
- 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.js +89 -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-debug-delegate.js +100 -0
- package/dist/lib/stage/stage-state.js +36 -0
- package/dist/lib/stage/stage.js +58 -0
- package/dist/lib/stage/zylem-stage.js +279 -0
- package/dist/lib/systems/transformable.system.js +43 -0
- package/dist/main.d.ts +4 -14
- package/dist/main.js +54 -45933
- package/dist/stage.d.ts +3 -0
- package/dist/stage.js +6 -0
- package/package.json +35 -1
- package/dist/lib/actions/behaviors/index.d.ts +0 -1
- 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
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
update = () => {
|
|
12
|
+
};
|
|
13
|
+
setup = () => {
|
|
14
|
+
};
|
|
15
|
+
destroy = () => {
|
|
16
|
+
};
|
|
17
|
+
constructor(t = []) {
|
|
18
|
+
const e = t.filter((i) => !(i instanceof s)).reduce((i, n) => ({ ...i, ...n }), {});
|
|
19
|
+
this.options = e, this.uuid = o();
|
|
20
|
+
}
|
|
21
|
+
setParent(t) {
|
|
22
|
+
this.parent = t;
|
|
23
|
+
}
|
|
24
|
+
getParent() {
|
|
25
|
+
return this.parent;
|
|
26
|
+
}
|
|
27
|
+
add(t) {
|
|
28
|
+
this.children.push(t), t.setParent(this);
|
|
29
|
+
}
|
|
30
|
+
remove(t) {
|
|
31
|
+
const e = this.children.indexOf(t);
|
|
32
|
+
e !== -1 && (this.children.splice(e, 1), t.setParent(null));
|
|
33
|
+
}
|
|
34
|
+
getChildren() {
|
|
35
|
+
return this.children;
|
|
36
|
+
}
|
|
37
|
+
isComposite() {
|
|
38
|
+
return this.children.length > 0;
|
|
39
|
+
}
|
|
40
|
+
nodeSetup(t) {
|
|
41
|
+
typeof this._setup == "function" && this._setup(t), this.setup && this.setup(t), this.children.forEach((e) => e.nodeSetup(t));
|
|
42
|
+
}
|
|
43
|
+
nodeUpdate(t) {
|
|
44
|
+
this.markedForRemoval || (typeof this._update == "function" && this._update(t), this.update && this.update(t), this.children.forEach((e) => e.nodeUpdate(t)));
|
|
45
|
+
}
|
|
46
|
+
nodeDestroy(t) {
|
|
47
|
+
this.children.forEach((e) => e.nodeDestroy(t)), this.destroy && this.destroy(t), typeof this._destroy == "function" && this._destroy(t), this.markedForRemoval = !0;
|
|
48
|
+
}
|
|
49
|
+
getOptions() {
|
|
50
|
+
return this.options;
|
|
51
|
+
}
|
|
52
|
+
setOptions(t) {
|
|
53
|
+
this.options = { ...this.options, ...t };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export {
|
|
57
|
+
s as BaseNode
|
|
58
|
+
};
|
|
@@ -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
|
+
};
|
|
@@ -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,20 @@
|
|
|
1
|
+
import { Color as i } from "three";
|
|
2
|
+
import { Vector3 as n } from "@dimforge/rapier3d-compat";
|
|
3
|
+
const u = new i("#0333EC");
|
|
4
|
+
function f(r) {
|
|
5
|
+
const e = Object.keys(r).sort().reduce((t, o) => (t[o] = r[o], t), {});
|
|
6
|
+
return JSON.stringify(e);
|
|
7
|
+
}
|
|
8
|
+
function h(r) {
|
|
9
|
+
let e = 0;
|
|
10
|
+
for (let t = 0; t < r.length; t++)
|
|
11
|
+
e = Math.imul(31, e) + r.charCodeAt(t) | 0;
|
|
12
|
+
return e.toString(36);
|
|
13
|
+
}
|
|
14
|
+
new n(0, 0, 0);
|
|
15
|
+
new n(1, 1, 1);
|
|
16
|
+
export {
|
|
17
|
+
u as ZylemBlueColor,
|
|
18
|
+
h as shortHash,
|
|
19
|
+
f as sortedStringify
|
|
20
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { BaseNode as a } from "./base-node.js";
|
|
2
|
+
const r = Symbol("vessel");
|
|
3
|
+
class n extends a {
|
|
4
|
+
static type = r;
|
|
5
|
+
_setup(e) {
|
|
6
|
+
}
|
|
7
|
+
_update(e) {
|
|
8
|
+
}
|
|
9
|
+
_destroy(e) {
|
|
10
|
+
}
|
|
11
|
+
create() {
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function c(...s) {
|
|
16
|
+
const e = new n();
|
|
17
|
+
return s.forEach((t) => e.add(t)), e;
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
r as VESSEL_TYPE,
|
|
21
|
+
n as Vessel,
|
|
22
|
+
c as vessel
|
|
23
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { proxy as s } from "valtio/vanilla";
|
|
2
|
+
import { printToConsole as t } from "./console/console-state.js";
|
|
3
|
+
const n = {
|
|
4
|
+
NONE: "NONE",
|
|
5
|
+
SELECT: "SELECT",
|
|
6
|
+
DELETE: "DELETE"
|
|
7
|
+
}, o = s({
|
|
8
|
+
on: !1,
|
|
9
|
+
paused: !1,
|
|
10
|
+
configuration: {
|
|
11
|
+
showCollisionBounds: !1,
|
|
12
|
+
showModelBounds: !1,
|
|
13
|
+
showSpriteBounds: !1
|
|
14
|
+
},
|
|
15
|
+
hovered: null,
|
|
16
|
+
selected: [],
|
|
17
|
+
tool: n.NONE
|
|
18
|
+
}), r = (e = !1) => {
|
|
19
|
+
o.on = e;
|
|
20
|
+
}, u = (e) => {
|
|
21
|
+
o.selected.push(e);
|
|
22
|
+
}, E = () => o.tool, a = (e) => {
|
|
23
|
+
o.hovered = e;
|
|
24
|
+
}, c = () => {
|
|
25
|
+
o.hovered = null;
|
|
26
|
+
}, i = () => o.hovered, f = (e) => {
|
|
27
|
+
o.paused = e, t(e ? "Paused" : "Resumed");
|
|
28
|
+
}, p = () => o.paused;
|
|
29
|
+
export {
|
|
30
|
+
n as DebugTools,
|
|
31
|
+
o as debugState,
|
|
32
|
+
E as getDebugTool,
|
|
33
|
+
i as getHoveredEntity,
|
|
34
|
+
p as isPaused,
|
|
35
|
+
c as resetHoveredEntity,
|
|
36
|
+
r as setDebugFlag,
|
|
37
|
+
a as setHoveredEntity,
|
|
38
|
+
f as setPaused,
|
|
39
|
+
u as setSelectedEntity
|
|
40
|
+
};
|