@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.
Files changed (119) hide show
  1. package/README.md +38 -13
  2. package/dist/.vite/manifest.json +665 -2
  3. package/dist/actions.d.ts +4 -0
  4. package/dist/actions.js +10 -0
  5. package/dist/behaviors.d.ts +3 -0
  6. package/dist/behaviors.js +8 -0
  7. package/dist/camera.d.ts +3 -0
  8. package/dist/camera.js +6 -0
  9. package/dist/core.d.ts +5 -0
  10. package/dist/core.js +11 -0
  11. package/dist/entities.d.ts +8 -0
  12. package/dist/entities.js +19 -0
  13. package/dist/lib/actions/behaviors/actions.js +35 -0
  14. package/dist/lib/actions/behaviors/boundaries/boundary.d.ts +1 -1
  15. package/dist/lib/actions/behaviors/boundaries/boundary.js +40 -0
  16. package/dist/lib/actions/behaviors/ricochet/ricochet-2d-collision.js +100 -0
  17. package/dist/lib/actions/behaviors/ricochet/ricochet-2d-in-bounds.js +37 -0
  18. package/dist/lib/actions/behaviors/ricochet/ricochet.d.ts +2 -0
  19. package/dist/lib/actions/behaviors/ricochet/ricochet.js +6 -0
  20. package/dist/lib/actions/capabilities/moveable.js +108 -0
  21. package/dist/lib/actions/capabilities/rotatable.js +82 -0
  22. package/dist/lib/actions/capabilities/transformable.js +9 -0
  23. package/dist/lib/actions/global-change.js +40 -0
  24. package/dist/lib/camera/camera.js +19 -0
  25. package/dist/lib/camera/fixed-2d.js +30 -0
  26. package/dist/lib/camera/perspective.js +10 -0
  27. package/dist/lib/camera/third-person.js +42 -0
  28. package/dist/lib/camera/zylem-camera.js +145 -0
  29. package/dist/lib/collision/collision-builder.js +46 -0
  30. package/dist/lib/collision/collision-delegate.js +6 -0
  31. package/dist/lib/collision/utils.js +24 -0
  32. package/dist/lib/collision/world.js +77 -0
  33. package/dist/lib/core/base-node-life-cycle.d.ts +14 -0
  34. package/dist/lib/core/base-node.d.ts +6 -2
  35. package/dist/lib/core/base-node.js +62 -0
  36. package/dist/lib/core/entity-asset-loader.js +57 -0
  37. package/dist/lib/core/lazy-loader.d.ts +2 -2
  38. package/dist/lib/core/lifecycle-base.js +20 -0
  39. package/dist/lib/core/preset-shader.js +30 -0
  40. package/dist/lib/core/three-addons/Timer.js +103 -0
  41. package/dist/lib/core/utility/nodes.d.ts +11 -0
  42. package/dist/lib/core/utility/nodes.js +27 -0
  43. package/dist/lib/core/utility/strings.d.ts +2 -0
  44. package/dist/lib/core/utility/strings.js +14 -0
  45. package/dist/lib/core/{utility.d.ts → utility/vector.d.ts} +0 -2
  46. package/dist/lib/core/utility/vector.js +8 -0
  47. package/dist/lib/core/vessel.d.ts +3 -1
  48. package/dist/lib/core/vessel.js +27 -0
  49. package/dist/lib/debug/console/console-state.js +11 -0
  50. package/dist/lib/debug/debug-state.js +40 -0
  51. package/dist/lib/device/aspect-ratio.d.ts +37 -0
  52. package/dist/lib/device/aspect-ratio.js +44 -0
  53. package/dist/lib/entities/actor.js +125 -0
  54. package/dist/lib/entities/box.js +68 -0
  55. package/dist/lib/entities/builder.js +79 -0
  56. package/dist/lib/entities/create.js +31 -0
  57. package/dist/lib/entities/delegates/animation.js +58 -0
  58. package/dist/lib/entities/delegates/debug.js +72 -0
  59. package/dist/lib/entities/delegates/loader.js +19 -0
  60. package/dist/lib/entities/destroy.js +15 -0
  61. package/dist/lib/entities/entity.d.ts +3 -1
  62. package/dist/lib/entities/entity.js +120 -0
  63. package/dist/lib/entities/plane.js +81 -0
  64. package/dist/lib/entities/rect.js +160 -0
  65. package/dist/lib/entities/sphere.js +68 -0
  66. package/dist/lib/entities/sprite.js +118 -0
  67. package/dist/lib/entities/text.js +111 -0
  68. package/dist/lib/entities/zone.js +103 -0
  69. package/dist/lib/game/game-blueprint.d.ts +44 -0
  70. package/dist/lib/game/game-canvas.d.ts +34 -0
  71. package/dist/lib/game/game-canvas.js +57 -0
  72. package/dist/lib/game/game-config.d.ts +47 -0
  73. package/dist/lib/game/game-config.js +53 -0
  74. package/dist/lib/game/game-default.d.ts +18 -0
  75. package/dist/lib/game/game-default.js +24 -0
  76. package/dist/lib/game/game-state.js +17 -0
  77. package/dist/lib/game/game.d.ts +2 -5
  78. package/dist/lib/game/game.js +133 -0
  79. package/dist/lib/game/zylem-game.d.ts +12 -1
  80. package/dist/lib/game/zylem-game.js +133 -0
  81. package/dist/lib/graphics/geometries/XZPlaneGeometry.js +34 -0
  82. package/dist/lib/graphics/material.d.ts +1 -1
  83. package/dist/lib/graphics/material.js +64 -0
  84. package/dist/lib/graphics/mesh.js +14 -0
  85. package/dist/lib/graphics/render-pass.js +56 -0
  86. package/dist/lib/graphics/shaders/fragment/debug.glsl.js +23 -0
  87. package/dist/lib/graphics/shaders/fragment/fire.glsl.js +52 -0
  88. package/dist/lib/graphics/shaders/fragment/standard.glsl.js +11 -0
  89. package/dist/lib/graphics/shaders/fragment/stars.glsl.js +44 -0
  90. package/dist/lib/graphics/shaders/vertex/debug.glsl.js +15 -0
  91. package/dist/lib/graphics/shaders/vertex/object-shader.glsl.js +11 -0
  92. package/dist/lib/graphics/shaders/vertex/standard.glsl.js +9 -0
  93. package/dist/lib/graphics/zylem-scene.d.ts +7 -7
  94. package/dist/lib/graphics/zylem-scene.js +75 -0
  95. package/dist/lib/input/gamepad-provider.js +58 -0
  96. package/dist/lib/input/input-manager.js +70 -0
  97. package/dist/lib/input/keyboard-provider.js +120 -0
  98. package/dist/lib/stage/debug-entity-cursor.js +53 -0
  99. package/dist/lib/stage/entity-spawner.js +27 -0
  100. package/dist/lib/stage/stage-blueprint.d.ts +44 -0
  101. package/dist/lib/stage/stage-blueprint.js +56 -0
  102. package/dist/lib/stage/stage-debug-delegate.js +100 -0
  103. package/dist/lib/stage/stage-default.d.ts +9 -0
  104. package/dist/lib/stage/stage-default.js +42 -0
  105. package/dist/lib/stage/stage-state.js +36 -0
  106. package/dist/lib/stage/stage.d.ts +2 -2
  107. package/dist/lib/stage/stage.js +60 -0
  108. package/dist/lib/stage/zylem-stage.d.ts +4 -3
  109. package/dist/lib/stage/zylem-stage.js +268 -0
  110. package/dist/lib/systems/transformable.system.js +43 -0
  111. package/dist/main.d.ts +6 -15
  112. package/dist/main.js +56 -45933
  113. package/dist/stage.d.ts +6 -0
  114. package/dist/stage.js +22 -0
  115. package/dist/tests/stage/stage-blueprint.spec.d.ts +1 -0
  116. package/package.json +35 -1
  117. package/dist/lib/actions/behaviors/index.d.ts +0 -1
  118. package/dist/lib/core/game-canvas.d.ts +0 -4
  119. package/dist/main.cjs +0 -4023
