2024-06-17 22:57:39 +00:00
|
|
|
var Ri = Object.defineProperty;
|
|
|
|
var s = (t, e) => Ri(t, "name", { value: e, configurable: !0 });
|
|
|
|
var jr = (() => {
|
|
|
|
for (var t = new Uint8Array(128), e = 0; e < 64; e++)
|
|
|
|
t[e < 26 ? e + 65 : e < 52 ? e + 71 : e < 62 ? e - 4 : e * 4 - 205] = e;
|
|
|
|
return (n) => {
|
|
|
|
for (
|
|
|
|
var o = n.length,
|
|
|
|
a = new Uint8Array(
|
|
|
|
(((o - (n[o - 1] == "=") - (n[o - 2] == "=")) * 3) / 4) | 0
|
|
|
|
),
|
|
|
|
u = 0,
|
|
|
|
l = 0;
|
|
|
|
u < o;
|
2024-06-01 06:31:08 +00:00
|
|
|
|
2024-06-17 22:57:39 +00:00
|
|
|
) {
|
|
|
|
var f = t[n.charCodeAt(u++)],
|
|
|
|
v = t[n.charCodeAt(u++)],
|
|
|
|
m = t[n.charCodeAt(u++)],
|
|
|
|
P = t[n.charCodeAt(u++)];
|
|
|
|
(a[l++] = (f << 2) | (v >> 4)),
|
|
|
|
(a[l++] = (v << 4) | (m >> 2)),
|
|
|
|
(a[l++] = (m << 6) | P);
|
|
|
|
}
|
|
|
|
return a;
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
function be(t) {
|
|
|
|
return (t * Math.PI) / 180;
|
|
|
|
}
|
|
|
|
s(be, "deg2rad");
|
|
|
|
function lt(t) {
|
|
|
|
return (t * 180) / Math.PI;
|
|
|
|
}
|
|
|
|
s(lt, "rad2deg");
|
|
|
|
function Qe(t, e, n) {
|
|
|
|
return e > n ? Qe(t, n, e) : Math.min(Math.max(t, e), n);
|
|
|
|
}
|
|
|
|
s(Qe, "clamp");
|
|
|
|
function Je(t, e, n) {
|
|
|
|
if (typeof t == "number" && typeof e == "number") return t + (e - t) * n;
|
|
|
|
if (t instanceof D && e instanceof D) return t.lerp(e, n);
|
|
|
|
if (t instanceof re && e instanceof re) return t.lerp(e, n);
|
|
|
|
throw new Error(
|
|
|
|
`Bad value for lerp(): ${t}, ${e}. Only number, Vec2 and Color is supported.`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(Je, "lerp");
|
|
|
|
function et(t, e, n, o, a) {
|
|
|
|
return o + ((t - e) / (n - e)) * (a - o);
|
|
|
|
}
|
|
|
|
s(et, "map");
|
|
|
|
function Nr(t, e, n, o, a) {
|
|
|
|
return Qe(et(t, e, n, o, a), o, a);
|
|
|
|
}
|
|
|
|
s(Nr, "mapc");
|
|
|
|
var D = class t {
|
|
|
|
static {
|
|
|
|
s(this, "Vec2");
|
|
|
|
}
|
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
constructor(e = 0, n = e) {
|
|
|
|
(this.x = e), (this.y = n);
|
|
|
|
}
|
|
|
|
static fromAngle(e) {
|
|
|
|
let n = be(e);
|
|
|
|
return new t(Math.cos(n), Math.sin(n));
|
|
|
|
}
|
|
|
|
static LEFT = new t(-1, 0);
|
|
|
|
static RIGHT = new t(1, 0);
|
|
|
|
static UP = new t(0, -1);
|
|
|
|
static DOWN = new t(0, 1);
|
|
|
|
clone() {
|
|
|
|
return new t(this.x, this.y);
|
|
|
|
}
|
|
|
|
add(...e) {
|
|
|
|
let n = T(...e);
|
|
|
|
return new t(this.x + n.x, this.y + n.y);
|
|
|
|
}
|
|
|
|
sub(...e) {
|
|
|
|
let n = T(...e);
|
|
|
|
return new t(this.x - n.x, this.y - n.y);
|
|
|
|
}
|
|
|
|
scale(...e) {
|
|
|
|
let n = T(...e);
|
|
|
|
return new t(this.x * n.x, this.y * n.y);
|
|
|
|
}
|
|
|
|
dist(...e) {
|
|
|
|
let n = T(...e);
|
|
|
|
return this.sub(n).len();
|
|
|
|
}
|
|
|
|
sdist(...e) {
|
|
|
|
let n = T(...e);
|
|
|
|
return this.sub(n).slen();
|
|
|
|
}
|
|
|
|
len() {
|
|
|
|
return Math.sqrt(this.dot(this));
|
|
|
|
}
|
|
|
|
slen() {
|
|
|
|
return this.dot(this);
|
|
|
|
}
|
|
|
|
unit() {
|
|
|
|
let e = this.len();
|
|
|
|
return e === 0 ? new t(0) : this.scale(1 / e);
|
|
|
|
}
|
|
|
|
normal() {
|
|
|
|
return new t(this.y, -this.x);
|
|
|
|
}
|
|
|
|
reflect(e) {
|
|
|
|
return this.sub(e.scale(2 * this.dot(e)));
|
|
|
|
}
|
|
|
|
project(e) {
|
|
|
|
return e.scale(e.dot(this) / e.len());
|
|
|
|
}
|
|
|
|
reject(e) {
|
|
|
|
return this.sub(this.project(e));
|
|
|
|
}
|
|
|
|
dot(e) {
|
|
|
|
return this.x * e.x + this.y * e.y;
|
|
|
|
}
|
|
|
|
cross(e) {
|
|
|
|
return this.x * e.y - this.y * e.x;
|
|
|
|
}
|
|
|
|
angle(...e) {
|
|
|
|
let n = T(...e);
|
|
|
|
return lt(Math.atan2(this.y - n.y, this.x - n.x));
|
|
|
|
}
|
|
|
|
angleBetween(...e) {
|
|
|
|
let n = T(...e);
|
|
|
|
return lt(Math.atan2(this.cross(n), this.dot(n)));
|
|
|
|
}
|
|
|
|
lerp(e, n) {
|
|
|
|
return new t(Je(this.x, e.x, n), Je(this.y, e.y, n));
|
|
|
|
}
|
|
|
|
slerp(e, n) {
|
|
|
|
let o = this.dot(e),
|
|
|
|
a = this.cross(e),
|
|
|
|
u = Math.atan2(a, o);
|
|
|
|
return this.scale(Math.sin((1 - n) * u))
|
|
|
|
.add(e.scale(Math.sin(n * u)))
|
|
|
|
.scale(1 / a);
|
|
|
|
}
|
|
|
|
isZero() {
|
|
|
|
return this.x === 0 && this.y === 0;
|
|
|
|
}
|
|
|
|
toFixed(e) {
|
|
|
|
return new t(Number(this.x.toFixed(e)), Number(this.y.toFixed(e)));
|
|
|
|
}
|
|
|
|
transform(e) {
|
|
|
|
return e.multVec2(this);
|
|
|
|
}
|
|
|
|
eq(e) {
|
|
|
|
return this.x === e.x && this.y === e.y;
|
|
|
|
}
|
|
|
|
bbox() {
|
|
|
|
return new me(this, 0, 0);
|
|
|
|
}
|
|
|
|
toString() {
|
|
|
|
return `vec2(${this.x.toFixed(2)}, ${this.y.toFixed(2)})`;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
function T(...t) {
|
|
|
|
if (t.length === 1) {
|
|
|
|
if (t[0] instanceof D) return new D(t[0].x, t[0].y);
|
|
|
|
if (Array.isArray(t[0]) && t[0].length === 2) return new D(...t[0]);
|
|
|
|
}
|
|
|
|
return new D(...t);
|
|
|
|
}
|
|
|
|
s(T, "vec2");
|
|
|
|
var re = class t {
|
|
|
|
static {
|
|
|
|
s(this, "Color");
|
|
|
|
}
|
|
|
|
r = 255;
|
|
|
|
g = 255;
|
|
|
|
b = 255;
|
|
|
|
constructor(e, n, o) {
|
|
|
|
(this.r = Qe(e, 0, 255)),
|
|
|
|
(this.g = Qe(n, 0, 255)),
|
|
|
|
(this.b = Qe(o, 0, 255));
|
|
|
|
}
|
|
|
|
static fromArray(e) {
|
|
|
|
return new t(e[0], e[1], e[2]);
|
|
|
|
}
|
|
|
|
static fromHex(e) {
|
|
|
|
if (typeof e == "number")
|
|
|
|
return new t((e >> 16) & 255, (e >> 8) & 255, (e >> 0) & 255);
|
|
|
|
if (typeof e == "string") {
|
|
|
|
let n = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);
|
|
|
|
return new t(parseInt(n[1], 16), parseInt(n[2], 16), parseInt(n[3], 16));
|
|
|
|
} else throw new Error("Invalid hex color format");
|
|
|
|
}
|
|
|
|
static fromHSL(e, n, o) {
|
|
|
|
if (n == 0) return new t(255 * o, 255 * o, 255 * o);
|
|
|
|
let a = s(
|
|
|
|
(P, b, M) => (
|
|
|
|
M < 0 && (M += 1),
|
|
|
|
M > 1 && (M -= 1),
|
|
|
|
M < 1 / 6
|
|
|
|
? P + (b - P) * 6 * M
|
|
|
|
: M < 1 / 2
|
|
|
|
? b
|
|
|
|
: M < 2 / 3
|
|
|
|
? P + (b - P) * (2 / 3 - M) * 6
|
|
|
|
: P
|
|
|
|
),
|
|
|
|
"hue2rgb"
|
|
|
|
),
|
|
|
|
u = o < 0.5 ? o * (1 + n) : o + n - o * n,
|
|
|
|
l = 2 * o - u,
|
|
|
|
f = a(l, u, e + 1 / 3),
|
|
|
|
v = a(l, u, e),
|
|
|
|
m = a(l, u, e - 1 / 3);
|
|
|
|
return new t(Math.round(f * 255), Math.round(v * 255), Math.round(m * 255));
|
|
|
|
}
|
|
|
|
static RED = new t(255, 0, 0);
|
|
|
|
static GREEN = new t(0, 255, 0);
|
|
|
|
static BLUE = new t(0, 0, 255);
|
|
|
|
static YELLOW = new t(255, 255, 0);
|
|
|
|
static MAGENTA = new t(255, 0, 255);
|
|
|
|
static CYAN = new t(0, 255, 255);
|
|
|
|
static WHITE = new t(255, 255, 255);
|
|
|
|
static BLACK = new t(0, 0, 0);
|
|
|
|
clone() {
|
|
|
|
return new t(this.r, this.g, this.b);
|
|
|
|
}
|
|
|
|
lighten(e) {
|
|
|
|
return new t(this.r + e, this.g + e, this.b + e);
|
|
|
|
}
|
|
|
|
darken(e) {
|
|
|
|
return this.lighten(-e);
|
|
|
|
}
|
|
|
|
invert() {
|
|
|
|
return new t(255 - this.r, 255 - this.g, 255 - this.b);
|
|
|
|
}
|
|
|
|
mult(e) {
|
|
|
|
return new t(
|
|
|
|
(this.r * e.r) / 255,
|
|
|
|
(this.g * e.g) / 255,
|
|
|
|
(this.b * e.b) / 255
|
|
|
|
);
|
|
|
|
}
|
|
|
|
lerp(e, n) {
|
|
|
|
return new t(Je(this.r, e.r, n), Je(this.g, e.g, n), Je(this.b, e.b, n));
|
|
|
|
}
|
|
|
|
toHSL() {
|
|
|
|
let e = this.r / 255,
|
|
|
|
n = this.g / 255,
|
|
|
|
o = this.b / 255,
|
|
|
|
a = Math.max(e, n, o),
|
|
|
|
u = Math.min(e, n, o),
|
|
|
|
l = (a + u) / 2,
|
|
|
|
f = l,
|
|
|
|
v = l;
|
|
|
|
if (a == u) l = f = 0;
|
|
|
|
else {
|
|
|
|
let m = a - u;
|
|
|
|
switch (((f = v > 0.5 ? m / (2 - a - u) : m / (a + u)), a)) {
|
|
|
|
case e:
|
|
|
|
l = (n - o) / m + (n < o ? 6 : 0);
|
|
|
|
break;
|
|
|
|
case n:
|
|
|
|
l = (o - e) / m + 2;
|
|
|
|
break;
|
|
|
|
case o:
|
|
|
|
l = (e - n) / m + 4;
|
|
|
|
break;
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
l /= 6;
|
|
|
|
}
|
|
|
|
return [l, f, v];
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
eq(e) {
|
|
|
|
return this.r === e.r && this.g === e.g && this.b === e.b;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
toString() {
|
|
|
|
return `rgb(${this.r}, ${this.g}, ${this.b})`;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
toHex() {
|
|
|
|
return (
|
|
|
|
"#" +
|
|
|
|
((1 << 24) + (this.r << 16) + (this.g << 8) + this.b)
|
|
|
|
.toString(16)
|
|
|
|
.slice(1)
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
toArray() {
|
|
|
|
return [this.r, this.g, this.b];
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
};
|
|
|
|
function ce(...t) {
|
|
|
|
if (t.length === 0) return new re(255, 255, 255);
|
|
|
|
if (t.length === 1) {
|
|
|
|
if (t[0] instanceof re) return t[0].clone();
|
|
|
|
if (typeof t[0] == "string") return re.fromHex(t[0]);
|
|
|
|
if (Array.isArray(t[0]) && t[0].length === 3) return re.fromArray(t[0]);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
return new re(...t);
|
|
|
|
}
|
|
|
|
s(ce, "rgb");
|
|
|
|
var _r = s((t, e, n) => re.fromHSL(t, e, n), "hsl2rgb"),
|
|
|
|
he = class t {
|
2024-06-01 06:31:08 +00:00
|
|
|
static {
|
2024-06-17 22:57:39 +00:00
|
|
|
s(this, "Quad");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
x = 0;
|
|
|
|
y = 0;
|
2024-06-17 22:57:39 +00:00
|
|
|
w = 1;
|
|
|
|
h = 1;
|
|
|
|
constructor(e, n, o, a) {
|
|
|
|
(this.x = e), (this.y = n), (this.w = o), (this.h = a);
|
|
|
|
}
|
|
|
|
scale(e) {
|
|
|
|
return new t(
|
|
|
|
this.x + this.w * e.x,
|
|
|
|
this.y + this.h * e.y,
|
|
|
|
this.w * e.w,
|
|
|
|
this.h * e.h
|
|
|
|
);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
pos() {
|
|
|
|
return new D(this.x, this.y);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
clone() {
|
2024-06-17 22:57:39 +00:00
|
|
|
return new t(this.x, this.y, this.w, this.h);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
eq(e) {
|
|
|
|
return (
|
|
|
|
this.x === e.x && this.y === e.y && this.w === e.w && this.h === e.h
|
|
|
|
);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
toString() {
|
|
|
|
return `quad(${this.x}, ${this.y}, ${this.w}, ${this.h})`;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
};
|
|
|
|
function ge(t, e, n, o) {
|
|
|
|
return new he(t, e, n, o);
|
|
|
|
}
|
|
|
|
s(ge, "quad");
|
|
|
|
var Vt = class t {
|
|
|
|
static {
|
|
|
|
s(this, "Mat2");
|
|
|
|
}
|
|
|
|
a;
|
|
|
|
b;
|
|
|
|
c;
|
|
|
|
d;
|
|
|
|
constructor(e, n, o, a) {
|
|
|
|
(this.a = e), (this.b = n), (this.c = o), (this.d = a);
|
|
|
|
}
|
|
|
|
mul(e) {
|
|
|
|
return new t(
|
|
|
|
this.a * e.a + this.b * e.c,
|
|
|
|
this.a * e.b + this.b * e.d,
|
|
|
|
this.c * e.a + this.d * e.c,
|
|
|
|
this.c * e.b + this.d * e.d
|
|
|
|
);
|
|
|
|
}
|
|
|
|
transform(e) {
|
|
|
|
return T(this.a * e.x + this.b * e.y, this.c * e.x + this.d * e.y);
|
|
|
|
}
|
|
|
|
get inverse() {
|
|
|
|
let e = this.det;
|
|
|
|
return new t(this.d / e, -this.b / e, -this.c / e, this.a / e);
|
|
|
|
}
|
|
|
|
get transpose() {
|
|
|
|
return new t(this.a, this.c, this.b, this.d);
|
|
|
|
}
|
|
|
|
get eigenvalues() {
|
|
|
|
let e = this.trace / 2,
|
|
|
|
n = this.det,
|
|
|
|
o = e + Math.sqrt(e * e - n),
|
|
|
|
a = e - Math.sqrt(e * e - n);
|
|
|
|
return [o, a];
|
|
|
|
}
|
|
|
|
eigenvectors(e, n) {
|
|
|
|
return this.c != 0
|
|
|
|
? [
|
|
|
|
[e - this.d, this.c],
|
|
|
|
[n - this.d, this.c],
|
|
|
|
]
|
|
|
|
: this.b != 0
|
|
|
|
? [
|
|
|
|
[this.b, e - this.a],
|
|
|
|
[this.b, n - this.a],
|
|
|
|
]
|
|
|
|
: Math.abs(this.transform(T(1, 0)).x - e) < Number.EPSILON
|
|
|
|
? [
|
|
|
|
[1, 0],
|
|
|
|
[0, 1],
|
|
|
|
]
|
|
|
|
: [
|
|
|
|
[0, 1],
|
|
|
|
[1, 0],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
get det() {
|
|
|
|
return this.a * this.d - this.b * this.c;
|
|
|
|
}
|
|
|
|
get trace() {
|
|
|
|
return this.a + this.d;
|
|
|
|
}
|
|
|
|
static rotation(e) {
|
|
|
|
let n = Math.cos(e),
|
|
|
|
o = Math.sin(e);
|
|
|
|
return new t(n, o, -o, n);
|
|
|
|
}
|
|
|
|
static scale(e, n) {
|
|
|
|
return new t(e, 0, 0, n);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
var bt = class t {
|
|
|
|
static {
|
|
|
|
s(this, "Mat3");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
m11;
|
|
|
|
m12;
|
|
|
|
m13;
|
|
|
|
m21;
|
|
|
|
m22;
|
|
|
|
m23;
|
|
|
|
m31;
|
|
|
|
m32;
|
|
|
|
m33;
|
|
|
|
constructor(e, n, o, a, u, l, f, v, m) {
|
|
|
|
(this.m11 = e),
|
|
|
|
(this.m12 = n),
|
|
|
|
(this.m13 = o),
|
|
|
|
(this.m21 = a),
|
|
|
|
(this.m22 = u),
|
|
|
|
(this.m23 = l),
|
|
|
|
(this.m31 = f),
|
|
|
|
(this.m32 = v),
|
|
|
|
(this.m33 = m);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
static fromMat2(e) {
|
|
|
|
return new t(e.a, e.b, 0, e.c, e.d, 0, 0, 0, 1);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
toMat2() {
|
|
|
|
return new Vt(this.m11, this.m12, this.m21, this.m22);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
mul(e) {
|
|
|
|
return new t(
|
|
|
|
this.m11 * e.m11 + this.m12 * e.m21 + this.m13 * e.m31,
|
|
|
|
this.m11 * e.m12 + this.m12 * e.m22 + this.m13 * e.m32,
|
|
|
|
this.m11 * e.m13 + this.m12 * e.m23 + this.m13 * e.m33,
|
|
|
|
this.m21 * e.m11 + this.m22 * e.m21 + this.m23 * e.m31,
|
|
|
|
this.m21 * e.m12 + this.m22 * e.m22 + this.m23 * e.m32,
|
|
|
|
this.m21 * e.m13 + this.m22 * e.m23 + this.m23 * e.m33,
|
|
|
|
this.m31 * e.m11 + this.m32 * e.m21 + this.m33 * e.m31,
|
|
|
|
this.m31 * e.m12 + this.m32 * e.m22 + this.m33 * e.m32,
|
|
|
|
this.m31 * e.m13 + this.m32 * e.m23 + this.m33 * e.m33
|
|
|
|
);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
get det() {
|
|
|
|
return (
|
|
|
|
this.m11 * this.m22 * this.m33 +
|
|
|
|
this.m12 * this.m23 * this.m31 +
|
|
|
|
this.m13 * this.m21 * this.m32 -
|
|
|
|
this.m13 * this.m22 * this.m31 -
|
|
|
|
this.m12 * this.m21 * this.m33 -
|
|
|
|
this.m11 * this.m23 * this.m32
|
|
|
|
);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
rotate(e) {
|
|
|
|
let n = Math.cos(e),
|
|
|
|
o = Math.sin(e),
|
|
|
|
a = this.m11,
|
|
|
|
u = this.m12;
|
|
|
|
return (
|
|
|
|
(this.m11 = n * this.m11 + o * this.m21),
|
|
|
|
(this.m12 = n * this.m12 + o * this.m22),
|
|
|
|
(this.m21 = n * this.m21 - o * a),
|
|
|
|
(this.m22 = n * this.m22 - o * u),
|
|
|
|
this
|
|
|
|
);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
scale(e, n) {
|
|
|
|
return (
|
|
|
|
(this.m11 *= e), (this.m12 *= e), (this.m21 *= n), (this.m22 *= n), this
|
|
|
|
);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
get inverse() {
|
|
|
|
let e = this.det;
|
|
|
|
return new t(
|
|
|
|
(this.m22 * this.m33 - this.m23 * this.m32) / e,
|
|
|
|
(this.m13 * this.m32 - this.m12 * this.m33) / e,
|
|
|
|
(this.m12 * this.m23 - this.m13 * this.m22) / e,
|
|
|
|
(this.m23 * this.m31 - this.m21 * this.m33) / e,
|
|
|
|
(this.m11 * this.m33 - this.m13 * this.m31) / e,
|
|
|
|
(this.m13 * this.m21 - this.m11 * this.m23) / e,
|
|
|
|
(this.m21 * this.m32 - this.m22 * this.m31) / e,
|
|
|
|
(this.m12 * this.m31 - this.m11 * this.m32) / e,
|
|
|
|
(this.m11 * this.m22 - this.m12 * this.m21) / e
|
|
|
|
);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
get transpose() {
|
|
|
|
return new t(
|
|
|
|
this.m11,
|
|
|
|
this.m21,
|
|
|
|
this.m31,
|
|
|
|
this.m12,
|
|
|
|
this.m22,
|
|
|
|
this.m32,
|
|
|
|
this.m13,
|
|
|
|
this.m23,
|
|
|
|
this.m33
|
|
|
|
);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
},
|
|
|
|
De = class t {
|
|
|
|
static {
|
|
|
|
s(this, "Mat4");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
m = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
|
|
constructor(e) {
|
|
|
|
e && (this.m = e);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
static translate(e) {
|
|
|
|
return new t([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, e.x, e.y, 0, 1]);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
static scale(e) {
|
|
|
|
return new t([e.x, 0, 0, 0, 0, e.y, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
static rotateX(e) {
|
|
|
|
e = be(-e);
|
|
|
|
let n = Math.cos(e),
|
|
|
|
o = Math.sin(e);
|
|
|
|
return new t([1, 0, 0, 0, 0, n, -o, 0, 0, o, n, 0, 0, 0, 0, 1]);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
static rotateY(e) {
|
|
|
|
e = be(-e);
|
|
|
|
let n = Math.cos(e),
|
|
|
|
o = Math.sin(e);
|
|
|
|
return new t([n, 0, o, 0, 0, 1, 0, 0, -o, 0, n, 0, 0, 0, 0, 1]);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
static rotateZ(e) {
|
|
|
|
e = be(-e);
|
|
|
|
let n = Math.cos(e),
|
|
|
|
o = Math.sin(e);
|
|
|
|
return new t([n, -o, 0, 0, o, n, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
translate(e) {
|
|
|
|
return (
|
|
|
|
(this.m[12] += this.m[0] * e.x + this.m[4] * e.y),
|
|
|
|
(this.m[13] += this.m[1] * e.x + this.m[5] * e.y),
|
|
|
|
(this.m[14] += this.m[2] * e.x + this.m[6] * e.y),
|
|
|
|
(this.m[15] += this.m[3] * e.x + this.m[7] * e.y),
|
|
|
|
this
|
|
|
|
);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
scale(e) {
|
|
|
|
return (
|
|
|
|
(this.m[0] *= e.x),
|
|
|
|
(this.m[4] *= e.y),
|
|
|
|
(this.m[1] *= e.x),
|
|
|
|
(this.m[5] *= e.y),
|
|
|
|
(this.m[2] *= e.x),
|
|
|
|
(this.m[6] *= e.y),
|
|
|
|
(this.m[3] *= e.x),
|
|
|
|
(this.m[7] *= e.y),
|
|
|
|
this
|
|
|
|
);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
rotate(e) {
|
|
|
|
e = be(-e);
|
|
|
|
let n = Math.cos(e),
|
|
|
|
o = Math.sin(e),
|
|
|
|
a = this.m[0],
|
|
|
|
u = this.m[1],
|
|
|
|
l = this.m[4],
|
|
|
|
f = this.m[5];
|
|
|
|
return (
|
|
|
|
(this.m[0] = a * n + u * o),
|
|
|
|
(this.m[1] = -a * o + u * n),
|
|
|
|
(this.m[4] = l * n + f * o),
|
|
|
|
(this.m[5] = -l * o + f * n),
|
|
|
|
this
|
|
|
|
);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
mult(e) {
|
|
|
|
let n = [];
|
|
|
|
for (let o = 0; o < 4; o++)
|
|
|
|
for (let a = 0; a < 4; a++)
|
|
|
|
n[o * 4 + a] =
|
|
|
|
this.m[0 * 4 + a] * e.m[o * 4 + 0] +
|
|
|
|
this.m[1 * 4 + a] * e.m[o * 4 + 1] +
|
|
|
|
this.m[2 * 4 + a] * e.m[o * 4 + 2] +
|
|
|
|
this.m[3 * 4 + a] * e.m[o * 4 + 3];
|
|
|
|
return new t(n);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
multVec2(e) {
|
|
|
|
return new D(
|
|
|
|
e.x * this.m[0] + e.y * this.m[4] + this.m[12],
|
|
|
|
e.x * this.m[1] + e.y * this.m[5] + this.m[13]
|
|
|
|
);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
getTranslation() {
|
|
|
|
return new D(this.m[12], this.m[13]);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
getScale() {
|
|
|
|
if (this.m[0] != 0 || this.m[1] != 0) {
|
|
|
|
let e = this.m[0] * this.m[5] - this.m[1] * this.m[4],
|
|
|
|
n = Math.sqrt(this.m[0] * this.m[0] + this.m[1] * this.m[1]);
|
|
|
|
return new D(n, e / n);
|
|
|
|
} else if (this.m[4] != 0 || this.m[5] != 0) {
|
|
|
|
let e = this.m[0] * this.m[5] - this.m[1] * this.m[4],
|
|
|
|
n = Math.sqrt(this.m[4] * this.m[4] + this.m[5] * this.m[5]);
|
|
|
|
return new D(e / n, n);
|
|
|
|
} else return new D(0, 0);
|
|
|
|
}
|
|
|
|
getRotation() {
|
|
|
|
if (this.m[0] != 0 || this.m[1] != 0) {
|
|
|
|
let e = Math.sqrt(this.m[0] * this.m[0] + this.m[1] * this.m[1]);
|
|
|
|
return lt(
|
|
|
|
this.m[1] > 0 ? Math.acos(this.m[0] / e) : -Math.acos(this.m[0] / e)
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
2024-06-17 22:57:39 +00:00
|
|
|
} else if (this.m[4] != 0 || this.m[5] != 0) {
|
|
|
|
let e = Math.sqrt(this.m[4] * this.m[4] + this.m[5] * this.m[5]);
|
|
|
|
return lt(
|
|
|
|
Math.PI / 2 -
|
|
|
|
(this.m[5] > 0
|
|
|
|
? Math.acos(-this.m[4] / e)
|
|
|
|
: -Math.acos(this.m[4] / e))
|
|
|
|
);
|
|
|
|
} else return 0;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
getSkew() {
|
|
|
|
if (this.m[0] != 0 || this.m[1] != 0) {
|
|
|
|
let e = Math.sqrt(this.m[0] * this.m[0] + this.m[1] * this.m[1]);
|
|
|
|
return new D(
|
|
|
|
Math.atan(this.m[0] * this.m[4] + this.m[1] * this.m[5]) / (e * e),
|
|
|
|
0
|
|
|
|
);
|
|
|
|
} else if (this.m[4] != 0 || this.m[5] != 0) {
|
|
|
|
let e = Math.sqrt(this.m[4] * this.m[4] + this.m[5] * this.m[5]);
|
|
|
|
return new D(
|
|
|
|
0,
|
|
|
|
Math.atan(this.m[0] * this.m[4] + this.m[1] * this.m[5]) / (e * e)
|
|
|
|
);
|
|
|
|
} else return new D(0, 0);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
invert() {
|
|
|
|
let e = [],
|
|
|
|
n = this.m[10] * this.m[15] - this.m[14] * this.m[11],
|
|
|
|
o = this.m[9] * this.m[15] - this.m[13] * this.m[11],
|
|
|
|
a = this.m[9] * this.m[14] - this.m[13] * this.m[10],
|
|
|
|
u = this.m[8] * this.m[15] - this.m[12] * this.m[11],
|
|
|
|
l = this.m[8] * this.m[14] - this.m[12] * this.m[10],
|
|
|
|
f = this.m[8] * this.m[13] - this.m[12] * this.m[9],
|
|
|
|
v = this.m[6] * this.m[15] - this.m[14] * this.m[7],
|
|
|
|
m = this.m[5] * this.m[15] - this.m[13] * this.m[7],
|
|
|
|
P = this.m[5] * this.m[14] - this.m[13] * this.m[6],
|
|
|
|
b = this.m[4] * this.m[15] - this.m[12] * this.m[7],
|
|
|
|
M = this.m[4] * this.m[14] - this.m[12] * this.m[6],
|
|
|
|
w = this.m[5] * this.m[15] - this.m[13] * this.m[7],
|
|
|
|
_ = this.m[4] * this.m[13] - this.m[12] * this.m[5],
|
|
|
|
$ = this.m[6] * this.m[11] - this.m[10] * this.m[7],
|
|
|
|
X = this.m[5] * this.m[11] - this.m[9] * this.m[7],
|
|
|
|
L = this.m[5] * this.m[10] - this.m[9] * this.m[6],
|
|
|
|
Q = this.m[4] * this.m[11] - this.m[8] * this.m[7],
|
|
|
|
O = this.m[4] * this.m[10] - this.m[8] * this.m[6],
|
|
|
|
oe = this.m[4] * this.m[9] - this.m[8] * this.m[5];
|
|
|
|
(e[0] = this.m[5] * n - this.m[6] * o + this.m[7] * a),
|
|
|
|
(e[4] = -(this.m[4] * n - this.m[6] * u + this.m[7] * l)),
|
|
|
|
(e[8] = this.m[4] * o - this.m[5] * u + this.m[7] * f),
|
|
|
|
(e[12] = -(this.m[4] * a - this.m[5] * l + this.m[6] * f)),
|
|
|
|
(e[1] = -(this.m[1] * n - this.m[2] * o + this.m[3] * a)),
|
|
|
|
(e[5] = this.m[0] * n - this.m[2] * u + this.m[3] * l),
|
|
|
|
(e[9] = -(this.m[0] * o - this.m[1] * u + this.m[3] * f)),
|
|
|
|
(e[13] = this.m[0] * a - this.m[1] * l + this.m[2] * f),
|
|
|
|
(e[2] = this.m[1] * v - this.m[2] * m + this.m[3] * P),
|
|
|
|
(e[6] = -(this.m[0] * v - this.m[2] * b + this.m[3] * M)),
|
|
|
|
(e[10] = this.m[0] * w - this.m[1] * b + this.m[3] * _),
|
|
|
|
(e[14] = -(this.m[0] * P - this.m[1] * M + this.m[2] * _)),
|
|
|
|
(e[3] = -(this.m[1] * $ - this.m[2] * X + this.m[3] * L)),
|
|
|
|
(e[7] = this.m[0] * $ - this.m[2] * Q + this.m[3] * O),
|
|
|
|
(e[11] = -(this.m[0] * X - this.m[1] * Q + this.m[3] * oe)),
|
|
|
|
(e[15] = this.m[0] * L - this.m[1] * O + this.m[2] * oe);
|
|
|
|
let H =
|
|
|
|
this.m[0] * e[0] +
|
|
|
|
this.m[1] * e[4] +
|
|
|
|
this.m[2] * e[8] +
|
|
|
|
this.m[3] * e[12];
|
|
|
|
for (let ie = 0; ie < 4; ie++)
|
|
|
|
for (let se = 0; se < 4; se++) e[ie * 4 + se] *= 1 / H;
|
|
|
|
return new t(e);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
clone() {
|
|
|
|
return new t([...this.m]);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
toString() {
|
|
|
|
return this.m.toString();
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
};
|
|
|
|
function $n(t, e, n, o = (a) => -Math.cos(a)) {
|
|
|
|
return t + ((o(n) + 1) / 2) * (e - t);
|
|
|
|
}
|
|
|
|
s($n, "wave");
|
|
|
|
var Ui = 1103515245,
|
|
|
|
Pi = 12345,
|
|
|
|
kr = 2147483648,
|
|
|
|
jt = class {
|
|
|
|
static {
|
|
|
|
s(this, "RNG");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
seed;
|
|
|
|
constructor(e) {
|
|
|
|
this.seed = e;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
gen() {
|
|
|
|
return (this.seed = (Ui * this.seed + Pi) % kr), this.seed / kr;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
genNumber(e, n) {
|
|
|
|
return e + this.gen() * (n - e);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
genVec2(e, n) {
|
|
|
|
return new D(this.genNumber(e.x, n.x), this.genNumber(e.y, n.y));
|
|
|
|
}
|
|
|
|
genColor(e, n) {
|
|
|
|
return new re(
|
|
|
|
this.genNumber(e.r, n.r),
|
|
|
|
this.genNumber(e.g, n.g),
|
|
|
|
this.genNumber(e.b, n.b)
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
genAny(...e) {
|
|
|
|
if (e.length === 0) return this.gen();
|
|
|
|
if (e.length === 1) {
|
|
|
|
if (typeof e[0] == "number") return this.genNumber(0, e[0]);
|
|
|
|
if (e[0] instanceof D) return this.genVec2(T(0, 0), e[0]);
|
|
|
|
if (e[0] instanceof re) return this.genColor(ce(0, 0, 0), e[0]);
|
|
|
|
} else if (e.length === 2) {
|
|
|
|
if (typeof e[0] == "number" && typeof e[1] == "number")
|
|
|
|
return this.genNumber(e[0], e[1]);
|
|
|
|
if (e[0] instanceof D && e[1] instanceof D)
|
|
|
|
return this.genVec2(e[0], e[1]);
|
|
|
|
if (e[0] instanceof re && e[1] instanceof re)
|
|
|
|
return this.genColor(e[0], e[1]);
|
|
|
|
}
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
},
|
|
|
|
Xn = new jt(Date.now());
|
|
|
|
function Hr(t) {
|
|
|
|
return t != null && (Xn.seed = t), Xn.seed;
|
|
|
|
}
|
|
|
|
s(Hr, "randSeed");
|
|
|
|
function kt(...t) {
|
|
|
|
return Xn.genAny(...t);
|
|
|
|
}
|
|
|
|
s(kt, "rand");
|
|
|
|
function Qn(...t) {
|
|
|
|
return Math.floor(kt(...t));
|
|
|
|
}
|
|
|
|
s(Qn, "randi");
|
|
|
|
function Kr(t) {
|
|
|
|
return kt() <= t;
|
|
|
|
}
|
|
|
|
s(Kr, "chance");
|
|
|
|
function Jn(t) {
|
|
|
|
for (let e = t.length - 1; e > 0; e--) {
|
|
|
|
let n = Math.floor(Math.random() * (e + 1));
|
|
|
|
[t[e], t[n]] = [t[n], t[e]];
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
s(Jn, "shuffle");
|
|
|
|
function qr(t, e) {
|
|
|
|
return t.length <= e ? t.slice() : Jn(t.slice()).slice(0, e);
|
|
|
|
}
|
|
|
|
s(qr, "chooseMultiple");
|
|
|
|
function zr(t) {
|
|
|
|
return t[Qn(t.length)];
|
|
|
|
}
|
|
|
|
s(zr, "choose");
|
|
|
|
function Zn(t, e) {
|
|
|
|
return (
|
|
|
|
t.pos.x + t.width > e.pos.x &&
|
|
|
|
t.pos.x < e.pos.x + e.width &&
|
|
|
|
t.pos.y + t.height > e.pos.y &&
|
|
|
|
t.pos.y < e.pos.y + e.height
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(Zn, "testRectRect");
|
|
|
|
function Mi(t, e) {
|
|
|
|
if (
|
|
|
|
(t.p1.x === t.p2.x && t.p1.y === t.p2.y) ||
|
|
|
|
(e.p1.x === e.p2.x && e.p1.y === e.p2.y)
|
|
|
|
)
|
|
|
|
return null;
|
|
|
|
let n =
|
|
|
|
(e.p2.y - e.p1.y) * (t.p2.x - t.p1.x) -
|
|
|
|
(e.p2.x - e.p1.x) * (t.p2.y - t.p1.y);
|
|
|
|
if (n === 0) return null;
|
|
|
|
let o =
|
|
|
|
((e.p2.x - e.p1.x) * (t.p1.y - e.p1.y) -
|
|
|
|
(e.p2.y - e.p1.y) * (t.p1.x - e.p1.x)) /
|
|
|
|
n,
|
|
|
|
a =
|
|
|
|
((t.p2.x - t.p1.x) * (t.p1.y - e.p1.y) -
|
|
|
|
(t.p2.y - t.p1.y) * (t.p1.x - e.p1.x)) /
|
|
|
|
n;
|
|
|
|
return o < 0 || o > 1 || a < 0 || a > 1 ? null : o;
|
|
|
|
}
|
|
|
|
s(Mi, "testLineLineT");
|
|
|
|
function an(t, e) {
|
|
|
|
let n = Mi(t, e);
|
|
|
|
return n
|
|
|
|
? T(t.p1.x + n * (t.p2.x - t.p1.x), t.p1.y + n * (t.p2.y - t.p1.y))
|
|
|
|
: null;
|
|
|
|
}
|
|
|
|
s(an, "testLineLine");
|
|
|
|
function cn(t, e) {
|
|
|
|
let n = e.p2.sub(e.p1),
|
|
|
|
o = Number.NEGATIVE_INFINITY,
|
|
|
|
a = Number.POSITIVE_INFINITY;
|
|
|
|
if (n.x != 0) {
|
|
|
|
let u = (t.pos.x - e.p1.x) / n.x,
|
|
|
|
l = (t.pos.x + t.width - e.p1.x) / n.x;
|
|
|
|
(o = Math.max(o, Math.min(u, l))), (a = Math.min(a, Math.max(u, l)));
|
|
|
|
}
|
|
|
|
if (n.y != 0) {
|
|
|
|
let u = (t.pos.y - e.p1.y) / n.y,
|
|
|
|
l = (t.pos.y + t.height - e.p1.y) / n.y;
|
|
|
|
(o = Math.max(o, Math.min(u, l))), (a = Math.min(a, Math.max(u, l)));
|
|
|
|
}
|
|
|
|
return a >= o && a >= 0 && o <= 1;
|
|
|
|
}
|
|
|
|
s(cn, "testRectLine");
|
|
|
|
function er(t, e) {
|
|
|
|
return (
|
|
|
|
e.x > t.pos.x &&
|
|
|
|
e.x < t.pos.x + t.width &&
|
|
|
|
e.y > t.pos.y &&
|
|
|
|
e.y < t.pos.y + t.height
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(er, "testRectPoint");
|
|
|
|
function Wr(t, e) {
|
|
|
|
let n = Math.max(t.pos.x, Math.min(e.center.x, t.pos.x + t.width)),
|
|
|
|
o = Math.max(t.pos.y, Math.min(e.center.y, t.pos.y + t.height));
|
|
|
|
return T(n, o).sdist(e.center) <= e.radius * e.radius;
|
|
|
|
}
|
|
|
|
s(Wr, "testRectCircle");
|
|
|
|
function Yr(t, e) {
|
|
|
|
return Xr(e, new Ae(t.points()));
|
|
|
|
}
|
|
|
|
s(Yr, "testRectPolygon");
|
|
|
|
function tr(t, e) {
|
|
|
|
let n = e.sub(t.p1),
|
|
|
|
o = t.p2.sub(t.p1);
|
|
|
|
if (Math.abs(n.cross(o)) > Number.EPSILON) return !1;
|
|
|
|
let a = n.dot(o) / o.dot(o);
|
|
|
|
return a >= 0 && a <= 1;
|
|
|
|
}
|
|
|
|
s(tr, "testLinePoint");
|
|
|
|
function Rt(t, e) {
|
|
|
|
let n = t.p2.sub(t.p1),
|
|
|
|
o = n.dot(n),
|
|
|
|
a = t.p1.sub(e.center),
|
|
|
|
u = 2 * n.dot(a),
|
|
|
|
l = a.dot(a) - e.radius * e.radius,
|
|
|
|
f = u * u - 4 * o * l;
|
|
|
|
if (o <= Number.EPSILON || f < 0) return !1;
|
|
|
|
if (f == 0) {
|
|
|
|
let v = -u / (2 * o);
|
|
|
|
if (v >= 0 && v <= 1) return !0;
|
|
|
|
} else {
|
|
|
|
let v = (-u + Math.sqrt(f)) / (2 * o),
|
|
|
|
m = (-u - Math.sqrt(f)) / (2 * o);
|
|
|
|
if ((v >= 0 && v <= 1) || (m >= 0 && m <= 1)) return !0;
|
|
|
|
}
|
|
|
|
return rr(e, t.p1);
|
|
|
|
}
|
|
|
|
s(Rt, "testLineCircle");
|
|
|
|
function nr(t, e) {
|
|
|
|
if (mt(e, t.p1) || mt(e, t.p2)) return !0;
|
|
|
|
for (let n = 0; n < e.pts.length; n++) {
|
|
|
|
let o = e.pts[n],
|
|
|
|
a = e.pts[(n + 1) % e.pts.length];
|
|
|
|
if (an(t, new Ge(o, a))) return !0;
|
|
|
|
}
|
|
|
|
return !1;
|
|
|
|
}
|
|
|
|
s(nr, "testLinePolygon");
|
|
|
|
function rr(t, e) {
|
|
|
|
return t.center.sdist(e) < t.radius * t.radius;
|
|
|
|
}
|
|
|
|
s(rr, "testCirclePoint");
|
|
|
|
function Di(t, e) {
|
|
|
|
return (
|
|
|
|
t.center.sdist(e.center) < (t.radius + e.radius) * (t.radius + e.radius)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(Di, "testCircleCircle");
|
|
|
|
function Nt(t, e) {
|
|
|
|
let n = e.pts[e.pts.length - 1];
|
|
|
|
for (let o of e.pts) {
|
|
|
|
if (Rt(new Ge(n, o), t)) return !0;
|
|
|
|
n = o;
|
|
|
|
}
|
|
|
|
return rr(t, e.pts[0]) ? !0 : mt(e, t.center);
|
|
|
|
}
|
|
|
|
s(Nt, "testCirclePolygon");
|
|
|
|
function Xr(t, e) {
|
|
|
|
for (let n = 0; n < t.pts.length; n++)
|
|
|
|
if (nr(new Ge(t.pts[n], t.pts[(n + 1) % t.pts.length]), e)) return !0;
|
|
|
|
return !!(t.pts.some((n) => mt(e, n)) || e.pts.some((n) => mt(t, n)));
|
|
|
|
}
|
|
|
|
s(Xr, "testPolygonPolygon");
|
|
|
|
function mt(t, e) {
|
|
|
|
let n = !1,
|
|
|
|
o = t.pts;
|
|
|
|
for (let a = 0, u = o.length - 1; a < o.length; u = a++)
|
|
|
|
o[a].y > e.y != o[u].y > e.y &&
|
|
|
|
e.x < ((o[u].x - o[a].x) * (e.y - o[a].y)) / (o[u].y - o[a].y) + o[a].x &&
|
|
|
|
(n = !n);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
s(mt, "testPolygonPoint");
|
|
|
|
function $r(t, e) {
|
|
|
|
e = e.sub(t.center);
|
|
|
|
let n = be(t.angle),
|
|
|
|
o = Math.cos(n),
|
|
|
|
a = Math.sin(n),
|
|
|
|
u = e.x * o + e.y * a,
|
|
|
|
l = -e.x * a + e.y * o;
|
|
|
|
return (
|
|
|
|
(u * u) / (t.radiusX * t.radiusX) + (l * l) / (t.radiusY * t.radiusY) < 1
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s($r, "testEllipsePoint");
|
|
|
|
function sn(t, e) {
|
|
|
|
let n = e.center.sub(t.center),
|
|
|
|
o = be(t.angle),
|
|
|
|
a = Math.cos(o),
|
|
|
|
u = Math.sin(o),
|
|
|
|
l = n.x * a + n.y * u,
|
|
|
|
f = -n.x * u + n.y * a;
|
|
|
|
return $r(
|
|
|
|
new Ye(T(), t.radiusX + e.radius, t.radiusY + e.radius, 0),
|
|
|
|
T(l, f)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(sn, "testEllipseCircle");
|
|
|
|
function Qr(t, e) {
|
|
|
|
let n = t.toMat2().inverse;
|
|
|
|
return (
|
|
|
|
(e = new Ge(
|
|
|
|
n.transform(e.p1.sub(t.center)),
|
|
|
|
n.transform(e.p2.sub(t.center))
|
|
|
|
)),
|
|
|
|
Rt(e, new Be(T(), 1))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(Qr, "testEllipseLine");
|
|
|
|
function Gi(t, e) {
|
|
|
|
if (t.radiusX === t.radiusY) return sn(e, new Be(t.center, t.radiusX));
|
|
|
|
if (e.radiusX === e.radiusY) return sn(t, new Be(e.center, e.radiusX));
|
|
|
|
let n = new bt(1 / t.radiusX ** 2, 0, 0, 0, 1 / t.radiusY ** 2, 0, 0, 0, -1),
|
|
|
|
o = new bt(1 / e.radiusX ** 2, 0, 0, 0, 1 / e.radiusY ** 2, 0, 0, 0, -1),
|
|
|
|
a = t.center.x,
|
|
|
|
u = t.center.y,
|
|
|
|
l = e.center.x,
|
|
|
|
f = e.center.y,
|
|
|
|
v = be(t.angle),
|
|
|
|
m = be(e.angle),
|
|
|
|
P = new bt(
|
|
|
|
Math.cos(v),
|
|
|
|
-Math.sin(v),
|
|
|
|
a,
|
|
|
|
Math.sin(v),
|
|
|
|
Math.cos(v),
|
|
|
|
u,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
1
|
|
|
|
),
|
|
|
|
b = new bt(
|
|
|
|
Math.cos(m),
|
|
|
|
-Math.sin(m),
|
|
|
|
l,
|
|
|
|
Math.sin(m),
|
|
|
|
Math.cos(m),
|
|
|
|
f,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
1
|
|
|
|
),
|
|
|
|
M = P.inverse,
|
|
|
|
w = b.inverse,
|
|
|
|
_ = M.transpose.mul(n).mul(M),
|
|
|
|
$ = w.transpose.mul(o).mul(w),
|
|
|
|
X = _.m11,
|
|
|
|
L = _.m12,
|
|
|
|
Q = _.m13,
|
|
|
|
O = _.m21,
|
|
|
|
oe = _.m22,
|
|
|
|
H = _.m23,
|
|
|
|
ie = _.m31,
|
|
|
|
se = _.m32,
|
|
|
|
ae = _.m33,
|
|
|
|
pe = $.m11,
|
|
|
|
Ce = $.m12,
|
|
|
|
ve = $.m13,
|
|
|
|
Ie = $.m21,
|
|
|
|
Le = $.m22,
|
|
|
|
Te = $.m23,
|
|
|
|
Ne = $.m31,
|
|
|
|
_e = $.m32,
|
|
|
|
He = $.m33,
|
|
|
|
dt =
|
|
|
|
X * oe * ae -
|
|
|
|
X * H * se -
|
|
|
|
L * O * ae +
|
|
|
|
L * H * ie +
|
|
|
|
Q * O * se -
|
|
|
|
Q * oe * ie,
|
|
|
|
Ee =
|
|
|
|
(X * oe * He -
|
|
|
|
X * H * _e -
|
|
|
|
X * se * Te +
|
|
|
|
X * ae * Le -
|
|
|
|
L * O * He +
|
|
|
|
L * H * Ne +
|
|
|
|
L * ie * Te -
|
|
|
|
L * ae * Ie +
|
|
|
|
Q * O * _e -
|
|
|
|
Q * oe * Ne -
|
|
|
|
Q * ie * Le +
|
|
|
|
Q * se * Ie +
|
|
|
|
O * se * ve -
|
|
|
|
O * ae * Ce -
|
|
|
|
oe * ie * ve +
|
|
|
|
oe * ae * pe +
|
|
|
|
H * ie * Ce -
|
|
|
|
H * se * pe) /
|
|
|
|
dt,
|
|
|
|
Re =
|
|
|
|
(X * Le * He -
|
|
|
|
X * Te * _e -
|
|
|
|
L * Ie * He +
|
|
|
|
L * Te * Ne +
|
|
|
|
Q * Ie * _e -
|
|
|
|
Q * Le * Ne -
|
|
|
|
O * Ce * He +
|
|
|
|
O * ve * _e +
|
|
|
|
oe * pe * He -
|
|
|
|
oe * ve * Ne -
|
|
|
|
H * pe * _e +
|
|
|
|
H * Ce * Ne +
|
|
|
|
ie * Ce * Te -
|
|
|
|
ie * ve * Le -
|
|
|
|
se * pe * Te +
|
|
|
|
se * ve * Ie +
|
|
|
|
ae * pe * Le -
|
|
|
|
ae * Ce * Ie) /
|
|
|
|
dt,
|
|
|
|
ze =
|
|
|
|
(pe * Le * He -
|
|
|
|
pe * Te * _e -
|
|
|
|
Ce * Ie * He +
|
|
|
|
Ce * Te * Ne +
|
|
|
|
ve * Ie * _e -
|
|
|
|
ve * Le * Ne) /
|
|
|
|
dt;
|
|
|
|
if (Ee >= 0) {
|
|
|
|
let ot = -3 * Re + Ee ** 2,
|
|
|
|
st = 3 * Ee * ze + Re * Ee ** 2 - 4 * Re ** 2,
|
|
|
|
Ct =
|
|
|
|
-27 * ze ** 2 +
|
|
|
|
18 * ze * Ee * Re +
|
|
|
|
Ee ** 2 * Re ** 2 -
|
|
|
|
4 * Ee ** 3 * ze -
|
|
|
|
4 * Re ** 3;
|
|
|
|
return !(ot > 0 && st < 0 && Ct > 0);
|
|
|
|
} else {
|
|
|
|
let ot = -3 * Re + Ee ** 2,
|
|
|
|
st =
|
|
|
|
-27 * ze ** 2 +
|
|
|
|
18 * ze * Ee * Re +
|
|
|
|
Ee ** 2 * Re ** 2 -
|
|
|
|
4 * Ee ** 3 * ze -
|
|
|
|
4 * Re ** 3;
|
|
|
|
return !(ot > 0 && st > 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s(Gi, "testEllipseEllipse");
|
|
|
|
function Jr(t, e) {
|
|
|
|
return or(t, new Ae(e.points()));
|
|
|
|
}
|
|
|
|
s(Jr, "testEllipseRect");
|
|
|
|
function or(t, e) {
|
|
|
|
let n = t.toMat2().inverse;
|
|
|
|
return (
|
|
|
|
(e = new Ae(e.pts.map((o) => n.transform(o.sub(t.center))))),
|
|
|
|
Nt(new Be(T(), 1), e)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(or, "testEllipsePolygon");
|
|
|
|
function Bi(t, e) {
|
|
|
|
return e instanceof D
|
|
|
|
? tr(t, e)
|
|
|
|
: e instanceof Be
|
|
|
|
? Rt(t, e)
|
|
|
|
: e instanceof Ge
|
|
|
|
? an(t, e) != null
|
|
|
|
: e instanceof me
|
|
|
|
? cn(e, t)
|
|
|
|
: e instanceof Ae
|
|
|
|
? nr(t, e)
|
|
|
|
: e instanceof Ye
|
|
|
|
? Qr(e, t)
|
|
|
|
: !1;
|
|
|
|
}
|
|
|
|
s(Bi, "testLineShape");
|
|
|
|
function Fi(t, e) {
|
|
|
|
return e instanceof D
|
|
|
|
? rr(t, e)
|
|
|
|
: e instanceof Be
|
|
|
|
? Di(t, e)
|
|
|
|
: e instanceof Ge
|
|
|
|
? Rt(e, t)
|
|
|
|
: e instanceof me
|
|
|
|
? Wr(e, t)
|
|
|
|
: e instanceof Ae
|
|
|
|
? Nt(t, e)
|
|
|
|
: e instanceof Ye
|
|
|
|
? sn(e, t)
|
|
|
|
: !1;
|
|
|
|
}
|
|
|
|
s(Fi, "testCircleShape");
|
|
|
|
function Ii(t, e) {
|
|
|
|
return e instanceof D
|
|
|
|
? er(t, e)
|
|
|
|
: e instanceof Be
|
|
|
|
? Wr(t, e)
|
|
|
|
: e instanceof Ge
|
|
|
|
? cn(t, e)
|
|
|
|
: e instanceof me
|
|
|
|
? Zn(t, e)
|
|
|
|
: e instanceof Ae
|
|
|
|
? Yr(t, e)
|
|
|
|
: e instanceof Ye
|
|
|
|
? Jr(e, t)
|
|
|
|
: !1;
|
|
|
|
}
|
|
|
|
s(Ii, "testRectShape");
|
|
|
|
function Li(t, e) {
|
|
|
|
return e instanceof D
|
|
|
|
? mt(t, e)
|
|
|
|
: e instanceof Be
|
|
|
|
? Nt(e, t)
|
|
|
|
: e instanceof Ge
|
|
|
|
? nr(e, t)
|
|
|
|
: e instanceof me
|
|
|
|
? Yr(e, t)
|
|
|
|
: e instanceof Ae
|
|
|
|
? Xr(e, t)
|
|
|
|
: e instanceof Ye
|
|
|
|
? or(e, t)
|
|
|
|
: !1;
|
|
|
|
}
|
|
|
|
s(Li, "testPolygonShape");
|
|
|
|
function ji(t, e) {
|
|
|
|
return e instanceof D
|
|
|
|
? $r(t, e)
|
|
|
|
: e instanceof Be
|
|
|
|
? sn(t, e)
|
|
|
|
: e instanceof Ge
|
|
|
|
? Qr(t, e)
|
|
|
|
: e instanceof me
|
|
|
|
? Jr(t, e)
|
|
|
|
: e instanceof Ae
|
|
|
|
? or(t, e)
|
|
|
|
: e instanceof Ye
|
|
|
|
? Gi(e, t)
|
|
|
|
: !1;
|
|
|
|
}
|
|
|
|
s(ji, "testEllipseShape");
|
|
|
|
function Zr(t, e, n) {
|
|
|
|
let o = t,
|
|
|
|
a = n.p1,
|
|
|
|
u = n.p2,
|
|
|
|
l = e,
|
|
|
|
f = u.sub(a),
|
|
|
|
v = l.cross(f);
|
|
|
|
if (Math.abs(v) < Number.EPSILON) return null;
|
|
|
|
let m = a.sub(o),
|
|
|
|
P = m.cross(f) / v;
|
|
|
|
if (P <= 0 || P >= 1) return null;
|
|
|
|
let b = m.cross(l) / v;
|
|
|
|
if (b <= 0 || b >= 1) return null;
|
|
|
|
let M = f.normal().unit();
|
|
|
|
return (
|
|
|
|
e.dot(M) > 0 && ((M.x *= -1), (M.y *= -1)),
|
|
|
|
{ point: o.add(l.scale(P)), normal: M, fraction: P }
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(Zr, "raycastLine");
|
|
|
|
function ki(t, e, n) {
|
|
|
|
let o = Number.NEGATIVE_INFINITY,
|
|
|
|
a = Number.POSITIVE_INFINITY,
|
|
|
|
u;
|
|
|
|
if (t.x != 0) {
|
|
|
|
let l = (n.pos.x - t.x) / e.x,
|
|
|
|
f = (n.pos.x + n.width - t.x) / e.x;
|
|
|
|
(u = T(-Math.sign(e.x), 0)),
|
|
|
|
(o = Math.max(o, Math.min(l, f))),
|
|
|
|
(a = Math.min(a, Math.max(l, f)));
|
|
|
|
}
|
|
|
|
if (t.y != 0) {
|
|
|
|
let l = (n.pos.y - t.y) / e.y,
|
|
|
|
f = (n.pos.y + n.height - t.y) / e.y;
|
|
|
|
Math.min(l, f) > o && (u = T(0, -Math.sign(e.y))),
|
|
|
|
(o = Math.max(o, Math.min(l, f))),
|
|
|
|
(a = Math.min(a, Math.max(l, f)));
|
|
|
|
}
|
|
|
|
return a >= o && o >= 0 && o <= 1
|
|
|
|
? { point: t.add(e.scale(o)), normal: u, fraction: o }
|
|
|
|
: null;
|
|
|
|
}
|
|
|
|
s(ki, "raycastRect");
|
|
|
|
function eo(t, e, n) {
|
|
|
|
let o = t,
|
|
|
|
a = n.center,
|
|
|
|
u = e,
|
|
|
|
l = u.dot(u),
|
|
|
|
f = o.sub(a),
|
|
|
|
v = 2 * u.dot(f),
|
|
|
|
m = f.dot(f) - n.radius * n.radius,
|
|
|
|
P = v * v - 4 * l * m;
|
|
|
|
if (l <= Number.EPSILON || P < 0) return null;
|
|
|
|
if (P == 0) {
|
|
|
|
let b = -v / (2 * l);
|
|
|
|
if (b >= 0 && b <= 1) {
|
|
|
|
let M = o.add(u.scale(b));
|
|
|
|
return { point: M, normal: M.sub(a), fraction: b };
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
let b = (-v + Math.sqrt(P)) / (2 * l),
|
|
|
|
M = (-v - Math.sqrt(P)) / (2 * l),
|
|
|
|
w = null;
|
|
|
|
if (
|
|
|
|
(b >= 0 && b <= 1 && (w = b),
|
|
|
|
M >= 0 && M <= 1 && (w = Math.min(M, w ?? M)),
|
|
|
|
w != null)
|
|
|
|
) {
|
|
|
|
let _ = o.add(u.scale(w));
|
|
|
|
return { point: _, normal: _.sub(a).unit(), fraction: w };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
s(eo, "raycastCircle");
|
|
|
|
function Ni(t, e, n) {
|
|
|
|
let o = n.pts,
|
|
|
|
a = null,
|
|
|
|
u = o[o.length - 1];
|
|
|
|
for (let l = 0; l < o.length; l++) {
|
|
|
|
let f = o[l],
|
|
|
|
v = Zr(t, e, new Ge(u, f));
|
|
|
|
v && (!a || a.fraction > v.fraction) && (a = v), (u = f);
|
|
|
|
}
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
s(Ni, "raycastPolygon");
|
|
|
|
function _i(t, e, n) {
|
|
|
|
let o = n.toMat2(),
|
|
|
|
a = o.inverse,
|
|
|
|
u = a.transform(t.sub(n.center)),
|
|
|
|
l = a.transform(e),
|
|
|
|
f = eo(u, l, new Be(T(), 1));
|
|
|
|
if (f) {
|
|
|
|
let v = Vt.rotation(be(-n.angle)),
|
|
|
|
P = Vt.scale(n.radiusX, n.radiusY).transform(f.point),
|
|
|
|
b = o.transform(f.point).add(n.center),
|
|
|
|
M = b.dist(t) / e.len();
|
|
|
|
return {
|
|
|
|
point: b,
|
|
|
|
normal: v.transform(T(n.radiusY ** 2 * P.x, n.radiusX ** 2 * P.y)),
|
|
|
|
fraction: M,
|
2024-06-01 06:31:08 +00:00
|
|
|
};
|
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
return f;
|
|
|
|
}
|
|
|
|
s(_i, "raycastEllipse");
|
|
|
|
function to(t, e, n, o = 64) {
|
|
|
|
let a = t,
|
|
|
|
u = e.len(),
|
|
|
|
l = e.scale(1 / u),
|
|
|
|
f = 0,
|
|
|
|
v = T(Math.floor(t.x), Math.floor(t.y)),
|
|
|
|
m = T(l.x > 0 ? 1 : -1, l.y > 0 ? 1 : -1),
|
|
|
|
P = T(Math.abs(1 / l.x), Math.abs(1 / l.y)),
|
|
|
|
b = T(
|
|
|
|
m.x > 0 ? v.x + 1 - t.x : t.x - v.x,
|
|
|
|
m.y > 0 ? v.y + 1 - t.y : t.y - v.y
|
|
|
|
),
|
|
|
|
M = T(P.x < 1 / 0 ? P.x * b.x : 1 / 0, P.y < 1 / 0 ? P.y * b.y : 1 / 0),
|
|
|
|
w = -1;
|
|
|
|
for (; f <= o; ) {
|
|
|
|
let _ = n(v);
|
|
|
|
if (_ === !0)
|
|
|
|
return {
|
|
|
|
point: a.add(l.scale(f)),
|
|
|
|
normal: T(w === 0 ? -m.x : 0, w === 1 ? -m.y : 0),
|
|
|
|
fraction: f / u,
|
|
|
|
gridPos: v,
|
|
|
|
};
|
|
|
|
if (_) return _;
|
|
|
|
M.x < M.y
|
|
|
|
? ((v.x += m.x), (f = M.x), (M.x += P.x), (w = 0))
|
|
|
|
: ((v.y += m.y), (f = M.y), (M.y += P.y), (w = 1));
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
s(to, "raycastGrid");
|
|
|
|
var Ge = class t {
|
2024-06-01 06:31:08 +00:00
|
|
|
static {
|
2024-06-17 22:57:39 +00:00
|
|
|
s(this, "Line");
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
p1;
|
|
|
|
p2;
|
|
|
|
constructor(e, n) {
|
|
|
|
(this.p1 = e.clone()), (this.p2 = n.clone());
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
transform(e) {
|
2024-06-17 22:57:39 +00:00
|
|
|
return new t(e.multVec2(this.p1), e.multVec2(this.p2));
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
bbox() {
|
|
|
|
return me.fromPoints(this.p1, this.p2);
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
area() {
|
|
|
|
return this.p1.dist(this.p2);
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
clone() {
|
|
|
|
return new t(this.p1, this.p2);
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
collides(e) {
|
|
|
|
return Bi(this, e);
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
contains(e) {
|
|
|
|
return this.collides(e);
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
raycast(e, n) {
|
|
|
|
return Zr(e, n, this);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
},
|
|
|
|
me = class t {
|
|
|
|
static {
|
|
|
|
s(this, "Rect");
|
|
|
|
}
|
|
|
|
pos;
|
|
|
|
width;
|
|
|
|
height;
|
|
|
|
constructor(e, n, o) {
|
|
|
|
(this.pos = e.clone()), (this.width = n), (this.height = o);
|
|
|
|
}
|
|
|
|
static fromPoints(e, n) {
|
|
|
|
return new t(e.clone(), n.x - e.x, n.y - e.y);
|
|
|
|
}
|
|
|
|
center() {
|
|
|
|
return new D(this.pos.x + this.width / 2, this.pos.y + this.height / 2);
|
|
|
|
}
|
|
|
|
points() {
|
|
|
|
return [
|
|
|
|
this.pos,
|
|
|
|
this.pos.add(this.width, 0),
|
|
|
|
this.pos.add(this.width, this.height),
|
|
|
|
this.pos.add(0, this.height),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
transform(e) {
|
|
|
|
return new Ae(this.points().map((n) => e.multVec2(n)));
|
|
|
|
}
|
|
|
|
bbox() {
|
|
|
|
return this.clone();
|
|
|
|
}
|
|
|
|
area() {
|
|
|
|
return this.width * this.height;
|
|
|
|
}
|
|
|
|
clone() {
|
|
|
|
return new t(this.pos.clone(), this.width, this.height);
|
|
|
|
}
|
|
|
|
distToPoint(e) {
|
|
|
|
return Math.sqrt(this.sdistToPoint(e));
|
|
|
|
}
|
|
|
|
sdistToPoint(e) {
|
|
|
|
let n = this.pos,
|
|
|
|
o = this.pos.add(this.width, this.height),
|
|
|
|
a = Math.max(n.x - e.x, 0, e.x - o.x),
|
|
|
|
u = Math.max(n.y - e.y, 0, e.y - o.y);
|
|
|
|
return a * a + u * u;
|
|
|
|
}
|
|
|
|
collides(e) {
|
|
|
|
return Ii(this, e);
|
|
|
|
}
|
|
|
|
contains(e) {
|
|
|
|
return this.collides(e);
|
|
|
|
}
|
|
|
|
raycast(e, n) {
|
|
|
|
return ki(e, n, this);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Be = class t {
|
|
|
|
static {
|
|
|
|
s(this, "Circle");
|
|
|
|
}
|
|
|
|
center;
|
|
|
|
radius;
|
|
|
|
constructor(e, n) {
|
|
|
|
(this.center = e.clone()), (this.radius = n);
|
|
|
|
}
|
|
|
|
transform(e) {
|
|
|
|
return new Ye(this.center, this.radius, this.radius).transform(e);
|
|
|
|
}
|
|
|
|
bbox() {
|
|
|
|
return me.fromPoints(
|
|
|
|
this.center.sub(T(this.radius)),
|
|
|
|
this.center.add(T(this.radius))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
area() {
|
|
|
|
return this.radius * this.radius * Math.PI;
|
|
|
|
}
|
|
|
|
clone() {
|
|
|
|
return new t(this.center, this.radius);
|
|
|
|
}
|
|
|
|
collides(e) {
|
|
|
|
return Fi(this, e);
|
|
|
|
}
|
|
|
|
contains(e) {
|
|
|
|
return this.collides(e);
|
|
|
|
}
|
|
|
|
raycast(e, n) {
|
|
|
|
return eo(e, n, this);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Ye = class t {
|
|
|
|
static {
|
|
|
|
s(this, "Ellipse");
|
|
|
|
}
|
|
|
|
center;
|
|
|
|
radiusX;
|
|
|
|
radiusY;
|
|
|
|
angle;
|
|
|
|
constructor(e, n, o, a = 0) {
|
|
|
|
(this.center = e.clone()),
|
|
|
|
(this.radiusX = n),
|
|
|
|
(this.radiusY = o),
|
|
|
|
(this.angle = a);
|
|
|
|
}
|
|
|
|
static fromMat2(e) {
|
|
|
|
let n = e.inverse,
|
|
|
|
o = n.transpose.mul(n),
|
|
|
|
[a, u] = o.eigenvalues,
|
|
|
|
[l, f] = o.eigenvectors(a, u),
|
|
|
|
[v, m] = [1 / Math.sqrt(a), 1 / Math.sqrt(u)];
|
|
|
|
return v > m
|
|
|
|
? new t(T(), v, m, lt(Math.atan2(-l[1], l[0])))
|
|
|
|
: new t(T(), m, v, lt(Math.atan2(-f[1], f[0])));
|
|
|
|
}
|
|
|
|
toMat2() {
|
|
|
|
let e = be(this.angle),
|
|
|
|
n = Math.cos(e),
|
|
|
|
o = Math.sin(e);
|
|
|
|
return new Vt(
|
|
|
|
n * this.radiusX,
|
|
|
|
o * this.radiusY,
|
|
|
|
-o * this.radiusX,
|
|
|
|
n * this.radiusY
|
|
|
|
);
|
|
|
|
}
|
|
|
|
transform(e) {
|
|
|
|
if (this.angle == 0 && e.getRotation() == 0)
|
2024-06-02 05:39:23 +00:00
|
|
|
return new t(
|
2024-06-17 22:57:39 +00:00
|
|
|
e.multVec2(this.center),
|
|
|
|
e.m[0] * this.radiusX,
|
|
|
|
e.m[5] * this.radiusY
|
2024-06-02 05:39:23 +00:00
|
|
|
);
|
2024-06-17 22:57:39 +00:00
|
|
|
{
|
|
|
|
let n = this.toMat2(),
|
|
|
|
o = e.getRotation(),
|
|
|
|
a = e.getScale();
|
|
|
|
n = bt.fromMat2(n).scale(a.x, a.y).rotate(o).toMat2();
|
|
|
|
let l = t.fromMat2(n);
|
|
|
|
return (l.center = e.multVec2(this.center)), l;
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
}
|
|
|
|
bbox() {
|
|
|
|
if (this.angle == 0)
|
|
|
|
return me.fromPoints(
|
|
|
|
this.center.sub(T(this.radiusX, this.radiusY)),
|
|
|
|
this.center.add(T(this.radiusX, this.radiusY))
|
2024-06-02 05:39:23 +00:00
|
|
|
);
|
2024-06-17 22:57:39 +00:00
|
|
|
{
|
|
|
|
let e = be(this.angle),
|
|
|
|
n = Math.cos(e),
|
|
|
|
o = Math.sin(e),
|
|
|
|
a = this.radiusX * n,
|
|
|
|
u = this.radiusX * o,
|
|
|
|
l = this.radiusY * o,
|
|
|
|
f = this.radiusY * n,
|
|
|
|
v = Math.sqrt(a * a + l * l),
|
|
|
|
m = Math.sqrt(u * u + f * f);
|
|
|
|
return me.fromPoints(
|
|
|
|
this.center.sub(T(v, m)),
|
|
|
|
this.center.add(T(v, m))
|
2024-06-02 05:39:23 +00:00
|
|
|
);
|
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
}
|
|
|
|
area() {
|
|
|
|
return this.radiusX * this.radiusY * Math.PI;
|
|
|
|
}
|
|
|
|
clone() {
|
|
|
|
return new t(this.center, this.radiusX, this.radiusY, this.angle);
|
|
|
|
}
|
|
|
|
collides(e) {
|
|
|
|
return ji(this, e);
|
|
|
|
}
|
|
|
|
contains(e) {
|
|
|
|
e = e.sub(this.center);
|
|
|
|
let n = be(this.angle),
|
|
|
|
o = Math.cos(n),
|
|
|
|
a = Math.sin(n),
|
|
|
|
u = e.x * o + e.y * a,
|
|
|
|
l = -e.x * a + e.y * o;
|
|
|
|
return (
|
|
|
|
(u * u) / (this.radiusX * this.radiusX) +
|
|
|
|
(l * l) / (this.radiusY * this.radiusY) <
|
|
|
|
1
|
|
|
|
);
|
|
|
|
}
|
|
|
|
raycast(e, n) {
|
|
|
|
return _i(e, n, this);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Ae = class t {
|
|
|
|
static {
|
|
|
|
s(this, "Polygon");
|
|
|
|
}
|
|
|
|
pts;
|
|
|
|
constructor(e) {
|
|
|
|
if (e.length < 3)
|
|
|
|
throw new Error("Polygons should have at least 3 vertices");
|
|
|
|
this.pts = e;
|
|
|
|
}
|
|
|
|
transform(e) {
|
|
|
|
return new t(this.pts.map((n) => e.multVec2(n)));
|
|
|
|
}
|
|
|
|
bbox() {
|
|
|
|
let e = T(Number.MAX_VALUE),
|
|
|
|
n = T(-Number.MAX_VALUE);
|
|
|
|
for (let o of this.pts)
|
|
|
|
(e.x = Math.min(e.x, o.x)),
|
|
|
|
(n.x = Math.max(n.x, o.x)),
|
|
|
|
(e.y = Math.min(e.y, o.y)),
|
|
|
|
(n.y = Math.max(n.y, o.y));
|
|
|
|
return me.fromPoints(e, n);
|
|
|
|
}
|
|
|
|
area() {
|
|
|
|
let e = 0,
|
|
|
|
n = this.pts.length;
|
|
|
|
for (let o = 0; o < n; o++) {
|
|
|
|
let a = this.pts[o],
|
|
|
|
u = this.pts[(o + 1) % n];
|
|
|
|
(e += a.x * u.y * 0.5), (e -= u.x * a.y * 0.5);
|
|
|
|
}
|
|
|
|
return Math.abs(e);
|
|
|
|
}
|
|
|
|
clone() {
|
|
|
|
return new t(this.pts.map((e) => e.clone()));
|
|
|
|
}
|
|
|
|
collides(e) {
|
|
|
|
return Li(this, e);
|
|
|
|
}
|
|
|
|
contains(e) {
|
|
|
|
return this.collides(e);
|
|
|
|
}
|
|
|
|
raycast(e, n) {
|
|
|
|
return Ni(e, n, this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
function no(t, e, n, o) {
|
|
|
|
let a = o * o,
|
|
|
|
u = 1 - o,
|
|
|
|
l = u * u;
|
|
|
|
return t
|
|
|
|
.scale(l)
|
|
|
|
.add(e.scale(2 * u * o))
|
|
|
|
.add(n.scale(a));
|
|
|
|
}
|
|
|
|
s(no, "evaluateQuadratic");
|
|
|
|
function ro(t, e, n, o) {
|
|
|
|
let a = 1 - o;
|
|
|
|
return e
|
|
|
|
.sub(t)
|
|
|
|
.scale(2 * a)
|
|
|
|
.add(n.sub(e).scale(2 * o));
|
|
|
|
}
|
|
|
|
s(ro, "evaluateQuadraticFirstDerivative");
|
|
|
|
function oo(t, e, n, o) {
|
|
|
|
return n.sub(e.scale(2)).add(t).scale(2);
|
|
|
|
}
|
|
|
|
s(oo, "evaluateQuadraticSecondDerivative");
|
|
|
|
function un(t, e, n, o, a) {
|
|
|
|
let u = a * a,
|
|
|
|
l = u * a,
|
|
|
|
f = 1 - a,
|
|
|
|
v = f * f,
|
|
|
|
m = v * f;
|
|
|
|
return t
|
|
|
|
.scale(m)
|
|
|
|
.add(e.scale(3 * v * a))
|
|
|
|
.add(n.scale(3 * f * u))
|
|
|
|
.add(o.scale(l));
|
|
|
|
}
|
|
|
|
s(un, "evaluateBezier");
|
|
|
|
function so(t, e, n, o, a) {
|
|
|
|
let u = a * a,
|
|
|
|
l = 1 - a,
|
|
|
|
f = l * l;
|
|
|
|
return e
|
|
|
|
.sub(t)
|
|
|
|
.scale(3 * f)
|
|
|
|
.add(n.sub(e).scale(6 * l * a))
|
|
|
|
.add(o.sub(n).scale(3 * u));
|
|
|
|
}
|
|
|
|
s(so, "evaluateBezierFirstDerivative");
|
|
|
|
function io(t, e, n, o, a) {
|
|
|
|
let u = 1 - a;
|
|
|
|
return n
|
|
|
|
.sub(e.scale(2))
|
|
|
|
.add(t)
|
|
|
|
.scale(6 * u)
|
|
|
|
.add(
|
|
|
|
o
|
|
|
|
.sub(n.scale(2))
|
|
|
|
.add(e)
|
|
|
|
.scale(6 * a)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(io, "evaluateBezierSecondDerivative");
|
|
|
|
function ao(t, e, n, o, a) {
|
|
|
|
let u = 0.5 * (((-a + 2) * a - 1) * a),
|
|
|
|
l = 0.5 * ((3 * a - 5) * a * a + 2),
|
|
|
|
f = 0.5 * (((-3 * a + 4) * a + 1) * a),
|
|
|
|
v = 0.5 * ((a - 1) * a * a);
|
|
|
|
return t.scale(u).add(e.scale(l)).add(n.scale(f)).add(o.scale(v));
|
|
|
|
}
|
|
|
|
s(ao, "evaluateCatmullRom");
|
|
|
|
function co(t, e, n, o, a) {
|
|
|
|
let u = 0.5 * ((-3 * a + 4) * a - 1),
|
|
|
|
l = 0.5 * ((9 * a - 10) * a),
|
|
|
|
f = 0.5 * ((-9 * a + 8) * a + 1),
|
|
|
|
v = 0.5 * ((3 * a - 2) * a);
|
|
|
|
return t.scale(u).add(e.scale(l)).add(n.scale(f)).add(o.scale(v));
|
|
|
|
}
|
|
|
|
s(co, "evaluateCatmullRomFirstDerivative");
|
|
|
|
function uo(t) {
|
|
|
|
let e = sr(t),
|
|
|
|
n = e(1);
|
|
|
|
return (o) => {
|
|
|
|
let a = o * n,
|
|
|
|
u = e(a, !0);
|
|
|
|
return t(u);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(uo, "normalizedCurve");
|
|
|
|
function sr(t, e = 10, n = 10) {
|
|
|
|
let o = [0],
|
|
|
|
a = [0],
|
|
|
|
l = 1 / (e - 1) / n,
|
|
|
|
f = 0,
|
|
|
|
v = t(0),
|
|
|
|
m = 0;
|
|
|
|
for (let P = 1; P < e; P++) {
|
|
|
|
for (let b = 0; b < n; b++) {
|
|
|
|
m += l;
|
|
|
|
let M = t(m),
|
|
|
|
w = M.dist(v);
|
|
|
|
(f += w), (v = M);
|
|
|
|
}
|
|
|
|
(o[P] = f), (a[P] = m);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
return (
|
|
|
|
(a[e - 1] = 1),
|
|
|
|
(P, b = !1) => {
|
|
|
|
if (b) {
|
|
|
|
let M = P;
|
|
|
|
if (M <= 0) return 0;
|
|
|
|
if (M >= f) return 1;
|
|
|
|
let w = 0;
|
|
|
|
for (; o[w + 1] < M; ) w++;
|
|
|
|
let _ = a[w],
|
|
|
|
$ = a[w + 1],
|
|
|
|
X = o[w],
|
|
|
|
L = o[w + 1],
|
|
|
|
Q = (M - X) / (L - X);
|
|
|
|
return _ + ($ - _) * Q;
|
|
|
|
} else {
|
|
|
|
if (P <= 0) return 0;
|
|
|
|
if (P >= 1) return o[e - 1];
|
|
|
|
let M = 0;
|
|
|
|
for (; a[M + 1] < P; ) M++;
|
|
|
|
let w = a[M],
|
|
|
|
_ = a[M + 1],
|
|
|
|
$ = o[M],
|
|
|
|
X = o[M + 1],
|
|
|
|
L = (P - w) / (_ - w);
|
|
|
|
return $ + (X - $) * L;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(sr, "curveLengthApproximation");
|
|
|
|
function It(t) {
|
|
|
|
return 0 <= t && t <= 1;
|
|
|
|
}
|
|
|
|
s(It, "inZeroOneDomain");
|
|
|
|
function Wn(t, e) {
|
|
|
|
return Math.abs(t - e) <= Number.EPSILON;
|
|
|
|
}
|
|
|
|
s(Wn, "approximately");
|
|
|
|
function Lt(t) {
|
|
|
|
return t < 0 ? -Math.pow(-t, 1 / 3) : Math.pow(t, 1 / 3);
|
|
|
|
}
|
|
|
|
s(Lt, "cubeRoot");
|
|
|
|
function Hi(t, e, n, o) {
|
|
|
|
let a = 3 * t - 6 * e + 3 * n,
|
|
|
|
u = -3 * t + 3 * e,
|
|
|
|
l = t,
|
|
|
|
f = -t + 3 * e - 3 * n + o;
|
|
|
|
if (Wn(f, 0)) {
|
|
|
|
if (Wn(a, 0)) return Wn(u, 0) ? [] : [-l / u].filter(It);
|
|
|
|
let L = Math.sqrt(u * u - 4 * a * l),
|
|
|
|
Q = 2 * a;
|
|
|
|
return [(L - u) / Q, (-u - L) / Q].filter(It);
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
(a /= f), (u /= f), (l /= f);
|
|
|
|
let v = (3 * u - a * a) / 3,
|
|
|
|
m = v / 3,
|
|
|
|
P = (2 * a * a * a - 9 * a * u + 27 * l) / 27,
|
|
|
|
b = P / 2,
|
|
|
|
M = b * b + m * m * m;
|
|
|
|
if (M < 0) {
|
|
|
|
let L = -v / 3,
|
|
|
|
Q = L * L * L,
|
|
|
|
O = Math.sqrt(Q),
|
|
|
|
oe = -P / (2 * O),
|
|
|
|
H = oe < -1 ? -1 : oe > 1 ? 1 : oe,
|
|
|
|
ie = Math.acos(H),
|
|
|
|
ae = 2 * Lt(O),
|
|
|
|
pe = ae * Math.cos(ie / 3) - a / 3,
|
|
|
|
Ce = ae * Math.cos((ie + 2 * Math.PI) / 3) - a / 3,
|
|
|
|
ve = ae * Math.cos((ie + 4 * Math.PI) / 3) - a / 3;
|
|
|
|
return [pe, Ce, ve].filter(It);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
if (M === 0) {
|
|
|
|
let L = b < 0 ? Lt(-b) : -Lt(b),
|
|
|
|
Q = 2 * L - a / 3,
|
|
|
|
O = -L - a / 3;
|
|
|
|
return [Q, O].filter(It);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
let w = Math.sqrt(M),
|
|
|
|
_ = Lt(w - b),
|
|
|
|
$ = Lt(w + b);
|
|
|
|
return [_ - $ - a / 3].filter(It);
|
|
|
|
}
|
|
|
|
s(Hi, "getCubicRoots");
|
|
|
|
function Ki(t, e, n, o, a) {
|
|
|
|
let u = Hi(t.x - a, e.x - a, n.x - a, o.x - a);
|
|
|
|
return u.length > 0 ? un(t, e, n, o, u[0]).y : NaN;
|
|
|
|
}
|
|
|
|
s(Ki, "cubicBezierYforX");
|
|
|
|
function lo(t) {
|
|
|
|
if (!t || t.length == 0)
|
|
|
|
throw new Error("Need at least one point for easingLinear.");
|
|
|
|
let e = t.length;
|
|
|
|
return (n) => {
|
|
|
|
if (n <= 0 || t.length == 1 || n <= t[0].x) return t[0].y;
|
|
|
|
for (let o = 0; o < e; o++)
|
|
|
|
if (t[o].x >= n) return et(n, t[o - 1].x, t[o].x, t[o - 1].y, t[o].y);
|
|
|
|
return t[t.length - 1].y;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(lo, "easingLinear");
|
|
|
|
function mo(t, e) {
|
|
|
|
return (n) => Ki(T(0, 0), t, e, T(1, 1), n);
|
|
|
|
}
|
|
|
|
s(mo, "easingCubicBezier");
|
|
|
|
function ho(t, e = "jump-end") {
|
|
|
|
let n = 1 / t,
|
|
|
|
o = e == "jump-start" || e == "jump-both",
|
|
|
|
a = e == "jump-end" || e == "jump-both",
|
|
|
|
u = 1 / (t + (a ? 1 : 0)),
|
|
|
|
l = o ? u : 0;
|
|
|
|
return (f) => {
|
|
|
|
let v = Math.floor(f / n);
|
|
|
|
return l + v * u;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(ho, "easingSteps");
|
|
|
|
function po(t, e) {
|
|
|
|
let n = Number.MAX_VALUE,
|
|
|
|
o = T(0);
|
|
|
|
for (let a of [t, e])
|
|
|
|
for (let u = 0; u < a.pts.length; u++) {
|
|
|
|
let l = a.pts[u],
|
|
|
|
v = a.pts[(u + 1) % a.pts.length].sub(l).normal().unit(),
|
|
|
|
m = Number.MAX_VALUE,
|
|
|
|
P = -Number.MAX_VALUE;
|
|
|
|
for (let _ = 0; _ < t.pts.length; _++) {
|
|
|
|
let $ = t.pts[_].dot(v);
|
|
|
|
(m = Math.min(m, $)), (P = Math.max(P, $));
|
|
|
|
}
|
|
|
|
let b = Number.MAX_VALUE,
|
|
|
|
M = -Number.MAX_VALUE;
|
|
|
|
for (let _ = 0; _ < e.pts.length; _++) {
|
|
|
|
let $ = e.pts[_].dot(v);
|
|
|
|
(b = Math.min(b, $)), (M = Math.max(M, $));
|
|
|
|
}
|
|
|
|
let w = Math.min(P, M) - Math.max(m, b);
|
|
|
|
if (w < 0) return null;
|
|
|
|
if (w < Math.abs(n)) {
|
|
|
|
let _ = M - m,
|
|
|
|
$ = b - P;
|
|
|
|
(n = Math.abs(_) < Math.abs($) ? _ : $), (o = v.scale(n));
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
return o;
|
|
|
|
}
|
|
|
|
s(po, "sat");
|
|
|
|
function fo(t, e, n) {
|
|
|
|
return (e.x - t.x) * (n.y - t.y) - (e.y - t.y) * (n.x - t.x) >= 0;
|
|
|
|
}
|
|
|
|
s(fo, "isOrientedCcw");
|
|
|
|
function qi(t) {
|
|
|
|
let e = 0,
|
|
|
|
n = t[t.length - 1];
|
|
|
|
for (let o = 0; o < t.length; o++)
|
|
|
|
(e += (t[o].x - n.x) * (t[o].y + n.y)), (n = t[o]);
|
|
|
|
return e < 0;
|
|
|
|
}
|
|
|
|
s(qi, "isOrientedCcwPolygon");
|
|
|
|
function Yn(t, e, n, o) {
|
|
|
|
let a = o.x - n.x,
|
|
|
|
u = o.y - n.y,
|
|
|
|
l = a * (t.y - n.y) - u * (t.x - n.x),
|
|
|
|
f = a * (e.y - n.y) - u * (e.x - n.x);
|
|
|
|
return l * f >= 0;
|
|
|
|
}
|
|
|
|
s(Yn, "onSameSide");
|
|
|
|
function zi(t, e, n, o) {
|
|
|
|
return Yn(t, e, n, o) && Yn(t, n, e, o) && Yn(t, o, e, n);
|
|
|
|
}
|
|
|
|
s(zi, "pointInTriangle");
|
|
|
|
function Wi(t, e, n, o) {
|
|
|
|
for (let a of t)
|
|
|
|
if (a !== e && a !== n && a !== o && zi(a, e, n, o)) return !0;
|
|
|
|
return !1;
|
|
|
|
}
|
|
|
|
s(Wi, "someInTriangle");
|
|
|
|
function Yi(t, e, n, o) {
|
|
|
|
return fo(t, e, n) && !Wi(o, t, e, n);
|
|
|
|
}
|
|
|
|
s(Yi, "isEar");
|
|
|
|
function ir(t) {
|
|
|
|
if (t.length < 3) return [];
|
|
|
|
if (t.length == 3) return [t];
|
|
|
|
let e = [],
|
|
|
|
n = [],
|
|
|
|
o = 0;
|
|
|
|
for (let b = 0; b < t.length; b++) {
|
|
|
|
let M = t[o],
|
|
|
|
w = t[b];
|
|
|
|
(w.x < M.x || (w.x == M.x && w.y < M.y)) && (o = o),
|
|
|
|
(e[b] = b + 1),
|
|
|
|
(n[b] = b - 1);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
(e[e.length - 1] = 0), (n[0] = n.length - 1), qi(t) || ([e, n] = [n, e]);
|
|
|
|
let a = [];
|
|
|
|
for (let b = 0; b < t.length; ++b) fo(t[n[b]], t[b], t[e[b]]) || a.push(t[b]);
|
|
|
|
let u = [],
|
|
|
|
l = t.length,
|
|
|
|
f = 1,
|
|
|
|
v = 0,
|
|
|
|
m,
|
|
|
|
P;
|
|
|
|
for (; l > 3; ) {
|
|
|
|
(m = e[f]), (P = n[f]);
|
|
|
|
let b = t[P],
|
|
|
|
M = t[f],
|
|
|
|
w = t[m];
|
|
|
|
if (Yi(b, M, w, a))
|
|
|
|
u.push([b, M, w]),
|
|
|
|
(e[P] = m),
|
|
|
|
(n[m] = P),
|
|
|
|
a.splice(a.indexOf(M), 1),
|
|
|
|
--l,
|
|
|
|
(v = 0);
|
|
|
|
else if (++v > l) return [];
|
|
|
|
f = m;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
return (m = e[f]), (P = n[f]), u.push([t[P], t[f], t[m]]), u;
|
|
|
|
}
|
|
|
|
s(ir, "triangulate");
|
|
|
|
function ar(t) {
|
|
|
|
if (t.length < 3) return !1;
|
|
|
|
let e = t.length - 2,
|
|
|
|
n = t.length - 1,
|
|
|
|
o = 0,
|
|
|
|
a = t[n].sub(t[e]),
|
|
|
|
u = t[o].sub(t[n]),
|
|
|
|
l = a.cross(u);
|
|
|
|
for (; o + 1 < t.length; )
|
2024-06-01 06:31:08 +00:00
|
|
|
if (
|
2024-06-17 22:57:39 +00:00
|
|
|
((e = n),
|
|
|
|
(n = o),
|
|
|
|
o++,
|
|
|
|
(a = t[n].sub(t[e])),
|
|
|
|
(u = t[o].sub(t[n])),
|
|
|
|
a.cross(u) * l < 0)
|
2024-06-01 06:31:08 +00:00
|
|
|
)
|
2024-06-17 22:57:39 +00:00
|
|
|
return !1;
|
|
|
|
return !0;
|
|
|
|
}
|
|
|
|
s(ar, "isConvex");
|
|
|
|
var _t = class extends Map {
|
|
|
|
static {
|
|
|
|
s(this, "Registry");
|
|
|
|
}
|
|
|
|
lastID = 0;
|
|
|
|
push(e) {
|
|
|
|
let n = this.lastID;
|
|
|
|
return this.set(n, e), this.lastID++, n;
|
|
|
|
}
|
|
|
|
pushd(e) {
|
|
|
|
let n = this.push(e);
|
|
|
|
return () => this.delete(n);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
tt = class t {
|
|
|
|
static {
|
|
|
|
s(this, "EventController");
|
|
|
|
}
|
|
|
|
paused = !1;
|
|
|
|
cancel;
|
|
|
|
constructor(e) {
|
|
|
|
this.cancel = e;
|
|
|
|
}
|
|
|
|
static join(e) {
|
|
|
|
let n = new t(() => e.forEach((o) => o.cancel()));
|
|
|
|
return (
|
|
|
|
Object.defineProperty(n, "paused", {
|
|
|
|
get: () => e[0].paused,
|
|
|
|
set: (o) => e.forEach((a) => (a.paused = o)),
|
|
|
|
}),
|
|
|
|
(n.paused = !1),
|
|
|
|
n
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
we = class {
|
|
|
|
static {
|
|
|
|
s(this, "Event");
|
|
|
|
}
|
|
|
|
handlers = new _t();
|
|
|
|
add(e) {
|
|
|
|
let n = this.handlers.pushd((...a) => {
|
|
|
|
o.paused || e(...a);
|
|
|
|
}),
|
|
|
|
o = new tt(n);
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
addOnce(e) {
|
|
|
|
let n = this.add((...o) => {
|
|
|
|
n.cancel(), e(...o);
|
|
|
|
});
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
next() {
|
|
|
|
return new Promise((e) => this.addOnce(e));
|
|
|
|
}
|
|
|
|
trigger(...e) {
|
|
|
|
this.handlers.forEach((n) => n(...e));
|
|
|
|
}
|
|
|
|
numListeners() {
|
|
|
|
return this.handlers.size;
|
|
|
|
}
|
|
|
|
clear() {
|
|
|
|
this.handlers.clear();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
nt = class {
|
|
|
|
static {
|
|
|
|
s(this, "EventHandler");
|
|
|
|
}
|
|
|
|
handlers = {};
|
|
|
|
on(e, n) {
|
|
|
|
return (
|
|
|
|
this.handlers[e] || (this.handlers[e] = new we()),
|
|
|
|
this.handlers[e].add(n)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
onOnce(e, n) {
|
|
|
|
let o = this.on(e, (...a) => {
|
|
|
|
o.cancel(), n(...a);
|
|
|
|
});
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
next(e) {
|
|
|
|
return new Promise((n) => {
|
|
|
|
this.onOnce(e, (...o) => n(o[0]));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
trigger(e, ...n) {
|
|
|
|
this.handlers[e] && this.handlers[e].trigger(...n);
|
|
|
|
}
|
|
|
|
remove(e) {
|
|
|
|
delete this.handlers[e];
|
|
|
|
}
|
|
|
|
clear() {
|
|
|
|
this.handlers = {};
|
|
|
|
}
|
|
|
|
numListeners(e) {
|
|
|
|
return this.handlers[e]?.numListeners() ?? 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
function mn(t, e) {
|
|
|
|
if (t === e) return !0;
|
|
|
|
let n = typeof t,
|
|
|
|
o = typeof e;
|
|
|
|
if (n !== o) return !1;
|
|
|
|
if (n === "object" && o === "object" && t !== null && e !== null) {
|
|
|
|
if (Array.isArray(t) !== Array.isArray(e)) return !1;
|
|
|
|
let a = Object.keys(t),
|
|
|
|
u = Object.keys(e);
|
|
|
|
if (a.length !== u.length) return !1;
|
|
|
|
for (let l of a) {
|
|
|
|
let f = t[l],
|
|
|
|
v = e[l];
|
|
|
|
if (!mn(f, v)) return !1;
|
|
|
|
}
|
|
|
|
return !0;
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
return !1;
|
|
|
|
}
|
|
|
|
s(mn, "deepEq");
|
|
|
|
function Xi(t) {
|
|
|
|
let e = window.atob(t),
|
|
|
|
n = e.length,
|
|
|
|
o = new Uint8Array(n);
|
|
|
|
for (let a = 0; a < n; a++) o[a] = e.charCodeAt(a);
|
|
|
|
return o.buffer;
|
|
|
|
}
|
|
|
|
s(Xi, "base64ToArrayBuffer");
|
|
|
|
function bo(t) {
|
|
|
|
return Xi(t.split(",")[1]);
|
|
|
|
}
|
|
|
|
s(bo, "dataURLToArrayBuffer");
|
|
|
|
function dn(t, e) {
|
|
|
|
let n = document.createElement("a");
|
|
|
|
(n.href = e), (n.download = t), n.click();
|
|
|
|
}
|
|
|
|
s(dn, "download");
|
|
|
|
function cr(t, e) {
|
|
|
|
dn(t, "data:text/plain;charset=utf-8," + e);
|
|
|
|
}
|
|
|
|
s(cr, "downloadText");
|
|
|
|
function vo(t, e) {
|
|
|
|
cr(t, JSON.stringify(e));
|
|
|
|
}
|
|
|
|
s(vo, "downloadJSON");
|
|
|
|
function ur(t, e) {
|
|
|
|
let n = URL.createObjectURL(e);
|
|
|
|
dn(t, n), URL.revokeObjectURL(n);
|
|
|
|
}
|
|
|
|
s(ur, "downloadBlob");
|
|
|
|
var lr = s((t) => t.match(/^data:\w+\/\w+;base64,.+/), "isDataURL");
|
|
|
|
var xo = s((t) => t.split(".").slice(0, -1).join("."), "getFileName");
|
|
|
|
function Fe(t, e) {
|
|
|
|
return (...n) => {
|
|
|
|
let o = n.length;
|
|
|
|
if (o === t.length) return t(...n);
|
|
|
|
if (o === e.length) return e(...n);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(Fe, "overload2");
|
|
|
|
var yo = (() => {
|
|
|
|
let t = 0;
|
|
|
|
return () => t++;
|
|
|
|
})(),
|
|
|
|
wo = s(
|
|
|
|
(t) => (t instanceof Error ? t.message : String(t)),
|
|
|
|
"getErrorMessage"
|
|
|
|
);
|
|
|
|
var ln = class {
|
|
|
|
static {
|
|
|
|
s(this, "BinaryHeap");
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
_items;
|
|
|
|
_compareFn;
|
|
|
|
constructor(e = (n, o) => n < o) {
|
|
|
|
(this._compareFn = e), (this._items = []);
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
insert(e) {
|
|
|
|
this._items.push(e), this.moveUp(this._items.length - 1);
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
remove() {
|
|
|
|
if (this._items.length === 0) return null;
|
|
|
|
let e = this._items[0],
|
|
|
|
n = this._items.pop();
|
2024-06-02 05:39:23 +00:00
|
|
|
return (
|
2024-06-17 22:57:39 +00:00
|
|
|
this._items.length !== 0 && ((this._items[0] = n), this.moveDown(0)), e
|
2024-06-02 05:39:23 +00:00
|
|
|
);
|
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
clear() {
|
|
|
|
this._items.splice(0, this._items.length);
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
moveUp(e) {
|
|
|
|
for (; e > 0; ) {
|
|
|
|
let n = Math.floor((e - 1) / 2);
|
|
|
|
if (
|
|
|
|
!this._compareFn(this._items[e], this._items[n]) &&
|
|
|
|
this._items[e] >= this._items[n]
|
|
|
|
)
|
|
|
|
break;
|
|
|
|
this.swap(e, n), (e = n);
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
moveDown(e) {
|
|
|
|
for (; e < Math.floor(this._items.length / 2); ) {
|
|
|
|
let n = 2 * e + 1;
|
|
|
|
if (
|
|
|
|
(n < this._items.length - 1 &&
|
|
|
|
!this._compareFn(this._items[n], this._items[n + 1]) &&
|
|
|
|
++n,
|
|
|
|
this._compareFn(this._items[e], this._items[n]))
|
|
|
|
)
|
|
|
|
break;
|
|
|
|
this.swap(e, n), (e = n);
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
swap(e, n) {
|
|
|
|
[this._items[e], this._items[n]] = [this._items[n], this._items[e]];
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
get length() {
|
|
|
|
return this._items.length;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
};
|
|
|
|
var $i = Object.freeze([
|
|
|
|
776, 2359, 2367, 2984, 3007, 3021, 3633, 3635, 3648, 3657, 4352, 4449, 4520,
|
|
|
|
]);
|
|
|
|
function Co(t) {
|
|
|
|
if (typeof t != "string")
|
|
|
|
throw new TypeError("string cannot be undefined or null");
|
|
|
|
let e = [],
|
|
|
|
n = 0,
|
|
|
|
o = 0;
|
|
|
|
for (; n < t.length; ) {
|
|
|
|
if (
|
|
|
|
((o += Qi(n + o, t)),
|
|
|
|
oa(t[n + o]) && o++,
|
|
|
|
ta(t[n + o]) && o++,
|
|
|
|
na(t[n + o]) && o++,
|
|
|
|
sa(t[n + o]))
|
|
|
|
) {
|
|
|
|
o++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
e.push(t.substring(n, n + o)), (n += o), (o = 0);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
return e;
|
|
|
|
}
|
|
|
|
s(Co, "runes");
|
|
|
|
function Qi(t, e) {
|
|
|
|
let n = e[t];
|
|
|
|
if (!Ji(n) || t === e.length - 1) return 1;
|
|
|
|
let o = n + e[t + 1],
|
|
|
|
a = e.substring(t + 2, t + 5);
|
|
|
|
return go(o) && go(a)
|
|
|
|
? 4
|
|
|
|
: Zi(o) && ra(a)
|
|
|
|
? e.slice(t).indexOf(String.fromCodePoint(917631)) + 2
|
|
|
|
: ea(a)
|
|
|
|
? 4
|
|
|
|
: 2;
|
|
|
|
}
|
|
|
|
s(Qi, "nextUnits");
|
|
|
|
function Ji(t) {
|
|
|
|
return t && vt(t[0].charCodeAt(0), 55296, 56319);
|
|
|
|
}
|
|
|
|
s(Ji, "isFirstOfSurrogatePair");
|
|
|
|
function go(t) {
|
|
|
|
return vt(mr(t), 127462, 127487);
|
|
|
|
}
|
|
|
|
s(go, "isRegionalIndicator");
|
|
|
|
function Zi(t) {
|
|
|
|
return vt(mr(t), 127988, 127988);
|
|
|
|
}
|
|
|
|
s(Zi, "isSubdivisionFlag");
|
|
|
|
function ea(t) {
|
|
|
|
return vt(mr(t), 127995, 127999);
|
|
|
|
}
|
|
|
|
s(ea, "isFitzpatrickModifier");
|
|
|
|
function ta(t) {
|
|
|
|
return typeof t == "string" && vt(t.charCodeAt(0), 65024, 65039);
|
|
|
|
}
|
|
|
|
s(ta, "isVariationSelector");
|
|
|
|
function na(t) {
|
|
|
|
return typeof t == "string" && vt(t.charCodeAt(0), 8400, 8447);
|
|
|
|
}
|
|
|
|
s(na, "isDiacriticalMark");
|
|
|
|
function ra(t) {
|
|
|
|
let e = t.codePointAt(0);
|
|
|
|
return typeof t == "string" && typeof e == "number" && vt(e, 917504, 917631);
|
|
|
|
}
|
|
|
|
s(ra, "isSupplementarySpecialpurposePlane");
|
|
|
|
function oa(t) {
|
|
|
|
return typeof t == "string" && $i.includes(t.charCodeAt(0));
|
|
|
|
}
|
|
|
|
s(oa, "isGrapheme");
|
|
|
|
function sa(t) {
|
|
|
|
return typeof t == "string" && t.charCodeAt(0) === 8205;
|
|
|
|
}
|
|
|
|
s(sa, "isZeroWidthJoiner");
|
|
|
|
function mr(t) {
|
|
|
|
let e = t.charCodeAt(0) - 55296,
|
|
|
|
n = t.charCodeAt(1) - 56320;
|
|
|
|
return (e << 10) + n + 65536;
|
|
|
|
}
|
|
|
|
s(mr, "codePointFromSurrogatePair");
|
|
|
|
function vt(t, e, n) {
|
|
|
|
return t >= e && t <= n;
|
|
|
|
}
|
|
|
|
s(vt, "betweenInclusive");
|
|
|
|
function To(t) {
|
|
|
|
return (
|
|
|
|
t?.prototype &&
|
|
|
|
Object.getOwnPropertyDescriptor(t.prototype, "constructor") !== void 0
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(To, "isClass");
|
|
|
|
var dr = {
|
|
|
|
"Joy-Con L+R (STANDARD GAMEPAD Vendor: 057e Product: 200e)": {
|
|
|
|
buttons: {
|
|
|
|
0: "south",
|
|
|
|
1: "east",
|
|
|
|
2: "west",
|
|
|
|
3: "north",
|
|
|
|
4: "lshoulder",
|
|
|
|
5: "rshoulder",
|
|
|
|
6: "ltrigger",
|
|
|
|
7: "rtrigger",
|
|
|
|
8: "select",
|
|
|
|
9: "start",
|
|
|
|
10: "lstick",
|
|
|
|
11: "rstick",
|
|
|
|
12: "dpad-up",
|
|
|
|
13: "dpad-down",
|
|
|
|
14: "dpad-left",
|
|
|
|
15: "dpad-right",
|
|
|
|
16: "home",
|
|
|
|
17: "capture",
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-17 22:57:39 +00:00
|
|
|
sticks: { left: { x: 0, y: 1 }, right: { x: 2, y: 3 } },
|
|
|
|
},
|
|
|
|
"Joy-Con (L) (STANDARD GAMEPAD Vendor: 057e Product: 2006)": {
|
|
|
|
buttons: {
|
|
|
|
0: "south",
|
|
|
|
1: "east",
|
|
|
|
2: "west",
|
|
|
|
3: "north",
|
|
|
|
4: "lshoulder",
|
|
|
|
5: "rshoulder",
|
|
|
|
9: "select",
|
|
|
|
10: "lstick",
|
|
|
|
16: "start",
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-17 22:57:39 +00:00
|
|
|
sticks: { left: { x: 0, y: 1 } },
|
|
|
|
},
|
|
|
|
"Joy-Con (R) (STANDARD GAMEPAD Vendor: 057e Product: 2007)": {
|
|
|
|
buttons: {
|
|
|
|
0: "south",
|
|
|
|
1: "east",
|
|
|
|
2: "west",
|
|
|
|
3: "north",
|
|
|
|
4: "lshoulder",
|
|
|
|
5: "rshoulder",
|
|
|
|
9: "start",
|
|
|
|
10: "lstick",
|
|
|
|
16: "select",
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-17 22:57:39 +00:00
|
|
|
sticks: { left: { x: 0, y: 1 } },
|
|
|
|
},
|
|
|
|
"Pro Controller (STANDARD GAMEPAD Vendor: 057e Product: 2009)": {
|
|
|
|
buttons: {
|
|
|
|
0: "south",
|
|
|
|
1: "east",
|
|
|
|
2: "west",
|
|
|
|
3: "north",
|
|
|
|
4: "lshoulder",
|
|
|
|
5: "rshoulder",
|
|
|
|
6: "ltrigger",
|
|
|
|
7: "rtrigger",
|
|
|
|
8: "select",
|
|
|
|
9: "start",
|
|
|
|
10: "lstick",
|
|
|
|
11: "rstick",
|
|
|
|
12: "dpad-up",
|
|
|
|
13: "dpad-down",
|
|
|
|
14: "dpad-left",
|
|
|
|
15: "dpad-right",
|
|
|
|
16: "home",
|
|
|
|
17: "capture",
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-17 22:57:39 +00:00
|
|
|
sticks: { left: { x: 0, y: 1 }, right: { x: 2, y: 3 } },
|
|
|
|
},
|
|
|
|
default: {
|
|
|
|
buttons: {
|
|
|
|
0: "south",
|
|
|
|
1: "east",
|
|
|
|
2: "west",
|
|
|
|
3: "north",
|
|
|
|
4: "lshoulder",
|
|
|
|
5: "rshoulder",
|
|
|
|
6: "ltrigger",
|
|
|
|
7: "rtrigger",
|
|
|
|
8: "select",
|
|
|
|
9: "start",
|
|
|
|
10: "lstick",
|
|
|
|
11: "rstick",
|
|
|
|
12: "dpad-up",
|
|
|
|
13: "dpad-down",
|
|
|
|
14: "dpad-left",
|
|
|
|
15: "dpad-right",
|
|
|
|
16: "home",
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-17 22:57:39 +00:00
|
|
|
sticks: { left: { x: 0, y: 1 }, right: { x: 2, y: 3 } },
|
|
|
|
},
|
|
|
|
};
|
|
|
|
var Ut = class {
|
|
|
|
static {
|
|
|
|
s(this, "ButtonState");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
pressed = new Set([]);
|
|
|
|
pressedRepeat = new Set([]);
|
|
|
|
released = new Set([]);
|
|
|
|
down = new Set([]);
|
|
|
|
update() {
|
|
|
|
this.pressed.clear(), this.released.clear(), this.pressedRepeat.clear();
|
|
|
|
}
|
|
|
|
press(e) {
|
|
|
|
this.pressed.add(e), this.pressedRepeat.add(e), this.down.add(e);
|
|
|
|
}
|
|
|
|
pressRepeat(e) {
|
|
|
|
this.pressedRepeat.add(e);
|
|
|
|
}
|
|
|
|
release(e) {
|
|
|
|
this.down.delete(e), this.pressed.delete(e), this.released.add(e);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
hr = class {
|
|
|
|
static {
|
|
|
|
s(this, "GamepadState");
|
|
|
|
}
|
|
|
|
buttonState = new Ut();
|
|
|
|
stickState = new Map();
|
|
|
|
},
|
|
|
|
pr = class {
|
2024-06-01 06:31:08 +00:00
|
|
|
static {
|
2024-06-17 22:57:39 +00:00
|
|
|
s(this, "FPSCounter");
|
|
|
|
}
|
|
|
|
dts = [];
|
|
|
|
timer = 0;
|
|
|
|
fps = 0;
|
|
|
|
tick(e) {
|
|
|
|
this.dts.push(e),
|
|
|
|
(this.timer += e),
|
|
|
|
this.timer >= 1 &&
|
|
|
|
((this.timer = 0),
|
|
|
|
(this.fps = Math.round(
|
|
|
|
1 / (this.dts.reduce((n, o) => n + o) / this.dts.length)
|
|
|
|
)),
|
|
|
|
(this.dts = []));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Eo = s((t) => {
|
|
|
|
if (!t.canvas) throw new Error("Please provide a canvas");
|
|
|
|
let e = {
|
|
|
|
canvas: t.canvas,
|
|
|
|
loopID: null,
|
|
|
|
stopped: !1,
|
|
|
|
dt: 0,
|
|
|
|
time: 0,
|
|
|
|
realTime: 0,
|
|
|
|
fpsCounter: new pr(),
|
|
|
|
timeScale: 1,
|
|
|
|
skipTime: !1,
|
|
|
|
isHidden: !1,
|
|
|
|
numFrames: 0,
|
|
|
|
mousePos: new D(0),
|
|
|
|
mouseDeltaPos: new D(0),
|
|
|
|
keyState: new Ut(),
|
|
|
|
mouseState: new Ut(),
|
|
|
|
mergedGamepadState: new hr(),
|
|
|
|
gamepadStates: new Map(),
|
|
|
|
gamepads: [],
|
|
|
|
charInputted: [],
|
|
|
|
isMouseMoved: !1,
|
|
|
|
lastWidth: t.canvas.offsetWidth,
|
|
|
|
lastHeight: t.canvas.offsetHeight,
|
|
|
|
events: new nt(),
|
|
|
|
};
|
|
|
|
function n() {
|
|
|
|
return e.dt * e.timeScale;
|
|
|
|
}
|
|
|
|
s(n, "dt");
|
|
|
|
function o() {
|
|
|
|
return e.isHidden;
|
|
|
|
}
|
|
|
|
s(o, "isHidden");
|
|
|
|
function a() {
|
|
|
|
return e.time;
|
|
|
|
}
|
|
|
|
s(a, "time");
|
|
|
|
function u() {
|
|
|
|
return e.fpsCounter.fps;
|
|
|
|
}
|
|
|
|
s(u, "fps");
|
|
|
|
function l() {
|
|
|
|
return e.numFrames;
|
|
|
|
}
|
|
|
|
s(l, "numFrames");
|
|
|
|
function f() {
|
|
|
|
return e.canvas.toDataURL();
|
|
|
|
}
|
|
|
|
s(f, "screenshot");
|
|
|
|
function v(p) {
|
|
|
|
e.canvas.style.cursor = p;
|
|
|
|
}
|
|
|
|
s(v, "setCursor");
|
|
|
|
function m() {
|
|
|
|
return e.canvas.style.cursor;
|
|
|
|
}
|
|
|
|
s(m, "getCursor");
|
|
|
|
function P(p) {
|
|
|
|
if (p)
|
|
|
|
try {
|
|
|
|
let V = e.canvas.requestPointerLock();
|
|
|
|
V.catch && V.catch((j) => console.error(j));
|
|
|
|
} catch (V) {
|
|
|
|
console.error(V);
|
|
|
|
}
|
|
|
|
else document.exitPointerLock();
|
|
|
|
}
|
|
|
|
s(P, "setCursorLocked");
|
|
|
|
function b() {
|
|
|
|
return !!document.pointerLockElement;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
s(b, "isCursorLocked");
|
|
|
|
function M(p) {
|
|
|
|
p.requestFullscreen
|
|
|
|
? p.requestFullscreen()
|
|
|
|
: p.webkitRequestFullscreen && p.webkitRequestFullscreen();
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
s(M, "enterFullscreen");
|
|
|
|
function w() {
|
|
|
|
document.exitFullscreen
|
|
|
|
? document.exitFullscreen()
|
|
|
|
: document.webkitExitFullScreen && document.webkitExitFullScreen();
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
s(w, "exitFullscreen");
|
|
|
|
function _(p = !0) {
|
|
|
|
p ? M(e.canvas) : w();
|
|
|
|
}
|
|
|
|
s(_, "setFullscreen");
|
|
|
|
function $() {
|
2024-06-01 06:31:08 +00:00
|
|
|
return (
|
2024-06-17 22:57:39 +00:00
|
|
|
document.fullscreenElement === e.canvas ||
|
|
|
|
document.webkitFullscreenElement === e.canvas
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
s($, "isFullscreen");
|
|
|
|
function X() {
|
|
|
|
e.stopped = !0;
|
|
|
|
for (let p in te) e.canvas.removeEventListener(p, te[p]);
|
|
|
|
for (let p in We) document.removeEventListener(p, We[p]);
|
|
|
|
for (let p in je) window.removeEventListener(p, je[p]);
|
|
|
|
tn.disconnect();
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
s(X, "quit");
|
|
|
|
function L(p) {
|
|
|
|
e.loopID !== null && cancelAnimationFrame(e.loopID);
|
|
|
|
let V = 0,
|
|
|
|
j = s((J) => {
|
|
|
|
if (e.stopped) return;
|
|
|
|
if (document.visibilityState !== "visible") {
|
|
|
|
e.loopID = requestAnimationFrame(j);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let xe = J / 1e3,
|
|
|
|
le = xe - e.realTime,
|
|
|
|
Ke = t.maxFPS ? 1 / t.maxFPS : 0;
|
|
|
|
(e.realTime = xe),
|
|
|
|
(V += le),
|
|
|
|
V > Ke &&
|
|
|
|
(e.skipTime ||
|
|
|
|
((e.dt = V), (e.time += n()), e.fpsCounter.tick(e.dt)),
|
|
|
|
(V = 0),
|
|
|
|
(e.skipTime = !1),
|
|
|
|
e.numFrames++,
|
|
|
|
Gt(),
|
|
|
|
p(),
|
|
|
|
Gn()),
|
|
|
|
(e.loopID = requestAnimationFrame(j));
|
|
|
|
}, "frame");
|
|
|
|
j(0);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
s(L, "run");
|
|
|
|
function Q() {
|
|
|
|
return "ontouchstart" in window || navigator.maxTouchPoints > 0;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
s(Q, "isTouchscreen");
|
|
|
|
function O() {
|
|
|
|
return e.mousePos.clone();
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
s(O, "mousePos");
|
|
|
|
function oe() {
|
|
|
|
return e.mouseDeltaPos.clone();
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
s(oe, "mouseDeltaPos");
|
|
|
|
function H(p = "left") {
|
|
|
|
return e.mouseState.pressed.has(p);
|
|
|
|
}
|
|
|
|
s(H, "isMousePressed");
|
|
|
|
function ie(p = "left") {
|
|
|
|
return e.mouseState.down.has(p);
|
|
|
|
}
|
|
|
|
s(ie, "isMouseDown");
|
|
|
|
function se(p = "left") {
|
|
|
|
return e.mouseState.released.has(p);
|
|
|
|
}
|
|
|
|
s(se, "isMouseReleased");
|
|
|
|
function ae() {
|
|
|
|
return e.isMouseMoved;
|
|
|
|
}
|
|
|
|
s(ae, "isMouseMoved");
|
|
|
|
function pe(p) {
|
|
|
|
return p === void 0
|
|
|
|
? e.keyState.pressed.size > 0
|
|
|
|
: e.keyState.pressed.has(p);
|
|
|
|
}
|
|
|
|
s(pe, "isKeyPressed");
|
|
|
|
function Ce(p) {
|
|
|
|
return p === void 0
|
|
|
|
? e.keyState.pressedRepeat.size > 0
|
|
|
|
: e.keyState.pressedRepeat.has(p);
|
|
|
|
}
|
|
|
|
s(Ce, "isKeyPressedRepeat");
|
|
|
|
function ve(p) {
|
|
|
|
return p === void 0 ? e.keyState.down.size > 0 : e.keyState.down.has(p);
|
|
|
|
}
|
|
|
|
s(ve, "isKeyDown");
|
|
|
|
function Ie(p) {
|
|
|
|
return p === void 0
|
|
|
|
? e.keyState.released.size > 0
|
|
|
|
: e.keyState.released.has(p);
|
|
|
|
}
|
|
|
|
s(Ie, "isKeyReleased");
|
|
|
|
function Le(p) {
|
|
|
|
return p === void 0
|
|
|
|
? e.mergedGamepadState.buttonState.pressed.size > 0
|
|
|
|
: e.mergedGamepadState.buttonState.pressed.has(p);
|
|
|
|
}
|
|
|
|
s(Le, "isGamepadButtonPressed");
|
|
|
|
function Te(p) {
|
|
|
|
return p === void 0
|
|
|
|
? e.mergedGamepadState.buttonState.down.size > 0
|
|
|
|
: e.mergedGamepadState.buttonState.down.has(p);
|
|
|
|
}
|
|
|
|
s(Te, "isGamepadButtonDown");
|
|
|
|
function Ne(p) {
|
|
|
|
return p === void 0
|
|
|
|
? e.mergedGamepadState.buttonState.released.size > 0
|
|
|
|
: e.mergedGamepadState.buttonState.released.has(p);
|
|
|
|
}
|
|
|
|
s(Ne, "isGamepadButtonReleased");
|
|
|
|
function _e(p) {
|
|
|
|
return e.events.on("resize", p);
|
|
|
|
}
|
|
|
|
s(_e, "onResize");
|
|
|
|
let He = Fe(
|
|
|
|
(p) => e.events.on("keyDown", p),
|
|
|
|
(p, V) => e.events.on("keyDown", (j) => j === p && V(p))
|
|
|
|
),
|
|
|
|
dt = Fe(
|
|
|
|
(p) => e.events.on("keyPress", p),
|
|
|
|
(p, V) => e.events.on("keyPress", (j) => j === p && V(p))
|
|
|
|
),
|
|
|
|
Ee = Fe(
|
|
|
|
(p) => e.events.on("keyPressRepeat", p),
|
|
|
|
(p, V) => e.events.on("keyPressRepeat", (j) => j === p && V(p))
|
|
|
|
),
|
|
|
|
Re = Fe(
|
|
|
|
(p) => e.events.on("keyRelease", p),
|
|
|
|
(p, V) => e.events.on("keyRelease", (j) => j === p && V(p))
|
|
|
|
),
|
|
|
|
ze = Fe(
|
|
|
|
(p) => e.events.on("mouseDown", (V) => p(V)),
|
|
|
|
(p, V) => e.events.on("mouseDown", (j) => j === p && V(j))
|
|
|
|
),
|
|
|
|
ot = Fe(
|
|
|
|
(p) => e.events.on("mousePress", (V) => p(V)),
|
|
|
|
(p, V) => e.events.on("mousePress", (j) => j === p && V(j))
|
|
|
|
),
|
|
|
|
st = Fe(
|
|
|
|
(p) => e.events.on("mouseRelease", (V) => p(V)),
|
|
|
|
(p, V) => e.events.on("mouseRelease", (j) => j === p && V(j))
|
|
|
|
);
|
|
|
|
function Ct(p) {
|
|
|
|
return e.events.on("mouseMove", () => p(O(), oe()));
|
|
|
|
}
|
|
|
|
s(Ct, "onMouseMove");
|
|
|
|
function Xt(p) {
|
|
|
|
return e.events.on("charInput", p);
|
|
|
|
}
|
|
|
|
s(Xt, "onCharInput");
|
|
|
|
function $t(p) {
|
|
|
|
return e.events.on("touchStart", p);
|
|
|
|
}
|
|
|
|
s($t, "onTouchStart");
|
|
|
|
function An(p) {
|
|
|
|
return e.events.on("touchMove", p);
|
|
|
|
}
|
|
|
|
s(An, "onTouchMove");
|
|
|
|
function Qt(p) {
|
|
|
|
return e.events.on("touchEnd", p);
|
|
|
|
}
|
|
|
|
s(Qt, "onTouchEnd");
|
|
|
|
function Vn(p) {
|
|
|
|
return e.events.on("scroll", p);
|
|
|
|
}
|
|
|
|
s(Vn, "onScroll");
|
|
|
|
function Rn(p) {
|
|
|
|
return e.events.on("hide", p);
|
|
|
|
}
|
|
|
|
s(Rn, "onHide");
|
|
|
|
function Jt(p) {
|
|
|
|
return e.events.on("show", p);
|
|
|
|
}
|
|
|
|
s(Jt, "onShow");
|
|
|
|
function Un(p, V) {
|
|
|
|
if (typeof p == "function") return e.events.on("gamepadButtonDown", p);
|
|
|
|
if (typeof p == "string" && typeof V == "function")
|
|
|
|
return e.events.on("gamepadButtonDown", (j) => j === p && V(p));
|
|
|
|
}
|
|
|
|
s(Un, "onGamepadButtonDown");
|
|
|
|
function Pn(p, V) {
|
|
|
|
if (typeof p == "function") return e.events.on("gamepadButtonPress", p);
|
|
|
|
if (typeof p == "string" && typeof V == "function")
|
|
|
|
return e.events.on("gamepadButtonPress", (j) => j === p && V(p));
|
|
|
|
}
|
|
|
|
s(Pn, "onGamepadButtonPress");
|
|
|
|
function Zt(p, V) {
|
|
|
|
if (typeof p == "function") return e.events.on("gamepadButtonRelease", p);
|
|
|
|
if (typeof p == "string" && typeof V == "function")
|
|
|
|
return e.events.on("gamepadButtonRelease", (j) => j === p && V(p));
|
|
|
|
}
|
|
|
|
s(Zt, "onGamepadButtonRelease");
|
|
|
|
function en(p, V) {
|
|
|
|
return e.events.on("gamepadStick", (j, J) => j === p && V(J));
|
|
|
|
}
|
|
|
|
s(en, "onGamepadStick");
|
|
|
|
function Mn(p) {
|
|
|
|
e.events.on("gamepadConnect", p);
|
|
|
|
}
|
|
|
|
s(Mn, "onGamepadConnect");
|
|
|
|
function Dt(p) {
|
|
|
|
e.events.on("gamepadDisconnect", p);
|
|
|
|
}
|
|
|
|
s(Dt, "onGamepadDisconnect");
|
|
|
|
function Dn(p) {
|
|
|
|
return e.mergedGamepadState.stickState.get(p) || new D(0);
|
|
|
|
}
|
|
|
|
s(Dn, "getGamepadStick");
|
|
|
|
function it() {
|
|
|
|
return [...e.charInputted];
|
|
|
|
}
|
|
|
|
s(it, "charInputted");
|
|
|
|
function Se() {
|
|
|
|
return [...e.gamepads];
|
|
|
|
}
|
|
|
|
s(Se, "getGamepads");
|
|
|
|
function Gt() {
|
|
|
|
e.events.trigger("input"),
|
|
|
|
e.keyState.down.forEach((p) => e.events.trigger("keyDown", p)),
|
|
|
|
e.mouseState.down.forEach((p) => e.events.trigger("mouseDown", p)),
|
|
|
|
Fn();
|
|
|
|
}
|
|
|
|
s(Gt, "processInput");
|
|
|
|
function Gn() {
|
|
|
|
e.keyState.update(),
|
|
|
|
e.mouseState.update(),
|
|
|
|
e.mergedGamepadState.buttonState.update(),
|
|
|
|
e.mergedGamepadState.stickState.forEach((p, V) => {
|
|
|
|
e.mergedGamepadState.stickState.set(V, new D(0));
|
|
|
|
}),
|
|
|
|
(e.charInputted = []),
|
|
|
|
(e.isMouseMoved = !1),
|
|
|
|
e.gamepadStates.forEach((p) => {
|
|
|
|
p.buttonState.update(),
|
|
|
|
p.stickState.forEach((V, j) => {
|
|
|
|
p.stickState.set(j, new D(0));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
s(Gn, "resetInput");
|
|
|
|
function Tt(p) {
|
|
|
|
let V = {
|
|
|
|
index: p.index,
|
|
|
|
isPressed: (j) =>
|
|
|
|
e.gamepadStates.get(p.index).buttonState.pressed.has(j),
|
|
|
|
isDown: (j) => e.gamepadStates.get(p.index).buttonState.down.has(j),
|
|
|
|
isReleased: (j) =>
|
|
|
|
e.gamepadStates.get(p.index).buttonState.released.has(j),
|
|
|
|
getStick: (j) => e.gamepadStates.get(p.index).stickState.get(j),
|
|
|
|
};
|
|
|
|
return (
|
|
|
|
e.gamepads.push(V),
|
|
|
|
e.gamepadStates.set(p.index, {
|
|
|
|
buttonState: new Ut(),
|
|
|
|
stickState: new Map([
|
|
|
|
["left", new D(0)],
|
|
|
|
["right", new D(0)],
|
|
|
|
]),
|
|
|
|
}),
|
|
|
|
V
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(Tt, "registerGamepad");
|
|
|
|
function Bn(p) {
|
|
|
|
(e.gamepads = e.gamepads.filter((V) => V.index !== p.index)),
|
|
|
|
e.gamepadStates.delete(p.index);
|
|
|
|
}
|
|
|
|
s(Bn, "removeGamepad");
|
|
|
|
function Fn() {
|
|
|
|
for (let p of navigator.getGamepads())
|
|
|
|
p && !e.gamepadStates.has(p.index) && Tt(p);
|
|
|
|
for (let p of e.gamepads) {
|
|
|
|
let V = navigator.getGamepads()[p.index],
|
|
|
|
J = (t.gamepads ?? {})[V.id] ?? dr[V.id] ?? dr.default,
|
|
|
|
xe = e.gamepadStates.get(p.index);
|
|
|
|
for (let le = 0; le < V.buttons.length; le++)
|
|
|
|
V.buttons[le].pressed
|
|
|
|
? (xe.buttonState.down.has(J.buttons[le]) ||
|
|
|
|
(e.mergedGamepadState.buttonState.press(J.buttons[le]),
|
|
|
|
xe.buttonState.press(J.buttons[le]),
|
|
|
|
e.events.trigger("gamepadButtonPress", J.buttons[le])),
|
|
|
|
e.events.trigger("gamepadButtonDown", J.buttons[le]))
|
|
|
|
: xe.buttonState.down.has(J.buttons[le]) &&
|
|
|
|
(e.mergedGamepadState.buttonState.release(J.buttons[le]),
|
|
|
|
xe.buttonState.release(J.buttons[le]),
|
|
|
|
e.events.trigger("gamepadButtonRelease", J.buttons[le]));
|
|
|
|
for (let le in J.sticks) {
|
|
|
|
let Ke = J.sticks[le],
|
|
|
|
at = new D(V.axes[Ke.x], V.axes[Ke.y]);
|
|
|
|
xe.stickState.set(le, at),
|
|
|
|
e.mergedGamepadState.stickState.set(le, at),
|
|
|
|
e.events.trigger("gamepadStick", le, at);
|
|
|
|
}
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
s(Fn, "processGamepad");
|
|
|
|
let te = {},
|
|
|
|
We = {},
|
|
|
|
je = {},
|
|
|
|
Ue = t.pixelDensity || window.devicePixelRatio || 1;
|
|
|
|
te.mousemove = (p) => {
|
|
|
|
let V = new D(p.offsetX, p.offsetY),
|
|
|
|
j = new D(p.movementX, p.movementY);
|
|
|
|
if ($()) {
|
|
|
|
let J = e.canvas.width / Ue,
|
|
|
|
xe = e.canvas.height / Ue,
|
|
|
|
le = window.innerWidth,
|
|
|
|
Ke = window.innerHeight,
|
|
|
|
at = le / Ke,
|
|
|
|
In = J / xe;
|
|
|
|
if (at > In) {
|
|
|
|
let $e = Ke / xe,
|
|
|
|
pt = (le - J * $e) / 2;
|
|
|
|
(V.x = et(p.offsetX - pt, 0, J * $e, 0, J)),
|
|
|
|
(V.y = et(p.offsetY, 0, xe * $e, 0, xe));
|
|
|
|
} else {
|
|
|
|
let $e = le / J,
|
|
|
|
pt = (Ke - xe * $e) / 2;
|
|
|
|
(V.x = et(p.offsetX, 0, J * $e, 0, J)),
|
|
|
|
(V.y = et(p.offsetY - pt, 0, xe * $e, 0, xe));
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
e.events.onOnce("input", () => {
|
|
|
|
(e.isMouseMoved = !0),
|
|
|
|
(e.mousePos = V),
|
|
|
|
(e.mouseDeltaPos = j),
|
|
|
|
e.events.trigger("mouseMove");
|
|
|
|
});
|
|
|
|
};
|
|
|
|
let Oe = ["left", "middle", "right", "back", "forward"];
|
|
|
|
(te.mousedown = (p) => {
|
|
|
|
e.events.onOnce("input", () => {
|
|
|
|
let V = Oe[p.button];
|
|
|
|
V && (e.mouseState.press(V), e.events.trigger("mousePress", V));
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
(te.mouseup = (p) => {
|
2024-06-01 06:31:08 +00:00
|
|
|
e.events.onOnce("input", () => {
|
2024-06-17 22:57:39 +00:00
|
|
|
let V = Oe[p.button];
|
|
|
|
V && (e.mouseState.release(V), e.events.trigger("mouseRelease", V));
|
2024-06-01 06:31:08 +00:00
|
|
|
});
|
2024-06-17 22:57:39 +00:00
|
|
|
});
|
|
|
|
let ht = new Set([
|
|
|
|
" ",
|
|
|
|
"ArrowLeft",
|
|
|
|
"ArrowRight",
|
|
|
|
"ArrowUp",
|
|
|
|
"ArrowDown",
|
|
|
|
"Tab",
|
|
|
|
]),
|
|
|
|
Et = {
|
|
|
|
ArrowLeft: "left",
|
|
|
|
ArrowRight: "right",
|
|
|
|
ArrowUp: "up",
|
|
|
|
ArrowDown: "down",
|
|
|
|
" ": "space",
|
2024-06-01 06:31:08 +00:00
|
|
|
};
|
2024-06-17 22:57:39 +00:00
|
|
|
(te.keydown = (p) => {
|
|
|
|
ht.has(p.key) && p.preventDefault(),
|
2024-06-01 06:31:08 +00:00
|
|
|
e.events.onOnce("input", () => {
|
2024-06-17 22:57:39 +00:00
|
|
|
let V = Et[p.key] || p.key.toLowerCase();
|
|
|
|
V.length === 1
|
|
|
|
? (e.events.trigger("charInput", V), e.charInputted.push(V))
|
|
|
|
: V === "space" &&
|
|
|
|
(e.events.trigger("charInput", " "), e.charInputted.push(" ")),
|
|
|
|
p.repeat
|
|
|
|
? (e.keyState.pressRepeat(V),
|
|
|
|
e.events.trigger("keyPressRepeat", V))
|
|
|
|
: (e.keyState.press(V),
|
|
|
|
e.events.trigger("keyPressRepeat", V),
|
|
|
|
e.events.trigger("keyPress", V));
|
2024-06-01 06:31:08 +00:00
|
|
|
});
|
2024-06-17 22:57:39 +00:00
|
|
|
}),
|
|
|
|
(te.keyup = (p) => {
|
|
|
|
e.events.onOnce("input", () => {
|
|
|
|
let V = Et[p.key] || p.key.toLowerCase();
|
|
|
|
e.keyState.release(V), e.events.trigger("keyRelease", V);
|
2024-06-01 06:31:08 +00:00
|
|
|
});
|
|
|
|
}),
|
2024-06-17 22:57:39 +00:00
|
|
|
(te.touchstart = (p) => {
|
|
|
|
p.preventDefault(),
|
2024-06-01 06:31:08 +00:00
|
|
|
e.events.onOnce("input", () => {
|
2024-06-17 22:57:39 +00:00
|
|
|
let V = [...p.changedTouches],
|
|
|
|
j = e.canvas.getBoundingClientRect();
|
2024-06-02 05:39:23 +00:00
|
|
|
t.touchToMouse !== !1 &&
|
2024-06-17 22:57:39 +00:00
|
|
|
((e.mousePos = new D(V[0].clientX - j.x, V[0].clientY - j.y)),
|
|
|
|
e.mouseState.press("left"),
|
|
|
|
e.events.trigger("mousePress", "left")),
|
|
|
|
V.forEach((J) => {
|
2024-06-01 06:31:08 +00:00
|
|
|
e.events.trigger(
|
2024-06-17 22:57:39 +00:00
|
|
|
"touchStart",
|
|
|
|
new D(J.clientX - j.x, J.clientY - j.y),
|
|
|
|
J
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2024-06-17 22:57:39 +00:00
|
|
|
}),
|
|
|
|
(te.touchmove = (p) => {
|
|
|
|
p.preventDefault(),
|
2024-06-01 06:31:08 +00:00
|
|
|
e.events.onOnce("input", () => {
|
2024-06-17 22:57:39 +00:00
|
|
|
let V = [...p.changedTouches],
|
|
|
|
j = e.canvas.getBoundingClientRect();
|
|
|
|
if (t.touchToMouse !== !1) {
|
|
|
|
let J = e.mousePos;
|
|
|
|
(e.mousePos = new D(V[0].clientX - j.x, V[0].clientY - j.y)),
|
|
|
|
(e.mouseDeltaPos = e.mousePos.sub(J)),
|
|
|
|
e.events.trigger("mouseMove");
|
|
|
|
}
|
|
|
|
V.forEach((J) => {
|
|
|
|
e.events.trigger(
|
|
|
|
"touchMove",
|
|
|
|
new D(J.clientX - j.x, J.clientY - j.y),
|
|
|
|
J
|
|
|
|
);
|
|
|
|
});
|
2024-06-01 06:31:08 +00:00
|
|
|
});
|
2024-06-17 22:57:39 +00:00
|
|
|
}),
|
|
|
|
(te.touchend = (p) => {
|
|
|
|
e.events.onOnce("input", () => {
|
|
|
|
let V = [...p.changedTouches],
|
|
|
|
j = e.canvas.getBoundingClientRect();
|
|
|
|
t.touchToMouse !== !1 &&
|
|
|
|
((e.mousePos = new D(V[0].clientX - j.x, V[0].clientY - j.y)),
|
|
|
|
(e.mouseDeltaPos = new D(0, 0)),
|
|
|
|
e.mouseState.release("left"),
|
|
|
|
e.events.trigger("mouseRelease", "left")),
|
|
|
|
V.forEach((J) => {
|
|
|
|
e.events.trigger(
|
|
|
|
"touchEnd",
|
|
|
|
new D(J.clientX - j.x, J.clientY - j.y),
|
|
|
|
J
|
|
|
|
);
|
2024-06-01 06:31:08 +00:00
|
|
|
});
|
2024-06-17 22:57:39 +00:00
|
|
|
});
|
|
|
|
}),
|
|
|
|
(te.touchcancel = (p) => {
|
|
|
|
e.events.onOnce("input", () => {
|
|
|
|
let V = [...p.changedTouches],
|
|
|
|
j = e.canvas.getBoundingClientRect();
|
|
|
|
t.touchToMouse !== !1 &&
|
|
|
|
((e.mousePos = new D(V[0].clientX - j.x, V[0].clientY - j.y)),
|
|
|
|
e.mouseState.release("left"),
|
|
|
|
e.events.trigger("mouseRelease", "left")),
|
|
|
|
V.forEach((J) => {
|
|
|
|
e.events.trigger(
|
|
|
|
"touchEnd",
|
|
|
|
new D(J.clientX - j.x, J.clientY - j.y),
|
|
|
|
J
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
(te.wheel = (p) => {
|
|
|
|
p.preventDefault(),
|
2024-06-01 06:31:08 +00:00
|
|
|
e.events.onOnce("input", () => {
|
2024-06-17 22:57:39 +00:00
|
|
|
e.events.trigger("scroll", new D(p.deltaX, p.deltaY));
|
2024-06-01 06:31:08 +00:00
|
|
|
});
|
2024-06-17 22:57:39 +00:00
|
|
|
}),
|
|
|
|
(te.contextmenu = (p) => p.preventDefault()),
|
|
|
|
(We.visibilitychange = () => {
|
|
|
|
document.visibilityState === "visible"
|
|
|
|
? ((e.skipTime = !0), (e.isHidden = !1), e.events.trigger("show"))
|
|
|
|
: ((e.isHidden = !0), e.events.trigger("hide"));
|
|
|
|
}),
|
|
|
|
(je.gamepadconnected = (p) => {
|
|
|
|
let V = Tt(p.gamepad);
|
|
|
|
e.events.onOnce("input", () => {
|
|
|
|
e.events.trigger("gamepadConnect", V);
|
2024-06-01 06:31:08 +00:00
|
|
|
});
|
2024-06-17 22:57:39 +00:00
|
|
|
}),
|
|
|
|
(je.gamepaddisconnected = (p) => {
|
|
|
|
let V = Se().filter((j) => j.index === p.gamepad.index)[0];
|
|
|
|
Bn(p.gamepad),
|
|
|
|
e.events.onOnce("input", () => {
|
|
|
|
e.events.trigger("gamepadDisconnect", V);
|
|
|
|
});
|
2024-06-01 06:31:08 +00:00
|
|
|
});
|
2024-06-17 22:57:39 +00:00
|
|
|
for (let p in te) e.canvas.addEventListener(p, te[p]);
|
|
|
|
for (let p in We) document.addEventListener(p, We[p]);
|
|
|
|
for (let p in je) window.addEventListener(p, je[p]);
|
|
|
|
let tn = new ResizeObserver((p) => {
|
|
|
|
for (let V of p)
|
|
|
|
if (V.target === e.canvas) {
|
|
|
|
if (
|
|
|
|
e.lastWidth === e.canvas.offsetWidth &&
|
|
|
|
e.lastHeight === e.canvas.offsetHeight
|
|
|
|
)
|
|
|
|
return;
|
|
|
|
(e.lastWidth = e.canvas.offsetWidth),
|
|
|
|
(e.lastHeight = e.canvas.offsetHeight),
|
|
|
|
e.events.onOnce("input", () => {
|
|
|
|
e.events.trigger("resize");
|
|
|
|
});
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
});
|
|
|
|
return (
|
|
|
|
tn.observe(e.canvas),
|
|
|
|
{
|
|
|
|
dt: n,
|
|
|
|
time: a,
|
|
|
|
run: L,
|
|
|
|
canvas: e.canvas,
|
|
|
|
fps: u,
|
|
|
|
numFrames: l,
|
|
|
|
quit: X,
|
|
|
|
isHidden: o,
|
|
|
|
setFullscreen: _,
|
|
|
|
isFullscreen: $,
|
|
|
|
setCursor: v,
|
|
|
|
screenshot: f,
|
|
|
|
getGamepads: Se,
|
|
|
|
getCursor: m,
|
|
|
|
setCursorLocked: P,
|
|
|
|
isCursorLocked: b,
|
|
|
|
isTouchscreen: Q,
|
|
|
|
mousePos: O,
|
|
|
|
mouseDeltaPos: oe,
|
|
|
|
isKeyDown: ve,
|
|
|
|
isKeyPressed: pe,
|
|
|
|
isKeyPressedRepeat: Ce,
|
|
|
|
isKeyReleased: Ie,
|
|
|
|
isMouseDown: ie,
|
|
|
|
isMousePressed: H,
|
|
|
|
isMouseReleased: se,
|
|
|
|
isMouseMoved: ae,
|
|
|
|
isGamepadButtonPressed: Le,
|
|
|
|
isGamepadButtonDown: Te,
|
|
|
|
isGamepadButtonReleased: Ne,
|
|
|
|
getGamepadStick: Dn,
|
|
|
|
charInputted: it,
|
|
|
|
onResize: _e,
|
|
|
|
onKeyDown: He,
|
|
|
|
onKeyPress: dt,
|
|
|
|
onKeyPressRepeat: Ee,
|
|
|
|
onKeyRelease: Re,
|
|
|
|
onMouseDown: ze,
|
|
|
|
onMousePress: ot,
|
|
|
|
onMouseRelease: st,
|
|
|
|
onMouseMove: Ct,
|
|
|
|
onCharInput: Xt,
|
|
|
|
onTouchStart: $t,
|
|
|
|
onTouchMove: An,
|
|
|
|
onTouchEnd: Qt,
|
|
|
|
onScroll: Vn,
|
|
|
|
onHide: Rn,
|
|
|
|
onShow: Jt,
|
|
|
|
onGamepadButtonDown: Un,
|
|
|
|
onGamepadButtonPress: Pn,
|
|
|
|
onGamepadButtonRelease: Zt,
|
|
|
|
onGamepadStick: en,
|
|
|
|
onGamepadConnect: Mn,
|
|
|
|
onGamepadDisconnect: Dt,
|
|
|
|
events: e.events,
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
);
|
|
|
|
}, "default");
|
|
|
|
var qe = class t {
|
|
|
|
static {
|
|
|
|
s(this, "Texture");
|
|
|
|
}
|
|
|
|
ctx;
|
|
|
|
src = null;
|
|
|
|
glTex;
|
|
|
|
width;
|
|
|
|
height;
|
|
|
|
constructor(e, n, o, a = {}) {
|
|
|
|
this.ctx = e;
|
|
|
|
let u = e.gl;
|
|
|
|
(this.glTex = e.gl.createTexture()),
|
2024-06-01 06:31:08 +00:00
|
|
|
e.onDestroy(() => this.free()),
|
2024-06-17 22:57:39 +00:00
|
|
|
(this.width = n),
|
|
|
|
(this.height = o);
|
|
|
|
let l =
|
|
|
|
{ linear: u.LINEAR, nearest: u.NEAREST }[
|
|
|
|
a.filter ?? e.opts.texFilter
|
|
|
|
] ?? u.NEAREST,
|
|
|
|
f =
|
|
|
|
{ repeat: u.REPEAT, clampToEadge: u.CLAMP_TO_EDGE }[a.wrap] ??
|
|
|
|
u.CLAMP_TO_EDGE;
|
|
|
|
this.bind(),
|
|
|
|
n &&
|
|
|
|
o &&
|
|
|
|
u.texImage2D(
|
|
|
|
u.TEXTURE_2D,
|
2024-06-01 06:31:08 +00:00
|
|
|
0,
|
2024-06-17 22:57:39 +00:00
|
|
|
u.RGBA,
|
|
|
|
n,
|
|
|
|
o,
|
2024-06-01 06:31:08 +00:00
|
|
|
0,
|
2024-06-17 22:57:39 +00:00
|
|
|
u.RGBA,
|
|
|
|
u.UNSIGNED_BYTE,
|
|
|
|
null
|
2024-06-01 06:31:08 +00:00
|
|
|
),
|
2024-06-17 22:57:39 +00:00
|
|
|
u.texParameteri(u.TEXTURE_2D, u.TEXTURE_MIN_FILTER, l),
|
|
|
|
u.texParameteri(u.TEXTURE_2D, u.TEXTURE_MAG_FILTER, l),
|
|
|
|
u.texParameteri(u.TEXTURE_2D, u.TEXTURE_WRAP_S, f),
|
|
|
|
u.texParameteri(u.TEXTURE_2D, u.TEXTURE_WRAP_T, f),
|
|
|
|
this.unbind();
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
static fromImage(e, n, o = {}) {
|
|
|
|
let a = new t(e, n.width, n.height, o);
|
|
|
|
return a.update(n), (a.src = n), a;
|
|
|
|
}
|
|
|
|
update(e, n = 0, o = 0) {
|
|
|
|
let a = this.ctx.gl;
|
|
|
|
this.bind(),
|
|
|
|
a.texSubImage2D(a.TEXTURE_2D, 0, n, o, a.RGBA, a.UNSIGNED_BYTE, e),
|
|
|
|
this.unbind();
|
|
|
|
}
|
|
|
|
bind() {
|
|
|
|
this.ctx.pushTexture2D(this.glTex);
|
|
|
|
}
|
|
|
|
unbind() {
|
|
|
|
this.ctx.popTexture2D();
|
|
|
|
}
|
|
|
|
free() {
|
|
|
|
this.ctx.gl.deleteTexture(this.glTex);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
yt = class {
|
|
|
|
static {
|
|
|
|
s(this, "FrameBuffer");
|
|
|
|
}
|
|
|
|
ctx;
|
|
|
|
tex;
|
|
|
|
glFramebuffer;
|
|
|
|
glRenderbuffer;
|
|
|
|
constructor(e, n, o, a = {}) {
|
|
|
|
this.ctx = e;
|
|
|
|
let u = e.gl;
|
|
|
|
e.onDestroy(() => this.free()),
|
|
|
|
(this.tex = new qe(e, n, o, a)),
|
|
|
|
(this.glFramebuffer = u.createFramebuffer()),
|
|
|
|
(this.glRenderbuffer = u.createRenderbuffer()),
|
|
|
|
this.bind(),
|
|
|
|
u.renderbufferStorage(u.RENDERBUFFER, u.DEPTH_STENCIL, n, o),
|
|
|
|
u.framebufferTexture2D(
|
|
|
|
u.FRAMEBUFFER,
|
|
|
|
u.COLOR_ATTACHMENT0,
|
|
|
|
u.TEXTURE_2D,
|
|
|
|
this.tex.glTex,
|
|
|
|
0
|
2024-06-01 06:31:08 +00:00
|
|
|
),
|
2024-06-17 22:57:39 +00:00
|
|
|
u.framebufferRenderbuffer(
|
|
|
|
u.FRAMEBUFFER,
|
|
|
|
u.DEPTH_STENCIL_ATTACHMENT,
|
|
|
|
u.RENDERBUFFER,
|
|
|
|
this.glRenderbuffer
|
|
|
|
),
|
|
|
|
this.unbind();
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
get width() {
|
|
|
|
return this.tex.width;
|
|
|
|
}
|
|
|
|
get height() {
|
|
|
|
return this.tex.height;
|
|
|
|
}
|
|
|
|
toImageData() {
|
|
|
|
let e = this.ctx.gl,
|
|
|
|
n = new Uint8ClampedArray(this.width * this.height * 4);
|
|
|
|
this.bind(),
|
|
|
|
e.readPixels(0, 0, this.width, this.height, e.RGBA, e.UNSIGNED_BYTE, n),
|
|
|
|
this.unbind();
|
|
|
|
let o = this.width * 4,
|
|
|
|
a = new Uint8Array(o);
|
|
|
|
for (let u = 0; u < ((this.height / 2) | 0); u++) {
|
|
|
|
let l = u * o,
|
|
|
|
f = (this.height - u - 1) * o;
|
|
|
|
a.set(n.subarray(l, l + o)), n.copyWithin(l, f, f + o), n.set(a, f);
|
|
|
|
}
|
|
|
|
return new ImageData(n, this.width, this.height);
|
|
|
|
}
|
|
|
|
toDataURL() {
|
|
|
|
let e = document.createElement("canvas"),
|
|
|
|
n = e.getContext("2d");
|
|
|
|
return (
|
|
|
|
(e.width = this.width),
|
|
|
|
(e.height = this.height),
|
|
|
|
n.putImageData(this.toImageData(), 0, 0),
|
|
|
|
e.toDataURL()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
clear() {
|
|
|
|
let e = this.ctx.gl;
|
|
|
|
e.clear(e.COLOR_BUFFER_BIT);
|
|
|
|
}
|
|
|
|
draw(e) {
|
|
|
|
this.bind(), e(), this.unbind();
|
|
|
|
}
|
|
|
|
bind() {
|
|
|
|
this.ctx.pushFramebuffer(this.glFramebuffer),
|
|
|
|
this.ctx.pushRenderbuffer(this.glRenderbuffer),
|
|
|
|
this.ctx.pushViewport({ x: 0, y: 0, w: this.width, h: this.height });
|
|
|
|
}
|
|
|
|
unbind() {
|
|
|
|
this.ctx.popFramebuffer(),
|
|
|
|
this.ctx.popRenderbuffer(),
|
|
|
|
this.ctx.popViewport();
|
|
|
|
}
|
|
|
|
free() {
|
|
|
|
let e = this.ctx.gl;
|
|
|
|
e.deleteFramebuffer(this.glFramebuffer),
|
|
|
|
e.deleteRenderbuffer(this.glRenderbuffer),
|
|
|
|
this.tex.free();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
hn = class {
|
|
|
|
static {
|
|
|
|
s(this, "Shader");
|
|
|
|
}
|
|
|
|
ctx;
|
|
|
|
glProgram;
|
|
|
|
constructor(e, n, o, a) {
|
|
|
|
(this.ctx = e), e.onDestroy(() => this.free());
|
|
|
|
let u = e.gl,
|
|
|
|
l = u.createShader(u.VERTEX_SHADER),
|
|
|
|
f = u.createShader(u.FRAGMENT_SHADER);
|
|
|
|
u.shaderSource(l, n),
|
|
|
|
u.shaderSource(f, o),
|
|
|
|
u.compileShader(l),
|
|
|
|
u.compileShader(f);
|
|
|
|
let v = u.createProgram();
|
|
|
|
if (
|
|
|
|
((this.glProgram = v),
|
|
|
|
u.attachShader(v, l),
|
|
|
|
u.attachShader(v, f),
|
|
|
|
a.forEach((m, P) => u.bindAttribLocation(v, P, m)),
|
|
|
|
u.linkProgram(v),
|
|
|
|
!u.getProgramParameter(v, u.LINK_STATUS))
|
|
|
|
) {
|
|
|
|
let m = u.getShaderInfoLog(l);
|
|
|
|
if (m) throw new Error("VERTEX SHADER " + m);
|
|
|
|
let P = u.getShaderInfoLog(f);
|
|
|
|
if (P) throw new Error("FRAGMENT SHADER " + P);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
u.deleteShader(l), u.deleteShader(f);
|
|
|
|
}
|
|
|
|
bind() {
|
|
|
|
this.ctx.pushProgram(this.glProgram);
|
|
|
|
}
|
|
|
|
unbind() {
|
|
|
|
this.ctx.popProgram();
|
|
|
|
}
|
|
|
|
send(e) {
|
|
|
|
let n = this.ctx.gl;
|
|
|
|
for (let o in e) {
|
|
|
|
let a = e[o],
|
|
|
|
u = n.getUniformLocation(this.glProgram, o);
|
|
|
|
if (typeof a == "number") n.uniform1f(u, a);
|
|
|
|
else if (a instanceof De)
|
|
|
|
n.uniformMatrix4fv(u, !1, new Float32Array(a.m));
|
|
|
|
else if (a instanceof re) n.uniform3f(u, a.r, a.g, a.b);
|
|
|
|
else if (a instanceof D) n.uniform2f(u, a.x, a.y);
|
|
|
|
else if (Array.isArray(a)) {
|
|
|
|
let l = a[0];
|
|
|
|
typeof l == "number"
|
|
|
|
? n.uniform1fv(u, a)
|
|
|
|
: l instanceof D
|
|
|
|
? n.uniform2fv(u, a.map((f) => [f.x, f.y]).flat())
|
|
|
|
: l instanceof re &&
|
|
|
|
n.uniform3fv(u, a.map((f) => [f.r, f.g, f.b]).flat());
|
|
|
|
} else throw new Error("Unsupported uniform data type");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
}
|
|
|
|
free() {
|
|
|
|
this.ctx.gl.deleteProgram(this.glProgram);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
pn = class {
|
|
|
|
static {
|
|
|
|
s(this, "BatchRenderer");
|
|
|
|
}
|
|
|
|
ctx;
|
|
|
|
glVBuf;
|
|
|
|
glIBuf;
|
|
|
|
vqueue = [];
|
|
|
|
iqueue = [];
|
|
|
|
stride;
|
|
|
|
maxVertices;
|
|
|
|
maxIndices;
|
|
|
|
vertexFormat;
|
|
|
|
numDraws = 0;
|
|
|
|
curPrimitive = null;
|
|
|
|
curTex = null;
|
|
|
|
curShader = null;
|
|
|
|
curUniform = {};
|
|
|
|
constructor(e, n, o, a) {
|
|
|
|
let u = e.gl;
|
|
|
|
(this.vertexFormat = n),
|
|
|
|
(this.ctx = e),
|
|
|
|
(this.stride = n.reduce((l, f) => l + f.size, 0)),
|
|
|
|
(this.maxVertices = o),
|
|
|
|
(this.maxIndices = a),
|
|
|
|
(this.glVBuf = u.createBuffer()),
|
|
|
|
e.pushArrayBuffer(this.glVBuf),
|
|
|
|
u.bufferData(u.ARRAY_BUFFER, o * 4, u.DYNAMIC_DRAW),
|
|
|
|
e.popArrayBuffer(),
|
|
|
|
(this.glIBuf = u.createBuffer()),
|
|
|
|
e.pushElementArrayBuffer(this.glIBuf),
|
|
|
|
u.bufferData(u.ELEMENT_ARRAY_BUFFER, a * 4, u.DYNAMIC_DRAW),
|
|
|
|
e.popElementArrayBuffer();
|
|
|
|
}
|
|
|
|
push(e, n, o, a, u = null, l = {}) {
|
|
|
|
(e !== this.curPrimitive ||
|
|
|
|
u !== this.curTex ||
|
|
|
|
a !== this.curShader ||
|
|
|
|
!mn(this.curUniform, l) ||
|
|
|
|
this.vqueue.length + n.length * this.stride > this.maxVertices ||
|
|
|
|
this.iqueue.length + o.length > this.maxIndices) &&
|
|
|
|
this.flush();
|
|
|
|
let f = this.vqueue.length / this.stride;
|
|
|
|
for (let v of n) this.vqueue.push(v);
|
|
|
|
for (let v of o) this.iqueue.push(v + f);
|
|
|
|
(this.curPrimitive = e),
|
|
|
|
(this.curShader = a),
|
|
|
|
(this.curTex = u),
|
|
|
|
(this.curUniform = l);
|
|
|
|
}
|
|
|
|
flush() {
|
|
|
|
if (
|
|
|
|
!this.curPrimitive ||
|
|
|
|
!this.curShader ||
|
|
|
|
this.vqueue.length === 0 ||
|
|
|
|
this.iqueue.length === 0
|
|
|
|
)
|
|
|
|
return;
|
|
|
|
let e = this.ctx.gl;
|
|
|
|
this.ctx.pushArrayBuffer(this.glVBuf),
|
|
|
|
e.bufferSubData(e.ARRAY_BUFFER, 0, new Float32Array(this.vqueue)),
|
|
|
|
this.ctx.pushElementArrayBuffer(this.glIBuf),
|
|
|
|
e.bufferSubData(
|
|
|
|
e.ELEMENT_ARRAY_BUFFER,
|
|
|
|
0,
|
|
|
|
new Uint16Array(this.iqueue)
|
|
|
|
),
|
|
|
|
this.ctx.setVertexFormat(this.vertexFormat),
|
|
|
|
this.curShader.bind(),
|
|
|
|
this.curShader.send(this.curUniform),
|
|
|
|
this.curTex?.bind(),
|
|
|
|
e.drawElements(
|
|
|
|
this.curPrimitive,
|
|
|
|
this.iqueue.length,
|
|
|
|
e.UNSIGNED_SHORT,
|
|
|
|
0
|
|
|
|
),
|
|
|
|
this.curTex?.unbind(),
|
|
|
|
this.curShader.unbind(),
|
|
|
|
this.ctx.popArrayBuffer(),
|
|
|
|
this.ctx.popElementArrayBuffer(),
|
|
|
|
(this.vqueue = []),
|
|
|
|
(this.iqueue = []),
|
|
|
|
this.numDraws++;
|
|
|
|
}
|
|
|
|
free() {
|
|
|
|
let e = this.ctx.gl;
|
|
|
|
e.deleteBuffer(this.glVBuf), e.deleteBuffer(this.glIBuf);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
function xt(t) {
|
|
|
|
let e = [],
|
|
|
|
n = s((u) => {
|
|
|
|
e.push(u), t(u);
|
|
|
|
}, "push"),
|
|
|
|
o = s(() => {
|
|
|
|
e.pop(), t(a() ?? null);
|
|
|
|
}, "pop"),
|
|
|
|
a = s(() => e[e.length - 1], "cur");
|
|
|
|
return [n, o, a];
|
|
|
|
}
|
|
|
|
s(xt, "genStack");
|
|
|
|
function fr(t, e = {}) {
|
|
|
|
let n = [];
|
|
|
|
function o(H) {
|
|
|
|
n.push(H);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
s(o, "onDestroy");
|
|
|
|
function a() {
|
|
|
|
n.forEach((H) => H()), t.getExtension("WEBGL_lose_context").loseContext();
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
s(a, "destroy");
|
|
|
|
let u = null;
|
|
|
|
function l(H) {
|
|
|
|
if (mn(H, u)) return;
|
|
|
|
u = H;
|
|
|
|
let ie = H.reduce((se, ae) => se + ae.size, 0);
|
|
|
|
H.reduce(
|
|
|
|
(se, ae, pe) => (
|
|
|
|
t.vertexAttribPointer(pe, ae.size, t.FLOAT, !1, ie * 4, se),
|
|
|
|
t.enableVertexAttribArray(pe),
|
|
|
|
se + ae.size * 4
|
|
|
|
),
|
|
|
|
0
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
s(l, "setVertexFormat");
|
|
|
|
let [f, v] = xt((H) => t.bindTexture(t.TEXTURE_2D, H)),
|
|
|
|
[m, P] = xt((H) => t.bindBuffer(t.ARRAY_BUFFER, H)),
|
|
|
|
[b, M] = xt((H) => t.bindBuffer(t.ELEMENT_ARRAY_BUFFER, H)),
|
|
|
|
[w, _] = xt((H) => t.bindFramebuffer(t.FRAMEBUFFER, H)),
|
|
|
|
[$, X] = xt((H) => t.bindRenderbuffer(t.RENDERBUFFER, H)),
|
|
|
|
[L, Q] = xt(({ x: H, y: ie, w: se, h: ae }) => {
|
|
|
|
t.viewport(H, ie, se, ae);
|
|
|
|
}),
|
|
|
|
[O, oe] = xt((H) => t.useProgram(H));
|
|
|
|
return (
|
|
|
|
L({ x: 0, y: 0, w: t.drawingBufferWidth, h: t.drawingBufferHeight }),
|
|
|
|
{
|
|
|
|
gl: t,
|
|
|
|
opts: e,
|
|
|
|
onDestroy: o,
|
|
|
|
destroy: a,
|
|
|
|
pushTexture2D: f,
|
|
|
|
popTexture2D: v,
|
|
|
|
pushArrayBuffer: m,
|
|
|
|
popArrayBuffer: P,
|
|
|
|
pushElementArrayBuffer: b,
|
|
|
|
popElementArrayBuffer: M,
|
|
|
|
pushFramebuffer: w,
|
|
|
|
popFramebuffer: _,
|
|
|
|
pushRenderbuffer: $,
|
|
|
|
popRenderbuffer: X,
|
|
|
|
pushViewport: L,
|
|
|
|
popViewport: Q,
|
|
|
|
pushProgram: O,
|
|
|
|
popProgram: oe,
|
|
|
|
setVertexFormat: l,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(fr, "initGfx");
|
|
|
|
var Ve = class t {
|
|
|
|
static {
|
|
|
|
s(this, "Asset");
|
|
|
|
}
|
|
|
|
loaded = !1;
|
|
|
|
data = null;
|
|
|
|
error = null;
|
|
|
|
onLoadEvents = new we();
|
|
|
|
onErrorEvents = new we();
|
|
|
|
onFinishEvents = new we();
|
|
|
|
constructor(e) {
|
|
|
|
e.then((n) => {
|
|
|
|
(this.loaded = !0), (this.data = n), this.onLoadEvents.trigger(n);
|
|
|
|
})
|
|
|
|
.catch((n) => {
|
|
|
|
if (((this.error = n), this.onErrorEvents.numListeners() > 0))
|
|
|
|
this.onErrorEvents.trigger(n);
|
|
|
|
else throw n;
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.onFinishEvents.trigger(), (this.loaded = !0);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
static loaded(e) {
|
|
|
|
let n = new t(Promise.resolve(e));
|
|
|
|
return (n.data = e), (n.loaded = !0), n;
|
|
|
|
}
|
|
|
|
onLoad(e) {
|
|
|
|
return (
|
|
|
|
this.loaded && this.data ? e(this.data) : this.onLoadEvents.add(e), this
|
|
|
|
);
|
|
|
|
}
|
|
|
|
onError(e) {
|
|
|
|
return (
|
|
|
|
this.loaded && this.error ? e(this.error) : this.onErrorEvents.add(e),
|
|
|
|
this
|
|
|
|
);
|
|
|
|
}
|
|
|
|
onFinish(e) {
|
|
|
|
return this.loaded ? e() : this.onFinishEvents.add(e), this;
|
|
|
|
}
|
|
|
|
then(e) {
|
|
|
|
return this.onLoad(e);
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
return this.onError(e);
|
|
|
|
}
|
|
|
|
finally(e) {
|
|
|
|
return this.onFinish(e);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
rt = class {
|
|
|
|
static {
|
|
|
|
s(this, "AssetBucket");
|
|
|
|
}
|
|
|
|
assets = new Map();
|
|
|
|
lastUID = 0;
|
|
|
|
add(e, n) {
|
|
|
|
let o = e ?? this.lastUID++ + "",
|
|
|
|
a = new Ve(n);
|
|
|
|
return this.assets.set(o, a), a;
|
|
|
|
}
|
|
|
|
addLoaded(e, n) {
|
|
|
|
let o = e ?? this.lastUID++ + "",
|
|
|
|
a = Ve.loaded(n);
|
|
|
|
return this.assets.set(o, a), a;
|
|
|
|
}
|
|
|
|
get(e) {
|
|
|
|
return this.assets.get(e);
|
|
|
|
}
|
|
|
|
progress() {
|
|
|
|
if (this.assets.size === 0) return 1;
|
|
|
|
let e = 0;
|
|
|
|
return (
|
|
|
|
this.assets.forEach((n) => {
|
|
|
|
n.loaded && e++;
|
|
|
|
}),
|
|
|
|
e / this.assets.size
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
function gr(t) {
|
|
|
|
return fetch(t).then((e) => {
|
|
|
|
if (!e.ok) throw new Error(`Failed to fetch "${t}"`);
|
|
|
|
return e;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
s(gr, "fetchURL");
|
|
|
|
function Ht(t) {
|
|
|
|
return gr(t).then((e) => e.json());
|
|
|
|
}
|
|
|
|
s(Ht, "fetchJSON");
|
|
|
|
function So(t) {
|
|
|
|
return gr(t).then((e) => e.text());
|
|
|
|
}
|
|
|
|
s(So, "fetchText");
|
|
|
|
function Oo(t) {
|
|
|
|
return gr(t).then((e) => e.arrayBuffer());
|
|
|
|
}
|
|
|
|
s(Oo, "fetchArrayBuffer");
|
|
|
|
function Kt(t) {
|
|
|
|
let e = new Image();
|
|
|
|
return (
|
|
|
|
(e.crossOrigin = "anonymous"),
|
|
|
|
(e.src = t),
|
|
|
|
new Promise((n, o) => {
|
|
|
|
(e.onload = () => n(e)),
|
|
|
|
(e.onerror = () => o(new Error(`Failed to load image from "${t}"`)));
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(Kt, "loadImg");
|
|
|
|
var br =
|
|
|
|
" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~",
|
|
|
|
Pt = "topleft";
|
|
|
|
var Ao = "monospace",
|
|
|
|
qt = "monospace";
|
|
|
|
var fn = "linear";
|
|
|
|
var gn = [
|
|
|
|
{ name: "a_pos", size: 2 },
|
|
|
|
{ name: "a_uv", size: 2 },
|
|
|
|
{ name: "a_color", size: 4 },
|
|
|
|
],
|
|
|
|
aa = gn.reduce((t, e) => t + e.size, 0),
|
|
|
|
Vo = 2048,
|
|
|
|
Ro = Vo * 4 * aa,
|
|
|
|
Uo = Vo * 6,
|
|
|
|
Po = `
|
2024-06-01 06:31:08 +00:00
|
|
|
attribute vec2 a_pos;
|
|
|
|
attribute vec2 a_uv;
|
|
|
|
attribute vec4 a_color;
|
|
|
|
|
|
|
|
varying vec2 v_pos;
|
|
|
|
varying vec2 v_uv;
|
|
|
|
varying vec4 v_color;
|
|
|
|
|
|
|
|
vec4 def_vert() {
|
|
|
|
return vec4(a_pos, 0.0, 1.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
{{user}}
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
vec4 pos = vert(a_pos, a_uv, a_color);
|
|
|
|
v_pos = a_pos;
|
|
|
|
v_uv = a_uv;
|
|
|
|
v_color = a_color;
|
|
|
|
gl_Position = pos;
|
|
|
|
}
|
|
|
|
`,
|
2024-06-17 22:57:39 +00:00
|
|
|
Mo = `
|
2024-06-01 06:31:08 +00:00
|
|
|
precision mediump float;
|
|
|
|
|
|
|
|
varying vec2 v_pos;
|
|
|
|
varying vec2 v_uv;
|
|
|
|
varying vec4 v_color;
|
|
|
|
|
|
|
|
uniform sampler2D u_tex;
|
|
|
|
|
|
|
|
vec4 def_frag() {
|
|
|
|
return v_color * texture2D(u_tex, v_uv);
|
|
|
|
}
|
|
|
|
|
|
|
|
{{user}}
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
gl_FragColor = frag(v_pos, v_uv, v_color, u_tex);
|
|
|
|
if (gl_FragColor.a == 0.0) {
|
|
|
|
discard;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
2024-06-17 22:57:39 +00:00
|
|
|
bn = `
|
2024-06-01 06:31:08 +00:00
|
|
|
vec4 vert(vec2 pos, vec2 uv, vec4 color) {
|
|
|
|
return def_vert();
|
|
|
|
}
|
|
|
|
`,
|
2024-06-17 22:57:39 +00:00
|
|
|
vn = `
|
2024-06-01 06:31:08 +00:00
|
|
|
vec4 frag(vec2 pos, vec2 uv, vec4 color, sampler2D tex) {
|
|
|
|
return def_frag();
|
|
|
|
}
|
|
|
|
`,
|
2024-06-17 22:57:39 +00:00
|
|
|
Do = new Set(["id", "require"]),
|
|
|
|
Go = new Set(["add", "update", "draw", "destroy", "inspect", "drawInspect"]),
|
|
|
|
vr = /\[(?<style>\w+)\](?<text>.*?)\[\/\k<style>\]/g,
|
|
|
|
Bo = 200,
|
|
|
|
Fo = 640,
|
|
|
|
Io = 65536;
|
|
|
|
var xn = 2.5949095,
|
|
|
|
Lo = 1.70158 + 1,
|
|
|
|
jo = (2 * Math.PI) / 3,
|
|
|
|
ko = (2 * Math.PI) / 4.5,
|
|
|
|
yn = {
|
|
|
|
linear: (t) => t,
|
|
|
|
easeInSine: (t) => 1 - Math.cos((t * Math.PI) / 2),
|
|
|
|
easeOutSine: (t) => Math.sin((t * Math.PI) / 2),
|
|
|
|
easeInOutSine: (t) => -(Math.cos(Math.PI * t) - 1) / 2,
|
|
|
|
easeInQuad: (t) => t * t,
|
|
|
|
easeOutQuad: (t) => 1 - (1 - t) * (1 - t),
|
|
|
|
easeInOutQuad: (t) =>
|
|
|
|
t < 0.5 ? 2 * t * t : 1 - Math.pow(-2 * t + 2, 2) / 2,
|
|
|
|
easeInCubic: (t) => t * t * t,
|
|
|
|
easeOutCubic: (t) => 1 - Math.pow(1 - t, 3),
|
|
|
|
easeInOutCubic: (t) =>
|
|
|
|
t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2,
|
|
|
|
easeInQuart: (t) => t * t * t * t,
|
|
|
|
easeOutQuart: (t) => 1 - Math.pow(1 - t, 4),
|
|
|
|
easeInOutQuart: (t) =>
|
|
|
|
t < 0.5 ? 8 * t * t * t * t : 1 - Math.pow(-2 * t + 2, 4) / 2,
|
|
|
|
easeInQuint: (t) => t * t * t * t * t,
|
|
|
|
easeOutQuint: (t) => 1 - Math.pow(1 - t, 5),
|
|
|
|
easeInOutQuint: (t) =>
|
|
|
|
t < 0.5 ? 16 * t * t * t * t * t : 1 - Math.pow(-2 * t + 2, 5) / 2,
|
|
|
|
easeInExpo: (t) => (t === 0 ? 0 : Math.pow(2, 10 * t - 10)),
|
|
|
|
easeOutExpo: (t) => (t === 1 ? 1 : 1 - Math.pow(2, -10 * t)),
|
|
|
|
easeInOutExpo: (t) =>
|
|
|
|
t === 0
|
|
|
|
? 0
|
|
|
|
: t === 1
|
|
|
|
? 1
|
|
|
|
: t < 0.5
|
|
|
|
? Math.pow(2, 20 * t - 10) / 2
|
|
|
|
: (2 - Math.pow(2, -20 * t + 10)) / 2,
|
|
|
|
easeInCirc: (t) => 1 - Math.sqrt(1 - Math.pow(t, 2)),
|
|
|
|
easeOutCirc: (t) => Math.sqrt(1 - Math.pow(t - 1, 2)),
|
|
|
|
easeInOutCirc: (t) =>
|
|
|
|
t < 0.5
|
|
|
|
? (1 - Math.sqrt(1 - Math.pow(2 * t, 2))) / 2
|
|
|
|
: (Math.sqrt(1 - Math.pow(-2 * t + 2, 2)) + 1) / 2,
|
|
|
|
easeInBack: (t) => Lo * t * t * t - 1.70158 * t * t,
|
|
|
|
easeOutBack: (t) =>
|
|
|
|
1 + Lo * Math.pow(t - 1, 3) + 1.70158 * Math.pow(t - 1, 2),
|
|
|
|
easeInOutBack: (t) =>
|
|
|
|
t < 0.5
|
|
|
|
? (Math.pow(2 * t, 2) * ((xn + 1) * 2 * t - xn)) / 2
|
|
|
|
: (Math.pow(2 * t - 2, 2) * ((xn + 1) * (t * 2 - 2) + xn) + 2) / 2,
|
|
|
|
easeInElastic: (t) =>
|
|
|
|
t === 0
|
|
|
|
? 0
|
|
|
|
: t === 1
|
|
|
|
? 1
|
|
|
|
: -Math.pow(2, 10 * t - 10) * Math.sin((t * 10 - 10.75) * jo),
|
|
|
|
easeOutElastic: (t) =>
|
|
|
|
t === 0
|
|
|
|
? 0
|
|
|
|
: t === 1
|
|
|
|
? 1
|
|
|
|
: Math.pow(2, -10 * t) * Math.sin((t * 10 - 0.75) * jo) + 1,
|
|
|
|
easeInOutElastic: (t) =>
|
|
|
|
t === 0
|
|
|
|
? 0
|
|
|
|
: t === 1
|
|
|
|
? 1
|
|
|
|
: t < 0.5
|
|
|
|
? -(Math.pow(2, 20 * t - 10) * Math.sin((20 * t - 11.125) * ko)) / 2
|
|
|
|
: (Math.pow(2, -20 * t + 10) * Math.sin((20 * t - 11.125) * ko)) / 2 +
|
|
|
|
1,
|
|
|
|
easeInBounce: (t) => 1 - yn.easeOutBounce(1 - t),
|
|
|
|
easeOutBounce: (t) =>
|
|
|
|
t < 1 / 2.75
|
|
|
|
? 7.5625 * t * t
|
|
|
|
: t < 2 / 2.75
|
|
|
|
? 7.5625 * (t -= 1.5 / 2.75) * t + 0.75
|
|
|
|
: t < 2.5 / 2.75
|
|
|
|
? 7.5625 * (t -= 2.25 / 2.75) * t + 0.9375
|
|
|
|
: 7.5625 * (t -= 2.625 / 2.75) * t + 0.984375,
|
|
|
|
easeInOutBounce: (t) =>
|
|
|
|
t < 0.5
|
|
|
|
? (1 - yn.easeOutBounce(1 - 2 * t)) / 2
|
|
|
|
: (1 + yn.easeOutBounce(2 * t - 1)) / 2,
|
|
|
|
},
|
|
|
|
Mt = yn;
|
|
|
|
var zt = class {
|
|
|
|
static {
|
|
|
|
s(this, "TexPacker");
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
textures = [];
|
|
|
|
bigTextures = [];
|
|
|
|
canvas;
|
|
|
|
c2d;
|
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
curHeight = 0;
|
|
|
|
gfx;
|
|
|
|
constructor(e, n, o) {
|
|
|
|
(this.gfx = e),
|
|
|
|
(this.canvas = document.createElement("canvas")),
|
|
|
|
(this.canvas.width = n),
|
|
|
|
(this.canvas.height = o),
|
|
|
|
(this.textures = [qe.fromImage(e, this.canvas)]),
|
|
|
|
(this.bigTextures = []),
|
|
|
|
(this.c2d = this.canvas.getContext("2d"));
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
add(e) {
|
|
|
|
if (e.width > this.canvas.width || e.height > this.canvas.height) {
|
|
|
|
let a = qe.fromImage(this.gfx, e);
|
|
|
|
return this.bigTextures.push(a), [a, new he(0, 0, 1, 1)];
|
|
|
|
}
|
|
|
|
this.x + e.width > this.canvas.width &&
|
|
|
|
((this.x = 0), (this.y += this.curHeight), (this.curHeight = 0)),
|
|
|
|
this.y + e.height > this.canvas.height &&
|
|
|
|
(this.c2d.clearRect(0, 0, this.canvas.width, this.canvas.height),
|
|
|
|
this.textures.push(qe.fromImage(this.gfx, this.canvas)),
|
|
|
|
(this.x = 0),
|
|
|
|
(this.y = 0),
|
|
|
|
(this.curHeight = 0));
|
|
|
|
let n = this.textures[this.textures.length - 1],
|
|
|
|
o = new D(this.x, this.y);
|
2024-06-02 05:39:23 +00:00
|
|
|
return (
|
2024-06-17 22:57:39 +00:00
|
|
|
(this.x += e.width),
|
|
|
|
e.height > this.curHeight && (this.curHeight = e.height),
|
|
|
|
e instanceof ImageData
|
|
|
|
? this.c2d.putImageData(e, o.x, o.y)
|
|
|
|
: this.c2d.drawImage(e, o.x, o.y),
|
|
|
|
n.update(this.canvas),
|
|
|
|
[
|
|
|
|
n,
|
|
|
|
new he(
|
|
|
|
o.x / this.canvas.width,
|
|
|
|
o.y / this.canvas.height,
|
|
|
|
e.width / this.canvas.width,
|
|
|
|
e.height / this.canvas.height
|
|
|
|
),
|
|
|
|
]
|
2024-06-02 05:39:23 +00:00
|
|
|
);
|
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
free() {
|
|
|
|
for (let e of this.textures) e.free();
|
|
|
|
for (let e of this.bigTextures) e.free();
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
};
|
|
|
|
function ca(t) {
|
|
|
|
return {
|
|
|
|
color: t.color,
|
|
|
|
opacity: t.opacity,
|
|
|
|
anchor: t.anchor,
|
|
|
|
outline: t.outline,
|
|
|
|
shader: t.shader,
|
|
|
|
uniform: t.uniform,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(ca, "getRenderProps");
|
|
|
|
function No(t, e = {}) {
|
|
|
|
let n = ne(this);
|
|
|
|
return {
|
|
|
|
id: "circle",
|
|
|
|
radius: t,
|
|
|
|
draw() {
|
|
|
|
n.drawCircle(
|
|
|
|
Object.assign(ca(this), { radius: this.radius, fill: e.fill })
|
2024-06-02 05:39:23 +00:00
|
|
|
);
|
2024-06-17 22:57:39 +00:00
|
|
|
},
|
|
|
|
renderArea() {
|
|
|
|
return new me(
|
|
|
|
new D(this.anchor ? 0 : -this.radius),
|
|
|
|
this.radius * 2,
|
|
|
|
this.radius * 2
|
|
|
|
);
|
|
|
|
},
|
|
|
|
inspect() {
|
|
|
|
return `${Math.ceil(this.radius)}`;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(No, "circle");
|
|
|
|
function _o(t) {
|
|
|
|
return {
|
|
|
|
add() {
|
|
|
|
this.canvas = t;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(_o, "drawon");
|
|
|
|
function Ho(t = 1) {
|
|
|
|
let e = ne(this),
|
|
|
|
n,
|
|
|
|
o = 0,
|
|
|
|
a = !1;
|
|
|
|
return {
|
|
|
|
require: ["opacity"],
|
|
|
|
add() {
|
|
|
|
(n = this.opacity), (this.opacity = 0);
|
|
|
|
},
|
|
|
|
update() {
|
|
|
|
a ||
|
|
|
|
((o += e.dt()),
|
|
|
|
(this.opacity = e.map(o, 0, t, 0, n)),
|
|
|
|
o >= t && ((this.opacity = n), (a = !0)));
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(Ho, "fadeIn");
|
|
|
|
function Ko(t = "intersect") {
|
|
|
|
return { id: "mask", mask: t };
|
|
|
|
}
|
|
|
|
s(Ko, "mask");
|
|
|
|
function qo(t) {
|
|
|
|
let e = ne(this),
|
|
|
|
n = fe(e);
|
|
|
|
return {
|
|
|
|
id: "opacity",
|
|
|
|
opacity: t ?? 1,
|
|
|
|
inspect() {
|
|
|
|
return `${n.toFixed(this.opacity, 1)}`;
|
|
|
|
},
|
|
|
|
fadeIn(o = 1, a = e.easings.linear) {
|
|
|
|
return e.tween(0, this.opacity, o, (u) => (this.opacity = u), a);
|
|
|
|
},
|
|
|
|
fadeOut(o = 1, a = e.easings.linear) {
|
|
|
|
return e.tween(this.opacity, 0, o, (u) => (this.opacity = u), a);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(qo, "opacity");
|
|
|
|
function zo(t = 1, e = ce(0, 0, 0), n = 1, o = "miter", a = 10, u = "butt") {
|
|
|
|
return {
|
|
|
|
id: "outline",
|
|
|
|
outline: { width: t, color: e, opacity: n, join: o, miterLimit: a, cap: u },
|
|
|
|
inspect() {
|
|
|
|
return `${this.outline.width}, ${this.outline.color}`;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(zo, "outline");
|
|
|
|
function Wo(t, e = {}) {
|
|
|
|
let n = ne(this),
|
|
|
|
o = fe(n);
|
|
|
|
if (t.length < 3)
|
|
|
|
throw new Error(
|
|
|
|
`Polygon's need more than two points, ${t.length} points provided`
|
|
|
|
);
|
|
|
|
return {
|
|
|
|
id: "polygon",
|
|
|
|
pts: t,
|
|
|
|
colors: e.colors,
|
|
|
|
uv: e.uv,
|
|
|
|
tex: e.tex,
|
|
|
|
radius: e.radius,
|
|
|
|
draw() {
|
|
|
|
n.drawPolygon(
|
|
|
|
Object.assign(o.getRenderProps(this), {
|
|
|
|
pts: this.pts,
|
|
|
|
colors: this.colors,
|
|
|
|
uv: this.uv,
|
|
|
|
tex: this.tex,
|
|
|
|
radius: this.radius,
|
|
|
|
fill: e.fill,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
},
|
|
|
|
renderArea() {
|
|
|
|
return new Ae(this.pts);
|
|
|
|
},
|
|
|
|
inspect() {
|
|
|
|
return this.pts.map((a) => `[${a.x},${a.y}]`).join(",");
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(Wo, "polygon");
|
|
|
|
function Yo(t, e, n) {
|
|
|
|
let o = ne(this),
|
|
|
|
a;
|
|
|
|
return (
|
|
|
|
o.get("area").forEach((l) => {
|
|
|
|
if (n && n.some((m) => l.is(m))) return;
|
|
|
|
let v = l.worldArea().raycast(t, e);
|
|
|
|
v &&
|
|
|
|
(a
|
|
|
|
? v.fraction < a.fraction && ((a = v), (a.object = l))
|
|
|
|
: ((a = v), (a.object = l)));
|
|
|
|
}),
|
|
|
|
a
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(Yo, "raycast");
|
|
|
|
function Xo(t, e, n = {}) {
|
|
|
|
let o = ne(this),
|
|
|
|
a = fe(o);
|
|
|
|
return {
|
|
|
|
id: "rect",
|
|
|
|
width: t,
|
|
|
|
height: e,
|
|
|
|
radius: n.radius || 0,
|
|
|
|
draw() {
|
|
|
|
o.drawRect(
|
|
|
|
Object.assign(a.getRenderProps(this), {
|
|
|
|
width: this.width,
|
|
|
|
height: this.height,
|
|
|
|
radius: this.radius,
|
|
|
|
fill: n.fill,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
},
|
|
|
|
renderArea() {
|
|
|
|
return new me(T(0), this.width, this.height);
|
|
|
|
},
|
|
|
|
inspect() {
|
|
|
|
return `${Math.ceil(this.width)}, ${Math.ceil(this.height)}`;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(Xo, "rect");
|
|
|
|
function $o(t, e) {
|
|
|
|
return {
|
|
|
|
id: "shader",
|
|
|
|
shader: t,
|
|
|
|
...(typeof e == "function"
|
|
|
|
? {
|
|
|
|
uniform: e(),
|
|
|
|
update() {
|
|
|
|
this.uniform = e();
|
|
|
|
},
|
|
|
|
}
|
|
|
|
: { uniform: e }),
|
|
|
|
inspect() {
|
|
|
|
return `shader: ${t}`;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s($o, "shader");
|
|
|
|
function wn(t, e = {}) {
|
|
|
|
let n = ne(this),
|
|
|
|
o = fe(n),
|
|
|
|
a = null,
|
|
|
|
u = null,
|
|
|
|
l = null,
|
|
|
|
f = new we();
|
|
|
|
if (!t) throw new Error("Please pass the resource name or data to sprite()");
|
|
|
|
let v = s((m, P, b, M) => {
|
|
|
|
let w = T(1, 1);
|
|
|
|
return (
|
|
|
|
b && M
|
|
|
|
? ((w.x = b / (m.width * P.w)), (w.y = M / (m.height * P.h)))
|
|
|
|
: b
|
|
|
|
? ((w.x = b / (m.width * P.w)), (w.y = w.x))
|
|
|
|
: M && ((w.y = M / (m.height * P.h)), (w.x = w.y)),
|
|
|
|
w
|
|
|
|
);
|
|
|
|
}, "calcTexScale");
|
|
|
|
return {
|
|
|
|
id: "sprite",
|
|
|
|
width: 0,
|
|
|
|
height: 0,
|
|
|
|
frame: e.frame || 0,
|
|
|
|
quad: e.quad || new he(0, 0, 1, 1),
|
|
|
|
animSpeed: e.animSpeed ?? 1,
|
|
|
|
flipX: e.flipX ?? !1,
|
|
|
|
flipY: e.flipY ?? !1,
|
|
|
|
draw() {
|
|
|
|
if (!a) return;
|
|
|
|
let m = a.frames[this.frame ?? 0];
|
|
|
|
if (!m) throw new Error(`Frame not found: ${this.frame ?? 0}`);
|
|
|
|
if (a.slice9) {
|
|
|
|
let { left: P, right: b, top: M, bottom: w } = a.slice9,
|
|
|
|
_ = a.tex.width * m.w,
|
|
|
|
$ = a.tex.height * m.h,
|
|
|
|
X = this.width - P - b,
|
|
|
|
L = this.height - M - w,
|
|
|
|
Q = P / _,
|
|
|
|
O = b / _,
|
|
|
|
oe = 1 - Q - O,
|
|
|
|
H = M / $,
|
|
|
|
ie = w / $,
|
|
|
|
se = 1 - H - ie,
|
|
|
|
ae = [
|
|
|
|
ge(0, 0, Q, H),
|
|
|
|
ge(Q, 0, oe, H),
|
|
|
|
ge(Q + oe, 0, O, H),
|
|
|
|
ge(0, H, Q, se),
|
|
|
|
ge(Q, H, oe, se),
|
|
|
|
ge(Q + oe, H, O, se),
|
|
|
|
ge(0, H + se, Q, ie),
|
|
|
|
ge(Q, H + se, oe, ie),
|
|
|
|
ge(Q + oe, H + se, O, ie),
|
|
|
|
ge(0, 0, P, M),
|
|
|
|
ge(P, 0, X, M),
|
|
|
|
ge(P + X, 0, b, M),
|
|
|
|
ge(0, M, P, L),
|
|
|
|
ge(P, M, X, L),
|
|
|
|
ge(P + X, M, b, L),
|
|
|
|
ge(0, M + L, P, w),
|
|
|
|
ge(P, M + L, X, w),
|
|
|
|
ge(P + X, M + L, b, w),
|
|
|
|
];
|
|
|
|
for (let pe = 0; pe < 9; pe++) {
|
|
|
|
let Ce = ae[pe],
|
|
|
|
ve = ae[pe + 9];
|
|
|
|
o.drawTexture(
|
|
|
|
Object.assign(o.getRenderProps(this), {
|
|
|
|
pos: ve.pos(),
|
2024-06-02 05:39:23 +00:00
|
|
|
tex: a.tex,
|
2024-06-17 22:57:39 +00:00
|
|
|
quad: m.scale(Ce),
|
2024-06-02 05:39:23 +00:00
|
|
|
flipX: this.flipX,
|
|
|
|
flipY: this.flipY,
|
|
|
|
tiled: e.tiled,
|
2024-06-17 22:57:39 +00:00
|
|
|
width: ve.w,
|
|
|
|
height: ve.h,
|
2024-06-02 05:39:23 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
} else
|
|
|
|
o.drawTexture(
|
|
|
|
Object.assign(o.getRenderProps(this), {
|
|
|
|
tex: a.tex,
|
|
|
|
quad: m.scale(this.quad ?? new he(0, 0, 1, 1)),
|
|
|
|
flipX: this.flipX,
|
|
|
|
flipY: this.flipY,
|
|
|
|
tiled: e.tiled,
|
2024-06-02 05:39:23 +00:00
|
|
|
width: this.width,
|
|
|
|
height: this.height,
|
2024-06-01 06:31:08 +00:00
|
|
|
})
|
|
|
|
);
|
2024-06-17 22:57:39 +00:00
|
|
|
},
|
|
|
|
add() {
|
|
|
|
let m = s((b) => {
|
|
|
|
let M = b.frames[0].clone();
|
|
|
|
e.quad && (M = M.scale(e.quad));
|
|
|
|
let w = v(b.tex, M, e.width, e.height);
|
|
|
|
(this.width = b.tex.width * M.w * w.x),
|
|
|
|
(this.height = b.tex.height * M.h * w.y),
|
|
|
|
e.anim && this.play(e.anim),
|
|
|
|
(a = b),
|
|
|
|
f.trigger(a);
|
|
|
|
}, "setSpriteData"),
|
|
|
|
P = o.resolveSprite(t);
|
|
|
|
P ? P.onLoad(m) : n.onLoad(() => m(o.resolveSprite(t).data));
|
|
|
|
},
|
|
|
|
update() {
|
|
|
|
if (!u) return;
|
|
|
|
let m = a.anims[u.name];
|
|
|
|
if (typeof m == "number") {
|
|
|
|
this.frame = m;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m.speed === 0) throw new Error("Sprite anim speed cannot be 0");
|
|
|
|
(u.timer += n.dt() * this.animSpeed),
|
|
|
|
u.timer >= 1 / u.speed &&
|
|
|
|
((u.timer = 0),
|
|
|
|
(this.frame += l),
|
|
|
|
(this.frame < Math.min(m.from, m.to) ||
|
|
|
|
this.frame > Math.max(m.from, m.to)) &&
|
|
|
|
(u.loop
|
|
|
|
? u.pingpong
|
|
|
|
? ((this.frame -= l), (l *= -1), (this.frame += l))
|
|
|
|
: (this.frame = m.from)
|
|
|
|
: u.pingpong
|
|
|
|
? l === Math.sign(m.to - m.from)
|
|
|
|
? ((this.frame = m.to), (l *= -1), (this.frame += l))
|
|
|
|
: ((this.frame = m.from), u.onEnd(), this.stop())
|
|
|
|
: ((this.frame = m.to), u.onEnd(), this.stop())));
|
|
|
|
},
|
|
|
|
play(m, P = {}) {
|
|
|
|
if (!a) {
|
|
|
|
f.add(() => this.play(m, P));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let b = a.anims[m];
|
|
|
|
if (b === void 0) throw new Error(`Anim not found: ${m}`);
|
|
|
|
u && this.stop(),
|
|
|
|
(u =
|
|
|
|
typeof b == "number"
|
|
|
|
? {
|
|
|
|
name: m,
|
|
|
|
timer: 0,
|
|
|
|
loop: !1,
|
|
|
|
pingpong: !1,
|
|
|
|
speed: 0,
|
|
|
|
onEnd: () => {},
|
|
|
|
}
|
|
|
|
: {
|
|
|
|
name: m,
|
|
|
|
timer: 0,
|
|
|
|
loop: P.loop ?? b.loop ?? !1,
|
|
|
|
pingpong: P.pingpong ?? b.pingpong ?? !1,
|
|
|
|
speed: P.speed ?? b.speed ?? 10,
|
|
|
|
onEnd: P.onEnd ?? (() => {}),
|
|
|
|
}),
|
|
|
|
(l = typeof b == "number" ? null : b.from < b.to ? 1 : -1),
|
|
|
|
(this.frame = typeof b == "number" ? b : b.from),
|
|
|
|
this.trigger("animStart", m);
|
|
|
|
},
|
|
|
|
stop() {
|
|
|
|
if (!u) return;
|
|
|
|
let m = u.name;
|
|
|
|
(u = null), this.trigger("animEnd", m);
|
|
|
|
},
|
|
|
|
numFrames() {
|
|
|
|
return a?.frames.length ?? 0;
|
|
|
|
},
|
|
|
|
getCurAnim() {
|
|
|
|
return u;
|
|
|
|
},
|
|
|
|
curAnim() {
|
|
|
|
return u?.name;
|
|
|
|
},
|
|
|
|
onAnimEnd(m) {
|
|
|
|
return this.on("animEnd", m);
|
|
|
|
},
|
|
|
|
onAnimStart(m) {
|
|
|
|
return this.on("animStart", m);
|
|
|
|
},
|
|
|
|
renderArea() {
|
|
|
|
return new n.Rect(T(0), this.width, this.height);
|
|
|
|
},
|
|
|
|
inspect() {
|
|
|
|
if (typeof t == "string") return `"${t}"`;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(wn, "sprite");
|
|
|
|
function Qo(t, e = {}) {
|
|
|
|
let n = ne(this),
|
|
|
|
o = fe(n);
|
|
|
|
function a(l) {
|
|
|
|
let f = n.formatText(
|
|
|
|
Object.assign(o.getRenderProps(l), {
|
|
|
|
text: l.text + "",
|
|
|
|
size: l.textSize,
|
|
|
|
font: l.font,
|
|
|
|
width: e.width && l.width,
|
|
|
|
align: l.align,
|
|
|
|
letterSpacing: l.letterSpacing,
|
|
|
|
lineSpacing: l.lineSpacing,
|
|
|
|
transform: l.textTransform,
|
|
|
|
styles: l.textStyles,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
return (
|
|
|
|
e.width || (l.width = f.width / (l.scale?.x || 1)),
|
|
|
|
(l.height = f.height / (l.scale?.y || 1)),
|
|
|
|
f
|
|
|
|
);
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
s(a, "update");
|
|
|
|
let u = {
|
|
|
|
id: "text",
|
|
|
|
set text(l) {
|
|
|
|
(t = l), a(this);
|
|
|
|
},
|
|
|
|
get text() {
|
|
|
|
return t;
|
|
|
|
},
|
|
|
|
textSize: e.size ?? 36,
|
|
|
|
font: e.font,
|
|
|
|
width: e.width ?? 0,
|
|
|
|
height: 0,
|
|
|
|
align: e.align,
|
|
|
|
lineSpacing: e.lineSpacing,
|
|
|
|
letterSpacing: e.letterSpacing,
|
|
|
|
textTransform: e.transform,
|
|
|
|
textStyles: e.styles,
|
|
|
|
add() {
|
|
|
|
n.onLoad(() => a(this));
|
|
|
|
},
|
|
|
|
draw() {
|
|
|
|
n.drawFormattedText(a(this));
|
|
|
|
},
|
|
|
|
renderArea() {
|
|
|
|
return new me(T(0), this.width, this.height);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
return a(u), u;
|
|
|
|
}
|
|
|
|
s(Qo, "text");
|
|
|
|
function Jo(t, e) {
|
|
|
|
let n = ne(this),
|
|
|
|
o = fe(n);
|
|
|
|
return {
|
|
|
|
id: "rect",
|
|
|
|
width: t,
|
|
|
|
height: e,
|
|
|
|
draw() {
|
|
|
|
n.drawUVQuad(
|
|
|
|
Object.assign(o.getRenderProps(this), {
|
|
|
|
width: this.width,
|
|
|
|
height: this.height,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
},
|
|
|
|
renderArea() {
|
|
|
|
return new me(T(0), this.width, this.height);
|
|
|
|
},
|
|
|
|
inspect() {
|
|
|
|
return `${Math.ceil(this.width)}, ${Math.ceil(this.height)}`;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(Jo, "uvquad");
|
|
|
|
function Zo(t = {}) {
|
|
|
|
let e = null,
|
|
|
|
n = null,
|
|
|
|
o = null,
|
|
|
|
a = null;
|
|
|
|
return {
|
|
|
|
id: "agent",
|
|
|
|
require: ["pos", "tile"],
|
|
|
|
agentSpeed: t.speed ?? 100,
|
|
|
|
allowDiagonals: t.allowDiagonals ?? !0,
|
|
|
|
getDistanceToTarget() {
|
|
|
|
return e ? this.pos.dist(e) : 0;
|
|
|
|
},
|
|
|
|
getNextLocation() {
|
|
|
|
return n && o ? n[o] : null;
|
|
|
|
},
|
|
|
|
getPath() {
|
|
|
|
return n ? n.slice() : null;
|
|
|
|
},
|
|
|
|
getTarget() {
|
|
|
|
return e;
|
|
|
|
},
|
|
|
|
isNavigationFinished() {
|
|
|
|
return n ? o === null : !0;
|
|
|
|
},
|
|
|
|
isTargetReachable() {
|
|
|
|
return n !== null;
|
|
|
|
},
|
|
|
|
isTargetReached() {
|
|
|
|
return e ? this.pos.eq(e) : !0;
|
|
|
|
},
|
|
|
|
setTarget(u) {
|
|
|
|
(e = u),
|
|
|
|
(n = this.getLevel().getPath(this.pos, e, {
|
|
|
|
allowDiagonals: this.allowDiagonals,
|
|
|
|
})),
|
|
|
|
(o = n ? 0 : null),
|
|
|
|
n
|
|
|
|
? (a ||
|
|
|
|
((a = this.getLevel().onNavigationMapChanged(() => {
|
|
|
|
n &&
|
|
|
|
o !== null &&
|
|
|
|
((n = this.getLevel().getPath(this.pos, e, {
|
|
|
|
allowDiagonals: this.allowDiagonals,
|
|
|
|
})),
|
|
|
|
(o = n ? 0 : null),
|
|
|
|
n
|
|
|
|
? this.trigger("navigation-next", this, n[o])
|
|
|
|
: this.trigger("navigation-ended", this));
|
|
|
|
})),
|
|
|
|
this.onDestroy(() => a.cancel())),
|
|
|
|
this.trigger("navigation-started", this),
|
|
|
|
this.trigger("navigation-next", this, n[o]))
|
|
|
|
: this.trigger("navigation-ended", this);
|
|
|
|
},
|
|
|
|
update() {
|
|
|
|
if (n && o !== null) {
|
|
|
|
if (this.pos.sdist(n[o]) < 2)
|
|
|
|
if (o === n.length - 1) {
|
|
|
|
(this.pos = e.clone()),
|
|
|
|
(o = null),
|
|
|
|
this.trigger("navigation-ended", this),
|
|
|
|
this.trigger("target-reached", this);
|
|
|
|
return;
|
|
|
|
} else o++, this.trigger("navigation-next", this, n[o]);
|
|
|
|
this.moveTo(n[o], this.agentSpeed);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onNavigationStarted(u) {
|
|
|
|
return this.on("navigation-started", u);
|
|
|
|
},
|
|
|
|
onNavigationNext(u) {
|
|
|
|
return this.on("navigation-next", u);
|
|
|
|
},
|
|
|
|
onNavigationEnded(u) {
|
|
|
|
return this.on("navigation-ended", u);
|
|
|
|
},
|
|
|
|
onTargetReached(u) {
|
|
|
|
return this.on("target-reached", u);
|
|
|
|
},
|
|
|
|
inspect() {
|
|
|
|
return JSON.stringify({
|
|
|
|
target: JSON.stringify(e),
|
|
|
|
path: JSON.stringify(n),
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(Zo, "agent");
|
|
|
|
function xr(t = {}) {
|
|
|
|
let e = T(0),
|
|
|
|
n = t.isObstacle ?? !1,
|
|
|
|
o = t.cost ?? 0,
|
|
|
|
a = t.edges ?? [],
|
|
|
|
u = s(() => {
|
|
|
|
let f = { left: 1, top: 2, right: 4, bottom: 8 };
|
|
|
|
return a.map((v) => f[v] || 0).reduce((v, m) => v | m, 0);
|
|
|
|
}, "getEdgeMask"),
|
|
|
|
l = u();
|
|
|
|
return {
|
|
|
|
id: "tile",
|
|
|
|
tilePosOffset: t.offset ?? T(0),
|
|
|
|
set tilePos(f) {
|
|
|
|
let v = this.getLevel();
|
|
|
|
(e = f.clone()),
|
|
|
|
(this.pos = T(
|
|
|
|
this.tilePos.x * v.tileWidth(),
|
|
|
|
this.tilePos.y * v.tileHeight()
|
|
|
|
).add(this.tilePosOffset));
|
|
|
|
},
|
|
|
|
get tilePos() {
|
|
|
|
return e;
|
|
|
|
},
|
|
|
|
set isObstacle(f) {
|
|
|
|
n !== f && ((n = f), this.getLevel().invalidateNavigationMap());
|
|
|
|
},
|
|
|
|
get isObstacle() {
|
|
|
|
return n;
|
|
|
|
},
|
|
|
|
set cost(f) {
|
|
|
|
o !== f && ((o = f), this.getLevel().invalidateNavigationMap());
|
|
|
|
},
|
|
|
|
get cost() {
|
|
|
|
return o;
|
|
|
|
},
|
|
|
|
set edges(f) {
|
|
|
|
(a = f), (l = u()), this.getLevel().invalidateNavigationMap();
|
|
|
|
},
|
|
|
|
get edges() {
|
|
|
|
return a;
|
|
|
|
},
|
|
|
|
get edgeMask() {
|
|
|
|
return l;
|
|
|
|
},
|
|
|
|
getLevel() {
|
|
|
|
return this.parent;
|
|
|
|
},
|
|
|
|
moveLeft() {
|
|
|
|
this.tilePos = this.tilePos.add(T(-1, 0));
|
|
|
|
},
|
|
|
|
moveRight() {
|
|
|
|
this.tilePos = this.tilePos.add(T(1, 0));
|
|
|
|
},
|
|
|
|
moveUp() {
|
|
|
|
this.tilePos = this.tilePos.add(T(0, -1));
|
|
|
|
},
|
|
|
|
moveDown() {
|
|
|
|
this.tilePos = this.tilePos.add(T(0, 1));
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(xr, "tile");
|
|
|
|
function es(t, e) {
|
|
|
|
if (t == null) throw new Error("health() requires the initial amount of hp");
|
|
|
|
return {
|
|
|
|
id: "health",
|
|
|
|
hurt(n = 1) {
|
|
|
|
this.setHP(t - n), this.trigger("hurt", n);
|
|
|
|
},
|
|
|
|
heal(n = 1) {
|
|
|
|
let o = t;
|
|
|
|
this.setHP(t + n), this.trigger("heal", t - o);
|
|
|
|
},
|
|
|
|
hp() {
|
|
|
|
return t;
|
|
|
|
},
|
|
|
|
maxHP() {
|
|
|
|
return e ?? null;
|
|
|
|
},
|
|
|
|
setMaxHP(n) {
|
|
|
|
e = n;
|
|
|
|
},
|
|
|
|
setHP(n) {
|
|
|
|
(t = e ? Math.min(e, n) : n), t <= 0 && this.trigger("death");
|
|
|
|
},
|
|
|
|
onHurt(n) {
|
|
|
|
return this.on("hurt", n);
|
|
|
|
},
|
|
|
|
onHeal(n) {
|
|
|
|
return this.on("heal", n);
|
|
|
|
},
|
|
|
|
onDeath(n) {
|
|
|
|
return this.on("death", n);
|
|
|
|
},
|
|
|
|
inspect() {
|
|
|
|
return `${t}`;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(es, "health");
|
|
|
|
function ts(t, e = {}) {
|
|
|
|
let n = ne(this);
|
|
|
|
if (t == null) throw new Error("lifespan() requires time");
|
|
|
|
let o = e.fade ?? 0;
|
|
|
|
return {
|
|
|
|
id: "lifespan",
|
|
|
|
require: ["opacity"],
|
|
|
|
async add() {
|
|
|
|
await n.wait(t),
|
|
|
|
(this.opacity = this.opacity ?? 1),
|
|
|
|
o > 0 &&
|
|
|
|
(await n.tween(
|
|
|
|
this.opacity,
|
|
|
|
0,
|
|
|
|
o,
|
|
|
|
(a) => (this.opacity = a),
|
|
|
|
Mt.linear
|
|
|
|
)),
|
|
|
|
this.destroy();
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(ts, "lifespan");
|
|
|
|
function ns(t, e, n) {
|
|
|
|
if (!t) throw new Error("state() requires an initial state");
|
|
|
|
let o = {};
|
|
|
|
function a(v) {
|
|
|
|
o[v] ||
|
|
|
|
(o[v] = {
|
|
|
|
enter: new we(),
|
|
|
|
end: new we(),
|
|
|
|
update: new we(),
|
|
|
|
draw: new we(),
|
|
|
|
});
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
s(a, "initStateEvents");
|
|
|
|
function u(v, m, P) {
|
|
|
|
return a(m), o[m][v].add(P);
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
s(u, "on");
|
|
|
|
function l(v, m, ...P) {
|
|
|
|
a(m), o[m][v].trigger(...P);
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
s(l, "trigger");
|
|
|
|
let f = !1;
|
|
|
|
return {
|
|
|
|
id: "state",
|
|
|
|
state: t,
|
|
|
|
enterState(v, ...m) {
|
|
|
|
if (((f = !0), e && !e.includes(v)))
|
|
|
|
throw new Error(`State not found: ${v}`);
|
|
|
|
let P = this.state;
|
|
|
|
if (n) {
|
|
|
|
if (!n?.[P]) return;
|
|
|
|
let b = typeof n[P] == "string" ? [n[P]] : n[P];
|
|
|
|
if (!b.includes(v))
|
|
|
|
throw new Error(
|
|
|
|
`Cannot transition state from "${P}" to "${v}". Available transitions: ${b
|
|
|
|
.map((M) => `"${M}"`)
|
|
|
|
.join(", ")}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
l("end", P, ...m),
|
|
|
|
(this.state = v),
|
|
|
|
l("enter", v, ...m),
|
|
|
|
l("enter", `${P} -> ${v}`, ...m);
|
|
|
|
},
|
|
|
|
onStateTransition(v, m, P) {
|
|
|
|
return u("enter", `${v} -> ${m}`, P);
|
|
|
|
},
|
|
|
|
onStateEnter(v, m) {
|
|
|
|
return u("enter", v, m);
|
|
|
|
},
|
|
|
|
onStateUpdate(v, m) {
|
|
|
|
return u("update", v, m);
|
|
|
|
},
|
|
|
|
onStateDraw(v, m) {
|
|
|
|
return u("draw", v, m);
|
|
|
|
},
|
|
|
|
onStateEnd(v, m) {
|
|
|
|
return u("end", v, m);
|
|
|
|
},
|
|
|
|
update() {
|
|
|
|
f || (l("enter", t), (f = !0)), l("update", this.state);
|
|
|
|
},
|
|
|
|
draw() {
|
|
|
|
l("draw", this.state);
|
|
|
|
},
|
|
|
|
inspect() {
|
|
|
|
return this.state;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(ns, "state");
|
|
|
|
function yr(t) {
|
|
|
|
return { id: "stay", stay: !0, scenesToStay: t };
|
|
|
|
}
|
|
|
|
s(yr, "stay");
|
|
|
|
function Cn() {
|
|
|
|
return {
|
|
|
|
id: "timer",
|
|
|
|
wait(t, e) {
|
|
|
|
let n = ne(this),
|
|
|
|
o = [];
|
|
|
|
e && o.push(e);
|
|
|
|
let a = 0,
|
|
|
|
u = this.onUpdate(() => {
|
|
|
|
(a += n.dt()), a >= t && (o.forEach((l) => l()), u.cancel());
|
2024-06-02 05:39:23 +00:00
|
|
|
});
|
2024-06-17 22:57:39 +00:00
|
|
|
return {
|
|
|
|
get paused() {
|
|
|
|
return u.paused;
|
|
|
|
},
|
|
|
|
set paused(l) {
|
|
|
|
u.paused = l;
|
|
|
|
},
|
|
|
|
cancel: u.cancel,
|
|
|
|
onEnd(l) {
|
|
|
|
o.push(l);
|
|
|
|
},
|
|
|
|
then(l) {
|
|
|
|
return this.onEnd(l), this;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
loop(t, e) {
|
|
|
|
let n = null,
|
|
|
|
o = s(() => {
|
|
|
|
(n = this.wait(t, o)), e();
|
|
|
|
}, "newAction");
|
|
|
|
return (
|
|
|
|
(n = this.wait(0, o)),
|
|
|
|
{
|
2024-06-02 05:39:23 +00:00
|
|
|
get paused() {
|
2024-06-17 22:57:39 +00:00
|
|
|
return n.paused;
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-17 22:57:39 +00:00
|
|
|
set paused(a) {
|
|
|
|
n.paused = a;
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-17 22:57:39 +00:00
|
|
|
cancel: () => n.cancel(),
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
tween(t, e, n, o, a = Mt.linear) {
|
|
|
|
let u = ne(this),
|
|
|
|
l = 0,
|
|
|
|
f = [],
|
|
|
|
v = this.onUpdate(() => {
|
|
|
|
l += u.dt();
|
|
|
|
let m = Math.min(l / n, 1);
|
|
|
|
o(Je(t, e, a(m))),
|
|
|
|
m === 1 && (v.cancel(), o(e), f.forEach((P) => P()));
|
2024-06-02 05:39:23 +00:00
|
|
|
});
|
2024-06-17 22:57:39 +00:00
|
|
|
return {
|
|
|
|
get paused() {
|
|
|
|
return v.paused;
|
|
|
|
},
|
|
|
|
set paused(m) {
|
|
|
|
v.paused = m;
|
|
|
|
},
|
|
|
|
onEnd(m) {
|
|
|
|
f.push(m);
|
|
|
|
},
|
|
|
|
then(m) {
|
|
|
|
return this.onEnd(m), this;
|
|
|
|
},
|
|
|
|
cancel() {
|
|
|
|
v.cancel();
|
|
|
|
},
|
|
|
|
finish() {
|
|
|
|
v.cancel(), o(e), f.forEach((m) => m());
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(Cn, "timer");
|
|
|
|
function rs(t = {}) {
|
|
|
|
let e = ne(this),
|
|
|
|
n = fe(e),
|
|
|
|
{ app: o } = n,
|
|
|
|
a = {},
|
|
|
|
u = new Set();
|
|
|
|
return {
|
|
|
|
id: "area",
|
|
|
|
collisionIgnore: t.collisionIgnore ?? [],
|
|
|
|
add() {
|
|
|
|
this.area.cursor && this.onHover(() => o.setCursor(this.area.cursor)),
|
|
|
|
this.onCollideUpdate((l, f) => {
|
|
|
|
a[l.id] || this.trigger("collide", l, f), (a[l.id] = f), u.add(l.id);
|
2024-06-02 05:39:23 +00:00
|
|
|
});
|
2024-06-17 22:57:39 +00:00
|
|
|
},
|
|
|
|
update() {
|
|
|
|
for (let l in a)
|
|
|
|
u.has(Number(l)) ||
|
|
|
|
(this.trigger("collideEnd", a[l].target), delete a[l]);
|
|
|
|
u.clear();
|
|
|
|
},
|
|
|
|
drawInspect() {
|
|
|
|
let l = this.localArea();
|
|
|
|
e.pushTransform(),
|
|
|
|
e.pushScale(this.area.scale),
|
|
|
|
e.pushTranslate(this.area.offset);
|
|
|
|
let f = {
|
|
|
|
outline: { width: 4 / n.getViewportScale(), color: ce(0, 0, 255) },
|
|
|
|
anchor: this.anchor,
|
|
|
|
fill: !1,
|
|
|
|
fixed: n.isFixed(this),
|
|
|
|
};
|
|
|
|
l instanceof e.Rect
|
|
|
|
? e.drawRect({ ...f, pos: l.pos, width: l.width, height: l.height })
|
|
|
|
: l instanceof e.Polygon
|
|
|
|
? e.drawPolygon({ ...f, pts: l.pts })
|
|
|
|
: l instanceof e.Circle &&
|
|
|
|
e.drawCircle({ ...f, pos: l.center, radius: l.radius }),
|
|
|
|
e.popTransform();
|
|
|
|
},
|
|
|
|
area: {
|
|
|
|
shape: t.shape ?? null,
|
|
|
|
scale: t.scale ? T(t.scale) : T(1),
|
|
|
|
offset: t.offset ?? T(0),
|
|
|
|
cursor: t.cursor ?? null,
|
|
|
|
},
|
|
|
|
isClicked() {
|
|
|
|
return o.isMousePressed() && this.isHovering();
|
|
|
|
},
|
|
|
|
isHovering() {
|
|
|
|
let l = n.isFixed(this) ? e.mousePos() : e.toWorld(e.mousePos());
|
|
|
|
return this.hasPoint(l);
|
|
|
|
},
|
|
|
|
checkCollision(l) {
|
|
|
|
return a[l.id] ?? null;
|
|
|
|
},
|
|
|
|
getCollisions() {
|
|
|
|
return Object.values(a);
|
|
|
|
},
|
|
|
|
isColliding(l) {
|
|
|
|
return !!a[l.id];
|
|
|
|
},
|
|
|
|
isOverlapping(l) {
|
|
|
|
let f = a[l.id];
|
|
|
|
return f && f.hasOverlap();
|
|
|
|
},
|
|
|
|
onClick(l, f = "left") {
|
|
|
|
let v = o.onMousePress(f, () => {
|
|
|
|
this.isHovering() && l();
|
|
|
|
});
|
|
|
|
return this.onDestroy(() => v.cancel()), v;
|
|
|
|
},
|
|
|
|
onHover(l) {
|
|
|
|
let f = !1;
|
|
|
|
return this.onUpdate(() => {
|
|
|
|
f ? (f = this.isHovering()) : this.isHovering() && ((f = !0), l());
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onHoverUpdate(l) {
|
|
|
|
return this.onUpdate(() => {
|
|
|
|
this.isHovering() && l();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onHoverEnd(l) {
|
|
|
|
let f = !1;
|
|
|
|
return this.onUpdate(() => {
|
|
|
|
f ? this.isHovering() || ((f = !1), l()) : (f = this.isHovering());
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onCollide(l, f) {
|
|
|
|
if (typeof l == "function" && f === void 0) return this.on("collide", l);
|
|
|
|
if (typeof l == "string")
|
|
|
|
return this.onCollide((v, m) => {
|
|
|
|
v.is(l) && f(v, m);
|
2024-06-02 05:39:23 +00:00
|
|
|
});
|
2024-06-17 22:57:39 +00:00
|
|
|
},
|
|
|
|
onCollideUpdate(l, f) {
|
|
|
|
if (typeof l == "function" && f === void 0)
|
|
|
|
return this.on("collideUpdate", l);
|
|
|
|
if (typeof l == "string")
|
|
|
|
return this.on("collideUpdate", (v, m) => v.is(l) && f(v, m));
|
|
|
|
},
|
|
|
|
onCollideEnd(l, f) {
|
|
|
|
if (typeof l == "function" && f === void 0)
|
|
|
|
return this.on("collideEnd", l);
|
|
|
|
if (typeof l == "string")
|
|
|
|
return this.on("collideEnd", (v) => v.is(l) && f(v));
|
|
|
|
},
|
|
|
|
hasPoint(l) {
|
|
|
|
return mt(this.worldArea(), l);
|
|
|
|
},
|
|
|
|
resolveCollision(l) {
|
|
|
|
let f = this.checkCollision(l);
|
|
|
|
f &&
|
|
|
|
!f.resolved &&
|
|
|
|
((this.pos = this.pos.add(f.displacement)), (f.resolved = !0));
|
|
|
|
},
|
|
|
|
localArea() {
|
|
|
|
return this.area.shape ? this.area.shape : this.renderArea();
|
|
|
|
},
|
|
|
|
worldArea() {
|
|
|
|
let l = this.localArea();
|
|
|
|
if (!(l instanceof e.Polygon || l instanceof e.Rect))
|
|
|
|
throw new Error("Only support polygon and rect shapes for now");
|
|
|
|
let f = this.transform
|
|
|
|
.clone()
|
|
|
|
.scale(T(this.area.scale ?? 1))
|
|
|
|
.translate(this.area.offset);
|
|
|
|
if (l instanceof e.Rect) {
|
|
|
|
let v = wt(this.anchor || Pt)
|
|
|
|
.add(1, 1)
|
|
|
|
.scale(-0.5)
|
|
|
|
.scale(l.width, l.height);
|
|
|
|
f.translate(v);
|
|
|
|
}
|
|
|
|
return l.transform(f);
|
|
|
|
},
|
|
|
|
screenArea() {
|
|
|
|
let l = this.worldArea();
|
|
|
|
return n.isFixed(this) ? l : l.transform(n.game.cam.transform);
|
|
|
|
},
|
|
|
|
inspect() {
|
|
|
|
return `(${this.area.scale.x.toFixed(1)}, ${this.area.scale.y.toFixed(
|
|
|
|
1
|
|
|
|
)})`;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(rs, "area");
|
|
|
|
function os(t = {}) {
|
|
|
|
let e = ne(this),
|
|
|
|
n = fe(e),
|
|
|
|
o = null,
|
|
|
|
a = null,
|
|
|
|
u = !1;
|
|
|
|
return {
|
|
|
|
id: "body",
|
|
|
|
require: ["pos"],
|
|
|
|
vel: T(0),
|
|
|
|
drag: t.drag ?? 0,
|
|
|
|
jumpForce: t.jumpForce ?? Fo,
|
|
|
|
gravityScale: t.gravityScale ?? 1,
|
|
|
|
isStatic: t.isStatic ?? !1,
|
|
|
|
mass: t.mass ?? 1,
|
|
|
|
add() {
|
|
|
|
if (this.mass === 0) throw new Error("Can't set body mass to 0");
|
|
|
|
this.is("area") &&
|
|
|
|
(this.onCollideUpdate((l, f) => {
|
|
|
|
if (!l.is("body") || f.resolved) return;
|
|
|
|
this.trigger("beforePhysicsResolve", f);
|
|
|
|
let v = f.reverse();
|
2024-06-02 05:39:23 +00:00
|
|
|
if (
|
2024-06-17 22:57:39 +00:00
|
|
|
(l.trigger("beforePhysicsResolve", v),
|
|
|
|
!(f.resolved || v.resolved) && !(this.isStatic && l.isStatic))
|
2024-06-02 05:39:23 +00:00
|
|
|
) {
|
2024-06-17 22:57:39 +00:00
|
|
|
if (!this.isStatic && !l.isStatic) {
|
|
|
|
let m = this.mass + l.mass;
|
|
|
|
(this.pos = this.pos.add(f.displacement.scale(l.mass / m))),
|
|
|
|
(l.pos = l.pos.add(f.displacement.scale(-this.mass / m))),
|
|
|
|
(this.transform = n.calcTransform(this)),
|
|
|
|
(l.transform = n.calcTransform(l));
|
|
|
|
} else {
|
|
|
|
let m = !this.isStatic && l.isStatic ? f : f.reverse();
|
|
|
|
(m.source.pos = m.source.pos.add(m.displacement)),
|
|
|
|
(m.source.transform = n.calcTransform(m.source));
|
|
|
|
}
|
|
|
|
(f.resolved = !0),
|
|
|
|
this.trigger("physicsResolve", f),
|
|
|
|
l.trigger("physicsResolve", f.reverse());
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
}),
|
|
|
|
this.onPhysicsResolve((l) => {
|
|
|
|
n.game.gravity &&
|
|
|
|
(l.isBottom() && this.isFalling()
|
|
|
|
? ((this.vel = this.vel.reject(n.game.gravity.unit())),
|
|
|
|
(o = l.target),
|
|
|
|
(a = l.target.pos),
|
|
|
|
u ? (u = !1) : this.trigger("ground", o))
|
|
|
|
: l.isTop() &&
|
|
|
|
this.isJumping() &&
|
|
|
|
((this.vel = this.vel.reject(n.game.gravity.unit())),
|
|
|
|
this.trigger("headbutt", l.target)));
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
update() {
|
|
|
|
if (n.game.gravity && !this.isStatic) {
|
|
|
|
u && ((o = null), (a = null), this.trigger("fallOff"), (u = !1));
|
|
|
|
let l = !0;
|
|
|
|
if (
|
|
|
|
(o &&
|
|
|
|
(!this.isColliding(o) || !o.exists() || !o.is("body")
|
|
|
|
? (u = !0)
|
|
|
|
: (!o.pos.eq(a) &&
|
|
|
|
t.stickToPlatform !== !1 &&
|
|
|
|
this.moveBy(o.pos.sub(a)),
|
|
|
|
(a = o.pos),
|
|
|
|
(l = !1))),
|
|
|
|
l)
|
|
|
|
) {
|
|
|
|
let f = this.vel.clone();
|
|
|
|
this.vel = this.vel.add(
|
|
|
|
n.game.gravity.scale(this.gravityScale * e.dt())
|
|
|
|
);
|
|
|
|
let v = t.maxVelocity ?? Io;
|
|
|
|
this.vel.slen() > v * v && (this.vel = this.vel.unit().scale(v)),
|
|
|
|
f.dot(n.game.gravity) < 0 &&
|
|
|
|
this.vel.dot(n.game.gravity) >= 0 &&
|
|
|
|
this.trigger("fall");
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
}
|
|
|
|
(this.vel.x *= 1 - this.drag),
|
|
|
|
(this.vel.y *= 1 - this.drag),
|
|
|
|
this.move(this.vel);
|
|
|
|
},
|
|
|
|
onPhysicsResolve(l) {
|
|
|
|
return this.on("physicsResolve", l);
|
|
|
|
},
|
|
|
|
onBeforePhysicsResolve(l) {
|
|
|
|
return this.on("beforePhysicsResolve", l);
|
|
|
|
},
|
|
|
|
curPlatform() {
|
|
|
|
return o;
|
|
|
|
},
|
|
|
|
isGrounded() {
|
|
|
|
return o !== null;
|
|
|
|
},
|
|
|
|
isFalling() {
|
|
|
|
return this.vel.dot(e.getGravityDirection()) > 0;
|
|
|
|
},
|
|
|
|
isJumping() {
|
|
|
|
return this.vel.dot(e.getGravityDirection()) < 0;
|
|
|
|
},
|
|
|
|
jump(l) {
|
|
|
|
(o = null),
|
|
|
|
(a = null),
|
|
|
|
(this.vel = e.getGravityDirection().scale(-l || -this.jumpForce));
|
|
|
|
},
|
|
|
|
onGround(l) {
|
|
|
|
return this.on("ground", l);
|
|
|
|
},
|
|
|
|
onFall(l) {
|
|
|
|
return this.on("fall", l);
|
|
|
|
},
|
|
|
|
onFallOff(l) {
|
|
|
|
return this.on("fallOff", l);
|
|
|
|
},
|
|
|
|
onHeadbutt(l) {
|
|
|
|
return this.on("headbutt", l);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(os, "body");
|
|
|
|
function ss(t = 2) {
|
|
|
|
let e = t;
|
|
|
|
return {
|
|
|
|
id: "doubleJump",
|
|
|
|
require: ["body"],
|
|
|
|
numJumps: t,
|
|
|
|
add() {
|
|
|
|
this.onGround(() => {
|
|
|
|
e = this.numJumps;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
doubleJump(n) {
|
|
|
|
e <= 0 ||
|
|
|
|
(e < this.numJumps && this.trigger("doubleJump"), e--, this.jump(n));
|
|
|
|
},
|
|
|
|
onDoubleJump(n) {
|
|
|
|
return this.on("doubleJump", n);
|
|
|
|
},
|
|
|
|
inspect() {
|
|
|
|
return `${e}`;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(ss, "doubleJump");
|
|
|
|
function Tn(t) {
|
|
|
|
if (!t) throw new Error("Please define an anchor");
|
|
|
|
return {
|
|
|
|
id: "anchor",
|
|
|
|
anchor: t,
|
|
|
|
inspect() {
|
|
|
|
return typeof this.anchor == "string"
|
|
|
|
? this.anchor
|
|
|
|
: this.anchor.toString();
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(Tn, "anchor");
|
|
|
|
function is() {
|
|
|
|
return { id: "fixed", fixed: !0 };
|
|
|
|
}
|
|
|
|
s(is, "fixed");
|
|
|
|
function as(t, e) {
|
|
|
|
return {
|
|
|
|
id: "follow",
|
|
|
|
require: ["pos"],
|
|
|
|
follow: { obj: t, offset: e ?? T(0) },
|
|
|
|
add() {
|
|
|
|
t.exists() && (this.pos = this.follow.obj.pos.add(this.follow.offset));
|
|
|
|
},
|
|
|
|
update() {
|
|
|
|
t.exists() && (this.pos = this.follow.obj.pos.add(this.follow.offset));
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(as, "follow");
|
|
|
|
function cs(t) {
|
|
|
|
let e = ne(this),
|
|
|
|
n = fe(e),
|
|
|
|
o = n.game.layers.indexOf(t);
|
|
|
|
return {
|
|
|
|
id: "layer",
|
|
|
|
get layerIndex() {
|
|
|
|
return o;
|
|
|
|
},
|
|
|
|
get layer() {
|
|
|
|
return e.layers[o];
|
|
|
|
},
|
|
|
|
set layer(a) {
|
|
|
|
if (((o = n.game.layers.indexOf(a)), o == -1))
|
|
|
|
throw Error("Invalid layer name");
|
|
|
|
},
|
|
|
|
inspect() {
|
|
|
|
return `${this.layer}`;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(cs, "layer");
|
|
|
|
function us(t, e) {
|
|
|
|
let n = typeof t == "number" ? D.fromAngle(t) : t.unit();
|
|
|
|
return {
|
|
|
|
id: "move",
|
|
|
|
require: ["pos"],
|
|
|
|
update() {
|
|
|
|
this.move(n.scale(e));
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(us, "move");
|
|
|
|
function ls(t = {}) {
|
|
|
|
let e = ne(this),
|
|
|
|
n = t.distance ?? Bo,
|
|
|
|
o = !1;
|
|
|
|
return {
|
|
|
|
id: "offscreen",
|
|
|
|
require: ["pos"],
|
|
|
|
isOffScreen() {
|
|
|
|
let a = this.screenPos(),
|
|
|
|
u = new me(T(0), e.width(), e.height());
|
|
|
|
return !e.testRectPoint(u, a) && u.sdistToPoint(a) > n * n;
|
|
|
|
},
|
|
|
|
onExitScreen(a) {
|
|
|
|
return this.on("exitView", a);
|
|
|
|
},
|
|
|
|
onEnterScreen(a) {
|
|
|
|
return this.on("enterView", a);
|
|
|
|
},
|
|
|
|
update() {
|
|
|
|
this.isOffScreen()
|
|
|
|
? (o || (this.trigger("exitView"), (o = !0)),
|
|
|
|
t.hide && (this.hidden = !0),
|
|
|
|
t.pause && (this.paused = !0),
|
|
|
|
t.destroy && this.destroy())
|
|
|
|
: (o && (this.trigger("enterView"), (o = !1)),
|
|
|
|
t.hide && (this.hidden = !1),
|
|
|
|
t.pause && (this.paused = !1));
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(ls, "offscreen");
|
|
|
|
function En(t) {
|
|
|
|
return t.fixed ? !0 : t.parent ? En(t.parent) : !1;
|
|
|
|
}
|
|
|
|
s(En, "isFixed");
|
|
|
|
function Wt(...t) {
|
|
|
|
let e = ne(this),
|
|
|
|
n = fe(e);
|
|
|
|
return {
|
|
|
|
id: "pos",
|
|
|
|
pos: T(...t),
|
|
|
|
moveBy(...o) {
|
|
|
|
this.pos = this.pos.add(T(...o));
|
|
|
|
},
|
|
|
|
move(...o) {
|
|
|
|
this.moveBy(T(...o).scale(e.dt()));
|
|
|
|
},
|
|
|
|
moveTo(...o) {
|
|
|
|
if (typeof o[0] == "number" && typeof o[1] == "number")
|
|
|
|
return this.moveTo(T(o[0], o[1]), o[2]);
|
|
|
|
let a = o[0],
|
|
|
|
u = o[1];
|
|
|
|
if (u === void 0) {
|
|
|
|
this.pos = T(a);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let l = a.sub(this.pos);
|
|
|
|
if (l.len() <= u * e.dt()) {
|
|
|
|
this.pos = T(a);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.move(l.unit().scale(u));
|
|
|
|
},
|
|
|
|
worldPos() {
|
|
|
|
return this.parent ? this.parent.transform.multVec2(this.pos) : this.pos;
|
|
|
|
},
|
|
|
|
toWorld(o) {
|
|
|
|
return this.parent
|
|
|
|
? this.parent.transform.multVec2(this.pos.add(o))
|
|
|
|
: this.pos.add(o);
|
|
|
|
},
|
|
|
|
fromWorld(o) {
|
|
|
|
return this.parent
|
|
|
|
? this.parent.transform.invert().multVec2(o).sub(this.pos)
|
|
|
|
: o.sub(this.pos);
|
|
|
|
},
|
|
|
|
screenPos() {
|
|
|
|
let o = this.worldPos();
|
|
|
|
return En(this) ? o : e.toScreen(o);
|
|
|
|
},
|
|
|
|
toScreen(o) {
|
|
|
|
let a = this.toWorld(o);
|
|
|
|
return En(this) ? a : e.toScreen(a);
|
|
|
|
},
|
|
|
|
fromScreen(o) {
|
|
|
|
return En(this) ? this.fromWorld(o) : this.fromWorld(e.toWorld(o));
|
|
|
|
},
|
|
|
|
toOther(o, a) {
|
|
|
|
return o.fromWorld(this.toWorld(a));
|
|
|
|
},
|
|
|
|
fromOther(o, a) {
|
|
|
|
return o.toOther(this, a);
|
|
|
|
},
|
|
|
|
inspect() {
|
|
|
|
return `(${Math.round(this.pos.x)}, ${Math.round(this.pos.y)})`;
|
|
|
|
},
|
|
|
|
drawInspect() {
|
|
|
|
e.drawCircle({
|
|
|
|
color: e.rgb(255, 0, 0),
|
|
|
|
radius: 4 / n.getViewportScale(),
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(Wt, "pos");
|
|
|
|
function ms(t) {
|
|
|
|
return {
|
|
|
|
id: "rotate",
|
|
|
|
angle: t ?? 0,
|
|
|
|
rotateBy(e) {
|
|
|
|
this.angle += e;
|
|
|
|
},
|
|
|
|
rotateTo(e) {
|
|
|
|
this.angle = e;
|
|
|
|
},
|
|
|
|
inspect() {
|
|
|
|
return `${Math.round(this.angle)}`;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(ms, "rotate");
|
|
|
|
function Yt(...t) {
|
|
|
|
let e = ne(this),
|
|
|
|
n = fe(e);
|
|
|
|
return t.length === 0
|
|
|
|
? Yt(1)
|
|
|
|
: {
|
|
|
|
id: "scale",
|
|
|
|
scale: T(...t),
|
|
|
|
scaleTo(...o) {
|
|
|
|
this.scale = T(...o);
|
|
|
|
},
|
|
|
|
scaleBy(...o) {
|
|
|
|
this.scale.scale(T(...o));
|
|
|
|
},
|
|
|
|
inspect() {
|
|
|
|
return `(${n.toFixed(this.scale.x, 2)}, ${n.toFixed(
|
|
|
|
this.scale.y,
|
|
|
|
2
|
|
|
|
)})`;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(Yt, "scale");
|
|
|
|
function ds(t) {
|
|
|
|
return {
|
|
|
|
id: "z",
|
|
|
|
z: t,
|
|
|
|
inspect() {
|
|
|
|
return `${this.z}`;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(ds, "z");
|
|
|
|
var hs =
|
|
|
|
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAD0AAAA1CAYAAADyMeOEAAAAAXNSR0IArs4c6QAAAoVJREFUaIHdm7txwkAQhheGAqACiCHzOKQDQrqgILpwSAeEDBnEUAF0gCMxZ7G72qce/mec2Lpf9+3unaS78wgSNZ8uX5729+d1FNWXUuGmXlBOUUEIMckEpeQJgBu6C+BSFngztBR2vd+ovY+7g+p6LbgaWgJrAeUkDYIUXgXdBBwNi6kpABJwMTQH3AZsXRR8GHTfgEth8E3gjdAUcNewpbTgY85sCMCUuOokozE0YM0YRzM9NGAAXd8+omAF5h4lnmBRvpSnZHyLoLEbaN+aKB9KWv/KWw0tAbbANnlG+UvB2dm77NxxdwgBpjrF/d7rW9cbmpvio2A5z8iAYpVU8pGZlo6/2+MSco2lHfd3rv9jAP038e1xef9o2mjvYb2OqpqKE81028/jeietlSEVO5FRWsxWsJit1G3aFpW8iWe5RwpiCZAk25QvV6nz6fIlynRGuTd5WqpJ4guAlDfVKBK87hXljflgv1ON6fV+4+5gVlA17SfeG0heKqQd4l4jI/wrmaA9N9R4ar+wpHJDZyrrfcH0nB66PqAzPi76pn+faSyJk/vzOorYhGurQrzj/P68jtBMawHaHBIR9xoD5O34dy0qQOSYHvqExq2TpT2nf76+w7y251OYF0CRaU+J920TwLUa6inx6OxE6g80lu2ux7Y2eJLF/rCXE6zEPdnenk9o+4ih9AEdnW2q81HXl5LuU6OTl2fXUhqganbXAGq3g6jJOWV/OnoesO6YqqEB/GdNsjf7uHtwj2DzmRNpp7iOZfm6D9oAxB6Yi1gC4oIYeo4MIPdopEQRB+cAko5J1tW386HpB2Kz1eop4Epdwls/kgZ1sh8gZsEjdcWkr//D8Qu3Z3l5Nl1NtAAAAABJRU5ErkJggg==";
|
|
|
|
var ps =
|
|
|
|
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOcAAACDCAYAAAB2kQxsAAAAAXNSR0IArs4c6QAABqxJREFUeJztnU1yFDkQRtMEB+AG7Fk6fBPO6ZsQLGc/N5gbMAtosJvqKv2kpPxS763A0W5XSXqVqZ+SngzgF58/fflx/7N///vnacW1gBkFD2Z2LOYNBF3Dx9UXAGs5kxLWwhNxU2qlJHrOhwLfkNZoiaBzIa3dCFJYLXgSboKXmETPeVDQyamR8vX55fe/v37/9vBzCDoH0tqktEpZ+t0IOh4KOBm16euZmETPtVDAiRgRLRF0HRRuEkrFrE1hzR4Lipxj+bD6AqCPz5++/Bgp5tXfdv1CeAdPPmFmSkn0nE+a0drdFm6XiOkdKWEuKRptTXqlLuqqFNaM6Dkb+T5nbb+npo8WjZVinqFantFJk9bWojaRThq7HzKN8wiPJ7aCoJHEZN5zHvJp7RE1DTV6SnZ1fa/PL1MjJtF5HmnT2tJF3GZ/BIj05I8ULUtR6ypER7ogjxpw61rRGxEal4KYjNyORzatbUlHSxr06tFcBTHPiN5NUEJWzlZKG/aKRqYk5tl1IKgPafucZ7w+vxSluLP6olHnL6MQQfYV6bpk/+BRZXm+cXHEiApSipZHlE6tRBDMkxmyysl5VsmtjXiFoJmiZU35ZWK0oNv1OY+omSv0GDDKJCaMI42cHg25dvFCi6QZxVS6ViVSpLUz38A4oiS9ySjlW2althGWKZrN6XNuOVpbwq0ReIzqZhfTrHwE/PZZuEYqcnqO0tZQGxVqRylprLGIEDXNkLOKEakbYsYiiphmiQaEZuD9BghixiKSmGYJIueqBt4TRZEyHtHENCNyNtMaRREzHhHFNBOKnKv7myVcVXKka4WfRBXTjMjpypl8iBmP6MsOmed0Bgk1UHjxXlpORIAWIqeybyGtha1QEdNMRM5s7wLCGpTENBORE6AXNTHNkBM2QFFMM4F5ToX5TYiLqphmRE7YmMhimiEnJEb9XBdJOUlp4Qp1Mc1E5QQ4I/qyvFJCy8n8JnijEjXNAi3fQ0TwIEM6e2OqnAgII8kkptkgOZEQZlN6BquZjqhVFxlBOkZq4Z6WASAFQQ8jZwQJ70FK8CTiaeb3fDSLJyMiwiwiS/q0SkwEBE+85jYjSTpcTiSE2WQRtVlOpAMVemVdtjXmlZxICFlQk/TJjHcmYS96JJ0p6KmcZggKeWmVdPopYwgKuxJVUuQE+EU0Sd99KYICxJH0ry9DUIA/rFy3WyWnGYLCnqyQ9PCXERTgmJmSPvwlBAU4p1bUWklPP1yytA9JYWdGRtLLDyEowDUjomiRwQgKUIZnJC3OgREUoByPSDpkDyEkBfhJj6RNQ7xEUYA6aiS9Cdo8SUoUBaijVtCuFQwICtBGiajdawARFKCNK0HdVtEjKUAd0+Q0q9v/FklhJ1rmP4e8JEoUBejfq2jYNgtEUdgJzwN7u6dSSkBQyMSME7O7FyHUQpoLCqw8rv5o+d6Uw3NvfzjagUkAZvOlLH1lLMyx8wCzWBEhW3ZDmLZ7NTsrwCpmyui5A1+IPidigjcjhZy14/vytBYxwRsPMVcf/2c2QU72wQUVIgj5lqFyIiZEJ5qQb1me1gLMJLKM93wY9cVETYiGkphmg+RETFhJljY2LHICQB/uchI1AXxwlRMxAfwgrYVtUHvxwk1OoiaAL8MjJ2ICtOEip1q6APnJEBS6VwiRzp4vtM5YBvf3m/EeI8DyvUZK33z4+v1bqsZ7dN+3n2W6zwgMO44hY0X1vIqkXh419x7lXh9ds8oyviFyRqmcXrxf2FUtF89ymFkG6nI2p7WZB4FGvUWfLcVt4ahsdy+TR7ifz6lc0F5v0GfalmXldpE3esrr6PrTR84sjNjS4kpQhQhaUi4lD6KR1xK9DHupfoKoR02vSFDy9FWNoKVivv1/lG7OfZkqR043OZUbWgmtFaomaGl51ZTHCnFv5bqNnFGjZvRtEFUEHSHmI1ZHWgVBXZ5+sxvX7ANlPChpjKsknSllKaPlRU4nZo0Yjq6wiIJGFPMML2mj3M8ZRRe4QkzF6FhCJEFbBn4i0iKswn11yenZiLLKeMRqQdWiZSmlkqrcV9d0gPfksAcqBW+2ZqAoq5gZGSrnTtGwlVmCIqUepxWxerj7iIyNZ7SgiKmJhJw7NJpRgiKmLuHl3KnReA4UIaU+y+WkcbzHQ1DEzMGQ9aJH0BDK6RE0y9wlTDp2HuppERQxc0FFBaZGUMTMB5UlQG/fHyk1odJEaBUUMXWh4oSoFRQxtaHyxMi2uBseQwUKciUoYuaAShTlkaCImQcqUph7QREzF/8DSS/2GZ2/N/sAAAAASUVORK5CYII=";
|
|
|
|
var fs = jr(
|
|
|
|
"SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU4Ljc2LjEwMAAAAAAAAAAAAAAA//tQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASW5mbwAAAA8AAAASAAAeMwAUFBQUFCIiIiIiIjAwMDAwPj4+Pj4+TExMTExZWVlZWVlnZ2dnZ3V1dXV1dYODg4ODkZGRkZGRn5+fn5+frKysrKy6urq6urrIyMjIyNbW1tbW1uTk5OTk8vLy8vLy//////8AAAAATGF2YzU4LjEzAAAAAAAAAAAAAAAAJAQKAAAAAAAAHjOZTf9/AAAAAAAAAAAAAAAAAAAAAP/7kGQAAANUMEoFPeACNQV40KEYABEY41g5vAAA9RjpZxRwAImU+W8eshaFpAQgALAAYALATx/nYDYCMJ0HITQYYA7AH4c7MoGsnCMU5pnW+OQnBcDrQ9Xx7w37/D+PimYavV8elKUpT5fqx5VjV6vZ38eJR48eRKa9KUp7v396UgPHkQwMAAAAAA//8MAOp39CECAAhlIEEIIECBAgTT1oj///tEQYT0wgEIYxgDC09aIiE7u7u7uIiIz+LtoIQGE/+XAGYLjpTAIOGYYy0ZACgDgSNFxC7YYiINocwERjAEDhIy0mRoGwAE7lOTBsGhj1qrXNCU9GrgwSPr80jj0dIpT9DRUNHKJbRxiWSiifVHuD2b0EbjLkOUzSXztP3uE1JpHzV6NPq+f3P5T0/f/lNH7lWTavQ5Xz1yLVe653///qf93B7f/vMdaKJAAJAMAIwIMAHMpzDkoYwD8CR717zVb8/p54P3MikXGCEWhQOEAOAdP6v8b8oNL/EzdnROC8Zo+z+71O8VVAGIKFEglKbidkoLam0mAFiwo0ZoVExf/7kmQLgAQyZFxvPWAENcVKXeK0ABAk2WFMaSNIzBMptBYfArbkZgpWjEQpcmjxQoG2qREWQcvpzuuIm29THt3ElhDNlrXV///XTGbm7Kbx0ymcRX///x7GVvquf5vk/dPs0Wi5Td1vggDxqbNII4bAPTU3Ix5h9FJTe7zv1LHG/uPsPrvth0ejchVzVT3giirs6sQAACgQAAIAdaXbRAYra/2t0//3HwqLKIlBOJhOg4BzAOkt+MOL6H8nlNvKyi3rOnqP//zf6AATwBAKIcHKixxwjl1TjDVIrvTqdmKQOFQBUBDwZ1EhHlDEGEVyGQWBAHrcJgRSXYbkvHK/8/6rbYjs4Qj0C8mRy2hwRv/82opGT55fROgRoBTjanaiQiMRHUu1/P3V9yGFffaVv78U1/6l/kpo0cz73vuSv/9GeaqDVRA5bWdHRKQKIEAAAAoIktKeEmdQFKN5sguv/ZSC0oxCAR7CzcJgEsd8cA0M/x0tzv15E7//5L5KCqoIAAmBFIKM1UxYtMMFjLKESTE8lhaelUyCBYeA2IN4rK1iDt//+5JkEgAkZzlVq29D8DJDWo0YLLARwPFZrL0PyLsUazTAlpI+hKSx01VSOfbjXg0iW9/jVPDleLJ15QQA4Okdc5ByMDFIeuCCE5CvevwBGH8YibiX9FtaIIgUikF42wrZw6ZJ6WlHrA+Ki5++NNMeYH1lEkwwJAIJB4ugVFguXFc20Vd/FLlvq1GSiSwAFABABABA47k6BFeNvxEQZO9v3L1IE4iEVElfrXmEmlyWIyGslFA55gH/sW7////o9AAFIBIIAAIUMzYTTNkgsAmYObfwQyzplrOmYvq0BKCKNN+nUTbvD7cJzvHxrEWG5QqvP8U1vFx6CwE8NoRc2ADBeEb/HoXh60N7ST8nw9QiiGoYvf/r6GtC9+vLwXHjaSkIp3iupC5+Nii81Zhu85pNYbFvrf+UFThDOYYY26off+W6b//73GTiN9xDfl0AAwBAiMBO8qsDBPOZtuT/dTbjVVbY/KSGH6ppHwKv/6X+s8gUCN/lODzv////GQAGAMQAADlXAUCBJiY0wFQZusYQOaQzaTwDBTcx0IvVp8m7uxKp//uSZBMCBHRI1eNPLHAyxNqWGeoYUIEnWYyxD8DUFSn0l6iojcd+oEOkzV6uWqyHNzjqmv+7V5xGUfY9yEmbziTzjRscm9OqFQp1PKFrqu3PX/7YuGtDU6bt0OUTpv38rdc+37dVDQLKUchaJ853E9edNDGqWwsYz1VoiSStEJtZvw6+sNqFWqaIXJjQCGAAGWAYVwmag/x3BRJw1wYF7IzVqDcNzn85d//FzK7IgwbQwccLoB4AsF8Nj/1ESRUAAVJwAFh0YOFEhmSJEHKQRDyhszgLUpHIgFrb5cySFg5jv10ImlYuvaaGBItfXqnNPmic+XNkmb5fW49vdhq97nQMQyGIlM2v8oQSrxKSxE4F1WqrduqvuJCRof1R7Gsre9KszUVF1/t3PzH2tnp+iSUG3rDwGNcDzxCGA8atuQF0paZAAkAhAQAEAC240yJV+nJgUrqq8axAYtVpYjZyFGb13/17jwiClQDaCdytZpyHHf1R/EG/+lUAgAAAChhmJvioVGGBCFgqdpsGAkUUrbTstwTCJgLQpFIsELW7t/68Iv/7kmQUgAQ9NFO9aeAAPAU6RKwUABClY2e5hoARGpDvPydCAsY8WO10fSvUOnfT98+n/l/6/+hxslhQ1DEOaevNKGocvIYba8WJpaP/15pX0NQ1DUNn/////k6lPp/N61rBi8RJFfERV3IgrqDsJA64sjCoKxDDQ9xEcWDpMBDwVFDIAEIAAzryxsjGi4q/oWpixKjhklAF4pUrDPjFhFVupDFZ/t/t0YPAygUBhADPR/KLCKJ8h2Oxhpxz/zNRAAFl0MAZLAYEAiVbEiz36LSgZ5QoQVat69KNy8FyM5Z80ACHAzgnISEkxUSJIDyBSwi5KF4mjBl4xJdbrG9ComLrL8YATiodhQKCkj6ROdyg1y5XmZlvMVmpJzYppJDwLi/Lp9vT3TfmimOGpuezi2U/9FNav0zX9Oja2r//8+hvuihuQAAMAVmqFgAgCcuboAEAAAUcqy8ca0BHBmwbFkED0CNA1YYDPkhcQrRJxcY3BzfxxltAz9vX62Xl3plAzWmRO+FkZyH///1qAAEjQBAACUpgU5o2AIBmFBGMamrGg0b/+5JkC4ADxyLWb2ngAEEkGofsoACP7U1JLaxTkOqFaKhspGgnW3SGC56ZgUJGCRnLOmIJAkuNBgvwU4Ocf8CJK9UsafH9/Frj///365XSoME+DZMw5UNjrMbVoeIj9EL91IuQ5KHyl5V2LCpdIdESgafOHxVGkAlkHuakmix/gN8+BP/sKguLAAoAtUjtvaoeEADwr3OK11E4KBlojgeQNQBJ4MvCAd/4t/xMMzeLhQGQ1//6tQu5BaBOGCT6U4aafvXZ//4iAPAAAAbLkgIlQmMSLA2H1CVNAlWwyVvKIQIxOSK1NWxs4MBUATlKrAkIMPAjCAdS6MVFzuURWa/+/qQWEGsA6EEpiBEJb9Q21lAHoBoD0B6aAPhyt+bG3muoXIN3RLadXxUfr/ohjGFF/p97eqNI5noKAqYLNPpUTDSI9/TmA6B+YAAADgA0Y4lxTW1SQfOQuDDDI0KTTuIrF5qoJrUFhUFAsg+AT2hbkaRZYGIjBKVDIa5VgNN/9P/rCDsBJbYJRKpCA1ArAkigIeYY61AjE+jubyiZFZ3+L789//uSZBCABHVj2entNmw1JXokLycYEFTFVa0wz4DYjKs08J2Q+r4n3lgbWaaMwMLEjFW88F39brqPF83cv1mCSJeY3Q2uiQxhBJxCBeR1D2LQRsYQcZUTzdNll8+OwZBsIwSgl45ymaHX603Mz7JmZuvt71GDTN66zev/+cLn/b5imV8pAHkg61FIJchBSG+zycgAZgADD6F1iQQRXRWmWS6bDIIgyBCZEcdl/KgXGmVKFv/vl8ry/5bLypf//U5jhYDhL9X/pAA0AKBIAAKgGtGXGGWJgEoF2JNsHlKfSKLRhGBAgIuWZKIJCFpF1VBhkB+EfzEyMUJdWuMrEZoPZ5BfF3/Nu62riIdjoO4AAKD2sTrDmpZZaYysf/810TitAVvn9xtFucieiaEy54YqiIO6RqkG
|
|
|
|
);
|
|
|
|
var gs =
|
|
|
|
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOcAAACDCAYAAAB2kQxsAAAAAXNSR0IArs4c6QAABdRJREFUeJzt3d3N3TYMgGG16ADdoAhyl7UyV9bqXRB0g2zQXgRGDcOWSIoUaX3vAwQBknMk/4gWLcnHrQEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACDEb9kb8FH99eeXf6Wf/efn35ynDyj1pEsb6G6NUxOYZ7sdB/QtPdnWRnn29gbKMYDUspPs0SgPb22cHANo/JG9AZF6wWBp3JLgeir36bvff3x9LOvzp2/dbSFA97bk5I4a9VMD7TXOUcP0uJ+d6emu5d6V1QvMs5nj8FZPx37X/b2TFpzShtnafeP0DipJMFnLnN3/w1OQ7tZgP+pA4VVKcHo0TG36KNULKGt5XsHZmi1APS5WM2Vqg0i7vbsG6YcIznN9vRTxXHavgdxtv6Tc3vc1pAHqdaG6ipwKYprpf1sFp6aH0gRTrxxLubPB2avHu+c/l3mICvqnsr//+Cq+qGrK1Xw/wzbBaRkNvSv3yew9cq+cu89L6nu6F/cMzCgzF1ftANlbe+Otp1IkDVxyVfbo6Z481f3507dhvXfbrk3HpdtjKTNqKuio8678c7mzF6ns6arfMyrVNoA75wMfNU2hKSeCx3Fq7dc+SPfDc39H9Vqn2CT//4bsYeT1PecOJyGSJdh6PZOlbElPZz2PHtlD1cUeS4LT4z5IOihwfNaD5ERm9qxH/dZ7Vmt9M999CtCZbdLUP/p3r2zFQ0paG8lr4Eb6+ZWBcSeq/qhyK6bXUfXOSgtO7/tOb9eT1NveqKttpYbiyXu/euV51JV16/T6e86zyF5TUp731V5Sp+Z7M71h9QvFNWWuvr0Sy4LzLfNvrel6zRX1e+hN2VzrnNlfaYD0xhCs++851lDh3vNV95xe6YvHgb8bwbNcuc+f09wbaUj2dzYgjz93//5kh94t0quCM8OKK6glKKuM0EYHfhUZWd8WwenZa0rLsp6s2YY66o0k9WUvS4NManBaGuo1eDIHgUZ1ePdkntsfFaCz5VZJdStsxyt7ziMNXHEAK5yk1mqmhrMPf1fcp57Vqe3SqZTMEduZhqAZyaywFne0DVHngHTZ11bznE88l/1lBZ9meP8851plWkBCO7drmQvWnL/sY/fKtFaqN3iy6iofsQxNktJnTMgfPXJUz3w3VaP5vOQ7Iyszvy2DczSi+aYFET2jINUEqFcAS4+rV480WlwRWXe07dLa0YGvfl9kmbTvPZJ1TXGvn4t4yuRp+2aMgk27wkm63DIztU3vOVfueC8wK4zKWtK0M+nvJXmOdlt65MgFFCva06qsKz044SvjIiN5TjLaaHxhtNyyouXBGZ1WSn66Ivt+M7pRZAWoZsDq+t2emeM1am/WtHxFG9runrO1/n1CxLK7CilxJM/H4bwuTJJBvWtgvm0gcNu01uvpd8la1soLE7xkpYDea4Ot6W3GOSzRc3o/qHw2M9qmXWA+uw+jbd0hyO9Yz0+vJ9QGcO/8ZV2YUqYVPN8dImXp3aJ/w1XTGGYfKZN+P7IXiXqO1uINLzFOm/Pz+BV4C03PNEqpZl//ELXP1ro8nhLyKLPHMyAiXyvh4cMFZ2uyAJXc62gzgJl1nhrSLMEzcLx+5qQnIhgqv6qhTHC2Zmus1tUuowCVDkRU6j0jgiJqhLPSSq2q7wMtMSBkdbcQWjNCq2nMlRrTnajAPP/t+c5Sj3K8VNueQ+pGzaa2MyOb2sZseW2dpL6ZnjMzfeQFt/Fe3XP2WIfGvRY6a569jCJ9TaIlcCS9KQE5p1TP2VrMbwLNDlZEvpE5AkGxh9f2nLO/QOetytIwAnMf6SfS2ns+jaZ6B4i2sWvSvF0HWOAj/aRGNFAaPXbw2rS2Rzr0T/ChshKNM3qd4135BCaqK9VAKy+lAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/4DBC0k0jFtF9wAAAAASUVORK5CYII=";
|
|
|
|
var ba = "3001.0.0";
|
|
|
|
function wt(t) {
|
|
|
|
switch (t) {
|
|
|
|
case "topleft":
|
|
|
|
return new D(-1, -1);
|
|
|
|
case "top":
|
|
|
|
return new D(0, -1);
|
|
|
|
case "topright":
|
|
|
|
return new D(1, -1);
|
|
|
|
case "left":
|
|
|
|
return new D(-1, 0);
|
|
|
|
case "center":
|
|
|
|
return new D(0, 0);
|
|
|
|
case "right":
|
|
|
|
return new D(1, 0);
|
|
|
|
case "botleft":
|
|
|
|
return new D(-1, 1);
|
|
|
|
case "bot":
|
|
|
|
return new D(0, 1);
|
|
|
|
case "botright":
|
|
|
|
return new D(1, 1);
|
|
|
|
default:
|
|
|
|
return t;
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
}
|
|
|
|
s(wt, "anchorPt");
|
|
|
|
function va(t) {
|
|
|
|
switch (t) {
|
|
|
|
case "left":
|
|
|
|
return 0;
|
|
|
|
case "center":
|
|
|
|
return 0.5;
|
|
|
|
case "right":
|
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
return 0;
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
}
|
|
|
|
s(va, "alignPt");
|
|
|
|
function xa(t) {
|
|
|
|
return t.createBuffer(1, 1, 44100);
|
|
|
|
}
|
|
|
|
s(xa, "createEmptyAudioBuffer");
|
|
|
|
var Xe,
|
|
|
|
ya = s((t) => t && t.loadAseprite, "isKaboomCtx"),
|
|
|
|
ne = s((t) => {
|
|
|
|
if (!Xe)
|
|
|
|
throw new Error(
|
|
|
|
"You are trying to access to Kaboom Context before their initialization."
|
|
|
|
);
|
|
|
|
return ya(t) ? t : Xe;
|
|
|
|
}, "getKaboomContext"),
|
|
|
|
fe = s((t) => t._k, "getInternalContext"),
|
|
|
|
wa = s((t = {}) => {
|
|
|
|
let e = t.root ?? document.body;
|
|
|
|
e === document.body &&
|
|
|
|
((document.body.style.width = "100%"),
|
|
|
|
(document.body.style.height = "100%"),
|
|
|
|
(document.body.style.margin = "0px"),
|
|
|
|
(document.documentElement.style.width = "100%"),
|
|
|
|
(document.documentElement.style.height = "100%"));
|
|
|
|
let n = t.canvas ?? e.appendChild(document.createElement("canvas")),
|
|
|
|
o = t.scale ?? 1,
|
|
|
|
a = t.width && t.height && !t.stretch && !t.letterbox;
|
|
|
|
a
|
|
|
|
? ((n.width = t.width * o), (n.height = t.height * o))
|
|
|
|
: ((n.width = n.parentElement.offsetWidth),
|
|
|
|
(n.height = n.parentElement.offsetHeight));
|
|
|
|
let u = ["outline: none", "cursor: default"];
|
|
|
|
if (a) {
|
|
|
|
let r = n.width,
|
|
|
|
i = n.height;
|
|
|
|
u.push(`width: ${r}px`), u.push(`height: ${i}px`);
|
|
|
|
} else u.push("width: 100%"), u.push("height: 100%");
|
|
|
|
t.crisp &&
|
|
|
|
(u.push("image-rendering: pixelated"),
|
|
|
|
u.push("image-rendering: crisp-edges")),
|
|
|
|
(n.style.cssText = u.join(";"));
|
|
|
|
let l = t.pixelDensity || window.devicePixelRatio;
|
|
|
|
(n.width *= l), (n.height *= l), (n.tabIndex = 0);
|
|
|
|
let f = document.createElement("canvas");
|
|
|
|
(f.width = 256), (f.height = 256);
|
|
|
|
let v = f.getContext("2d", { willReadFrequently: !0 }),
|
|
|
|
m = Eo({
|
|
|
|
canvas: n,
|
|
|
|
touchToMouse: t.touchToMouse,
|
|
|
|
gamepads: t.gamepads,
|
|
|
|
pixelDensity: t.pixelDensity,
|
|
|
|
maxFPS: t.maxFPS,
|
|
|
|
}),
|
|
|
|
P = [],
|
|
|
|
b = m.canvas.getContext("webgl", {
|
|
|
|
antialias: !0,
|
|
|
|
depth: !0,
|
|
|
|
stencil: !0,
|
|
|
|
alpha: !0,
|
|
|
|
preserveDrawingBuffer: !0,
|
|
|
|
}),
|
|
|
|
M = fr(b, { texFilter: t.texFilter }),
|
|
|
|
w = (() => {
|
|
|
|
let r = Dt(bn, vn),
|
|
|
|
i = qe.fromImage(
|
|
|
|
M,
|
|
|
|
new ImageData(new Uint8ClampedArray([255, 255, 255, 255]), 1, 1)
|
|
|
|
),
|
|
|
|
c =
|
|
|
|
t.width && t.height
|
|
|
|
? new yt(M, t.width * l * o, t.height * l * o)
|
|
|
|
: new yt(M, b.drawingBufferWidth, b.drawingBufferHeight),
|
|
|
|
d = null,
|
|
|
|
h = 1;
|
|
|
|
t.background &&
|
|
|
|
((d = ce(t.background)),
|
|
|
|
(h = Array.isArray(t.background) ? t.background[3] : 1),
|
|
|
|
b.clearColor(d.r / 255, d.g / 255, d.b / 255, h ?? 1)),
|
|
|
|
b.enable(b.BLEND),
|
|
|
|
b.blendFuncSeparate(
|
|
|
|
b.SRC_ALPHA,
|
|
|
|
b.ONE_MINUS_SRC_ALPHA,
|
|
|
|
b.ONE,
|
|
|
|
b.ONE_MINUS_SRC_ALPHA
|
2024-06-02 05:39:23 +00:00
|
|
|
);
|
2024-06-17 22:57:39 +00:00
|
|
|
let y = new pn(M, gn, Ro, Uo),
|
|
|
|
x = qe.fromImage(
|
|
|
|
M,
|
|
|
|
new ImageData(
|
|
|
|
new Uint8ClampedArray([
|
|
|
|
128, 128, 128, 255, 190, 190, 190, 255, 190, 190, 190, 255, 128,
|
|
|
|
128, 128, 255,
|
|
|
|
]),
|
|
|
|
2,
|
|
|
|
2
|
|
|
|
),
|
|
|
|
{ wrap: "repeat", filter: "nearest" }
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
2024-06-17 22:57:39 +00:00
|
|
|
return {
|
|
|
|
lastDrawCalls: 0,
|
|
|
|
defShader: r,
|
|
|
|
defTex: i,
|
|
|
|
frameBuffer: c,
|
|
|
|
postShader: null,
|
|
|
|
postShaderUniform: null,
|
|
|
|
renderer: y,
|
|
|
|
transform: new De(),
|
|
|
|
transformStack: [],
|
|
|
|
bgTex: x,
|
|
|
|
bgColor: d,
|
|
|
|
bgAlpha: h,
|
|
|
|
width: t.width ?? b.drawingBufferWidth / l / o,
|
|
|
|
height: t.height ?? b.drawingBufferHeight / l / o,
|
|
|
|
viewport: {
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
width: b.drawingBufferWidth,
|
|
|
|
height: b.drawingBufferHeight,
|
|
|
|
},
|
|
|
|
fixed: !1,
|
2024-06-02 05:39:23 +00:00
|
|
|
};
|
2024-06-17 22:57:39 +00:00
|
|
|
})();
|
|
|
|
class _ {
|
|
|
|
static {
|
|
|
|
s(this, "SpriteData");
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
tex;
|
|
|
|
frames = [new he(0, 0, 1, 1)];
|
|
|
|
anims = {};
|
|
|
|
slice9 = null;
|
|
|
|
constructor(i, c, d = {}, h = null) {
|
|
|
|
(this.tex = i),
|
|
|
|
c && (this.frames = c),
|
|
|
|
(this.anims = d),
|
|
|
|
(this.slice9 = h);
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
get width() {
|
|
|
|
return this.tex.width * this.frames[0].w;
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
get height() {
|
|
|
|
return this.tex.height * this.frames[0].h;
|
|
|
|
}
|
|
|
|
static from(i, c = {}) {
|
|
|
|
return typeof i == "string"
|
|
|
|
? _.fromURL(i, c)
|
|
|
|
: Promise.resolve(_.fromImage(i, c));
|
|
|
|
}
|
|
|
|
static fromImage(i, c = {}) {
|
|
|
|
let [d, h] = L.packer.add(i),
|
|
|
|
y = c.frames
|
|
|
|
? c.frames.map(
|
|
|
|
(x) =>
|
|
|
|
new he(h.x + x.x * h.w, h.y + x.y * h.h, x.w * h.w, x.h * h.h)
|
|
|
|
)
|
|
|
|
: ve(c.sliceX || 1, c.sliceY || 1, h.x, h.y, h.w, h.h);
|
|
|
|
return new _(d, y, c.anims, c.slice9);
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
static fromURL(i, c = {}) {
|
|
|
|
return Kt(i).then((d) => _.fromImage(d, c));
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
}
|
|
|
|
class $ {
|
|
|
|
static {
|
|
|
|
s(this, "SoundData");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
buf;
|
|
|
|
constructor(i) {
|
|
|
|
this.buf = i;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
static fromArrayBuffer(i) {
|
|
|
|
return new Promise((c, d) => X.ctx.decodeAudioData(i, c, d)).then(
|
|
|
|
(c) => new $(c)
|
2024-06-02 05:39:23 +00:00
|
|
|
);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
static fromURL(i) {
|
|
|
|
return lr(i)
|
|
|
|
? $.fromArrayBuffer(bo(i))
|
|
|
|
: Oo(i).then((c) => $.fromArrayBuffer(c));
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
}
|
|
|
|
let X = (() => {
|
|
|
|
let r = new (window.AudioContext || window.webkitAudioContext)(),
|
|
|
|
i = r.createGain();
|
|
|
|
i.connect(r.destination);
|
|
|
|
let c = new $(xa(r));
|
2024-06-02 05:39:23 +00:00
|
|
|
return (
|
2024-06-17 22:57:39 +00:00
|
|
|
r
|
|
|
|
.decodeAudioData(fs.buffer.slice(0))
|
|
|
|
.then((d) => {
|
|
|
|
c.buf = d;
|
|
|
|
})
|
|
|
|
.catch((d) => {
|
|
|
|
console.error("Failed to load burp: ", d);
|
|
|
|
}),
|
|
|
|
{ ctx: r, masterNode: i, burpSnd: c }
|
2024-06-02 05:39:23 +00:00
|
|
|
);
|
2024-06-17 22:57:39 +00:00
|
|
|
})(),
|
|
|
|
L = {
|
|
|
|
urlPrefix: "",
|
|
|
|
sprites: new rt(),
|
|
|
|
fonts: new rt(),
|
|
|
|
bitmapFonts: new rt(),
|
|
|
|
sounds: new rt(),
|
|
|
|
shaders: new rt(),
|
|
|
|
custom: new rt(),
|
|
|
|
music: {},
|
|
|
|
packer: new zt(M, 2048, 2048),
|
|
|
|
loaded: !1,
|
|
|
|
};
|
|
|
|
function Q(r) {
|
|
|
|
return typeof r != "string" || lr(r) ? r : L.urlPrefix + r;
|
|
|
|
}
|
|
|
|
s(Q, "fixURL");
|
|
|
|
let O = {
|
|
|
|
events: new nt(),
|
|
|
|
objEvents: new nt(),
|
|
|
|
root: kn([]),
|
|
|
|
gravity: null,
|
|
|
|
scenes: {},
|
|
|
|
currentScene: null,
|
|
|
|
layers: null,
|
|
|
|
defaultLayerIndex: 0,
|
|
|
|
logs: [],
|
|
|
|
cam: {
|
|
|
|
pos: null,
|
|
|
|
scale: new D(1),
|
|
|
|
angle: 0,
|
|
|
|
shake: 0,
|
|
|
|
transform: new De(),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
O.root.use(Cn());
|
|
|
|
function oe(r) {
|
|
|
|
return L.custom.add(null, r);
|
|
|
|
}
|
|
|
|
s(oe, "load");
|
|
|
|
function H() {
|
|
|
|
let r = [
|
|
|
|
L.sprites,
|
|
|
|
L.sounds,
|
|
|
|
L.shaders,
|
|
|
|
L.fonts,
|
|
|
|
L.bitmapFonts,
|
|
|
|
L.custom,
|
|
|
|
];
|
|
|
|
return r.reduce((i, c) => i + c.progress(), 0) / r.length;
|
|
|
|
}
|
|
|
|
s(H, "loadProgress");
|
|
|
|
function ie(r) {
|
|
|
|
return r !== void 0 && (L.urlPrefix = r), L.urlPrefix;
|
|
|
|
}
|
|
|
|
s(ie, "loadRoot");
|
|
|
|
function se(r, i) {
|
|
|
|
return L.custom.add(r, Ht(i));
|
|
|
|
}
|
|
|
|
s(se, "loadJSON");
|
|
|
|
class ae {
|
|
|
|
static {
|
|
|
|
s(this, "FontData");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
fontface;
|
|
|
|
filter = fn;
|
|
|
|
outline = null;
|
|
|
|
size = 64;
|
|
|
|
constructor(i, c = {}) {
|
|
|
|
if (
|
|
|
|
((this.fontface = i),
|
|
|
|
(this.filter = c.filter ?? fn),
|
|
|
|
(this.size = c.size ?? 64),
|
|
|
|
this.size > 256)
|
|
|
|
)
|
|
|
|
throw new Error(`Max font size: ${256}`);
|
|
|
|
c.outline &&
|
|
|
|
((this.outline = { width: 1, color: ce(0, 0, 0) }),
|
|
|
|
typeof c.outline == "number"
|
|
|
|
? (this.outline.width = c.outline)
|
|
|
|
: typeof c.outline == "object" &&
|
|
|
|
(c.outline.width && (this.outline.width = c.outline.width),
|
|
|
|
c.outline.color && (this.outline.color = c.outline.color)));
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
}
|
|
|
|
function pe(r, i, c = {}) {
|
|
|
|
let d = new FontFace(r, typeof i == "string" ? `url(${i})` : i);
|
|
|
|
return (
|
|
|
|
document.fonts.add(d),
|
|
|
|
L.fonts.add(
|
|
|
|
r,
|
|
|
|
d
|
|
|
|
.load()
|
|
|
|
.catch((h) => {
|
|
|
|
throw new Error(`Failed to load font from "${i}": ${h}`);
|
2024-06-02 05:39:23 +00:00
|
|
|
})
|
2024-06-17 22:57:39 +00:00
|
|
|
.then((h) => new ae(h, c))
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(pe, "loadFont");
|
|
|
|
function Ce(r, i, c, d, h = {}) {
|
|
|
|
return L.bitmapFonts.add(
|
|
|
|
r,
|
|
|
|
Kt(i).then((y) => Dn(qe.fromImage(M, y, h), c, d, h.chars ?? br))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(Ce, "loadBitmapFont");
|
|
|
|
function ve(r = 1, i = 1, c = 0, d = 0, h = 1, y = 1) {
|
|
|
|
let x = [],
|
|
|
|
A = h / r,
|
|
|
|
E = y / i;
|
|
|
|
for (let g = 0; g < i; g++)
|
|
|
|
for (let C = 0; C < r; C++) x.push(new he(c + C * A, d + g * E, A, E));
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
s(ve, "slice");
|
|
|
|
function Ie(r, i) {
|
|
|
|
return (
|
|
|
|
(r = Q(r)),
|
|
|
|
oe(
|
|
|
|
typeof i == "string"
|
|
|
|
? new Promise((c, d) => {
|
|
|
|
Ht(i).then((h) => {
|
|
|
|
Ie(r, h).then(c).catch(d);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
: _.from(r).then((c) => {
|
|
|
|
let d = {};
|
|
|
|
for (let h in i) {
|
|
|
|
let y = i[h],
|
|
|
|
x = c.frames[0],
|
|
|
|
A = 2048 * x.w,
|
|
|
|
E = 2048 * x.h,
|
|
|
|
g = y.frames
|
|
|
|
? y.frames.map(
|
|
|
|
(N) =>
|
|
|
|
new he(
|
|
|
|
x.x + ((y.x + N.x) / A) * x.w,
|
|
|
|
x.y + ((y.y + N.y) / E) * x.h,
|
|
|
|
(N.w / A) * x.w,
|
|
|
|
(N.h / E) * x.h
|
|
|
|
)
|
|
|
|
)
|
|
|
|
: ve(
|
|
|
|
y.sliceX || 1,
|
|
|
|
y.sliceY || 1,
|
|
|
|
x.x + (y.x / A) * x.w,
|
|
|
|
x.y + (y.y / E) * x.h,
|
|
|
|
(y.width / A) * x.w,
|
|
|
|
(y.height / E) * x.h
|
|
|
|
),
|
|
|
|
C = new _(c.tex, g, y.anims);
|
|
|
|
L.sprites.addLoaded(h, C), (d[h] = C);
|
|
|
|
}
|
|
|
|
return d;
|
|
|
|
})
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(Ie, "loadSpriteAtlas");
|
|
|
|
function Le(r, i = {}) {
|
|
|
|
let c = document.createElement("canvas"),
|
|
|
|
d = r[0].width,
|
|
|
|
h = r[0].height;
|
|
|
|
(c.width = d * r.length), (c.height = h);
|
|
|
|
let y = c.getContext("2d");
|
|
|
|
r.forEach((A, E) => {
|
|
|
|
A instanceof ImageData
|
|
|
|
? y.putImageData(A, E * d, 0)
|
|
|
|
: y.drawImage(A, E * d, 0);
|
|
|
|
});
|
|
|
|
let x = y.getImageData(0, 0, r.length * d, h);
|
|
|
|
return _.fromImage(x, { ...i, sliceX: r.length, sliceY: 1 });
|
|
|
|
}
|
|
|
|
s(Le, "createSpriteSheet");
|
|
|
|
function Te(r, i, c = { sliceX: 1, sliceY: 1, anims: {} }) {
|
|
|
|
return (
|
|
|
|
(i = Q(i)),
|
|
|
|
Array.isArray(i)
|
|
|
|
? i.some((d) => typeof d == "string")
|
|
|
|
? L.sprites.add(
|
|
|
|
r,
|
|
|
|
Promise.all(
|
|
|
|
i.map((d) =>
|
|
|
|
typeof d == "string" ? Kt(d) : Promise.resolve(d)
|
2024-06-02 05:39:23 +00:00
|
|
|
)
|
2024-06-17 22:57:39 +00:00
|
|
|
).then((d) => Le(d, c))
|
|
|
|
)
|
|
|
|
: L.sprites.addLoaded(r, Le(i, c))
|
|
|
|
: typeof i == "string"
|
|
|
|
? L.sprites.add(r, _.from(i, c))
|
|
|
|
: L.sprites.addLoaded(r, _.fromImage(i, c))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(Te, "loadSprite");
|
|
|
|
function Ne(r, i) {
|
|
|
|
return (
|
|
|
|
(i = Q(i)),
|
|
|
|
L.sprites.add(
|
|
|
|
r,
|
|
|
|
new Promise(async (c) => {
|
|
|
|
let d = typeof i == "string" ? await Ht(i) : i,
|
|
|
|
h = await Promise.all(d.frames.map(Kt)),
|
|
|
|
y = document.createElement("canvas");
|
|
|
|
(y.width = d.width), (y.height = d.height * d.frames.length);
|
|
|
|
let x = y.getContext("2d");
|
|
|
|
h.forEach((E, g) => {
|
|
|
|
x.drawImage(E, 0, g * d.height);
|
|
|
|
});
|
|
|
|
let A = await Te(null, y, {
|
|
|
|
sliceY: d.frames.length,
|
|
|
|
anims: d.anims,
|
|
|
|
});
|
|
|
|
c(A);
|
2024-06-02 05:39:23 +00:00
|
|
|
})
|
2024-06-17 22:57:39 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(Ne, "loadPedit");
|
|
|
|
function _e(r, i, c) {
|
|
|
|
(i = Q(i)),
|
|
|
|
(c = Q(c)),
|
|
|
|
typeof i == "string" && !c && (c = xo(i) + ".json");
|
|
|
|
let d = typeof c == "string" ? Ht(c) : Promise.resolve(c);
|
|
|
|
return L.sprites.add(
|
|
|
|
r,
|
|
|
|
d.then((h) => {
|
|
|
|
let y = h.meta.size,
|
|
|
|
x = h.frames.map(
|
|
|
|
(E) =>
|
|
|
|
new he(
|
|
|
|
E.frame.x / y.w,
|
|
|
|
E.frame.y / y.h,
|
|
|
|
E.frame.w / y.w,
|
|
|
|
E.frame.h / y.h
|
|
|
|
)
|
|
|
|
),
|
|
|
|
A = {};
|
|
|
|
for (let E of h.meta.frameTags)
|
|
|
|
E.from === E.to
|
|
|
|
? (A[E.name] = E.from)
|
|
|
|
: (A[E.name] = {
|
|
|
|
from: E.from,
|
|
|
|
to: E.to,
|
|
|
|
speed: 10,
|
|
|
|
loop: !0,
|
|
|
|
pingpong: E.direction === "pingpong",
|
|
|
|
});
|
|
|
|
return _.from(i, { frames: x, anims: A });
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(_e, "loadAseprite");
|
|
|
|
function He(r, i, c) {
|
|
|
|
return L.shaders.addLoaded(r, Dt(i, c));
|
|
|
|
}
|
|
|
|
s(He, "loadShader");
|
|
|
|
function dt(r, i, c) {
|
|
|
|
(i = Q(i)), (c = Q(c));
|
|
|
|
let d = s((y) => (y ? So(y) : Promise.resolve(null)), "resolveUrl"),
|
|
|
|
h = Promise.all([d(i), d(c)]).then(([y, x]) => Dt(y, x));
|
|
|
|
return L.shaders.add(r, h);
|
|
|
|
}
|
|
|
|
s(dt, "loadShaderURL");
|
|
|
|
function Ee(r, i) {
|
|
|
|
return (
|
|
|
|
(i = Q(i)),
|
|
|
|
L.sounds.add(
|
|
|
|
r,
|
|
|
|
typeof i == "string" ? $.fromURL(i) : $.fromArrayBuffer(i)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(Ee, "loadSound");
|
|
|
|
function Re(r, i) {
|
|
|
|
let c = new Audio(i);
|
|
|
|
return (c.preload = "auto"), (L.music[r] = Q(i));
|
|
|
|
}
|
|
|
|
s(Re, "loadMusic");
|
|
|
|
function ze(r = "bean") {
|
|
|
|
return Te(r, hs);
|
|
|
|
}
|
|
|
|
s(ze, "loadBean");
|
|
|
|
function ot(r) {
|
|
|
|
return L.sprites.get(r);
|
|
|
|
}
|
|
|
|
s(ot, "getSprite");
|
|
|
|
function st(r) {
|
|
|
|
return L.sounds.get(r);
|
|
|
|
}
|
|
|
|
s(st, "getSound");
|
|
|
|
function Ct(r) {
|
|
|
|
return L.fonts.get(r);
|
|
|
|
}
|
|
|
|
s(Ct, "getFont");
|
|
|
|
function Xt(r) {
|
|
|
|
return L.bitmapFonts.get(r);
|
|
|
|
}
|
|
|
|
s(Xt, "getBitmapFont");
|
|
|
|
function $t(r) {
|
|
|
|
return L.shaders.get(r);
|
|
|
|
}
|
|
|
|
s($t, "getShader");
|
|
|
|
function An(r) {
|
|
|
|
return L.custom.get(r);
|
|
|
|
}
|
|
|
|
s(An, "getAsset");
|
|
|
|
function Qt(r) {
|
|
|
|
if (typeof r == "string") {
|
|
|
|
let i = ot(r);
|
|
|
|
if (i) return i;
|
|
|
|
if (H() < 1) return null;
|
|
|
|
throw new Error(`Sprite not found: ${r}`);
|
|
|
|
} else {
|
|
|
|
if (r instanceof _) return Ve.loaded(r);
|
|
|
|
if (r instanceof Ve) return r;
|
|
|
|
throw new Error(`Invalid sprite: ${r}`);
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
}
|
|
|
|
s(Qt, "resolveSprite");
|
|
|
|
function Vn(r) {
|
|
|
|
if (typeof r == "string") {
|
|
|
|
let i = st(r);
|
|
|
|
if (i) return i;
|
|
|
|
if (H() < 1) return null;
|
|
|
|
throw new Error(`Sound not found: ${r}`);
|
|
|
|
} else {
|
|
|
|
if (r instanceof $) return Ve.loaded(r);
|
|
|
|
if (r instanceof Ve) return r;
|
|
|
|
throw new Error(`Invalid sound: ${r}`);
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
}
|
|
|
|
s(Vn, "resolveSound");
|
|
|
|
function Rn(r) {
|
|
|
|
if (!r) return w.defShader;
|
|
|
|
if (typeof r == "string") {
|
|
|
|
let i = $t(r);
|
|
|
|
if (i) return i.data ?? i;
|
|
|
|
if (H() < 1) return null;
|
|
|
|
throw new Error(`Shader not found: ${r}`);
|
|
|
|
} else if (r instanceof Ve) return r.data ? r.data : r;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
s(Rn, "resolveShader");
|
|
|
|
function Jt(r) {
|
|
|
|
if (!r) return Jt(t.font ?? Ao);
|
|
|
|
if (typeof r == "string") {
|
|
|
|
let i = Xt(r),
|
|
|
|
c = Ct(r);
|
|
|
|
if (i) return i.data ?? i;
|
|
|
|
if (c) return c.data ?? c;
|
|
|
|
if (document.fonts.check(`${64}px ${r}`)) return r;
|
|
|
|
if (H() < 1) return null;
|
|
|
|
throw new Error(`Font not found: ${r}`);
|
|
|
|
} else if (r instanceof Ve) return r.data ? r.data : r;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
s(Jt, "resolveFont");
|
|
|
|
function Un(r) {
|
|
|
|
return (
|
|
|
|
r !== void 0 && (X.masterNode.gain.value = r), X.masterNode.gain.value
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(Un, "volume");
|
|
|
|
function Pn(r, i = {}) {
|
|
|
|
let c = new we(),
|
|
|
|
d = new Audio(r);
|
|
|
|
X.ctx.createMediaElementSource(d).connect(X.masterNode);
|
|
|
|
function y() {
|
|
|
|
de.paused || (m.isHidden() && !t.backgroundAudio) || X.ctx.resume();
|
|
|
|
}
|
|
|
|
s(y, "resumeAudioCtx");
|
|
|
|
function x() {
|
|
|
|
y(), d.play();
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
return (
|
|
|
|
s(x, "play"),
|
|
|
|
i.paused || x(),
|
|
|
|
(d.onended = () => c.trigger()),
|
|
|
|
{
|
|
|
|
play() {
|
|
|
|
x();
|
2024-06-02 05:39:23 +00:00
|
|
|
},
|
2024-06-17 22:57:39 +00:00
|
|
|
seek(A) {
|
|
|
|
d.currentTime = A;
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-17 22:57:39 +00:00
|
|
|
stop() {
|
|
|
|
d.pause(), this.seek(0);
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-17 22:57:39 +00:00
|
|
|
set loop(A) {
|
|
|
|
d.loop = A;
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-17 22:57:39 +00:00
|
|
|
get loop() {
|
|
|
|
return d.loop;
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-17 22:57:39 +00:00
|
|
|
set paused(A) {
|
|
|
|
A ? d.pause() : x();
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-17 22:57:39 +00:00
|
|
|
get paused() {
|
|
|
|
return d.paused;
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-17 22:57:39 +00:00
|
|
|
time() {
|
|
|
|
return d.currentTime;
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-17 22:57:39 +00:00
|
|
|
duration() {
|
|
|
|
return d.duration;
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-17 22:57:39 +00:00
|
|
|
set volume(A) {
|
|
|
|
d.volume = Qe(A, 0, 1);
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
get volume() {
|
2024-06-17 22:57:39 +00:00
|
|
|
return d.volume;
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-17 22:57:39 +00:00
|
|
|
set speed(A) {
|
|
|
|
d.playbackRate = Math.max(A, 0);
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-17 22:57:39 +00:00
|
|
|
get speed() {
|
|
|
|
return d.playbackRate;
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-17 22:57:39 +00:00
|
|
|
set detune(A) {},
|
|
|
|
get detune() {
|
|
|
|
return 0;
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-17 22:57:39 +00:00
|
|
|
onEnd(A) {
|
|
|
|
return c.add(A);
|
|
|
|
},
|
|
|
|
then(A) {
|
|
|
|
return this.onEnd(A);
|
2024-06-02 05:39:23 +00:00
|
|
|
},
|
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
s(Pn, "playMusic");
|
|
|
|
function Zt(r, i = {}) {
|
|
|
|
if (typeof r == "string" && L.music[r]) return Pn(L.music[r], i);
|
|
|
|
let c = X.ctx,
|
|
|
|
d = i.paused ?? !1,
|
|
|
|
h = c.createBufferSource(),
|
|
|
|
y = new we(),
|
|
|
|
x = c.createGain(),
|
|
|
|
A = i.seek ?? 0,
|
|
|
|
E = 0,
|
|
|
|
g = 0,
|
|
|
|
C = !1;
|
|
|
|
(h.loop = !!i.loop),
|
|
|
|
(h.detune.value = i.detune ?? 0),
|
|
|
|
(h.playbackRate.value = i.speed ?? 1),
|
|
|
|
h.connect(x),
|
|
|
|
(h.onended = () => {
|
|
|
|
F() >= (h.buffer?.duration ?? Number.POSITIVE_INFINITY) &&
|
|
|
|
y.trigger();
|
|
|
|
}),
|
|
|
|
x.connect(X.masterNode),
|
|
|
|
(x.gain.value = i.volume ?? 1);
|
|
|
|
let N = s((B) => {
|
|
|
|
(h.buffer = B.buf),
|
|
|
|
d || ((E = c.currentTime), h.start(0, A), (C = !0));
|
|
|
|
}, "start"),
|
|
|
|
G = Vn(r);
|
|
|
|
G instanceof Ve && G.onLoad(N);
|
|
|
|
let F = s(() => {
|
|
|
|
if (!h.buffer) return 0;
|
|
|
|
let B = d ? g - E : c.currentTime - E,
|
|
|
|
R = h.buffer.duration;
|
|
|
|
return h.loop ? B % R : Math.min(B, R);
|
|
|
|
}, "getTime"),
|
|
|
|
S = s((B) => {
|
|
|
|
let R = c.createBufferSource();
|
|
|
|
return (
|
|
|
|
(R.buffer = B.buffer),
|
|
|
|
(R.loop = B.loop),
|
|
|
|
(R.playbackRate.value = B.playbackRate.value),
|
|
|
|
(R.detune.value = B.detune.value),
|
|
|
|
(R.onended = B.onended),
|
|
|
|
R.connect(x),
|
|
|
|
R
|
|
|
|
);
|
|
|
|
}, "cloneNode");
|
|
|
|
return {
|
|
|
|
stop() {
|
|
|
|
(this.paused = !0), this.seek(0);
|
|
|
|
},
|
|
|
|
set paused(B) {
|
|
|
|
if (d !== B)
|
|
|
|
if (((d = B), B)) C && (h.stop(), (C = !1)), (g = c.currentTime);
|
|
|
|
else {
|
|
|
|
h = S(h);
|
|
|
|
let R = g - E;
|
|
|
|
h.start(0, R), (C = !0), (E = c.currentTime - R), (g = 0);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
get paused() {
|
|
|
|
return d;
|
|
|
|
},
|
|
|
|
play(B = 0) {
|
|
|
|
this.seek(B), (this.paused = !1);
|
|
|
|
},
|
|
|
|
seek(B) {
|
|
|
|
h.buffer?.duration &&
|
|
|
|
(B > h.buffer.duration ||
|
|
|
|
(d
|
|
|
|
? ((h = S(h)), (E = g - B))
|
|
|
|
: (h.stop(),
|
|
|
|
(h = S(h)),
|
|
|
|
(E = c.currentTime - B),
|
|
|
|
h.start(0, B),
|
|
|
|
(C = !0),
|
|
|
|
(g = 0))));
|
|
|
|
},
|
|
|
|
set speed(B) {
|
|
|
|
h.playbackRate.value = B;
|
|
|
|
},
|
|
|
|
get speed() {
|
|
|
|
return h.playbackRate.value;
|
|
|
|
},
|
|
|
|
set detune(B) {
|
|
|
|
h.detune.value = B;
|
|
|
|
},
|
|
|
|
get detune() {
|
|
|
|
return h.detune.value;
|
|
|
|
},
|
|
|
|
set volume(B) {
|
|
|
|
x.gain.value = Math.max(B, 0);
|
|
|
|
},
|
|
|
|
get volume() {
|
|
|
|
return x.gain.value;
|
|
|
|
},
|
|
|
|
set loop(B) {
|
|
|
|
h.loop = B;
|
|
|
|
},
|
|
|
|
get loop() {
|
|
|
|
return h.loop;
|
|
|
|
},
|
|
|
|
duration() {
|
|
|
|
return h.buffer?.duration ?? 0;
|
|
|
|
},
|
|
|
|
time() {
|
|
|
|
return F() % this.duration();
|
|
|
|
},
|
|
|
|
onEnd(B) {
|
|
|
|
return y.add(B);
|
|
|
|
},
|
|
|
|
then(B) {
|
|
|
|
return this.onEnd(B);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(Zt, "play");
|
|
|
|
function en(r) {
|
|
|
|
return Zt(X.burpSnd, r);
|
|
|
|
}
|
|
|
|
s(en, "burp");
|
|
|
|
function Mn(r, i) {
|
|
|
|
let c = new yt(M, r, i);
|
|
|
|
return {
|
|
|
|
clear: () => c.clear(),
|
|
|
|
free: () => c.free(),
|
|
|
|
toDataURL: () => c.toDataURL(),
|
|
|
|
toImageData: () => c.toImageData(),
|
|
|
|
width: c.width,
|
|
|
|
height: c.height,
|
|
|
|
draw: (d) => {
|
|
|
|
Se(), c.bind(), d(), Se(), c.unbind();
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(Mn, "makeCanvas");
|
|
|
|
function Dt(r = bn, i = vn) {
|
|
|
|
let c = Po.replace("{{user}}", r ?? bn),
|
|
|
|
d = Mo.replace("{{user}}", i ?? vn);
|
|
|
|
try {
|
|
|
|
return new hn(
|
|
|
|
M,
|
|
|
|
c,
|
|
|
|
d,
|
|
|
|
gn.map((h) => h.name)
|
|
|
|
);
|
|
|
|
} catch (h) {
|
|
|
|
let x = /(?<type>^\w+) SHADER ERROR: 0:(?<line>\d+): (?<msg>.+)/,
|
|
|
|
A = wo(h).match(x),
|
|
|
|
E = Number(A.groups.line) - 14,
|
|
|
|
g = A.groups.msg.trim(),
|
|
|
|
C = A.groups.type.toLowerCase();
|
|
|
|
throw new Error(`${C} shader line ${E}: ${g}`);
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
}
|
|
|
|
s(Dt, "makeShader");
|
|
|
|
function Dn(r, i, c, d) {
|
|
|
|
let h = r.width / i,
|
|
|
|
y = {},
|
|
|
|
x = d.split("").entries();
|
|
|
|
for (let [A, E] of x)
|
|
|
|
y[E] = new he((A % h) * i, Math.floor(A / h) * c, i, c);
|
|
|
|
return { tex: r, map: y, size: c };
|
|
|
|
}
|
|
|
|
s(Dn, "makeFont");
|
|
|
|
function it(r, i, c, d = w.defTex, h = w.defShader, y = {}) {
|
|
|
|
let x = Rn(h);
|
|
|
|
if (!x || x instanceof Ve) return;
|
|
|
|
let A = w.fixed || c ? w.transform : O.cam.transform.mult(w.transform),
|
|
|
|
E = [];
|
|
|
|
for (let g of r) {
|
|
|
|
let C = Bn(A.multVec2(g.pos));
|
|
|
|
E.push(
|
|
|
|
C.x,
|
|
|
|
C.y,
|
|
|
|
g.uv.x,
|
|
|
|
g.uv.y,
|
|
|
|
g.color.r / 255,
|
|
|
|
g.color.g / 255,
|
|
|
|
g.color.b / 255,
|
|
|
|
g.opacity
|
|
|
|
);
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
w.renderer.push(b.TRIANGLES, E, i, x, d, y);
|
|
|
|
}
|
|
|
|
s(it, "drawRaw");
|
|
|
|
function Se() {
|
|
|
|
w.renderer.flush();
|
|
|
|
}
|
|
|
|
s(Se, "flush");
|
|
|
|
function Gt() {
|
|
|
|
b.clear(b.COLOR_BUFFER_BIT),
|
|
|
|
w.frameBuffer.bind(),
|
|
|
|
b.clear(b.COLOR_BUFFER_BIT),
|
|
|
|
w.bgColor ||
|
|
|
|
ct(() => {
|
|
|
|
ht({
|
|
|
|
width: Pe(),
|
|
|
|
height: ke(),
|
|
|
|
quad: new he(0, 0, Pe() / 64, ke() / 64),
|
|
|
|
tex: w.bgTex,
|
|
|
|
fixed: !0,
|
|
|
|
});
|
2024-06-02 05:39:23 +00:00
|
|
|
}),
|
2024-06-17 22:57:39 +00:00
|
|
|
(w.renderer.numDraws = 0),
|
|
|
|
(w.fixed = !1),
|
|
|
|
(w.transformStack.length = 0),
|
|
|
|
(w.transform = new De());
|
|
|
|
}
|
|
|
|
s(Gt, "frameStart");
|
|
|
|
function Gn(r, i) {
|
|
|
|
(w.postShader = r), (w.postShaderUniform = i ?? null);
|
|
|
|
}
|
|
|
|
s(Gn, "usePostEffect");
|
|
|
|
function Tt() {
|
|
|
|
Se(),
|
|
|
|
(w.lastDrawCalls = w.renderer.numDraws),
|
|
|
|
w.frameBuffer.unbind(),
|
|
|
|
b.viewport(0, 0, b.drawingBufferWidth, b.drawingBufferHeight);
|
|
|
|
let r = w.width,
|
|
|
|
i = w.height;
|
|
|
|
(w.width = b.drawingBufferWidth / l),
|
|
|
|
(w.height = b.drawingBufferHeight / l),
|
|
|
|
Et({
|
|
|
|
flipY: !0,
|
|
|
|
tex: w.frameBuffer.tex,
|
|
|
|
pos: new D(w.viewport.x, w.viewport.y),
|
|
|
|
width: w.viewport.width,
|
|
|
|
height: w.viewport.height,
|
|
|
|
shader: w.postShader,
|
|
|
|
uniform:
|
|
|
|
typeof w.postShaderUniform == "function"
|
|
|
|
? w.postShaderUniform()
|
|
|
|
: w.postShaderUniform,
|
|
|
|
fixed: !0,
|
|
|
|
}),
|
|
|
|
Se(),
|
|
|
|
(w.width = r),
|
|
|
|
(w.height = i);
|
|
|
|
}
|
|
|
|
s(Tt, "frameEnd");
|
|
|
|
function Bn(r) {
|
|
|
|
return new D((r.x / Pe()) * 2 - 1, (-r.y / ke()) * 2 + 1);
|
|
|
|
}
|
|
|
|
s(Bn, "screen2ndc");
|
|
|
|
function Fn(r) {
|
|
|
|
w.transform = r.clone();
|
|
|
|
}
|
|
|
|
s(Fn, "pushMatrix");
|
|
|
|
function te(...r) {
|
|
|
|
if (r[0] === void 0) return;
|
|
|
|
let i = T(...r);
|
|
|
|
(i.x === 0 && i.y === 0) || w.transform.translate(i);
|
|
|
|
}
|
|
|
|
s(te, "pushTranslate");
|
|
|
|
function We(...r) {
|
|
|
|
if (r[0] === void 0) return;
|
|
|
|
let i = T(...r);
|
|
|
|
(i.x === 1 && i.y === 1) || w.transform.scale(i);
|
|
|
|
}
|
|
|
|
s(We, "pushScale");
|
|
|
|
function je(r) {
|
|
|
|
r && w.transform.rotate(r);
|
|
|
|
}
|
|
|
|
s(je, "pushRotate");
|
|
|
|
function Ue() {
|
|
|
|
w.transformStack.push(w.transform.clone());
|
|
|
|
}
|
|
|
|
s(Ue, "pushTransform");
|
|
|
|
function Oe() {
|
|
|
|
w.transformStack.length > 0 && (w.transform = w.transformStack.pop());
|
|
|
|
}
|
|
|
|
s(Oe, "popTransform");
|
|
|
|
function ht(r) {
|
|
|
|
if (r.width === void 0 || r.height === void 0)
|
|
|
|
throw new Error('drawUVQuad() requires property "width" and "height".');
|
|
|
|
if (r.width <= 0 || r.height <= 0) return;
|
|
|
|
let i = r.width,
|
|
|
|
c = r.height,
|
|
|
|
h = wt(r.anchor || Pt).scale(new D(i, c).scale(-0.5)),
|
|
|
|
y = r.quad || new he(0, 0, 1, 1),
|
|
|
|
x = r.color || ce(255, 255, 255),
|
|
|
|
A = r.opacity ?? 1,
|
|
|
|
E = r.tex ? 0.1 / r.tex.width : 0,
|
|
|
|
g = r.tex ? 0.1 / r.tex.height : 0,
|
|
|
|
C = y.x + E,
|
|
|
|
N = y.y + g,
|
|
|
|
G = y.w - E * 2,
|
|
|
|
F = y.h - g * 2;
|
|
|
|
Ue(),
|
|
|
|
te(r.pos),
|
|
|
|
je(r.angle),
|
|
|
|
We(r.scale),
|
|
|
|
te(h),
|
|
|
|
it(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
pos: new D(-i / 2, c / 2),
|
|
|
|
uv: new D(r.flipX ? C + G : C, r.flipY ? N : N + F),
|
|
|
|
color: x,
|
|
|
|
opacity: A,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pos: new D(-i / 2, -c / 2),
|
|
|
|
uv: new D(r.flipX ? C + G : C, r.flipY ? N + F : N),
|
|
|
|
color: x,
|
|
|
|
opacity: A,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pos: new D(i / 2, -c / 2),
|
|
|
|
uv: new D(r.flipX ? C : C + G, r.flipY ? N + F : N),
|
|
|
|
color: x,
|
|
|
|
opacity: A,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pos: new D(i / 2, c / 2),
|
|
|
|
uv: new D(r.flipX ? C : C + G, r.flipY ? N : N + F),
|
|
|
|
color: x,
|
|
|
|
opacity: A,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[0, 1, 3, 1, 2, 3],
|
|
|
|
r.fixed,
|
|
|
|
r.tex,
|
|
|
|
r.shader,
|
|
|
|
r.uniform
|
|
|
|
),
|
|
|
|
Oe();
|
|
|
|
}
|
|
|
|
s(ht, "drawUVQuad");
|
|
|
|
function Et(r) {
|
|
|
|
if (!r.tex) throw new Error('drawTexture() requires property "tex".');
|
|
|
|
let i = r.quad ?? new he(0, 0, 1, 1),
|
|
|
|
c = r.tex.width * i.w,
|
|
|
|
d = r.tex.height * i.h,
|
|
|
|
h = new D(1);
|
|
|
|
if (r.tiled) {
|
|
|
|
let y = Math.ceil((r.width || c) / c),
|
|
|
|
x = Math.ceil((r.height || d) / d),
|
|
|
|
E = wt(r.anchor || Pt)
|
|
|
|
.add(new D(1, 1))
|
|
|
|
.scale(0.5)
|
|
|
|
.scale(y * c, x * d);
|
|
|
|
for (let g = 0; g < y; g++)
|
|
|
|
for (let C = 0; C < x; C++)
|
|
|
|
ht(
|
|
|
|
Object.assign({}, r, {
|
|
|
|
pos: (r.pos || new D(0)).add(new D(c * g, d * C)).sub(E),
|
|
|
|
scale: h.scale(r.scale || new D(1)),
|
|
|
|
tex: r.tex,
|
|
|
|
quad: i,
|
2024-06-02 05:39:23 +00:00
|
|
|
width: c,
|
2024-06-17 22:57:39 +00:00
|
|
|
height: d,
|
|
|
|
anchor: "topleft",
|
2024-06-02 05:39:23 +00:00
|
|
|
})
|
|
|
|
);
|
2024-06-17 22:57:39 +00:00
|
|
|
} else
|
|
|
|
r.width && r.height
|
|
|
|
? ((h.x = r.width / c), (h.y = r.height / d))
|
|
|
|
: r.width
|
|
|
|
? ((h.x = r.width / c), (h.y = h.x))
|
|
|
|
: r.height && ((h.y = r.height / d), (h.x = h.y)),
|
|
|
|
ht(
|
|
|
|
Object.assign({}, r, {
|
|
|
|
scale: h.scale(r.scale || new D(1)),
|
|
|
|
tex: r.tex,
|
|
|
|
quad: i,
|
|
|
|
width: c,
|
|
|
|
height: d,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(Et, "drawTexture");
|
|
|
|
function tn(r) {
|
|
|
|
if (!r.sprite) throw new Error('drawSprite() requires property "sprite"');
|
|
|
|
let i = Qt(r.sprite);
|
|
|
|
if (!i || !i.data) return;
|
|
|
|
let c = i.data.frames[r.frame ?? 0];
|
|
|
|
if (!c) throw new Error(`Frame not found: ${r.frame ?? 0}`);
|
|
|
|
Et(
|
|
|
|
Object.assign({}, r, {
|
|
|
|
tex: i.data.tex,
|
|
|
|
quad: c.scale(r.quad ?? new he(0, 0, 1, 1)),
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(tn, "drawSprite");
|
|
|
|
function p(r, i, c, d, h, y = 1) {
|
|
|
|
(d = be(d % 360)), (h = be(h % 360)), h <= d && (h += Math.PI * 2);
|
|
|
|
let x = [],
|
|
|
|
A = Math.ceil(((h - d) / be(8)) * y),
|
|
|
|
E = (h - d) / A;
|
|
|
|
for (let g = d; g < h; g += E)
|
|
|
|
x.push(r.add(i * Math.cos(g), c * Math.sin(g)));
|
|
|
|
return x.push(r.add(i * Math.cos(h), c * Math.sin(h))), x;
|
|
|
|
}
|
|
|
|
s(p, "getArcPts");
|
|
|
|
function V(r) {
|
|
|
|
if (r.width === void 0 || r.height === void 0)
|
|
|
|
throw new Error('drawRect() requires property "width" and "height".');
|
|
|
|
if (r.width <= 0 || r.height <= 0) return;
|
|
|
|
let i = r.width,
|
|
|
|
c = r.height,
|
|
|
|
h = wt(r.anchor || Pt)
|
|
|
|
.add(1, 1)
|
|
|
|
.scale(new D(i, c).scale(-0.5)),
|
|
|
|
y = [new D(0, 0), new D(i, 0), new D(i, c), new D(0, c)];
|
|
|
|
if (r.radius) {
|
|
|
|
let x = Math.min(i, c) / 2,
|
|
|
|
A = Array.isArray(r.radius)
|
|
|
|
? r.radius.map((E) => Math.min(x, E))
|
|
|
|
: new Array(4).fill(Math.min(x, r.radius));
|
|
|
|
y = [
|
|
|
|
new D(A[0], 0),
|
|
|
|
...(A[1]
|
|
|
|
? p(new D(i - A[1], A[1]), A[1], A[1], 270, 360)
|
|
|
|
: [T(i, 0)]),
|
|
|
|
...(A[2]
|
|
|
|
? p(new D(i - A[2], c - A[2]), A[2], A[2], 0, 90)
|
|
|
|
: [T(i, c)]),
|
|
|
|
...(A[3] ? p(new D(A[3], c - A[3]), A[3], A[3], 90, 180) : [T(0, c)]),
|
|
|
|
...(A[0] ? p(new D(A[0], A[0]), A[0], A[0], 180, 270) : []),
|
|
|
|
];
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
St(
|
|
|
|
Object.assign({}, r, {
|
|
|
|
offset: h,
|
|
|
|
pts: y,
|
|
|
|
...(r.gradient
|
|
|
|
? {
|
|
|
|
colors: r.horizontal
|
|
|
|
? [r.gradient[0], r.gradient[1], r.gradient[1], r.gradient[0]]
|
|
|
|
: [
|
|
|
|
r.gradient[0],
|
|
|
|
r.gradient[0],
|
|
|
|
r.gradient[1],
|
|
|
|
r.gradient[1],
|
|
|
|
],
|
|
|
|
}
|
|
|
|
: {}),
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(V, "drawRect");
|
|
|
|
function j(r) {
|
|
|
|
let { p1: i, p2: c } = r;
|
|
|
|
if (!i || !c)
|
|
|
|
throw new Error('drawLine() requires properties "p1" and "p2".');
|
|
|
|
let d = r.width || 1,
|
|
|
|
h = c
|
|
|
|
.sub(i)
|
|
|
|
.unit()
|
|
|
|
.normal()
|
|
|
|
.scale(d * 0.5),
|
|
|
|
y = [i.sub(h), i.add(h), c.add(h), c.sub(h)].map((x) => ({
|
|
|
|
pos: new D(x.x, x.y),
|
|
|
|
uv: new D(0),
|
|
|
|
color: r.color ?? re.WHITE,
|
|
|
|
opacity: r.opacity ?? 1,
|
|
|
|
}));
|
|
|
|
it(y, [0, 1, 3, 1, 2, 3], r.fixed, w.defTex, r.shader, r.uniform);
|
|
|
|
}
|
|
|
|
s(j, "drawLine");
|
|
|
|
function J(r) {
|
|
|
|
let i = r.pts,
|
|
|
|
c = [],
|
|
|
|
d = (r.width || 1) * 0.5,
|
|
|
|
h = i[0] === i[i.length - 1] || i[0].eq(i[i.length - 1]),
|
|
|
|
y = r.pos || T(0, 0),
|
|
|
|
x;
|
|
|
|
h ? (x = i[0].sub(i[i.length - 2])) : (x = i[1].sub(i[0]));
|
|
|
|
let A = x.len(),
|
|
|
|
E = x.normal().scale(-d / A),
|
|
|
|
g,
|
|
|
|
C = i[0];
|
|
|
|
if (!h)
|
|
|
|
switch (r.cap) {
|
|
|
|
case "square": {
|
|
|
|
let S = x.scale(-d / A);
|
|
|
|
c.push(C.add(S).add(E)), c.push(C.add(S).sub(E));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "round": {
|
|
|
|
let S = Math.max(d, 10),
|
|
|
|
B = Math.PI / S,
|
|
|
|
R = E.scale(-1),
|
|
|
|
W = Math.cos(B),
|
|
|
|
q = Math.sin(B);
|
|
|
|
for (let Y = 0; Y < S; Y++)
|
|
|
|
c.push(C),
|
|
|
|
c.push(C.sub(R)),
|
|
|
|
(R = T(R.x * W - R.y * q, R.x * q + R.y * W));
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
for (let S = 1; S < i.length; S++) {
|
|
|
|
if (C === i[S] || C.eq(i[S])) continue;
|
|
|
|
(g = C), (C = i[S]);
|
|
|
|
let B = C.sub(g),
|
|
|
|
R = B.len(),
|
|
|
|
W = B.normal().scale(-d / R),
|
|
|
|
q = x.cross(B);
|
|
|
|
if (Math.abs(q) / (A * R) < 0.05) {
|
|
|
|
c.push(g.add(E)),
|
|
|
|
c.push(g.sub(E)),
|
|
|
|
x.dot(B) < 0 && (c.push(g.sub(E)), c.push(g.add(E))),
|
|
|
|
(x = B),
|
|
|
|
(A = R),
|
|
|
|
(E = W);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
let Y = W.sub(E).cross(B) / q,
|
|
|
|
z = E.add(x.scale(Y));
|
|
|
|
q > 0
|
|
|
|
? (c.push(g.add(z)),
|
|
|
|
c.push(g.sub(E)),
|
|
|
|
c.push(g.add(z)),
|
|
|
|
c.push(g.sub(W)))
|
|
|
|
: (c.push(g.add(E)),
|
|
|
|
c.push(g.sub(z)),
|
|
|
|
c.push(g.add(W)),
|
|
|
|
c.push(g.sub(z))),
|
|
|
|
(x = B),
|
|
|
|
(A = R),
|
|
|
|
(E = W);
|
|
|
|
}
|
|
|
|
if (!h)
|
|
|
|
switch ((c.push(C.add(E)), c.push(C.sub(E)), r.cap)) {
|
|
|
|
case "square": {
|
|
|
|
let S = x.scale(d / A);
|
|
|
|
c.push(C.add(S).add(E)), c.push(C.add(S).sub(E));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "round": {
|
|
|
|
let S = Math.max(d, 10),
|
|
|
|
B = Math.PI / S,
|
|
|
|
R = E.scale(1),
|
|
|
|
W = Math.cos(B),
|
|
|
|
q = Math.sin(B);
|
|
|
|
for (let Y = 0; Y < S; Y++)
|
|
|
|
(R = T(R.x * W - R.y * q, R.x * q + R.y * W)),
|
|
|
|
c.push(C),
|
|
|
|
c.push(C.sub(R));
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
if (c.length < 4) return;
|
|
|
|
let N = c.map((S) => ({
|
|
|
|
pos: y.add(S),
|
|
|
|
uv: T(),
|
|
|
|
color: r.color || re.WHITE,
|
|
|
|
opacity: r.opacity ?? 1,
|
|
|
|
})),
|
|
|
|
G = [],
|
|
|
|
F = 0;
|
|
|
|
for (let S = 0; S < c.length - 2; S += 2)
|
|
|
|
(G[F++] = S + 1),
|
|
|
|
(G[F++] = S),
|
|
|
|
(G[F++] = S + 2),
|
|
|
|
(G[F++] = S + 2),
|
|
|
|
(G[F++] = S + 3),
|
|
|
|
(G[F++] = S + 1);
|
|
|
|
h &&
|
|
|
|
((G[F++] = c.length - 1),
|
|
|
|
(G[F++] = c.length - 2),
|
|
|
|
(G[F++] = 0),
|
|
|
|
(G[F++] = 0),
|
|
|
|
(G[F++] = 1),
|
|
|
|
(G[F++] = c.length - 1)),
|
|
|
|
it(N, G, r.fixed, w.defTex, r.shader, r.uniform);
|
|
|
|
}
|
|
|
|
s(J, "_drawLinesBevel");
|
|
|
|
function xe(r) {
|
|
|
|
let i = r.pts,
|
|
|
|
c = [],
|
|
|
|
d = (r.width || 1) * 0.5,
|
|
|
|
h = i[0] === i[i.length - 1] || i[0].eq(i[i.length - 1]),
|
|
|
|
y = r.pos || T(0, 0),
|
|
|
|
x;
|
|
|
|
h ? (x = i[0].sub(i[i.length - 2])) : (x = i[1].sub(i[0]));
|
|
|
|
let A = x.len(),
|
|
|
|
E = x.normal().scale(-d / A),
|
|
|
|
g,
|
|
|
|
C = i[0];
|
|
|
|
if (!h)
|
|
|
|
switch (r.cap) {
|
|
|
|
case "square": {
|
|
|
|
let S = x.scale(-d / A);
|
|
|
|
c.push(C.add(S).add(E)), c.push(C.add(S).sub(E));
|
|
|
|
break;
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
case "round": {
|
|
|
|
let S = Math.max(d, 10),
|
|
|
|
B = Math.PI / S,
|
|
|
|
R = E.scale(-1),
|
|
|
|
W = Math.cos(B),
|
|
|
|
q = Math.sin(B);
|
|
|
|
for (let Y = 0; Y < S; Y++)
|
|
|
|
c.push(C),
|
|
|
|
c.push(C.sub(R)),
|
|
|
|
(R = T(R.x * W - R.y * q, R.x * q + R.y * W));
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
for (let S = 1; S < i.length; S++) {
|
|
|
|
if (C === i[S] || C.eq(i[S])) continue;
|
|
|
|
(g = C), (C = i[S]);
|
|
|
|
let B = C.sub(g),
|
|
|
|
R = B.len(),
|
|
|
|
W = B.normal().scale(-d / R),
|
|
|
|
q = x.cross(B);
|
|
|
|
if (Math.abs(q) / (A * R) < 0.05) {
|
|
|
|
c.push(g.add(E)),
|
|
|
|
c.push(g.sub(E)),
|
|
|
|
x.dot(B) < 0 && (c.push(g.sub(E)), c.push(g.add(E))),
|
|
|
|
(x = B),
|
|
|
|
(A = R),
|
|
|
|
(E = W);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
let Y = W.sub(E).cross(B) / q,
|
|
|
|
z = E.add(x.scale(Y));
|
|
|
|
if (q > 0) {
|
|
|
|
let Me = g.add(z),
|
|
|
|
U = Math.max(d, 10),
|
|
|
|
k = be(E.angleBetween(W) / U),
|
|
|
|
I = E,
|
|
|
|
K = Math.cos(k),
|
|
|
|
Z = Math.sin(k);
|
|
|
|
for (let ee = 0; ee < U; ee++)
|
|
|
|
c.push(Me),
|
|
|
|
c.push(g.sub(I)),
|
|
|
|
(I = T(I.x * K - I.y * Z, I.x * Z + I.y * K));
|
|
|
|
} else {
|
|
|
|
let Me = g.sub(z),
|
|
|
|
U = Math.max(d, 10),
|
|
|
|
k = be(E.angleBetween(W) / U),
|
|
|
|
I = E,
|
|
|
|
K = Math.cos(k),
|
|
|
|
Z = Math.sin(k);
|
|
|
|
for (let ee = 0; ee < U; ee++)
|
|
|
|
c.push(g.add(I)),
|
|
|
|
c.push(Me),
|
|
|
|
(I = T(I.x * K - I.y * Z, I.x * Z + I.y * K));
|
|
|
|
}
|
|
|
|
(x = B), (A = R), (E = W);
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
if (!h)
|
|
|
|
switch ((c.push(C.add(E)), c.push(C.sub(E)), r.cap)) {
|
|
|
|
case "square": {
|
|
|
|
let S = x.scale(d / A);
|
|
|
|
c.push(C.add(S).add(E)), c.push(C.add(S).sub(E));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "round": {
|
|
|
|
let S = Math.max(d, 10),
|
|
|
|
B = Math.PI / S,
|
|
|
|
R = E.scale(1),
|
|
|
|
W = Math.cos(B),
|
|
|
|
q = Math.sin(B);
|
|
|
|
for (let Y = 0; Y < S; Y++)
|
|
|
|
(R = T(R.x * W - R.y * q, R.x * q + R.y * W)),
|
|
|
|
c.push(C),
|
|
|
|
c.push(C.sub(R));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (c.length < 4) return;
|
|
|
|
let N = c.map((S) => ({
|
|
|
|
pos: y.add(S),
|
|
|
|
uv: T(),
|
|
|
|
color: r.color || re.WHITE,
|
|
|
|
opacity: r.opacity ?? 1,
|
|
|
|
})),
|
|
|
|
G = [],
|
|
|
|
F = 0;
|
|
|
|
for (let S = 0; S < c.length - 2; S += 2)
|
|
|
|
(G[F++] = S + 1),
|
|
|
|
(G[F++] = S),
|
|
|
|
(G[F++] = S + 2),
|
|
|
|
(G[F++] = S + 2),
|
|
|
|
(G[F++] = S + 3),
|
|
|
|
(G[F++] = S + 1);
|
|
|
|
h &&
|
|
|
|
((G[F++] = c.length - 1),
|
|
|
|
(G[F++] = c.length - 2),
|
|
|
|
(G[F++] = 0),
|
|
|
|
(G[F++] = 0),
|
|
|
|
(G[F++] = 1),
|
|
|
|
(G[F++] = c.length - 1)),
|
|
|
|
it(N, G, r.fixed, w.defTex, r.shader, r.uniform);
|
|
|
|
}
|
|
|
|
s(xe, "_drawLinesRound");
|
|
|
|
function le(r) {
|
|
|
|
let i = r.pts,
|
|
|
|
c = [],
|
|
|
|
d = (r.width || 1) * 0.5,
|
|
|
|
h = i[0] === i[i.length - 1] || i[0].eq(i[i.length - 1]),
|
|
|
|
y = r.pos || T(0, 0),
|
|
|
|
x;
|
|
|
|
h ? (x = i[0].sub(i[i.length - 2])) : (x = i[1].sub(i[0]));
|
|
|
|
let A = x.len(),
|
|
|
|
E = x.normal().scale(-d / A),
|
|
|
|
g,
|
|
|
|
C = i[0];
|
|
|
|
if (!h)
|
|
|
|
switch (r.cap) {
|
|
|
|
case "square": {
|
|
|
|
let S = x.scale(-d / A);
|
|
|
|
c.push(C.add(S).add(E)), c.push(C.add(S).sub(E));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "round": {
|
|
|
|
let S = Math.max(d, 10),
|
|
|
|
B = Math.PI / S,
|
|
|
|
R = E.scale(-1),
|
|
|
|
W = Math.cos(B),
|
|
|
|
q = Math.sin(B);
|
|
|
|
for (let Y = 0; Y < S; Y++)
|
|
|
|
c.push(C),
|
|
|
|
c.push(C.sub(R)),
|
|
|
|
(R = T(R.x * W - R.y * q, R.x * q + R.y * W));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (let S = 1; S < i.length; S++) {
|
|
|
|
if (C === i[S] || C.eq(i[S])) continue;
|
|
|
|
(g = C), (C = i[S]);
|
|
|
|
let B = C.sub(g),
|
|
|
|
R = B.len(),
|
|
|
|
W = B.normal().scale(-d / R),
|
|
|
|
q = x.cross(B);
|
|
|
|
if (Math.abs(q) / (A * R) < 0.05) {
|
|
|
|
c.push(g.add(E)),
|
|
|
|
c.push(g.sub(E)),
|
|
|
|
x.dot(B) < 0 && (c.push(g.sub(E)), c.push(g.add(E))),
|
|
|
|
(x = B),
|
|
|
|
(A = R),
|
|
|
|
(E = W);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
let Y = W.sub(E).cross(B) / q,
|
|
|
|
z = E.add(x.scale(Y));
|
|
|
|
c.push(g.add(z)), c.push(g.sub(z)), (x = B), (A = R), (E = W);
|
|
|
|
}
|
|
|
|
if (!h)
|
|
|
|
switch ((c.push(C.add(E)), c.push(C.sub(E)), r.cap)) {
|
|
|
|
case "square": {
|
|
|
|
let S = x.scale(d / A);
|
|
|
|
c.push(C.add(S).add(E)), c.push(C.add(S).sub(E));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "round": {
|
|
|
|
let S = Math.max(d, 10),
|
|
|
|
B = Math.PI / S,
|
|
|
|
R = E.scale(1),
|
|
|
|
W = Math.cos(B),
|
|
|
|
q = Math.sin(B);
|
|
|
|
for (let Y = 0; Y < S; Y++)
|
|
|
|
(R = T(R.x * W - R.y * q, R.x * q + R.y * W)),
|
|
|
|
c.push(C),
|
|
|
|
c.push(C.sub(R));
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
if (c.length < 4) return;
|
|
|
|
let N = c.map((S) => ({
|
|
|
|
pos: y.add(S),
|
|
|
|
uv: T(),
|
|
|
|
color: r.color || re.WHITE,
|
|
|
|
opacity: r.opacity ?? 1,
|
|
|
|
})),
|
|
|
|
G = [],
|
|
|
|
F = 0;
|
|
|
|
for (let S = 0; S < c.length - 2; S += 2)
|
|
|
|
(G[F++] = S + 1),
|
|
|
|
(G[F++] = S),
|
|
|
|
(G[F++] = S + 2),
|
|
|
|
(G[F++] = S + 2),
|
|
|
|
(G[F++] = S + 3),
|
|
|
|
(G[F++] = S + 1);
|
|
|
|
h &&
|
|
|
|
((G[F++] = c.length - 1),
|
|
|
|
(G[F++] = c.length - 2),
|
|
|
|
(G[F++] = 0),
|
|
|
|
(G[F++] = 0),
|
|
|
|
(G[F++] = 1),
|
|
|
|
(G[F++] = c.length - 1)),
|
|
|
|
it(N, G, r.fixed, w.defTex, r.shader, r.uniform);
|
|
|
|
}
|
|
|
|
s(le, "_drawLinesMiter");
|
|
|
|
function Ke(r) {
|
|
|
|
let i = r.pts;
|
|
|
|
if (!i) throw new Error('drawLines() requires property "pts".');
|
|
|
|
if (!(i.length < 2)) {
|
|
|
|
if (i.length > 2)
|
|
|
|
switch (r.join) {
|
|
|
|
case "bevel":
|
|
|
|
return J(r);
|
|
|
|
case "round":
|
|
|
|
return xe(r);
|
|
|
|
case "miter":
|
|
|
|
return le(r);
|
|
|
|
}
|
|
|
|
if (r.radius && i.length >= 3) {
|
|
|
|
j(Object.assign({}, r, { p1: i[0], p2: i[1] }));
|
|
|
|
for (let c = 1; c < i.length - 2; c++) {
|
|
|
|
let d = i[c],
|
|
|
|
h = i[c + 1];
|
|
|
|
j(Object.assign({}, r, { p1: d, p2: h }));
|
|
|
|
}
|
|
|
|
j(Object.assign({}, r, { p1: i[i.length - 2], p2: i[i.length - 1] }));
|
|
|
|
} else
|
|
|
|
for (let c = 0; c < i.length - 1; c++)
|
|
|
|
j(Object.assign({}, r, { p1: i[c], p2: i[c + 1] })),
|
|
|
|
r.join !== "none" &&
|
|
|
|
pt(Object.assign({}, r, { pos: i[c], radius: r.width / 2 }));
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
}
|
|
|
|
s(Ke, "drawLines");
|
|
|
|
function at(r, i) {
|
|
|
|
let c = i.segments ?? 16,
|
|
|
|
d = [];
|
|
|
|
for (let h = 0; h <= c; h++) d.push(r(h / c));
|
|
|
|
Ke({
|
|
|
|
pts: d,
|
|
|
|
width: i.width || 1,
|
|
|
|
pos: i.pos,
|
|
|
|
color: i.color,
|
|
|
|
opacity: i.opacity,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
s(at, "drawCurve");
|
|
|
|
function In(r) {
|
|
|
|
at((i) => un(r.pt1, r.pt2, r.pt3, r.pt4, i), r);
|
|
|
|
}
|
|
|
|
s(In, "drawBezier");
|
|
|
|
function $e(r) {
|
|
|
|
if (!r.p1 || !r.p2 || !r.p3)
|
|
|
|
throw new Error(
|
|
|
|
'drawTriangle() requires properties "p1", "p2" and "p3".'
|
|
|
|
);
|
|
|
|
return St(Object.assign({}, r, { pts: [r.p1, r.p2, r.p3] }));
|
|
|
|
}
|
|
|
|
s($e, "drawTriangle");
|
|
|
|
function pt(r) {
|
|
|
|
if (typeof r.radius != "number")
|
|
|
|
throw new Error('drawCircle() requires property "radius".');
|
|
|
|
r.radius !== 0 &&
|
|
|
|
wr(
|
|
|
|
Object.assign({}, r, {
|
|
|
|
radiusX: r.radius,
|
|
|
|
radiusY: r.radius,
|
|
|
|
angle: 0,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(pt, "drawCircle");
|
|
|
|
function wr(r) {
|
|
|
|
if (r.radiusX === void 0 || r.radiusY === void 0)
|
|
|
|
throw new Error(
|
|
|
|
'drawEllipse() requires properties "radiusX" and "radiusY".'
|
|
|
|
);
|
|
|
|
if (r.radiusX === 0 || r.radiusY === 0) return;
|
|
|
|
let i = r.start ?? 0,
|
|
|
|
c = r.end ?? 360,
|
|
|
|
d = wt(r.anchor ?? "center").scale(new D(-r.radiusX, -r.radiusY)),
|
|
|
|
h = p(d, r.radiusX, r.radiusY, i, c, r.resolution);
|
|
|
|
h.unshift(d);
|
|
|
|
let y = Object.assign({}, r, {
|
|
|
|
pts: h,
|
|
|
|
radius: 0,
|
|
|
|
...(r.gradient
|
|
|
|
? {
|
|
|
|
colors: [
|
|
|
|
r.gradient[0],
|
|
|
|
...Array(h.length - 1).fill(r.gradient[1]),
|
|
|
|
],
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
: {}),
|
|
|
|
});
|
|
|
|
if (c - i >= 360 && r.outline) {
|
|
|
|
r.fill !== !1 && St(Object.assign({}, y, { outline: null })),
|
|
|
|
St(Object.assign({}, y, { pts: h.slice(1), fill: !1 }));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
St(y);
|
|
|
|
}
|
|
|
|
s(wr, "drawEllipse");
|
|
|
|
function St(r) {
|
|
|
|
if (!r.pts) throw new Error('drawPolygon() requires property "pts".');
|
|
|
|
let i = r.pts.length;
|
|
|
|
if (!(i < 3)) {
|
|
|
|
if (
|
|
|
|
(Ue(),
|
|
|
|
te(r.pos),
|
|
|
|
We(r.scale),
|
|
|
|
je(r.angle),
|
|
|
|
te(r.offset),
|
|
|
|
r.fill !== !1)
|
|
|
|
) {
|
|
|
|
let c = r.color ?? re.WHITE,
|
|
|
|
d = r.pts.map((y, x) => ({
|
|
|
|
pos: new D(y.x, y.y),
|
|
|
|
uv: r.uv ? r.uv[x] : new D(0, 0),
|
|
|
|
color: r.colors && r.colors[x] ? r.colors[x].mult(c) : c,
|
|
|
|
opacity: r.opacity ?? 1,
|
|
|
|
})),
|
|
|
|
h;
|
|
|
|
r.triangulate && ar(r.pts)
|
|
|
|
? (h = ir(r.pts)
|
|
|
|
.map((x) => x.map((A) => r.pts.indexOf(A)))
|
|
|
|
.flat())
|
|
|
|
: (h = [...Array(i - 2).keys()]
|
|
|
|
.map((y) => [0, y + 1, y + 2])
|
|
|
|
.flat()),
|
|
|
|
it(
|
|
|
|
d,
|
|
|
|
r.indices ?? h,
|
|
|
|
r.fixed,
|
|
|
|
r.uv ? r.tex : w.defTex,
|
|
|
|
r.shader,
|
|
|
|
r.uniform
|
2024-06-02 05:39:23 +00:00
|
|
|
);
|
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
r.outline &&
|
|
|
|
Ke({
|
|
|
|
pts: [...r.pts, r.pts[0]],
|
|
|
|
radius: r.radius,
|
|
|
|
width: r.outline.width,
|
|
|
|
color: r.outline.color,
|
|
|
|
join: r.outline.join,
|
|
|
|
uniform: r.uniform,
|
|
|
|
fixed: r.fixed,
|
|
|
|
opacity: r.opacity ?? r.outline.opacity,
|
|
|
|
}),
|
|
|
|
Oe();
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
}
|
|
|
|
s(St, "drawPolygon");
|
|
|
|
function Cr(r, i, c) {
|
|
|
|
Se(),
|
|
|
|
b.clear(b.STENCIL_BUFFER_BIT),
|
|
|
|
b.enable(b.STENCIL_TEST),
|
|
|
|
b.stencilFunc(b.NEVER, 1, 255),
|
|
|
|
b.stencilOp(b.REPLACE, b.REPLACE, b.REPLACE),
|
|
|
|
i(),
|
|
|
|
Se(),
|
|
|
|
b.stencilFunc(c, 1, 255),
|
|
|
|
b.stencilOp(b.KEEP, b.KEEP, b.KEEP),
|
|
|
|
r(),
|
|
|
|
Se(),
|
|
|
|
b.disable(b.STENCIL_TEST);
|
|
|
|
}
|
|
|
|
s(Cr, "drawStenciled");
|
|
|
|
function Tr(r, i) {
|
|
|
|
Cr(r, i, b.EQUAL);
|
|
|
|
}
|
|
|
|
s(Tr, "drawMasked");
|
|
|
|
function Er(r, i) {
|
|
|
|
Cr(r, i, b.NOTEQUAL);
|
|
|
|
}
|
|
|
|
s(Er, "drawSubtracted");
|
|
|
|
function Ts() {
|
|
|
|
return (w.viewport.width + w.viewport.height) / (w.width + w.height);
|
|
|
|
}
|
|
|
|
s(Ts, "getViewportScale");
|
|
|
|
function ct(r) {
|
|
|
|
Se();
|
|
|
|
let i = w.width,
|
|
|
|
c = w.height;
|
|
|
|
(w.width = w.viewport.width),
|
|
|
|
(w.height = w.viewport.height),
|
|
|
|
r(),
|
|
|
|
Se(),
|
|
|
|
(w.width = i),
|
|
|
|
(w.height = c);
|
|
|
|
}
|
|
|
|
s(ct, "drawUnscaled");
|
|
|
|
function Sr(r, i) {
|
|
|
|
i.pos && (r.pos = r.pos.add(i.pos)),
|
|
|
|
i.scale && (r.scale = r.scale.scale(T(i.scale))),
|
|
|
|
i.angle && (r.angle += i.angle),
|
|
|
|
i.color && r.ch.length === 1 && (r.color = r.color.mult(i.color)),
|
|
|
|
i.opacity && (r.opacity *= i.opacity);
|
|
|
|
}
|
|
|
|
s(Sr, "applyCharTransform");
|
|
|
|
function Es(r) {
|
|
|
|
let i = {},
|
|
|
|
c = r.replace(vr, "$2"),
|
|
|
|
d = 0;
|
|
|
|
for (let h of r.matchAll(vr)) {
|
|
|
|
let y = h.index - d;
|
|
|
|
for (let x = 0; x < h.groups.text.length; x++)
|
|
|
|
i[x + y] = [h.groups.style];
|
|
|
|
d += h[0].length - h.groups.text.length;
|
|
|
|
}
|
|
|
|
return { charStyleMap: i, text: c };
|
|
|
|
}
|
|
|
|
s(Es, "compileStyledText");
|
|
|
|
let Ln = {};
|
|
|
|
function Ot(r) {
|
|
|
|
if (r.text === void 0)
|
|
|
|
throw new Error('formatText() requires property "text".');
|
|
|
|
let i = Jt(r.font);
|
|
|
|
if (r.text === "" || i instanceof Ve || !i)
|
|
|
|
return { width: 0, height: 0, chars: [], opt: r };
|
|
|
|
let { charStyleMap: c, text: d } = Es(r.text + ""),
|
|
|
|
h = Co(d);
|
|
|
|
if (i instanceof ae || typeof i == "string") {
|
|
|
|
let q = i instanceof ae ? i.fontface.family : i,
|
|
|
|
Y =
|
|
|
|
i instanceof ae
|
|
|
|
? { outline: i.outline, filter: i.filter }
|
|
|
|
: { outline: null, filter: fn },
|
|
|
|
z = Ln[q] ?? {
|
|
|
|
font: {
|
|
|
|
tex: new qe(M, 2048, 2048, { filter: Y.filter }),
|
|
|
|
map: {},
|
|
|
|
size: 64,
|
|
|
|
},
|
|
|
|
cursor: new D(0),
|
|
|
|
outline: Y.outline,
|
|
|
|
};
|
|
|
|
Ln[q] || (Ln[q] = z), (i = z.font);
|
|
|
|
for (let Me of h)
|
|
|
|
if (!z.font.map[Me]) {
|
|
|
|
let U = v;
|
|
|
|
U.clearRect(0, 0, f.width, f.height),
|
|
|
|
(U.font = `${i.size}px ${q}`),
|
|
|
|
(U.textBaseline = "top"),
|
|
|
|
(U.textAlign = "left"),
|
|
|
|
(U.fillStyle = "#ffffff");
|
|
|
|
let k = U.measureText(Me),
|
|
|
|
I = Math.ceil(k.width);
|
|
|
|
if (!I) continue;
|
|
|
|
let K = i.size;
|
|
|
|
z.outline &&
|
|
|
|
((U.lineJoin = "round"),
|
|
|
|
(U.lineWidth = z.outline.width * 2),
|
|
|
|
(U.strokeStyle = z.outline.color.toHex()),
|
|
|
|
U.strokeText(Me, z.outline.width, z.outline.width),
|
|
|
|
(I += z.outline.width * 2),
|
|
|
|
(K += z.outline.width * 3)),
|
|
|
|
U.fillText(Me, z.outline?.width ?? 0, z.outline?.width ?? 0);
|
|
|
|
let Z = U.getImageData(0, 0, I, K);
|
|
|
|
if (
|
|
|
|
z.cursor.x + I > 2048 &&
|
|
|
|
((z.cursor.x = 0), (z.cursor.y += K), z.cursor.y > 2048)
|
|
|
|
)
|
|
|
|
throw new Error("Font atlas exceeds character limit");
|
|
|
|
i.tex.update(Z, z.cursor.x, z.cursor.y),
|
|
|
|
(i.map[Me] = new he(z.cursor.x, z.cursor.y, I, K)),
|
|
|
|
(z.cursor.x += I);
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
let y = r.size || i.size,
|
|
|
|
x = T(r.scale ?? 1).scale(y / i.size),
|
|
|
|
A = r.lineSpacing ?? 0,
|
|
|
|
E = r.letterSpacing ?? 0,
|
|
|
|
g = 0,
|
|
|
|
C = 0,
|
|
|
|
N = 0,
|
|
|
|
G = [],
|
|
|
|
F = [],
|
|
|
|
S = 0,
|
|
|
|
B = null,
|
|
|
|
R = null;
|
|
|
|
for (; S < h.length; ) {
|
|
|
|
let q = h[S];
|
|
|
|
if (
|
|
|
|
q ===
|
|
|
|
`
|
|
|
|
`
|
|
|
|
)
|
|
|
|
(N += y + A),
|
|
|
|
G.push({ width: g - E, chars: F }),
|
|
|
|
(B = null),
|
|
|
|
(R = null),
|
|
|
|
(g = 0),
|
|
|
|
(F = []);
|
|
|
|
else {
|
|
|
|
let Y = i.map[q];
|
|
|
|
if (Y) {
|
|
|
|
let z = Y.w * x.x;
|
|
|
|
r.width &&
|
|
|
|
g + z > r.width &&
|
|
|
|
((N += y + A),
|
|
|
|
B != null &&
|
|
|
|
((S -= F.length - B),
|
|
|
|
(q = h[S]),
|
|
|
|
(Y = i.map[q]),
|
|
|
|
(z = Y.w * x.x),
|
|
|
|
(F = F.slice(0, B - 1)),
|
|
|
|
(g = R)),
|
|
|
|
(B = null),
|
|
|
|
(R = null),
|
|
|
|
G.push({ width: g - E, chars: F }),
|
|
|
|
(g = 0),
|
|
|
|
(F = [])),
|
|
|
|
F.push({
|
|
|
|
tex: i.tex,
|
|
|
|
width: Y.w,
|
|
|
|
height: Y.h,
|
|
|
|
quad: new he(
|
|
|
|
Y.x / i.tex.width,
|
|
|
|
Y.y / i.tex.height,
|
|
|
|
Y.w / i.tex.width,
|
|
|
|
Y.h / i.tex.height
|
|
|
|
),
|
|
|
|
ch: q,
|
|
|
|
pos: new D(g, N),
|
|
|
|
opacity: r.opacity ?? 1,
|
|
|
|
color: r.color ?? re.WHITE,
|
|
|
|
scale: T(x),
|
|
|
|
angle: 0,
|
|
|
|
}),
|
|
|
|
q === " " && ((B = F.length), (R = g)),
|
|
|
|
(g += z),
|
|
|
|
(C = Math.max(C, g)),
|
|
|
|
(g += E);
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
S++;
|
|
|
|
}
|
|
|
|
G.push({ width: g - E, chars: F }), (N += y), r.width && (C = r.width);
|
|
|
|
let W = [];
|
|
|
|
for (let q = 0; q < G.length; q++) {
|
|
|
|
let Y = (C - G[q].width) * va(r.align ?? "left");
|
|
|
|
for (let z of G[q].chars) {
|
|
|
|
let Me = i.map[z.ch],
|
|
|
|
U = W.length + q;
|
2024-06-02 05:39:23 +00:00
|
|
|
if (
|
2024-06-17 22:57:39 +00:00
|
|
|
((z.pos = z.pos.add(Y, 0).add(Me.w * x.x * 0.5, Me.h * x.y * 0.5)),
|
|
|
|
r.transform)
|
2024-06-02 05:39:23 +00:00
|
|
|
) {
|
2024-06-17 22:57:39 +00:00
|
|
|
let k =
|
|
|
|
typeof r.transform == "function"
|
|
|
|
? r.transform(U, z.ch)
|
|
|
|
: r.transform;
|
|
|
|
k && Sr(z, k);
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
if (c[U]) {
|
|
|
|
let k = c[U];
|
|
|
|
for (let I of k) {
|
|
|
|
let K = r.styles[I],
|
|
|
|
Z = typeof K == "function" ? K(U, z.ch) : K;
|
|
|
|
Z && Sr(z, Z);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
W.push(z);
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
return { width: C, height: N, chars: W, opt: r };
|
|
|
|
}
|
|
|
|
s(Ot, "formatText");
|
|
|
|
function Or(r) {
|
|
|
|
At(Ot(r));
|
|
|
|
}
|
|
|
|
s(Or, "drawText");
|
|
|
|
function At(r) {
|
|
|
|
Ue(),
|
|
|
|
te(r.opt.pos),
|
|
|
|
je(r.opt.angle),
|
|
|
|
te(
|
|
|
|
wt(r.opt.anchor ?? "topleft")
|
|
|
|
.add(1, 1)
|
|
|
|
.scale(r.width, r.height)
|
|
|
|
.scale(-0.5)
|
|
|
|
),
|
|
|
|
r.chars.forEach((i) => {
|
|
|
|
ht({
|
|
|
|
tex: i.tex,
|
|
|
|
width: i.width,
|
|
|
|
height: i.height,
|
|
|
|
pos: i.pos,
|
|
|
|
scale: i.scale,
|
|
|
|
angle: i.angle,
|
|
|
|
color: i.color,
|
|
|
|
opacity: i.opacity,
|
|
|
|
quad: i.quad,
|
|
|
|
anchor: "center",
|
|
|
|
uniform: r.opt.uniform,
|
|
|
|
shader: r.opt.shader,
|
|
|
|
fixed: r.opt.fixed,
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
Oe();
|
|
|
|
}
|
|
|
|
s(At, "drawFormattedText");
|
|
|
|
function Pe() {
|
|
|
|
return w.width;
|
|
|
|
}
|
|
|
|
s(Pe, "width");
|
|
|
|
function ke() {
|
|
|
|
return w.height;
|
|
|
|
}
|
|
|
|
s(ke, "height");
|
|
|
|
function Ss() {
|
|
|
|
return O.root;
|
|
|
|
}
|
|
|
|
s(Ss, "getTreeRoot");
|
|
|
|
function Os(r) {
|
|
|
|
return new D(
|
|
|
|
((r.x - w.viewport.x) * Pe()) / w.viewport.width,
|
|
|
|
((r.y - w.viewport.y) * ke()) / w.viewport.height
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(Os, "windowToContent");
|
|
|
|
function As(r) {
|
|
|
|
return new D(
|
|
|
|
(r.x * w.viewport.width) / w.width,
|
|
|
|
(r.y * w.viewport.height) / w.height
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(As, "contentToView");
|
|
|
|
function Ar() {
|
|
|
|
return Os(m.mousePos());
|
|
|
|
}
|
|
|
|
s(Ar, "mousePos");
|
|
|
|
let Vr = !1,
|
|
|
|
de = {
|
|
|
|
inspect: !1,
|
|
|
|
timeScale: 1,
|
|
|
|
showLog: !0,
|
|
|
|
fps: () => m.fps(),
|
|
|
|
numFrames: () => m.numFrames(),
|
|
|
|
stepFrame: Br,
|
|
|
|
drawCalls: () => w.lastDrawCalls,
|
|
|
|
clearLog: () => (O.logs = []),
|
|
|
|
log: (r) => {
|
|
|
|
let i = t.logMax ?? 8;
|
|
|
|
O.logs.unshift({ msg: r, time: m.time() }),
|
|
|
|
O.logs.length > i && (O.logs = O.logs.slice(0, i));
|
|
|
|
},
|
|
|
|
error: (r) => de.log(new Error(r.toString ? r.toString() : r)),
|
|
|
|
curRecording: null,
|
|
|
|
numObjects: () => Hn("*", { recursive: !0 }).length,
|
|
|
|
get paused() {
|
|
|
|
return Vr;
|
|
|
|
},
|
|
|
|
set paused(r) {
|
|
|
|
(Vr = r), r ? X.ctx.suspend() : X.ctx.resume();
|
|
|
|
},
|
|
|
|
};
|
|
|
|
function jn() {
|
|
|
|
return m.dt() * de.timeScale;
|
|
|
|
}
|
|
|
|
s(jn, "dt");
|
|
|
|
function Vs(...r) {
|
|
|
|
return (
|
|
|
|
r.length > 0 && (O.cam.pos = T(...r)),
|
|
|
|
O.cam.pos ? O.cam.pos.clone() : rn()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(Vs, "camPos");
|
|
|
|
function Rs(...r) {
|
|
|
|
return r.length > 0 && (O.cam.scale = T(...r)), O.cam.scale.clone();
|
|
|
|
}
|
|
|
|
s(Rs, "camScale");
|
|
|
|
function Us(r) {
|
|
|
|
return r !== void 0 && (O.cam.angle = r), O.cam.angle;
|
|
|
|
}
|
|
|
|
s(Us, "camRot");
|
|
|
|
function Ps() {
|
|
|
|
return O.cam.transform.clone();
|
|
|
|
}
|
|
|
|
s(Ps, "camTransform");
|
|
|
|
function Ms(r = 12) {
|
|
|
|
O.cam.shake += r;
|
|
|
|
}
|
|
|
|
s(Ms, "shake");
|
|
|
|
function Ds(r) {
|
|
|
|
return O.cam.transform.multVec2(r);
|
|
|
|
}
|
|
|
|
s(Ds, "toScreen");
|
|
|
|
function Gs(r) {
|
|
|
|
return O.cam.transform.invert().multVec2(r);
|
|
|
|
}
|
|
|
|
s(Gs, "toWorld");
|
|
|
|
function Rr(r) {
|
|
|
|
let i = new De();
|
|
|
|
return (
|
|
|
|
r.pos && i.translate(r.pos),
|
|
|
|
r.scale && i.scale(r.scale),
|
|
|
|
r.angle && i.rotate(r.angle),
|
|
|
|
r.parent ? i.mult(r.parent.transform) : i
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(Rr, "calcTransform");
|
|
|
|
function kn(r = []) {
|
|
|
|
let i = new Map(),
|
|
|
|
c = {},
|
|
|
|
d = new nt(),
|
|
|
|
h = [],
|
|
|
|
y = null,
|
|
|
|
x = !1,
|
|
|
|
A = {
|
|
|
|
id: yo(),
|
|
|
|
hidden: !1,
|
|
|
|
transform: new De(),
|
|
|
|
children: [],
|
|
|
|
parent: null,
|
|
|
|
set paused(g) {
|
|
|
|
if (g !== x) {
|
|
|
|
x = g;
|
|
|
|
for (let C of h) C.paused = g;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
get paused() {
|
|
|
|
return x;
|
|
|
|
},
|
|
|
|
add(g = []) {
|
|
|
|
let C = Array.isArray(g) ? kn(g) : g;
|
|
|
|
if (C.parent)
|
|
|
|
throw new Error(
|
|
|
|
"Cannot add a game obj that already has a parent."
|
|
|
|
);
|
|
|
|
return (
|
|
|
|
(C.parent = this),
|
|
|
|
(C.transform = Rr(C)),
|
|
|
|
this.children.push(C),
|
|
|
|
C.trigger("add", C),
|
|
|
|
O.events.trigger("add", C),
|
|
|
|
C
|
|
|
|
);
|
|
|
|
},
|
|
|
|
readd(g) {
|
|
|
|
let C = this.children.indexOf(g);
|
|
|
|
return (
|
|
|
|
C !== -1 && (this.children.splice(C, 1), this.children.push(g)), g
|
|
|
|
);
|
|
|
|
},
|
|
|
|
remove(g) {
|
|
|
|
let C = this.children.indexOf(g);
|
|
|
|
if (C !== -1) {
|
|
|
|
(g.parent = null), this.children.splice(C, 1);
|
|
|
|
let N = s((G) => {
|
|
|
|
G.trigger("destroy"),
|
|
|
|
O.events.trigger("destroy", G),
|
|
|
|
G.children.forEach((F) => N(F));
|
|
|
|
}, "trigger");
|
|
|
|
N(g);
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
},
|
|
|
|
removeAll(g) {
|
|
|
|
if (g) this.get(g).forEach((C) => this.remove(C));
|
|
|
|
else for (let C of [...this.children]) this.remove(C);
|
|
|
|
},
|
|
|
|
update() {
|
|
|
|
this.paused ||
|
|
|
|
(this.children.forEach((g) => g.update()),
|
|
|
|
this.trigger("update"));
|
|
|
|
},
|
|
|
|
draw() {
|
|
|
|
if (this.hidden) return;
|
|
|
|
this.canvas && (Se(), this.canvas.bind());
|
|
|
|
let g = w.fixed;
|
|
|
|
this.fixed && (w.fixed = !0),
|
|
|
|
Ue(),
|
|
|
|
te(this.pos),
|
|
|
|
We(this.scale),
|
|
|
|
je(this.angle);
|
|
|
|
let C = this.children.sort((N, G) => {
|
|
|
|
let F = N.layerIndex ?? O.defaultLayerIndex,
|
|
|
|
S = G.layerIndex ?? O.defaultLayerIndex;
|
|
|
|
return F - S || (N.z ?? 0) - (G.z ?? 0);
|
|
|
|
});
|
|
|
|
if (this.mask) {
|
|
|
|
let N = { intersect: Tr, subtract: Er }[this.mask];
|
|
|
|
if (!N) throw new Error(`Invalid mask func: "${this.mask}"`);
|
|
|
|
N(
|
|
|
|
() => {
|
|
|
|
C.forEach((G) => G.draw());
|
|
|
|
},
|
|
|
|
() => {
|
|
|
|
this.trigger("draw");
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} else this.trigger("draw"), C.forEach((N) => N.draw());
|
|
|
|
Oe(), (w.fixed = g), this.canvas && (Se(), this.canvas.unbind());
|
|
|
|
},
|
|
|
|
drawInspect() {
|
|
|
|
this.hidden ||
|
|
|
|
(Ue(),
|
|
|
|
te(this.pos),
|
|
|
|
We(this.scale),
|
|
|
|
je(this.angle),
|
|
|
|
this.children.forEach((g) => g.drawInspect()),
|
|
|
|
this.trigger("drawInspect"),
|
|
|
|
Oe());
|
|
|
|
},
|
|
|
|
use(g) {
|
|
|
|
if (!g) return;
|
|
|
|
if ((To(g) && (g = new g(this)), typeof g == "function"))
|
|
|
|
return this.use(g(this));
|
|
|
|
if (typeof g == "string") return this.use({ id: g });
|
|
|
|
let C = [];
|
|
|
|
g.id &&
|
|
|
|
(this.unuse(g.id), (c[g.id] = []), (C = c[g.id]), i.set(g.id, g));
|
|
|
|
for (let G in g) {
|
|
|
|
if (Do.has(G)) continue;
|
|
|
|
let F = Object.getOwnPropertyDescriptor(g, G);
|
|
|
|
if (
|
|
|
|
(typeof F.value == "function" && (g[G] = g[G].bind(this)),
|
|
|
|
F.set && Object.defineProperty(g, G, { set: F.set.bind(this) }),
|
|
|
|
F.get && Object.defineProperty(g, G, { get: F.get.bind(this) }),
|
|
|
|
Go.has(G))
|
|
|
|
) {
|
|
|
|
let S =
|
|
|
|
G === "add"
|
|
|
|
? () => {
|
|
|
|
(y = s((B) => C.push(B), "onCurCompCleanup")),
|
|
|
|
g[G](),
|
|
|
|
(y = null);
|
|
|
|
}
|
|
|
|
: g[G];
|
|
|
|
C.push(this.on(G, S).cancel);
|
|
|
|
} else if (this[G] === void 0)
|
|
|
|
Object.defineProperty(this, G, {
|
|
|
|
get: () => g[G],
|
|
|
|
set: (S) => (g[G] = S),
|
|
|
|
configurable: !0,
|
|
|
|
enumerable: !0,
|
2024-06-02 05:39:23 +00:00
|
|
|
}),
|
2024-06-17 22:57:39 +00:00
|
|
|
C.push(() => delete this[G]);
|
|
|
|
else throw new Error(`Duplicate component property: "${G}"`);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
let N = s(() => {
|
|
|
|
if (g.require) {
|
|
|
|
for (let G of g.require)
|
|
|
|
if (!this.c(G))
|
|
|
|
throw new Error(
|
|
|
|
`Component "${g.id}" requires component "${G}"`
|
|
|
|
);
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
}, "checkDeps");
|
|
|
|
g.destroy && C.push(g.destroy.bind(this)),
|
|
|
|
this.exists()
|
|
|
|
? (N(),
|
|
|
|
g.add &&
|
|
|
|
((y = s((G) => C.push(G), "onCurCompCleanup")),
|
|
|
|
g.add.call(this),
|
|
|
|
(y = null)))
|
|
|
|
: g.require && C.push(this.on("add", N).cancel);
|
|
|
|
},
|
|
|
|
unuse(g) {
|
|
|
|
c[g] && (c[g].forEach((C) => C()), delete c[g]),
|
|
|
|
i.has(g) && i.delete(g);
|
|
|
|
},
|
|
|
|
c(g) {
|
|
|
|
return i.get(g);
|
|
|
|
},
|
|
|
|
get(g, C = {}) {
|
|
|
|
let N = C.recursive
|
|
|
|
? this.children.flatMap(
|
|
|
|
s(function G(F) {
|
|
|
|
return [F, ...F.children.flatMap(G)];
|
|
|
|
}, "recurse")
|
|
|
|
)
|
|
|
|
: this.children;
|
|
|
|
if (((N = N.filter((G) => (g ? G.is(g) : !0))), C.liveUpdate)) {
|
|
|
|
let G = s(
|
|
|
|
(S) =>
|
|
|
|
C.recursive ? this.isAncestorOf(S) : S.parent === this,
|
|
|
|
"isChild"
|
|
|
|
),
|
|
|
|
F = [];
|
|
|
|
F.push(
|
|
|
|
Nn((S) => {
|
|
|
|
G(S) && S.is(g) && N.push(S);
|
|
|
|
})
|
|
|
|
),
|
|
|
|
F.push(
|
|
|
|
Ur((S) => {
|
|
|
|
if (G(S) && S.is(g)) {
|
|
|
|
let B = N.findIndex((R) => R.id === S.id);
|
|
|
|
B !== -1 && N.splice(B, 1);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
),
|
|
|
|
this.onDestroy(() => {
|
|
|
|
for (let S of F) S.cancel();
|
|
|
|
});
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
return N;
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-17 22:57:39 +00:00
|
|
|
isAncestorOf(g) {
|
|
|
|
return g.parent
|
|
|
|
? g.parent === this || this.isAncestorOf(g.parent)
|
|
|
|
: !1;
|
|
|
|
},
|
|
|
|
exists() {
|
|
|
|
return O.root.isAncestorOf(this);
|
|
|
|
},
|
|
|
|
is(g) {
|
|
|
|
if (g === "*") return !0;
|
|
|
|
if (Array.isArray(g)) {
|
|
|
|
for (let C of g) if (!this.c(C)) return !1;
|
|
|
|
return !0;
|
|
|
|
} else return this.c(g) != null;
|
|
|
|
},
|
|
|
|
on(g, C) {
|
|
|
|
let N = d.on(g, C.bind(this));
|
|
|
|
return y && y(() => N.cancel()), N;
|
|
|
|
},
|
|
|
|
trigger(g, ...C) {
|
|
|
|
d.trigger(g, ...C), O.objEvents.trigger(g, this, ...C);
|
|
|
|
},
|
|
|
|
destroy() {
|
|
|
|
this.parent && this.parent.remove(this);
|
|
|
|
},
|
|
|
|
inspect() {
|
|
|
|
let g = {};
|
|
|
|
for (let [C, N] of i) g[C] = N.inspect ? N.inspect() : null;
|
|
|
|
return g;
|
|
|
|
},
|
|
|
|
onAdd(g) {
|
|
|
|
return this.on("add", g);
|
|
|
|
},
|
|
|
|
onUpdate(g) {
|
|
|
|
return this.on("update", g);
|
|
|
|
},
|
|
|
|
onDraw(g) {
|
|
|
|
return this.on("draw", g);
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-17 22:57:39 +00:00
|
|
|
onDestroy(g) {
|
|
|
|
return this.on("destroy", g);
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-17 22:57:39 +00:00
|
|
|
clearEvents() {
|
|
|
|
d.clear();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
E = [
|
|
|
|
"onKeyPress",
|
|
|
|
"onKeyPressRepeat",
|
|
|
|
"onKeyDown",
|
|
|
|
"onKeyRelease",
|
|
|
|
"onMousePress",
|
|
|
|
"onMouseDown",
|
|
|
|
"onMouseRelease",
|
|
|
|
"onMouseMove",
|
|
|
|
"onCharInput",
|
|
|
|
"onMouseMove",
|
|
|
|
"onTouchStart",
|
|
|
|
"onTouchMove",
|
|
|
|
"onTouchEnd",
|
|
|
|
"onScroll",
|
|
|
|
"onGamepadButtonPress",
|
|
|
|
"onGamepadButtonDown",
|
|
|
|
"onGamepadButtonRelease",
|
|
|
|
"onGamepadStick",
|
|
|
|
];
|
|
|
|
for (let g of E)
|
|
|
|
A[g] = (...C) => {
|
|
|
|
let N = m[g](...C);
|
|
|
|
return h.push(N), A.onDestroy(() => N.cancel()), N;
|
2024-06-02 05:39:23 +00:00
|
|
|
};
|
2024-06-17 22:57:39 +00:00
|
|
|
for (let g of r) A.use(g);
|
|
|
|
return A;
|
|
|
|
}
|
|
|
|
s(kn, "make");
|
|
|
|
function ut(r, i, c) {
|
|
|
|
return (
|
|
|
|
O.objEvents[r] || (O.objEvents[r] = new _t()),
|
|
|
|
O.objEvents.on(r, (d, ...h) => {
|
|
|
|
d.is(i) && c(d, ...h);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(ut, "on");
|
|
|
|
let Bs = Fe(
|
|
|
|
(r) => {
|
|
|
|
let i = Bt([{ update: r }]);
|
|
|
|
return {
|
2024-06-02 05:39:23 +00:00
|
|
|
get paused() {
|
2024-06-17 22:57:39 +00:00
|
|
|
return i.paused;
|
2024-06-02 05:39:23 +00:00
|
|
|
},
|
2024-06-17 22:57:39 +00:00
|
|
|
set paused(c) {
|
|
|
|
i.paused = c;
|
2024-06-02 05:39:23 +00:00
|
|
|
},
|
2024-06-17 22:57:39 +00:00
|
|
|
cancel: () => i.destroy(),
|
|
|
|
};
|
|
|
|
},
|
|
|
|
(r, i) => ut("update", r, i)
|
|
|
|
),
|
|
|
|
Fs = Fe(
|
|
|
|
(r) => {
|
|
|
|
let i = Bt([{ draw: r }]);
|
|
|
|
return {
|
|
|
|
get paused() {
|
|
|
|
return i.hidden;
|
2024-06-02 05:39:23 +00:00
|
|
|
},
|
2024-06-17 22:57:39 +00:00
|
|
|
set paused(c) {
|
|
|
|
i.hidden = c;
|
2024-06-02 05:39:23 +00:00
|
|
|
},
|
2024-06-17 22:57:39 +00:00
|
|
|
cancel: () => i.destroy(),
|
2024-06-02 05:39:23 +00:00
|
|
|
};
|
2024-06-17 22:57:39 +00:00
|
|
|
},
|
|
|
|
(r, i) => ut("draw", r, i)
|
|
|
|
),
|
|
|
|
Nn = Fe(
|
|
|
|
(r) => O.events.on("add", r),
|
|
|
|
(r, i) => ut("add", r, i)
|
|
|
|
),
|
|
|
|
Ur = Fe(
|
|
|
|
(r) => O.events.on("destroy", r),
|
|
|
|
(r, i) => ut("destroy", r, i)
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
2024-06-17 22:57:39 +00:00
|
|
|
function Is(r, i, c) {
|
|
|
|
return ut("collide", r, (d, h, y) => h.is(i) && c(d, h, y));
|
|
|
|
}
|
|
|
|
s(Is, "onCollide");
|
|
|
|
function Ls(r, i, c) {
|
|
|
|
return ut("collideUpdate", r, (d, h, y) => h.is(i) && c(d, h, y));
|
|
|
|
}
|
|
|
|
s(Ls, "onCollideUpdate");
|
|
|
|
function js(r, i, c) {
|
|
|
|
return ut("collideEnd", r, (d, h, y) => h.is(i) && c(d, h, y));
|
|
|
|
}
|
|
|
|
s(js, "onCollideEnd");
|
|
|
|
function nn(r, i) {
|
|
|
|
Hn(r, { recursive: !0 }).forEach(i), Nn(r, i);
|
|
|
|
}
|
|
|
|
s(nn, "forAllCurrentAndFuture");
|
|
|
|
let ks = Fe(
|
|
|
|
(r) => m.onMousePress(r),
|
|
|
|
(r, i) => {
|
2024-06-02 05:39:23 +00:00
|
|
|
let c = [];
|
|
|
|
return (
|
2024-06-17 22:57:39 +00:00
|
|
|
nn(r, (d) => {
|
|
|
|
if (!d.area)
|
2024-06-02 05:39:23 +00:00
|
|
|
throw new Error(
|
2024-06-17 22:57:39 +00:00
|
|
|
"onClick() requires the object to have area() component"
|
2024-06-02 05:39:23 +00:00
|
|
|
);
|
2024-06-17 22:57:39 +00:00
|
|
|
c.push(d.onClick(() => i(d)));
|
2024-06-02 05:39:23 +00:00
|
|
|
}),
|
2024-06-17 22:57:39 +00:00
|
|
|
tt.join(c)
|
2024-06-02 05:39:23 +00:00
|
|
|
);
|
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
);
|
|
|
|
function Ns(r, i) {
|
|
|
|
let c = [];
|
|
|
|
return (
|
|
|
|
nn(r, (d) => {
|
|
|
|
if (!d.area)
|
|
|
|
throw new Error(
|
|
|
|
"onHover() requires the object to have area() component"
|
|
|
|
);
|
|
|
|
c.push(d.onHover(() => i(d)));
|
|
|
|
}),
|
|
|
|
tt.join(c)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(Ns, "onHover");
|
|
|
|
function _s(r, i) {
|
|
|
|
let c = [];
|
|
|
|
return (
|
|
|
|
nn(r, (d) => {
|
|
|
|
if (!d.area)
|
|
|
|
throw new Error(
|
|
|
|
"onHoverUpdate() requires the object to have area() component"
|
|
|
|
);
|
|
|
|
c.push(d.onHoverUpdate(() => i(d)));
|
|
|
|
}),
|
|
|
|
tt.join(c)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(_s, "onHoverUpdate");
|
|
|
|
function Hs(r, i) {
|
|
|
|
let c = [];
|
|
|
|
return (
|
|
|
|
nn(r, (d) => {
|
|
|
|
if (!d.area)
|
|
|
|
throw new Error(
|
|
|
|
"onHoverEnd() requires the object to have area() component"
|
|
|
|
);
|
|
|
|
c.push(d.onHoverEnd(() => i(d)));
|
|
|
|
}),
|
|
|
|
tt.join(c)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(Hs, "onHoverEnd");
|
|
|
|
function Ks(r) {
|
|
|
|
O.gravity = r ? (O.gravity || T(0, 1)).unit().scale(r) : null;
|
|
|
|
}
|
|
|
|
s(Ks, "setGravity");
|
|
|
|
function qs() {
|
|
|
|
return O.gravity ? O.gravity.len() : 0;
|
|
|
|
}
|
|
|
|
s(qs, "getGravity");
|
|
|
|
function zs(r) {
|
|
|
|
O.gravity = r.unit().scale(O.gravity ? O.gravity.len() : 1);
|
|
|
|
}
|
|
|
|
s(zs, "setGravityDirection");
|
|
|
|
function Ws() {
|
|
|
|
return O.gravity ? O.gravity.unit() : T(0, 1);
|
|
|
|
}
|
|
|
|
s(Ws, "getGravityDirection");
|
|
|
|
function Ys(...r) {
|
|
|
|
r.length === 1 || r.length === 2
|
|
|
|
? ((w.bgColor = ce(r[0])), r[1] && (w.bgAlpha = r[1]))
|
|
|
|
: (r.length === 3 || r.length === 4) &&
|
|
|
|
((w.bgColor = ce(r[0], r[1], r[2])), r[3] && (w.bgAlpha = r[3])),
|
|
|
|
b.clearColor(
|
|
|
|
w.bgColor.r / 255,
|
|
|
|
w.bgColor.g / 255,
|
|
|
|
w.bgColor.b / 255,
|
|
|
|
w.bgAlpha
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
2024-06-17 22:57:39 +00:00
|
|
|
}
|
|
|
|
s(Ys, "setBackground");
|
|
|
|
function Xs() {
|
|
|
|
return w.bgColor.clone();
|
|
|
|
}
|
|
|
|
s(Xs, "getBackground");
|
|
|
|
function $s(...r) {
|
|
|
|
return {
|
|
|
|
id: "color",
|
|
|
|
color: ce(...r),
|
|
|
|
inspect() {
|
|
|
|
return this.color.toString();
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s($s, "color");
|
|
|
|
function _n(r, i) {
|
|
|
|
return Number(r.toFixed(i));
|
|
|
|
}
|
|
|
|
s(_n, "toFixed");
|
|
|
|
function Pr(r) {
|
|
|
|
return r.fixed ? !0 : r.parent ? Pr(r.parent) : !1;
|
|
|
|
}
|
|
|
|
s(Pr, "isFixed");
|
|
|
|
function Qs(r) {
|
|
|
|
return {
|
|
|
|
color: r.color,
|
|
|
|
opacity: r.opacity,
|
|
|
|
anchor: r.anchor,
|
|
|
|
outline: r.outline,
|
|
|
|
shader: r.shader,
|
|
|
|
uniform: r.uniform,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(Qs, "getRenderProps");
|
|
|
|
function Js(r) {
|
|
|
|
L.loaded ? r() : O.events.on("load", r);
|
|
|
|
}
|
|
|
|
s(Js, "onLoad");
|
|
|
|
function Zs(r, i) {
|
|
|
|
O.scenes[r] = i;
|
|
|
|
}
|
|
|
|
s(Zs, "scene");
|
|
|
|
function ei(r, ...i) {
|
|
|
|
if (!O.scenes[r]) throw new Error(`Scene not found: ${r}`);
|
|
|
|
O.events.onOnce("frameEnd", () => {
|
|
|
|
O.events.trigger("sceneLeave", r),
|
|
|
|
m.events.clear(),
|
|
|
|
O.events.clear(),
|
|
|
|
O.objEvents.clear(),
|
|
|
|
[...O.root.children].forEach((c) => {
|
|
|
|
(!c.stay || (c.scenesToStay && !c.scenesToStay.includes(r))) &&
|
|
|
|
O.root.remove(c);
|
2024-06-02 05:39:23 +00:00
|
|
|
}),
|
2024-06-17 22:57:39 +00:00
|
|
|
O.root.clearEvents(),
|
|
|
|
Lr(),
|
|
|
|
(O.cam = {
|
|
|
|
pos: null,
|
|
|
|
scale: T(1),
|
|
|
|
angle: 0,
|
|
|
|
shake: 0,
|
|
|
|
transform: new De(),
|
|
|
|
}),
|
|
|
|
O.scenes[r](...i);
|
|
|
|
}),
|
|
|
|
(O.currentScene = r);
|
|
|
|
}
|
|
|
|
s(ei, "go");
|
|
|
|
function ti(r) {
|
|
|
|
return O.events.on("sceneLeave", r);
|
|
|
|
}
|
|
|
|
s(ti, "onSceneLeave");
|
|
|
|
function ni() {
|
|
|
|
return O.currentScene;
|
|
|
|
}
|
|
|
|
s(ni, "getSceneName");
|
|
|
|
function ri(r, i) {
|
|
|
|
try {
|
|
|
|
return JSON.parse(window.localStorage[r]);
|
|
|
|
} catch {
|
|
|
|
return i ? (Mr(r, i), i) : null;
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
}
|
|
|
|
s(ri, "getData");
|
|
|
|
function Mr(r, i) {
|
|
|
|
window.localStorage[r] = JSON.stringify(i);
|
|
|
|
}
|
|
|
|
s(Mr, "setData");
|
|
|
|
function Dr(r, ...i) {
|
|
|
|
let c = r(Xe),
|
|
|
|
d;
|
|
|
|
typeof c == "function" ? (d = c(...i)(Xe)) : (d = c);
|
|
|
|
for (let h in d) (Xe[h] = d[h]), t.global !== !1 && (window[h] = d[h]);
|
|
|
|
return Xe;
|
|
|
|
}
|
|
|
|
s(Dr, "plug");
|
|
|
|
function rn() {
|
|
|
|
return T(Pe() / 2, ke() / 2);
|
|
|
|
}
|
|
|
|
s(rn, "center");
|
|
|
|
let oi;
|
|
|
|
((R) => (
|
|
|
|
(R[(R.None = 0)] = "None"),
|
|
|
|
(R[(R.Left = 1)] = "Left"),
|
|
|
|
(R[(R.Top = 2)] = "Top"),
|
|
|
|
(R[(R.LeftTop = 3)] = "LeftTop"),
|
|
|
|
(R[(R.Right = 4)] = "Right"),
|
|
|
|
(R[(R.Horizontal = 5)] = "Horizontal"),
|
|
|
|
(R[(R.RightTop = 6)] = "RightTop"),
|
|
|
|
(R[(R.HorizontalTop = 7)] = "HorizontalTop"),
|
|
|
|
(R[(R.Bottom = 8)] = "Bottom"),
|
|
|
|
(R[(R.LeftBottom = 9)] = "LeftBottom"),
|
|
|
|
(R[(R.Vertical = 10)] = "Vertical"),
|
|
|
|
(R[(R.LeftVertical = 11)] = "LeftVertical"),
|
|
|
|
(R[(R.RightBottom = 12)] = "RightBottom"),
|
|
|
|
(R[(R.HorizontalBottom = 13)] = "HorizontalBottom"),
|
|
|
|
(R[(R.RightVertical = 14)] = "RightVertical"),
|
|
|
|
(R[(R.All = 15)] = "All")
|
|
|
|
))((oi ||= {}));
|
|
|
|
function si(r, i) {
|
|
|
|
if (!i.tileWidth || !i.tileHeight)
|
|
|
|
throw new Error("Must provide tileWidth and tileHeight.");
|
|
|
|
let c = Bt([Wt(i.pos ?? T(0))]),
|
|
|
|
d = r.length,
|
|
|
|
h = 0,
|
|
|
|
y = null,
|
|
|
|
x = null,
|
|
|
|
A = null,
|
|
|
|
E = null,
|
|
|
|
g = s((U) => U.x + U.y * h, "tile2Hash"),
|
|
|
|
C = s((U) => T(Math.floor(U % h), Math.floor(U / h)), "hash2Tile"),
|
|
|
|
N = s(() => {
|
|
|
|
y = [];
|
|
|
|
for (let U of c.children) G(U);
|
|
|
|
}, "createSpatialMap"),
|
|
|
|
G = s((U) => {
|
|
|
|
let k = g(U.tilePos);
|
|
|
|
y[k] ? y[k].push(U) : (y[k] = [U]);
|
|
|
|
}, "insertIntoSpatialMap"),
|
|
|
|
F = s((U) => {
|
|
|
|
let k = g(U.tilePos);
|
|
|
|
if (y[k]) {
|
|
|
|
let I = y[k].indexOf(U);
|
|
|
|
I >= 0 && y[k].splice(I, 1);
|
|
|
|
}
|
|
|
|
}, "removeFromSpatialMap"),
|
|
|
|
S = s(() => {
|
|
|
|
let U = !1;
|
|
|
|
for (let k of c.children) {
|
|
|
|
let I = c.pos2Tile(k.pos);
|
|
|
|
(k.tilePos.x != I.x || k.tilePos.y != I.y) &&
|
|
|
|
((U = !0), F(k), (k.tilePos.x = I.x), (k.tilePos.y = I.y), G(k));
|
|
|
|
}
|
|
|
|
U && c.trigger("spatial_map_changed");
|
|
|
|
}, "updateSpatialMap"),
|
|
|
|
B = s(() => {
|
|
|
|
let U = c.getSpatialMap(),
|
|
|
|
k = c.numRows() * c.numColumns();
|
|
|
|
x ? (x.length = k) : (x = new Array(k)), x.fill(1, 0, k);
|
|
|
|
for (let I = 0; I < U.length; I++) {
|
|
|
|
let K = U[I];
|
|
|
|
if (K) {
|
|
|
|
let Z = 0;
|
|
|
|
for (let ee of K)
|
|
|
|
if (ee.isObstacle) {
|
|
|
|
Z = 1 / 0;
|
|
|
|
break;
|
|
|
|
} else Z += ee.cost;
|
|
|
|
x[I] = Z || 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, "createCostMap"),
|
|
|
|
R = s(() => {
|
|
|
|
let U = c.getSpatialMap(),
|
|
|
|
k = c.numRows() * c.numColumns();
|
|
|
|
A ? (A.length = k) : (A = new Array(k)), A.fill(15, 0, k);
|
|
|
|
for (let I = 0; I < U.length; I++) {
|
|
|
|
let K = U[I];
|
|
|
|
if (K) {
|
|
|
|
let Z = K.length,
|
|
|
|
ee = 15;
|
|
|
|
for (let ue = 0; ue < Z; ue++) ee |= K[ue].edgeMask;
|
|
|
|
A[I] = ee;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, "createEdgeMap"),
|
|
|
|
W = s(() => {
|
|
|
|
let U = c.numRows() * c.numColumns(),
|
|
|
|
k = s((K, Z) => {
|
|
|
|
let ee = [];
|
|
|
|
for (ee.push(K); ee.length > 0; ) {
|
|
|
|
let ue = ee.pop();
|
|
|
|
z(ue).forEach((ye) => {
|
|
|
|
E[ye] < 0 && ((E[ye] = Z), ee.push(ye));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, "traverse");
|
|
|
|
E ? (E.length = U) : (E = new Array(U)), E.fill(-1, 0, U);
|
|
|
|
let I = 0;
|
|
|
|
for (let K = 0; K < x.length; K++) {
|
|
|
|
if (E[K] >= 0) {
|
|
|
|
I++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
k(K, I), I++;
|
|
|
|
}
|
|
|
|
}, "createConnectivityMap"),
|
|
|
|
q = s((U, k) => x[k], "getCost"),
|
|
|
|
Y = s((U, k) => {
|
|
|
|
let I = C(U),
|
|
|
|
K = C(k);
|
|
|
|
return I.dist(K);
|
|
|
|
}, "getHeuristic"),
|
|
|
|
z = s((U, k) => {
|
|
|
|
let I = [],
|
|
|
|
K = Math.floor(U % h),
|
|
|
|
Z = K > 0 && A[U] & 1 && x[U - 1] !== 1 / 0,
|
|
|
|
ee = U >= h && A[U] & 2 && x[U - h] !== 1 / 0,
|
|
|
|
ue = K < h - 1 && A[U] & 4 && x[U + 1] !== 1 / 0,
|
|
|
|
ye = U < h * d - h - 1 && A[U] & 8 && x[U + h] !== 1 / 0;
|
|
|
|
return (
|
|
|
|
k
|
|
|
|
? (Z &&
|
|
|
|
(ee && I.push(U - h - 1),
|
|
|
|
I.push(U - 1),
|
|
|
|
ye && I.push(U + h - 1)),
|
|
|
|
ee && I.push(U - h),
|
|
|
|
ue &&
|
|
|
|
(ee && I.push(U - h + 1),
|
|
|
|
I.push(U + 1),
|
|
|
|
ye && I.push(U + h + 1)),
|
|
|
|
ye && I.push(U + h))
|
|
|
|
: (Z && I.push(U - 1),
|
|
|
|
ee && I.push(U - h),
|
|
|
|
ue && I.push(U + 1),
|
|
|
|
ye && I.push(U + h)),
|
|
|
|
I
|
2024-06-02 05:39:23 +00:00
|
|
|
);
|
2024-06-17 22:57:39 +00:00
|
|
|
}, "getNeighbours"),
|
|
|
|
Me = {
|
|
|
|
id: "level",
|
|
|
|
tileWidth() {
|
|
|
|
return i.tileWidth;
|
|
|
|
},
|
|
|
|
tileHeight() {
|
|
|
|
return i.tileHeight;
|
|
|
|
},
|
|
|
|
spawn(U, ...k) {
|
|
|
|
let I = T(...k),
|
|
|
|
K = (() => {
|
|
|
|
if (typeof U == "string") {
|
|
|
|
if (i.tiles[U]) {
|
|
|
|
if (typeof i.tiles[U] != "function")
|
|
|
|
throw new Error(
|
|
|
|
"Level symbol def must be a function returning a component list"
|
|
|
|
);
|
|
|
|
return i.tiles[U](I);
|
|
|
|
} else if (i.wildcardTile) return i.wildcardTile(U, I);
|
|
|
|
} else {
|
|
|
|
if (Array.isArray(U)) return U;
|
|
|
|
throw new Error("Expected a symbol or a component list");
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
if (!K) return null;
|
|
|
|
let Z = !1,
|
|
|
|
ee = !1;
|
|
|
|
for (let ye of K)
|
|
|
|
ye.id === "tile" && (ee = !0), ye.id === "pos" && (Z = !0);
|
|
|
|
Z || K.push(Wt()), ee || K.push(xr());
|
|
|
|
let ue = c.add(K);
|
|
|
|
return (
|
|
|
|
Z && (ue.tilePosOffset = ue.pos.clone()),
|
|
|
|
(ue.tilePos = I),
|
|
|
|
y &&
|
|
|
|
(G(ue),
|
|
|
|
this.trigger("spatial_map_changed"),
|
|
|
|
this.trigger("navigation_map_invalid")),
|
|
|
|
ue
|
|
|
|
);
|
|
|
|
},
|
|
|
|
numColumns() {
|
|
|
|
return h;
|
|
|
|
},
|
|
|
|
numRows() {
|
|
|
|
return d;
|
|
|
|
},
|
|
|
|
levelWidth() {
|
|
|
|
return h * this.tileWidth();
|
|
|
|
},
|
|
|
|
levelHeight() {
|
|
|
|
return d * this.tileHeight();
|
|
|
|
},
|
|
|
|
tile2Pos(...U) {
|
|
|
|
return T(...U).scale(this.tileWidth(), this.tileHeight());
|
|
|
|
},
|
|
|
|
pos2Tile(...U) {
|
|
|
|
let k = T(...U);
|
|
|
|
return T(
|
|
|
|
Math.floor(k.x / this.tileWidth()),
|
|
|
|
Math.floor(k.y / this.tileHeight())
|
|
|
|
);
|
|
|
|
},
|
|
|
|
getSpatialMap() {
|
|
|
|
return y || N(), y;
|
|
|
|
},
|
|
|
|
onSpatialMapChanged(U) {
|
|
|
|
return this.on("spatial_map_changed", U);
|
|
|
|
},
|
|
|
|
onNavigationMapInvalid(U) {
|
|
|
|
return this.on("navigation_map_invalid", U);
|
|
|
|
},
|
|
|
|
getAt(U) {
|
|
|
|
y || N();
|
|
|
|
let k = g(U);
|
|
|
|
return y[k] || [];
|
|
|
|
},
|
|
|
|
raycast(U, k) {
|
|
|
|
U = U.scale(1 / this.tileWidth(), 1 / this.tileHeight());
|
|
|
|
let I = to(
|
|
|
|
U,
|
|
|
|
k,
|
|
|
|
(K) => {
|
|
|
|
let Z = this.getAt(K);
|
|
|
|
if (Z.some((ue) => ue.isObstacle)) return !0;
|
|
|
|
let ee;
|
|
|
|
for (let ue of Z)
|
|
|
|
if (ue.is("area")) {
|
|
|
|
let ft = ue.worldArea().raycast(U, k);
|
|
|
|
ee
|
|
|
|
? ft.fraction < ee.fraction &&
|
|
|
|
((ee = ft), (ee.object = ue))
|
|
|
|
: ((ee = ft), (ee.object = ue));
|
|
|
|
}
|
|
|
|
return ee || !1;
|
|
|
|
},
|
|
|
|
64
|
|
|
|
);
|
|
|
|
return (
|
|
|
|
I &&
|
|
|
|
(I.point = I.point.scale(this.tileWidth(), this.tileHeight())),
|
|
|
|
I
|
|
|
|
);
|
|
|
|
},
|
|
|
|
update() {
|
|
|
|
y && S();
|
|
|
|
},
|
|
|
|
invalidateNavigationMap() {
|
|
|
|
(x = null), (A = null), (E = null);
|
|
|
|
},
|
|
|
|
onNavigationMapChanged(U) {
|
|
|
|
return this.on("navigation_map_changed", U);
|
|
|
|
},
|
|
|
|
getTilePath(U, k, I = {}) {
|
|
|
|
if (
|
|
|
|
(x || B(),
|
|
|
|
A || R(),
|
|
|
|
E || W(),
|
|
|
|
U.x < 0 ||
|
|
|
|
U.x >= h ||
|
|
|
|
U.y < 0 ||
|
|
|
|
U.y >= d ||
|
|
|
|
k.x < 0 ||
|
|
|
|
k.x >= h ||
|
|
|
|
k.y < 0 ||
|
|
|
|
k.y >= d)
|
|
|
|
)
|
|
|
|
return null;
|
|
|
|
let K = g(U),
|
|
|
|
Z = g(k);
|
|
|
|
if (x[Z] === 1 / 0) return null;
|
|
|
|
if (K === Z) return [];
|
|
|
|
if (E[K] != -1 && E[K] !== E[Z]) return null;
|
|
|
|
let ee = new ln((Ze, qn) => Ze.cost < qn.cost);
|
|
|
|
ee.insert({ cost: 0, node: K });
|
|
|
|
let ue = new Map();
|
|
|
|
ue.set(K, K);
|
|
|
|
let ye = new Map();
|
|
|
|
for (ye.set(K, 0); ee.length !== 0; ) {
|
|
|
|
let Ze = ee.remove()?.node;
|
|
|
|
if (Ze === Z) break;
|
|
|
|
let qn = z(Ze, I.allowDiagonals);
|
|
|
|
for (let gt of qn) {
|
|
|
|
let zn = (ye.get(Ze) || 0) + q(Ze, gt) + Y(gt, Z);
|
|
|
|
(!ye.has(gt) || zn < ye.get(gt)) &&
|
|
|
|
(ye.set(gt, zn),
|
|
|
|
ee.insert({ cost: zn, node: gt }),
|
|
|
|
ue.set(gt, Ze));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let ft = [],
|
|
|
|
Ft = Z,
|
|
|
|
Vi = C(Ft);
|
|
|
|
for (ft.push(Vi); Ft !== K; ) {
|
|
|
|
Ft = ue.get(Ft);
|
|
|
|
let Ze = C(Ft);
|
|
|
|
ft.push(Ze);
|
|
|
|
}
|
|
|
|
return ft.reverse();
|
|
|
|
},
|
|
|
|
getPath(U, k, I = {}) {
|
|
|
|
let K = this.tileWidth(),
|
|
|
|
Z = this.tileHeight(),
|
|
|
|
ee = this.getTilePath(this.pos2Tile(U), this.pos2Tile(k), I);
|
|
|
|
return ee
|
|
|
|
? [
|
|
|
|
U,
|
|
|
|
...ee
|
|
|
|
.slice(1, -1)
|
|
|
|
.map((ue) => ue.scale(K, Z).add(K / 2, Z / 2)),
|
|
|
|
k,
|
|
|
|
]
|
|
|
|
: null;
|
2024-06-02 05:39:23 +00:00
|
|
|
},
|
|
|
|
};
|
2024-06-17 22:57:39 +00:00
|
|
|
return (
|
|
|
|
c.use(Me),
|
|
|
|
c.onNavigationMapInvalid(() => {
|
|
|
|
c.invalidateNavigationMap(), c.trigger("navigation_map_changed");
|
|
|
|
}),
|
|
|
|
r.forEach((U, k) => {
|
|
|
|
let I = U.split("");
|
|
|
|
(h = Math.max(I.length, h)),
|
|
|
|
I.forEach((K, Z) => {
|
|
|
|
c.spawn(K, T(Z, k));
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
c
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(si, "addLevel");
|
|
|
|
function ii(r) {
|
|
|
|
let i = m.canvas.captureStream(r),
|
|
|
|
c = X.ctx.createMediaStreamDestination();
|
|
|
|
X.masterNode.connect(c);
|
|
|
|
let d = new MediaRecorder(i),
|
|
|
|
h = [];
|
|
|
|
return (
|
|
|
|
(d.ondataavailable = (y) => {
|
|
|
|
y.data.size > 0 && h.push(y.data);
|
|
|
|
}),
|
|
|
|
(d.onerror = () => {
|
|
|
|
X.masterNode.disconnect(c), i.getTracks().forEach((y) => y.stop());
|
2024-06-02 05:39:23 +00:00
|
|
|
}),
|
2024-06-17 22:57:39 +00:00
|
|
|
d.start(),
|
|
|
|
{
|
|
|
|
resume() {
|
|
|
|
d.resume();
|
|
|
|
},
|
|
|
|
pause() {
|
|
|
|
d.pause();
|
|
|
|
},
|
|
|
|
stop() {
|
|
|
|
return (
|
|
|
|
d.stop(),
|
|
|
|
X.masterNode.disconnect(c),
|
|
|
|
i.getTracks().forEach((y) => y.stop()),
|
|
|
|
new Promise((y) => {
|
|
|
|
d.onstop = () => {
|
|
|
|
y(new Blob(h, { type: "video/mp4" }));
|
|
|
|
};
|
|
|
|
})
|
|
|
|
);
|
|
|
|
},
|
|
|
|
download(y = "kaboom.mp4") {
|
|
|
|
this.stop().then((x) => ur(y, x));
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(ii, "record");
|
|
|
|
function ai() {
|
|
|
|
return document.activeElement === m.canvas;
|
|
|
|
}
|
|
|
|
s(ai, "isFocused");
|
|
|
|
function ci(r) {
|
|
|
|
r.destroy();
|
|
|
|
}
|
|
|
|
s(ci, "destroy");
|
|
|
|
let Bt = O.root.add.bind(O.root),
|
|
|
|
ui = O.root.readd.bind(O.root),
|
|
|
|
li = O.root.removeAll.bind(O.root),
|
|
|
|
Hn = O.root.get.bind(O.root),
|
|
|
|
mi = O.root.wait.bind(O.root),
|
|
|
|
di = O.root.loop.bind(O.root),
|
|
|
|
hi = O.root.tween.bind(O.root),
|
|
|
|
pi = s(function (r, i) {
|
|
|
|
if (O.layers) throw Error("Layers can only be assigned once.");
|
|
|
|
let c = r.indexOf(i);
|
|
|
|
if (c == -1)
|
|
|
|
throw Error(
|
|
|
|
"The default layer name should be present in the layers list."
|
|
|
|
);
|
|
|
|
(O.layers = r), (O.defaultLayerIndex = c);
|
|
|
|
}, "layers");
|
|
|
|
function Gr(r = 2, i = 1) {
|
|
|
|
let c = 0;
|
|
|
|
return {
|
|
|
|
require: ["scale"],
|
|
|
|
update() {
|
|
|
|
let d = Math.sin(c * r) * i;
|
|
|
|
d < 0 && this.destroy(), (this.scale = T(d)), (c += jn());
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
s(Gr, "boom");
|
|
|
|
let fi = Te(null, gs),
|
|
|
|
gi = Te(null, ps);
|
|
|
|
function bi(r, i = {}) {
|
|
|
|
let c = Bt([Wt(r), yr()]),
|
|
|
|
d = (i.speed || 1) * 5,
|
|
|
|
h = i.scale || 1;
|
|
|
|
c.add([wn(gi), Yt(0), Tn("center"), Gr(d, h), ...(i.comps ?? [])]);
|
|
|
|
let y = c.add([wn(fi), Yt(0), Tn("center"), Cn(), ...(i.comps ?? [])]);
|
|
|
|
return (
|
|
|
|
y.wait(0.4 / d, () => y.use(Gr(d, h))),
|
|
|
|
y.onDestroy(() => c.destroy()),
|
|
|
|
c
|
|
|
|
);
|
|
|
|
}
|
|
|
|
s(bi, "addKaboom");
|
|
|
|
function Br() {
|
|
|
|
O.root.update();
|
|
|
|
}
|
|
|
|
s(Br, "updateFrame");
|
|
|
|
class Kn {
|
|
|
|
static {
|
|
|
|
s(this, "Collision");
|
|
|
|
}
|
|
|
|
source;
|
|
|
|
target;
|
|
|
|
displacement;
|
|
|
|
resolved = !1;
|
|
|
|
constructor(i, c, d, h = !1) {
|
|
|
|
(this.source = i),
|
|
|
|
(this.target = c),
|
|
|
|
(this.displacement = d),
|
|
|
|
(this.resolved = h);
|
|
|
|
}
|
|
|
|
reverse() {
|
|
|
|
return new Kn(
|
|
|
|
this.target,
|
|
|
|
this.source,
|
|
|
|
this.displacement.scale(-1),
|
|
|
|
this.resolved
|
|
|
|
);
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
hasOverlap() {
|
|
|
|
return !this.displacement.isZero();
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
isLeft() {
|
|
|
|
return this.displacement.cross(O.gravity || T(0, 1)) > 0;
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
isRight() {
|
|
|
|
return this.displacement.cross(O.gravity || T(0, 1)) < 0;
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
isTop() {
|
|
|
|
return this.displacement.dot(O.gravity || T(0, 1)) > 0;
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
isBottom() {
|
|
|
|
return this.displacement.dot(O.gravity || T(0, 1)) < 0;
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
preventResolution() {
|
|
|
|
this.resolved = !0;
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
}
|
|
|
|
function vi() {
|
|
|
|
let r = {},
|
|
|
|
i = t.hashGridSize || 64,
|
|
|
|
c = new De(),
|
|
|
|
d = [];
|
|
|
|
function h(y) {
|
|
|
|
if (
|
|
|
|
(d.push(c.clone()),
|
|
|
|
y.pos && c.translate(y.pos),
|
|
|
|
y.scale && c.scale(y.scale),
|
|
|
|
y.angle && c.rotate(y.angle),
|
|
|
|
(y.transform = c.clone()),
|
|
|
|
y.c("area") && !y.paused)
|
|
|
|
) {
|
|
|
|
let x = y,
|
|
|
|
E = x.worldArea().bbox(),
|
|
|
|
g = Math.floor(E.pos.x / i),
|
|
|
|
C = Math.floor(E.pos.y / i),
|
|
|
|
N = Math.ceil((E.pos.x + E.width) / i),
|
|
|
|
G = Math.ceil((E.pos.y + E.height) / i),
|
|
|
|
F = new Set();
|
|
|
|
for (let S = g; S <= N; S++)
|
|
|
|
for (let B = C; B <= G; B++)
|
|
|
|
if (!r[S]) (r[S] = {}), (r[S][B] = [x]);
|
|
|
|
else if (!r[S][B]) r[S][B] = [x];
|
|
|
|
else {
|
|
|
|
let R = r[S][B];
|
|
|
|
e: for (let W of R) {
|
|
|
|
if (W.paused || !W.exists() || F.has(W.id)) continue;
|
|
|
|
for (let Y of x.collisionIgnore) if (W.is(Y)) continue e;
|
|
|
|
for (let Y of W.collisionIgnore) if (x.is(Y)) continue e;
|
|
|
|
let q = po(x.worldArea(), W.worldArea());
|
|
|
|
if (q) {
|
|
|
|
let Y = new Kn(x, W, q);
|
|
|
|
x.trigger("collideUpdate", W, Y);
|
|
|
|
let z = Y.reverse();
|
|
|
|
(z.resolved = Y.resolved), W.trigger("collideUpdate", x, z);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
F.add(W.id);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
R.push(x);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
}
|
|
|
|
y.children.forEach(h), (c = d.pop());
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
s(h, "checkObj"), h(O.root);
|
|
|
|
}
|
|
|
|
s(vi, "checkFrame");
|
|
|
|
function xi() {
|
|
|
|
let r = O.cam,
|
|
|
|
i = D.fromAngle(kt(0, 360)).scale(r.shake);
|
|
|
|
(r.shake = Je(r.shake, 0, 5 * jn())),
|
|
|
|
(r.transform = new De()
|
|
|
|
.translate(rn())
|
|
|
|
.scale(r.scale)
|
|
|
|
.rotate(r.angle)
|
|
|
|
.translate((r.pos ?? rn()).scale(-1).add(i))),
|
|
|
|
O.root.draw(),
|
|
|
|
Se();
|
|
|
|
}
|
|
|
|
s(xi, "drawFrame");
|
|
|
|
function yi() {
|
|
|
|
let r = H();
|
|
|
|
O.events.numListeners("loading") > 0
|
|
|
|
? O.events.trigger("loading", r)
|
|
|
|
: ct(() => {
|
|
|
|
let i = Pe() / 2,
|
|
|
|
c = 24,
|
|
|
|
d = T(Pe() / 2, ke() / 2).sub(T(i / 2, c / 2));
|
|
|
|
V({ pos: T(0), width: Pe(), height: ke(), color: ce(0, 0, 0) }),
|
|
|
|
V({
|
|
|
|
pos: d,
|
|
|
|
width: i,
|
|
|
|
height: c,
|
|
|
|
fill: !1,
|
|
|
|
outline: { width: 4 },
|
|
|
|
}),
|
|
|
|
V({ pos: d, width: i * r, height: c });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
s(yi, "drawLoadScreen");
|
|
|
|
function Fr(r, i) {
|
|
|
|
ct(() => {
|
|
|
|
let c = T(8);
|
|
|
|
Ue(), te(r);
|
|
|
|
let d = Ot({
|
|
|
|
text: i,
|
|
|
|
font: qt,
|
|
|
|
size: 16,
|
|
|
|
pos: c,
|
|
|
|
color: ce(255, 255, 255),
|
|
|
|
fixed: !0,
|
2024-06-01 06:31:08 +00:00
|
|
|
}),
|
2024-06-17 22:57:39 +00:00
|
|
|
h = d.width + c.x * 2,
|
|
|
|
y = d.height + c.x * 2;
|
|
|
|
r.x + h >= Pe() && te(T(-h, 0)),
|
|
|
|
r.y + y >= ke() && te(T(0, -y)),
|
|
|
|
V({
|
|
|
|
width: h,
|
|
|
|
height: y,
|
|
|
|
color: ce(0, 0, 0),
|
|
|
|
radius: 4,
|
|
|
|
opacity: 0.8,
|
|
|
|
fixed: !0,
|
2024-06-01 06:31:08 +00:00
|
|
|
}),
|
2024-06-17 22:57:39 +00:00
|
|
|
At(d),
|
|
|
|
Oe();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
s(Fr, "drawInspectText");
|
|
|
|
function wi() {
|
|
|
|
if (de.inspect) {
|
|
|
|
let r = null;
|
|
|
|
for (let i of O.root.get("*", { recursive: !0 }))
|
|
|
|
if (i.c("area") && i.isHovering()) {
|
|
|
|
r = i;
|
|
|
|
break;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
if ((O.root.drawInspect(), r)) {
|
|
|
|
let i = [],
|
|
|
|
c = r.inspect();
|
|
|
|
for (let d in c) c[d] ? i.push(`${d}: ${c[d]}`) : i.push(`${d}`);
|
|
|
|
Fr(
|
|
|
|
As(Ar()),
|
|
|
|
i.join(`
|
|
|
|
`)
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
Fr(T(8), `FPS: ${de.fps()}`);
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
de.paused &&
|
2024-06-02 05:39:23 +00:00
|
|
|
ct(() => {
|
2024-06-17 22:57:39 +00:00
|
|
|
Ue(), te(Pe(), 0), te(-8, 8);
|
|
|
|
let r = 32;
|
|
|
|
V({
|
|
|
|
width: r,
|
|
|
|
height: r,
|
|
|
|
anchor: "topright",
|
|
|
|
color: ce(0, 0, 0),
|
|
|
|
opacity: 0.8,
|
|
|
|
radius: 4,
|
|
|
|
fixed: !0,
|
|
|
|
});
|
|
|
|
for (let i = 1; i <= 2; i++)
|
|
|
|
V({
|
|
|
|
width: 4,
|
|
|
|
height: r * 0.6,
|
|
|
|
anchor: "center",
|
|
|
|
pos: T((-r / 3) * i, r * 0.5),
|
|
|
|
color: ce(255, 255, 255),
|
|
|
|
radius: 2,
|
2024-06-02 05:39:23 +00:00
|
|
|
fixed: !0,
|
2024-06-17 22:57:39 +00:00
|
|
|
});
|
|
|
|
Oe();
|
|
|
|
}),
|
|
|
|
de.timeScale !== 1 &&
|
2024-06-02 05:39:23 +00:00
|
|
|
ct(() => {
|
2024-06-17 22:57:39 +00:00
|
|
|
Ue(), te(Pe(), ke()), te(-8, -8);
|
|
|
|
let r = 8,
|
|
|
|
i = Ot({
|
|
|
|
text: de.timeScale.toFixed(1),
|
|
|
|
font: qt,
|
|
|
|
size: 16,
|
|
|
|
color: ce(255, 255, 255),
|
|
|
|
pos: T(-r),
|
|
|
|
anchor: "botright",
|
|
|
|
fixed: !0,
|
|
|
|
});
|
|
|
|
V({
|
|
|
|
width: i.width + r * 2 + r * 4,
|
|
|
|
height: i.height + r * 2,
|
|
|
|
anchor: "botright",
|
|
|
|
color: ce(0, 0, 0),
|
2024-06-01 06:31:08 +00:00
|
|
|
opacity: 0.8,
|
|
|
|
radius: 4,
|
|
|
|
fixed: !0,
|
|
|
|
});
|
2024-06-17 22:57:39 +00:00
|
|
|
for (let c = 0; c < 2; c++) {
|
|
|
|
let d = de.timeScale < 1;
|
|
|
|
$e({
|
|
|
|
p1: T(-i.width - r * (d ? 2 : 3.5), -r),
|
|
|
|
p2: T(-i.width - r * (d ? 2 : 3.5), -r - i.height),
|
|
|
|
p3: T(-i.width - r * (d ? 3.5 : 2), -r - i.height / 2),
|
|
|
|
pos: T(-c * r * 1 + (d ? -r * 0.5 : 0), 0),
|
|
|
|
color: ce(255, 255, 255),
|
2024-06-01 06:31:08 +00:00
|
|
|
fixed: !0,
|
|
|
|
});
|
2024-06-17 22:57:39 +00:00
|
|
|
}
|
|
|
|
At(i), Oe();
|
2024-06-01 06:31:08 +00:00
|
|
|
}),
|
2024-06-17 22:57:39 +00:00
|
|
|
de.curRecording &&
|
|
|
|
ct(() => {
|
|
|
|
Ue(),
|
|
|
|
te(0, ke()),
|
|
|
|
te(24, -24),
|
|
|
|
pt({
|
|
|
|
radius: 12,
|
|
|
|
color: ce(255, 0, 0),
|
|
|
|
opacity: $n(0, 1, m.time() * 4),
|
2024-06-01 06:31:08 +00:00
|
|
|
fixed: !0,
|
2024-06-17 22:57:39 +00:00
|
|
|
}),
|
|
|
|
Oe();
|
|
|
|
}),
|
|
|
|
de.showLog &&
|
|
|
|
O.logs.length > 0 &&
|
|
|
|
ct(() => {
|
|
|
|
Ue(), te(0, ke()), te(8, -8);
|
|
|
|
let r = 8,
|
|
|
|
i = [];
|
|
|
|
for (let d of O.logs) {
|
|
|
|
let h = "",
|
|
|
|
y = d.msg instanceof Error ? "error" : "info";
|
|
|
|
(h += `[time]${d.time.toFixed(2)}[/time]`),
|
|
|
|
(h += " "),
|
|
|
|
(h += `[${y}]${
|
|
|
|
d.msg?.toString ? d.msg.toString() : d.msg
|
|
|
|
}[/${y}]`),
|
|
|
|
i.push(h);
|
|
|
|
}
|
|
|
|
O.logs = O.logs.filter((d) => m.time() - d.time < (t.logTime || 4));
|
|
|
|
let c = Ot({
|
|
|
|
text: i.join(`
|
|
|
|
`),
|
|
|
|
font: qt,
|
|
|
|
pos: T(r, -r),
|
|
|
|
anchor: "botleft",
|
|
|
|
size: 16,
|
|
|
|
width: Pe() * 0.6,
|
|
|
|
lineSpacing: r / 2,
|
|
|
|
fixed: !0,
|
|
|
|
styles: {
|
|
|
|
time: { color: ce(127, 127, 127) },
|
|
|
|
info: { color: ce(255, 255, 255) },
|
|
|
|
error: { color: ce(255, 0, 127) },
|
|
|
|
},
|
|
|
|
});
|
|
|
|
V({
|
|
|
|
width: c.width + r * 2,
|
|
|
|
height: c.height + r * 2,
|
|
|
|
anchor: "botleft",
|
|
|
|
color: ce(0, 0, 0),
|
|
|
|
radius: 4,
|
|
|
|
opacity: 0.8,
|
|
|
|
fixed: !0,
|
2024-06-02 05:39:23 +00:00
|
|
|
}),
|
2024-06-17 22:57:39 +00:00
|
|
|
At(c),
|
|
|
|
Oe();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
s(wi, "drawDebug");
|
|
|
|
function Ci(r) {
|
|
|
|
O.events.on("loading", r);
|
|
|
|
}
|
|
|
|
s(Ci, "onLoading");
|
|
|
|
function Ti(r) {
|
|
|
|
m.onResize(r);
|
|
|
|
}
|
|
|
|
s(Ti, "onResize");
|
|
|
|
function Ei(r) {
|
|
|
|
O.events.on("error", r);
|
|
|
|
}
|
|
|
|
s(Ei, "onError");
|
|
|
|
function Si(r) {
|
|
|
|
console.error(r),
|
|
|
|
X.ctx.suspend(),
|
|
|
|
m.run(() => {
|
|
|
|
Gt(),
|
2024-06-02 05:39:23 +00:00
|
|
|
ct(() => {
|
2024-06-17 22:57:39 +00:00
|
|
|
let d = Pe(),
|
|
|
|
h = ke(),
|
|
|
|
y = {
|
|
|
|
size: 36,
|
|
|
|
width: d - 32 * 2,
|
|
|
|
letterSpacing: 4,
|
|
|
|
lineSpacing: 4,
|
|
|
|
font: qt,
|
2024-06-01 06:31:08 +00:00
|
|
|
fixed: !0,
|
2024-06-17 22:57:39 +00:00
|
|
|
};
|
|
|
|
V({ width: d, height: h, color: ce(0, 0, 255), fixed: !0 });
|
|
|
|
let x = Ot({
|
|
|
|
...y,
|
|
|
|
text: "Error",
|
|
|
|
pos: T(32),
|
|
|
|
color: ce(255, 128, 0),
|
2024-06-02 05:39:23 +00:00
|
|
|
fixed: !0,
|
|
|
|
});
|
2024-06-17 22:57:39 +00:00
|
|
|
At(x),
|
|
|
|
Or({
|
|
|
|
...y,
|
|
|
|
text: r.message,
|
|
|
|
pos: T(32, 32 + x.height + 16),
|
2024-06-02 05:39:23 +00:00
|
|
|
fixed: !0,
|
2024-06-17 22:57:39 +00:00
|
|
|
}),
|
|
|
|
Oe(),
|
|
|
|
O.events.trigger("error", r);
|
|
|
|
}),
|
|
|
|
Tt();
|
2024-06-01 06:31:08 +00:00
|
|
|
});
|
2024-06-17 22:57:39 +00:00
|
|
|
}
|
|
|
|
s(Si, "handleErr");
|
|
|
|
function Oi(r) {
|
|
|
|
P.push(r);
|
|
|
|
}
|
|
|
|
s(Oi, "onCleanup");
|
|
|
|
function Ai() {
|
|
|
|
O.events.onOnce("frameEnd", () => {
|
|
|
|
m.quit(),
|
|
|
|
b.clear(
|
|
|
|
b.COLOR_BUFFER_BIT | b.DEPTH_BUFFER_BIT | b.STENCIL_BUFFER_BIT
|
|
|
|
);
|
|
|
|
let r = b.getParameter(b.MAX_TEXTURE_IMAGE_UNITS);
|
|
|
|
for (let i = 0; i < r; i++)
|
|
|
|
b.activeTexture(b.TEXTURE0 + i),
|
|
|
|
b.bindTexture(b.TEXTURE_2D, null),
|
|
|
|
b.bindTexture(b.TEXTURE_CUBE_MAP, null);
|
|
|
|
b.bindBuffer(b.ARRAY_BUFFER, null),
|
|
|
|
b.bindBuffer(b.ELEMENT_ARRAY_BUFFER, null),
|
|
|
|
b.bindRenderbuffer(b.RENDERBUFFER, null),
|
|
|
|
b.bindFramebuffer(b.FRAMEBUFFER, null),
|
|
|
|
M.destroy(),
|
|
|
|
P.forEach((i) => i());
|
2024-06-02 05:39:23 +00:00
|
|
|
});
|
2024-06-17 22:57:39 +00:00
|
|
|
}
|
|
|
|
s(Ai, "quit");
|
|
|
|
let on = !0;
|
|
|
|
m.run(() => {
|
|
|
|
try {
|
|
|
|
L.loaded ||
|
|
|
|
(H() === 1 && !on && ((L.loaded = !0), O.events.trigger("load"))),
|
|
|
|
(!L.loaded && t.loadingScreen !== !1) || on
|
|
|
|
? (Gt(), yi(), Tt())
|
|
|
|
: (de.paused || Br(),
|
|
|
|
vi(),
|
|
|
|
Gt(),
|
|
|
|
xi(),
|
|
|
|
t.debug !== !1 && wi(),
|
|
|
|
Tt()),
|
|
|
|
on && (on = !1),
|
|
|
|
O.events.trigger("frameEnd");
|
|
|
|
} catch (r) {
|
|
|
|
Si(r);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
function Ir() {
|
|
|
|
let r = l,
|
|
|
|
i = b.drawingBufferWidth / r,
|
|
|
|
c = b.drawingBufferHeight / r;
|
|
|
|
if (t.letterbox) {
|
|
|
|
if (!t.width || !t.height)
|
|
|
|
throw new Error("Letterboxing requires width and height defined.");
|
|
|
|
let d = i / c,
|
|
|
|
h = t.width / t.height;
|
|
|
|
if (d > h) {
|
|
|
|
let y = c * h,
|
|
|
|
x = (i - y) / 2;
|
|
|
|
w.viewport = { x, y: 0, width: y, height: c };
|
|
|
|
} else {
|
|
|
|
let y = i / h,
|
|
|
|
x = (c - y) / 2;
|
|
|
|
w.viewport = { x: 0, y: x, width: i, height: y };
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
return;
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
2024-06-17 22:57:39 +00:00
|
|
|
if (t.stretch && (!t.width || !t.height))
|
|
|
|
throw new Error("Stretching requires width and height defined.");
|
|
|
|
w.viewport = { x: 0, y: 0, width: i, height: c };
|
|
|
|
}
|
|
|
|
s(Ir, "updateViewport");
|
|
|
|
function Lr() {
|
|
|
|
m.onHide(() => {
|
|
|
|
t.backgroundAudio || X.ctx.suspend();
|
|
|
|
}),
|
|
|
|
m.onShow(() => {
|
|
|
|
!t.backgroundAudio && !de.paused && X.ctx.resume();
|
2024-06-01 06:31:08 +00:00
|
|
|
}),
|
2024-06-17 22:57:39 +00:00
|
|
|
m.onResize(() => {
|
|
|
|
if (m.isFullscreen()) return;
|
|
|
|
let r = t.width && t.height;
|
|
|
|
(r && !t.stretch && !t.letterbox) ||
|
|
|
|
((n.width = n.offsetWidth * l),
|
|
|
|
(n.height = n.offsetHeight * l),
|
|
|
|
Ir(),
|
|
|
|
r ||
|
|
|
|
(w.frameBuffer.free(),
|
|
|
|
(w.frameBuffer = new yt(
|
|
|
|
M,
|
|
|
|
b.drawingBufferWidth,
|
|
|
|
b.drawingBufferHeight
|
|
|
|
)),
|
|
|
|
(w.width = b.drawingBufferWidth / l / o),
|
|
|
|
(w.height = b.drawingBufferHeight / l / o)));
|
|
|
|
}),
|
|
|
|
t.debug !== !1 &&
|
|
|
|
(m.onKeyPress(t.debugKey ?? "f1", () => (de.inspect = !de.inspect)),
|
|
|
|
m.onKeyPress("f2", () => de.clearLog()),
|
|
|
|
m.onKeyPress("f8", () => (de.paused = !de.paused)),
|
|
|
|
m.onKeyPress("f7", () => {
|
|
|
|
de.timeScale = _n(Qe(de.timeScale - 0.2, 0, 2), 1);
|
2024-06-01 06:31:08 +00:00
|
|
|
}),
|
2024-06-17 22:57:39 +00:00
|
|
|
m.onKeyPress("f9", () => {
|
|
|
|
de.timeScale = _n(Qe(de.timeScale + 0.2, 0, 2), 1);
|
2024-06-01 06:31:08 +00:00
|
|
|
}),
|
2024-06-17 22:57:39 +00:00
|
|
|
m.onKeyPress("f10", () => de.stepFrame())),
|
|
|
|
t.burp && m.onKeyPress("b", () => en());
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
(s(Lr, "initEvents"),
|
|
|
|
Ir(),
|
|
|
|
Lr(),
|
|
|
|
(Xe = {
|
|
|
|
_k: {
|
|
|
|
kaboomCtx: Xe,
|
|
|
|
app: m,
|
|
|
|
game: O,
|
|
|
|
isFixed: Pr,
|
|
|
|
toFixed: _n,
|
|
|
|
getViewportScale: Ts,
|
|
|
|
getRenderProps: Qs,
|
|
|
|
resolveSprite: Qt,
|
|
|
|
drawTexture: Et,
|
|
|
|
calcTransform: Rr,
|
|
|
|
},
|
|
|
|
VERSION: ba,
|
|
|
|
loadRoot: ie,
|
|
|
|
loadProgress: H,
|
|
|
|
loadSprite: Te,
|
|
|
|
loadSpriteAtlas: Ie,
|
|
|
|
loadSound: Ee,
|
|
|
|
loadMusic: Re,
|
|
|
|
loadBitmapFont: Ce,
|
|
|
|
loadFont: pe,
|
|
|
|
loadShader: He,
|
|
|
|
loadShaderURL: dt,
|
|
|
|
loadAseprite: _e,
|
|
|
|
loadPedit: Ne,
|
|
|
|
loadBean: ze,
|
|
|
|
loadJSON: se,
|
|
|
|
load: oe,
|
|
|
|
getSprite: ot,
|
|
|
|
getSound: st,
|
|
|
|
getFont: Ct,
|
|
|
|
getBitmapFont: Xt,
|
|
|
|
getShader: $t,
|
|
|
|
getAsset: An,
|
|
|
|
Asset: Ve,
|
|
|
|
SpriteData: _,
|
|
|
|
SoundData: $,
|
|
|
|
width: Pe,
|
|
|
|
height: ke,
|
|
|
|
center: rn,
|
|
|
|
dt: jn,
|
|
|
|
time: m.time,
|
|
|
|
screenshot: m.screenshot,
|
|
|
|
record: ii,
|
|
|
|
isFocused: ai,
|
|
|
|
setCursor: m.setCursor,
|
|
|
|
getCursor: m.getCursor,
|
|
|
|
setCursorLocked: m.setCursorLocked,
|
|
|
|
isCursorLocked: m.isCursorLocked,
|
|
|
|
setFullscreen: m.setFullscreen,
|
|
|
|
isFullscreen: m.isFullscreen,
|
|
|
|
isTouchscreen: m.isTouchscreen,
|
|
|
|
onLoad: Js,
|
|
|
|
onLoading: Ci,
|
|
|
|
onResize: Ti,
|
|
|
|
onGamepadConnect: m.onGamepadConnect,
|
|
|
|
onGamepadDisconnect: m.onGamepadDisconnect,
|
|
|
|
onError: Ei,
|
|
|
|
onCleanup: Oi,
|
|
|
|
camPos: Vs,
|
|
|
|
camScale: Rs,
|
|
|
|
camRot: Us,
|
|
|
|
camTransform: Ps,
|
|
|
|
shake: Ms,
|
|
|
|
toScreen: Ds,
|
|
|
|
toWorld: Gs,
|
|
|
|
setGravity: Ks,
|
|
|
|
getGravity: qs,
|
|
|
|
setGravityDirection: zs,
|
|
|
|
getGravityDirection: Ws,
|
|
|
|
setBackground: Ys,
|
|
|
|
getBackground: Xs,
|
|
|
|
getGamepads: m.getGamepads,
|
|
|
|
getTreeRoot: Ss,
|
|
|
|
add: Bt,
|
|
|
|
make: kn,
|
|
|
|
destroy: ci,
|
|
|
|
destroyAll: li,
|
|
|
|
get: Hn,
|
|
|
|
readd: ui,
|
|
|
|
pos: Wt,
|
|
|
|
scale: Yt,
|
|
|
|
rotate: ms,
|
|
|
|
color: $s,
|
|
|
|
opacity: qo,
|
|
|
|
anchor: Tn,
|
|
|
|
area: rs,
|
|
|
|
sprite: wn,
|
|
|
|
text: Qo,
|
|
|
|
polygon: Wo,
|
|
|
|
rect: Xo,
|
|
|
|
circle: No,
|
|
|
|
uvquad: Jo,
|
|
|
|
outline: zo,
|
|
|
|
body: os,
|
|
|
|
doubleJump: ss,
|
|
|
|
shader: $o,
|
|
|
|
timer: Cn,
|
|
|
|
fixed: is,
|
|
|
|
stay: yr,
|
|
|
|
health: es,
|
|
|
|
lifespan: ts,
|
|
|
|
state: ns,
|
|
|
|
z: ds,
|
|
|
|
layer: cs,
|
|
|
|
move: us,
|
|
|
|
offscreen: ls,
|
|
|
|
follow: as,
|
|
|
|
fadeIn: Ho,
|
|
|
|
mask: Ko,
|
|
|
|
drawon: _o,
|
|
|
|
raycast: Yo,
|
|
|
|
tile: xr,
|
|
|
|
agent: Zo,
|
|
|
|
on: ut,
|
|
|
|
onUpdate: Bs,
|
|
|
|
onDraw: Fs,
|
|
|
|
onAdd: Nn,
|
|
|
|
onDestroy: Ur,
|
|
|
|
onClick: ks,
|
|
|
|
onCollide: Is,
|
|
|
|
onCollideUpdate: Ls,
|
|
|
|
onCollideEnd: js,
|
|
|
|
onHover: Ns,
|
|
|
|
onHoverUpdate: _s,
|
|
|
|
onHoverEnd: Hs,
|
|
|
|
onKeyDown: m.onKeyDown,
|
|
|
|
onKeyPress: m.onKeyPress,
|
|
|
|
onKeyPressRepeat: m.onKeyPressRepeat,
|
|
|
|
onKeyRelease: m.onKeyRelease,
|
|
|
|
onMouseDown: m.onMouseDown,
|
|
|
|
onMousePress: m.onMousePress,
|
|
|
|
onMouseRelease: m.onMouseRelease,
|
|
|
|
onMouseMove: m.onMouseMove,
|
|
|
|
onCharInput: m.onCharInput,
|
|
|
|
onTouchStart: m.onTouchStart,
|
|
|
|
onTouchMove: m.onTouchMove,
|
|
|
|
onTouchEnd: m.onTouchEnd,
|
|
|
|
onScroll: m.onScroll,
|
|
|
|
onHide: m.onHide,
|
|
|
|
onShow: m.onShow,
|
|
|
|
onGamepadButtonDown: m.onGamepadButtonDown,
|
|
|
|
onGamepadButtonPress: m.onGamepadButtonPress,
|
|
|
|
onGamepadButtonRelease: m.onGamepadButtonRelease,
|
|
|
|
onGamepadStick: m.onGamepadStick,
|
|
|
|
mousePos: Ar,
|
|
|
|
mouseDeltaPos: m.mouseDeltaPos,
|
|
|
|
isKeyDown: m.isKeyDown,
|
|
|
|
isKeyPressed: m.isKeyPressed,
|
|
|
|
isKeyPressedRepeat: m.isKeyPressedRepeat,
|
|
|
|
isKeyReleased: m.isKeyReleased,
|
|
|
|
isMouseDown: m.isMouseDown,
|
|
|
|
isMousePressed: m.isMousePressed,
|
|
|
|
isMouseReleased: m.isMouseReleased,
|
|
|
|
isMouseMoved: m.isMouseMoved,
|
|
|
|
isGamepadButtonPressed: m.isGamepadButtonPressed,
|
|
|
|
isGamepadButtonDown: m.isGamepadButtonDown,
|
|
|
|
isGamepadButtonReleased: m.isGamepadButtonReleased,
|
|
|
|
getGamepadStick: m.getGamepadStick,
|
|
|
|
charInputted: m.charInputted,
|
|
|
|
loop: di,
|
|
|
|
wait: mi,
|
|
|
|
play: Zt,
|
|
|
|
volume: Un,
|
|
|
|
burp: en,
|
|
|
|
audioCtx: X.ctx,
|
|
|
|
Line: Ge,
|
|
|
|
Rect: me,
|
|
|
|
Circle: Be,
|
|
|
|
Ellipse: Ye,
|
|
|
|
Polygon: Ae,
|
|
|
|
Vec2: D,
|
|
|
|
Color: re,
|
|
|
|
Mat4: De,
|
|
|
|
Quad: he,
|
|
|
|
RNG: jt,
|
|
|
|
rand: kt,
|
|
|
|
randi: Qn,
|
|
|
|
randSeed: Hr,
|
|
|
|
vec2: T,
|
|
|
|
rgb: ce,
|
|
|
|
hsl2rgb: _r,
|
|
|
|
quad: ge,
|
|
|
|
choose: zr,
|
|
|
|
chooseMultiple: qr,
|
|
|
|
shuffle: Jn,
|
|
|
|
chance: Kr,
|
|
|
|
lerp: Je,
|
|
|
|
tween: hi,
|
|
|
|
easings: Mt,
|
|
|
|
map: et,
|
|
|
|
mapc: Nr,
|
|
|
|
wave: $n,
|
|
|
|
deg2rad: be,
|
|
|
|
rad2deg: lt,
|
|
|
|
clamp: Qe,
|
|
|
|
evaluateQuadratic: no,
|
|
|
|
evaluateQuadraticFirstDerivative: ro,
|
|
|
|
evaluateQuadraticSecondDerivative: oo,
|
|
|
|
evaluateBezier: un,
|
|
|
|
evaluateBezierFirstDerivative: so,
|
|
|
|
evaluateBezierSecondDerivative: io,
|
|
|
|
evaluateCatmullRom: ao,
|
|
|
|
evaluateCatmullRomFirstDerivative: co,
|
|
|
|
curveLengthApproximation: sr,
|
|
|
|
normalizedCurve: uo,
|
|
|
|
easingSteps: ho,
|
|
|
|
easingLinear: lo,
|
|
|
|
easingCubicBezier: mo,
|
|
|
|
testLineLine: an,
|
|
|
|
testRectRect: Zn,
|
|
|
|
testRectLine: cn,
|
|
|
|
testRectPoint: er,
|
|
|
|
testCirclePolygon: Nt,
|
|
|
|
testLinePoint: tr,
|
|
|
|
testLineCircle: Rt,
|
|
|
|
isConvex: ar,
|
|
|
|
triangulate: ir,
|
|
|
|
drawSprite: tn,
|
|
|
|
drawText: Or,
|
|
|
|
formatText: Ot,
|
|
|
|
drawRect: V,
|
|
|
|
drawLine: j,
|
|
|
|
drawLines: Ke,
|
|
|
|
drawTriangle: $e,
|
|
|
|
drawCircle: pt,
|
|
|
|
drawEllipse: wr,
|
|
|
|
drawUVQuad: ht,
|
|
|
|
drawPolygon: St,
|
|
|
|
drawCurve: at,
|
|
|
|
drawBezier: In,
|
|
|
|
drawFormattedText: At,
|
|
|
|
drawMasked: Tr,
|
|
|
|
drawSubtracted: Er,
|
|
|
|
pushTransform: Ue,
|
|
|
|
popTransform: Oe,
|
|
|
|
pushTranslate: te,
|
|
|
|
pushScale: We,
|
|
|
|
pushRotate: je,
|
|
|
|
pushMatrix: Fn,
|
|
|
|
usePostEffect: Gn,
|
|
|
|
makeCanvas: Mn,
|
|
|
|
debug: de,
|
|
|
|
scene: Zs,
|
|
|
|
getSceneName: ni,
|
|
|
|
go: ei,
|
|
|
|
onSceneLeave: ti,
|
|
|
|
layers: pi,
|
|
|
|
addLevel: si,
|
|
|
|
getData: ri,
|
|
|
|
setData: Mr,
|
|
|
|
download: dn,
|
|
|
|
downloadJSON: vo,
|
|
|
|
downloadText: cr,
|
|
|
|
downloadBlob: ur,
|
|
|
|
plug: Dr,
|
|
|
|
ASCII_CHARS: br,
|
|
|
|
canvas: m.canvas,
|
|
|
|
addKaboom: bi,
|
|
|
|
LEFT: D.LEFT,
|
|
|
|
RIGHT: D.RIGHT,
|
|
|
|
UP: D.UP,
|
|
|
|
DOWN: D.DOWN,
|
|
|
|
RED: re.RED,
|
|
|
|
GREEN: re.GREEN,
|
|
|
|
BLUE: re.BLUE,
|
|
|
|
YELLOW: re.YELLOW,
|
|
|
|
MAGENTA: re.MAGENTA,
|
|
|
|
CYAN: re.CYAN,
|
|
|
|
WHITE: re.WHITE,
|
|
|
|
BLACK: re.BLACK,
|
|
|
|
quit: Ai,
|
|
|
|
Event: we,
|
|
|
|
EventHandler: nt,
|
|
|
|
EventController: tt,
|
|
|
|
}),
|
|
|
|
t.plugins && t.plugins.forEach(Dr),
|
|
|
|
t.global !== !1)
|
|
|
|
)
|
|
|
|
for (let r in Xe) window[r] = Xe[r];
|
|
|
|
return t.focus !== !1 && m.canvas.focus(), Xe;
|
|
|
|
}, "kaplay"),
|
|
|
|
rm = wa;
|
|
|
|
export {
|
|
|
|
wt as anchorPt,
|
|
|
|
rm as default,
|
|
|
|
fe as getInternalContext,
|
|
|
|
ne as getKaboomContext,
|
|
|
|
ya as isKaboomCtx,
|
|
|
|
};
|
|
|
|
//# sourceMappingURL=kaboom.mjs.map
|