@@ -0,0 +1,10 @@
1
+ import * as o from "./lib/actions/behaviors/actions.js";
2
+ import { makeMoveable as a } from "./lib/actions/capabilities/moveable.js";
3
+ import { makeRotatable as t } from "./lib/actions/capabilities/rotatable.js";
4
+ import { makeTransformable as p } from "./lib/actions/capabilities/transformable.js";
5
+ export {
6
+ o as actions,
7
+ a as makeMoveable,
8
+ t as makeRotatable,
9
+ p as makeTransformable
10
+ };
@@ -0,0 +1,3 @@
1
+ export { boundary2d } from './lib/actions/behaviors/boundaries/boundary';
2
+ export { ricochet2DInBounds } from './lib/actions/behaviors/ricochet/ricochet-2d-in-bounds';
3
+ export { ricochet2DCollision } from './lib/actions/behaviors/ricochet/ricochet-2d-collision';
@@ -0,0 +1,8 @@
1
+ import { boundary2d as e } from "./lib/actions/behaviors/boundaries/boundary.js";
2
+ import { ricochet2DInBounds as c } from "./lib/actions/behaviors/ricochet/ricochet-2d-in-bounds.js";
3
+ import { ricochet2DCollision as n } from "./lib/actions/behaviors/ricochet/ricochet-2d-collision.js";
4
+ export {
5
+ e as boundary2d,
6
+ n as ricochet2DCollision,
7
+ c as ricochet2DInBounds
8
+ };
@@ -0,0 +1,3 @@
1
+ export { camera } from './lib/camera/camera';
2
+ export type { PerspectiveType } from './lib/camera/perspective';
3
+ export { Perspectives } from './lib/camera/perspective';
package/dist/camera.js ADDED
@@ -0,0 +1,6 @@
1
+ import { camera as o } from "./lib/camera/camera.js";
2
+ import { Perspectives as p } from "./lib/camera/perspective.js";
3
+ export {
4
+ p as Perspectives,
5
+ o as camera
6
+ };
package/dist/core.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export { game } from './lib/game/game';
2
+ export type { ZylemGameConfig } from './lib/game/game-interfaces';
3
+ export { vessel } from './lib/core/vessel';
4
+ export type { Vect3 } from './lib/core/utility/vector';
5
+ export { globalChange, globalChanges, variableChange, variableChanges } from './lib/actions/global-change';
package/dist/core.js ADDED
@@ -0,0 +1,11 @@
1
+ import { game as o } from "./lib/game/game.js";
2
+ import { vessel as g } from "./lib/core/vessel.js";
3
+ import { globalChange as b, globalChanges as h, variableChange as m, variableChanges as n } from "./lib/actions/global-change.js";
4
+ export {
5
+ o as game,
6
+ b as globalChange,
7
+ h as globalChanges,
8
+ m as variableChange,
9
+ n as variableChanges,
10
+ g as vessel
11
+ };
@@ -0,0 +1,8 @@
1
+ export { box, ZylemBox } from './lib/entities/box';
2
+ export { sphere } from './lib/entities/sphere';
3
+ export { sprite } from './lib/entities/sprite';
4
+ export { plane } from './lib/entities/plane';
5
+ export { zone } from './lib/entities/zone';
6
+ export { actor } from './lib/entities/actor';
7
+ export { text } from './lib/entities/text';
8
+ export { rect } from './lib/entities/rect';
@@ -0,0 +1,19 @@
1
+ import { ZylemBox as e, box as t } from "./lib/entities/box.js";
2
+ import { sphere as x } from "./lib/entities/sphere.js";
3
+ import { sprite as f } from "./lib/entities/sprite.js";
4
+ import { plane as c } from "./lib/entities/plane.js";
5
+ import { zone as n } from "./lib/entities/zone.js";
6
+ import { actor as b } from "./lib/entities/actor.js";
7
+ import { text as i } from "./lib/entities/text.js";
8
+ import { rect as z } from "./lib/entities/rect.js";
9
+ export {
10
+ e as ZylemBox,
11
+ b as actor,
12
+ t as box,
13
+ c as plane,
14
+ z as rect,
15
+ x as sphere,
16
+ f as sprite,
17
+ i as text,
18
+ n as zone
19
+ };
@@ -0,0 +1,35 @@
1
+ function s(t, e) {
2
+ setTimeout(e, t);
3
+ }
4
+ const c = /* @__PURE__ */ (() => {
5
+ let t = !1;
6
+ return (e, n) => {
7
+ e && !t ? (t = !0, n()) : e || (t = !1);
8
+ };
9
+ })(), u = /* @__PURE__ */ (() => {
10
+ let t = !1;
11
+ return (e, n) => {
12
+ !e && t ? (t = !1, n()) : e && (t = !0);
13
+ };
14
+ })(), f = /* @__PURE__ */ (() => {
15
+ let t = -1 / 0, e = !1;
16
+ return ({ timer: n, immediate: o = !0 }, l, r) => {
17
+ let i = Date.now();
18
+ !e && !o && (e = !0, t = i);
19
+ const a = i - t;
20
+ a >= n && (t = i, l()), r({ delta: a });
21
+ };
22
+ })(), m = /* @__PURE__ */ (() => {
23
+ let t = 0;
24
+ return (e, n) => {
25
+ const o = Date.now();
26
+ o - t >= e && (t = o, n());
27
+ };
28
+ })();
29
+ export {
30
+ c as actionOnPress,
31
+ u as actionOnRelease,
32
+ f as actionWithCooldown,
33
+ m as actionWithThrottle,
34
+ s as wait
35
+ };
@@ -27,7 +27,7 @@ export interface BoundaryOptions {
27
27
  * @param options.stopMovement Whether to stop the entity's movement when it hits a boundary
28
28
  * @returns A behavior callback with type 'update' and a handler function
29
29
  */
30
- export declare function boundary(options?: Partial<BoundaryOptions>): {
30
+ export declare function boundary2d(options?: Partial<BoundaryOptions>): {
31
31
  type: BehaviorCallbackType;
32
32
  handler: (ctx: UpdateContext<MoveableEntity>) => void;
33
33
  };
@@ -0,0 +1,40 @@
1
+ const y = {
2
+ boundaries: {
3
+ top: 0,
4
+ bottom: 0,
5
+ left: 0,
6
+ right: 0
7
+ },
8
+ stopMovement: !0
9
+ };
10
+ function d(i = {}) {
11
+ return {
12
+ type: "update",
13
+ handler: (n) => {
14
+ a(n, i);
15
+ }
16
+ };
17
+ }
18
+ function a(i, n) {
19
+ const { me: r } = i, { boundaries: s, onBoundary: u } = {
20
+ ...y,
21
+ ...n
22
+ }, e = r.getPosition();
23
+ if (!e)
24
+ return;
25
+ let t = { top: !1, bottom: !1, left: !1, right: !1 };
26
+ if (e.x <= s.left ? t.left = !0 : e.x >= s.right && (t.right = !0), e.y <= s.bottom ? t.bottom = !0 : e.y >= s.top && (t.top = !0), (n.stopMovement ?? !0) && t) {
27
+ const o = r.getVelocity() ?? { x: 0, y: 0 };
28
+ let { x: f, y: l } = o;
29
+ (o?.y < 0 && t.bottom || o?.y > 0 && t.top) && (l = 0), (o?.x < 0 && t.left || o?.x > 0 && t.right) && (f = 0), r.moveXY(f, l);
30
+ }
31
+ u && t && u({
32
+ me: r,
33
+ boundary: t,
34
+ position: { x: e.x, y: e.y, z: e.z },
35
+ updateContext: i
36
+ });
37
+ }
38
+ export {
39
+ d as boundary2d
40
+ };
@@ -0,0 +1,100 @@
1
+ import { matchesCollisionSelector as T } from "../../../collision/utils.js";
2
+ import { clamp as E } from "./ricochet.js";
3
+ function tt(O = {}, b) {
4
+ return {
5
+ type: "collision",
6
+ handler: (D) => {
7
+ Z(D, O, b);
8
+ }
9
+ };
10
+ }
11
+ function Z(O, b, D) {
12
+ const { entity: K, other: y } = O, f = K;
13
+ if (y.collider?.isSensor())
14
+ return;
15
+ const { minSpeed: C = 2, maxSpeed: H = 20, separation: U = 0, collisionWith: L = void 0 } = {
16
+ ...b
17
+ }, I = b?.reflectionMode ?? "angled", W = b?.maxAngleDeg ?? 60, _ = b?.speedUpFactor ?? 1.05, j = b?.minOffsetForAngle ?? 0.15, G = b?.centerRetentionFactor ?? 0.5;
18
+ if (!T(y, L))
19
+ return;
20
+ const i = f.getPosition(), X = y.body?.translation(), e = f.getVelocity();
21
+ if (!i || !X || !e)
22
+ return;
23
+ let c = e.x, o = e.y, Y = i.x, P = i.y;
24
+ const p = i.x - X.x, m = i.y - X.y;
25
+ let n = null, s = null;
26
+ const u = y.collider?.shape;
27
+ if (u && (u.halfExtents && (n = Math.abs(u.halfExtents.x ?? u.halfExtents[0] ?? null), s = Math.abs(u.halfExtents.y ?? u.halfExtents[1] ?? null)), (n == null || s == null) && typeof u.radius == "number" && (n = n ?? Math.abs(u.radius), s = s ?? Math.abs(u.radius))), (n == null || s == null) && typeof y.collider?.halfExtents == "function") {
28
+ const t = y.collider.halfExtents();
29
+ t && (n = n ?? Math.abs(t.x), s = s ?? Math.abs(t.y));
30
+ }
31
+ if ((n == null || s == null) && typeof y.collider?.radius == "function") {
32
+ const t = y.collider.radius();
33
+ typeof t == "number" && (n = n ?? Math.abs(t), s = s ?? Math.abs(t));
34
+ }
35
+ let q = 0, z = 0;
36
+ n && s ? (q = E(p / n, -1, 1), z = E(m / s, -1, 1)) : (q = Math.sign(p), z = Math.sign(m));
37
+ let J = Math.abs(m) >= Math.abs(p), a = null, l = null;
38
+ const M = f.collider?.shape;
39
+ if (M && (M.halfExtents && (a = Math.abs(M.halfExtents.x ?? M.halfExtents[0] ?? null), l = Math.abs(M.halfExtents.y ?? M.halfExtents[1] ?? null)), (a == null || l == null) && typeof M.radius == "number" && (a = a ?? Math.abs(M.radius), l = l ?? Math.abs(M.radius))), (a == null || l == null) && typeof f.collider?.halfExtents == "function") {
40
+ const t = f.collider.halfExtents();
41
+ t && (a = a ?? Math.abs(t.x), l = l ?? Math.abs(t.y));
42
+ }
43
+ if ((a == null || l == null) && typeof f.collider?.radius == "function") {
44
+ const t = f.collider.radius();
45
+ typeof t == "number" && (a = a ?? Math.abs(t), l = l ?? Math.abs(t));
46
+ }
47
+ if (n != null && s != null && a != null && l != null) {
48
+ const t = a + n - Math.abs(p), r = l + s - Math.abs(m);
49
+ !Number.isNaN(t) && !Number.isNaN(r) && (J = r <= t);
50
+ }
51
+ let F = !1;
52
+ if (J) {
53
+ const t = (s ?? 0) + (l ?? 0) + U;
54
+ if (P = X.y + (m > 0 ? t : -t), Y = i.x, n != null && s != null && n > s && I === "angled") {
55
+ const v = W * Math.PI / 180, g = Math.max(0, Math.min(1, j)), N = E(q, -1, 1), V = Math.abs(N), S = Math.sqrt(e.x * e.x + e.y * e.y), h = E(S * _, C, H);
56
+ if (V > g) {
57
+ const d = (V - g) / (1 - g), x = Math.sign(N) * (d * v), A = Math.cos(x), w = Math.sin(x), B = Math.abs(h * A), Q = h * w;
58
+ o = m > 0 ? B : -B, c = Q;
59
+ } else {
60
+ const d = e.x * G, x = Math.max(0, h * h - d * d), A = Math.sqrt(x);
61
+ o = m > 0 ? A : -A, c = d;
62
+ }
63
+ F = !0;
64
+ } else
65
+ o = m > 0 ? Math.abs(e.y) : -Math.abs(e.y), I === "simple" && (F = !0);
66
+ } else {
67
+ const t = (n ?? 0) + (a ?? 0) + U;
68
+ if (Y = X.x + (p > 0 ? t : -t), P = i.y, I === "angled") {
69
+ const r = W * Math.PI / 180, v = Math.max(0, Math.min(1, j)), g = E(z, -1, 1), N = Math.abs(g), V = Math.sqrt(e.x * e.x + e.y * e.y), S = E(V * _, C, H);
70
+ if (N > v) {
71
+ const h = (N - v) / (1 - v), d = Math.sign(g) * (h * r), x = Math.cos(d), A = Math.sin(d), w = Math.abs(S * x), B = S * A;
72
+ c = p > 0 ? w : -w, o = B;
73
+ } else {
74
+ const h = e.y * G, d = Math.max(0, S * S - h * h), x = Math.sqrt(d);
75
+ c = p > 0 ? x : -x, o = h;
76
+ }
77
+ F = !0;
78
+ } else
79
+ c = p > 0 ? Math.abs(e.x) : -Math.abs(e.x), o = e.y, F = !0;
80
+ }
81
+ if (!F) {
82
+ const t = Math.abs(c), r = Math.abs(o), v = Math.sign(q) * Math.abs(q) * t, g = Math.sign(z) * Math.abs(z) * r;
83
+ c += v, o += g;
84
+ }
85
+ const R = Math.sqrt(c * c + o * o);
86
+ if (R > 0) {
87
+ const t = E(R, C, H);
88
+ if (t !== R) {
89
+ const r = t / R;
90
+ c *= r, o *= r;
91
+ }
92
+ }
93
+ (Y !== i.x || P !== i.y) && (f.setPosition(Y, P, i.z), f.moveXY(c, o), D && f.getVelocity() && D({
94
+ position: { x: Y, y: P, z: i.z },
95
+ ...O
96
+ }));
97
+ }
98
+ export {
99
+ tt as ricochet2DCollision
100
+ };
@@ -0,0 +1,37 @@
1
+ import { clamp as g } from "./ricochet.js";
2
+ function w(a = {}, u) {
3
+ return {
4
+ type: "update",
5
+ handler: (y) => {
6
+ M(y, a, u);
7
+ }
8
+ };
9
+ }
10
+ function M(a, u, y) {
11
+ const { me: r } = a, { restitution: d = 0, minSpeed: b = 2, maxSpeed: x = 20, boundaries: e = { top: 5, bottom: -5, left: -6.5, right: 6.5 }, separation: p = 0 } = { ...u }, t = r.getPosition(), o = r.getVelocity();
12
+ if (!t || !o)
13
+ return;
14
+ let i = o.x, n = o.y, c = t.x, l = t.y, s = null;
15
+ t.x <= e.left ? (i = Math.abs(o.x), c = e.left + p, s = "left") : t.x >= e.right && (i = -Math.abs(o.x), c = e.right - p, s = "right"), t.y <= e.bottom ? (n = Math.abs(o.y), l = e.bottom + p, s = "bottom") : t.y >= e.top && (n = -Math.abs(o.y), l = e.top - p, s = "top");
16
+ const h = Math.sqrt(i * i + n * n);
17
+ if (h > 0) {
18
+ const f = g(h, b, x);
19
+ if (f !== h) {
20
+ const m = f / h;
21
+ i *= m, n *= m;
22
+ }
23
+ }
24
+ if (d && (i *= d, n *= d), (c !== t.x || l !== t.y) && (r.setPosition(c, l, t.z), r.moveXY(i, n), y && s)) {
25
+ const f = r.getVelocity();
26
+ f && y({
27
+ boundary: s,
28
+ position: { x: c, y: l, z: t.z },
29
+ velocityBefore: o,
30
+ velocityAfter: f,
31
+ ...a
32
+ });
33
+ }
34
+ }
35
+ export {
36
+ w as ricochet2DInBounds
37
+ };
@@ -39,3 +39,5 @@ export interface Ricochet2DCollisionOptions {
39
39
  export type Ricochet2DCallback = (event: RicochetEvent) => void;
40
40
  export type Ricochet2DCollisionCallback = (event: RicochetCollisionEvent) => void;
41
41
  export declare function clamp(value: number, min: number, max: number): number;
42
+ export { ricochet2DInBounds } from './ricochet-2d-in-bounds';
43
+ export { ricochet2DCollision } from './ricochet-2d-collision';
@@ -0,0 +1,6 @@
1
+ function m(t, a, n) {
2
+ return Math.max(a, Math.min(n, t));
3
+ }
4
+ export {
5
+ m as clamp
6
+ };
@@ -0,0 +1,108 @@
1
+ import { Vector3 as l } from "three";
2
+ function b(o, e) {
3
+ if (!o.body)
4
+ return;
5
+ const n = o.body.linvel(), r = new l(e, n.y, n.z);
6
+ o.body.setLinvel(r, !0);
7
+ }
8
+ function y(o, e) {
9
+ if (!o.body)
10
+ return;
11
+ const n = o.body.linvel(), r = new l(n.x, e, n.z);
12
+ o.body.setLinvel(r, !0);
13
+ }
14
+ function m(o, e) {
15
+ if (!o.body)
16
+ return;
17
+ const n = o.body.linvel(), r = new l(n.x, n.y, e);
18
+ o.body.setLinvel(r, !0);
19
+ }
20
+ function w(o, e, n) {
21
+ if (!o.body)
22
+ return;
23
+ const r = o.body.linvel(), c = new l(e, n, r.z);
24
+ o.body.setLinvel(c, !0);
25
+ }
26
+ function V(o, e, n) {
27
+ if (!o.body)
28
+ return;
29
+ const r = o.body.linvel(), c = new l(e, r.y, n);
30
+ o.body.setLinvel(c, !0);
31
+ }
32
+ function P(o, e) {
33
+ if (!o.body)
34
+ return;
35
+ const n = o.body.linvel(), r = new l(n.x + e.x, n.y + e.y, n.z + e.z);
36
+ o.body.setLinvel(r, !0);
37
+ }
38
+ function p(o) {
39
+ o.body && (o.body.setLinvel(new l(0, 0, 0), !0), o.body.setLinearDamping(5));
40
+ }
41
+ function x(o, e, n) {
42
+ const r = Math.sin(-n) * e, c = Math.cos(-n) * e;
43
+ w(o, r, c);
44
+ }
45
+ function u(o) {
46
+ return o.body ? o.body.translation() : null;
47
+ }
48
+ function X(o) {
49
+ return o.body ? o.body.linvel() : null;
50
+ }
51
+ function f(o, e, n, r) {
52
+ o.body && o.body.setTranslation({ x: e, y: n, z: r }, !0);
53
+ }
54
+ function z(o, e) {
55
+ if (!o.body)
56
+ return;
57
+ const { y: n, z: r } = o.body.translation();
58
+ o.body.setTranslation({ x: e, y: n, z: r }, !0);
59
+ }
60
+ function L(o, e) {
61
+ if (!o.body)
62
+ return;
63
+ const { x: n, z: r } = o.body.translation();
64
+ o.body.setTranslation({ x: n, y: e, z: r }, !0);
65
+ }
66
+ function Y(o, e) {
67
+ if (!o.body)
68
+ return;
69
+ const { x: n, y: r } = o.body.translation();
70
+ o.body.setTranslation({ x: n, y: r, z: e }, !0);
71
+ }
72
+ function g(o, e, n) {
73
+ const r = u(o);
74
+ if (!r)
75
+ return;
76
+ const { x: c, y: t } = r, i = c > e ? -e : c < -e ? e : c, s = t > n ? -n : t < -n ? n : t;
77
+ (i !== c || s !== t) && f(o, i, s, 0);
78
+ }
79
+ function T(o, e, n, r) {
80
+ const c = u(o);
81
+ if (!c)
82
+ return;
83
+ const { x: t, y: i, z: s } = c, a = t > e ? -e : t < -e ? e : t, d = i > n ? -n : i < -n ? n : i, v = s > r ? -r : s < -r ? r : s;
84
+ (a !== t || d !== i || v !== s) && f(o, a, d, v);
85
+ }
86
+ function A(o) {
87
+ const e = o;
88
+ return e.moveX = (n) => b(o, n), e.moveY = (n) => y(o, n), e.moveZ = (n) => m(o, n), e.moveXY = (n, r) => w(o, n, r), e.moveXZ = (n, r) => V(o, n, r), e.move = (n) => P(o, n), e.resetVelocity = () => p(o), e.moveForwardXY = (n, r) => x(o, n, r), e.getPosition = () => u(o), e.getVelocity = () => X(o), e.setPosition = (n, r, c) => f(o, n, r, c), e.setPositionX = (n) => z(o, n), e.setPositionY = (n) => L(o, n), e.setPositionZ = (n) => Y(o, n), e.wrapAroundXY = (n, r) => g(o, n, r), e.wrapAround3D = (n, r, c) => T(o, n, r, c), e;
89
+ }
90
+ export {
91
+ u as getPosition,
92
+ X as getVelocity,
93
+ A as makeMoveable,
94
+ P as move,
95
+ x as moveForwardXY,
96
+ b as moveX,
97
+ w as moveXY,
98
+ V as moveXZ,
99
+ y as moveY,
100
+ m as moveZ,
101
+ p as resetVelocity,
102
+ f as setPosition,
103
+ z as setPositionX,
104
+ L as setPositionY,
105
+ Y as setPositionZ,
106
+ T as wrapAround3D,
107
+ g as wrapAroundXY
108
+ };
@@ -0,0 +1,82 @@
1
+ import { Vector3 as g, Euler as i, MathUtils as a, Quaternion as l } from "three";
2
+ function b(o, t) {
3
+ if (!o.body)
4
+ return;
5
+ const e = Math.atan2(-t.x, t.z);
6
+ c(o, e);
7
+ }
8
+ function c(o, t) {
9
+ f(o, new g(0, -t, 0));
10
+ }
11
+ function f(o, t) {
12
+ if (!o.group)
13
+ return;
14
+ const e = new i(t.x, t.y, t.z);
15
+ o.group.setRotationFromEuler(e);
16
+ }
17
+ function h(o, t) {
18
+ s(o, t);
19
+ }
20
+ function D(o, t) {
21
+ u(o, t);
22
+ }
23
+ function s(o, t) {
24
+ if (!o.body)
25
+ return;
26
+ const e = t / 2, r = Math.cos(e), n = Math.sin(e);
27
+ o.body.setRotation({ w: r, x: 0, y: n, z: 0 }, !0);
28
+ }
29
+ function w(o, t) {
30
+ o.body && s(o, a.degToRad(t));
31
+ }
32
+ function R(o, t) {
33
+ if (!o.body)
34
+ return;
35
+ const e = t / 2, r = Math.cos(e), n = Math.sin(e);
36
+ o.body.setRotation({ w: r, x: n, y: 0, z: 0 }, !0);
37
+ }
38
+ function x(o, t) {
39
+ o.body && R(o, a.degToRad(t));
40
+ }
41
+ function u(o, t) {
42
+ if (!o.body)
43
+ return;
44
+ const e = t / 2, r = Math.cos(e), n = Math.sin(e);
45
+ o.body.setRotation({ w: r, x: 0, y: 0, z: n }, !0);
46
+ }
47
+ function z(o, t) {
48
+ o.body && u(o, a.degToRad(t));
49
+ }
50
+ function d(o, t, e, r) {
51
+ if (!o.body)
52
+ return;
53
+ const n = new l().setFromEuler(new i(t, e, r));
54
+ o.body.setRotation({ w: n.w, x: n.x, y: n.y, z: n.z }, !0);
55
+ }
56
+ function E(o, t, e, r) {
57
+ o.body && d(o, a.degToRad(t), a.degToRad(e), a.degToRad(r));
58
+ }
59
+ function M(o) {
60
+ return o.body ? o.body.rotation() : null;
61
+ }
62
+ function m(o) {
63
+ const t = o;
64
+ return t.rotateInDirection = (e) => b(o, e), t.rotateYEuler = (e) => c(o, e), t.rotateEuler = (e) => f(o, e), t.rotateY = (e) => h(o, e), t.rotateZ = (e) => D(o, e), t.setRotationY = (e) => s(o, e), t.setRotationX = (e) => R(o, e), t.setRotationZ = (e) => u(o, e), t.setRotationDegreesY = (e) => w(o, e), t.setRotationDegreesX = (e) => x(o, e), t.setRotationDegreesZ = (e) => z(o, e), t.setRotationDegrees = (e, r, n) => E(o, e, r, n), t.setRotation = (e, r, n) => d(o, e, r, n), t.getRotation = () => M(o), t;
65
+ }
66
+ export {
67
+ M as getRotation,
68
+ m as makeRotatable,
69
+ f as rotateEuler,
70
+ b as rotateInDirection,
71
+ h as rotateY,
72
+ c as rotateYEuler,
73
+ D as rotateZ,
74
+ d as setRotation,
75
+ E as setRotationDegrees,
76
+ x as setRotationDegreesX,
77
+ w as setRotationDegreesY,
78
+ z as setRotationDegreesZ,
79
+ R as setRotationX,
80
+ s as setRotationY,
81
+ u as setRotationZ
82
+ };
@@ -0,0 +1,9 @@
1
+ import { makeMoveable as e } from "./moveable.js";
2
+ import { makeRotatable as a } from "./rotatable.js";
3
+ function i(t) {
4
+ const o = e(t);
5
+ return a(o);
6
+ }
7
+ export {
8
+ i as makeTransformable
9
+ };
@@ -0,0 +1,40 @@
1
+ function v(r, l) {
2
+ let n;
3
+ return (a) => {
4
+ const e = a.globals?.[r];
5
+ n !== e && (n === void 0 && e === void 0 || l(e, a), n = e);
6
+ };
7
+ }
8
+ function d(r, l) {
9
+ let n = new Array(r.length).fill(void 0);
10
+ return (a) => {
11
+ const e = r.map((t) => a.globals?.[t]);
12
+ if (e.some((t, o) => n[o] !== t)) {
13
+ const t = n.every((i) => i === void 0), o = e.every((i) => i === void 0);
14
+ t && o || l(e, a), n = e;
15
+ }
16
+ };
17
+ }
18
+ function f(r, l) {
19
+ let n;
20
+ return (a) => {
21
+ const e = a.stage?.getVariable?.(r) ?? void 0;
22
+ n !== e && (n === void 0 && e === void 0 || l(e, a), n = e);
23
+ };
24
+ }
25
+ function g(r, l) {
26
+ let n = new Array(r.length).fill(void 0);
27
+ return (a) => {
28
+ const e = (o) => a.stage?.getVariable?.(o), s = r.map(e);
29
+ if (s.some((o, i) => n[i] !== o)) {
30
+ const o = n.every((u) => u === void 0), i = s.every((u) => u === void 0);
31
+ o && i || l(s, a), n = s;
32
+ }
33
+ };
34
+ }
35
+ export {
36
+ v as globalChange,
37
+ d as globalChanges,
38
+ f as variableChange,
39
+ g as variableChanges
40
+ };
@@ -0,0 +1,19 @@
1
+ import { Vector2 as c, Vector3 as a } from "three";
2
+ import { ZylemCamera as m } from "./zylem-camera.js";
3
+ class o {
4
+ cameraRef;
5
+ constructor(r) {
6
+ this.cameraRef = r;
7
+ }
8
+ }
9
+ function w(e) {
10
+ const r = e.screenResolution || new c(window.innerWidth, window.innerHeight);
11
+ let n = 10;
12
+ e.perspective === "fixed-2d" && (n = e.zoom || 10);
13
+ const t = new m(e.perspective || "third-person", r, n);
14
+ return t.move(e.position || new a(0, 0, 0)), t.camera.lookAt(e.target || new a(0, 0, 0)), new o(t);
15
+ }
16
+ export {
17
+ o as CameraWrapper,
18
+ w as camera
19
+ };
@@ -0,0 +1,30 @@
1
+ class c {
2
+ screenResolution = null;
3
+ renderer = null;
4
+ scene = null;
5
+ cameraRef = null;
6
+ constructor() {
7
+ }
8
+ /**
9
+ * Setup the fixed 2D camera controller
10
+ */
11
+ setup(e) {
12
+ const { screenResolution: s, renderer: r, scene: t, camera: n } = e;
13
+ this.screenResolution = s, this.renderer = r, this.scene = t, this.cameraRef = n, this.cameraRef.camera.position.set(0, 0, 10), this.cameraRef.camera.lookAt(0, 0, 0);
14
+ }
15
+ /**
16
+ * Update the fixed 2D camera
17
+ * Fixed cameras don't need to update position/rotation automatically
18
+ */
19
+ update(e) {
20
+ }
21
+ /**
22
+ * Handle resize events for 2D camera
23
+ */
24
+ resize(e, s) {
25
+ this.screenResolution && this.screenResolution.set(e, s);
26
+ }
27
+ }
28
+ export {
29
+ c as Fixed2DCamera
30
+ };
@@ -0,0 +1,10 @@
1
+ const e = {
2
+ FirstPerson: "first-person",
3
+ ThirdPerson: "third-person",
4
+ Isometric: "isometric",
5
+ Flat2D: "flat-2d",
6
+ Fixed2D: "fixed-2d"
7
+ };
8
+ export {
9
+ e as Perspectives
10
+ };
@@ -0,0 +1,42 @@
1
+ import { Vector3 as a } from "three";
2
+ class c {
3
+ distance;
4
+ screenResolution = null;
5
+ renderer = null;
6
+ scene = null;
7
+ cameraRef = null;
8
+ constructor() {
9
+ this.distance = new a(0, 5, 8);
10
+ }
11
+ /**
12
+ * Setup the third person camera controller
13
+ */
14
+ setup(e) {
15
+ const { screenResolution: t, renderer: s, scene: r, camera: i } = e;
16
+ this.screenResolution = t, this.renderer = s, this.scene = r, this.cameraRef = i;
17
+ }
18
+ /**
19
+ * Update the third person camera
20
+ */
21
+ update(e) {
22
+ if (!this.cameraRef.target)
23
+ return;
24
+ const t = this.cameraRef.target.group.position.clone().add(this.distance);
25
+ this.cameraRef.camera.position.lerp(t, 0.1), this.cameraRef.camera.lookAt(this.cameraRef.target.group.position);
26
+ }
27
+ /**
28
+ * Handle resize events
29
+ */
30
+ resize(e, t) {
31
+ this.screenResolution && this.screenResolution.set(e, t);
32
+ }
33
+ /**
34
+ * Set the distance from the target
35
+ */
36
+ setDistance(e) {
37
+ this.distance = e;
38
+ }
39
+ }
40
+ export {
41
+ c as ThirdPersonCamera
42
+ };