2024-06-01 06:31:08 +00:00
|
|
|
var kaplay = (() => {
|
2024-06-02 05:39:23 +00:00
|
|
|
var sn = Object.defineProperty;
|
|
|
|
var mi = Object.getOwnPropertyDescriptor;
|
|
|
|
var di = Object.getOwnPropertyNames;
|
|
|
|
var hi = Object.prototype.hasOwnProperty;
|
|
|
|
var i = (t, e) => sn(t, "name", { value: e, configurable: !0 });
|
|
|
|
var pi = (t, e) => {
|
|
|
|
for (var r in e) sn(t, r, { get: e[r], enumerable: !0 });
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
fi = (t, e, r, s) => {
|
2024-06-01 06:31:08 +00:00
|
|
|
if ((e && typeof e == "object") || typeof e == "function")
|
2024-06-02 05:39:23 +00:00
|
|
|
for (let a of di(e))
|
|
|
|
!hi.call(t, a) &&
|
|
|
|
a !== r &&
|
|
|
|
sn(t, a, {
|
|
|
|
get: () => e[a],
|
|
|
|
enumerable: !(s = mi(e, a)) || s.enumerable,
|
2024-06-01 06:31:08 +00:00
|
|
|
});
|
2024-06-02 05:39:23 +00:00
|
|
|
return t;
|
2024-06-01 06:31:08 +00:00
|
|
|
};
|
2024-06-02 05:39:23 +00:00
|
|
|
var gi = (t) => fi(sn({}, "__esModule", { value: !0 }), t);
|
|
|
|
var Br = (() => {
|
|
|
|
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 (r) => {
|
2024-06-01 06:31:08 +00:00
|
|
|
for (
|
2024-06-02 05:39:23 +00:00
|
|
|
var s = r.length,
|
|
|
|
a = new Uint8Array(
|
|
|
|
(((s - (r[s - 1] == "=") - (r[s - 2] == "=")) * 3) / 4) | 0
|
2024-06-01 06:31:08 +00:00
|
|
|
),
|
2024-06-02 05:39:23 +00:00
|
|
|
l = 0,
|
|
|
|
u = 0;
|
|
|
|
l < s;
|
2024-06-01 06:31:08 +00:00
|
|
|
|
|
|
|
) {
|
2024-06-02 05:39:23 +00:00
|
|
|
var f = t[r.charCodeAt(l++)],
|
|
|
|
y = t[r.charCodeAt(l++)],
|
|
|
|
m = t[r.charCodeAt(l++)],
|
|
|
|
V = t[r.charCodeAt(l++)];
|
|
|
|
(a[u++] = (f << 2) | (y >> 4)),
|
|
|
|
(a[u++] = (y << 4) | (m >> 2)),
|
|
|
|
(a[u++] = (m << 6) | V);
|
|
|
|
}
|
|
|
|
return a;
|
2024-06-01 06:31:08 +00:00
|
|
|
};
|
|
|
|
})();
|
2024-06-02 05:39:23 +00:00
|
|
|
var aa = {};
|
|
|
|
pi(aa, {
|
|
|
|
anchorPt: () => ht,
|
|
|
|
default: () => ia,
|
|
|
|
getInternalContext: () => fe,
|
|
|
|
getKaboomContext: () => J,
|
|
|
|
isKaboomCtx: () => as,
|
|
|
|
});
|
|
|
|
function ve(t) {
|
|
|
|
return (t * Math.PI) / 180;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(ve, "deg2rad");
|
|
|
|
function lt(t) {
|
|
|
|
return (t * 180) / Math.PI;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(lt, "rad2deg");
|
|
|
|
function Qe(t, e, r) {
|
|
|
|
return e > r ? Qe(t, r, e) : Math.min(Math.max(t, e), r);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Qe, "clamp");
|
|
|
|
function Je(t, e, r) {
|
|
|
|
if (typeof t == "number" && typeof e == "number") return t + (e - t) * r;
|
|
|
|
if (t instanceof T && e instanceof T) return t.lerp(e, r);
|
|
|
|
if (t instanceof ee && e instanceof ee) return t.lerp(e, r);
|
2024-06-01 06:31:08 +00:00
|
|
|
throw new Error(
|
2024-06-02 05:39:23 +00:00
|
|
|
`Bad value for lerp(): ${t}, ${e}. Only number, Vec2 and Color is supported.`
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Je, "lerp");
|
|
|
|
function dt(t, e, r, s, a) {
|
|
|
|
return s + ((t - e) / (r - e)) * (a - s);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(dt, "map");
|
|
|
|
function Ir(t, e, r, s, a) {
|
|
|
|
return Qe(dt(t, e, r, s, a), s, a);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Ir, "mapc");
|
|
|
|
var T = class t {
|
2024-06-01 06:31:08 +00:00
|
|
|
static {
|
2024-06-02 05:39:23 +00:00
|
|
|
i(this, "Vec2");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
x = 0;
|
|
|
|
y = 0;
|
2024-06-02 05:39:23 +00:00
|
|
|
constructor(e = 0, r = e) {
|
|
|
|
(this.x = e), (this.y = r);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
static fromAngle(e) {
|
2024-06-02 05:39:23 +00:00
|
|
|
let r = ve(e);
|
|
|
|
return new t(Math.cos(r), Math.sin(r));
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
static LEFT = new t(-1, 0);
|
|
|
|
static RIGHT = new t(1, 0);
|
|
|
|
static UP = new t(0, -1);
|
|
|
|
static DOWN = new t(0, 1);
|
2024-06-01 06:31:08 +00:00
|
|
|
clone() {
|
2024-06-02 05:39:23 +00:00
|
|
|
return new t(this.x, this.y);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
add(...e) {
|
2024-06-02 05:39:23 +00:00
|
|
|
let r = C(...e);
|
|
|
|
return new t(this.x + r.x, this.y + r.y);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
sub(...e) {
|
2024-06-02 05:39:23 +00:00
|
|
|
let r = C(...e);
|
|
|
|
return new t(this.x - r.x, this.y - r.y);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
scale(...e) {
|
2024-06-02 05:39:23 +00:00
|
|
|
let r = C(...e);
|
|
|
|
return new t(this.x * r.x, this.y * r.y);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
dist(...e) {
|
2024-06-02 05:39:23 +00:00
|
|
|
let r = C(...e);
|
|
|
|
return this.sub(r).len();
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
sdist(...e) {
|
2024-06-02 05:39:23 +00:00
|
|
|
let r = C(...e);
|
|
|
|
return this.sub(r).slen();
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
len() {
|
|
|
|
return Math.sqrt(this.dot(this));
|
|
|
|
}
|
|
|
|
slen() {
|
|
|
|
return this.dot(this);
|
|
|
|
}
|
|
|
|
unit() {
|
|
|
|
let e = this.len();
|
2024-06-02 05:39:23 +00:00
|
|
|
return e === 0 ? new t(0) : this.scale(1 / e);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
normal() {
|
2024-06-02 05:39:23 +00:00
|
|
|
return new t(this.y, -this.x);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
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) {
|
2024-06-02 05:39:23 +00:00
|
|
|
let r = C(...e);
|
|
|
|
return lt(Math.atan2(this.y - r.y, this.x - r.x));
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
angleBetween(...e) {
|
2024-06-02 05:39:23 +00:00
|
|
|
let r = C(...e);
|
|
|
|
return lt(Math.atan2(this.cross(r), this.dot(r)));
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
lerp(e, r) {
|
|
|
|
return new t(Je(this.x, e.x, r), Je(this.y, e.y, r));
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
slerp(e, r) {
|
|
|
|
let s = this.dot(e),
|
|
|
|
a = this.cross(e),
|
|
|
|
l = Math.atan2(a, s);
|
|
|
|
return this.scale(Math.sin((1 - r) * l))
|
|
|
|
.add(e.scale(Math.sin(r * l)))
|
|
|
|
.scale(1 / a);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
isZero() {
|
|
|
|
return this.x === 0 && this.y === 0;
|
|
|
|
}
|
|
|
|
toFixed(e) {
|
2024-06-02 05:39:23 +00:00
|
|
|
return new t(Number(this.x.toFixed(e)), Number(this.y.toFixed(e)));
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
transform(e) {
|
|
|
|
return e.multVec2(this);
|
|
|
|
}
|
|
|
|
eq(e) {
|
|
|
|
return this.x === e.x && this.y === e.y;
|
|
|
|
}
|
|
|
|
bbox() {
|
2024-06-02 05:39:23 +00:00
|
|
|
return new ue(this, 0, 0);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
toString() {
|
|
|
|
return `vec2(${this.x.toFixed(2)}, ${this.y.toFixed(2)})`;
|
|
|
|
}
|
|
|
|
};
|
2024-06-02 05:39:23 +00:00
|
|
|
function C(...t) {
|
|
|
|
if (t.length === 1) {
|
|
|
|
if (t[0] instanceof T) return new T(t[0].x, t[0].y);
|
|
|
|
if (Array.isArray(t[0]) && t[0].length === 2) return new T(...t[0]);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
return new T(...t);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(C, "vec2");
|
|
|
|
var ee = class t {
|
2024-06-01 06:31:08 +00:00
|
|
|
static {
|
2024-06-02 05:39:23 +00:00
|
|
|
i(this, "Color");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
r = 255;
|
|
|
|
g = 255;
|
|
|
|
b = 255;
|
2024-06-02 05:39:23 +00:00
|
|
|
constructor(e, r, s) {
|
|
|
|
(this.r = Qe(e, 0, 255)),
|
|
|
|
(this.g = Qe(r, 0, 255)),
|
|
|
|
(this.b = Qe(s, 0, 255));
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
static fromArray(e) {
|
2024-06-02 05:39:23 +00:00
|
|
|
return new t(e[0], e[1], e[2]);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
static fromHex(e) {
|
|
|
|
if (typeof e == "number")
|
2024-06-02 05:39:23 +00:00
|
|
|
return new t((e >> 16) & 255, (e >> 8) & 255, (e >> 0) & 255);
|
2024-06-01 06:31:08 +00:00
|
|
|
if (typeof e == "string") {
|
2024-06-02 05:39:23 +00:00
|
|
|
let r = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);
|
|
|
|
return new t(
|
|
|
|
parseInt(r[1], 16),
|
|
|
|
parseInt(r[2], 16),
|
|
|
|
parseInt(r[3], 16)
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
|
|
|
} else throw new Error("Invalid hex color format");
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
static fromHSL(e, r, s) {
|
|
|
|
if (r == 0) return new t(255 * s, 255 * s, 255 * s);
|
|
|
|
let a = i(
|
|
|
|
(V, x, P) => (
|
|
|
|
P < 0 && (P += 1),
|
|
|
|
P > 1 && (P -= 1),
|
|
|
|
P < 1 / 6
|
|
|
|
? V + (x - V) * 6 * P
|
|
|
|
: P < 1 / 2
|
|
|
|
? x
|
|
|
|
: P < 2 / 3
|
|
|
|
? V + (x - V) * (2 / 3 - P) * 6
|
|
|
|
: V
|
2024-06-01 06:31:08 +00:00
|
|
|
),
|
|
|
|
"hue2rgb"
|
|
|
|
),
|
2024-06-02 05:39:23 +00:00
|
|
|
l = s < 0.5 ? s * (1 + r) : s + r - s * r,
|
|
|
|
u = 2 * s - l,
|
|
|
|
f = a(u, l, e + 1 / 3),
|
|
|
|
y = a(u, l, e),
|
|
|
|
m = a(u, l, e - 1 / 3);
|
|
|
|
return new t(
|
|
|
|
Math.round(f * 255),
|
|
|
|
Math.round(y * 255),
|
|
|
|
Math.round(m * 255)
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
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);
|
2024-06-01 06:31:08 +00:00
|
|
|
clone() {
|
2024-06-02 05:39:23 +00:00
|
|
|
return new t(this.r, this.g, this.b);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
lighten(e) {
|
2024-06-02 05:39:23 +00:00
|
|
|
return new t(this.r + e, this.g + e, this.b + e);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
darken(e) {
|
|
|
|
return this.lighten(-e);
|
|
|
|
}
|
|
|
|
invert() {
|
2024-06-02 05:39:23 +00:00
|
|
|
return new t(255 - this.r, 255 - this.g, 255 - this.b);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
mult(e) {
|
2024-06-02 05:39:23 +00:00
|
|
|
return new t(
|
2024-06-01 06:31:08 +00:00
|
|
|
(this.r * e.r) / 255,
|
|
|
|
(this.g * e.g) / 255,
|
|
|
|
(this.b * e.b) / 255
|
|
|
|
);
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
lerp(e, r) {
|
|
|
|
return new t(Je(this.r, e.r, r), Je(this.g, e.g, r), Je(this.b, e.b, r));
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
toHSL() {
|
|
|
|
let e = this.r / 255,
|
2024-06-02 05:39:23 +00:00
|
|
|
r = this.g / 255,
|
|
|
|
s = this.b / 255,
|
|
|
|
a = Math.max(e, r, s),
|
|
|
|
l = Math.min(e, r, s),
|
|
|
|
u = (a + l) / 2,
|
|
|
|
f = u,
|
|
|
|
y = u;
|
|
|
|
if (a == l) u = f = 0;
|
2024-06-01 06:31:08 +00:00
|
|
|
else {
|
2024-06-02 05:39:23 +00:00
|
|
|
let m = a - l;
|
|
|
|
switch (((f = y > 0.5 ? m / (2 - a - l) : m / (a + l)), a)) {
|
2024-06-01 06:31:08 +00:00
|
|
|
case e:
|
2024-06-02 05:39:23 +00:00
|
|
|
u = (r - s) / m + (r < s ? 6 : 0);
|
2024-06-01 06:31:08 +00:00
|
|
|
break;
|
2024-06-02 05:39:23 +00:00
|
|
|
case r:
|
|
|
|
u = (s - e) / m + 2;
|
2024-06-01 06:31:08 +00:00
|
|
|
break;
|
2024-06-02 05:39:23 +00:00
|
|
|
case s:
|
|
|
|
u = (e - r) / m + 4;
|
2024-06-01 06:31:08 +00:00
|
|
|
break;
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
u /= 6;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
return [u, f, y];
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
eq(e) {
|
|
|
|
return this.r === e.r && this.g === e.g && this.b === e.b;
|
|
|
|
}
|
|
|
|
toString() {
|
|
|
|
return `rgb(${this.r}, ${this.g}, ${this.b})`;
|
|
|
|
}
|
|
|
|
toHex() {
|
|
|
|
return (
|
|
|
|
"#" +
|
|
|
|
((1 << 24) + (this.r << 16) + (this.g << 8) + this.b)
|
|
|
|
.toString(16)
|
|
|
|
.slice(1)
|
|
|
|
);
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
toArray() {
|
|
|
|
return [this.r, this.g, this.b];
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
};
|
|
|
|
function oe(...t) {
|
|
|
|
if (t.length === 0) return new ee(255, 255, 255);
|
|
|
|
if (t.length === 1) {
|
|
|
|
if (t[0] instanceof ee) return t[0].clone();
|
|
|
|
if (typeof t[0] == "string") return ee.fromHex(t[0]);
|
|
|
|
if (Array.isArray(t[0]) && t[0].length === 3) return ee.fromArray(t[0]);
|
|
|
|
}
|
|
|
|
return new ee(...t);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(oe, "rgb");
|
|
|
|
var Lr = i((t, e, r) => ee.fromHSL(t, e, r), "hsl2rgb"),
|
|
|
|
me = class t {
|
2024-06-01 06:31:08 +00:00
|
|
|
static {
|
2024-06-02 05:39:23 +00:00
|
|
|
i(this, "Quad");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
w = 1;
|
|
|
|
h = 1;
|
2024-06-02 05:39:23 +00:00
|
|
|
constructor(e, r, s, a) {
|
|
|
|
(this.x = e), (this.y = r), (this.w = s), (this.h = a);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
scale(e) {
|
2024-06-02 05:39:23 +00:00
|
|
|
return new t(
|
2024-06-01 06:31:08 +00:00
|
|
|
this.x + this.w * e.x,
|
|
|
|
this.y + this.h * e.y,
|
|
|
|
this.w * e.w,
|
|
|
|
this.h * e.h
|
|
|
|
);
|
|
|
|
}
|
|
|
|
pos() {
|
2024-06-02 05:39:23 +00:00
|
|
|
return new T(this.x, this.y);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
clone() {
|
2024-06-02 05:39:23 +00:00
|
|
|
return new t(this.x, this.y, this.w, this.h);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
eq(e) {
|
|
|
|
return (
|
|
|
|
this.x === e.x && this.y === e.y && this.w === e.w && this.h === e.h
|
|
|
|
);
|
|
|
|
}
|
|
|
|
toString() {
|
|
|
|
return `quad(${this.x}, ${this.y}, ${this.w}, ${this.h})`;
|
|
|
|
}
|
|
|
|
};
|
2024-06-02 05:39:23 +00:00
|
|
|
function pe(t, e, r, s) {
|
|
|
|
return new me(t, e, r, s);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(pe, "quad");
|
|
|
|
var Ot = class t {
|
2024-06-01 06:31:08 +00:00
|
|
|
static {
|
2024-06-02 05:39:23 +00:00
|
|
|
i(this, "Mat2");
|
|
|
|
}
|
|
|
|
a;
|
|
|
|
b;
|
|
|
|
c;
|
|
|
|
d;
|
|
|
|
constructor(e, r, s, a) {
|
|
|
|
(this.a = e), (this.b = r), (this.c = s), (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
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
transform(e) {
|
|
|
|
return C(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,
|
|
|
|
r = this.det,
|
|
|
|
s = e + Math.sqrt(e * e - r),
|
|
|
|
a = e - Math.sqrt(e * e - r);
|
|
|
|
return [s, a];
|
|
|
|
}
|
|
|
|
eigenvectors(e, r) {
|
|
|
|
return this.c != 0
|
|
|
|
? [
|
|
|
|
[e - this.d, this.c],
|
|
|
|
[r - this.d, this.c],
|
|
|
|
]
|
|
|
|
: this.b != 0
|
|
|
|
? [
|
|
|
|
[this.b, e - this.a],
|
|
|
|
[this.b, r - this.a],
|
|
|
|
]
|
|
|
|
: Math.abs(this.transform(C(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 r = Math.cos(e),
|
|
|
|
s = Math.sin(e);
|
|
|
|
return new t(r, s, -s, r);
|
|
|
|
}
|
|
|
|
static scale(e, r) {
|
|
|
|
return new t(e, 0, 0, r);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
};
|
|
|
|
var bt = class t {
|
|
|
|
static {
|
|
|
|
i(this, "Mat3");
|
|
|
|
}
|
|
|
|
m11;
|
|
|
|
m12;
|
|
|
|
m13;
|
|
|
|
m21;
|
|
|
|
m22;
|
|
|
|
m23;
|
|
|
|
m31;
|
|
|
|
m32;
|
|
|
|
m33;
|
|
|
|
constructor(e, r, s, a, l, u, f, y, m) {
|
|
|
|
(this.m11 = e),
|
|
|
|
(this.m12 = r),
|
|
|
|
(this.m13 = s),
|
|
|
|
(this.m21 = a),
|
|
|
|
(this.m22 = l),
|
|
|
|
(this.m23 = u),
|
|
|
|
(this.m31 = f),
|
|
|
|
(this.m32 = y),
|
|
|
|
(this.m33 = m);
|
|
|
|
}
|
|
|
|
static fromMat2(e) {
|
|
|
|
return new t(e.a, e.b, 0, e.c, e.d, 0, 0, 0, 1);
|
|
|
|
}
|
|
|
|
toMat2() {
|
|
|
|
return new Ot(this.m11, this.m12, this.m21, this.m22);
|
|
|
|
}
|
|
|
|
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-02 05:39:23 +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-02 05:39:23 +00:00
|
|
|
}
|
|
|
|
rotate(e) {
|
|
|
|
let r = Math.cos(e),
|
|
|
|
s = Math.sin(e),
|
|
|
|
a = this.m11,
|
|
|
|
l = this.m12;
|
|
|
|
return (
|
|
|
|
(this.m11 = r * this.m11 + s * this.m21),
|
|
|
|
(this.m12 = r * this.m12 + s * this.m22),
|
|
|
|
(this.m21 = r * this.m21 - s * a),
|
|
|
|
(this.m22 = r * this.m22 - s * l),
|
|
|
|
this
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
|
|
|
scale(e, r) {
|
|
|
|
return (
|
|
|
|
(this.m11 *= e),
|
|
|
|
(this.m12 *= e),
|
|
|
|
(this.m21 *= r),
|
|
|
|
(this.m22 *= r),
|
|
|
|
this
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
2024-06-02 05:39:23 +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
|
|
|
|
);
|
|
|
|
}
|
|
|
|
get transpose() {
|
|
|
|
return new t(
|
|
|
|
this.m11,
|
|
|
|
this.m21,
|
|
|
|
this.m31,
|
|
|
|
this.m12,
|
|
|
|
this.m22,
|
|
|
|
this.m32,
|
|
|
|
this.m13,
|
|
|
|
this.m23,
|
|
|
|
this.m33
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Ge = class t {
|
|
|
|
static {
|
|
|
|
i(this, "Mat4");
|
|
|
|
}
|
|
|
|
m = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
|
|
constructor(e) {
|
|
|
|
e && (this.m = e);
|
|
|
|
}
|
|
|
|
static translate(e) {
|
|
|
|
return new t([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, e.x, e.y, 0, 1]);
|
|
|
|
}
|
|
|
|
static scale(e) {
|
|
|
|
return new t([e.x, 0, 0, 0, 0, e.y, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
|
|
|
}
|
|
|
|
static rotateX(e) {
|
|
|
|
e = ve(-e);
|
|
|
|
let r = Math.cos(e),
|
|
|
|
s = Math.sin(e);
|
|
|
|
return new t([1, 0, 0, 0, 0, r, -s, 0, 0, s, r, 0, 0, 0, 0, 1]);
|
|
|
|
}
|
|
|
|
static rotateY(e) {
|
|
|
|
e = ve(-e);
|
|
|
|
let r = Math.cos(e),
|
|
|
|
s = Math.sin(e);
|
|
|
|
return new t([r, 0, s, 0, 0, 1, 0, 0, -s, 0, r, 0, 0, 0, 0, 1]);
|
|
|
|
}
|
|
|
|
static rotateZ(e) {
|
|
|
|
e = ve(-e);
|
|
|
|
let r = Math.cos(e),
|
|
|
|
s = Math.sin(e);
|
|
|
|
return new t([r, -s, 0, 0, s, r, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
|
|
|
}
|
|
|
|
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
|
|
|
|
);
|
|
|
|
}
|
|
|
|
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
|
|
|
|
);
|
|
|
|
}
|
|
|
|
rotate(e) {
|
|
|
|
e = ve(-e);
|
|
|
|
let r = Math.cos(e),
|
|
|
|
s = Math.sin(e),
|
|
|
|
a = this.m[0],
|
|
|
|
l = this.m[1],
|
|
|
|
u = this.m[4],
|
|
|
|
f = this.m[5];
|
|
|
|
return (
|
|
|
|
(this.m[0] = a * r + l * s),
|
|
|
|
(this.m[1] = -a * s + l * r),
|
|
|
|
(this.m[4] = u * r + f * s),
|
|
|
|
(this.m[5] = -u * s + f * r),
|
|
|
|
this
|
|
|
|
);
|
|
|
|
}
|
|
|
|
mult(e) {
|
|
|
|
let r = [];
|
|
|
|
for (let s = 0; s < 4; s++)
|
|
|
|
for (let a = 0; a < 4; a++)
|
|
|
|
r[s * 4 + a] =
|
|
|
|
this.m[0 * 4 + a] * e.m[s * 4 + 0] +
|
|
|
|
this.m[1 * 4 + a] * e.m[s * 4 + 1] +
|
|
|
|
this.m[2 * 4 + a] * e.m[s * 4 + 2] +
|
|
|
|
this.m[3 * 4 + a] * e.m[s * 4 + 3];
|
|
|
|
return new t(r);
|
|
|
|
}
|
|
|
|
multVec2(e) {
|
|
|
|
return new T(
|
|
|
|
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]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
getTranslation() {
|
|
|
|
return new T(this.m[12], this.m[13]);
|
|
|
|
}
|
|
|
|
getScale() {
|
|
|
|
if (this.m[0] != 0 || this.m[1] != 0) {
|
|
|
|
let e = this.m[0] * this.m[5] - this.m[1] * this.m[4],
|
|
|
|
r = Math.sqrt(this.m[0] * this.m[0] + this.m[1] * this.m[1]);
|
|
|
|
return new T(r, e / r);
|
|
|
|
} else if (this.m[4] != 0 || this.m[5] != 0) {
|
|
|
|
let e = this.m[0] * this.m[5] - this.m[1] * this.m[4],
|
|
|
|
r = Math.sqrt(this.m[4] * this.m[4] + this.m[5] * this.m[5]);
|
|
|
|
return new T(e / r, r);
|
|
|
|
} else return new T(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)
|
|
|
|
);
|
|
|
|
} 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;
|
|
|
|
}
|
|
|
|
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 T(
|
|
|
|
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 T(
|
|
|
|
0,
|
|
|
|
Math.atan(this.m[0] * this.m[4] + this.m[1] * this.m[5]) / (e * e)
|
|
|
|
);
|
|
|
|
} else return new T(0, 0);
|
|
|
|
}
|
|
|
|
invert() {
|
|
|
|
let e = [],
|
|
|
|
r = this.m[10] * this.m[15] - this.m[14] * this.m[11],
|
|
|
|
s = 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],
|
|
|
|
l = this.m[8] * this.m[15] - this.m[12] * this.m[11],
|
|
|
|
u = 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],
|
|
|
|
y = 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],
|
|
|
|
V = this.m[5] * this.m[14] - this.m[13] * this.m[6],
|
|
|
|
x = this.m[4] * this.m[15] - this.m[12] * this.m[7],
|
|
|
|
P = 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],
|
|
|
|
K = this.m[4] * this.m[13] - this.m[12] * this.m[5],
|
|
|
|
X = this.m[6] * this.m[11] - this.m[10] * this.m[7],
|
|
|
|
z = this.m[5] * this.m[11] - this.m[9] * this.m[7],
|
|
|
|
N = this.m[5] * this.m[10] - this.m[9] * this.m[6],
|
|
|
|
$ = 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],
|
|
|
|
se = this.m[4] * this.m[9] - this.m[8] * this.m[5];
|
|
|
|
(e[0] = this.m[5] * r - this.m[6] * s + this.m[7] * a),
|
|
|
|
(e[4] = -(this.m[4] * r - this.m[6] * l + this.m[7] * u)),
|
|
|
|
(e[8] = this.m[4] * s - this.m[5] * l + this.m[7] * f),
|
|
|
|
(e[12] = -(this.m[4] * a - this.m[5] * u + this.m[6] * f)),
|
|
|
|
(e[1] = -(this.m[1] * r - this.m[2] * s + this.m[3] * a)),
|
|
|
|
(e[5] = this.m[0] * r - this.m[2] * l + this.m[3] * u),
|
|
|
|
(e[9] = -(this.m[0] * s - this.m[1] * l + this.m[3] * f)),
|
|
|
|
(e[13] = this.m[0] * a - this.m[1] * u + this.m[2] * f),
|
|
|
|
(e[2] = this.m[1] * y - this.m[2] * m + this.m[3] * V),
|
|
|
|
(e[6] = -(this.m[0] * y - this.m[2] * x + this.m[3] * P)),
|
|
|
|
(e[10] = this.m[0] * w - this.m[1] * x + this.m[3] * K),
|
|
|
|
(e[14] = -(this.m[0] * V - this.m[1] * P + this.m[2] * K)),
|
|
|
|
(e[3] = -(this.m[1] * X - this.m[2] * z + this.m[3] * N)),
|
|
|
|
(e[7] = this.m[0] * X - this.m[2] * $ + this.m[3] * O),
|
|
|
|
(e[11] = -(this.m[0] * z - this.m[1] * $ + this.m[3] * se)),
|
|
|
|
(e[15] = this.m[0] * N - this.m[1] * O + this.m[2] * se);
|
|
|
|
let _ =
|
|
|
|
this.m[0] * e[0] +
|
|
|
|
this.m[1] * e[4] +
|
|
|
|
this.m[2] * e[8] +
|
|
|
|
this.m[3] * e[12];
|
|
|
|
for (let ae = 0; ae < 4; ae++)
|
|
|
|
for (let re = 0; re < 4; re++) e[ae * 4 + re] *= 1 / _;
|
|
|
|
return new t(e);
|
|
|
|
}
|
|
|
|
clone() {
|
|
|
|
return new t([...this.m]);
|
|
|
|
}
|
|
|
|
toString() {
|
|
|
|
return this.m.toString();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
function Yn(t, e, r, s = (a) => -Math.cos(a)) {
|
|
|
|
return t + ((s(r) + 1) / 2) * (e - t);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Yn, "wave");
|
|
|
|
var bi = 1103515245,
|
|
|
|
vi = 12345,
|
|
|
|
Fr = 2147483648,
|
|
|
|
It = class {
|
2024-06-01 06:31:08 +00:00
|
|
|
static {
|
2024-06-02 05:39:23 +00:00
|
|
|
i(this, "RNG");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
seed;
|
|
|
|
constructor(e) {
|
|
|
|
this.seed = e;
|
|
|
|
}
|
|
|
|
gen() {
|
2024-06-02 05:39:23 +00:00
|
|
|
return (this.seed = (bi * this.seed + vi) % Fr), this.seed / Fr;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
genNumber(e, r) {
|
|
|
|
return e + this.gen() * (r - e);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
genVec2(e, r) {
|
|
|
|
return new T(this.genNumber(e.x, r.x), this.genNumber(e.y, r.y));
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
genColor(e, r) {
|
|
|
|
return new ee(
|
|
|
|
this.genNumber(e.r, r.r),
|
|
|
|
this.genNumber(e.g, r.g),
|
|
|
|
this.genNumber(e.b, r.b)
|
2024-06-01 06:31:08 +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]);
|
2024-06-02 05:39:23 +00:00
|
|
|
if (e[0] instanceof T) return this.genVec2(C(0, 0), e[0]);
|
|
|
|
if (e[0] instanceof ee) return this.genColor(oe(0, 0, 0), e[0]);
|
2024-06-01 06:31:08 +00:00
|
|
|
} else if (e.length === 2) {
|
|
|
|
if (typeof e[0] == "number" && typeof e[1] == "number")
|
|
|
|
return this.genNumber(e[0], e[1]);
|
2024-06-02 05:39:23 +00:00
|
|
|
if (e[0] instanceof T && e[1] instanceof T)
|
2024-06-01 06:31:08 +00:00
|
|
|
return this.genVec2(e[0], e[1]);
|
2024-06-02 05:39:23 +00:00
|
|
|
if (e[0] instanceof ee && e[1] instanceof ee)
|
2024-06-01 06:31:08 +00:00
|
|
|
return this.genColor(e[0], e[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
zn = new It(Date.now());
|
|
|
|
function jr(t) {
|
|
|
|
return t != null && (zn.seed = t), zn.seed;
|
|
|
|
}
|
|
|
|
i(jr, "randSeed");
|
|
|
|
function Lt(...t) {
|
|
|
|
return zn.genAny(...t);
|
|
|
|
}
|
|
|
|
i(Lt, "rand");
|
|
|
|
function Xn(...t) {
|
|
|
|
return Math.floor(Lt(...t));
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Xn, "randi");
|
|
|
|
function kr(t) {
|
|
|
|
return Lt() <= t;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(kr, "chance");
|
|
|
|
function Wn(t) {
|
|
|
|
for (let e = t.length - 1; e > 0; e--) {
|
|
|
|
let r = Math.floor(Math.random() * (e + 1));
|
|
|
|
[t[e], t[r]] = [t[r], t[e]];
|
|
|
|
}
|
|
|
|
return t;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Wn, "shuffle");
|
|
|
|
function Nr(t, e) {
|
|
|
|
return t.length <= e ? t.slice() : Wn(t.slice()).slice(0, e);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Nr, "chooseMultiple");
|
|
|
|
function _r(t) {
|
|
|
|
return t[Xn(t.length)];
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(_r, "choose");
|
|
|
|
function $n(t, e) {
|
2024-06-01 06:31:08 +00:00
|
|
|
return (
|
2024-06-02 05:39:23 +00:00
|
|
|
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
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i($n, "testRectRect");
|
|
|
|
function xi(t, e) {
|
2024-06-01 06:31:08 +00:00
|
|
|
if (
|
2024-06-02 05:39:23 +00:00
|
|
|
(t.p1.x === t.p2.x && t.p1.y === t.p2.y) ||
|
2024-06-01 06:31:08 +00:00
|
|
|
(e.p1.x === e.p2.x && e.p1.y === e.p2.y)
|
|
|
|
)
|
|
|
|
return null;
|
2024-06-02 05:39:23 +00:00
|
|
|
let r =
|
|
|
|
(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 (r === 0) return null;
|
|
|
|
let s =
|
|
|
|
((e.p2.x - e.p1.x) * (t.p1.y - e.p1.y) -
|
|
|
|
(e.p2.y - e.p1.y) * (t.p1.x - e.p1.x)) /
|
|
|
|
r,
|
|
|
|
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)) /
|
|
|
|
r;
|
|
|
|
return s < 0 || s > 1 || a < 0 || a > 1 ? null : s;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(xi, "testLineLineT");
|
|
|
|
function cn(t, e) {
|
|
|
|
let r = xi(t, e);
|
|
|
|
return r
|
|
|
|
? C(t.p1.x + r * (t.p2.x - t.p1.x), t.p1.y + r * (t.p2.y - t.p1.y))
|
2024-06-01 06:31:08 +00:00
|
|
|
: null;
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(cn, "testLineLine");
|
|
|
|
function un(t, e) {
|
|
|
|
let r = e.p2.sub(e.p1),
|
|
|
|
s = Number.NEGATIVE_INFINITY,
|
|
|
|
a = Number.POSITIVE_INFINITY;
|
|
|
|
if (r.x != 0) {
|
|
|
|
let l = (t.pos.x - e.p1.x) / r.x,
|
|
|
|
u = (t.pos.x + t.width - e.p1.x) / r.x;
|
|
|
|
(s = Math.max(s, Math.min(l, u))), (a = Math.min(a, Math.max(l, u)));
|
|
|
|
}
|
|
|
|
if (r.y != 0) {
|
|
|
|
let l = (t.pos.y - e.p1.y) / r.y,
|
|
|
|
u = (t.pos.y + t.height - e.p1.y) / r.y;
|
|
|
|
(s = Math.max(s, Math.min(l, u))), (a = Math.min(a, Math.max(l, u)));
|
|
|
|
}
|
|
|
|
return a >= s && a >= 0 && s <= 1;
|
|
|
|
}
|
|
|
|
i(un, "testRectLine");
|
|
|
|
function Qn(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
|
|
|
|
);
|
|
|
|
}
|
|
|
|
i(Qn, "testRectPoint");
|
|
|
|
function Hr(t, e) {
|
|
|
|
let r = Math.max(t.pos.x, Math.min(e.center.x, t.pos.x + t.width)),
|
|
|
|
s = Math.max(t.pos.y, Math.min(e.center.y, t.pos.y + t.height));
|
|
|
|
return C(r, s).sdist(e.center) <= e.radius * e.radius;
|
|
|
|
}
|
|
|
|
i(Hr, "testRectCircle");
|
|
|
|
function Kr(t, e) {
|
|
|
|
return qr(e, new Oe(t.points()));
|
|
|
|
}
|
|
|
|
i(Kr, "testRectPolygon");
|
|
|
|
function Jn(t, e) {
|
|
|
|
let r = e.sub(t.p1),
|
|
|
|
s = t.p2.sub(t.p1);
|
|
|
|
if (Math.abs(r.cross(s)) > Number.EPSILON) return !1;
|
|
|
|
let a = r.dot(s) / s.dot(s);
|
|
|
|
return a >= 0 && a <= 1;
|
|
|
|
}
|
|
|
|
i(Jn, "testLinePoint");
|
|
|
|
function Rt(t, e) {
|
|
|
|
let r = t.p2.sub(t.p1),
|
|
|
|
s = r.dot(r),
|
|
|
|
a = t.p1.sub(e.center),
|
|
|
|
l = 2 * r.dot(a),
|
|
|
|
u = a.dot(a) - e.radius * e.radius,
|
|
|
|
f = l * l - 4 * s * u;
|
|
|
|
if (s <= Number.EPSILON || f < 0) return !1;
|
|
|
|
if (f == 0) {
|
|
|
|
let y = -l / (2 * s);
|
|
|
|
if (y >= 0 && y <= 1) return !0;
|
|
|
|
} else {
|
|
|
|
let y = (-l + Math.sqrt(f)) / (2 * s),
|
|
|
|
m = (-l - Math.sqrt(f)) / (2 * s);
|
|
|
|
if ((y >= 0 && y <= 1) || (m >= 0 && m <= 1)) return !0;
|
|
|
|
}
|
|
|
|
return er(e, t.p1);
|
|
|
|
}
|
|
|
|
i(Rt, "testLineCircle");
|
|
|
|
function Zn(t, e) {
|
|
|
|
if (mt(e, t.p1) || mt(e, t.p2)) return !0;
|
|
|
|
for (let r = 0; r < e.pts.length; r++) {
|
|
|
|
let s = e.pts[r],
|
|
|
|
a = e.pts[(r + 1) % e.pts.length];
|
|
|
|
if (cn(t, new Be(s, a))) return !0;
|
|
|
|
}
|
|
|
|
return !1;
|
|
|
|
}
|
|
|
|
i(Zn, "testLinePolygon");
|
|
|
|
function er(t, e) {
|
|
|
|
return t.center.sdist(e) < t.radius * t.radius;
|
|
|
|
}
|
|
|
|
i(er, "testCirclePoint");
|
|
|
|
function yi(t, e) {
|
|
|
|
return (
|
|
|
|
t.center.sdist(e.center) < (t.radius + e.radius) * (t.radius + e.radius)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
i(yi, "testCircleCircle");
|
|
|
|
function jt(t, e) {
|
|
|
|
let r = e.pts[e.pts.length - 1];
|
|
|
|
for (let s of e.pts) {
|
|
|
|
if (Rt(new Be(r, s), t)) return !0;
|
|
|
|
r = s;
|
|
|
|
}
|
|
|
|
return er(t, e.pts[0]) ? !0 : mt(e, t.center);
|
|
|
|
}
|
|
|
|
i(jt, "testCirclePolygon");
|
|
|
|
function qr(t, e) {
|
|
|
|
for (let r = 0; r < t.pts.length; r++)
|
|
|
|
if (Zn(new Be(t.pts[r], t.pts[(r + 1) % t.pts.length]), e)) return !0;
|
|
|
|
return !!(t.pts.some((r) => mt(e, r)) || e.pts.some((r) => mt(t, r)));
|
|
|
|
}
|
|
|
|
i(qr, "testPolygonPolygon");
|
|
|
|
function mt(t, e) {
|
|
|
|
let r = !1,
|
|
|
|
s = t.pts;
|
|
|
|
for (let a = 0, l = s.length - 1; a < s.length; l = a++)
|
|
|
|
s[a].y > e.y != s[l].y > e.y &&
|
|
|
|
e.x <
|
|
|
|
((s[l].x - s[a].x) * (e.y - s[a].y)) / (s[l].y - s[a].y) + s[a].x &&
|
|
|
|
(r = !r);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
i(mt, "testPolygonPoint");
|
|
|
|
function zr(t, e) {
|
|
|
|
e = e.sub(t.center);
|
|
|
|
let r = ve(t.angle),
|
|
|
|
s = Math.cos(r),
|
|
|
|
a = Math.sin(r),
|
|
|
|
l = e.x * s + e.y * a,
|
|
|
|
u = -e.x * a + e.y * s;
|
|
|
|
return (
|
|
|
|
(l * l) / (t.radiusX * t.radiusX) + (u * u) / (t.radiusY * t.radiusY) < 1
|
|
|
|
);
|
|
|
|
}
|
|
|
|
i(zr, "testEllipsePoint");
|
|
|
|
function an(t, e) {
|
|
|
|
let r = e.center.sub(t.center),
|
|
|
|
s = ve(t.angle),
|
|
|
|
a = Math.cos(s),
|
|
|
|
l = Math.sin(s),
|
|
|
|
u = r.x * a + r.y * l,
|
|
|
|
f = -r.x * l + r.y * a;
|
|
|
|
return zr(
|
|
|
|
new We(C(), t.radiusX + e.radius, t.radiusY + e.radius, 0),
|
|
|
|
C(u, f)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
i(an, "testEllipseCircle");
|
|
|
|
function Yr(t, e) {
|
|
|
|
let r = t.toMat2().inverse;
|
|
|
|
return (
|
|
|
|
(e = new Be(
|
|
|
|
r.transform(e.p1.sub(t.center)),
|
|
|
|
r.transform(e.p2.sub(t.center))
|
|
|
|
)),
|
|
|
|
Rt(e, new Fe(C(), 1))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
i(Yr, "testEllipseLine");
|
|
|
|
function wi(t, e) {
|
|
|
|
if (t.radiusX === t.radiusY) return an(e, new Fe(t.center, t.radiusX));
|
|
|
|
if (e.radiusX === e.radiusY) return an(t, new Fe(e.center, e.radiusX));
|
|
|
|
let r = new bt(
|
|
|
|
1 / t.radiusX ** 2,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
1 / t.radiusY ** 2,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
-1
|
|
|
|
),
|
|
|
|
s = new bt(1 / e.radiusX ** 2, 0, 0, 0, 1 / e.radiusY ** 2, 0, 0, 0, -1),
|
|
|
|
a = t.center.x,
|
|
|
|
l = t.center.y,
|
|
|
|
u = e.center.x,
|
|
|
|
f = e.center.y,
|
|
|
|
y = ve(t.angle),
|
|
|
|
m = ve(e.angle),
|
|
|
|
V = new bt(
|
|
|
|
Math.cos(y),
|
|
|
|
-Math.sin(y),
|
|
|
|
a,
|
|
|
|
Math.sin(y),
|
|
|
|
Math.cos(y),
|
|
|
|
l,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
1
|
|
|
|
),
|
|
|
|
x = new bt(
|
|
|
|
Math.cos(m),
|
|
|
|
-Math.sin(m),
|
|
|
|
u,
|
|
|
|
Math.sin(m),
|
|
|
|
Math.cos(m),
|
|
|
|
f,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
1
|
|
|
|
),
|
|
|
|
P = V.inverse,
|
|
|
|
w = x.inverse,
|
|
|
|
K = P.transpose.mul(r).mul(P),
|
|
|
|
X = w.transpose.mul(s).mul(w),
|
|
|
|
z = K.m11,
|
|
|
|
N = K.m12,
|
|
|
|
$ = K.m13,
|
|
|
|
O = K.m21,
|
|
|
|
se = K.m22,
|
|
|
|
_ = K.m23,
|
|
|
|
ae = K.m31,
|
|
|
|
re = K.m32,
|
|
|
|
ce = K.m33,
|
|
|
|
ge = X.m11,
|
|
|
|
Ue = X.m12,
|
|
|
|
Ce = X.m13,
|
|
|
|
Le = X.m21,
|
|
|
|
je = X.m22,
|
|
|
|
Ee = X.m23,
|
|
|
|
Ne = X.m31,
|
|
|
|
_e = X.m32,
|
|
|
|
He = X.m33,
|
|
|
|
pt =
|
|
|
|
z * se * ce -
|
|
|
|
z * _ * re -
|
|
|
|
N * O * ce +
|
|
|
|
N * _ * ae +
|
|
|
|
$ * O * re -
|
|
|
|
$ * se * ae,
|
|
|
|
Se =
|
|
|
|
(z * se * He -
|
|
|
|
z * _ * _e -
|
|
|
|
z * re * Ee +
|
|
|
|
z * ce * je -
|
|
|
|
N * O * He +
|
|
|
|
N * _ * Ne +
|
|
|
|
N * ae * Ee -
|
|
|
|
N * ce * Le +
|
|
|
|
$ * O * _e -
|
|
|
|
$ * se * Ne -
|
|
|
|
$ * ae * je +
|
|
|
|
$ * re * Le +
|
|
|
|
O * re * Ce -
|
|
|
|
O * ce * Ue -
|
|
|
|
se * ae * Ce +
|
|
|
|
se * ce * ge +
|
|
|
|
_ * ae * Ue -
|
|
|
|
_ * re * ge) /
|
|
|
|
pt,
|
|
|
|
Ve =
|
|
|
|
(z * je * He -
|
|
|
|
z * Ee * _e -
|
|
|
|
N * Le * He +
|
|
|
|
N * Ee * Ne +
|
|
|
|
$ * Le * _e -
|
|
|
|
$ * je * Ne -
|
|
|
|
O * Ue * He +
|
|
|
|
O * Ce * _e +
|
|
|
|
se * ge * He -
|
|
|
|
se * Ce * Ne -
|
|
|
|
_ * ge * _e +
|
|
|
|
_ * Ue * Ne +
|
|
|
|
ae * Ue * Ee -
|
|
|
|
ae * Ce * je -
|
|
|
|
re * ge * Ee +
|
|
|
|
re * Ce * Le +
|
|
|
|
ce * ge * je -
|
|
|
|
ce * Ue * Le) /
|
|
|
|
pt,
|
|
|
|
ze =
|
|
|
|
(ge * je * He -
|
|
|
|
ge * Ee * _e -
|
|
|
|
Ue * Le * He +
|
|
|
|
Ue * Ee * Ne +
|
|
|
|
Ce * Le * _e -
|
|
|
|
Ce * je * Ne) /
|
|
|
|
pt;
|
|
|
|
if (Se >= 0) {
|
|
|
|
let rt = -3 * Ve + Se ** 2,
|
|
|
|
ot = 3 * Se * ze + Ve * Se ** 2 - 4 * Ve ** 2,
|
|
|
|
wt =
|
|
|
|
-27 * ze ** 2 +
|
|
|
|
18 * ze * Se * Ve +
|
|
|
|
Se ** 2 * Ve ** 2 -
|
|
|
|
4 * Se ** 3 * ze -
|
|
|
|
4 * Ve ** 3;
|
|
|
|
return !(rt > 0 && ot < 0 && wt > 0);
|
|
|
|
} else {
|
|
|
|
let rt = -3 * Ve + Se ** 2,
|
|
|
|
ot =
|
|
|
|
-27 * ze ** 2 +
|
|
|
|
18 * ze * Se * Ve +
|
|
|
|
Se ** 2 * Ve ** 2 -
|
|
|
|
4 * Se ** 3 * ze -
|
|
|
|
4 * Ve ** 3;
|
|
|
|
return !(rt > 0 && ot > 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i(wi, "testEllipseEllipse");
|
|
|
|
function Xr(t, e) {
|
|
|
|
return tr(t, new Oe(e.points()));
|
|
|
|
}
|
|
|
|
i(Xr, "testEllipseRect");
|
|
|
|
function tr(t, e) {
|
|
|
|
let r = t.toMat2().inverse;
|
2024-06-01 06:31:08 +00:00
|
|
|
return (
|
2024-06-02 05:39:23 +00:00
|
|
|
(e = new Oe(e.pts.map((s) => r.transform(s.sub(t.center))))),
|
|
|
|
jt(new Fe(C(), 1), e)
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(tr, "testEllipsePolygon");
|
|
|
|
function Ci(t, e) {
|
|
|
|
return e instanceof T
|
|
|
|
? Jn(t, e)
|
|
|
|
: e instanceof Fe
|
|
|
|
? Rt(t, e)
|
|
|
|
: e instanceof Be
|
|
|
|
? cn(t, e) != null
|
|
|
|
: e instanceof ue
|
|
|
|
? un(e, t)
|
|
|
|
: e instanceof Oe
|
|
|
|
? Zn(t, e)
|
|
|
|
: e instanceof We
|
|
|
|
? Yr(e, t)
|
|
|
|
: !1;
|
|
|
|
}
|
|
|
|
i(Ci, "testLineShape");
|
|
|
|
function Ti(t, e) {
|
|
|
|
return e instanceof T
|
|
|
|
? er(t, e)
|
|
|
|
: e instanceof Fe
|
|
|
|
? yi(t, e)
|
|
|
|
: e instanceof Be
|
|
|
|
? Rt(e, t)
|
|
|
|
: e instanceof ue
|
|
|
|
? Hr(e, t)
|
|
|
|
: e instanceof Oe
|
|
|
|
? jt(t, e)
|
|
|
|
: e instanceof We
|
|
|
|
? an(e, t)
|
|
|
|
: !1;
|
|
|
|
}
|
|
|
|
i(Ti, "testCircleShape");
|
|
|
|
function Ei(t, e) {
|
|
|
|
return e instanceof T
|
|
|
|
? Qn(t, e)
|
|
|
|
: e instanceof Fe
|
|
|
|
? Hr(t, e)
|
|
|
|
: e instanceof Be
|
|
|
|
? un(t, e)
|
|
|
|
: e instanceof ue
|
|
|
|
? $n(t, e)
|
|
|
|
: e instanceof Oe
|
|
|
|
? Kr(t, e)
|
|
|
|
: e instanceof We
|
|
|
|
? Xr(e, t)
|
|
|
|
: !1;
|
|
|
|
}
|
|
|
|
i(Ei, "testRectShape");
|
|
|
|
function Si(t, e) {
|
|
|
|
return e instanceof T
|
|
|
|
? mt(t, e)
|
|
|
|
: e instanceof Fe
|
|
|
|
? jt(e, t)
|
|
|
|
: e instanceof Be
|
|
|
|
? Zn(e, t)
|
|
|
|
: e instanceof ue
|
|
|
|
? Kr(e, t)
|
|
|
|
: e instanceof Oe
|
|
|
|
? qr(e, t)
|
|
|
|
: e instanceof We
|
|
|
|
? tr(e, t)
|
|
|
|
: !1;
|
|
|
|
}
|
|
|
|
i(Si, "testPolygonShape");
|
|
|
|
function Ai(t, e) {
|
|
|
|
return e instanceof T
|
|
|
|
? zr(t, e)
|
|
|
|
: e instanceof Fe
|
|
|
|
? an(t, e)
|
|
|
|
: e instanceof Be
|
|
|
|
? Yr(t, e)
|
|
|
|
: e instanceof ue
|
|
|
|
? Xr(t, e)
|
|
|
|
: e instanceof Oe
|
|
|
|
? tr(t, e)
|
|
|
|
: e instanceof We
|
|
|
|
? wi(e, t)
|
|
|
|
: !1;
|
|
|
|
}
|
|
|
|
i(Ai, "testEllipseShape");
|
|
|
|
function Wr(t, e, r) {
|
|
|
|
let s = t,
|
|
|
|
a = r.p1,
|
|
|
|
l = r.p2,
|
|
|
|
u = e,
|
|
|
|
f = l.sub(a),
|
|
|
|
y = u.cross(f);
|
|
|
|
if (Math.abs(y) < Number.EPSILON) return null;
|
|
|
|
let m = a.sub(s),
|
|
|
|
V = m.cross(f) / y;
|
|
|
|
if (V <= 0 || V >= 1) return null;
|
|
|
|
let x = m.cross(u) / y;
|
|
|
|
if (x <= 0 || x >= 1) return null;
|
|
|
|
let P = f.normal().unit();
|
2024-06-01 06:31:08 +00:00
|
|
|
return (
|
2024-06-02 05:39:23 +00:00
|
|
|
e.dot(P) > 0 && ((P.x *= -1), (P.y *= -1)),
|
|
|
|
{ point: s.add(u.scale(V)), normal: P, fraction: V }
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Wr, "raycastLine");
|
|
|
|
function Oi(t, e, r) {
|
|
|
|
let s = Number.NEGATIVE_INFINITY,
|
|
|
|
a = Number.POSITIVE_INFINITY,
|
|
|
|
l;
|
|
|
|
if (t.x != 0) {
|
|
|
|
let u = (r.pos.x - t.x) / e.x,
|
|
|
|
f = (r.pos.x + r.width - t.x) / e.x;
|
|
|
|
(l = C(-Math.sign(e.x), 0)),
|
|
|
|
(s = Math.max(s, Math.min(u, f))),
|
|
|
|
(a = Math.min(a, Math.max(u, f)));
|
|
|
|
}
|
|
|
|
if (t.y != 0) {
|
|
|
|
let u = (r.pos.y - t.y) / e.y,
|
|
|
|
f = (r.pos.y + r.height - t.y) / e.y;
|
|
|
|
Math.min(u, f) > s && (l = C(0, -Math.sign(e.y))),
|
|
|
|
(s = Math.max(s, Math.min(u, f))),
|
|
|
|
(a = Math.min(a, Math.max(u, f)));
|
|
|
|
}
|
|
|
|
return a >= s && s >= 0 && s <= 1
|
|
|
|
? { point: t.add(e.scale(s)), normal: l, fraction: s }
|
|
|
|
: null;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Oi, "raycastRect");
|
|
|
|
function $r(t, e, r) {
|
|
|
|
let s = t,
|
|
|
|
a = r.center,
|
|
|
|
l = e,
|
|
|
|
u = l.dot(l),
|
|
|
|
f = s.sub(a),
|
|
|
|
y = 2 * l.dot(f),
|
|
|
|
m = f.dot(f) - r.radius * r.radius,
|
|
|
|
V = y * y - 4 * u * m;
|
|
|
|
if (u <= Number.EPSILON || V < 0) return null;
|
|
|
|
if (V == 0) {
|
|
|
|
let x = -y / (2 * u);
|
|
|
|
if (x >= 0 && x <= 1) {
|
|
|
|
let P = s.add(l.scale(x));
|
|
|
|
return { point: P, normal: P.sub(a), fraction: x };
|
|
|
|
}
|
2024-06-01 06:31:08 +00:00
|
|
|
} else {
|
2024-06-02 05:39:23 +00:00
|
|
|
let x = (-y + Math.sqrt(V)) / (2 * u),
|
|
|
|
P = (-y - Math.sqrt(V)) / (2 * u),
|
|
|
|
w = null;
|
|
|
|
if (
|
|
|
|
(x >= 0 && x <= 1 && (w = x),
|
|
|
|
P >= 0 && P <= 1 && (w = Math.min(P, w ?? P)),
|
|
|
|
w != null)
|
|
|
|
) {
|
|
|
|
let K = s.add(l.scale(w));
|
|
|
|
return { point: K, normal: K.sub(a).unit(), fraction: w };
|
|
|
|
}
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
return null;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i($r, "raycastCircle");
|
|
|
|
function Ri(t, e, r) {
|
|
|
|
let s = r.pts,
|
|
|
|
a = null,
|
|
|
|
l = s[s.length - 1];
|
|
|
|
for (let u = 0; u < s.length; u++) {
|
|
|
|
let f = s[u],
|
|
|
|
y = Wr(t, e, new Be(l, f));
|
|
|
|
y && (!a || a.fraction > y.fraction) && (a = y), (l = f);
|
|
|
|
}
|
|
|
|
return a;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Ri, "raycastPolygon");
|
|
|
|
function Ui(t, e, r) {
|
|
|
|
let s = r.toMat2(),
|
|
|
|
a = s.inverse,
|
|
|
|
l = a.transform(t.sub(r.center)),
|
|
|
|
u = a.transform(e),
|
|
|
|
f = $r(l, u, new Fe(C(), 1));
|
|
|
|
if (f) {
|
|
|
|
let y = Ot.rotation(ve(-r.angle)),
|
|
|
|
V = Ot.scale(r.radiusX, r.radiusY).transform(f.point),
|
|
|
|
x = s.transform(f.point).add(r.center),
|
|
|
|
P = x.dist(t) / e.len();
|
|
|
|
return {
|
|
|
|
point: x,
|
|
|
|
normal: y.transform(C(r.radiusY ** 2 * V.x, r.radiusX ** 2 * V.y)),
|
|
|
|
fraction: P,
|
|
|
|
};
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
return f;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Ui, "raycastEllipse");
|
|
|
|
function Qr(t, e, r, s = 64) {
|
|
|
|
let a = t,
|
|
|
|
l = e.len(),
|
|
|
|
u = e.scale(1 / l),
|
|
|
|
f = 0,
|
|
|
|
y = C(Math.floor(t.x), Math.floor(t.y)),
|
|
|
|
m = C(u.x > 0 ? 1 : -1, u.y > 0 ? 1 : -1),
|
|
|
|
V = C(Math.abs(1 / u.x), Math.abs(1 / u.y)),
|
|
|
|
x = C(
|
|
|
|
m.x > 0 ? y.x + 1 - t.x : t.x - y.x,
|
|
|
|
m.y > 0 ? y.y + 1 - t.y : t.y - y.y
|
|
|
|
),
|
|
|
|
P = C(V.x < 1 / 0 ? V.x * x.x : 1 / 0, V.y < 1 / 0 ? V.y * x.y : 1 / 0),
|
|
|
|
w = -1;
|
|
|
|
for (; f <= s; ) {
|
|
|
|
let K = r(y);
|
|
|
|
if (K === !0)
|
|
|
|
return {
|
|
|
|
point: a.add(u.scale(f)),
|
|
|
|
normal: C(w === 0 ? -m.x : 0, w === 1 ? -m.y : 0),
|
|
|
|
fraction: f / l,
|
|
|
|
gridPos: y,
|
|
|
|
};
|
|
|
|
if (K) return K;
|
|
|
|
P.x < P.y
|
|
|
|
? ((y.x += m.x), (f = P.x), (P.x += V.x), (w = 0))
|
|
|
|
: ((y.y += m.y), (f = P.y), (P.y += V.y), (w = 1));
|
|
|
|
}
|
|
|
|
return null;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Qr, "raycastGrid");
|
|
|
|
var Be = class t {
|
2024-06-01 06:31:08 +00:00
|
|
|
static {
|
2024-06-02 05:39:23 +00:00
|
|
|
i(this, "Line");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
p1;
|
|
|
|
p2;
|
2024-06-02 05:39:23 +00:00
|
|
|
constructor(e, r) {
|
|
|
|
(this.p1 = e.clone()), (this.p2 = r.clone());
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
transform(e) {
|
2024-06-02 05:39:23 +00:00
|
|
|
return new t(e.multVec2(this.p1), e.multVec2(this.p2));
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
bbox() {
|
2024-06-02 05:39:23 +00:00
|
|
|
return ue.fromPoints(this.p1, this.p2);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
area() {
|
|
|
|
return this.p1.dist(this.p2);
|
|
|
|
}
|
|
|
|
clone() {
|
2024-06-02 05:39:23 +00:00
|
|
|
return new t(this.p1, this.p2);
|
|
|
|
}
|
|
|
|
collides(e) {
|
|
|
|
return Ci(this, e);
|
|
|
|
}
|
|
|
|
contains(e) {
|
|
|
|
return this.collides(e);
|
|
|
|
}
|
|
|
|
raycast(e, r) {
|
|
|
|
return Wr(e, r, this);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
ue = class t {
|
2024-06-01 06:31:08 +00:00
|
|
|
static {
|
2024-06-02 05:39:23 +00:00
|
|
|
i(this, "Rect");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
pos;
|
|
|
|
width;
|
|
|
|
height;
|
2024-06-02 05:39:23 +00:00
|
|
|
constructor(e, r, s) {
|
|
|
|
(this.pos = e.clone()), (this.width = r), (this.height = s);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
static fromPoints(e, r) {
|
|
|
|
return new t(e.clone(), r.x - e.x, r.y - e.y);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
center() {
|
2024-06-02 05:39:23 +00:00
|
|
|
return new T(this.pos.x + this.width / 2, this.pos.y + this.height / 2);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
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) {
|
2024-06-02 05:39:23 +00:00
|
|
|
return new Oe(this.points().map((r) => e.multVec2(r)));
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
bbox() {
|
|
|
|
return this.clone();
|
|
|
|
}
|
|
|
|
area() {
|
|
|
|
return this.width * this.height;
|
|
|
|
}
|
|
|
|
clone() {
|
2024-06-02 05:39:23 +00:00
|
|
|
return new t(this.pos.clone(), this.width, this.height);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
distToPoint(e) {
|
|
|
|
return Math.sqrt(this.sdistToPoint(e));
|
|
|
|
}
|
|
|
|
sdistToPoint(e) {
|
2024-06-02 05:39:23 +00:00
|
|
|
let r = this.pos,
|
|
|
|
s = this.pos.add(this.width, this.height),
|
|
|
|
a = Math.max(r.x - e.x, 0, e.x - s.x),
|
|
|
|
l = Math.max(r.y - e.y, 0, e.y - s.y);
|
|
|
|
return a * a + l * l;
|
|
|
|
}
|
|
|
|
collides(e) {
|
|
|
|
return Ei(this, e);
|
|
|
|
}
|
|
|
|
contains(e) {
|
|
|
|
return this.collides(e);
|
|
|
|
}
|
|
|
|
raycast(e, r) {
|
|
|
|
return Oi(e, r, this);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
Fe = class t {
|
2024-06-01 06:31:08 +00:00
|
|
|
static {
|
2024-06-02 05:39:23 +00:00
|
|
|
i(this, "Circle");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
center;
|
|
|
|
radius;
|
2024-06-02 05:39:23 +00:00
|
|
|
constructor(e, r) {
|
|
|
|
(this.center = e.clone()), (this.radius = r);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
transform(e) {
|
2024-06-02 05:39:23 +00:00
|
|
|
return new We(this.center, this.radius, this.radius).transform(e);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
bbox() {
|
2024-06-02 05:39:23 +00:00
|
|
|
return ue.fromPoints(
|
|
|
|
this.center.sub(C(this.radius)),
|
|
|
|
this.center.add(C(this.radius))
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
area() {
|
|
|
|
return this.radius * this.radius * Math.PI;
|
|
|
|
}
|
|
|
|
clone() {
|
2024-06-02 05:39:23 +00:00
|
|
|
return new t(this.center, this.radius);
|
|
|
|
}
|
|
|
|
collides(e) {
|
|
|
|
return Ti(this, e);
|
|
|
|
}
|
|
|
|
contains(e) {
|
|
|
|
return this.collides(e);
|
|
|
|
}
|
|
|
|
raycast(e, r) {
|
|
|
|
return $r(e, r, this);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
We = class t {
|
2024-06-01 06:31:08 +00:00
|
|
|
static {
|
2024-06-02 05:39:23 +00:00
|
|
|
i(this, "Ellipse");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
center;
|
|
|
|
radiusX;
|
|
|
|
radiusY;
|
2024-06-02 05:39:23 +00:00
|
|
|
angle;
|
|
|
|
constructor(e, r, s, a = 0) {
|
|
|
|
(this.center = e.clone()),
|
|
|
|
(this.radiusX = r),
|
|
|
|
(this.radiusY = s),
|
|
|
|
(this.angle = a);
|
|
|
|
}
|
|
|
|
static fromMat2(e) {
|
|
|
|
let r = e.inverse,
|
|
|
|
s = r.transpose.mul(r),
|
|
|
|
[a, l] = s.eigenvalues,
|
|
|
|
[u, f] = s.eigenvectors(a, l),
|
|
|
|
[y, m] = [1 / Math.sqrt(a), 1 / Math.sqrt(l)];
|
|
|
|
return y > m
|
|
|
|
? new t(C(), y, m, lt(Math.atan2(-u[1], u[0])))
|
|
|
|
: new t(C(), m, y, lt(Math.atan2(-f[1], f[0])));
|
|
|
|
}
|
|
|
|
toMat2() {
|
|
|
|
let e = ve(this.angle),
|
|
|
|
r = Math.cos(e),
|
|
|
|
s = Math.sin(e);
|
|
|
|
return new Ot(
|
|
|
|
r * this.radiusX,
|
|
|
|
s * this.radiusY,
|
|
|
|
-s * this.radiusX,
|
|
|
|
r * this.radiusY
|
|
|
|
);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
transform(e) {
|
2024-06-02 05:39:23 +00:00
|
|
|
if (this.angle == 0 && e.getRotation() == 0)
|
|
|
|
return new t(
|
|
|
|
e.multVec2(this.center),
|
|
|
|
e.m[0] * this.radiusX,
|
|
|
|
e.m[5] * this.radiusY
|
|
|
|
);
|
|
|
|
{
|
|
|
|
let r = this.toMat2(),
|
|
|
|
s = e.getRotation(),
|
|
|
|
a = e.getScale();
|
|
|
|
r = bt.fromMat2(r).scale(a.x, a.y).rotate(s).toMat2();
|
|
|
|
let u = t.fromMat2(r);
|
|
|
|
return (u.center = e.multVec2(this.center)), u;
|
|
|
|
}
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
bbox() {
|
2024-06-02 05:39:23 +00:00
|
|
|
if (this.angle == 0)
|
|
|
|
return ue.fromPoints(
|
|
|
|
this.center.sub(C(this.radiusX, this.radiusY)),
|
|
|
|
this.center.add(C(this.radiusX, this.radiusY))
|
|
|
|
);
|
|
|
|
{
|
|
|
|
let e = ve(this.angle),
|
|
|
|
r = Math.cos(e),
|
|
|
|
s = Math.sin(e),
|
|
|
|
a = this.radiusX * r,
|
|
|
|
l = this.radiusX * s,
|
|
|
|
u = this.radiusY * s,
|
|
|
|
f = this.radiusY * r,
|
|
|
|
y = Math.sqrt(a * a + u * u),
|
|
|
|
m = Math.sqrt(l * l + f * f);
|
|
|
|
return ue.fromPoints(
|
|
|
|
this.center.sub(C(y, m)),
|
|
|
|
this.center.add(C(y, m))
|
|
|
|
);
|
|
|
|
}
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
area() {
|
|
|
|
return this.radiusX * this.radiusY * Math.PI;
|
|
|
|
}
|
|
|
|
clone() {
|
2024-06-02 05:39:23 +00:00
|
|
|
return new t(this.center, this.radiusX, this.radiusY, this.angle);
|
|
|
|
}
|
|
|
|
collides(e) {
|
|
|
|
return Ai(this, e);
|
|
|
|
}
|
|
|
|
contains(e) {
|
|
|
|
e = e.sub(this.center);
|
|
|
|
let r = ve(this.angle),
|
|
|
|
s = Math.cos(r),
|
|
|
|
a = Math.sin(r),
|
|
|
|
l = e.x * s + e.y * a,
|
|
|
|
u = -e.x * a + e.y * s;
|
|
|
|
return (
|
|
|
|
(l * l) / (this.radiusX * this.radiusX) +
|
|
|
|
(u * u) / (this.radiusY * this.radiusY) <
|
|
|
|
1
|
|
|
|
);
|
|
|
|
}
|
|
|
|
raycast(e, r) {
|
|
|
|
return Ui(e, r, this);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
Oe = class t {
|
2024-06-01 06:31:08 +00:00
|
|
|
static {
|
2024-06-02 05:39:23 +00:00
|
|
|
i(this, "Polygon");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
pts;
|
|
|
|
constructor(e) {
|
|
|
|
if (e.length < 3)
|
|
|
|
throw new Error("Polygons should have at least 3 vertices");
|
|
|
|
this.pts = e;
|
|
|
|
}
|
|
|
|
transform(e) {
|
2024-06-02 05:39:23 +00:00
|
|
|
return new t(this.pts.map((r) => e.multVec2(r)));
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
bbox() {
|
2024-06-02 05:39:23 +00:00
|
|
|
let e = C(Number.MAX_VALUE),
|
|
|
|
r = C(-Number.MAX_VALUE);
|
|
|
|
for (let s of this.pts)
|
|
|
|
(e.x = Math.min(e.x, s.x)),
|
|
|
|
(r.x = Math.max(r.x, s.x)),
|
|
|
|
(e.y = Math.min(e.y, s.y)),
|
|
|
|
(r.y = Math.max(r.y, s.y));
|
|
|
|
return ue.fromPoints(e, r);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
area() {
|
|
|
|
let e = 0,
|
2024-06-02 05:39:23 +00:00
|
|
|
r = this.pts.length;
|
|
|
|
for (let s = 0; s < r; s++) {
|
|
|
|
let a = this.pts[s],
|
|
|
|
l = this.pts[(s + 1) % r];
|
|
|
|
(e += a.x * l.y * 0.5), (e -= l.x * a.y * 0.5);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
return Math.abs(e);
|
|
|
|
}
|
|
|
|
clone() {
|
2024-06-02 05:39:23 +00:00
|
|
|
return new t(this.pts.map((e) => e.clone()));
|
|
|
|
}
|
|
|
|
collides(e) {
|
|
|
|
return Si(this, e);
|
|
|
|
}
|
|
|
|
contains(e) {
|
|
|
|
return this.collides(e);
|
|
|
|
}
|
|
|
|
raycast(e, r) {
|
|
|
|
return Ri(e, r, this);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
};
|
2024-06-02 05:39:23 +00:00
|
|
|
function nr(t, e, r, s, a) {
|
|
|
|
let l = a * a,
|
|
|
|
u = l * a,
|
|
|
|
f = 1 - a,
|
|
|
|
y = f * f,
|
|
|
|
m = y * f;
|
|
|
|
return t
|
|
|
|
.scale(m)
|
|
|
|
.add(e.scale(3 * y * a))
|
|
|
|
.add(r.scale(3 * f * l))
|
|
|
|
.add(s.scale(u));
|
|
|
|
}
|
|
|
|
i(nr, "evaluateBezier");
|
|
|
|
function Jr(t, e) {
|
|
|
|
let r = Number.MAX_VALUE,
|
|
|
|
s = C(0);
|
|
|
|
for (let a of [t, e])
|
|
|
|
for (let l = 0; l < a.pts.length; l++) {
|
|
|
|
let u = a.pts[l],
|
|
|
|
y = a.pts[(l + 1) % a.pts.length].sub(u).normal().unit(),
|
|
|
|
m = Number.MAX_VALUE,
|
|
|
|
V = -Number.MAX_VALUE;
|
|
|
|
for (let K = 0; K < t.pts.length; K++) {
|
|
|
|
let X = t.pts[K].dot(y);
|
|
|
|
(m = Math.min(m, X)), (V = Math.max(V, X));
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
let x = Number.MAX_VALUE,
|
|
|
|
P = -Number.MAX_VALUE;
|
2024-06-01 06:31:08 +00:00
|
|
|
for (let K = 0; K < e.pts.length; K++) {
|
2024-06-02 05:39:23 +00:00
|
|
|
let X = e.pts[K].dot(y);
|
|
|
|
(x = Math.min(x, X)), (P = Math.max(P, X));
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
let w = Math.min(V, P) - Math.max(m, x);
|
|
|
|
if (w < 0) return null;
|
|
|
|
if (w < Math.abs(r)) {
|
|
|
|
let K = P - m,
|
|
|
|
X = x - V;
|
|
|
|
(r = Math.abs(K) < Math.abs(X) ? K : X), (s = y.scale(r));
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
i(Jr, "sat");
|
|
|
|
function Zr(t, e, r) {
|
|
|
|
return (e.x - t.x) * (r.y - t.y) - (e.y - t.y) * (r.x - t.x) >= 0;
|
|
|
|
}
|
|
|
|
i(Zr, "isOrientedCcw");
|
|
|
|
function Vi(t) {
|
|
|
|
let e = 0,
|
|
|
|
r = t[t.length - 1];
|
|
|
|
for (let s = 0; s < t.length; s++)
|
|
|
|
(e += (t[s].x - r.x) * (t[s].y + r.y)), (r = t[s]);
|
|
|
|
return e < 0;
|
|
|
|
}
|
|
|
|
i(Vi, "isOrientedCcwPolygon");
|
|
|
|
function qn(t, e, r, s) {
|
|
|
|
let a = s.x - r.x,
|
|
|
|
l = s.y - r.y,
|
|
|
|
u = a * (t.y - r.y) - l * (t.x - r.x),
|
|
|
|
f = a * (e.y - r.y) - l * (e.x - r.x);
|
|
|
|
return u * f >= 0;
|
|
|
|
}
|
|
|
|
i(qn, "onSameSide");
|
|
|
|
function Pi(t, e, r, s) {
|
|
|
|
return qn(t, e, r, s) && qn(t, r, e, s) && qn(t, s, e, r);
|
|
|
|
}
|
|
|
|
i(Pi, "pointInTriangle");
|
|
|
|
function Di(t, e, r, s) {
|
|
|
|
for (let a of t)
|
|
|
|
if (a !== e && a !== r && a !== s && Pi(a, e, r, s)) return !0;
|
|
|
|
return !1;
|
|
|
|
}
|
|
|
|
i(Di, "someInTriangle");
|
|
|
|
function Mi(t, e, r, s) {
|
|
|
|
return Zr(t, e, r) && !Di(s, t, e, r);
|
|
|
|
}
|
|
|
|
i(Mi, "isEar");
|
|
|
|
function rr(t) {
|
|
|
|
if (t.length < 3) return [];
|
|
|
|
if (t.length == 3) return [t];
|
|
|
|
let e = [],
|
|
|
|
r = [],
|
|
|
|
s = 0;
|
|
|
|
for (let x = 0; x < t.length; x++) {
|
|
|
|
let P = t[s],
|
|
|
|
w = t[x];
|
|
|
|
(w.x < P.x || (w.x == P.x && w.y < P.y)) && (s = s),
|
|
|
|
(e[x] = x + 1),
|
|
|
|
(r[x] = x - 1);
|
|
|
|
}
|
|
|
|
(e[e.length - 1] = 0), (r[0] = r.length - 1), Vi(t) || ([e, r] = [r, e]);
|
|
|
|
let a = [];
|
|
|
|
for (let x = 0; x < t.length; ++x)
|
|
|
|
Zr(t[r[x]], t[x], t[e[x]]) || a.push(t[x]);
|
|
|
|
let l = [],
|
|
|
|
u = t.length,
|
|
|
|
f = 1,
|
|
|
|
y = 0,
|
|
|
|
m,
|
|
|
|
V;
|
|
|
|
for (; u > 3; ) {
|
|
|
|
(m = e[f]), (V = r[f]);
|
|
|
|
let x = t[V],
|
|
|
|
P = t[f],
|
|
|
|
w = t[m];
|
|
|
|
if (Mi(x, P, w, a))
|
|
|
|
l.push([x, P, w]),
|
|
|
|
(e[V] = m),
|
|
|
|
(r[m] = V),
|
|
|
|
a.splice(a.indexOf(P), 1),
|
|
|
|
--u,
|
|
|
|
(y = 0);
|
|
|
|
else if (++y > u) return [];
|
|
|
|
f = m;
|
|
|
|
}
|
|
|
|
return (m = e[f]), (V = r[f]), l.push([t[V], t[f], t[m]]), l;
|
|
|
|
}
|
|
|
|
i(rr, "triangulate");
|
|
|
|
function or(t) {
|
|
|
|
if (t.length < 3) return !1;
|
|
|
|
let e = t.length - 2,
|
|
|
|
r = t.length - 1,
|
|
|
|
s = 0,
|
|
|
|
a = t[r].sub(t[e]),
|
|
|
|
l = t[s].sub(t[r]),
|
|
|
|
u = a.cross(l);
|
|
|
|
for (; s + 1 < t.length; )
|
|
|
|
if (
|
|
|
|
((e = r),
|
|
|
|
(r = s),
|
|
|
|
s++,
|
|
|
|
(a = t[r].sub(t[e])),
|
|
|
|
(l = t[s].sub(t[r])),
|
|
|
|
a.cross(l) * u < 0)
|
|
|
|
)
|
|
|
|
return !1;
|
|
|
|
return !0;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(or, "isConvex");
|
|
|
|
var kt = class extends Map {
|
2024-06-01 06:31:08 +00:00
|
|
|
static {
|
2024-06-02 05:39:23 +00:00
|
|
|
i(this, "Registry");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
lastID = 0;
|
2024-06-01 06:31:08 +00:00
|
|
|
push(e) {
|
2024-06-02 05:39:23 +00:00
|
|
|
let r = this.lastID;
|
|
|
|
return this.set(r, e), this.lastID++, r;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
pushd(e) {
|
2024-06-02 05:39:23 +00:00
|
|
|
let r = this.push(e);
|
|
|
|
return () => this.delete(r);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
et = class t {
|
2024-06-01 06:31:08 +00:00
|
|
|
static {
|
2024-06-02 05:39:23 +00:00
|
|
|
i(this, "EventController");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
paused = !1;
|
|
|
|
cancel;
|
|
|
|
constructor(e) {
|
|
|
|
this.cancel = e;
|
|
|
|
}
|
|
|
|
static join(e) {
|
2024-06-02 05:39:23 +00:00
|
|
|
let r = new t(() => e.forEach((s) => s.cancel()));
|
2024-06-01 06:31:08 +00:00
|
|
|
return (
|
2024-06-02 05:39:23 +00:00
|
|
|
Object.defineProperty(r, "paused", {
|
2024-06-01 06:31:08 +00:00
|
|
|
get: () => e[0].paused,
|
2024-06-02 05:39:23 +00:00
|
|
|
set: (s) => e.forEach((a) => (a.paused = s)),
|
2024-06-01 06:31:08 +00:00
|
|
|
}),
|
2024-06-02 05:39:23 +00:00
|
|
|
(r.paused = !1),
|
|
|
|
r
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
we = class {
|
2024-06-01 06:31:08 +00:00
|
|
|
static {
|
2024-06-02 05:39:23 +00:00
|
|
|
i(this, "Event");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
handlers = new kt();
|
2024-06-01 06:31:08 +00:00
|
|
|
add(e) {
|
2024-06-02 05:39:23 +00:00
|
|
|
let r = this.handlers.pushd((...a) => {
|
|
|
|
s.paused || e(...a);
|
2024-06-01 06:31:08 +00:00
|
|
|
}),
|
2024-06-02 05:39:23 +00:00
|
|
|
s = new et(r);
|
|
|
|
return s;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
addOnce(e) {
|
2024-06-02 05:39:23 +00:00
|
|
|
let r = this.add((...s) => {
|
|
|
|
r.cancel(), e(...s);
|
2024-06-01 06:31:08 +00:00
|
|
|
});
|
2024-06-02 05:39:23 +00:00
|
|
|
return r;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
next() {
|
|
|
|
return new Promise((e) => this.addOnce(e));
|
|
|
|
}
|
|
|
|
trigger(...e) {
|
2024-06-02 05:39:23 +00:00
|
|
|
this.handlers.forEach((r) => r(...e));
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
numListeners() {
|
|
|
|
return this.handlers.size;
|
|
|
|
}
|
|
|
|
clear() {
|
|
|
|
this.handlers.clear();
|
|
|
|
}
|
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
tt = class {
|
2024-06-01 06:31:08 +00:00
|
|
|
static {
|
2024-06-02 05:39:23 +00:00
|
|
|
i(this, "EventHandler");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
handlers = {};
|
2024-06-02 05:39:23 +00:00
|
|
|
on(e, r) {
|
2024-06-01 06:31:08 +00:00
|
|
|
return (
|
2024-06-02 05:39:23 +00:00
|
|
|
this.handlers[e] || (this.handlers[e] = new we()),
|
|
|
|
this.handlers[e].add(r)
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
onOnce(e, r) {
|
|
|
|
let s = this.on(e, (...a) => {
|
|
|
|
s.cancel(), r(...a);
|
2024-06-01 06:31:08 +00:00
|
|
|
});
|
2024-06-02 05:39:23 +00:00
|
|
|
return s;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
next(e) {
|
2024-06-02 05:39:23 +00:00
|
|
|
return new Promise((r) => {
|
|
|
|
this.onOnce(e, (...s) => r(s[0]));
|
2024-06-01 06:31:08 +00:00
|
|
|
});
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
trigger(e, ...r) {
|
|
|
|
this.handlers[e] && this.handlers[e].trigger(...r);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
remove(e) {
|
|
|
|
delete this.handlers[e];
|
|
|
|
}
|
|
|
|
clear() {
|
|
|
|
this.handlers = {};
|
|
|
|
}
|
|
|
|
numListeners(e) {
|
|
|
|
return this.handlers[e]?.numListeners() ?? 0;
|
|
|
|
}
|
|
|
|
};
|
2024-06-02 05:39:23 +00:00
|
|
|
function mn(t, e) {
|
|
|
|
if (t === e) return !0;
|
|
|
|
let r = typeof t,
|
|
|
|
s = typeof e;
|
|
|
|
if (r !== s) return !1;
|
|
|
|
if (r === "object" && s === "object" && t !== null && e !== null) {
|
|
|
|
if (Array.isArray(t) !== Array.isArray(e)) return !1;
|
|
|
|
let a = Object.keys(t),
|
|
|
|
l = Object.keys(e);
|
|
|
|
if (a.length !== l.length) return !1;
|
|
|
|
for (let u of a) {
|
|
|
|
let f = t[u],
|
|
|
|
y = e[u];
|
|
|
|
if (!mn(f, y)) return !1;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
return !0;
|
|
|
|
}
|
|
|
|
return !1;
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(mn, "deepEq");
|
|
|
|
function Gi(t) {
|
|
|
|
let e = window.atob(t),
|
|
|
|
r = e.length,
|
|
|
|
s = new Uint8Array(r);
|
|
|
|
for (let a = 0; a < r; a++) s[a] = e.charCodeAt(a);
|
|
|
|
return s.buffer;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Gi, "base64ToArrayBuffer");
|
|
|
|
function to(t) {
|
|
|
|
return Gi(t.split(",")[1]);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(to, "dataURLToArrayBuffer");
|
|
|
|
function dn(t, e) {
|
|
|
|
let r = document.createElement("a");
|
|
|
|
(r.href = e), (r.download = t), r.click();
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(dn, "download");
|
|
|
|
function sr(t, e) {
|
|
|
|
dn(t, "data:text/plain;charset=utf-8," + e);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(sr, "downloadText");
|
|
|
|
function no(t, e) {
|
|
|
|
sr(t, JSON.stringify(e));
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(no, "downloadJSON");
|
|
|
|
function ir(t, e) {
|
|
|
|
let r = URL.createObjectURL(e);
|
|
|
|
dn(t, r), URL.revokeObjectURL(r);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(ir, "downloadBlob");
|
|
|
|
var ar = i((t) => t.match(/^data:\w+\/\w+;base64,.+/), "isDataURL");
|
|
|
|
var ro = i((t) => t.split(".").slice(0, -1).join("."), "getFileName");
|
|
|
|
function Ie(t, e) {
|
|
|
|
return (...r) => {
|
|
|
|
let s = r.length;
|
|
|
|
if (s === t.length) return t(...r);
|
|
|
|
if (s === e.length) return e(...r);
|
2024-06-01 06:31:08 +00:00
|
|
|
};
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Ie, "overload2");
|
|
|
|
var oo = (() => {
|
|
|
|
let t = 0;
|
|
|
|
return () => t++;
|
2024-06-01 06:31:08 +00:00
|
|
|
})(),
|
2024-06-02 05:39:23 +00:00
|
|
|
so = i(
|
|
|
|
(t) => (t instanceof Error ? t.message : String(t)),
|
2024-06-01 06:31:08 +00:00
|
|
|
"getErrorMessage"
|
|
|
|
);
|
2024-06-02 05:39:23 +00:00
|
|
|
var ln = class {
|
2024-06-01 06:31:08 +00:00
|
|
|
static {
|
2024-06-02 05:39:23 +00:00
|
|
|
i(this, "BinaryHeap");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
_items;
|
|
|
|
_compareFn;
|
2024-06-02 05:39:23 +00:00
|
|
|
constructor(e = (r, s) => r < s) {
|
2024-06-01 06:31:08 +00:00
|
|
|
(this._compareFn = e), (this._items = []);
|
|
|
|
}
|
|
|
|
insert(e) {
|
|
|
|
this._items.push(e), this.moveUp(this._items.length - 1);
|
|
|
|
}
|
|
|
|
remove() {
|
|
|
|
if (this._items.length === 0) return null;
|
|
|
|
let e = this._items[0],
|
2024-06-02 05:39:23 +00:00
|
|
|
r = this._items.pop();
|
2024-06-01 06:31:08 +00:00
|
|
|
return (
|
2024-06-02 05:39:23 +00:00
|
|
|
this._items.length !== 0 && ((this._items[0] = r), this.moveDown(0)), e
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
clear() {
|
|
|
|
this._items.splice(0, this._items.length);
|
|
|
|
}
|
|
|
|
moveUp(e) {
|
|
|
|
for (; e > 0; ) {
|
2024-06-02 05:39:23 +00:00
|
|
|
let r = Math.floor((e - 1) / 2);
|
2024-06-01 06:31:08 +00:00
|
|
|
if (
|
2024-06-02 05:39:23 +00:00
|
|
|
!this._compareFn(this._items[e], this._items[r]) &&
|
|
|
|
this._items[e] >= this._items[r]
|
2024-06-01 06:31:08 +00:00
|
|
|
)
|
|
|
|
break;
|
2024-06-02 05:39:23 +00:00
|
|
|
this.swap(e, r), (e = r);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
moveDown(e) {
|
|
|
|
for (; e < Math.floor(this._items.length / 2); ) {
|
2024-06-02 05:39:23 +00:00
|
|
|
let r = 2 * e + 1;
|
2024-06-01 06:31:08 +00:00
|
|
|
if (
|
2024-06-02 05:39:23 +00:00
|
|
|
(r < this._items.length - 1 &&
|
|
|
|
!this._compareFn(this._items[r], this._items[r + 1]) &&
|
|
|
|
++r,
|
|
|
|
this._compareFn(this._items[e], this._items[r]))
|
2024-06-01 06:31:08 +00:00
|
|
|
)
|
|
|
|
break;
|
2024-06-02 05:39:23 +00:00
|
|
|
this.swap(e, r), (e = r);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
swap(e, r) {
|
|
|
|
[this._items[e], this._items[r]] = [this._items[r], this._items[e]];
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
get length() {
|
|
|
|
return this._items.length;
|
|
|
|
}
|
|
|
|
};
|
2024-06-02 05:39:23 +00:00
|
|
|
var Bi = Object.freeze([
|
2024-06-01 06:31:08 +00:00
|
|
|
776, 2359, 2367, 2984, 3007, 3021, 3633, 3635, 3648, 3657, 4352, 4449, 4520,
|
|
|
|
]);
|
2024-06-02 05:39:23 +00:00
|
|
|
function io(t) {
|
|
|
|
if (typeof t != "string")
|
2024-06-01 06:31:08 +00:00
|
|
|
throw new TypeError("string cannot be undefined or null");
|
|
|
|
let e = [],
|
2024-06-02 05:39:23 +00:00
|
|
|
r = 0,
|
|
|
|
s = 0;
|
|
|
|
for (; r < t.length; ) {
|
2024-06-01 06:31:08 +00:00
|
|
|
if (
|
2024-06-02 05:39:23 +00:00
|
|
|
((s += Fi(r + s, t)),
|
|
|
|
Hi(t[r + s]) && s++,
|
|
|
|
ki(t[r + s]) && s++,
|
|
|
|
Ni(t[r + s]) && s++,
|
|
|
|
Ki(t[r + s]))
|
2024-06-01 06:31:08 +00:00
|
|
|
) {
|
2024-06-02 05:39:23 +00:00
|
|
|
s++;
|
2024-06-01 06:31:08 +00:00
|
|
|
continue;
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
e.push(t.substring(r, r + s)), (r += s), (s = 0);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
return e;
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(io, "runes");
|
|
|
|
function Fi(t, e) {
|
|
|
|
let r = e[t];
|
|
|
|
if (!Ii(r) || t === e.length - 1) return 1;
|
|
|
|
let s = r + e[t + 1],
|
|
|
|
a = e.substring(t + 2, t + 5);
|
|
|
|
return eo(s) && eo(a)
|
2024-06-01 06:31:08 +00:00
|
|
|
? 4
|
2024-06-02 05:39:23 +00:00
|
|
|
: Li(s) && _i(a)
|
|
|
|
? e.slice(t).indexOf(String.fromCodePoint(917631)) + 2
|
|
|
|
: ji(a)
|
2024-06-01 06:31:08 +00:00
|
|
|
? 4
|
|
|
|
: 2;
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Fi, "nextUnits");
|
|
|
|
function Ii(t) {
|
|
|
|
return t && vt(t[0].charCodeAt(0), 55296, 56319);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Ii, "isFirstOfSurrogatePair");
|
|
|
|
function eo(t) {
|
|
|
|
return vt(cr(t), 127462, 127487);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(eo, "isRegionalIndicator");
|
|
|
|
function Li(t) {
|
|
|
|
return vt(cr(t), 127988, 127988);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Li, "isSubdivisionFlag");
|
|
|
|
function ji(t) {
|
|
|
|
return vt(cr(t), 127995, 127999);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(ji, "isFitzpatrickModifier");
|
|
|
|
function ki(t) {
|
|
|
|
return typeof t == "string" && vt(t.charCodeAt(0), 65024, 65039);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(ki, "isVariationSelector");
|
|
|
|
function Ni(t) {
|
|
|
|
return typeof t == "string" && vt(t.charCodeAt(0), 8400, 8447);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Ni, "isDiacriticalMark");
|
|
|
|
function _i(t) {
|
|
|
|
let e = t.codePointAt(0);
|
2024-06-01 06:31:08 +00:00
|
|
|
return (
|
2024-06-02 05:39:23 +00:00
|
|
|
typeof t == "string" && typeof e == "number" && vt(e, 917504, 917631)
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(_i, "isSupplementarySpecialpurposePlane");
|
|
|
|
function Hi(t) {
|
|
|
|
return typeof t == "string" && Bi.includes(t.charCodeAt(0));
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Hi, "isGrapheme");
|
|
|
|
function Ki(t) {
|
|
|
|
return typeof t == "string" && t.charCodeAt(0) === 8205;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Ki, "isZeroWidthJoiner");
|
|
|
|
function cr(t) {
|
|
|
|
let e = t.charCodeAt(0) - 55296,
|
|
|
|
r = t.charCodeAt(1) - 56320;
|
|
|
|
return (e << 10) + r + 65536;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(cr, "codePointFromSurrogatePair");
|
|
|
|
function vt(t, e, r) {
|
|
|
|
return t >= e && t <= r;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(vt, "betweenInclusive");
|
|
|
|
var ur = {
|
2024-06-01 06:31:08 +00:00
|
|
|
"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",
|
|
|
|
},
|
|
|
|
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",
|
|
|
|
},
|
|
|
|
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",
|
|
|
|
},
|
|
|
|
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",
|
|
|
|
},
|
|
|
|
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",
|
|
|
|
},
|
|
|
|
sticks: { left: { x: 0, y: 1 }, right: { x: 2, y: 3 } },
|
|
|
|
},
|
|
|
|
};
|
2024-06-02 05:39:23 +00:00
|
|
|
var Ut = class {
|
2024-06-01 06:31:08 +00:00
|
|
|
static {
|
2024-06-02 05:39:23 +00:00
|
|
|
i(this, "ButtonState");
|
2024-06-01 06:31:08 +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);
|
|
|
|
}
|
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
lr = class {
|
2024-06-01 06:31:08 +00:00
|
|
|
static {
|
2024-06-02 05:39:23 +00:00
|
|
|
i(this, "GamepadState");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
buttonState = new Ut();
|
2024-06-01 06:31:08 +00:00
|
|
|
stickState = new Map();
|
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
mr = class {
|
2024-06-01 06:31:08 +00:00
|
|
|
static {
|
2024-06-02 05:39:23 +00:00
|
|
|
i(this, "FPSCounter");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
dts = [];
|
|
|
|
timer = 0;
|
|
|
|
fps = 0;
|
|
|
|
tick(e) {
|
|
|
|
this.dts.push(e),
|
|
|
|
(this.timer += e),
|
|
|
|
this.timer >= 1 &&
|
|
|
|
((this.timer = 0),
|
|
|
|
(this.fps = Math.round(
|
2024-06-02 05:39:23 +00:00
|
|
|
1 / (this.dts.reduce((r, s) => r + s) / this.dts.length)
|
2024-06-01 06:31:08 +00:00
|
|
|
)),
|
|
|
|
(this.dts = []));
|
|
|
|
}
|
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
ao = i((t) => {
|
|
|
|
if (!t.canvas) throw new Error("Please provide a canvas");
|
2024-06-01 06:31:08 +00:00
|
|
|
let e = {
|
2024-06-02 05:39:23 +00:00
|
|
|
canvas: t.canvas,
|
2024-06-01 06:31:08 +00:00
|
|
|
loopID: null,
|
|
|
|
stopped: !1,
|
|
|
|
dt: 0,
|
|
|
|
time: 0,
|
|
|
|
realTime: 0,
|
2024-06-02 05:39:23 +00:00
|
|
|
fpsCounter: new mr(),
|
2024-06-01 06:31:08 +00:00
|
|
|
timeScale: 1,
|
|
|
|
skipTime: !1,
|
2024-06-02 05:39:23 +00:00
|
|
|
isHidden: !1,
|
2024-06-01 06:31:08 +00:00
|
|
|
numFrames: 0,
|
2024-06-02 05:39:23 +00:00
|
|
|
mousePos: new T(0),
|
|
|
|
mouseDeltaPos: new T(0),
|
|
|
|
keyState: new Ut(),
|
|
|
|
mouseState: new Ut(),
|
|
|
|
mergedGamepadState: new lr(),
|
2024-06-01 06:31:08 +00:00
|
|
|
gamepadStates: new Map(),
|
|
|
|
gamepads: [],
|
|
|
|
charInputted: [],
|
|
|
|
isMouseMoved: !1,
|
2024-06-02 05:39:23 +00:00
|
|
|
lastWidth: t.canvas.offsetWidth,
|
|
|
|
lastHeight: t.canvas.offsetHeight,
|
|
|
|
events: new tt(),
|
2024-06-01 06:31:08 +00:00
|
|
|
};
|
2024-06-02 05:39:23 +00:00
|
|
|
function r() {
|
2024-06-01 06:31:08 +00:00
|
|
|
return e.dt * e.timeScale;
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(r, "dt");
|
|
|
|
function s() {
|
|
|
|
return e.isHidden;
|
|
|
|
}
|
|
|
|
i(s, "isHidden");
|
|
|
|
function a() {
|
2024-06-01 06:31:08 +00:00
|
|
|
return e.time;
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(a, "time");
|
|
|
|
function l() {
|
2024-06-01 06:31:08 +00:00
|
|
|
return e.fpsCounter.fps;
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(l, "fps");
|
|
|
|
function u() {
|
2024-06-01 06:31:08 +00:00
|
|
|
return e.numFrames;
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(u, "numFrames");
|
|
|
|
function f() {
|
2024-06-01 06:31:08 +00:00
|
|
|
return e.canvas.toDataURL();
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(f, "screenshot");
|
|
|
|
function y(p) {
|
|
|
|
e.canvas.style.cursor = p;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(y, "setCursor");
|
|
|
|
function m() {
|
2024-06-01 06:31:08 +00:00
|
|
|
return e.canvas.style.cursor;
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(m, "getCursor");
|
|
|
|
function V(p) {
|
|
|
|
if (p)
|
2024-06-01 06:31:08 +00:00
|
|
|
try {
|
2024-06-02 05:39:23 +00:00
|
|
|
let S = e.canvas.requestPointerLock();
|
|
|
|
S.catch && S.catch((L) => console.error(L));
|
|
|
|
} catch (S) {
|
|
|
|
console.error(S);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
else document.exitPointerLock();
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(V, "setCursorLocked");
|
|
|
|
function x() {
|
2024-06-01 06:31:08 +00:00
|
|
|
return !!document.pointerLockElement;
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(x, "isCursorLocked");
|
|
|
|
function P(p) {
|
|
|
|
p.requestFullscreen
|
|
|
|
? p.requestFullscreen()
|
|
|
|
: p.webkitRequestFullscreen && p.webkitRequestFullscreen();
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(P, "enterFullscreen");
|
|
|
|
function w() {
|
2024-06-01 06:31:08 +00:00
|
|
|
document.exitFullscreen
|
|
|
|
? document.exitFullscreen()
|
|
|
|
: document.webkitExitFullScreen && document.webkitExitFullScreen();
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(w, "exitFullscreen");
|
|
|
|
function K() {
|
2024-06-01 06:31:08 +00:00
|
|
|
return document.fullscreenElement || document.webkitFullscreenElement;
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(K, "getFullscreenElement");
|
|
|
|
function X(p = !0) {
|
|
|
|
p ? P(e.canvas) : w();
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(X, "setFullscreen");
|
|
|
|
function z() {
|
|
|
|
return !!K();
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(z, "isFullscreen");
|
|
|
|
function N() {
|
2024-06-01 06:31:08 +00:00
|
|
|
e.stopped = !0;
|
2024-06-02 05:39:23 +00:00
|
|
|
for (let p in he) e.canvas.removeEventListener(p, he[p]);
|
|
|
|
for (let p in Ke) document.removeEventListener(p, Ke[p]);
|
|
|
|
for (let p in xe) window.removeEventListener(p, xe[p]);
|
|
|
|
at.disconnect();
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(N, "quit");
|
|
|
|
function $(p) {
|
2024-06-01 06:31:08 +00:00
|
|
|
e.loopID !== null && cancelAnimationFrame(e.loopID);
|
2024-06-02 05:39:23 +00:00
|
|
|
let S = 0,
|
|
|
|
L = i((Y) => {
|
2024-06-01 06:31:08 +00:00
|
|
|
if (e.stopped) return;
|
|
|
|
if (document.visibilityState !== "visible") {
|
2024-06-02 05:39:23 +00:00
|
|
|
e.loopID = requestAnimationFrame(L);
|
2024-06-01 06:31:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
let ye = Y / 1e3,
|
|
|
|
ie = ye - e.realTime,
|
|
|
|
Ye = t.maxFPS ? 1 / t.maxFPS : 0;
|
|
|
|
(e.realTime = ye),
|
|
|
|
(S += ie),
|
|
|
|
S > Ye &&
|
2024-06-01 06:31:08 +00:00
|
|
|
(e.skipTime ||
|
2024-06-02 05:39:23 +00:00
|
|
|
((e.dt = S), (e.time += r()), e.fpsCounter.tick(e.dt)),
|
|
|
|
(S = 0),
|
2024-06-01 06:31:08 +00:00
|
|
|
(e.skipTime = !1),
|
|
|
|
e.numFrames++,
|
2024-06-02 05:39:23 +00:00
|
|
|
Mn(),
|
|
|
|
p(),
|
|
|
|
Mt()),
|
|
|
|
(e.loopID = requestAnimationFrame(L));
|
2024-06-01 06:31:08 +00:00
|
|
|
}, "frame");
|
2024-06-02 05:39:23 +00:00
|
|
|
L(0);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i($, "run");
|
|
|
|
function O() {
|
2024-06-01 06:31:08 +00:00
|
|
|
return "ontouchstart" in window || navigator.maxTouchPoints > 0;
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(O, "isTouchscreen");
|
|
|
|
function se() {
|
2024-06-01 06:31:08 +00:00
|
|
|
return e.mousePos.clone();
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(se, "mousePos");
|
|
|
|
function _() {
|
2024-06-01 06:31:08 +00:00
|
|
|
return e.mouseDeltaPos.clone();
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(_, "mouseDeltaPos");
|
|
|
|
function ae(p = "left") {
|
|
|
|
return e.mouseState.pressed.has(p);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(ae, "isMousePressed");
|
|
|
|
function re(p = "left") {
|
|
|
|
return e.mouseState.down.has(p);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(re, "isMouseDown");
|
|
|
|
function ce(p = "left") {
|
|
|
|
return e.mouseState.released.has(p);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(ce, "isMouseReleased");
|
|
|
|
function ge() {
|
2024-06-01 06:31:08 +00:00
|
|
|
return e.isMouseMoved;
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(ge, "isMouseMoved");
|
|
|
|
function Ue(p) {
|
|
|
|
return p === void 0
|
2024-06-01 06:31:08 +00:00
|
|
|
? e.keyState.pressed.size > 0
|
2024-06-02 05:39:23 +00:00
|
|
|
: e.keyState.pressed.has(p);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Ue, "isKeyPressed");
|
|
|
|
function Ce(p) {
|
|
|
|
return p === void 0
|
2024-06-01 06:31:08 +00:00
|
|
|
? e.keyState.pressedRepeat.size > 0
|
2024-06-02 05:39:23 +00:00
|
|
|
: e.keyState.pressedRepeat.has(p);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Ce, "isKeyPressedRepeat");
|
|
|
|
function Le(p) {
|
|
|
|
return p === void 0 ? e.keyState.down.size > 0 : e.keyState.down.has(p);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Le, "isKeyDown");
|
|
|
|
function je(p) {
|
|
|
|
return p === void 0
|
2024-06-01 06:31:08 +00:00
|
|
|
? e.keyState.released.size > 0
|
2024-06-02 05:39:23 +00:00
|
|
|
: e.keyState.released.has(p);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(je, "isKeyReleased");
|
|
|
|
function Ee(p) {
|
|
|
|
return p === void 0
|
2024-06-01 06:31:08 +00:00
|
|
|
? e.mergedGamepadState.buttonState.pressed.size > 0
|
2024-06-02 05:39:23 +00:00
|
|
|
: e.mergedGamepadState.buttonState.pressed.has(p);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Ee, "isGamepadButtonPressed");
|
|
|
|
function Ne(p) {
|
|
|
|
return p === void 0
|
2024-06-01 06:31:08 +00:00
|
|
|
? e.mergedGamepadState.buttonState.down.size > 0
|
2024-06-02 05:39:23 +00:00
|
|
|
: e.mergedGamepadState.buttonState.down.has(p);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Ne, "isGamepadButtonDown");
|
|
|
|
function _e(p) {
|
|
|
|
return p === void 0
|
2024-06-01 06:31:08 +00:00
|
|
|
? e.mergedGamepadState.buttonState.released.size > 0
|
2024-06-02 05:39:23 +00:00
|
|
|
: e.mergedGamepadState.buttonState.released.has(p);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(_e, "isGamepadButtonReleased");
|
|
|
|
function He(p) {
|
|
|
|
return e.events.on("resize", p);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(He, "onResize");
|
|
|
|
let pt = Ie(
|
|
|
|
(p) => e.events.on("keyDown", p),
|
|
|
|
(p, S) => e.events.on("keyDown", (L) => L === p && S(p))
|
2024-06-01 06:31:08 +00:00
|
|
|
),
|
2024-06-02 05:39:23 +00:00
|
|
|
Se = Ie(
|
|
|
|
(p) => e.events.on("keyPress", p),
|
|
|
|
(p, S) => e.events.on("keyPress", (L) => L === p && S(p))
|
2024-06-01 06:31:08 +00:00
|
|
|
),
|
2024-06-02 05:39:23 +00:00
|
|
|
Ve = Ie(
|
|
|
|
(p) => e.events.on("keyPressRepeat", p),
|
|
|
|
(p, S) => e.events.on("keyPressRepeat", (L) => L === p && S(p))
|
2024-06-01 06:31:08 +00:00
|
|
|
),
|
2024-06-02 05:39:23 +00:00
|
|
|
ze = Ie(
|
|
|
|
(p) => e.events.on("keyRelease", p),
|
|
|
|
(p, S) => e.events.on("keyRelease", (L) => L === p && S(p))
|
2024-06-01 06:31:08 +00:00
|
|
|
),
|
2024-06-02 05:39:23 +00:00
|
|
|
rt = Ie(
|
|
|
|
(p) => e.events.on("mouseDown", (S) => p(S)),
|
|
|
|
(p, S) => e.events.on("mouseDown", (L) => L === p && S(L))
|
2024-06-01 06:31:08 +00:00
|
|
|
),
|
2024-06-02 05:39:23 +00:00
|
|
|
ot = Ie(
|
|
|
|
(p) => e.events.on("mousePress", (S) => p(S)),
|
|
|
|
(p, S) => e.events.on("mousePress", (L) => L === p && S(L))
|
2024-06-01 06:31:08 +00:00
|
|
|
),
|
2024-06-02 05:39:23 +00:00
|
|
|
wt = Ie(
|
|
|
|
(p) => e.events.on("mouseRelease", (S) => p(S)),
|
|
|
|
(p, S) => e.events.on("mouseRelease", (L) => L === p && S(L))
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
2024-06-02 05:39:23 +00:00
|
|
|
function Yt(p) {
|
|
|
|
return e.events.on("mouseMove", () => p(se(), _()));
|
|
|
|
}
|
|
|
|
i(Yt, "onMouseMove");
|
|
|
|
function Xt(p) {
|
|
|
|
return e.events.on("charInput", p);
|
|
|
|
}
|
|
|
|
i(Xt, "onCharInput");
|
|
|
|
function An(p) {
|
|
|
|
return e.events.on("touchStart", p);
|
|
|
|
}
|
|
|
|
i(An, "onTouchStart");
|
|
|
|
function Wt(p) {
|
|
|
|
return e.events.on("touchMove", p);
|
|
|
|
}
|
|
|
|
i(Wt, "onTouchMove");
|
|
|
|
function On(p) {
|
|
|
|
return e.events.on("touchEnd", p);
|
|
|
|
}
|
|
|
|
i(On, "onTouchEnd");
|
|
|
|
function Rn(p) {
|
|
|
|
return e.events.on("scroll", p);
|
|
|
|
}
|
|
|
|
i(Rn, "onScroll");
|
|
|
|
function $t(p) {
|
|
|
|
return e.events.on("hide", p);
|
|
|
|
}
|
|
|
|
i($t, "onHide");
|
|
|
|
function Un(p) {
|
|
|
|
return e.events.on("show", p);
|
|
|
|
}
|
|
|
|
i(Un, "onShow");
|
|
|
|
function Vn(p, S) {
|
|
|
|
if (typeof p == "function") return e.events.on("gamepadButtonDown", p);
|
|
|
|
if (typeof p == "string" && typeof S == "function")
|
|
|
|
return e.events.on("gamepadButtonDown", (L) => L === p && S(p));
|
|
|
|
}
|
|
|
|
i(Vn, "onGamepadButtonDown");
|
|
|
|
function Qt(p, S) {
|
|
|
|
if (typeof p == "function") return e.events.on("gamepadButtonPress", p);
|
|
|
|
if (typeof p == "string" && typeof S == "function")
|
|
|
|
return e.events.on("gamepadButtonPress", (L) => L === p && S(p));
|
|
|
|
}
|
|
|
|
i(Qt, "onGamepadButtonPress");
|
|
|
|
function Jt(p, S) {
|
|
|
|
if (typeof p == "function")
|
|
|
|
return e.events.on("gamepadButtonRelease", p);
|
|
|
|
if (typeof p == "string" && typeof S == "function")
|
|
|
|
return e.events.on("gamepadButtonRelease", (L) => L === p && S(p));
|
|
|
|
}
|
|
|
|
i(Jt, "onGamepadButtonRelease");
|
|
|
|
function Pn(p, S) {
|
|
|
|
return e.events.on("gamepadStick", (L, Y) => L === p && S(Y));
|
|
|
|
}
|
|
|
|
i(Pn, "onGamepadStick");
|
|
|
|
function Dt(p) {
|
|
|
|
e.events.on("gamepadConnect", p);
|
|
|
|
}
|
|
|
|
i(Dt, "onGamepadConnect");
|
|
|
|
function Dn(p) {
|
|
|
|
e.events.on("gamepadDisconnect", p);
|
|
|
|
}
|
|
|
|
i(Dn, "onGamepadDisconnect");
|
|
|
|
function st(p) {
|
|
|
|
return e.mergedGamepadState.stickState.get(p) || new T(0);
|
|
|
|
}
|
|
|
|
i(st, "getGamepadStick");
|
|
|
|
function Pe() {
|
2024-06-01 06:31:08 +00:00
|
|
|
return [...e.charInputted];
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Pe, "charInputted");
|
|
|
|
function Ct() {
|
2024-06-01 06:31:08 +00:00
|
|
|
return [...e.gamepads];
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Ct, "getGamepads");
|
|
|
|
function Mn() {
|
2024-06-01 06:31:08 +00:00
|
|
|
e.events.trigger("input"),
|
2024-06-02 05:39:23 +00:00
|
|
|
e.keyState.down.forEach((p) => e.events.trigger("keyDown", p)),
|
|
|
|
e.mouseState.down.forEach((p) => e.events.trigger("mouseDown", p)),
|
|
|
|
de();
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Mn, "processInput");
|
|
|
|
function Mt() {
|
2024-06-01 06:31:08 +00:00
|
|
|
e.keyState.update(),
|
|
|
|
e.mouseState.update(),
|
|
|
|
e.mergedGamepadState.buttonState.update(),
|
2024-06-02 05:39:23 +00:00
|
|
|
e.mergedGamepadState.stickState.forEach((p, S) => {
|
|
|
|
e.mergedGamepadState.stickState.set(S, new T(0));
|
2024-06-01 06:31:08 +00:00
|
|
|
}),
|
|
|
|
(e.charInputted = []),
|
|
|
|
(e.isMouseMoved = !1),
|
2024-06-02 05:39:23 +00:00
|
|
|
e.gamepadStates.forEach((p) => {
|
|
|
|
p.buttonState.update(),
|
|
|
|
p.stickState.forEach((S, L) => {
|
|
|
|
p.stickState.set(L, new T(0));
|
2024-06-01 06:31:08 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Mt, "resetInput");
|
|
|
|
function Zt(p) {
|
|
|
|
let S = {
|
|
|
|
index: p.index,
|
|
|
|
isPressed: (L) =>
|
|
|
|
e.gamepadStates.get(p.index).buttonState.pressed.has(L),
|
|
|
|
isDown: (L) => e.gamepadStates.get(p.index).buttonState.down.has(L),
|
|
|
|
isReleased: (L) =>
|
|
|
|
e.gamepadStates.get(p.index).buttonState.released.has(L),
|
|
|
|
getStick: (L) => e.gamepadStates.get(p.index).stickState.get(L),
|
2024-06-01 06:31:08 +00:00
|
|
|
};
|
|
|
|
return (
|
2024-06-02 05:39:23 +00:00
|
|
|
e.gamepads.push(S),
|
|
|
|
e.gamepadStates.set(p.index, {
|
|
|
|
buttonState: new Ut(),
|
2024-06-01 06:31:08 +00:00
|
|
|
stickState: new Map([
|
2024-06-02 05:39:23 +00:00
|
|
|
["left", new T(0)],
|
|
|
|
["right", new T(0)],
|
2024-06-01 06:31:08 +00:00
|
|
|
]),
|
|
|
|
}),
|
2024-06-02 05:39:23 +00:00
|
|
|
S
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Zt, "registerGamepad");
|
|
|
|
function Gn(p) {
|
|
|
|
(e.gamepads = e.gamepads.filter((S) => S.index !== p.index)),
|
|
|
|
e.gamepadStates.delete(p.index);
|
|
|
|
}
|
|
|
|
i(Gn, "removeGamepad");
|
|
|
|
function de() {
|
|
|
|
for (let p of navigator.getGamepads())
|
|
|
|
p && !e.gamepadStates.has(p.index) && Zt(p);
|
|
|
|
for (let p of e.gamepads) {
|
|
|
|
let S = navigator.getGamepads()[p.index],
|
|
|
|
Y = (t.gamepads ?? {})[S.id] ?? ur[S.id] ?? ur.default,
|
|
|
|
ye = e.gamepadStates.get(p.index);
|
|
|
|
for (let ie = 0; ie < S.buttons.length; ie++)
|
|
|
|
S.buttons[ie].pressed
|
|
|
|
? (ye.buttonState.down.has(Y.buttons[ie]) ||
|
|
|
|
(e.mergedGamepadState.buttonState.press(Y.buttons[ie]),
|
|
|
|
ye.buttonState.press(Y.buttons[ie]),
|
|
|
|
e.events.trigger("gamepadButtonPress", Y.buttons[ie])),
|
|
|
|
e.events.trigger("gamepadButtonDown", Y.buttons[ie]))
|
|
|
|
: ye.buttonState.down.has(Y.buttons[ie]) &&
|
|
|
|
(e.mergedGamepadState.buttonState.release(Y.buttons[ie]),
|
|
|
|
ye.buttonState.release(Y.buttons[ie]),
|
|
|
|
e.events.trigger("gamepadButtonRelease", Y.buttons[ie]));
|
|
|
|
for (let ie in Y.sticks) {
|
|
|
|
let Ye = Y.sticks[ie],
|
|
|
|
ft = new T(S.axes[Ye.x], S.axes[Ye.y]);
|
|
|
|
ye.stickState.set(ie, ft),
|
|
|
|
e.mergedGamepadState.stickState.set(ie, ft),
|
|
|
|
e.events.trigger("gamepadStick", ie, ft);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(de, "processGamepad");
|
|
|
|
let he = {},
|
|
|
|
Ke = {},
|
|
|
|
xe = {},
|
|
|
|
Ae = t.pixelDensity || window.devicePixelRatio || 1;
|
|
|
|
he.mousemove = (p) => {
|
|
|
|
let S = new T(p.offsetX, p.offsetY),
|
|
|
|
L = new T(p.movementX, p.movementY);
|
|
|
|
if (z()) {
|
|
|
|
let Y = e.canvas.width / Ae,
|
|
|
|
ye = e.canvas.height / Ae,
|
|
|
|
ie = window.innerWidth,
|
|
|
|
Ye = window.innerHeight,
|
|
|
|
ft = ie / Ye,
|
|
|
|
tn = Y / ye;
|
|
|
|
if (ft > tn) {
|
|
|
|
let Xe = Ye / ye,
|
|
|
|
Tt = (ie - Y * Xe) / 2;
|
|
|
|
(S.x = dt(p.offsetX - Tt, 0, Y * Xe, 0, Y)),
|
|
|
|
(S.y = dt(p.offsetY, 0, ye * Xe, 0, ye));
|
2024-06-01 06:31:08 +00:00
|
|
|
} else {
|
2024-06-02 05:39:23 +00:00
|
|
|
let Xe = ie / Y,
|
|
|
|
Tt = (Ye - ye * Xe) / 2;
|
|
|
|
(S.x = dt(p.offsetX, 0, Y * Xe, 0, Y)),
|
|
|
|
(S.y = dt(p.offsetY - Tt, 0, ye * Xe, 0, ye));
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
e.events.onOnce("input", () => {
|
|
|
|
(e.isMouseMoved = !0),
|
2024-06-02 05:39:23 +00:00
|
|
|
(e.mousePos = S),
|
|
|
|
(e.mouseDeltaPos = L),
|
2024-06-01 06:31:08 +00:00
|
|
|
e.events.trigger("mouseMove");
|
|
|
|
});
|
|
|
|
};
|
2024-06-02 05:39:23 +00:00
|
|
|
let it = ["left", "middle", "right", "back", "forward"];
|
|
|
|
(he.mousedown = (p) => {
|
2024-06-01 06:31:08 +00:00
|
|
|
e.events.onOnce("input", () => {
|
2024-06-02 05:39:23 +00:00
|
|
|
let S = it[p.button];
|
|
|
|
S && (e.mouseState.press(S), e.events.trigger("mousePress", S));
|
2024-06-01 06:31:08 +00:00
|
|
|
});
|
|
|
|
}),
|
2024-06-02 05:39:23 +00:00
|
|
|
(he.mouseup = (p) => {
|
2024-06-01 06:31:08 +00:00
|
|
|
e.events.onOnce("input", () => {
|
2024-06-02 05:39:23 +00:00
|
|
|
let S = it[p.button];
|
|
|
|
S && (e.mouseState.release(S), e.events.trigger("mouseRelease", S));
|
2024-06-01 06:31:08 +00:00
|
|
|
});
|
|
|
|
});
|
2024-06-02 05:39:23 +00:00
|
|
|
let Gt = new Set([
|
2024-06-01 06:31:08 +00:00
|
|
|
" ",
|
|
|
|
"ArrowLeft",
|
|
|
|
"ArrowRight",
|
|
|
|
"ArrowUp",
|
|
|
|
"ArrowDown",
|
|
|
|
"Tab",
|
|
|
|
]),
|
2024-06-02 05:39:23 +00:00
|
|
|
en = {
|
2024-06-01 06:31:08 +00:00
|
|
|
ArrowLeft: "left",
|
|
|
|
ArrowRight: "right",
|
|
|
|
ArrowUp: "up",
|
|
|
|
ArrowDown: "down",
|
|
|
|
" ": "space",
|
|
|
|
};
|
2024-06-02 05:39:23 +00:00
|
|
|
(he.keydown = (p) => {
|
|
|
|
Gt.has(p.key) && p.preventDefault(),
|
2024-06-01 06:31:08 +00:00
|
|
|
e.events.onOnce("input", () => {
|
2024-06-02 05:39:23 +00:00
|
|
|
let S = en[p.key] || p.key.toLowerCase();
|
|
|
|
S.length === 1
|
|
|
|
? (e.events.trigger("charInput", S), e.charInputted.push(S))
|
|
|
|
: S === "space" &&
|
2024-06-01 06:31:08 +00:00
|
|
|
(e.events.trigger("charInput", " "), e.charInputted.push(" ")),
|
2024-06-02 05:39:23 +00:00
|
|
|
p.repeat
|
|
|
|
? (e.keyState.pressRepeat(S),
|
|
|
|
e.events.trigger("keyPressRepeat", S))
|
|
|
|
: (e.keyState.press(S),
|
|
|
|
e.events.trigger("keyPressRepeat", S),
|
|
|
|
e.events.trigger("keyPress", S));
|
2024-06-01 06:31:08 +00:00
|
|
|
});
|
|
|
|
}),
|
2024-06-02 05:39:23 +00:00
|
|
|
(he.keyup = (p) => {
|
2024-06-01 06:31:08 +00:00
|
|
|
e.events.onOnce("input", () => {
|
2024-06-02 05:39:23 +00:00
|
|
|
let S = en[p.key] || p.key.toLowerCase();
|
|
|
|
e.keyState.release(S), e.events.trigger("keyRelease", S);
|
2024-06-01 06:31:08 +00:00
|
|
|
});
|
|
|
|
}),
|
2024-06-02 05:39:23 +00:00
|
|
|
(he.touchstart = (p) => {
|
|
|
|
p.preventDefault(),
|
2024-06-01 06:31:08 +00:00
|
|
|
e.events.onOnce("input", () => {
|
2024-06-02 05:39:23 +00:00
|
|
|
let S = [...p.changedTouches],
|
|
|
|
L = e.canvas.getBoundingClientRect();
|
|
|
|
t.touchToMouse !== !1 &&
|
|
|
|
((e.mousePos = new T(S[0].clientX - L.x, S[0].clientY - L.y)),
|
2024-06-01 06:31:08 +00:00
|
|
|
e.mouseState.press("left"),
|
|
|
|
e.events.trigger("mousePress", "left")),
|
2024-06-02 05:39:23 +00:00
|
|
|
S.forEach((Y) => {
|
2024-06-01 06:31:08 +00:00
|
|
|
e.events.trigger(
|
|
|
|
"touchStart",
|
2024-06-02 05:39:23 +00:00
|
|
|
new T(Y.clientX - L.x, Y.clientY - L.y),
|
|
|
|
Y
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}),
|
2024-06-02 05:39:23 +00:00
|
|
|
(he.touchmove = (p) => {
|
|
|
|
p.preventDefault(),
|
2024-06-01 06:31:08 +00:00
|
|
|
e.events.onOnce("input", () => {
|
2024-06-02 05:39:23 +00:00
|
|
|
let S = [...p.changedTouches],
|
|
|
|
L = e.canvas.getBoundingClientRect();
|
|
|
|
if (t.touchToMouse !== !1) {
|
|
|
|
let Y = e.mousePos;
|
|
|
|
(e.mousePos = new T(S[0].clientX - L.x, S[0].clientY - L.y)),
|
|
|
|
(e.mouseDeltaPos = e.mousePos.sub(Y)),
|
|
|
|
e.events.trigger("mouseMove");
|
|
|
|
}
|
|
|
|
S.forEach((Y) => {
|
|
|
|
e.events.trigger(
|
|
|
|
"touchMove",
|
|
|
|
new T(Y.clientX - L.x, Y.clientY - L.y),
|
|
|
|
Y
|
|
|
|
);
|
|
|
|
});
|
2024-06-01 06:31:08 +00:00
|
|
|
});
|
|
|
|
}),
|
2024-06-02 05:39:23 +00:00
|
|
|
(he.touchend = (p) => {
|
2024-06-01 06:31:08 +00:00
|
|
|
e.events.onOnce("input", () => {
|
2024-06-02 05:39:23 +00:00
|
|
|
let S = [...p.changedTouches],
|
|
|
|
L = e.canvas.getBoundingClientRect();
|
|
|
|
t.touchToMouse !== !1 &&
|
|
|
|
((e.mousePos = new T(S[0].clientX - L.x, S[0].clientY - L.y)),
|
|
|
|
(e.mouseDeltaPos = new T(0, 0)),
|
2024-06-01 06:31:08 +00:00
|
|
|
e.mouseState.release("left"),
|
|
|
|
e.events.trigger("mouseRelease", "left")),
|
2024-06-02 05:39:23 +00:00
|
|
|
S.forEach((Y) => {
|
2024-06-01 06:31:08 +00:00
|
|
|
e.events.trigger(
|
|
|
|
"touchEnd",
|
2024-06-02 05:39:23 +00:00
|
|
|
new T(Y.clientX - L.x, Y.clientY - L.y),
|
|
|
|
Y
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}),
|
2024-06-02 05:39:23 +00:00
|
|
|
(he.touchcancel = (p) => {
|
2024-06-01 06:31:08 +00:00
|
|
|
e.events.onOnce("input", () => {
|
2024-06-02 05:39:23 +00:00
|
|
|
let S = [...p.changedTouches],
|
|
|
|
L = e.canvas.getBoundingClientRect();
|
|
|
|
t.touchToMouse !== !1 &&
|
|
|
|
((e.mousePos = new T(S[0].clientX - L.x, S[0].clientY - L.y)),
|
2024-06-01 06:31:08 +00:00
|
|
|
e.mouseState.release("left"),
|
|
|
|
e.events.trigger("mouseRelease", "left")),
|
2024-06-02 05:39:23 +00:00
|
|
|
S.forEach((Y) => {
|
2024-06-01 06:31:08 +00:00
|
|
|
e.events.trigger(
|
|
|
|
"touchEnd",
|
2024-06-02 05:39:23 +00:00
|
|
|
new T(Y.clientX - L.x, Y.clientY - L.y),
|
|
|
|
Y
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}),
|
2024-06-02 05:39:23 +00:00
|
|
|
(he.wheel = (p) => {
|
|
|
|
p.preventDefault(),
|
2024-06-01 06:31:08 +00:00
|
|
|
e.events.onOnce("input", () => {
|
2024-06-02 05:39:23 +00:00
|
|
|
e.events.trigger("scroll", new T(p.deltaX, p.deltaY));
|
2024-06-01 06:31:08 +00:00
|
|
|
});
|
|
|
|
}),
|
2024-06-02 05:39:23 +00:00
|
|
|
(he.contextmenu = (p) => p.preventDefault()),
|
|
|
|
(Ke.visibilitychange = () => {
|
2024-06-01 06:31:08 +00:00
|
|
|
document.visibilityState === "visible"
|
2024-06-02 05:39:23 +00:00
|
|
|
? ((e.skipTime = !0), (e.isHidden = !1), e.events.trigger("show"))
|
|
|
|
: ((e.isHidden = !0), e.events.trigger("hide"));
|
2024-06-01 06:31:08 +00:00
|
|
|
}),
|
2024-06-02 05:39:23 +00:00
|
|
|
(xe.gamepadconnected = (p) => {
|
|
|
|
let S = Zt(p.gamepad);
|
2024-06-01 06:31:08 +00:00
|
|
|
e.events.onOnce("input", () => {
|
2024-06-02 05:39:23 +00:00
|
|
|
e.events.trigger("gamepadConnect", S);
|
2024-06-01 06:31:08 +00:00
|
|
|
});
|
|
|
|
}),
|
2024-06-02 05:39:23 +00:00
|
|
|
(xe.gamepaddisconnected = (p) => {
|
|
|
|
let S = Ct().filter((L) => L.index === p.gamepad.index)[0];
|
|
|
|
Gn(p.gamepad),
|
2024-06-01 06:31:08 +00:00
|
|
|
e.events.onOnce("input", () => {
|
2024-06-02 05:39:23 +00:00
|
|
|
e.events.trigger("gamepadDisconnect", S);
|
2024-06-01 06:31:08 +00:00
|
|
|
});
|
|
|
|
});
|
2024-06-02 05:39:23 +00:00
|
|
|
for (let p in he) e.canvas.addEventListener(p, he[p]);
|
|
|
|
for (let p in Ke) document.addEventListener(p, Ke[p]);
|
|
|
|
for (let p in xe) window.addEventListener(p, xe[p]);
|
|
|
|
let at = new ResizeObserver((p) => {
|
|
|
|
for (let S of p)
|
|
|
|
if (S.target === e.canvas) {
|
2024-06-01 06:31:08 +00:00
|
|
|
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");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return (
|
2024-06-02 05:39:23 +00:00
|
|
|
at.observe(e.canvas),
|
2024-06-01 06:31:08 +00:00
|
|
|
{
|
2024-06-02 05:39:23 +00:00
|
|
|
dt: r,
|
|
|
|
time: a,
|
|
|
|
run: $,
|
2024-06-01 06:31:08 +00:00
|
|
|
canvas: e.canvas,
|
2024-06-02 05:39:23 +00:00
|
|
|
fps: l,
|
|
|
|
numFrames: u,
|
|
|
|
quit: N,
|
|
|
|
isHidden: s,
|
|
|
|
setFullscreen: X,
|
|
|
|
isFullscreen: z,
|
|
|
|
setCursor: y,
|
|
|
|
screenshot: f,
|
|
|
|
getGamepads: Ct,
|
|
|
|
getCursor: m,
|
|
|
|
setCursorLocked: V,
|
|
|
|
isCursorLocked: x,
|
|
|
|
isTouchscreen: O,
|
|
|
|
mousePos: se,
|
|
|
|
mouseDeltaPos: _,
|
|
|
|
isKeyDown: Le,
|
|
|
|
isKeyPressed: Ue,
|
|
|
|
isKeyPressedRepeat: Ce,
|
|
|
|
isKeyReleased: je,
|
|
|
|
isMouseDown: re,
|
|
|
|
isMousePressed: ae,
|
|
|
|
isMouseReleased: ce,
|
|
|
|
isMouseMoved: ge,
|
|
|
|
isGamepadButtonPressed: Ee,
|
|
|
|
isGamepadButtonDown: Ne,
|
|
|
|
isGamepadButtonReleased: _e,
|
|
|
|
getGamepadStick: st,
|
|
|
|
charInputted: Pe,
|
|
|
|
onResize: He,
|
|
|
|
onKeyDown: pt,
|
|
|
|
onKeyPress: Se,
|
|
|
|
onKeyPressRepeat: Ve,
|
|
|
|
onKeyRelease: ze,
|
|
|
|
onMouseDown: rt,
|
|
|
|
onMousePress: ot,
|
|
|
|
onMouseRelease: wt,
|
|
|
|
onMouseMove: Yt,
|
|
|
|
onCharInput: Xt,
|
|
|
|
onTouchStart: An,
|
|
|
|
onTouchMove: Wt,
|
|
|
|
onTouchEnd: On,
|
|
|
|
onScroll: Rn,
|
|
|
|
onHide: $t,
|
|
|
|
onShow: Un,
|
|
|
|
onGamepadButtonDown: Vn,
|
|
|
|
onGamepadButtonPress: Qt,
|
|
|
|
onGamepadButtonRelease: Jt,
|
|
|
|
onGamepadStick: Pn,
|
|
|
|
onGamepadConnect: Dt,
|
|
|
|
onGamepadDisconnect: Dn,
|
2024-06-01 06:31:08 +00:00
|
|
|
events: e.events,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}, "default");
|
2024-06-02 05:39:23 +00:00
|
|
|
var qe = class t {
|
2024-06-01 06:31:08 +00:00
|
|
|
static {
|
2024-06-02 05:39:23 +00:00
|
|
|
i(this, "Texture");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
ctx;
|
|
|
|
src = null;
|
|
|
|
glTex;
|
|
|
|
width;
|
|
|
|
height;
|
2024-06-02 05:39:23 +00:00
|
|
|
constructor(e, r, s, a = {}) {
|
2024-06-01 06:31:08 +00:00
|
|
|
this.ctx = e;
|
2024-06-02 05:39:23 +00:00
|
|
|
let l = e.gl;
|
2024-06-01 06:31:08 +00:00
|
|
|
(this.glTex = e.gl.createTexture()),
|
|
|
|
e.onDestroy(() => this.free()),
|
2024-06-02 05:39:23 +00:00
|
|
|
(this.width = r),
|
|
|
|
(this.height = s);
|
|
|
|
let u =
|
|
|
|
{ linear: l.LINEAR, nearest: l.NEAREST }[
|
|
|
|
a.filter ?? e.opts.texFilter
|
|
|
|
] ?? l.NEAREST,
|
|
|
|
f =
|
|
|
|
{ repeat: l.REPEAT, clampToEadge: l.CLAMP_TO_EDGE }[a.wrap] ??
|
|
|
|
l.CLAMP_TO_EDGE;
|
2024-06-01 06:31:08 +00:00
|
|
|
this.bind(),
|
2024-06-02 05:39:23 +00:00
|
|
|
r &&
|
|
|
|
s &&
|
|
|
|
l.texImage2D(
|
|
|
|
l.TEXTURE_2D,
|
2024-06-01 06:31:08 +00:00
|
|
|
0,
|
2024-06-02 05:39:23 +00:00
|
|
|
l.RGBA,
|
|
|
|
r,
|
|
|
|
s,
|
2024-06-01 06:31:08 +00:00
|
|
|
0,
|
2024-06-02 05:39:23 +00:00
|
|
|
l.RGBA,
|
|
|
|
l.UNSIGNED_BYTE,
|
2024-06-01 06:31:08 +00:00
|
|
|
null
|
|
|
|
),
|
2024-06-02 05:39:23 +00:00
|
|
|
l.texParameteri(l.TEXTURE_2D, l.TEXTURE_MIN_FILTER, u),
|
|
|
|
l.texParameteri(l.TEXTURE_2D, l.TEXTURE_MAG_FILTER, u),
|
|
|
|
l.texParameteri(l.TEXTURE_2D, l.TEXTURE_WRAP_S, f),
|
|
|
|
l.texParameteri(l.TEXTURE_2D, l.TEXTURE_WRAP_T, f),
|
2024-06-01 06:31:08 +00:00
|
|
|
this.unbind();
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
static fromImage(e, r, s = {}) {
|
|
|
|
let a = new t(e, r.width, r.height, s);
|
|
|
|
return a.update(r), (a.src = r), a;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
update(e, r = 0, s = 0) {
|
|
|
|
let a = this.ctx.gl;
|
2024-06-01 06:31:08 +00:00
|
|
|
this.bind(),
|
2024-06-02 05:39:23 +00:00
|
|
|
a.texSubImage2D(a.TEXTURE_2D, 0, r, s, a.RGBA, a.UNSIGNED_BYTE, e),
|
2024-06-01 06:31:08 +00:00
|
|
|
this.unbind();
|
|
|
|
}
|
|
|
|
bind() {
|
|
|
|
this.ctx.pushTexture2D(this.glTex);
|
|
|
|
}
|
|
|
|
unbind() {
|
|
|
|
this.ctx.popTexture2D();
|
|
|
|
}
|
|
|
|
free() {
|
|
|
|
this.ctx.gl.deleteTexture(this.glTex);
|
|
|
|
}
|
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
yt = class {
|
2024-06-01 06:31:08 +00:00
|
|
|
static {
|
2024-06-02 05:39:23 +00:00
|
|
|
i(this, "FrameBuffer");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
ctx;
|
|
|
|
tex;
|
|
|
|
glFramebuffer;
|
|
|
|
glRenderbuffer;
|
2024-06-02 05:39:23 +00:00
|
|
|
constructor(e, r, s, a = {}) {
|
2024-06-01 06:31:08 +00:00
|
|
|
this.ctx = e;
|
2024-06-02 05:39:23 +00:00
|
|
|
let l = e.gl;
|
2024-06-01 06:31:08 +00:00
|
|
|
e.onDestroy(() => this.free()),
|
2024-06-02 05:39:23 +00:00
|
|
|
(this.tex = new qe(e, r, s, a)),
|
|
|
|
(this.glFramebuffer = l.createFramebuffer()),
|
|
|
|
(this.glRenderbuffer = l.createRenderbuffer()),
|
2024-06-01 06:31:08 +00:00
|
|
|
this.bind(),
|
2024-06-02 05:39:23 +00:00
|
|
|
l.renderbufferStorage(l.RENDERBUFFER, l.DEPTH_STENCIL, r, s),
|
|
|
|
l.framebufferTexture2D(
|
|
|
|
l.FRAMEBUFFER,
|
|
|
|
l.COLOR_ATTACHMENT0,
|
|
|
|
l.TEXTURE_2D,
|
2024-06-01 06:31:08 +00:00
|
|
|
this.tex.glTex,
|
|
|
|
0
|
|
|
|
),
|
2024-06-02 05:39:23 +00:00
|
|
|
l.framebufferRenderbuffer(
|
|
|
|
l.FRAMEBUFFER,
|
|
|
|
l.DEPTH_STENCIL_ATTACHMENT,
|
|
|
|
l.RENDERBUFFER,
|
2024-06-01 06:31:08 +00:00
|
|
|
this.glRenderbuffer
|
|
|
|
),
|
|
|
|
this.unbind();
|
|
|
|
}
|
|
|
|
get width() {
|
|
|
|
return this.tex.width;
|
|
|
|
}
|
|
|
|
get height() {
|
|
|
|
return this.tex.height;
|
|
|
|
}
|
|
|
|
toImageData() {
|
|
|
|
let e = this.ctx.gl,
|
2024-06-02 05:39:23 +00:00
|
|
|
r = new Uint8ClampedArray(this.width * this.height * 4);
|
2024-06-01 06:31:08 +00:00
|
|
|
this.bind(),
|
|
|
|
e.readPixels(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
this.width,
|
|
|
|
this.height,
|
|
|
|
e.RGBA,
|
|
|
|
e.UNSIGNED_BYTE,
|
2024-06-02 05:39:23 +00:00
|
|
|
r
|
2024-06-01 06:31:08 +00:00
|
|
|
),
|
|
|
|
this.unbind();
|
2024-06-02 05:39:23 +00:00
|
|
|
let s = this.width * 4,
|
|
|
|
a = new Uint8Array(s);
|
|
|
|
for (let l = 0; l < ((this.height / 2) | 0); l++) {
|
|
|
|
let u = l * s,
|
|
|
|
f = (this.height - l - 1) * s;
|
|
|
|
a.set(r.subarray(u, u + s)), r.copyWithin(u, f, f + s), r.set(a, f);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
return new ImageData(r, this.width, this.height);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
toDataURL() {
|
|
|
|
let e = document.createElement("canvas"),
|
2024-06-02 05:39:23 +00:00
|
|
|
r = e.getContext("2d");
|
2024-06-01 06:31:08 +00:00
|
|
|
return (
|
|
|
|
(e.width = this.width),
|
|
|
|
(e.height = this.height),
|
2024-06-02 05:39:23 +00:00
|
|
|
r.putImageData(this.toImageData(), 0, 0),
|
2024-06-01 06:31:08 +00:00
|
|
|
e.toDataURL()
|
|
|
|
);
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
clear() {
|
|
|
|
let e = this.ctx.gl;
|
|
|
|
e.clear(e.COLOR_BUFFER_BIT);
|
|
|
|
}
|
2024-06-01 06:31:08 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
hn = class {
|
2024-06-01 06:31:08 +00:00
|
|
|
static {
|
2024-06-02 05:39:23 +00:00
|
|
|
i(this, "Shader");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
ctx;
|
|
|
|
glProgram;
|
2024-06-02 05:39:23 +00:00
|
|
|
constructor(e, r, s, a) {
|
2024-06-01 06:31:08 +00:00
|
|
|
(this.ctx = e), e.onDestroy(() => this.free());
|
2024-06-02 05:39:23 +00:00
|
|
|
let l = e.gl,
|
|
|
|
u = l.createShader(l.VERTEX_SHADER),
|
|
|
|
f = l.createShader(l.FRAGMENT_SHADER);
|
|
|
|
l.shaderSource(u, r),
|
|
|
|
l.shaderSource(f, s),
|
|
|
|
l.compileShader(u),
|
|
|
|
l.compileShader(f);
|
|
|
|
let y = l.createProgram();
|
2024-06-01 06:31:08 +00:00
|
|
|
if (
|
2024-06-02 05:39:23 +00:00
|
|
|
((this.glProgram = y),
|
|
|
|
l.attachShader(y, u),
|
|
|
|
l.attachShader(y, f),
|
|
|
|
a.forEach((m, V) => l.bindAttribLocation(y, V, m)),
|
|
|
|
l.linkProgram(y),
|
|
|
|
!l.getProgramParameter(y, l.LINK_STATUS))
|
2024-06-01 06:31:08 +00:00
|
|
|
) {
|
2024-06-02 05:39:23 +00:00
|
|
|
let m = l.getShaderInfoLog(u);
|
|
|
|
if (m) throw new Error("VERTEX SHADER " + m);
|
|
|
|
let V = l.getShaderInfoLog(f);
|
|
|
|
if (V) throw new Error("FRAGMENT SHADER " + V);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
l.deleteShader(u), l.deleteShader(f);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
bind() {
|
|
|
|
this.ctx.pushProgram(this.glProgram);
|
|
|
|
}
|
|
|
|
unbind() {
|
|
|
|
this.ctx.popProgram();
|
|
|
|
}
|
|
|
|
send(e) {
|
2024-06-02 05:39:23 +00:00
|
|
|
let r = this.ctx.gl;
|
|
|
|
for (let s in e) {
|
|
|
|
let a = e[s],
|
|
|
|
l = r.getUniformLocation(this.glProgram, s);
|
|
|
|
if (typeof a == "number") r.uniform1f(l, a);
|
|
|
|
else if (a instanceof Ge)
|
|
|
|
r.uniformMatrix4fv(l, !1, new Float32Array(a.m));
|
|
|
|
else if (a instanceof ee) r.uniform3f(l, a.r, a.g, a.b);
|
|
|
|
else if (a instanceof T) r.uniform2f(l, a.x, a.y);
|
|
|
|
else if (Array.isArray(a)) {
|
|
|
|
let u = a[0];
|
|
|
|
typeof u == "number"
|
|
|
|
? r.uniform1fv(l, a)
|
|
|
|
: u instanceof T
|
|
|
|
? r.uniform2fv(l, a.map((f) => [f.x, f.y]).flat())
|
|
|
|
: u instanceof ee &&
|
|
|
|
r.uniform3fv(l, 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
|
|
|
}
|
|
|
|
}
|
|
|
|
free() {
|
|
|
|
this.ctx.gl.deleteProgram(this.glProgram);
|
|
|
|
}
|
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
pn = class {
|
2024-06-01 06:31:08 +00:00
|
|
|
static {
|
2024-06-02 05:39:23 +00:00
|
|
|
i(this, "BatchRenderer");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
ctx;
|
|
|
|
glVBuf;
|
|
|
|
glIBuf;
|
|
|
|
vqueue = [];
|
|
|
|
iqueue = [];
|
|
|
|
stride;
|
|
|
|
maxVertices;
|
|
|
|
maxIndices;
|
|
|
|
vertexFormat;
|
|
|
|
numDraws = 0;
|
|
|
|
curPrimitive = null;
|
|
|
|
curTex = null;
|
|
|
|
curShader = null;
|
|
|
|
curUniform = {};
|
2024-06-02 05:39:23 +00:00
|
|
|
constructor(e, r, s, a) {
|
|
|
|
let l = e.gl;
|
|
|
|
(this.vertexFormat = r),
|
2024-06-01 06:31:08 +00:00
|
|
|
(this.ctx = e),
|
2024-06-02 05:39:23 +00:00
|
|
|
(this.stride = r.reduce((u, f) => u + f.size, 0)),
|
|
|
|
(this.maxVertices = s),
|
|
|
|
(this.maxIndices = a),
|
|
|
|
(this.glVBuf = l.createBuffer()),
|
2024-06-01 06:31:08 +00:00
|
|
|
e.pushArrayBuffer(this.glVBuf),
|
2024-06-02 05:39:23 +00:00
|
|
|
l.bufferData(l.ARRAY_BUFFER, s * 4, l.DYNAMIC_DRAW),
|
2024-06-01 06:31:08 +00:00
|
|
|
e.popArrayBuffer(),
|
2024-06-02 05:39:23 +00:00
|
|
|
(this.glIBuf = l.createBuffer()),
|
2024-06-01 06:31:08 +00:00
|
|
|
e.pushElementArrayBuffer(this.glIBuf),
|
2024-06-02 05:39:23 +00:00
|
|
|
l.bufferData(l.ELEMENT_ARRAY_BUFFER, a * 4, l.DYNAMIC_DRAW),
|
2024-06-01 06:31:08 +00:00
|
|
|
e.popElementArrayBuffer();
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
push(e, r, s, a, l = null, u = {}) {
|
2024-06-01 06:31:08 +00:00
|
|
|
(e !== this.curPrimitive ||
|
2024-06-02 05:39:23 +00:00
|
|
|
l !== this.curTex ||
|
|
|
|
a !== this.curShader ||
|
|
|
|
!mn(this.curUniform, u) ||
|
|
|
|
this.vqueue.length + r.length * this.stride > this.maxVertices ||
|
|
|
|
this.iqueue.length + s.length > this.maxIndices) &&
|
2024-06-01 06:31:08 +00:00
|
|
|
this.flush();
|
2024-06-02 05:39:23 +00:00
|
|
|
let f = this.vqueue.length / this.stride;
|
|
|
|
for (let y of r) this.vqueue.push(y);
|
|
|
|
for (let y of s) this.iqueue.push(y + f);
|
2024-06-01 06:31:08 +00:00
|
|
|
(this.curPrimitive = e),
|
2024-06-02 05:39:23 +00:00
|
|
|
(this.curShader = a),
|
|
|
|
(this.curTex = l),
|
|
|
|
(this.curUniform = u);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
2024-06-02 05:39:23 +00:00
|
|
|
function xt(t) {
|
2024-06-01 06:31:08 +00:00
|
|
|
let e = [],
|
2024-06-02 05:39:23 +00:00
|
|
|
r = i((l) => {
|
|
|
|
e.push(l), t(l);
|
2024-06-01 06:31:08 +00:00
|
|
|
}, "push"),
|
2024-06-02 05:39:23 +00:00
|
|
|
s = i(() => {
|
|
|
|
e.pop(), t(a() ?? null);
|
2024-06-01 06:31:08 +00:00
|
|
|
}, "pop"),
|
2024-06-02 05:39:23 +00:00
|
|
|
a = i(() => e[e.length - 1], "cur");
|
|
|
|
return [r, s, a];
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(xt, "genStack");
|
|
|
|
function dr(t, e = {}) {
|
|
|
|
let r = [];
|
|
|
|
function s(_) {
|
|
|
|
r.push(_);
|
|
|
|
}
|
|
|
|
i(s, "onDestroy");
|
|
|
|
function a() {
|
|
|
|
r.forEach((_) => _()), t.getExtension("WEBGL_lose_context").loseContext();
|
|
|
|
}
|
|
|
|
i(a, "destroy");
|
|
|
|
let l = null;
|
|
|
|
function u(_) {
|
|
|
|
if (mn(_, l)) return;
|
|
|
|
l = _;
|
|
|
|
let ae = _.reduce((re, ce) => re + ce.size, 0);
|
|
|
|
_.reduce(
|
|
|
|
(re, ce, ge) => (
|
|
|
|
t.vertexAttribPointer(ge, ce.size, t.FLOAT, !1, ae * 4, re),
|
|
|
|
t.enableVertexAttribArray(ge),
|
|
|
|
re + ce.size * 4
|
2024-06-01 06:31:08 +00:00
|
|
|
),
|
|
|
|
0
|
|
|
|
);
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(u, "setVertexFormat");
|
|
|
|
let [f, y] = xt((_) => t.bindTexture(t.TEXTURE_2D, _)),
|
|
|
|
[m, V] = xt((_) => t.bindBuffer(t.ARRAY_BUFFER, _)),
|
|
|
|
[x, P] = xt((_) => t.bindBuffer(t.ELEMENT_ARRAY_BUFFER, _)),
|
|
|
|
[w, K] = xt((_) => t.bindFramebuffer(t.FRAMEBUFFER, _)),
|
|
|
|
[X, z] = xt((_) => t.bindRenderbuffer(t.RENDERBUFFER, _)),
|
|
|
|
[N, $] = xt(({ x: _, y: ae, w: re, h: ce }) => {
|
|
|
|
t.viewport(_, ae, re, ce);
|
2024-06-01 06:31:08 +00:00
|
|
|
}),
|
2024-06-02 05:39:23 +00:00
|
|
|
[O, se] = xt((_) => t.useProgram(_));
|
2024-06-01 06:31:08 +00:00
|
|
|
return (
|
2024-06-02 05:39:23 +00:00
|
|
|
N({ x: 0, y: 0, w: t.drawingBufferWidth, h: t.drawingBufferHeight }),
|
2024-06-01 06:31:08 +00:00
|
|
|
{
|
2024-06-02 05:39:23 +00:00
|
|
|
gl: t,
|
2024-06-01 06:31:08 +00:00
|
|
|
opts: e,
|
2024-06-02 05:39:23 +00:00
|
|
|
onDestroy: s,
|
|
|
|
destroy: a,
|
|
|
|
pushTexture2D: f,
|
|
|
|
popTexture2D: y,
|
|
|
|
pushArrayBuffer: m,
|
|
|
|
popArrayBuffer: V,
|
|
|
|
pushElementArrayBuffer: x,
|
|
|
|
popElementArrayBuffer: P,
|
|
|
|
pushFramebuffer: w,
|
2024-06-01 06:31:08 +00:00
|
|
|
popFramebuffer: K,
|
2024-06-02 05:39:23 +00:00
|
|
|
pushRenderbuffer: X,
|
|
|
|
popRenderbuffer: z,
|
|
|
|
pushViewport: N,
|
|
|
|
popViewport: $,
|
|
|
|
pushProgram: O,
|
|
|
|
popProgram: se,
|
|
|
|
setVertexFormat: u,
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(dr, "initGfx");
|
|
|
|
var Re = class t {
|
2024-06-01 06:31:08 +00:00
|
|
|
static {
|
2024-06-02 05:39:23 +00:00
|
|
|
i(this, "Asset");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
loaded = !1;
|
|
|
|
data = null;
|
|
|
|
error = null;
|
2024-06-02 05:39:23 +00:00
|
|
|
onLoadEvents = new we();
|
|
|
|
onErrorEvents = new we();
|
|
|
|
onFinishEvents = new we();
|
2024-06-01 06:31:08 +00:00
|
|
|
constructor(e) {
|
2024-06-02 05:39:23 +00:00
|
|
|
e.then((r) => {
|
|
|
|
(this.loaded = !0), (this.data = r), this.onLoadEvents.trigger(r);
|
2024-06-01 06:31:08 +00:00
|
|
|
})
|
2024-06-02 05:39:23 +00:00
|
|
|
.catch((r) => {
|
|
|
|
if (((this.error = r), this.onErrorEvents.numListeners() > 0))
|
|
|
|
this.onErrorEvents.trigger(r);
|
|
|
|
else throw r;
|
2024-06-01 06:31:08 +00:00
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.onFinishEvents.trigger(), (this.loaded = !0);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
static loaded(e) {
|
2024-06-02 05:39:23 +00:00
|
|
|
let r = new t(Promise.resolve(e));
|
|
|
|
return (r.data = e), (r.loaded = !0), r;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
nt = class {
|
2024-06-01 06:31:08 +00:00
|
|
|
static {
|
2024-06-02 05:39:23 +00:00
|
|
|
i(this, "AssetBucket");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
assets = new Map();
|
|
|
|
lastUID = 0;
|
2024-06-02 05:39:23 +00:00
|
|
|
add(e, r) {
|
|
|
|
let s = e ?? this.lastUID++ + "",
|
|
|
|
a = new Re(r);
|
|
|
|
return this.assets.set(s, a), a;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
addLoaded(e, r) {
|
|
|
|
let s = e ?? this.lastUID++ + "",
|
|
|
|
a = Re.loaded(r);
|
|
|
|
return this.assets.set(s, a), a;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
get(e) {
|
|
|
|
return this.assets.get(e);
|
|
|
|
}
|
|
|
|
progress() {
|
|
|
|
if (this.assets.size === 0) return 1;
|
|
|
|
let e = 0;
|
|
|
|
return (
|
2024-06-02 05:39:23 +00:00
|
|
|
this.assets.forEach((r) => {
|
|
|
|
r.loaded && e++;
|
2024-06-01 06:31:08 +00:00
|
|
|
}),
|
|
|
|
e / this.assets.size
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
2024-06-02 05:39:23 +00:00
|
|
|
function hr(t) {
|
|
|
|
return fetch(t).then((e) => {
|
|
|
|
if (!e.ok) throw new Error(`Failed to fetch "${t}"`);
|
2024-06-01 06:31:08 +00:00
|
|
|
return e;
|
|
|
|
});
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(hr, "fetchURL");
|
|
|
|
function Nt(t) {
|
|
|
|
return hr(t).then((e) => e.json());
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Nt, "fetchJSON");
|
|
|
|
function co(t) {
|
|
|
|
return hr(t).then((e) => e.text());
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(co, "fetchText");
|
|
|
|
function uo(t) {
|
|
|
|
return hr(t).then((e) => e.arrayBuffer());
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(uo, "fetchArrayBuffer");
|
|
|
|
function _t(t) {
|
2024-06-01 06:31:08 +00:00
|
|
|
let e = new Image();
|
|
|
|
return (
|
|
|
|
(e.crossOrigin = "anonymous"),
|
2024-06-02 05:39:23 +00:00
|
|
|
(e.src = t),
|
|
|
|
new Promise((r, s) => {
|
|
|
|
(e.onload = () => r(e)),
|
|
|
|
(e.onerror = () => s(new Error(`Failed to load image from "${t}"`)));
|
2024-06-01 06:31:08 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(_t, "loadImg");
|
|
|
|
var pr =
|
2024-06-01 06:31:08 +00:00
|
|
|
" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~",
|
2024-06-02 05:39:23 +00:00
|
|
|
Vt = "topleft";
|
|
|
|
var lo = "monospace",
|
|
|
|
Ht = "monospace";
|
|
|
|
var fn = "linear";
|
|
|
|
var gn = [
|
2024-06-01 06:31:08 +00:00
|
|
|
{ name: "a_pos", size: 2 },
|
|
|
|
{ name: "a_uv", size: 2 },
|
|
|
|
{ name: "a_color", size: 4 },
|
|
|
|
],
|
2024-06-02 05:39:23 +00:00
|
|
|
zi = gn.reduce((t, e) => t + e.size, 0),
|
|
|
|
mo = 2048,
|
|
|
|
ho = mo * 4 * zi,
|
|
|
|
po = mo * 6,
|
|
|
|
fo = `
|
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-02 05:39:23 +00:00
|
|
|
go = `
|
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-02 05:39:23 +00:00
|
|
|
bn = `
|
2024-06-01 06:31:08 +00:00
|
|
|
vec4 vert(vec2 pos, vec2 uv, vec4 color) {
|
|
|
|
return def_vert();
|
|
|
|
}
|
|
|
|
`,
|
2024-06-02 05:39:23 +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-02 05:39:23 +00:00
|
|
|
bo = new Set(["id", "require"]),
|
|
|
|
vo = new Set([
|
2024-06-01 06:31:08 +00:00
|
|
|
"add",
|
|
|
|
"update",
|
|
|
|
"draw",
|
|
|
|
"destroy",
|
|
|
|
"inspect",
|
|
|
|
"drawInspect",
|
2024-06-02 05:39:23 +00:00
|
|
|
]),
|
|
|
|
fr = /\[(?<style>\w+)\](?<text>.*?)\[\/\k<style>\]/g,
|
|
|
|
xo = 200,
|
|
|
|
yo = 640,
|
|
|
|
wo = 65536;
|
|
|
|
var xn = 2.5949095,
|
|
|
|
Co = 1.70158 + 1,
|
|
|
|
To = (2 * Math.PI) / 3,
|
|
|
|
Eo = (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) => Co * t * t * t - 1.70158 * t * t,
|
|
|
|
easeOutBack: (t) =>
|
|
|
|
1 + Co * 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) * To),
|
|
|
|
easeOutElastic: (t) =>
|
|
|
|
t === 0
|
|
|
|
? 0
|
|
|
|
: t === 1
|
|
|
|
? 1
|
|
|
|
: Math.pow(2, -10 * t) * Math.sin((t * 10 - 0.75) * To) + 1,
|
|
|
|
easeInOutElastic: (t) =>
|
|
|
|
t === 0
|
|
|
|
? 0
|
|
|
|
: t === 1
|
|
|
|
? 1
|
|
|
|
: t < 0.5
|
|
|
|
? -(Math.pow(2, 20 * t - 10) * Math.sin((20 * t - 11.125) * Eo)) / 2
|
|
|
|
: (Math.pow(2, -20 * t + 10) * Math.sin((20 * t - 11.125) * Eo)) / 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,
|
|
|
|
},
|
|
|
|
Pt = yn;
|
|
|
|
var Kt = class {
|
|
|
|
static {
|
|
|
|
i(this, "TexPacker");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
textures = [];
|
|
|
|
bigTextures = [];
|
|
|
|
canvas;
|
|
|
|
c2d;
|
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
curHeight = 0;
|
|
|
|
gfx;
|
|
|
|
constructor(e, r, s) {
|
|
|
|
(this.gfx = e),
|
|
|
|
(this.canvas = document.createElement("canvas")),
|
|
|
|
(this.canvas.width = r),
|
|
|
|
(this.canvas.height = s),
|
|
|
|
(this.textures = [qe.fromImage(e, this.canvas)]),
|
|
|
|
(this.bigTextures = []),
|
|
|
|
(this.c2d = this.canvas.getContext("2d"));
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +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 me(0, 0, 1, 1)];
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
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 r = this.textures[this.textures.length - 1],
|
|
|
|
s = new T(this.x, this.y);
|
|
|
|
return (
|
|
|
|
(this.x += e.width),
|
|
|
|
e.height > this.curHeight && (this.curHeight = e.height),
|
|
|
|
e instanceof ImageData
|
|
|
|
? this.c2d.putImageData(e, s.x, s.y)
|
|
|
|
: this.c2d.drawImage(e, s.x, s.y),
|
|
|
|
r.update(this.canvas),
|
|
|
|
[
|
|
|
|
r,
|
|
|
|
new me(
|
|
|
|
s.x / this.canvas.width,
|
|
|
|
s.y / this.canvas.height,
|
|
|
|
e.width / this.canvas.width,
|
|
|
|
e.height / this.canvas.height
|
|
|
|
),
|
|
|
|
]
|
|
|
|
);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
free() {
|
|
|
|
for (let e of this.textures) e.free();
|
|
|
|
for (let e of this.bigTextures) e.free();
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
};
|
|
|
|
function Yi(t) {
|
|
|
|
return {
|
|
|
|
color: t.color,
|
|
|
|
opacity: t.opacity,
|
|
|
|
anchor: t.anchor,
|
|
|
|
outline: t.outline,
|
|
|
|
shader: t.shader,
|
|
|
|
uniform: t.uniform,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
i(Yi, "getRenderProps");
|
|
|
|
function So(t, e = {}) {
|
|
|
|
let r = J(this);
|
|
|
|
return {
|
|
|
|
id: "circle",
|
|
|
|
radius: t,
|
|
|
|
draw() {
|
|
|
|
r.drawCircle(
|
|
|
|
Object.assign(Yi(this), { radius: this.radius, fill: e.fill })
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
2024-06-02 05:39:23 +00:00
|
|
|
},
|
|
|
|
renderArea() {
|
|
|
|
return new ue(
|
|
|
|
new T(this.anchor ? 0 : -this.radius),
|
|
|
|
this.radius * 2,
|
|
|
|
this.radius * 2
|
|
|
|
);
|
|
|
|
},
|
|
|
|
inspect() {
|
|
|
|
return `${Math.ceil(this.radius)}`;
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
|
|
|
};
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
|
|
|
i(So, "circle");
|
|
|
|
function Ao(t) {
|
|
|
|
return {
|
|
|
|
add() {
|
|
|
|
this.canvas = t;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
i(Ao, "drawon");
|
|
|
|
function Oo(t = 1) {
|
|
|
|
let e = J(this),
|
|
|
|
r,
|
|
|
|
s = 0,
|
|
|
|
a = !1;
|
|
|
|
return {
|
|
|
|
require: ["opacity"],
|
|
|
|
add() {
|
|
|
|
(r = this.opacity), (this.opacity = 0);
|
|
|
|
},
|
|
|
|
update() {
|
|
|
|
a ||
|
|
|
|
((s += e.dt()),
|
|
|
|
(this.opacity = e.map(s, 0, t, 0, r)),
|
|
|
|
s >= t && ((this.opacity = r), (a = !0)));
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
i(Oo, "fadeIn");
|
|
|
|
function Ro(t = "intersect") {
|
|
|
|
return { id: "mask", mask: t };
|
|
|
|
}
|
|
|
|
i(Ro, "mask");
|
|
|
|
function Uo(t) {
|
|
|
|
let e = J(this),
|
|
|
|
r = fe(e);
|
|
|
|
return {
|
|
|
|
id: "opacity",
|
|
|
|
opacity: t ?? 1,
|
|
|
|
inspect() {
|
|
|
|
return `${r.toFixed(this.opacity, 1)}`;
|
|
|
|
},
|
|
|
|
fadeIn(s = 1, a = e.easings.linear) {
|
|
|
|
return e.tween(0, this.opacity, s, (l) => (this.opacity = l), a);
|
|
|
|
},
|
|
|
|
fadeOut(s = 1, a = e.easings.linear) {
|
|
|
|
return e.tween(this.opacity, 0, s, (l) => (this.opacity = l), a);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
i(Uo, "opacity");
|
|
|
|
function Vo(t = 1, e = oe(0, 0, 0)) {
|
|
|
|
return { id: "outline", outline: { width: t, color: e } };
|
|
|
|
}
|
|
|
|
i(Vo, "outline");
|
|
|
|
function Po(t, e = {}) {
|
|
|
|
let r = J(this),
|
|
|
|
s = fe(r);
|
|
|
|
if (t.length < 3)
|
|
|
|
throw new Error(
|
|
|
|
`Polygon's need more than two points, ${t.length} points provided`
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
2024-06-02 05:39:23 +00:00
|
|
|
return {
|
|
|
|
id: "polygon",
|
|
|
|
pts: t,
|
|
|
|
colors: e.colors,
|
|
|
|
uv: e.uv,
|
|
|
|
tex: e.tex,
|
|
|
|
radius: e.radius,
|
|
|
|
draw() {
|
|
|
|
r.drawPolygon(
|
|
|
|
Object.assign(s.getRenderProps(this), {
|
|
|
|
pts: this.pts,
|
|
|
|
colors: this.colors,
|
|
|
|
uv: this.uv,
|
|
|
|
tex: this.tex,
|
|
|
|
radius: this.radius,
|
|
|
|
fill: e.fill,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
},
|
|
|
|
renderArea() {
|
|
|
|
return new Oe(this.pts);
|
|
|
|
},
|
|
|
|
inspect() {
|
|
|
|
return this.pts.map((a) => `[${a.x},${a.y}]`).join(",");
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
i(Po, "polygon");
|
|
|
|
function Do(t, e, r) {
|
|
|
|
let s = J(this),
|
|
|
|
a;
|
|
|
|
return (
|
|
|
|
s.get("area").forEach((u) => {
|
|
|
|
if (r && r.some((m) => u.is(m))) return;
|
|
|
|
let y = u.worldArea().raycast(t, e);
|
|
|
|
y &&
|
|
|
|
(a
|
|
|
|
? y.fraction < a.fraction && ((a = y), (a.object = u))
|
|
|
|
: ((a = y), (a.object = u)));
|
|
|
|
}),
|
|
|
|
a
|
|
|
|
);
|
|
|
|
}
|
|
|
|
i(Do, "raycast");
|
|
|
|
function Mo(t, e, r = {}) {
|
|
|
|
let s = J(this),
|
|
|
|
a = fe(s);
|
|
|
|
return {
|
|
|
|
id: "rect",
|
|
|
|
width: t,
|
|
|
|
height: e,
|
|
|
|
radius: r.radius || 0,
|
|
|
|
draw() {
|
|
|
|
s.drawRect(
|
|
|
|
Object.assign(a.getRenderProps(this), {
|
|
|
|
width: this.width,
|
|
|
|
height: this.height,
|
|
|
|
radius: this.radius,
|
|
|
|
fill: r.fill,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
},
|
|
|
|
renderArea() {
|
|
|
|
return new ue(C(0), this.width, this.height);
|
|
|
|
},
|
|
|
|
inspect() {
|
|
|
|
return `${Math.ceil(this.width)}, ${Math.ceil(this.height)}`;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
i(Mo, "rect");
|
|
|
|
function Go(t, e) {
|
|
|
|
return {
|
|
|
|
id: "shader",
|
|
|
|
shader: t,
|
|
|
|
...(typeof e == "function"
|
|
|
|
? {
|
|
|
|
uniform: e(),
|
|
|
|
update() {
|
|
|
|
this.uniform = e();
|
|
|
|
},
|
|
|
|
}
|
|
|
|
: { uniform: e }),
|
|
|
|
inspect() {
|
|
|
|
return `shader: ${t}`;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
i(Go, "shader");
|
|
|
|
function wn(t, e = {}) {
|
|
|
|
let r = J(this),
|
|
|
|
s = fe(this),
|
|
|
|
a = null,
|
|
|
|
l = null,
|
|
|
|
u = null,
|
|
|
|
f = new we();
|
|
|
|
if (!t)
|
|
|
|
throw new Error("Please pass the resource name or data to sprite()");
|
|
|
|
let y = i((m, V, x, P) => {
|
|
|
|
let w = C(1, 1);
|
2024-06-01 06:31:08 +00:00
|
|
|
return (
|
2024-06-02 05:39:23 +00:00
|
|
|
x && P
|
|
|
|
? ((w.x = x / (m.width * V.w)), (w.y = P / (m.height * V.h)))
|
|
|
|
: x
|
|
|
|
? ((w.x = x / (m.width * V.w)), (w.y = w.x))
|
|
|
|
: P && ((w.y = P / (m.height * V.h)), (w.x = w.y)),
|
|
|
|
w
|
|
|
|
);
|
|
|
|
}, "calcTexScale");
|
|
|
|
return {
|
|
|
|
id: "sprite",
|
|
|
|
width: 0,
|
|
|
|
height: 0,
|
|
|
|
frame: e.frame || 0,
|
|
|
|
quad: e.quad || new me(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: V, right: x, top: P, bottom: w } = a.slice9,
|
|
|
|
K = a.tex.width * m.w,
|
|
|
|
X = a.tex.height * m.h,
|
|
|
|
z = this.width - V - x,
|
|
|
|
N = this.height - P - w,
|
|
|
|
$ = V / K,
|
|
|
|
O = x / K,
|
|
|
|
se = 1 - $ - O,
|
|
|
|
_ = P / X,
|
|
|
|
ae = w / X,
|
|
|
|
re = 1 - _ - ae,
|
|
|
|
ce = [
|
|
|
|
pe(0, 0, $, _),
|
|
|
|
pe($, 0, se, _),
|
|
|
|
pe($ + se, 0, O, _),
|
|
|
|
pe(0, _, $, re),
|
|
|
|
pe($, _, se, re),
|
|
|
|
pe($ + se, _, O, re),
|
|
|
|
pe(0, _ + re, $, ae),
|
|
|
|
pe($, _ + re, se, ae),
|
|
|
|
pe($ + se, _ + re, O, ae),
|
|
|
|
pe(0, 0, V, P),
|
|
|
|
pe(V, 0, z, P),
|
|
|
|
pe(V + z, 0, x, P),
|
|
|
|
pe(0, P, V, N),
|
|
|
|
pe(V, P, z, N),
|
|
|
|
pe(V + z, P, x, N),
|
|
|
|
pe(0, P + N, V, w),
|
|
|
|
pe(V, P + N, z, w),
|
|
|
|
pe(V + z, P + N, x, w),
|
|
|
|
];
|
|
|
|
for (let ge = 0; ge < 9; ge++) {
|
|
|
|
let Ue = ce[ge],
|
|
|
|
Ce = ce[ge + 9];
|
|
|
|
s.drawTexture(
|
|
|
|
Object.assign(s.getRenderProps(this), {
|
|
|
|
pos: Ce.pos(),
|
|
|
|
tex: a.tex,
|
|
|
|
quad: m.scale(Ue),
|
|
|
|
flipX: this.flipX,
|
|
|
|
flipY: this.flipY,
|
|
|
|
tiled: e.tiled,
|
|
|
|
width: Ce.w,
|
|
|
|
height: Ce.h,
|
2024-06-01 06:31:08 +00:00
|
|
|
})
|
2024-06-02 05:39:23 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
s.drawTexture(
|
|
|
|
Object.assign(s.getRenderProps(this), {
|
|
|
|
tex: a.tex,
|
|
|
|
quad: m.scale(this.quad ?? new me(0, 0, 1, 1)),
|
|
|
|
flipX: this.flipX,
|
|
|
|
flipY: this.flipY,
|
|
|
|
tiled: e.tiled,
|
|
|
|
width: this.width,
|
|
|
|
height: this.height,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
},
|
|
|
|
add() {
|
|
|
|
let m = i((x) => {
|
|
|
|
let P = x.frames[0].clone();
|
|
|
|
e.quad && (P = P.scale(e.quad));
|
|
|
|
let w = y(x.tex, P, e.width, e.height);
|
|
|
|
(this.width = x.tex.width * P.w * w.x),
|
|
|
|
(this.height = x.tex.height * P.h * w.y),
|
|
|
|
e.anim && this.play(e.anim),
|
|
|
|
(a = x),
|
|
|
|
f.trigger(a);
|
|
|
|
}, "setSpriteData"),
|
|
|
|
V = s.resolveSprite(t);
|
|
|
|
V ? V.onLoad(m) : r.onLoad(() => m(s.resolveSprite(t).data));
|
|
|
|
},
|
|
|
|
update() {
|
|
|
|
if (!l) return;
|
|
|
|
let m = a.anims[l.name];
|
|
|
|
if (typeof m == "number") {
|
|
|
|
this.frame = m;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m.speed === 0) throw new Error("Sprite anim speed cannot be 0");
|
|
|
|
(l.timer += r.dt() * this.animSpeed),
|
|
|
|
l.timer >= 1 / l.speed &&
|
|
|
|
((l.timer = 0),
|
|
|
|
(this.frame += u),
|
|
|
|
(this.frame < Math.min(m.from, m.to) ||
|
|
|
|
this.frame > Math.max(m.from, m.to)) &&
|
|
|
|
(l.loop
|
|
|
|
? l.pingpong
|
|
|
|
? ((this.frame -= u), (u *= -1), (this.frame += u))
|
|
|
|
: (this.frame = m.from)
|
|
|
|
: l.pingpong
|
|
|
|
? u === Math.sign(m.to - m.from)
|
|
|
|
? ((this.frame = m.to), (u *= -1), (this.frame += u))
|
|
|
|
: ((this.frame = m.from), l.onEnd(), this.stop())
|
|
|
|
: ((this.frame = m.to), l.onEnd(), this.stop())));
|
|
|
|
},
|
|
|
|
play(m, V = {}) {
|
|
|
|
if (!a) {
|
|
|
|
f.add(() => this.play(m, V));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let x = a.anims[m];
|
|
|
|
if (x === void 0) throw new Error(`Anim not found: ${m}`);
|
|
|
|
l && this.stop(),
|
|
|
|
(l =
|
|
|
|
typeof x == "number"
|
|
|
|
? {
|
|
|
|
name: m,
|
|
|
|
timer: 0,
|
|
|
|
loop: !1,
|
|
|
|
pingpong: !1,
|
|
|
|
speed: 0,
|
|
|
|
onEnd: () => {},
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
: {
|
|
|
|
name: m,
|
|
|
|
timer: 0,
|
|
|
|
loop: V.loop ?? x.loop ?? !1,
|
|
|
|
pingpong: V.pingpong ?? x.pingpong ?? !1,
|
|
|
|
speed: V.speed ?? x.speed ?? 10,
|
|
|
|
onEnd: V.onEnd ?? (() => {}),
|
|
|
|
}),
|
|
|
|
(u = typeof x == "number" ? null : x.from < x.to ? 1 : -1),
|
|
|
|
(this.frame = typeof x == "number" ? x : x.from),
|
|
|
|
this.trigger("animStart", m);
|
|
|
|
},
|
|
|
|
stop() {
|
|
|
|
if (!l) return;
|
|
|
|
let m = l.name;
|
|
|
|
(l = null), this.trigger("animEnd", m);
|
|
|
|
},
|
|
|
|
numFrames() {
|
|
|
|
return a?.frames.length ?? 0;
|
|
|
|
},
|
|
|
|
curAnim() {
|
|
|
|
return l?.name;
|
|
|
|
},
|
|
|
|
onAnimEnd(m) {
|
|
|
|
return this.on("animEnd", m);
|
|
|
|
},
|
|
|
|
onAnimStart(m) {
|
|
|
|
return this.on("animStart", m);
|
|
|
|
},
|
|
|
|
renderArea() {
|
|
|
|
return new r.Rect(C(0), this.width, this.height);
|
|
|
|
},
|
|
|
|
inspect() {
|
|
|
|
if (typeof t == "string") return `"${t}"`;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
i(wn, "sprite");
|
|
|
|
function Bo(t, e = {}) {
|
|
|
|
let r = J(this),
|
|
|
|
s = fe(r);
|
|
|
|
function a(u) {
|
|
|
|
let f = r.formatText(
|
|
|
|
Object.assign(s.getRenderProps(u), {
|
|
|
|
text: u.text + "",
|
|
|
|
size: u.textSize,
|
|
|
|
font: u.font,
|
|
|
|
width: e.width && u.width,
|
|
|
|
align: u.align,
|
|
|
|
letterSpacing: u.letterSpacing,
|
|
|
|
lineSpacing: u.lineSpacing,
|
|
|
|
transform: u.textTransform,
|
|
|
|
styles: u.textStyles,
|
2024-06-01 06:31:08 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
return (
|
2024-06-02 05:39:23 +00:00
|
|
|
e.width || (u.width = f.width / (u.scale?.x || 1)),
|
|
|
|
(u.height = f.height / (u.scale?.y || 1)),
|
|
|
|
f
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(a, "update");
|
|
|
|
let l = {
|
|
|
|
id: "text",
|
|
|
|
set text(u) {
|
|
|
|
(t = u), 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() {
|
|
|
|
r.onLoad(() => a(this));
|
|
|
|
},
|
|
|
|
draw() {
|
|
|
|
r.drawFormattedText(a(this));
|
|
|
|
},
|
|
|
|
renderArea() {
|
|
|
|
return new ue(C(0), this.width, this.height);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
return a(l), l;
|
|
|
|
}
|
|
|
|
i(Bo, "text");
|
|
|
|
function Fo(t, e) {
|
|
|
|
let r = J(this),
|
|
|
|
s = fe(r);
|
|
|
|
return {
|
|
|
|
id: "rect",
|
|
|
|
width: t,
|
|
|
|
height: e,
|
|
|
|
draw() {
|
|
|
|
r.drawUVQuad(
|
|
|
|
Object.assign(s.getRenderProps(this), {
|
|
|
|
width: this.width,
|
|
|
|
height: this.height,
|
2024-06-01 06:31:08 +00:00
|
|
|
})
|
|
|
|
);
|
2024-06-02 05:39:23 +00:00
|
|
|
},
|
|
|
|
renderArea() {
|
|
|
|
return new ue(C(0), this.width, this.height);
|
|
|
|
},
|
|
|
|
inspect() {
|
|
|
|
return `${Math.ceil(this.width)}, ${Math.ceil(this.height)}`;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
i(Fo, "uvquad");
|
|
|
|
function Io(t = {}) {
|
|
|
|
let e = null,
|
|
|
|
r = null,
|
|
|
|
s = 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 r && s ? r[s] : null;
|
|
|
|
},
|
|
|
|
getPath() {
|
|
|
|
return r ? r.slice() : null;
|
|
|
|
},
|
|
|
|
getTarget() {
|
|
|
|
return e;
|
|
|
|
},
|
|
|
|
isNavigationFinished() {
|
|
|
|
return r ? s === null : !0;
|
|
|
|
},
|
|
|
|
isTargetReachable() {
|
|
|
|
return r !== null;
|
|
|
|
},
|
|
|
|
isTargetReached() {
|
|
|
|
return e ? this.pos.eq(e) : !0;
|
|
|
|
},
|
|
|
|
setTarget(l) {
|
|
|
|
(e = l),
|
|
|
|
(r = this.getLevel().getPath(this.pos, e, {
|
|
|
|
allowDiagonals: this.allowDiagonals,
|
|
|
|
})),
|
|
|
|
(s = r ? 0 : null),
|
|
|
|
r
|
|
|
|
? (a ||
|
|
|
|
((a = this.getLevel().onNavigationMapChanged(() => {
|
|
|
|
r &&
|
|
|
|
s !== null &&
|
|
|
|
((r = this.getLevel().getPath(this.pos, e, {
|
|
|
|
allowDiagonals: this.allowDiagonals,
|
|
|
|
})),
|
|
|
|
(s = r ? 0 : null),
|
|
|
|
r
|
|
|
|
? this.trigger("navigation-next", this, r[s])
|
|
|
|
: this.trigger("navigation-ended", this));
|
|
|
|
})),
|
|
|
|
this.onDestroy(() => a.cancel())),
|
|
|
|
this.trigger("navigation-started", this),
|
|
|
|
this.trigger("navigation-next", this, r[s]))
|
|
|
|
: this.trigger("navigation-ended", this);
|
|
|
|
},
|
|
|
|
update() {
|
|
|
|
if (r && s !== null) {
|
|
|
|
if (this.pos.sdist(r[s]) < 2)
|
|
|
|
if (s === r.length - 1) {
|
|
|
|
(this.pos = e.clone()),
|
|
|
|
(s = null),
|
|
|
|
this.trigger("navigation-ended", this),
|
|
|
|
this.trigger("target-reached", this);
|
|
|
|
return;
|
|
|
|
} else s++, this.trigger("navigation-next", this, r[s]);
|
|
|
|
this.moveTo(r[s], this.agentSpeed);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
},
|
|
|
|
onNavigationStarted(l) {
|
|
|
|
return this.on("navigation-started", l);
|
|
|
|
},
|
|
|
|
onNavigationNext(l) {
|
|
|
|
return this.on("navigation-next", l);
|
|
|
|
},
|
|
|
|
onNavigationEnded(l) {
|
|
|
|
return this.on("navigation-ended", l);
|
|
|
|
},
|
|
|
|
onTargetReached(l) {
|
|
|
|
return this.on("target-reached", l);
|
|
|
|
},
|
|
|
|
inspect() {
|
|
|
|
return JSON.stringify({
|
|
|
|
target: JSON.stringify(e),
|
|
|
|
path: JSON.stringify(r),
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
i(Io, "agent");
|
|
|
|
function gr(t = {}) {
|
|
|
|
let e = C(0),
|
|
|
|
r = t.isObstacle ?? !1,
|
|
|
|
s = t.cost ?? 0,
|
|
|
|
a = t.edges ?? [],
|
|
|
|
l = i(() => {
|
|
|
|
let f = { left: 1, top: 2, right: 4, bottom: 8 };
|
|
|
|
return a.map((y) => f[y] || 0).reduce((y, m) => y | m, 0);
|
|
|
|
}, "getEdgeMask"),
|
|
|
|
u = l();
|
|
|
|
return {
|
|
|
|
id: "tile",
|
|
|
|
tilePosOffset: t.offset ?? C(0),
|
|
|
|
set tilePos(f) {
|
|
|
|
let y = this.getLevel();
|
|
|
|
(e = f.clone()),
|
|
|
|
(this.pos = C(
|
|
|
|
this.tilePos.x * y.tileWidth(),
|
|
|
|
this.tilePos.y * y.tileHeight()
|
|
|
|
).add(this.tilePosOffset));
|
|
|
|
},
|
|
|
|
get tilePos() {
|
|
|
|
return e;
|
|
|
|
},
|
|
|
|
set isObstacle(f) {
|
|
|
|
r !== f && ((r = f), this.getLevel().invalidateNavigationMap());
|
|
|
|
},
|
|
|
|
get isObstacle() {
|
|
|
|
return r;
|
|
|
|
},
|
|
|
|
set cost(f) {
|
|
|
|
s !== f && ((s = f), this.getLevel().invalidateNavigationMap());
|
|
|
|
},
|
|
|
|
get cost() {
|
|
|
|
return s;
|
|
|
|
},
|
|
|
|
set edges(f) {
|
|
|
|
(a = f), (u = l()), this.getLevel().invalidateNavigationMap();
|
|
|
|
},
|
|
|
|
get edges() {
|
|
|
|
return a;
|
|
|
|
},
|
|
|
|
get edgeMask() {
|
|
|
|
return u;
|
|
|
|
},
|
|
|
|
getLevel() {
|
|
|
|
return this.parent;
|
|
|
|
},
|
|
|
|
moveLeft() {
|
|
|
|
this.tilePos = this.tilePos.add(C(-1, 0));
|
|
|
|
},
|
|
|
|
moveRight() {
|
|
|
|
this.tilePos = this.tilePos.add(C(1, 0));
|
|
|
|
},
|
|
|
|
moveUp() {
|
|
|
|
this.tilePos = this.tilePos.add(C(0, -1));
|
|
|
|
},
|
|
|
|
moveDown() {
|
|
|
|
this.tilePos = this.tilePos.add(C(0, 1));
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
i(gr, "tile");
|
|
|
|
function Lo(t, e) {
|
|
|
|
if (t == null)
|
|
|
|
throw new Error("health() requires the initial amount of hp");
|
|
|
|
return {
|
|
|
|
id: "health",
|
|
|
|
hurt(r = 1) {
|
|
|
|
this.setHP(t - r), this.trigger("hurt", r);
|
|
|
|
},
|
|
|
|
heal(r = 1) {
|
|
|
|
let s = t;
|
|
|
|
this.setHP(t + r), this.trigger("heal", t - s);
|
|
|
|
},
|
|
|
|
hp() {
|
|
|
|
return t;
|
|
|
|
},
|
|
|
|
maxHP() {
|
|
|
|
return e ?? null;
|
|
|
|
},
|
|
|
|
setMaxHP(r) {
|
|
|
|
e = r;
|
|
|
|
},
|
|
|
|
setHP(r) {
|
|
|
|
(t = e ? Math.min(e, r) : r), t <= 0 && this.trigger("death");
|
|
|
|
},
|
|
|
|
onHurt(r) {
|
|
|
|
return this.on("hurt", r);
|
|
|
|
},
|
|
|
|
onHeal(r) {
|
|
|
|
return this.on("heal", r);
|
|
|
|
},
|
|
|
|
onDeath(r) {
|
|
|
|
return this.on("death", r);
|
|
|
|
},
|
|
|
|
inspect() {
|
|
|
|
return `${t}`;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
i(Lo, "health");
|
|
|
|
function jo(t, e = {}) {
|
|
|
|
let r = J(this);
|
|
|
|
if (t == null) throw new Error("lifespan() requires time");
|
|
|
|
let s = e.fade ?? 0;
|
|
|
|
return {
|
|
|
|
id: "lifespan",
|
|
|
|
require: ["opacity"],
|
|
|
|
async add() {
|
|
|
|
await r.wait(t),
|
|
|
|
(this.opacity = this.opacity ?? 1),
|
|
|
|
s > 0 &&
|
|
|
|
(await r.tween(
|
|
|
|
this.opacity,
|
|
|
|
0,
|
|
|
|
s,
|
|
|
|
(a) => (this.opacity = a),
|
|
|
|
Pt.linear
|
|
|
|
)),
|
|
|
|
this.destroy();
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
i(jo, "lifespan");
|
|
|
|
function ko(t, e, r) {
|
|
|
|
if (!t) throw new Error("state() requires an initial state");
|
|
|
|
let s = {};
|
|
|
|
function a(y) {
|
|
|
|
s[y] ||
|
|
|
|
(s[y] = {
|
|
|
|
enter: new we(),
|
|
|
|
end: new we(),
|
|
|
|
update: new we(),
|
|
|
|
draw: new we(),
|
|
|
|
});
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(a, "initStateEvents");
|
|
|
|
function l(y, m, V) {
|
|
|
|
return a(m), s[m][y].add(V);
|
|
|
|
}
|
|
|
|
i(l, "on");
|
|
|
|
function u(y, m, ...V) {
|
|
|
|
a(m), s[m][y].trigger(...V);
|
|
|
|
}
|
|
|
|
i(u, "trigger");
|
|
|
|
let f = !1;
|
|
|
|
return {
|
|
|
|
id: "state",
|
|
|
|
state: t,
|
|
|
|
enterState(y, ...m) {
|
|
|
|
if (((f = !0), e && !e.includes(y)))
|
|
|
|
throw new Error(`State not found: ${y}`);
|
|
|
|
let V = this.state;
|
|
|
|
if (r) {
|
|
|
|
if (!r?.[V]) return;
|
|
|
|
let x = typeof r[V] == "string" ? [r[V]] : r[V];
|
|
|
|
if (!x.includes(y))
|
|
|
|
throw new Error(
|
|
|
|
`Cannot transition state from "${V}" to "${y}". Available transitions: ${x
|
|
|
|
.map((P) => `"${P}"`)
|
|
|
|
.join(", ")}`
|
|
|
|
);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
u("end", V, ...m),
|
|
|
|
(this.state = y),
|
|
|
|
u("enter", y, ...m),
|
|
|
|
u("enter", `${V} -> ${y}`, ...m);
|
|
|
|
},
|
|
|
|
onStateTransition(y, m, V) {
|
|
|
|
return l("enter", `${y} -> ${m}`, V);
|
|
|
|
},
|
|
|
|
onStateEnter(y, m) {
|
|
|
|
return l("enter", y, m);
|
|
|
|
},
|
|
|
|
onStateUpdate(y, m) {
|
|
|
|
return l("update", y, m);
|
|
|
|
},
|
|
|
|
onStateDraw(y, m) {
|
|
|
|
return l("draw", y, m);
|
|
|
|
},
|
|
|
|
onStateEnd(y, m) {
|
|
|
|
return l("end", y, m);
|
|
|
|
},
|
|
|
|
update() {
|
|
|
|
f || (u("enter", t), (f = !0)), u("update", this.state);
|
|
|
|
},
|
|
|
|
draw() {
|
|
|
|
u("draw", this.state);
|
|
|
|
},
|
|
|
|
inspect() {
|
|
|
|
return this.state;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
i(ko, "state");
|
|
|
|
function br(t) {
|
|
|
|
return { id: "stay", stay: !0, scenesToStay: t };
|
|
|
|
}
|
|
|
|
i(br, "stay");
|
|
|
|
function Cn() {
|
|
|
|
return {
|
|
|
|
id: "timer",
|
|
|
|
wait(t, e) {
|
|
|
|
let r = J(this),
|
|
|
|
s = [];
|
|
|
|
e && s.push(e);
|
|
|
|
let a = 0,
|
|
|
|
l = this.onUpdate(() => {
|
|
|
|
(a += r.dt()), a >= t && (s.forEach((u) => u()), l.cancel());
|
2024-06-01 06:31:08 +00:00
|
|
|
});
|
2024-06-02 05:39:23 +00:00
|
|
|
return {
|
2024-06-01 06:31:08 +00:00
|
|
|
get paused() {
|
2024-06-02 05:39:23 +00:00
|
|
|
return l.paused;
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
set paused(u) {
|
|
|
|
l.paused = u;
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
cancel: l.cancel,
|
|
|
|
onEnd(u) {
|
|
|
|
s.push(u);
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
then(u) {
|
|
|
|
return this.onEnd(u), this;
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
loop(t, e) {
|
|
|
|
let r = null,
|
|
|
|
s = i(() => {
|
|
|
|
(r = this.wait(t, s)), e();
|
|
|
|
}, "newAction");
|
|
|
|
return (
|
|
|
|
(r = this.wait(0, s)),
|
|
|
|
{
|
|
|
|
get paused() {
|
|
|
|
return r.paused;
|
|
|
|
},
|
|
|
|
set paused(a) {
|
|
|
|
r.paused = a;
|
|
|
|
},
|
|
|
|
cancel: () => r.cancel(),
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
tween(t, e, r, s, a = Pt.linear) {
|
|
|
|
let l = J(this),
|
|
|
|
u = 0,
|
|
|
|
f = [],
|
|
|
|
y = this.onUpdate(() => {
|
|
|
|
u += l.dt();
|
|
|
|
let m = Math.min(u / r, 1);
|
|
|
|
s(Je(t, e, a(m))),
|
|
|
|
m === 1 && (y.cancel(), s(e), f.forEach((V) => V()));
|
|
|
|
});
|
|
|
|
return {
|
|
|
|
get paused() {
|
|
|
|
return y.paused;
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
set paused(m) {
|
|
|
|
y.paused = m;
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
onEnd(m) {
|
|
|
|
f.push(m);
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
then(m) {
|
|
|
|
return this.onEnd(m), this;
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
cancel() {
|
|
|
|
y.cancel();
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
finish() {
|
|
|
|
y.cancel(), s(e), f.forEach((m) => m());
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
|
|
|
};
|
2024-06-02 05:39:23 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
i(Cn, "timer");
|
|
|
|
function No(t = {}) {
|
|
|
|
let e = J(this),
|
|
|
|
r = fe(e),
|
|
|
|
{ app: s } = r,
|
|
|
|
a = {},
|
|
|
|
l = new Set();
|
|
|
|
return {
|
|
|
|
id: "area",
|
|
|
|
collisionIgnore: t.collisionIgnore ?? [],
|
|
|
|
add() {
|
|
|
|
this.area.cursor && this.onHover(() => s.setCursor(this.area.cursor)),
|
|
|
|
this.onCollideUpdate((u, f) => {
|
|
|
|
a[u.id] || this.trigger("collide", u, f),
|
|
|
|
(a[u.id] = f),
|
|
|
|
l.add(u.id);
|
2024-06-01 06:31:08 +00:00
|
|
|
});
|
2024-06-02 05:39:23 +00:00
|
|
|
},
|
|
|
|
update() {
|
|
|
|
for (let u in a)
|
|
|
|
l.has(Number(u)) ||
|
|
|
|
(this.trigger("collideEnd", a[u].target), delete a[u]);
|
|
|
|
l.clear();
|
|
|
|
},
|
|
|
|
drawInspect() {
|
|
|
|
let u = this.localArea();
|
|
|
|
e.pushTransform(),
|
|
|
|
e.pushScale(this.area.scale),
|
|
|
|
e.pushTranslate(this.area.offset);
|
|
|
|
let f = {
|
|
|
|
outline: { width: 4 / r.getViewportScale(), color: oe(0, 0, 255) },
|
|
|
|
anchor: this.anchor,
|
|
|
|
fill: !1,
|
|
|
|
fixed: r.isFixed(this),
|
|
|
|
};
|
|
|
|
u instanceof e.Rect
|
|
|
|
? e.drawRect({ ...f, pos: u.pos, width: u.width, height: u.height })
|
|
|
|
: u instanceof e.Polygon
|
|
|
|
? e.drawPolygon({ ...f, pts: u.pts })
|
|
|
|
: u instanceof e.Circle &&
|
|
|
|
e.drawCircle({ ...f, pos: u.center, radius: u.radius }),
|
|
|
|
e.popTransform();
|
|
|
|
},
|
|
|
|
area: {
|
|
|
|
shape: t.shape ?? null,
|
|
|
|
scale: t.scale ? C(t.scale) : C(1),
|
|
|
|
offset: t.offset ?? C(0),
|
|
|
|
cursor: t.cursor ?? null,
|
|
|
|
},
|
|
|
|
isClicked() {
|
|
|
|
return s.isMousePressed() && this.isHovering();
|
|
|
|
},
|
|
|
|
isHovering() {
|
|
|
|
let u = r.isFixed(this) ? e.mousePos() : e.toWorld(e.mousePos());
|
|
|
|
return this.hasPoint(u);
|
|
|
|
},
|
|
|
|
checkCollision(u) {
|
|
|
|
return a[u.id] ?? null;
|
|
|
|
},
|
|
|
|
getCollisions() {
|
|
|
|
return Object.values(a);
|
|
|
|
},
|
|
|
|
isColliding(u) {
|
|
|
|
return !!a[u.id];
|
|
|
|
},
|
|
|
|
isOverlapping(u) {
|
|
|
|
let f = a[u.id];
|
|
|
|
return f && f.hasOverlap();
|
|
|
|
},
|
|
|
|
onClick(u, f = "left") {
|
|
|
|
let y = s.onMousePress(f, () => {
|
|
|
|
this.isHovering() && u();
|
|
|
|
});
|
|
|
|
return this.onDestroy(() => y.cancel()), y;
|
|
|
|
},
|
|
|
|
onHover(u) {
|
|
|
|
let f = !1;
|
|
|
|
return this.onUpdate(() => {
|
|
|
|
f ? (f = this.isHovering()) : this.isHovering() && ((f = !0), u());
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onHoverUpdate(u) {
|
|
|
|
return this.onUpdate(() => {
|
|
|
|
this.isHovering() && u();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onHoverEnd(u) {
|
|
|
|
let f = !1;
|
|
|
|
return this.onUpdate(() => {
|
|
|
|
f ? this.isHovering() || ((f = !1), u()) : (f = this.isHovering());
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onCollide(u, f) {
|
|
|
|
if (typeof u == "function" && f === void 0)
|
|
|
|
return this.on("collide", u);
|
|
|
|
if (typeof u == "string")
|
|
|
|
return this.onCollide((y, m) => {
|
|
|
|
y.is(u) && f(y, m);
|
2024-06-01 06:31:08 +00:00
|
|
|
});
|
2024-06-02 05:39:23 +00:00
|
|
|
},
|
|
|
|
onCollideUpdate(u, f) {
|
|
|
|
if (typeof u == "function" && f === void 0)
|
|
|
|
return this.on("collideUpdate", u);
|
|
|
|
if (typeof u == "string")
|
|
|
|
return this.on("collideUpdate", (y, m) => y.is(u) && f(y, m));
|
|
|
|
},
|
|
|
|
onCollideEnd(u, f) {
|
|
|
|
if (typeof u == "function" && f === void 0)
|
|
|
|
return this.on("collideEnd", u);
|
|
|
|
if (typeof u == "string")
|
|
|
|
return this.on("collideEnd", (y) => y.is(u) && f(y));
|
|
|
|
},
|
|
|
|
hasPoint(u) {
|
|
|
|
return mt(this.worldArea(), u);
|
|
|
|
},
|
|
|
|
resolveCollision(u) {
|
|
|
|
let f = this.checkCollision(u);
|
|
|
|
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 u = this.localArea();
|
|
|
|
if (!(u instanceof e.Polygon || u instanceof e.Rect))
|
|
|
|
throw new Error("Only support polygon and rect shapes for now");
|
|
|
|
let f = this.transform
|
|
|
|
.clone()
|
|
|
|
.scale(C(this.area.scale ?? 1))
|
|
|
|
.translate(this.area.offset);
|
|
|
|
if (u instanceof e.Rect) {
|
|
|
|
let y = ht(this.anchor || Vt)
|
|
|
|
.add(1, 1)
|
|
|
|
.scale(-0.5)
|
|
|
|
.scale(u.width, u.height);
|
|
|
|
f.translate(y);
|
|
|
|
}
|
|
|
|
return u.transform(f);
|
|
|
|
},
|
|
|
|
screenArea() {
|
|
|
|
let u = this.worldArea();
|
|
|
|
return r.isFixed(this) ? u : u.transform(r.game.cam.transform);
|
|
|
|
},
|
|
|
|
inspect() {
|
|
|
|
return `(${this.area.scale.x.toFixed(1)}, ${this.area.scale.y.toFixed(
|
|
|
|
1
|
|
|
|
)})`;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
i(No, "area");
|
|
|
|
function _o(t = {}) {
|
|
|
|
let e = J(this),
|
|
|
|
r = fe(e),
|
|
|
|
s = null,
|
|
|
|
a = null,
|
|
|
|
l = !1;
|
|
|
|
return {
|
|
|
|
id: "body",
|
|
|
|
require: ["pos"],
|
|
|
|
vel: C(0),
|
|
|
|
drag: t.drag ?? 0,
|
|
|
|
jumpForce: t.jumpForce ?? yo,
|
|
|
|
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((u, f) => {
|
|
|
|
if (!u.is("body") || f.resolved) return;
|
|
|
|
this.trigger("beforePhysicsResolve", f);
|
|
|
|
let y = f.reverse();
|
|
|
|
if (
|
|
|
|
(u.trigger("beforePhysicsResolve", y),
|
|
|
|
!(f.resolved || y.resolved) && !(this.isStatic && u.isStatic))
|
|
|
|
) {
|
|
|
|
if (!this.isStatic && !u.isStatic) {
|
|
|
|
let m = this.mass + u.mass;
|
|
|
|
(this.pos = this.pos.add(f.displacement.scale(u.mass / m))),
|
|
|
|
(u.pos = u.pos.add(f.displacement.scale(-this.mass / m))),
|
|
|
|
(this.transform = r.calcTransform(this)),
|
|
|
|
(u.transform = r.calcTransform(u));
|
|
|
|
} else {
|
|
|
|
let m = !this.isStatic && u.isStatic ? f : f.reverse();
|
|
|
|
(m.source.pos = m.source.pos.add(m.displacement)),
|
|
|
|
(m.source.transform = r.calcTransform(m.source));
|
|
|
|
}
|
|
|
|
(f.resolved = !0),
|
|
|
|
this.trigger("physicsResolve", f),
|
|
|
|
u.trigger("physicsResolve", f.reverse());
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
}),
|
|
|
|
this.onPhysicsResolve((u) => {
|
|
|
|
r.game.gravity &&
|
|
|
|
(u.isBottom() && this.isFalling()
|
|
|
|
? ((this.vel = this.vel.reject(r.game.gravity.unit())),
|
|
|
|
(s = u.target),
|
|
|
|
(a = u.target.pos),
|
|
|
|
l ? (l = !1) : this.trigger("ground", s))
|
|
|
|
: u.isTop() &&
|
|
|
|
this.isJumping() &&
|
|
|
|
((this.vel = this.vel.reject(r.game.gravity.unit())),
|
|
|
|
this.trigger("headbutt", u.target)));
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
update() {
|
|
|
|
if (r.game.gravity && !this.isStatic) {
|
|
|
|
l && ((s = null), (a = null), this.trigger("fallOff"), (l = !1));
|
|
|
|
let u = !0;
|
|
|
|
if (
|
|
|
|
(s &&
|
|
|
|
(!this.isColliding(s) || !s.exists() || !s.is("body")
|
|
|
|
? (l = !0)
|
|
|
|
: (!s.pos.eq(a) &&
|
|
|
|
t.stickToPlatform !== !1 &&
|
|
|
|
this.moveBy(s.pos.sub(a)),
|
|
|
|
(a = s.pos),
|
|
|
|
(u = !1))),
|
|
|
|
u)
|
|
|
|
) {
|
|
|
|
let f = this.vel.clone();
|
|
|
|
this.vel = this.vel.add(
|
|
|
|
r.game.gravity.scale(this.gravityScale * e.dt())
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
2024-06-02 05:39:23 +00:00
|
|
|
let y = t.maxVelocity ?? wo;
|
|
|
|
this.vel.slen() > y * y && (this.vel = this.vel.unit().scale(y)),
|
|
|
|
f.dot(r.game.gravity) < 0 &&
|
|
|
|
this.vel.dot(r.game.gravity) >= 0 &&
|
|
|
|
this.trigger("fall");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
|
|
|
(this.vel.x *= 1 - this.drag),
|
|
|
|
(this.vel.y *= 1 - this.drag),
|
|
|
|
this.move(this.vel);
|
|
|
|
},
|
|
|
|
onPhysicsResolve(u) {
|
|
|
|
return this.on("physicsResolve", u);
|
|
|
|
},
|
|
|
|
onBeforePhysicsResolve(u) {
|
|
|
|
return this.on("beforePhysicsResolve", u);
|
|
|
|
},
|
|
|
|
curPlatform() {
|
|
|
|
return s;
|
|
|
|
},
|
|
|
|
isGrounded() {
|
|
|
|
return s !== null;
|
|
|
|
},
|
|
|
|
isFalling() {
|
|
|
|
return this.vel.dot(e.getGravityDirection()) > 0;
|
|
|
|
},
|
|
|
|
isJumping() {
|
|
|
|
return this.vel.dot(e.getGravityDirection()) < 0;
|
|
|
|
},
|
|
|
|
jump(u) {
|
|
|
|
(s = null),
|
|
|
|
(a = null),
|
|
|
|
(this.vel = e.getGravityDirection().scale(-u || -this.jumpForce));
|
|
|
|
},
|
|
|
|
onGround(u) {
|
|
|
|
return this.on("ground", u);
|
|
|
|
},
|
|
|
|
onFall(u) {
|
|
|
|
return this.on("fall", u);
|
|
|
|
},
|
|
|
|
onFallOff(u) {
|
|
|
|
return this.on("fallOff", u);
|
|
|
|
},
|
|
|
|
onHeadbutt(u) {
|
|
|
|
return this.on("headbutt", u);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
i(_o, "body");
|
|
|
|
function Ho(t = 2) {
|
|
|
|
let e = t;
|
|
|
|
return {
|
|
|
|
id: "doubleJump",
|
|
|
|
require: ["body"],
|
|
|
|
numJumps: t,
|
|
|
|
add() {
|
|
|
|
this.onGround(() => {
|
|
|
|
e = this.numJumps;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
doubleJump(r) {
|
|
|
|
e <= 0 ||
|
|
|
|
(e < this.numJumps && this.trigger("doubleJump"), e--, this.jump(r));
|
|
|
|
},
|
|
|
|
onDoubleJump(r) {
|
|
|
|
return this.on("doubleJump", r);
|
|
|
|
},
|
|
|
|
inspect() {
|
|
|
|
return `${e}`;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
i(Ho, "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();
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
i(Tn, "anchor");
|
|
|
|
function Ko() {
|
|
|
|
return { id: "fixed", fixed: !0 };
|
|
|
|
}
|
|
|
|
i(Ko, "fixed");
|
|
|
|
function qo(t, e) {
|
|
|
|
return {
|
|
|
|
id: "follow",
|
|
|
|
require: ["pos"],
|
|
|
|
follow: { obj: t, offset: e ?? C(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));
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
i(qo, "follow");
|
|
|
|
function zo(t, e) {
|
|
|
|
let r = typeof t == "number" ? T.fromAngle(t) : t.unit();
|
|
|
|
return {
|
|
|
|
id: "move",
|
|
|
|
require: ["pos"],
|
|
|
|
update() {
|
|
|
|
this.move(r.scale(e));
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
i(zo, "move");
|
|
|
|
function Yo(t = {}) {
|
|
|
|
let e = J(this),
|
|
|
|
r = t.distance ?? xo,
|
|
|
|
s = !1;
|
|
|
|
return {
|
|
|
|
id: "offscreen",
|
|
|
|
require: ["pos"],
|
|
|
|
isOffScreen() {
|
|
|
|
let a = this.screenPos(),
|
|
|
|
l = new ue(C(0), e.width(), e.height());
|
|
|
|
return !e.testRectPoint(l, a) && l.sdistToPoint(a) > r * r;
|
|
|
|
},
|
|
|
|
onExitScreen(a) {
|
|
|
|
return this.on("exitView", a);
|
|
|
|
},
|
|
|
|
onEnterScreen(a) {
|
|
|
|
return this.on("enterView", a);
|
|
|
|
},
|
|
|
|
update() {
|
|
|
|
this.isOffScreen()
|
|
|
|
? (s || (this.trigger("exitView"), (s = !0)),
|
|
|
|
t.hide && (this.hidden = !0),
|
|
|
|
t.pause && (this.paused = !0),
|
|
|
|
t.destroy && this.destroy())
|
|
|
|
: (s && (this.trigger("enterView"), (s = !1)),
|
|
|
|
t.hide && (this.hidden = !1),
|
|
|
|
t.pause && (this.paused = !1));
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
i(Yo, "offscreen");
|
|
|
|
function Xo(t) {
|
|
|
|
return t.fixed ? !0 : t.parent ? Xo(t.parent) : !1;
|
|
|
|
}
|
|
|
|
i(Xo, "isFixed");
|
|
|
|
function qt(...t) {
|
|
|
|
let e = J(this),
|
|
|
|
r = fe(e);
|
|
|
|
return {
|
|
|
|
id: "pos",
|
|
|
|
pos: C(...t),
|
|
|
|
moveBy(...s) {
|
|
|
|
this.pos = this.pos.add(C(...s));
|
|
|
|
},
|
|
|
|
move(...s) {
|
|
|
|
this.moveBy(C(...s).scale(e.dt()));
|
|
|
|
},
|
|
|
|
moveTo(...s) {
|
|
|
|
if (typeof s[0] == "number" && typeof s[1] == "number")
|
|
|
|
return this.moveTo(C(s[0], s[1]), s[2]);
|
|
|
|
let a = s[0],
|
|
|
|
l = s[1];
|
|
|
|
if (l === void 0) {
|
|
|
|
this.pos = C(a);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let u = a.sub(this.pos);
|
|
|
|
if (u.len() <= l * e.dt()) {
|
|
|
|
this.pos = C(a);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.move(u.unit().scale(l));
|
|
|
|
},
|
|
|
|
worldPos() {
|
|
|
|
return this.parent
|
|
|
|
? this.parent.transform.multVec2(this.pos)
|
|
|
|
: this.pos;
|
|
|
|
},
|
|
|
|
screenPos() {
|
|
|
|
let s = this.worldPos();
|
|
|
|
return Xo(this) ? s : e.toScreen(s);
|
|
|
|
},
|
|
|
|
inspect() {
|
|
|
|
return `(${Math.round(this.pos.x)}, ${Math.round(this.pos.y)})`;
|
|
|
|
},
|
|
|
|
drawInspect() {
|
|
|
|
e.drawCircle({
|
|
|
|
color: e.rgb(255, 0, 0),
|
|
|
|
radius: 4 / r.getViewportScale(),
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
i(qt, "pos");
|
|
|
|
function Wo(t) {
|
|
|
|
return {
|
|
|
|
id: "rotate",
|
|
|
|
angle: t ?? 0,
|
|
|
|
rotateBy(e) {
|
|
|
|
this.angle += e;
|
|
|
|
},
|
|
|
|
rotateTo(e) {
|
|
|
|
this.angle = e;
|
|
|
|
},
|
|
|
|
inspect() {
|
|
|
|
return `${Math.round(this.angle)}`;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
i(Wo, "rotate");
|
|
|
|
function zt(...t) {
|
|
|
|
let e = J(this),
|
|
|
|
r = fe(e);
|
|
|
|
return t.length === 0
|
|
|
|
? zt(1)
|
|
|
|
: {
|
|
|
|
id: "scale",
|
|
|
|
scale: C(...t),
|
|
|
|
scaleTo(...s) {
|
|
|
|
this.scale = C(...s);
|
|
|
|
},
|
|
|
|
scaleBy(...s) {
|
|
|
|
this.scale.scale(C(...s));
|
|
|
|
},
|
|
|
|
inspect() {
|
|
|
|
return `(${r.toFixed(this.scale.x, 2)}, ${r.toFixed(
|
|
|
|
this.scale.y,
|
|
|
|
2
|
|
|
|
)})`;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
i(zt, "scale");
|
|
|
|
function $o(t) {
|
|
|
|
return {
|
|
|
|
id: "z",
|
|
|
|
z: t,
|
|
|
|
inspect() {
|
|
|
|
return `${this.z}`;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
i($o, "z");
|
|
|
|
var Qo =
|
|
|
|
"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 Jo =
|
|
|
|
"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 Zo = Br(
|
|
|
|
"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/810TitAVvn9xtFucieiaEy54YqiIO6Rq
|
|
|
|
);
|
|
|
|
var es =
|
|
|
|
"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 na = "3001.0.0";
|
|
|
|
function ht(t) {
|
|
|
|
switch (t) {
|
|
|
|
case "topleft":
|
|
|
|
return new T(-1, -1);
|
|
|
|
case "top":
|
|
|
|
return new T(0, -1);
|
|
|
|
case "topright":
|
|
|
|
return new T(1, -1);
|
|
|
|
case "left":
|
|
|
|
return new T(-1, 0);
|
|
|
|
case "center":
|
|
|
|
return new T(0, 0);
|
|
|
|
case "right":
|
|
|
|
return new T(1, 0);
|
|
|
|
case "botleft":
|
|
|
|
return new T(-1, 1);
|
|
|
|
case "bot":
|
|
|
|
return new T(0, 1);
|
|
|
|
case "botright":
|
|
|
|
return new T(1, 1);
|
|
|
|
default:
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i(ht, "anchorPt");
|
|
|
|
function ra(t) {
|
|
|
|
switch (t) {
|
|
|
|
case "left":
|
|
|
|
return 0;
|
|
|
|
case "center":
|
|
|
|
return 0.5;
|
|
|
|
case "right":
|
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
return 0;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
|
|
|
i(ra, "alignPt");
|
|
|
|
function oa(t) {
|
|
|
|
return t.createBuffer(1, 1, 44100);
|
|
|
|
}
|
|
|
|
i(oa, "createEmptyAudioBuffer");
|
|
|
|
var $e,
|
|
|
|
as = i((t) => t && t.loadAseprite, "isKaboomCtx"),
|
|
|
|
J = i((t) => {
|
|
|
|
if (!$e)
|
2024-06-01 06:31:08 +00:00
|
|
|
throw new Error(
|
2024-06-02 05:39:23 +00:00
|
|
|
"You are trying to access to Kaboom Context before their initialization."
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
2024-06-02 05:39:23 +00:00
|
|
|
return as(t) ? t : $e;
|
|
|
|
}, "getKaboomContext"),
|
|
|
|
fe = i((t) => t._k, "getInternalContext"),
|
|
|
|
sa = i((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 r = t.canvas ?? e.appendChild(document.createElement("canvas")),
|
|
|
|
s = t.scale ?? 1,
|
|
|
|
a = t.width && t.height && !t.stretch && !t.letterbox;
|
|
|
|
a
|
|
|
|
? ((r.width = t.width * s), (r.height = t.height * s))
|
|
|
|
: ((r.width = r.parentElement.offsetWidth),
|
|
|
|
(r.height = r.parentElement.offsetHeight));
|
|
|
|
let l = ["outline: none", "cursor: default"];
|
|
|
|
if (a) {
|
|
|
|
let n = r.width,
|
|
|
|
o = r.height;
|
|
|
|
l.push(`width: ${n}px`), l.push(`height: ${o}px`);
|
|
|
|
} else l.push("width: 100%"), l.push("height: 100%");
|
|
|
|
t.crisp &&
|
|
|
|
(l.push("image-rendering: pixelated"),
|
|
|
|
l.push("image-rendering: crisp-edges")),
|
|
|
|
(r.style.cssText = l.join(";"));
|
|
|
|
let u = t.pixelDensity || window.devicePixelRatio;
|
|
|
|
(r.width *= u), (r.height *= u), (r.tabIndex = 0);
|
|
|
|
let f = document.createElement("canvas");
|
|
|
|
(f.width = 256), (f.height = 256);
|
|
|
|
let y = f.getContext("2d", { willReadFrequently: !0 }),
|
|
|
|
m = ao({
|
|
|
|
canvas: r,
|
|
|
|
touchToMouse: t.touchToMouse,
|
|
|
|
gamepads: t.gamepads,
|
|
|
|
pixelDensity: t.pixelDensity,
|
|
|
|
maxFPS: t.maxFPS,
|
|
|
|
}),
|
|
|
|
V = [],
|
|
|
|
x = m.canvas.getContext("webgl", {
|
|
|
|
antialias: !0,
|
|
|
|
depth: !0,
|
|
|
|
stencil: !0,
|
|
|
|
alpha: !0,
|
|
|
|
preserveDrawingBuffer: !0,
|
|
|
|
}),
|
|
|
|
P = dr(x, { texFilter: t.texFilter }),
|
|
|
|
w = (() => {
|
|
|
|
let n = Dt(bn, vn),
|
|
|
|
o = qe.fromImage(
|
|
|
|
P,
|
|
|
|
new ImageData(new Uint8ClampedArray([255, 255, 255, 255]), 1, 1)
|
|
|
|
),
|
|
|
|
c =
|
|
|
|
t.width && t.height
|
|
|
|
? new yt(P, t.width * u * s, t.height * u * s)
|
|
|
|
: new yt(P, x.drawingBufferWidth, x.drawingBufferHeight),
|
|
|
|
h = null,
|
|
|
|
d = 1;
|
|
|
|
t.background &&
|
|
|
|
((h = oe(t.background)),
|
|
|
|
(d = Array.isArray(t.background) ? t.background[3] : 1),
|
|
|
|
x.clearColor(h.r / 255, h.g / 255, h.b / 255, d ?? 1)),
|
|
|
|
x.enable(x.BLEND),
|
|
|
|
x.blendFuncSeparate(
|
|
|
|
x.SRC_ALPHA,
|
|
|
|
x.ONE_MINUS_SRC_ALPHA,
|
|
|
|
x.ONE,
|
|
|
|
x.ONE_MINUS_SRC_ALPHA
|
|
|
|
);
|
|
|
|
let v = new pn(P, gn, ho, po),
|
|
|
|
b = qe.fromImage(
|
|
|
|
P,
|
|
|
|
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
|
|
|
return {
|
2024-06-02 05:39:23 +00:00
|
|
|
lastDrawCalls: 0,
|
|
|
|
defShader: n,
|
|
|
|
defTex: o,
|
|
|
|
frameBuffer: c,
|
|
|
|
postShader: null,
|
|
|
|
postShaderUniform: null,
|
|
|
|
renderer: v,
|
|
|
|
transform: new Ge(),
|
|
|
|
transformStack: [],
|
|
|
|
bgTex: b,
|
|
|
|
bgColor: h,
|
|
|
|
bgAlpha: d,
|
|
|
|
width: t.width ?? x.drawingBufferWidth / u / s,
|
|
|
|
height: t.height ?? x.drawingBufferHeight / u / s,
|
|
|
|
viewport: {
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
width: x.drawingBufferWidth,
|
|
|
|
height: x.drawingBufferHeight,
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
fixed: !1,
|
2024-06-01 06:31:08 +00:00
|
|
|
};
|
2024-06-02 05:39:23 +00:00
|
|
|
})();
|
|
|
|
class K {
|
|
|
|
static {
|
|
|
|
i(this, "SpriteData");
|
|
|
|
}
|
|
|
|
tex;
|
|
|
|
frames = [new me(0, 0, 1, 1)];
|
|
|
|
anims = {};
|
|
|
|
slice9 = null;
|
|
|
|
constructor(o, c, h = {}, d = null) {
|
|
|
|
(this.tex = o),
|
|
|
|
c && (this.frames = c),
|
|
|
|
(this.anims = h),
|
|
|
|
(this.slice9 = d);
|
|
|
|
}
|
|
|
|
get width() {
|
|
|
|
return this.tex.width * this.frames[0].w;
|
|
|
|
}
|
|
|
|
get height() {
|
|
|
|
return this.tex.height * this.frames[0].h;
|
|
|
|
}
|
|
|
|
static from(o, c = {}) {
|
|
|
|
return typeof o == "string"
|
|
|
|
? K.fromURL(o, c)
|
|
|
|
: Promise.resolve(K.fromImage(o, c));
|
|
|
|
}
|
|
|
|
static fromImage(o, c = {}) {
|
|
|
|
let [h, d] = N.packer.add(o),
|
|
|
|
v = c.frames
|
|
|
|
? c.frames.map(
|
|
|
|
(b) =>
|
|
|
|
new me(
|
|
|
|
d.x + b.x * d.w,
|
|
|
|
d.y + b.y * d.h,
|
|
|
|
b.w * d.w,
|
|
|
|
b.h * d.h
|
|
|
|
)
|
|
|
|
)
|
|
|
|
: Ce(c.sliceX || 1, c.sliceY || 1, d.x, d.y, d.w, d.h);
|
|
|
|
return new K(h, v, c.anims, c.slice9);
|
|
|
|
}
|
|
|
|
static fromURL(o, c = {}) {
|
|
|
|
return _t(o).then((h) => K.fromImage(h, c));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class X {
|
|
|
|
static {
|
|
|
|
i(this, "SoundData");
|
|
|
|
}
|
|
|
|
buf;
|
|
|
|
constructor(o) {
|
|
|
|
this.buf = o;
|
|
|
|
}
|
|
|
|
static fromArrayBuffer(o) {
|
|
|
|
return new Promise((c, h) => z.ctx.decodeAudioData(o, c, h)).then(
|
|
|
|
(c) => new X(c)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
static fromURL(o) {
|
|
|
|
return ar(o)
|
|
|
|
? X.fromArrayBuffer(to(o))
|
|
|
|
: uo(o).then((c) => X.fromArrayBuffer(c));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let z = (() => {
|
|
|
|
let n = new (window.AudioContext || window.webkitAudioContext)(),
|
|
|
|
o = n.createGain();
|
|
|
|
o.connect(n.destination);
|
|
|
|
let c = new X(oa(n));
|
2024-06-01 06:31:08 +00:00
|
|
|
return (
|
2024-06-02 05:39:23 +00:00
|
|
|
n
|
|
|
|
.decodeAudioData(Zo.buffer.slice(0))
|
|
|
|
.then((h) => {
|
|
|
|
c.buf = h;
|
|
|
|
})
|
|
|
|
.catch((h) => {
|
|
|
|
console.error("Failed to load burp: ", h);
|
|
|
|
}),
|
|
|
|
{ ctx: n, masterNode: o, burpSnd: c }
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
2024-06-02 05:39:23 +00:00
|
|
|
})(),
|
|
|
|
N = {
|
|
|
|
urlPrefix: "",
|
|
|
|
sprites: new nt(),
|
|
|
|
fonts: new nt(),
|
|
|
|
bitmapFonts: new nt(),
|
|
|
|
sounds: new nt(),
|
|
|
|
shaders: new nt(),
|
|
|
|
custom: new nt(),
|
|
|
|
music: {},
|
|
|
|
packer: new Kt(P, 2048, 2048),
|
|
|
|
loaded: !1,
|
|
|
|
};
|
|
|
|
function $(n) {
|
|
|
|
return typeof n != "string" || ar(n) ? n : N.urlPrefix + n;
|
|
|
|
}
|
|
|
|
i($, "fixURL");
|
|
|
|
let O = {
|
|
|
|
events: new tt(),
|
|
|
|
objEvents: new tt(),
|
|
|
|
root: In([]),
|
|
|
|
gravity: null,
|
|
|
|
scenes: {},
|
|
|
|
currentScene: null,
|
|
|
|
logs: [],
|
|
|
|
cam: {
|
|
|
|
pos: null,
|
|
|
|
scale: new T(1),
|
|
|
|
angle: 0,
|
|
|
|
shake: 0,
|
|
|
|
transform: new Ge(),
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
|
|
|
};
|
2024-06-02 05:39:23 +00:00
|
|
|
O.root.use(Cn());
|
|
|
|
function se(n) {
|
|
|
|
return N.custom.add(null, n);
|
|
|
|
}
|
|
|
|
i(se, "load");
|
|
|
|
function _() {
|
|
|
|
let n = [
|
|
|
|
N.sprites,
|
|
|
|
N.sounds,
|
|
|
|
N.shaders,
|
|
|
|
N.fonts,
|
|
|
|
N.bitmapFonts,
|
|
|
|
N.custom,
|
|
|
|
];
|
|
|
|
return n.reduce((o, c) => o + c.progress(), 0) / n.length;
|
|
|
|
}
|
|
|
|
i(_, "loadProgress");
|
|
|
|
function ae(n) {
|
|
|
|
return n !== void 0 && (N.urlPrefix = n), N.urlPrefix;
|
|
|
|
}
|
|
|
|
i(ae, "loadRoot");
|
|
|
|
function re(n, o) {
|
|
|
|
return N.custom.add(n, Nt(o));
|
|
|
|
}
|
|
|
|
i(re, "loadJSON");
|
|
|
|
class ce {
|
|
|
|
static {
|
|
|
|
i(this, "FontData");
|
|
|
|
}
|
|
|
|
fontface;
|
|
|
|
filter = fn;
|
|
|
|
outline = null;
|
|
|
|
size = 64;
|
|
|
|
constructor(o, c = {}) {
|
2024-06-01 06:31:08 +00:00
|
|
|
if (
|
2024-06-02 05:39:23 +00:00
|
|
|
((this.fontface = o),
|
|
|
|
(this.filter = c.filter ?? fn),
|
|
|
|
(this.size = c.size ?? 64),
|
|
|
|
this.size > 256)
|
2024-06-01 06:31:08 +00:00
|
|
|
)
|
2024-06-02 05:39:23 +00:00
|
|
|
throw new Error(`Max font size: ${256}`);
|
|
|
|
c.outline &&
|
|
|
|
((this.outline = { width: 1, color: oe(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-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
function ge(n, o, c = {}) {
|
|
|
|
let h = new FontFace(n, typeof o == "string" ? `url(${o})` : o);
|
|
|
|
return (
|
|
|
|
document.fonts.add(h),
|
|
|
|
N.fonts.add(
|
|
|
|
n,
|
|
|
|
h
|
|
|
|
.load()
|
|
|
|
.catch((d) => {
|
|
|
|
throw new Error(`Failed to load font from "${o}": ${d}`);
|
|
|
|
})
|
|
|
|
.then((d) => new ce(d, c))
|
|
|
|
)
|
|
|
|
);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(ge, "loadFont");
|
|
|
|
function Ue(n, o, c, h, d = {}) {
|
|
|
|
return N.bitmapFonts.add(
|
|
|
|
n,
|
|
|
|
_t(o).then((v) => Dn(qe.fromImage(P, v, d), c, h, d.chars ?? pr))
|
|
|
|
);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Ue, "loadBitmapFont");
|
|
|
|
function Ce(n = 1, o = 1, c = 0, h = 0, d = 1, v = 1) {
|
|
|
|
let b = [],
|
|
|
|
D = d / n,
|
|
|
|
R = v / o;
|
|
|
|
for (let g = 0; g < o; g++)
|
|
|
|
for (let A = 0; A < n; A++)
|
|
|
|
b.push(new me(c + A * D, h + g * R, D, R));
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
i(Ce, "slice");
|
|
|
|
function Le(n, o) {
|
|
|
|
return (
|
|
|
|
(n = $(n)),
|
|
|
|
se(
|
|
|
|
typeof o == "string"
|
|
|
|
? new Promise((c, h) => {
|
|
|
|
Nt(o).then((d) => {
|
|
|
|
Le(n, d).then(c).catch(h);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
: K.from(n).then((c) => {
|
|
|
|
let h = {};
|
|
|
|
for (let d in o) {
|
|
|
|
let v = o[d],
|
|
|
|
b = c.frames[0],
|
|
|
|
D = 2048 * b.w,
|
|
|
|
R = 2048 * b.h,
|
|
|
|
g = v.frames
|
|
|
|
? v.frames.map(
|
|
|
|
(k) =>
|
|
|
|
new me(
|
|
|
|
b.x + ((v.x + k.x) / D) * b.w,
|
|
|
|
b.y + ((v.y + k.y) / R) * b.h,
|
|
|
|
(k.w / D) * b.w,
|
|
|
|
(k.h / R) * b.h
|
|
|
|
)
|
|
|
|
)
|
|
|
|
: Ce(
|
|
|
|
v.sliceX || 1,
|
|
|
|
v.sliceY || 1,
|
|
|
|
b.x + (v.x / D) * b.w,
|
|
|
|
b.y + (v.y / R) * b.h,
|
|
|
|
(v.width / D) * b.w,
|
|
|
|
(v.height / R) * b.h
|
|
|
|
),
|
|
|
|
A = new K(c.tex, g, v.anims);
|
|
|
|
N.sprites.addLoaded(d, A), (h[d] = A);
|
|
|
|
}
|
|
|
|
return h;
|
|
|
|
})
|
|
|
|
)
|
|
|
|
);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Le, "loadSpriteAtlas");
|
|
|
|
function je(n, o = {}) {
|
|
|
|
let c = document.createElement("canvas"),
|
|
|
|
h = n[0].width,
|
|
|
|
d = n[0].height;
|
|
|
|
(c.width = h * n.length), (c.height = d);
|
|
|
|
let v = c.getContext("2d");
|
|
|
|
n.forEach((D, R) => {
|
|
|
|
D instanceof ImageData
|
|
|
|
? v.putImageData(D, R * h, 0)
|
|
|
|
: v.drawImage(D, R * h, 0);
|
|
|
|
});
|
|
|
|
let b = v.getImageData(0, 0, n.length * h, d);
|
|
|
|
return K.fromImage(b, { ...o, sliceX: n.length, sliceY: 1 });
|
|
|
|
}
|
|
|
|
i(je, "createSpriteSheet");
|
|
|
|
function Ee(n, o, c = { sliceX: 1, sliceY: 1, anims: {} }) {
|
|
|
|
return (
|
|
|
|
(o = $(o)),
|
|
|
|
Array.isArray(o)
|
|
|
|
? o.some((h) => typeof h == "string")
|
|
|
|
? N.sprites.add(
|
|
|
|
n,
|
|
|
|
Promise.all(
|
|
|
|
o.map((h) =>
|
|
|
|
typeof h == "string" ? _t(h) : Promise.resolve(h)
|
|
|
|
)
|
|
|
|
).then((h) => je(h, c))
|
|
|
|
)
|
|
|
|
: N.sprites.addLoaded(n, je(o, c))
|
|
|
|
: typeof o == "string"
|
|
|
|
? N.sprites.add(n, K.from(o, c))
|
|
|
|
: N.sprites.addLoaded(n, K.fromImage(o, c))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
i(Ee, "loadSprite");
|
|
|
|
function Ne(n, o) {
|
|
|
|
return (
|
|
|
|
(o = $(o)),
|
|
|
|
N.sprites.add(
|
|
|
|
n,
|
|
|
|
new Promise(async (c) => {
|
|
|
|
let h = typeof o == "string" ? await Nt(o) : o,
|
|
|
|
d = await Promise.all(h.frames.map(_t)),
|
|
|
|
v = document.createElement("canvas");
|
|
|
|
(v.width = h.width), (v.height = h.height * h.frames.length);
|
|
|
|
let b = v.getContext("2d");
|
|
|
|
d.forEach((R, g) => {
|
|
|
|
b.drawImage(R, 0, g * h.height);
|
|
|
|
});
|
|
|
|
let D = await Ee(null, v, {
|
|
|
|
sliceY: h.frames.length,
|
|
|
|
anims: h.anims,
|
|
|
|
});
|
|
|
|
c(D);
|
|
|
|
})
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
i(Ne, "loadPedit");
|
|
|
|
function _e(n, o, c) {
|
|
|
|
(o = $(o)),
|
|
|
|
(c = $(c)),
|
|
|
|
typeof o == "string" && !c && (c = ro(o) + ".json");
|
|
|
|
let h = typeof c == "string" ? Nt(c) : Promise.resolve(c);
|
|
|
|
return N.sprites.add(
|
|
|
|
n,
|
|
|
|
h.then((d) => {
|
|
|
|
let v = d.meta.size,
|
|
|
|
b = d.frames.map(
|
|
|
|
(R) =>
|
|
|
|
new me(
|
|
|
|
R.frame.x / v.w,
|
|
|
|
R.frame.y / v.h,
|
|
|
|
R.frame.w / v.w,
|
|
|
|
R.frame.h / v.h
|
|
|
|
)
|
|
|
|
),
|
|
|
|
D = {};
|
|
|
|
for (let R of d.meta.frameTags)
|
|
|
|
R.from === R.to
|
|
|
|
? (D[R.name] = R.from)
|
|
|
|
: (D[R.name] = {
|
|
|
|
from: R.from,
|
|
|
|
to: R.to,
|
|
|
|
speed: 10,
|
|
|
|
loop: !0,
|
|
|
|
pingpong: R.direction === "pingpong",
|
|
|
|
});
|
|
|
|
return K.from(o, { frames: b, anims: D });
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
i(_e, "loadAseprite");
|
|
|
|
function He(n, o, c) {
|
|
|
|
return N.shaders.addLoaded(n, Dt(o, c));
|
|
|
|
}
|
|
|
|
i(He, "loadShader");
|
|
|
|
function pt(n, o, c) {
|
|
|
|
(o = $(o)), (c = $(c));
|
|
|
|
let h = i((v) => (v ? co(v) : Promise.resolve(null)), "resolveUrl"),
|
|
|
|
d = Promise.all([h(o), h(c)]).then(([v, b]) => Dt(v, b));
|
|
|
|
return N.shaders.add(n, d);
|
|
|
|
}
|
|
|
|
i(pt, "loadShaderURL");
|
|
|
|
function Se(n, o) {
|
|
|
|
return (
|
|
|
|
(o = $(o)),
|
|
|
|
N.sounds.add(
|
|
|
|
n,
|
|
|
|
typeof o == "string" ? X.fromURL(o) : X.fromArrayBuffer(o)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
i(Se, "loadSound");
|
|
|
|
function Ve(n, o) {
|
|
|
|
let c = new Audio(o);
|
|
|
|
return (c.preload = "auto"), (N.music[n] = $(o));
|
|
|
|
}
|
|
|
|
i(Ve, "loadMusic");
|
|
|
|
function ze(n = "bean") {
|
|
|
|
return Ee(n, Qo);
|
|
|
|
}
|
|
|
|
i(ze, "loadBean");
|
|
|
|
function rt(n) {
|
|
|
|
return N.sprites.get(n);
|
|
|
|
}
|
|
|
|
i(rt, "getSprite");
|
|
|
|
function ot(n) {
|
|
|
|
return N.sounds.get(n);
|
|
|
|
}
|
|
|
|
i(ot, "getSound");
|
|
|
|
function wt(n) {
|
|
|
|
return N.fonts.get(n);
|
|
|
|
}
|
|
|
|
i(wt, "getFont");
|
|
|
|
function Yt(n) {
|
|
|
|
return N.bitmapFonts.get(n);
|
|
|
|
}
|
|
|
|
i(Yt, "getBitmapFont");
|
|
|
|
function Xt(n) {
|
|
|
|
return N.shaders.get(n);
|
|
|
|
}
|
|
|
|
i(Xt, "getShader");
|
|
|
|
function An(n) {
|
|
|
|
return N.custom.get(n);
|
|
|
|
}
|
|
|
|
i(An, "getAsset");
|
|
|
|
function Wt(n) {
|
|
|
|
if (typeof n == "string") {
|
|
|
|
let o = rt(n);
|
|
|
|
if (o) return o;
|
|
|
|
if (_() < 1) return null;
|
|
|
|
throw new Error(`Sprite not found: ${n}`);
|
|
|
|
} else {
|
|
|
|
if (n instanceof K) return Re.loaded(n);
|
|
|
|
if (n instanceof Re) return n;
|
|
|
|
throw new Error(`Invalid sprite: ${n}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i(Wt, "resolveSprite");
|
|
|
|
function On(n) {
|
|
|
|
if (typeof n == "string") {
|
|
|
|
let o = ot(n);
|
|
|
|
if (o) return o;
|
|
|
|
if (_() < 1) return null;
|
|
|
|
throw new Error(`Sound not found: ${n}`);
|
|
|
|
} else {
|
|
|
|
if (n instanceof X) return Re.loaded(n);
|
|
|
|
if (n instanceof Re) return n;
|
|
|
|
throw new Error(`Invalid sound: ${n}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i(On, "resolveSound");
|
|
|
|
function Rn(n) {
|
|
|
|
if (!n) return w.defShader;
|
|
|
|
if (typeof n == "string") {
|
|
|
|
let o = Xt(n);
|
|
|
|
if (o) return o.data ?? o;
|
|
|
|
if (_() < 1) return null;
|
|
|
|
throw new Error(`Shader not found: ${n}`);
|
|
|
|
} else if (n instanceof Re) return n.data ? n.data : n;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
i(Rn, "resolveShader");
|
|
|
|
function $t(n) {
|
|
|
|
if (!n) return $t(t.font ?? lo);
|
|
|
|
if (typeof n == "string") {
|
|
|
|
let o = Yt(n),
|
|
|
|
c = wt(n);
|
|
|
|
if (o) return o.data ?? o;
|
|
|
|
if (c) return c.data ?? c;
|
|
|
|
if (document.fonts.check(`${64}px ${n}`)) return n;
|
|
|
|
if (_() < 1) return null;
|
|
|
|
throw new Error(`Font not found: ${n}`);
|
|
|
|
} else if (n instanceof Re) return n.data ? n.data : n;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
i($t, "resolveFont");
|
|
|
|
function Un(n) {
|
|
|
|
return (
|
|
|
|
n !== void 0 && (z.masterNode.gain.value = n), z.masterNode.gain.value
|
|
|
|
);
|
|
|
|
}
|
|
|
|
i(Un, "volume");
|
|
|
|
function Vn(n, o = {}) {
|
|
|
|
let c = new we(),
|
|
|
|
h = new Audio(n);
|
|
|
|
z.ctx.createMediaElementSource(h).connect(z.masterNode);
|
|
|
|
function v() {
|
|
|
|
le.paused || (m.isHidden() && !t.backgroundAudio) || z.ctx.resume();
|
|
|
|
}
|
|
|
|
i(v, "resumeAudioCtx");
|
|
|
|
function b() {
|
|
|
|
v(), h.play();
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
i(b, "play"),
|
|
|
|
o.paused || b(),
|
|
|
|
(h.onended = () => c.trigger()),
|
|
|
|
{
|
|
|
|
play() {
|
|
|
|
b();
|
|
|
|
},
|
|
|
|
seek(D) {
|
|
|
|
h.currentTime = D;
|
|
|
|
},
|
|
|
|
stop() {
|
|
|
|
h.pause(), this.seek(0);
|
|
|
|
},
|
|
|
|
set loop(D) {
|
|
|
|
h.loop = D;
|
|
|
|
},
|
|
|
|
get loop() {
|
|
|
|
return h.loop;
|
|
|
|
},
|
|
|
|
set paused(D) {
|
|
|
|
D ? h.pause() : b();
|
|
|
|
},
|
|
|
|
get paused() {
|
|
|
|
return h.paused;
|
|
|
|
},
|
|
|
|
time() {
|
|
|
|
return h.currentTime;
|
|
|
|
},
|
|
|
|
duration() {
|
|
|
|
return h.duration;
|
|
|
|
},
|
|
|
|
set volume(D) {
|
|
|
|
h.volume = Qe(D, 0, 1);
|
|
|
|
},
|
|
|
|
get volume() {
|
|
|
|
return h.volume;
|
|
|
|
},
|
|
|
|
set speed(D) {
|
|
|
|
h.playbackRate = Math.max(D, 0);
|
|
|
|
},
|
|
|
|
get speed() {
|
|
|
|
return h.playbackRate;
|
|
|
|
},
|
|
|
|
set detune(D) {},
|
|
|
|
get detune() {
|
|
|
|
return 0;
|
|
|
|
},
|
|
|
|
onEnd(D) {
|
|
|
|
return c.add(D);
|
|
|
|
},
|
|
|
|
then(D) {
|
|
|
|
return this.onEnd(D);
|
|
|
|
},
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
i(Vn, "playMusic");
|
|
|
|
function Qt(n, o = {}) {
|
|
|
|
if (typeof n == "string" && N.music[n]) return Vn(N.music[n], o);
|
|
|
|
let c = z.ctx,
|
|
|
|
h = o.paused ?? !1,
|
|
|
|
d = c.createBufferSource(),
|
|
|
|
v = new we(),
|
|
|
|
b = c.createGain(),
|
|
|
|
D = o.seek ?? 0,
|
|
|
|
R = 0,
|
|
|
|
g = 0,
|
|
|
|
A = !1;
|
|
|
|
(d.loop = !!o.loop),
|
|
|
|
(d.detune.value = o.detune ?? 0),
|
|
|
|
(d.playbackRate.value = o.speed ?? 1),
|
|
|
|
d.connect(b),
|
|
|
|
(d.onended = () => {
|
|
|
|
B() >= (d.buffer?.duration ?? Number.POSITIVE_INFINITY) &&
|
|
|
|
v.trigger();
|
|
|
|
}),
|
|
|
|
b.connect(z.masterNode),
|
|
|
|
(b.gain.value = o.volume ?? 1);
|
|
|
|
let k = i((G) => {
|
|
|
|
(d.buffer = G.buf),
|
|
|
|
h || ((R = c.currentTime), d.start(0, D), (A = !0));
|
|
|
|
}, "start"),
|
|
|
|
U = On(n);
|
|
|
|
U instanceof Re && U.onLoad(k);
|
|
|
|
let B = i(() => {
|
|
|
|
if (!d.buffer) return 0;
|
|
|
|
let G = h ? g - R : c.currentTime - R,
|
|
|
|
I = d.buffer.duration;
|
|
|
|
return d.loop ? G % I : Math.min(G, I);
|
|
|
|
}, "getTime"),
|
|
|
|
M = i((G) => {
|
|
|
|
let I = c.createBufferSource();
|
|
|
|
return (
|
|
|
|
(I.buffer = G.buffer),
|
|
|
|
(I.loop = G.loop),
|
|
|
|
(I.playbackRate.value = G.playbackRate.value),
|
|
|
|
(I.detune.value = G.detune.value),
|
|
|
|
(I.onended = G.onended),
|
|
|
|
I.connect(b),
|
|
|
|
I
|
|
|
|
);
|
|
|
|
}, "cloneNode");
|
|
|
|
return {
|
|
|
|
stop() {
|
|
|
|
(this.paused = !0), this.seek(0);
|
|
|
|
},
|
|
|
|
set paused(G) {
|
|
|
|
if (h !== G)
|
|
|
|
if (((h = G), G)) A && (d.stop(), (A = !1)), (g = c.currentTime);
|
|
|
|
else {
|
|
|
|
d = M(d);
|
|
|
|
let I = g - R;
|
|
|
|
d.start(0, I), (A = !0), (R = c.currentTime - I), (g = 0);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
get paused() {
|
|
|
|
return h;
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
play(G = 0) {
|
|
|
|
this.seek(G), (this.paused = !1);
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
seek(G) {
|
|
|
|
d.buffer?.duration &&
|
|
|
|
(G > d.buffer.duration ||
|
|
|
|
(h
|
|
|
|
? ((d = M(d)), (R = g - G))
|
|
|
|
: (d.stop(),
|
|
|
|
(d = M(d)),
|
|
|
|
(R = c.currentTime - G),
|
|
|
|
d.start(0, G),
|
|
|
|
(A = !0),
|
|
|
|
(g = 0))));
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
set speed(G) {
|
|
|
|
d.playbackRate.value = G;
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
get speed() {
|
|
|
|
return d.playbackRate.value;
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
set detune(G) {
|
|
|
|
d.detune.value = G;
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
get detune() {
|
|
|
|
return d.detune.value;
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
set volume(G) {
|
|
|
|
b.gain.value = Math.max(G, 0);
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
get volume() {
|
|
|
|
return b.gain.value;
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
set loop(G) {
|
|
|
|
d.loop = G;
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
get loop() {
|
|
|
|
return d.loop;
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
duration() {
|
|
|
|
return d.buffer?.duration ?? 0;
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
time() {
|
|
|
|
return B() % this.duration();
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
onEnd(G) {
|
|
|
|
return v.add(G);
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
then(G) {
|
|
|
|
return this.onEnd(G);
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
i(Qt, "play");
|
|
|
|
function Jt(n) {
|
|
|
|
return Qt(z.burpSnd, n);
|
|
|
|
}
|
|
|
|
i(Jt, "burp");
|
|
|
|
function Pn(n, o) {
|
|
|
|
let c = new yt(P, n, o);
|
|
|
|
return {
|
|
|
|
clear: () => c.clear(),
|
|
|
|
free: () => c.free(),
|
|
|
|
toDataURL: () => c.toDataURL(),
|
|
|
|
toImageData: () => c.toImageData(),
|
|
|
|
width: c.width,
|
|
|
|
height: c.height,
|
|
|
|
draw: (h) => {
|
|
|
|
Pe(), c.bind(), h(), Pe(), c.unbind();
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
i(Pn, "makeCanvas");
|
|
|
|
function Dt(n = bn, o = vn) {
|
|
|
|
let c = fo.replace("{{user}}", n ?? bn),
|
|
|
|
h = go.replace("{{user}}", o ?? vn);
|
|
|
|
try {
|
|
|
|
return new hn(
|
|
|
|
P,
|
|
|
|
c,
|
|
|
|
h,
|
|
|
|
gn.map((d) => d.name)
|
|
|
|
);
|
|
|
|
} catch (d) {
|
|
|
|
let b = /(?<type>^\w+) SHADER ERROR: 0:(?<line>\d+): (?<msg>.+)/,
|
|
|
|
D = so(d).match(b),
|
|
|
|
R = Number(D.groups.line) - 14,
|
|
|
|
g = D.groups.msg.trim(),
|
|
|
|
A = D.groups.type.toLowerCase();
|
|
|
|
throw new Error(`${A} shader line ${R}: ${g}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i(Dt, "makeShader");
|
|
|
|
function Dn(n, o, c, h) {
|
|
|
|
let d = n.width / o,
|
|
|
|
v = {},
|
|
|
|
b = h.split("").entries();
|
|
|
|
for (let [D, R] of b)
|
|
|
|
v[R] = new me((D % d) * o, Math.floor(D / d) * c, o, c);
|
|
|
|
return { tex: n, map: v, size: c };
|
|
|
|
}
|
|
|
|
i(Dn, "makeFont");
|
|
|
|
function st(n, o, c, h = w.defTex, d = w.defShader, v = {}) {
|
|
|
|
let b = Rn(d);
|
|
|
|
if (!b || b instanceof Re) return;
|
|
|
|
let D = w.fixed || c ? w.transform : O.cam.transform.mult(w.transform),
|
|
|
|
R = [];
|
|
|
|
for (let g of n) {
|
|
|
|
let A = Zt(D.multVec2(g.pos));
|
|
|
|
R.push(
|
|
|
|
A.x,
|
|
|
|
A.y,
|
|
|
|
g.uv.x,
|
|
|
|
g.uv.y,
|
|
|
|
g.color.r / 255,
|
|
|
|
g.color.g / 255,
|
|
|
|
g.color.b / 255,
|
|
|
|
g.opacity
|
|
|
|
);
|
|
|
|
}
|
|
|
|
w.renderer.push(x.TRIANGLES, R, o, b, h, v);
|
|
|
|
}
|
|
|
|
i(st, "drawRaw");
|
|
|
|
function Pe() {
|
|
|
|
w.renderer.flush();
|
|
|
|
}
|
|
|
|
i(Pe, "flush");
|
|
|
|
function Ct() {
|
|
|
|
x.clear(x.COLOR_BUFFER_BIT),
|
|
|
|
w.frameBuffer.bind(),
|
|
|
|
x.clear(x.COLOR_BUFFER_BIT),
|
|
|
|
w.bgColor ||
|
|
|
|
ct(() => {
|
|
|
|
it({
|
|
|
|
width: De(),
|
|
|
|
height: ke(),
|
|
|
|
quad: new me(0, 0, De() / 64, ke() / 64),
|
|
|
|
tex: w.bgTex,
|
|
|
|
fixed: !0,
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
(w.renderer.numDraws = 0),
|
|
|
|
(w.fixed = !1),
|
|
|
|
(w.transformStack.length = 0),
|
|
|
|
(w.transform = new Ge());
|
|
|
|
}
|
|
|
|
i(Ct, "frameStart");
|
|
|
|
function Mn(n, o) {
|
|
|
|
(w.postShader = n), (w.postShaderUniform = o ?? null);
|
|
|
|
}
|
|
|
|
i(Mn, "usePostEffect");
|
|
|
|
function Mt() {
|
|
|
|
Pe(),
|
|
|
|
(w.lastDrawCalls = w.renderer.numDraws),
|
|
|
|
w.frameBuffer.unbind(),
|
|
|
|
x.viewport(0, 0, x.drawingBufferWidth, x.drawingBufferHeight);
|
|
|
|
let n = w.width,
|
|
|
|
o = w.height;
|
|
|
|
(w.width = x.drawingBufferWidth / u),
|
|
|
|
(w.height = x.drawingBufferHeight / u),
|
|
|
|
Gt({
|
|
|
|
flipY: !0,
|
|
|
|
tex: w.frameBuffer.tex,
|
|
|
|
pos: new T(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,
|
|
|
|
}),
|
|
|
|
Pe(),
|
|
|
|
(w.width = n),
|
|
|
|
(w.height = o);
|
|
|
|
}
|
|
|
|
i(Mt, "frameEnd");
|
|
|
|
function Zt(n) {
|
|
|
|
return new T((n.x / De()) * 2 - 1, (-n.y / ke()) * 2 + 1);
|
|
|
|
}
|
|
|
|
i(Zt, "screen2ndc");
|
|
|
|
function Gn(n) {
|
|
|
|
w.transform = n.clone();
|
|
|
|
}
|
|
|
|
i(Gn, "pushMatrix");
|
|
|
|
function de(...n) {
|
|
|
|
if (n[0] === void 0) return;
|
|
|
|
let o = C(...n);
|
|
|
|
(o.x === 0 && o.y === 0) || w.transform.translate(o);
|
|
|
|
}
|
|
|
|
i(de, "pushTranslate");
|
|
|
|
function he(...n) {
|
|
|
|
if (n[0] === void 0) return;
|
|
|
|
let o = C(...n);
|
|
|
|
(o.x === 1 && o.y === 1) || w.transform.scale(o);
|
|
|
|
}
|
|
|
|
i(he, "pushScale");
|
|
|
|
function Ke(n) {
|
|
|
|
n && w.transform.rotate(n);
|
|
|
|
}
|
|
|
|
i(Ke, "pushRotate");
|
|
|
|
function xe() {
|
|
|
|
w.transformStack.push(w.transform.clone());
|
|
|
|
}
|
|
|
|
i(xe, "pushTransform");
|
|
|
|
function Ae() {
|
|
|
|
w.transformStack.length > 0 && (w.transform = w.transformStack.pop());
|
|
|
|
}
|
|
|
|
i(Ae, "popTransform");
|
|
|
|
function it(n) {
|
|
|
|
if (n.width === void 0 || n.height === void 0)
|
|
|
|
throw new Error(
|
|
|
|
'drawUVQuad() requires property "width" and "height".'
|
|
|
|
);
|
|
|
|
if (n.width <= 0 || n.height <= 0) return;
|
|
|
|
let o = n.width,
|
|
|
|
c = n.height,
|
|
|
|
d = ht(n.anchor || Vt).scale(new T(o, c).scale(-0.5)),
|
|
|
|
v = n.quad || new me(0, 0, 1, 1),
|
|
|
|
b = n.color || oe(255, 255, 255),
|
|
|
|
D = n.opacity ?? 1,
|
|
|
|
R = n.tex ? 0.1 / n.tex.width : 0,
|
|
|
|
g = n.tex ? 0.1 / n.tex.height : 0,
|
|
|
|
A = v.x + R,
|
|
|
|
k = v.y + g,
|
|
|
|
U = v.w - R * 2,
|
|
|
|
B = v.h - g * 2;
|
|
|
|
xe(),
|
|
|
|
de(n.pos),
|
|
|
|
Ke(n.angle),
|
|
|
|
he(n.scale),
|
|
|
|
de(d),
|
|
|
|
st(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
pos: new T(-o / 2, c / 2),
|
|
|
|
uv: new T(n.flipX ? A + U : A, n.flipY ? k : k + B),
|
|
|
|
color: b,
|
|
|
|
opacity: D,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pos: new T(-o / 2, -c / 2),
|
|
|
|
uv: new T(n.flipX ? A + U : A, n.flipY ? k + B : k),
|
|
|
|
color: b,
|
|
|
|
opacity: D,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pos: new T(o / 2, -c / 2),
|
|
|
|
uv: new T(n.flipX ? A : A + U, n.flipY ? k + B : k),
|
|
|
|
color: b,
|
|
|
|
opacity: D,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pos: new T(o / 2, c / 2),
|
|
|
|
uv: new T(n.flipX ? A : A + U, n.flipY ? k : k + B),
|
|
|
|
color: b,
|
|
|
|
opacity: D,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[0, 1, 3, 1, 2, 3],
|
|
|
|
n.fixed,
|
|
|
|
n.tex,
|
|
|
|
n.shader,
|
|
|
|
n.uniform
|
|
|
|
),
|
|
|
|
Ae();
|
|
|
|
}
|
|
|
|
i(it, "drawUVQuad");
|
|
|
|
function Gt(n) {
|
|
|
|
if (!n.tex) throw new Error('drawTexture() requires property "tex".');
|
|
|
|
let o = n.quad ?? new me(0, 0, 1, 1),
|
|
|
|
c = n.tex.width * o.w,
|
|
|
|
h = n.tex.height * o.h,
|
|
|
|
d = new T(1);
|
|
|
|
if (n.tiled) {
|
|
|
|
let v = Math.ceil((n.width || c) / c),
|
|
|
|
b = Math.ceil((n.height || h) / h),
|
|
|
|
R = ht(n.anchor || Vt)
|
|
|
|
.add(new T(1, 1))
|
|
|
|
.scale(0.5)
|
|
|
|
.scale(v * c, b * h);
|
|
|
|
for (let g = 0; g < v; g++)
|
|
|
|
for (let A = 0; A < b; A++)
|
|
|
|
it(
|
|
|
|
Object.assign({}, n, {
|
|
|
|
pos: (n.pos || new T(0)).add(new T(c * g, h * A)).sub(R),
|
|
|
|
scale: d.scale(n.scale || new T(1)),
|
|
|
|
tex: n.tex,
|
|
|
|
quad: o,
|
|
|
|
width: c,
|
|
|
|
height: h,
|
|
|
|
anchor: "topleft",
|
|
|
|
})
|
|
|
|
);
|
|
|
|
} else
|
|
|
|
n.width && n.height
|
|
|
|
? ((d.x = n.width / c), (d.y = n.height / h))
|
|
|
|
: n.width
|
|
|
|
? ((d.x = n.width / c), (d.y = d.x))
|
|
|
|
: n.height && ((d.y = n.height / h), (d.x = d.y)),
|
|
|
|
it(
|
|
|
|
Object.assign({}, n, {
|
|
|
|
scale: d.scale(n.scale || new T(1)),
|
|
|
|
tex: n.tex,
|
|
|
|
quad: o,
|
|
|
|
width: c,
|
|
|
|
height: h,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
i(Gt, "drawTexture");
|
|
|
|
function en(n) {
|
|
|
|
if (!n.sprite)
|
|
|
|
throw new Error('drawSprite() requires property "sprite"');
|
|
|
|
let o = Wt(n.sprite);
|
|
|
|
if (!o || !o.data) return;
|
|
|
|
let c = o.data.frames[n.frame ?? 0];
|
|
|
|
if (!c) throw new Error(`Frame not found: ${n.frame ?? 0}`);
|
|
|
|
Gt(
|
|
|
|
Object.assign({}, n, {
|
|
|
|
tex: o.data.tex,
|
|
|
|
quad: c.scale(n.quad ?? new me(0, 0, 1, 1)),
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
i(en, "drawSprite");
|
|
|
|
function at(n, o, c, h, d, v = 1) {
|
|
|
|
(h = ve(h % 360)), (d = ve(d % 360)), d <= h && (d += Math.PI * 2);
|
|
|
|
let b = [],
|
|
|
|
D = Math.ceil(((d - h) / ve(8)) * v),
|
|
|
|
R = (d - h) / D;
|
|
|
|
for (let g = h; g < d; g += R)
|
|
|
|
b.push(n.add(o * Math.cos(g), c * Math.sin(g)));
|
|
|
|
return b.push(n.add(o * Math.cos(d), c * Math.sin(d))), b;
|
|
|
|
}
|
|
|
|
i(at, "getArcPts");
|
|
|
|
function p(n) {
|
|
|
|
if (n.width === void 0 || n.height === void 0)
|
|
|
|
throw new Error('drawRect() requires property "width" and "height".');
|
|
|
|
if (n.width <= 0 || n.height <= 0) return;
|
|
|
|
let o = n.width,
|
|
|
|
c = n.height,
|
|
|
|
d = ht(n.anchor || Vt)
|
|
|
|
.add(1, 1)
|
|
|
|
.scale(new T(o, c).scale(-0.5)),
|
|
|
|
v = [new T(0, 0), new T(o, 0), new T(o, c), new T(0, c)];
|
|
|
|
if (n.radius) {
|
|
|
|
let b = Math.min(Math.min(o, c) / 2, n.radius);
|
|
|
|
v = [
|
|
|
|
new T(b, 0),
|
|
|
|
new T(o - b, 0),
|
|
|
|
...at(new T(o - b, b), b, b, 270, 360),
|
|
|
|
new T(o, b),
|
|
|
|
new T(o, c - b),
|
|
|
|
...at(new T(o - b, c - b), b, b, 0, 90),
|
|
|
|
new T(o - b, c),
|
|
|
|
new T(b, c),
|
|
|
|
...at(new T(b, c - b), b, b, 90, 180),
|
|
|
|
new T(0, c - b),
|
|
|
|
new T(0, b),
|
|
|
|
...at(new T(b, b), b, b, 180, 270),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
Et(
|
|
|
|
Object.assign({}, n, {
|
|
|
|
offset: d,
|
|
|
|
pts: v,
|
|
|
|
...(n.gradient
|
|
|
|
? {
|
|
|
|
colors: n.horizontal
|
|
|
|
? [
|
|
|
|
n.gradient[0],
|
|
|
|
n.gradient[1],
|
|
|
|
n.gradient[1],
|
|
|
|
n.gradient[0],
|
|
|
|
]
|
|
|
|
: [
|
|
|
|
n.gradient[0],
|
|
|
|
n.gradient[0],
|
|
|
|
n.gradient[1],
|
|
|
|
n.gradient[1],
|
|
|
|
],
|
|
|
|
}
|
|
|
|
: {}),
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
i(p, "drawRect");
|
|
|
|
function S(n) {
|
|
|
|
let { p1: o, p2: c } = n;
|
|
|
|
if (!o || !c)
|
|
|
|
throw new Error('drawLine() requires properties "p1" and "p2".');
|
|
|
|
let h = n.width || 1,
|
|
|
|
d = c
|
|
|
|
.sub(o)
|
|
|
|
.unit()
|
|
|
|
.normal()
|
|
|
|
.scale(h * 0.5),
|
|
|
|
v = [o.sub(d), o.add(d), c.add(d), c.sub(d)].map((b) => ({
|
|
|
|
pos: new T(b.x, b.y),
|
|
|
|
uv: new T(0),
|
|
|
|
color: n.color ?? ee.WHITE,
|
|
|
|
opacity: n.opacity ?? 1,
|
|
|
|
}));
|
|
|
|
st(v, [0, 1, 3, 1, 2, 3], n.fixed, w.defTex, n.shader, n.uniform);
|
|
|
|
}
|
|
|
|
i(S, "drawLine");
|
|
|
|
function L(n) {
|
|
|
|
let o = n.pts,
|
|
|
|
c = [],
|
|
|
|
h = (n.width || 1) * 0.5,
|
|
|
|
d = o[0] === o[o.length - 1] || o[0].eq(o[o.length - 1]),
|
|
|
|
v = n.pos || C(0, 0),
|
|
|
|
b;
|
|
|
|
d ? (b = o[0].sub(o[o.length - 2])) : (b = o[1].sub(o[0]));
|
|
|
|
let D = b.len(),
|
|
|
|
R = b.normal().scale(-h / D),
|
|
|
|
g,
|
|
|
|
A = o[0];
|
|
|
|
for (let M = 1; M < o.length; M++) {
|
|
|
|
(g = A), (A = o[M]);
|
|
|
|
let G = A.sub(g),
|
|
|
|
I = G.len(),
|
|
|
|
te = G.normal().scale(-h / I),
|
|
|
|
Z = b.cross(G);
|
|
|
|
if (Math.abs(Z) / (D * I) < 0.05) {
|
|
|
|
c.push(g.add(R)),
|
|
|
|
c.push(g.sub(R)),
|
|
|
|
b.dot(G) < 0 && (c.push(g.sub(R)), c.push(g.add(R))),
|
|
|
|
(b = G),
|
|
|
|
(D = I),
|
|
|
|
(R = te);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
let ne = te.sub(R).cross(G) / Z,
|
|
|
|
q = R.add(b.scale(ne));
|
|
|
|
Z > 0
|
|
|
|
? (c.push(g.add(q)),
|
|
|
|
c.push(g.sub(R)),
|
|
|
|
c.push(g.add(q)),
|
|
|
|
c.push(g.sub(te)))
|
|
|
|
: (c.push(g.add(R)),
|
|
|
|
c.push(g.sub(q)),
|
|
|
|
c.push(g.add(te)),
|
|
|
|
c.push(g.sub(q))),
|
|
|
|
(b = G),
|
|
|
|
(D = I),
|
|
|
|
(R = te);
|
|
|
|
}
|
|
|
|
let k = c.map((M) => ({
|
|
|
|
pos: v.add(M),
|
|
|
|
uv: C(),
|
|
|
|
color: n.color || ee.WHITE,
|
|
|
|
opacity: n.opacity ?? 1,
|
|
|
|
})),
|
|
|
|
U = [],
|
|
|
|
B = 0;
|
|
|
|
for (let M = 0; M < c.length - 2; M += 2)
|
|
|
|
(U[B++] = M + 1),
|
|
|
|
(U[B++] = M),
|
|
|
|
(U[B++] = M + 2),
|
|
|
|
(U[B++] = M + 2),
|
|
|
|
(U[B++] = M + 3),
|
|
|
|
(U[B++] = M + 1);
|
|
|
|
d &&
|
|
|
|
((U[B++] = c.length - 1),
|
|
|
|
(U[B++] = c.length - 2),
|
|
|
|
(U[B++] = 0),
|
|
|
|
(U[B++] = 0),
|
|
|
|
(U[B++] = 1),
|
|
|
|
(U[B++] = c.length - 1)),
|
|
|
|
st(k, U, n.fixed, w.defTex, n.shader, n.uniform);
|
|
|
|
}
|
|
|
|
i(L, "_drawLinesBevel");
|
|
|
|
function Y(n) {
|
|
|
|
let o = n.pts,
|
|
|
|
c = [],
|
|
|
|
h = (n.width || 1) * 0.5,
|
|
|
|
d = o[0] === o[o.length - 1] || o[0].eq(o[o.length - 1]),
|
|
|
|
v = n.pos || C(0, 0),
|
|
|
|
b;
|
|
|
|
d ? (b = o[0].sub(o[o.length - 2])) : (b = o[1].sub(o[0]));
|
|
|
|
let D = b.len(),
|
|
|
|
R = b.normal().scale(-h / D),
|
|
|
|
g,
|
|
|
|
A = o[0];
|
|
|
|
for (let M = 1; M < o.length; M++) {
|
|
|
|
(g = A), (A = o[M]);
|
|
|
|
let G = A.sub(g),
|
|
|
|
I = G.len(),
|
|
|
|
te = G.normal().scale(-h / I),
|
|
|
|
Z = b.cross(G);
|
|
|
|
if (Math.abs(Z) / (D * I) < 0.05) {
|
|
|
|
c.push(g.add(R)),
|
|
|
|
c.push(g.sub(R)),
|
|
|
|
b.dot(G) < 0 && (c.push(g.sub(R)), c.push(g.add(R))),
|
|
|
|
(b = G),
|
|
|
|
(D = I),
|
|
|
|
(R = te);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
let ne = te.sub(R).cross(G) / Z,
|
|
|
|
q = R.add(b.scale(ne));
|
|
|
|
if (Z > 0) {
|
|
|
|
let Me = g.add(q),
|
|
|
|
E = Math.max(h, 10),
|
|
|
|
j = ve(R.angleBetween(te) / E),
|
|
|
|
F = R,
|
|
|
|
H = Math.cos(j),
|
|
|
|
W = Math.sin(j);
|
|
|
|
for (let Q = 0; Q < E; Q++)
|
|
|
|
c.push(Me),
|
|
|
|
c.push(g.sub(F)),
|
|
|
|
(F = C(F.x * H - F.y * W, F.x * W + F.y * H));
|
|
|
|
} else {
|
|
|
|
let Me = g.sub(q),
|
|
|
|
E = Math.max(h, 10),
|
|
|
|
j = ve(R.angleBetween(te) / E),
|
|
|
|
F = R,
|
|
|
|
H = Math.cos(j),
|
|
|
|
W = Math.sin(j);
|
|
|
|
for (let Q = 0; Q < E; Q++)
|
|
|
|
c.push(g.add(F)),
|
|
|
|
c.push(Me),
|
|
|
|
(F = C(F.x * H - F.y * W, F.x * W + F.y * H));
|
|
|
|
}
|
|
|
|
(b = G), (D = I), (R = te);
|
|
|
|
}
|
|
|
|
let k = c.map((M) => ({
|
|
|
|
pos: v.add(M),
|
|
|
|
uv: C(),
|
|
|
|
color: n.color || ee.WHITE,
|
|
|
|
opacity: n.opacity ?? 1,
|
|
|
|
})),
|
|
|
|
U = [],
|
|
|
|
B = 0;
|
|
|
|
for (let M = 0; M < c.length - 2; M += 2)
|
|
|
|
(U[B++] = M + 1),
|
|
|
|
(U[B++] = M),
|
|
|
|
(U[B++] = M + 2),
|
|
|
|
(U[B++] = M + 2),
|
|
|
|
(U[B++] = M + 3),
|
|
|
|
(U[B++] = M + 1);
|
|
|
|
d &&
|
|
|
|
((U[B++] = c.length - 1),
|
|
|
|
(U[B++] = c.length - 2),
|
|
|
|
(U[B++] = 0),
|
|
|
|
(U[B++] = 0),
|
|
|
|
(U[B++] = 1),
|
|
|
|
(U[B++] = c.length - 1)),
|
|
|
|
st(k, U, n.fixed, w.defTex, n.shader, n.uniform);
|
|
|
|
}
|
|
|
|
i(Y, "_drawLinesRound");
|
|
|
|
function ye(n) {
|
|
|
|
let o = n.pts,
|
|
|
|
c = [],
|
|
|
|
h = (n.width || 1) * 0.5,
|
|
|
|
d = o[0] === o[o.length - 1] || o[0].eq(o[o.length - 1]),
|
|
|
|
v = n.pos || C(0, 0),
|
|
|
|
b;
|
|
|
|
d ? (b = o[0].sub(o[o.length - 2])) : (b = o[1].sub(o[0]));
|
|
|
|
let D = b.len(),
|
|
|
|
R = b.normal().scale(-h / D),
|
|
|
|
g,
|
|
|
|
A = o[0];
|
|
|
|
for (let M = 1; M < o.length; M++) {
|
|
|
|
(g = A), (A = o[M]);
|
|
|
|
let G = A.sub(g),
|
|
|
|
I = G.len(),
|
|
|
|
te = G.normal().scale(-h / I),
|
|
|
|
Z = b.cross(G);
|
|
|
|
if (Math.abs(Z) / (D * I) < 0.05) {
|
|
|
|
c.push(g.add(R)),
|
|
|
|
c.push(g.sub(R)),
|
|
|
|
b.dot(G) < 0 && (c.push(g.sub(R)), c.push(g.add(R))),
|
|
|
|
(b = G),
|
|
|
|
(D = I),
|
|
|
|
(R = te);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
let ne = te.sub(R).cross(G) / Z,
|
|
|
|
q = R.add(b.scale(ne));
|
|
|
|
c.push(g.add(q)), c.push(g.sub(q)), (b = G), (D = I), (R = te);
|
|
|
|
}
|
|
|
|
let k = c.map((M) => ({
|
|
|
|
pos: v.add(M),
|
|
|
|
uv: C(),
|
|
|
|
color: n.color || ee.WHITE,
|
|
|
|
opacity: n.opacity ?? 1,
|
|
|
|
})),
|
|
|
|
U = [],
|
|
|
|
B = 0;
|
|
|
|
for (let M = 0; M < c.length - 2; M += 2)
|
|
|
|
(U[B++] = M + 1),
|
|
|
|
(U[B++] = M),
|
|
|
|
(U[B++] = M + 2),
|
|
|
|
(U[B++] = M + 2),
|
|
|
|
(U[B++] = M + 3),
|
|
|
|
(U[B++] = M + 1);
|
|
|
|
d &&
|
|
|
|
((U[B++] = c.length - 1),
|
|
|
|
(U[B++] = c.length - 2),
|
|
|
|
(U[B++] = 0),
|
|
|
|
(U[B++] = 0),
|
|
|
|
(U[B++] = 1),
|
|
|
|
(U[B++] = c.length - 1)),
|
|
|
|
st(k, U, n.fixed, w.defTex, n.shader, n.uniform);
|
|
|
|
}
|
|
|
|
i(ye, "_drawLinesMiter");
|
|
|
|
function ie(n) {
|
|
|
|
let o = n.pts;
|
|
|
|
if (!o) throw new Error('drawLines() requires property "pts".');
|
|
|
|
if (!(o.length < 2)) {
|
|
|
|
if (o.length > 2)
|
|
|
|
switch (n.join) {
|
|
|
|
case "bevel":
|
|
|
|
return L(n);
|
|
|
|
case "round":
|
|
|
|
return Y(n);
|
|
|
|
case "miter":
|
|
|
|
return ye(n);
|
|
|
|
}
|
|
|
|
if (n.radius && o.length >= 3) {
|
|
|
|
let c = o[0].sdist(o[1]);
|
|
|
|
for (let d = 1; d < o.length - 1; d++)
|
|
|
|
c = Math.min(o[d].sdist(o[d + 1]), c);
|
|
|
|
let h = Math.min(n.radius, Math.sqrt(c) / 2);
|
|
|
|
S(Object.assign({}, n, { p1: o[0], p2: o[1] }));
|
|
|
|
for (let d = 1; d < o.length - 2; d++) {
|
|
|
|
let v = o[d],
|
|
|
|
b = o[d + 1];
|
|
|
|
S(Object.assign({}, n, { p1: v, p2: b }));
|
|
|
|
}
|
|
|
|
S(
|
|
|
|
Object.assign({}, n, { p1: o[o.length - 2], p2: o[o.length - 1] })
|
|
|
|
);
|
|
|
|
} else
|
|
|
|
for (let c = 0; c < o.length - 1; c++)
|
|
|
|
S(Object.assign({}, n, { p1: o[c], p2: o[c + 1] })),
|
|
|
|
n.join !== "none" &&
|
|
|
|
Xe(Object.assign({}, n, { pos: o[c], radius: n.width / 2 }));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i(ie, "drawLines");
|
|
|
|
function Ye(n, o) {
|
|
|
|
let c = o.segments ?? 16,
|
|
|
|
h = [];
|
|
|
|
for (let d = 0; d <= c; d++) h.push(n(d / c));
|
|
|
|
ie({ pts: h, width: o.width || 1, pos: o.pos, color: o.color });
|
|
|
|
}
|
|
|
|
i(Ye, "drawCurve");
|
|
|
|
function ft(n) {
|
|
|
|
Ye((o) => nr(n.pt1, n.pt2, n.pt3, n.pt4, o), n);
|
|
|
|
}
|
|
|
|
i(ft, "drawBezier");
|
|
|
|
function tn(n) {
|
|
|
|
if (!n.p1 || !n.p2 || !n.p3)
|
|
|
|
throw new Error(
|
|
|
|
'drawTriangle() requires properties "p1", "p2" and "p3".'
|
|
|
|
);
|
|
|
|
return Et(Object.assign({}, n, { pts: [n.p1, n.p2, n.p3] }));
|
|
|
|
}
|
|
|
|
i(tn, "drawTriangle");
|
|
|
|
function Xe(n) {
|
|
|
|
if (typeof n.radius != "number")
|
|
|
|
throw new Error('drawCircle() requires property "radius".');
|
|
|
|
n.radius !== 0 &&
|
|
|
|
Tt(
|
|
|
|
Object.assign({}, n, {
|
|
|
|
radiusX: n.radius,
|
|
|
|
radiusY: n.radius,
|
|
|
|
angle: 0,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
i(Xe, "drawCircle");
|
|
|
|
function Tt(n) {
|
|
|
|
if (n.radiusX === void 0 || n.radiusY === void 0)
|
|
|
|
throw new Error(
|
|
|
|
'drawEllipse() requires properties "radiusX" and "radiusY".'
|
|
|
|
);
|
|
|
|
if (n.radiusX === 0 || n.radiusY === 0) return;
|
|
|
|
let o = n.start ?? 0,
|
|
|
|
c = n.end ?? 360,
|
|
|
|
h = ht(n.anchor ?? "center").scale(new T(-n.radiusX, -n.radiusY)),
|
|
|
|
d = at(h, n.radiusX, n.radiusY, o, c, n.resolution);
|
|
|
|
d.unshift(h);
|
|
|
|
let v = Object.assign({}, n, {
|
|
|
|
pts: d,
|
|
|
|
radius: 0,
|
|
|
|
...(n.gradient
|
|
|
|
? {
|
|
|
|
colors: [
|
|
|
|
n.gradient[0],
|
|
|
|
...Array(d.length - 1).fill(n.gradient[1]),
|
|
|
|
],
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
: {}),
|
|
|
|
});
|
|
|
|
if (c - o >= 360 && n.outline) {
|
|
|
|
n.fill !== !1 && Et(Object.assign({}, v, { outline: null })),
|
|
|
|
Et(Object.assign({}, v, { pts: d.slice(1), fill: !1 }));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Et(v);
|
|
|
|
}
|
|
|
|
i(Tt, "drawEllipse");
|
|
|
|
function Et(n) {
|
|
|
|
if (!n.pts) throw new Error('drawPolygon() requires property "pts".');
|
|
|
|
let o = n.pts.length;
|
|
|
|
if (!(o < 3)) {
|
|
|
|
if (
|
|
|
|
(xe(),
|
|
|
|
de(n.pos),
|
|
|
|
he(n.scale),
|
|
|
|
Ke(n.angle),
|
|
|
|
de(n.offset),
|
|
|
|
n.fill !== !1)
|
|
|
|
) {
|
|
|
|
let c = n.color ?? ee.WHITE,
|
|
|
|
h = n.pts.map((v, b) => ({
|
|
|
|
pos: new T(v.x, v.y),
|
|
|
|
uv: n.uv ? n.uv[b] : new T(0, 0),
|
|
|
|
color: n.colors && n.colors[b] ? n.colors[b].mult(c) : c,
|
|
|
|
opacity: n.opacity ?? 1,
|
|
|
|
})),
|
|
|
|
d;
|
|
|
|
n.triangulate && or(n.pts)
|
|
|
|
? (d = rr(n.pts)
|
|
|
|
.map((b) => b.map((D) => n.pts.indexOf(D)))
|
|
|
|
.flat())
|
|
|
|
: (d = [...Array(o - 2).keys()]
|
|
|
|
.map((v) => [0, v + 1, v + 2])
|
|
|
|
.flat()),
|
|
|
|
st(
|
|
|
|
h,
|
|
|
|
n.indices ?? d,
|
|
|
|
n.fixed,
|
|
|
|
n.uv ? n.tex : w.defTex,
|
|
|
|
n.shader,
|
|
|
|
n.uniform
|
|
|
|
);
|
|
|
|
}
|
|
|
|
n.outline &&
|
|
|
|
ie({
|
|
|
|
pts: [...n.pts, n.pts[0]],
|
|
|
|
radius: n.radius,
|
|
|
|
width: n.outline.width,
|
|
|
|
color: n.outline.color,
|
|
|
|
join: n.outline.join,
|
|
|
|
uniform: n.uniform,
|
|
|
|
fixed: n.fixed,
|
|
|
|
opacity: n.opacity,
|
|
|
|
}),
|
|
|
|
Ae();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i(Et, "drawPolygon");
|
|
|
|
function vr(n, o, c) {
|
|
|
|
Pe(),
|
|
|
|
x.clear(x.STENCIL_BUFFER_BIT),
|
|
|
|
x.enable(x.STENCIL_TEST),
|
|
|
|
x.stencilFunc(x.NEVER, 1, 255),
|
|
|
|
x.stencilOp(x.REPLACE, x.REPLACE, x.REPLACE),
|
|
|
|
o(),
|
|
|
|
Pe(),
|
|
|
|
x.stencilFunc(c, 1, 255),
|
|
|
|
x.stencilOp(x.KEEP, x.KEEP, x.KEEP),
|
|
|
|
n(),
|
|
|
|
Pe(),
|
|
|
|
x.disable(x.STENCIL_TEST);
|
|
|
|
}
|
|
|
|
i(vr, "drawStenciled");
|
|
|
|
function xr(n, o) {
|
|
|
|
vr(n, o, x.EQUAL);
|
|
|
|
}
|
|
|
|
i(xr, "drawMasked");
|
|
|
|
function yr(n, o) {
|
|
|
|
vr(n, o, x.NOTEQUAL);
|
|
|
|
}
|
|
|
|
i(yr, "drawSubtracted");
|
|
|
|
function cs() {
|
|
|
|
return (w.viewport.width + w.viewport.height) / (w.width + w.height);
|
|
|
|
}
|
|
|
|
i(cs, "getViewportScale");
|
|
|
|
function ct(n) {
|
|
|
|
Pe();
|
|
|
|
let o = w.width,
|
|
|
|
c = w.height;
|
|
|
|
(w.width = w.viewport.width),
|
|
|
|
(w.height = w.viewport.height),
|
|
|
|
n(),
|
|
|
|
Pe(),
|
|
|
|
(w.width = o),
|
|
|
|
(w.height = c);
|
|
|
|
}
|
|
|
|
i(ct, "drawUnscaled");
|
|
|
|
function wr(n, o) {
|
|
|
|
o.pos && (n.pos = n.pos.add(o.pos)),
|
|
|
|
o.scale && (n.scale = n.scale.scale(C(o.scale))),
|
|
|
|
o.angle && (n.angle += o.angle),
|
|
|
|
o.color && n.ch.length === 1 && (n.color = n.color.mult(o.color)),
|
|
|
|
o.opacity && (n.opacity *= o.opacity);
|
|
|
|
}
|
|
|
|
i(wr, "applyCharTransform");
|
|
|
|
function us(n) {
|
|
|
|
let o = {},
|
|
|
|
c = n.replace(fr, "$2"),
|
|
|
|
h = 0;
|
|
|
|
for (let d of n.matchAll(fr)) {
|
|
|
|
let v = d.index - h;
|
|
|
|
for (let b = 0; b < d.groups.text.length; b++)
|
|
|
|
o[b + v] = [d.groups.style];
|
|
|
|
h += d[0].length - d.groups.text.length;
|
|
|
|
}
|
|
|
|
return { charStyleMap: o, text: c };
|
|
|
|
}
|
|
|
|
i(us, "compileStyledText");
|
|
|
|
let Bn = {};
|
|
|
|
function St(n) {
|
|
|
|
if (n.text === void 0)
|
|
|
|
throw new Error('formatText() requires property "text".');
|
|
|
|
let o = $t(n.font);
|
|
|
|
if (n.text === "" || o instanceof Re || !o)
|
|
|
|
return { width: 0, height: 0, chars: [], opt: n };
|
|
|
|
let { charStyleMap: c, text: h } = us(n.text + ""),
|
|
|
|
d = io(h);
|
|
|
|
if (o instanceof ce || typeof o == "string") {
|
|
|
|
let Z = o instanceof ce ? o.fontface.family : o,
|
|
|
|
ne =
|
|
|
|
o instanceof ce
|
|
|
|
? { outline: o.outline, filter: o.filter }
|
|
|
|
: { outline: null, filter: fn },
|
|
|
|
q = Bn[Z] ?? {
|
|
|
|
font: {
|
|
|
|
tex: new qe(P, 2048, 2048, { filter: ne.filter }),
|
|
|
|
map: {},
|
|
|
|
size: 64,
|
|
|
|
},
|
|
|
|
cursor: new T(0),
|
|
|
|
outline: ne.outline,
|
|
|
|
};
|
|
|
|
Bn[Z] || (Bn[Z] = q), (o = q.font);
|
|
|
|
for (let Me of d)
|
|
|
|
if (!q.font.map[Me]) {
|
|
|
|
let E = y;
|
|
|
|
E.clearRect(0, 0, f.width, f.height),
|
|
|
|
(E.font = `${o.size}px ${Z}`),
|
|
|
|
(E.textBaseline = "top"),
|
|
|
|
(E.textAlign = "left"),
|
|
|
|
(E.fillStyle = "#ffffff");
|
|
|
|
let j = E.measureText(Me),
|
|
|
|
F = Math.ceil(j.width);
|
|
|
|
if (!F) continue;
|
|
|
|
let H = o.size;
|
|
|
|
q.outline &&
|
|
|
|
((E.lineJoin = "round"),
|
|
|
|
(E.lineWidth = q.outline.width * 2),
|
|
|
|
(E.strokeStyle = q.outline.color.toHex()),
|
|
|
|
E.strokeText(Me, q.outline.width, q.outline.width),
|
|
|
|
(F += q.outline.width * 2),
|
|
|
|
(H += q.outline.width * 3)),
|
|
|
|
E.fillText(Me, q.outline?.width ?? 0, q.outline?.width ?? 0);
|
|
|
|
let W = E.getImageData(0, 0, F, H);
|
|
|
|
if (
|
|
|
|
q.cursor.x + F > 2048 &&
|
|
|
|
((q.cursor.x = 0), (q.cursor.y += H), q.cursor.y > 2048)
|
|
|
|
)
|
|
|
|
throw new Error("Font atlas exceeds character limit");
|
|
|
|
o.tex.update(W, q.cursor.x, q.cursor.y),
|
|
|
|
(o.map[Me] = new me(q.cursor.x, q.cursor.y, F, H)),
|
|
|
|
(q.cursor.x += F);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let v = n.size || o.size,
|
|
|
|
b = C(n.scale ?? 1).scale(v / o.size),
|
|
|
|
D = n.lineSpacing ?? 0,
|
|
|
|
R = n.letterSpacing ?? 0,
|
|
|
|
g = 0,
|
|
|
|
A = 0,
|
|
|
|
k = 0,
|
|
|
|
U = [],
|
|
|
|
B = [],
|
|
|
|
M = 0,
|
|
|
|
G = null,
|
|
|
|
I = null;
|
|
|
|
for (; M < d.length; ) {
|
|
|
|
let Z = d[M];
|
|
|
|
if (
|
|
|
|
Z ===
|
|
|
|
`
|
|
|
|
`
|
|
|
|
)
|
|
|
|
(k += v + D),
|
|
|
|
U.push({ width: g - R, chars: B }),
|
|
|
|
(G = null),
|
|
|
|
(I = null),
|
|
|
|
(g = 0),
|
|
|
|
(B = []);
|
|
|
|
else {
|
|
|
|
let ne = o.map[Z];
|
|
|
|
if (ne) {
|
|
|
|
let q = ne.w * b.x;
|
|
|
|
n.width &&
|
|
|
|
g + q > n.width &&
|
|
|
|
((k += v + D),
|
|
|
|
G != null &&
|
|
|
|
((M -= B.length - G),
|
|
|
|
(Z = d[M]),
|
|
|
|
(ne = o.map[Z]),
|
|
|
|
(q = ne.w * b.x),
|
|
|
|
(B = B.slice(0, G - 1)),
|
|
|
|
(g = I)),
|
|
|
|
(G = null),
|
|
|
|
(I = null),
|
|
|
|
U.push({ width: g - R, chars: B }),
|
|
|
|
(g = 0),
|
|
|
|
(B = [])),
|
|
|
|
B.push({
|
|
|
|
tex: o.tex,
|
|
|
|
width: ne.w,
|
|
|
|
height: ne.h,
|
|
|
|
quad: new me(
|
|
|
|
ne.x / o.tex.width,
|
|
|
|
ne.y / o.tex.height,
|
|
|
|
ne.w / o.tex.width,
|
|
|
|
ne.h / o.tex.height
|
|
|
|
),
|
|
|
|
ch: Z,
|
|
|
|
pos: new T(g, k),
|
|
|
|
opacity: n.opacity ?? 1,
|
|
|
|
color: n.color ?? ee.WHITE,
|
|
|
|
scale: C(b),
|
|
|
|
angle: 0,
|
|
|
|
}),
|
|
|
|
Z === " " && ((G = B.length), (I = g)),
|
|
|
|
(g += q),
|
|
|
|
(A = Math.max(A, g)),
|
|
|
|
(g += R);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
M++;
|
|
|
|
}
|
|
|
|
U.push({ width: g - R, chars: B }), (k += v), n.width && (A = n.width);
|
|
|
|
let te = [];
|
|
|
|
for (let Z = 0; Z < U.length; Z++) {
|
|
|
|
let ne = (A - U[Z].width) * ra(n.align ?? "left");
|
|
|
|
for (let q of U[Z].chars) {
|
|
|
|
let Me = o.map[q.ch],
|
|
|
|
E = te.length + Z;
|
|
|
|
if (
|
|
|
|
((q.pos = q.pos
|
|
|
|
.add(ne, 0)
|
|
|
|
.add(Me.w * b.x * 0.5, Me.h * b.y * 0.5)),
|
|
|
|
n.transform)
|
|
|
|
) {
|
|
|
|
let j =
|
|
|
|
typeof n.transform == "function"
|
|
|
|
? n.transform(E, q.ch)
|
|
|
|
: n.transform;
|
|
|
|
j && wr(q, j);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
if (c[E]) {
|
|
|
|
let j = c[E];
|
|
|
|
for (let F of j) {
|
|
|
|
let H = n.styles[F],
|
|
|
|
W = typeof H == "function" ? H(E, q.ch) : H;
|
|
|
|
W && wr(q, W);
|
|
|
|
}
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
te.push(q);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return { width: A, height: k, chars: te, opt: n };
|
|
|
|
}
|
|
|
|
i(St, "formatText");
|
|
|
|
function Cr(n) {
|
|
|
|
At(St(n));
|
|
|
|
}
|
|
|
|
i(Cr, "drawText");
|
|
|
|
function At(n) {
|
|
|
|
xe(),
|
|
|
|
de(n.opt.pos),
|
|
|
|
Ke(n.opt.angle),
|
|
|
|
de(
|
|
|
|
ht(n.opt.anchor ?? "topleft")
|
|
|
|
.add(1, 1)
|
|
|
|
.scale(n.width, n.height)
|
|
|
|
.scale(-0.5)
|
|
|
|
),
|
|
|
|
n.chars.forEach((o) => {
|
|
|
|
it({
|
|
|
|
tex: o.tex,
|
|
|
|
width: o.width,
|
|
|
|
height: o.height,
|
|
|
|
pos: o.pos,
|
|
|
|
scale: o.scale,
|
|
|
|
angle: o.angle,
|
|
|
|
color: o.color,
|
|
|
|
opacity: o.opacity,
|
|
|
|
quad: o.quad,
|
|
|
|
anchor: "center",
|
|
|
|
uniform: n.opt.uniform,
|
|
|
|
shader: n.opt.shader,
|
|
|
|
fixed: n.opt.fixed,
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
Ae();
|
|
|
|
}
|
|
|
|
i(At, "drawFormattedText");
|
|
|
|
function De() {
|
|
|
|
return w.width;
|
|
|
|
}
|
|
|
|
i(De, "width");
|
|
|
|
function ke() {
|
|
|
|
return w.height;
|
|
|
|
}
|
|
|
|
i(ke, "height");
|
|
|
|
function ls(n) {
|
|
|
|
return new T(
|
|
|
|
((n.x - w.viewport.x) * De()) / w.viewport.width,
|
|
|
|
((n.y - w.viewport.y) * ke()) / w.viewport.height
|
|
|
|
);
|
|
|
|
}
|
|
|
|
i(ls, "windowToContent");
|
|
|
|
function ms(n) {
|
|
|
|
return new T(
|
|
|
|
(n.x * w.viewport.width) / w.width,
|
|
|
|
(n.y * w.viewport.height) / w.height
|
|
|
|
);
|
|
|
|
}
|
|
|
|
i(ms, "contentToView");
|
|
|
|
function Tr() {
|
|
|
|
return ls(m.mousePos());
|
|
|
|
}
|
|
|
|
i(Tr, "mousePos");
|
|
|
|
let Er = !1,
|
|
|
|
le = {
|
|
|
|
inspect: !1,
|
|
|
|
timeScale: 1,
|
|
|
|
showLog: !0,
|
|
|
|
fps: () => m.fps(),
|
|
|
|
numFrames: () => m.numFrames(),
|
|
|
|
stepFrame: Pr,
|
|
|
|
drawCalls: () => w.lastDrawCalls,
|
|
|
|
clearLog: () => (O.logs = []),
|
|
|
|
log: (n) => {
|
|
|
|
let o = t.logMax ?? 8;
|
|
|
|
O.logs.unshift({ msg: n, time: m.time() }),
|
|
|
|
O.logs.length > o && (O.logs = O.logs.slice(0, o));
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
error: (n) => le.log(new Error(n.toString ? n.toString() : n)),
|
|
|
|
curRecording: null,
|
|
|
|
numObjects: () => kn("*", { recursive: !0 }).length,
|
|
|
|
get paused() {
|
|
|
|
return Er;
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
set paused(n) {
|
|
|
|
(Er = n), n ? z.ctx.suspend() : z.ctx.resume();
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
};
|
|
|
|
function Fn() {
|
|
|
|
return m.dt() * le.timeScale;
|
|
|
|
}
|
|
|
|
i(Fn, "dt");
|
|
|
|
function ds(...n) {
|
|
|
|
return (
|
|
|
|
n.length > 0 && (O.cam.pos = C(...n)),
|
|
|
|
O.cam.pos ? O.cam.pos.clone() : rn()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
i(ds, "camPos");
|
|
|
|
function hs(...n) {
|
|
|
|
return n.length > 0 && (O.cam.scale = C(...n)), O.cam.scale.clone();
|
|
|
|
}
|
|
|
|
i(hs, "camScale");
|
|
|
|
function ps(n) {
|
|
|
|
return n !== void 0 && (O.cam.angle = n), O.cam.angle;
|
|
|
|
}
|
|
|
|
i(ps, "camRot");
|
|
|
|
function fs(n = 12) {
|
|
|
|
O.cam.shake += n;
|
|
|
|
}
|
|
|
|
i(fs, "shake");
|
|
|
|
function gs(n) {
|
|
|
|
return O.cam.transform.multVec2(n);
|
|
|
|
}
|
|
|
|
i(gs, "toScreen");
|
|
|
|
function bs(n) {
|
|
|
|
return O.cam.transform.invert().multVec2(n);
|
|
|
|
}
|
|
|
|
i(bs, "toWorld");
|
|
|
|
function Sr(n) {
|
|
|
|
let o = new Ge();
|
|
|
|
return (
|
|
|
|
n.pos && o.translate(n.pos),
|
|
|
|
n.scale && o.scale(n.scale),
|
|
|
|
n.angle && o.rotate(n.angle),
|
|
|
|
n.parent ? o.mult(n.parent.transform) : o
|
|
|
|
);
|
|
|
|
}
|
|
|
|
i(Sr, "calcTransform");
|
|
|
|
function In(n = []) {
|
|
|
|
let o = new Map(),
|
|
|
|
c = {},
|
|
|
|
h = new tt(),
|
|
|
|
d = [],
|
|
|
|
v = null,
|
|
|
|
b = !1,
|
|
|
|
D = {
|
|
|
|
id: oo(),
|
|
|
|
hidden: !1,
|
|
|
|
transform: new Ge(),
|
|
|
|
children: [],
|
|
|
|
parent: null,
|
|
|
|
set paused(g) {
|
|
|
|
if (g !== b) {
|
|
|
|
b = g;
|
|
|
|
for (let A of d) A.paused = g;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
get paused() {
|
|
|
|
return b;
|
|
|
|
},
|
|
|
|
add(g = []) {
|
|
|
|
let A = Array.isArray(g) ? In(g) : g;
|
|
|
|
if (A.parent)
|
|
|
|
throw new Error(
|
|
|
|
"Cannot add a game obj that already has a parent."
|
|
|
|
);
|
|
|
|
return (
|
|
|
|
(A.parent = this),
|
|
|
|
(A.transform = Sr(A)),
|
|
|
|
this.children.push(A),
|
|
|
|
A.trigger("add", A),
|
|
|
|
O.events.trigger("add", A),
|
|
|
|
A
|
|
|
|
);
|
|
|
|
},
|
|
|
|
readd(g) {
|
|
|
|
let A = this.children.indexOf(g);
|
|
|
|
return (
|
|
|
|
A !== -1 && (this.children.splice(A, 1), this.children.push(g)),
|
|
|
|
g
|
|
|
|
);
|
|
|
|
},
|
|
|
|
remove(g) {
|
|
|
|
let A = this.children.indexOf(g);
|
|
|
|
if (A !== -1) {
|
|
|
|
(g.parent = null), this.children.splice(A, 1);
|
|
|
|
let k = i((U) => {
|
|
|
|
U.trigger("destroy"),
|
|
|
|
O.events.trigger("destroy", U),
|
|
|
|
U.children.forEach((B) => k(B));
|
|
|
|
}, "trigger");
|
|
|
|
k(g);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
removeAll(g) {
|
|
|
|
if (g) this.get(g).forEach((A) => this.remove(A));
|
|
|
|
else for (let A of [...this.children]) this.remove(A);
|
|
|
|
},
|
|
|
|
update() {
|
|
|
|
this.paused ||
|
|
|
|
(this.children
|
|
|
|
.sort((g, A) => (g.z ?? 0) - (A.z ?? 0))
|
|
|
|
.forEach((g) => g.update()),
|
|
|
|
this.trigger("update"));
|
|
|
|
},
|
|
|
|
draw() {
|
|
|
|
if (this.hidden) return;
|
|
|
|
this.canvas && (Pe(), this.canvas.bind());
|
|
|
|
let g = w.fixed;
|
|
|
|
this.fixed && (w.fixed = !0),
|
|
|
|
xe(),
|
|
|
|
de(this.pos),
|
|
|
|
he(this.scale),
|
|
|
|
Ke(this.angle);
|
|
|
|
let A = this.children.sort((k, U) => (k.z ?? 0) - (U.z ?? 0));
|
|
|
|
if (this.mask) {
|
|
|
|
let k = { intersect: xr, subtract: yr }[this.mask];
|
|
|
|
if (!k) throw new Error(`Invalid mask func: "${this.mask}"`);
|
|
|
|
k(
|
|
|
|
() => {
|
|
|
|
A.forEach((U) => U.draw());
|
|
|
|
},
|
|
|
|
() => {
|
|
|
|
this.trigger("draw");
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} else this.trigger("draw"), A.forEach((k) => k.draw());
|
|
|
|
Ae(), (w.fixed = g), this.canvas && (Pe(), this.canvas.unbind());
|
|
|
|
},
|
|
|
|
drawInspect() {
|
|
|
|
this.hidden ||
|
|
|
|
(xe(),
|
|
|
|
de(this.pos),
|
|
|
|
he(this.scale),
|
|
|
|
Ke(this.angle),
|
|
|
|
this.children
|
|
|
|
.sort((g, A) => (g.z ?? 0) - (A.z ?? 0))
|
|
|
|
.forEach((g) => g.drawInspect()),
|
|
|
|
this.trigger("drawInspect"),
|
|
|
|
Ae());
|
|
|
|
},
|
|
|
|
use(g) {
|
|
|
|
if (!g) return;
|
|
|
|
if (typeof g == "string") return this.use({ id: g });
|
|
|
|
let A = [];
|
|
|
|
g.id &&
|
|
|
|
(this.unuse(g.id),
|
|
|
|
(c[g.id] = []),
|
|
|
|
(A = c[g.id]),
|
|
|
|
o.set(g.id, g));
|
|
|
|
for (let U in g) {
|
|
|
|
if (bo.has(U)) continue;
|
|
|
|
let B = Object.getOwnPropertyDescriptor(g, U);
|
|
|
|
if (
|
|
|
|
(typeof B.value == "function" && (g[U] = g[U].bind(this)),
|
|
|
|
B.set &&
|
|
|
|
Object.defineProperty(g, U, { set: B.set.bind(this) }),
|
|
|
|
B.get &&
|
|
|
|
Object.defineProperty(g, U, { get: B.get.bind(this) }),
|
|
|
|
vo.has(U))
|
|
|
|
) {
|
|
|
|
let M =
|
|
|
|
U === "add"
|
|
|
|
? () => {
|
|
|
|
(v = i((G) => A.push(G), "onCurCompCleanup")),
|
|
|
|
g[U](),
|
|
|
|
(v = null);
|
|
|
|
}
|
|
|
|
: g[U];
|
|
|
|
A.push(this.on(U, M).cancel);
|
|
|
|
} else if (this[U] === void 0)
|
|
|
|
Object.defineProperty(this, U, {
|
|
|
|
get: () => g[U],
|
|
|
|
set: (M) => (g[U] = M),
|
|
|
|
configurable: !0,
|
|
|
|
enumerable: !0,
|
|
|
|
}),
|
|
|
|
A.push(() => delete this[U]);
|
|
|
|
else throw new Error(`Duplicate component property: "${U}"`);
|
|
|
|
}
|
|
|
|
let k = i(() => {
|
|
|
|
if (g.require) {
|
|
|
|
for (let U of g.require)
|
|
|
|
if (!this.c(U))
|
|
|
|
throw new Error(
|
|
|
|
`Component "${g.id}" requires component "${U}"`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}, "checkDeps");
|
|
|
|
g.destroy && A.push(g.destroy.bind(this)),
|
|
|
|
this.exists()
|
|
|
|
? (k(),
|
|
|
|
g.add &&
|
|
|
|
((v = i((U) => A.push(U), "onCurCompCleanup")),
|
|
|
|
g.add.call(this),
|
|
|
|
(v = null)))
|
|
|
|
: g.require && A.push(this.on("add", k).cancel);
|
|
|
|
},
|
|
|
|
unuse(g) {
|
|
|
|
c[g] && (c[g].forEach((A) => A()), delete c[g]),
|
|
|
|
o.has(g) && o.delete(g);
|
|
|
|
},
|
|
|
|
c(g) {
|
|
|
|
return o.get(g);
|
|
|
|
},
|
|
|
|
get(g, A = {}) {
|
|
|
|
let k = A.recursive
|
|
|
|
? this.children.flatMap(
|
|
|
|
i(function U(B) {
|
|
|
|
return [B, ...B.children.flatMap(U)];
|
|
|
|
}, "recurse")
|
|
|
|
)
|
|
|
|
: this.children;
|
|
|
|
if (((k = k.filter((U) => (g ? U.is(g) : !0))), A.liveUpdate)) {
|
|
|
|
let U = i(
|
|
|
|
(M) =>
|
|
|
|
A.recursive ? this.isAncestorOf(M) : M.parent === this,
|
|
|
|
"isChild"
|
|
|
|
),
|
|
|
|
B = [];
|
|
|
|
B.push(
|
|
|
|
Ln((M) => {
|
|
|
|
U(M) && M.is(g) && k.push(M);
|
|
|
|
})
|
|
|
|
),
|
|
|
|
B.push(
|
|
|
|
Ar((M) => {
|
|
|
|
if (U(M) && M.is(g)) {
|
|
|
|
let G = k.findIndex((I) => I.id === M.id);
|
|
|
|
G !== -1 && k.splice(G, 1);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
),
|
|
|
|
this.onDestroy(() => {
|
|
|
|
for (let M of B) M.cancel();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return k;
|
|
|
|
},
|
|
|
|
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 A of g) if (!this.c(A)) return !1;
|
|
|
|
return !0;
|
|
|
|
} else return this.c(g) != null;
|
|
|
|
},
|
|
|
|
on(g, A) {
|
|
|
|
let k = h.on(g, A.bind(this));
|
|
|
|
return v && v(() => k.cancel()), k;
|
|
|
|
},
|
|
|
|
trigger(g, ...A) {
|
|
|
|
h.trigger(g, ...A), O.objEvents.trigger(g, this, ...A);
|
|
|
|
},
|
|
|
|
destroy() {
|
|
|
|
this.parent && this.parent.remove(this);
|
|
|
|
},
|
|
|
|
inspect() {
|
|
|
|
let g = {};
|
|
|
|
for (let [A, k] of o) g[A] = k.inspect ? k.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);
|
|
|
|
},
|
|
|
|
onDestroy(g) {
|
|
|
|
return this.on("destroy", g);
|
|
|
|
},
|
|
|
|
clearEvents() {
|
|
|
|
h.clear();
|
|
|
|
},
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
R = [
|
|
|
|
"onKeyPress",
|
|
|
|
"onKeyPressRepeat",
|
|
|
|
"onKeyDown",
|
|
|
|
"onKeyRelease",
|
|
|
|
"onMousePress",
|
|
|
|
"onMouseDown",
|
|
|
|
"onMouseRelease",
|
|
|
|
"onMouseMove",
|
|
|
|
"onCharInput",
|
|
|
|
"onMouseMove",
|
|
|
|
"onTouchStart",
|
|
|
|
"onTouchMove",
|
|
|
|
"onTouchEnd",
|
|
|
|
"onScroll",
|
|
|
|
"onGamepadButtonPress",
|
|
|
|
"onGamepadButtonDown",
|
|
|
|
"onGamepadButtonRelease",
|
|
|
|
"onGamepadStick",
|
|
|
|
];
|
|
|
|
for (let g of R)
|
|
|
|
D[g] = (...A) => {
|
|
|
|
let k = m[g](...A);
|
|
|
|
return d.push(k), D.onDestroy(() => k.cancel()), k;
|
|
|
|
};
|
|
|
|
for (let g of n) D.use(g);
|
|
|
|
return D;
|
|
|
|
}
|
|
|
|
i(In, "make");
|
|
|
|
function ut(n, o, c) {
|
|
|
|
return (
|
|
|
|
O.objEvents[n] || (O.objEvents[n] = new kt()),
|
|
|
|
O.objEvents.on(n, (h, ...d) => {
|
|
|
|
h.is(o) && c(h, ...d);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
i(ut, "on");
|
|
|
|
let vs = Ie(
|
|
|
|
(n) => {
|
|
|
|
let o = Bt([{ update: n }]);
|
|
|
|
return {
|
|
|
|
get paused() {
|
|
|
|
return o.paused;
|
|
|
|
},
|
|
|
|
set paused(c) {
|
|
|
|
o.paused = c;
|
|
|
|
},
|
|
|
|
cancel: () => o.destroy(),
|
|
|
|
};
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
(n, o) => ut("update", n, o)
|
|
|
|
),
|
|
|
|
xs = Ie(
|
|
|
|
(n) => {
|
|
|
|
let o = Bt([{ draw: n }]);
|
|
|
|
return {
|
|
|
|
get paused() {
|
|
|
|
return o.hidden;
|
|
|
|
},
|
|
|
|
set paused(c) {
|
|
|
|
o.hidden = c;
|
|
|
|
},
|
|
|
|
cancel: () => o.destroy(),
|
|
|
|
};
|
2024-06-01 06:31:08 +00:00
|
|
|
},
|
2024-06-02 05:39:23 +00:00
|
|
|
(n, o) => ut("draw", n, o)
|
|
|
|
),
|
|
|
|
Ln = Ie(
|
|
|
|
(n) => O.events.on("add", n),
|
|
|
|
(n, o) => ut("add", n, o)
|
|
|
|
),
|
|
|
|
Ar = Ie(
|
|
|
|
(n) => O.events.on("destroy", n),
|
|
|
|
(n, o) => ut("destroy", n, o)
|
|
|
|
);
|
|
|
|
function ys(n, o, c) {
|
|
|
|
return ut("collide", n, (h, d, v) => d.is(o) && c(h, d, v));
|
|
|
|
}
|
|
|
|
i(ys, "onCollide");
|
|
|
|
function ws(n, o, c) {
|
|
|
|
return ut("collideUpdate", n, (h, d, v) => d.is(o) && c(h, d, v));
|
|
|
|
}
|
|
|
|
i(ws, "onCollideUpdate");
|
|
|
|
function Cs(n, o, c) {
|
|
|
|
return ut("collideEnd", n, (h, d, v) => d.is(o) && c(h, d, v));
|
|
|
|
}
|
|
|
|
i(Cs, "onCollideEnd");
|
|
|
|
function nn(n, o) {
|
|
|
|
kn(n, { recursive: !0 }).forEach(o), Ln(n, o);
|
|
|
|
}
|
|
|
|
i(nn, "forAllCurrentAndFuture");
|
|
|
|
let Ts = Ie(
|
|
|
|
(n) => m.onMousePress(n),
|
|
|
|
(n, o) => {
|
|
|
|
let c = [];
|
|
|
|
return (
|
|
|
|
nn(n, (h) => {
|
|
|
|
if (!h.area)
|
|
|
|
throw new Error(
|
|
|
|
"onClick() requires the object to have area() component"
|
|
|
|
);
|
|
|
|
c.push(h.onClick(() => o(h)));
|
|
|
|
}),
|
|
|
|
et.join(c)
|
|
|
|
);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
);
|
2024-06-02 05:39:23 +00:00
|
|
|
function Es(n, o) {
|
|
|
|
let c = [];
|
|
|
|
return (
|
|
|
|
nn(n, (h) => {
|
|
|
|
if (!h.area)
|
|
|
|
throw new Error(
|
|
|
|
"onHover() requires the object to have area() component"
|
|
|
|
);
|
|
|
|
c.push(h.onHover(() => o(h)));
|
|
|
|
}),
|
|
|
|
et.join(c)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
i(Es, "onHover");
|
|
|
|
function Ss(n, o) {
|
|
|
|
let c = [];
|
|
|
|
return (
|
|
|
|
nn(n, (h) => {
|
|
|
|
if (!h.area)
|
|
|
|
throw new Error(
|
|
|
|
"onHoverUpdate() requires the object to have area() component"
|
|
|
|
);
|
|
|
|
c.push(h.onHoverUpdate(() => o(h)));
|
|
|
|
}),
|
|
|
|
et.join(c)
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Ss, "onHoverUpdate");
|
|
|
|
function As(n, o) {
|
|
|
|
let c = [];
|
|
|
|
return (
|
|
|
|
nn(n, (h) => {
|
|
|
|
if (!h.area)
|
|
|
|
throw new Error(
|
|
|
|
"onHoverEnd() requires the object to have area() component"
|
|
|
|
);
|
|
|
|
c.push(h.onHoverEnd(() => o(h)));
|
|
|
|
}),
|
|
|
|
et.join(c)
|
|
|
|
);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(As, "onHoverEnd");
|
|
|
|
function Os(n) {
|
|
|
|
O.gravity = n ? (O.gravity || C(0, 1)).unit().scale(n) : null;
|
|
|
|
}
|
|
|
|
i(Os, "setGravity");
|
|
|
|
function Rs() {
|
|
|
|
return O.gravity ? O.gravity.len() : 0;
|
|
|
|
}
|
|
|
|
i(Rs, "getGravity");
|
|
|
|
function Us(n) {
|
|
|
|
O.gravity = n.unit().scale(O.gravity ? O.gravity.len() : 1);
|
|
|
|
}
|
|
|
|
i(Us, "setGravityDirection");
|
|
|
|
function Vs() {
|
|
|
|
return O.gravity ? O.gravity.unit() : C(0, 1);
|
|
|
|
}
|
|
|
|
i(Vs, "getGravityDirection");
|
|
|
|
function Ps(...n) {
|
|
|
|
n.length === 1 || n.length === 2
|
|
|
|
? ((w.bgColor = oe(n[0])), n[1] && (w.bgAlpha = n[1]))
|
|
|
|
: (n.length === 3 || n.length === 4) &&
|
|
|
|
((w.bgColor = oe(n[0], n[1], n[2])), n[3] && (w.bgAlpha = n[3])),
|
|
|
|
x.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-02 05:39:23 +00:00
|
|
|
i(Ps, "setBackground");
|
|
|
|
function Ds() {
|
|
|
|
return w.bgColor.clone();
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Ds, "getBackground");
|
|
|
|
function Ms(...n) {
|
|
|
|
return {
|
|
|
|
id: "color",
|
|
|
|
color: oe(...n),
|
|
|
|
inspect() {
|
|
|
|
return this.color.toString();
|
|
|
|
},
|
|
|
|
};
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Ms, "color");
|
|
|
|
function jn(n, o) {
|
|
|
|
return Number(n.toFixed(o));
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(jn, "toFixed");
|
|
|
|
function Or(n) {
|
|
|
|
return n.fixed ? !0 : n.parent ? Or(n.parent) : !1;
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(Or, "isFixed");
|
|
|
|
function Gs(n) {
|
|
|
|
return {
|
|
|
|
color: n.color,
|
|
|
|
opacity: n.opacity,
|
|
|
|
anchor: n.anchor,
|
|
|
|
outline: n.outline,
|
|
|
|
shader: n.shader,
|
|
|
|
uniform: n.uniform,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
i(Gs, "getRenderProps");
|
|
|
|
function Bs(n) {
|
|
|
|
N.loaded ? n() : O.events.on("load", n);
|
|
|
|
}
|
|
|
|
i(Bs, "onLoad");
|
|
|
|
function Fs(n, o) {
|
|
|
|
O.scenes[n] = o;
|
|
|
|
}
|
|
|
|
i(Fs, "scene");
|
|
|
|
function Is(n, ...o) {
|
|
|
|
if (!O.scenes[n]) throw new Error(`Scene not found: ${n}`);
|
|
|
|
O.events.onOnce("frameEnd", () => {
|
|
|
|
O.events.trigger("sceneLeave", n),
|
|
|
|
m.events.clear(),
|
|
|
|
O.events.clear(),
|
|
|
|
O.objEvents.clear(),
|
|
|
|
[...O.root.children].forEach((c) => {
|
|
|
|
(!c.stay || (c.scenesToStay && !c.scenesToStay.includes(n))) &&
|
|
|
|
O.root.remove(c);
|
|
|
|
}),
|
|
|
|
O.root.clearEvents(),
|
|
|
|
Gr(),
|
|
|
|
(O.cam = {
|
|
|
|
pos: null,
|
|
|
|
scale: C(1),
|
|
|
|
angle: 0,
|
|
|
|
shake: 0,
|
|
|
|
transform: new Ge(),
|
|
|
|
}),
|
|
|
|
O.scenes[n](...o);
|
|
|
|
}),
|
|
|
|
(O.currentScene = n);
|
|
|
|
}
|
|
|
|
i(Is, "go");
|
|
|
|
function Ls(n) {
|
|
|
|
return O.events.on("sceneLeave", n);
|
|
|
|
}
|
|
|
|
i(Ls, "onSceneLeave");
|
|
|
|
function js() {
|
|
|
|
return O.currentScene;
|
|
|
|
}
|
|
|
|
i(js, "getSceneName");
|
|
|
|
function ks(n, o) {
|
|
|
|
try {
|
|
|
|
return JSON.parse(window.localStorage[n]);
|
|
|
|
} catch {
|
|
|
|
return o ? (Rr(n, o), o) : null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i(ks, "getData");
|
|
|
|
function Rr(n, o) {
|
|
|
|
window.localStorage[n] = JSON.stringify(o);
|
|
|
|
}
|
|
|
|
i(Rr, "setData");
|
|
|
|
function Ur(n, ...o) {
|
|
|
|
let c = n($e),
|
|
|
|
h;
|
|
|
|
typeof c == "function" ? (h = c(...o)($e)) : (h = c);
|
|
|
|
for (let d in h) ($e[d] = h[d]), t.global !== !1 && (window[d] = h[d]);
|
|
|
|
return $e;
|
|
|
|
}
|
|
|
|
i(Ur, "plug");
|
|
|
|
function rn() {
|
|
|
|
return C(De() / 2, ke() / 2);
|
|
|
|
}
|
|
|
|
i(rn, "center");
|
|
|
|
let Ns;
|
|
|
|
((I) => (
|
|
|
|
(I[(I.None = 0)] = "None"),
|
|
|
|
(I[(I.Left = 1)] = "Left"),
|
|
|
|
(I[(I.Top = 2)] = "Top"),
|
|
|
|
(I[(I.LeftTop = 3)] = "LeftTop"),
|
|
|
|
(I[(I.Right = 4)] = "Right"),
|
|
|
|
(I[(I.Horizontal = 5)] = "Horizontal"),
|
|
|
|
(I[(I.RightTop = 6)] = "RightTop"),
|
|
|
|
(I[(I.HorizontalTop = 7)] = "HorizontalTop"),
|
|
|
|
(I[(I.Bottom = 8)] = "Bottom"),
|
|
|
|
(I[(I.LeftBottom = 9)] = "LeftBottom"),
|
|
|
|
(I[(I.Vertical = 10)] = "Vertical"),
|
|
|
|
(I[(I.LeftVertical = 11)] = "LeftVertical"),
|
|
|
|
(I[(I.RightBottom = 12)] = "RightBottom"),
|
|
|
|
(I[(I.HorizontalBottom = 13)] = "HorizontalBottom"),
|
|
|
|
(I[(I.RightVertical = 14)] = "RightVertical"),
|
|
|
|
(I[(I.All = 15)] = "All")
|
|
|
|
))((Ns ||= {}));
|
|
|
|
function _s(n, o) {
|
|
|
|
if (!o.tileWidth || !o.tileHeight)
|
|
|
|
throw new Error("Must provide tileWidth and tileHeight.");
|
|
|
|
let c = Bt([qt(o.pos ?? C(0))]),
|
|
|
|
h = n.length,
|
|
|
|
d = 0,
|
|
|
|
v = null,
|
|
|
|
b = null,
|
|
|
|
D = null,
|
|
|
|
R = null,
|
|
|
|
g = i((E) => E.x + E.y * d, "tile2Hash"),
|
|
|
|
A = i((E) => C(Math.floor(E % d), Math.floor(E / d)), "hash2Tile"),
|
|
|
|
k = i(() => {
|
|
|
|
v = [];
|
|
|
|
for (let E of c.children) U(E);
|
|
|
|
}, "createSpatialMap"),
|
|
|
|
U = i((E) => {
|
|
|
|
let j = g(E.tilePos);
|
|
|
|
v[j] ? v[j].push(E) : (v[j] = [E]);
|
|
|
|
}, "insertIntoSpatialMap"),
|
|
|
|
B = i((E) => {
|
|
|
|
let j = g(E.tilePos);
|
|
|
|
if (v[j]) {
|
|
|
|
let F = v[j].indexOf(E);
|
|
|
|
F >= 0 && v[j].splice(F, 1);
|
|
|
|
}
|
|
|
|
}, "removeFromSpatialMap"),
|
|
|
|
M = i(() => {
|
|
|
|
let E = !1;
|
|
|
|
for (let j of c.children) {
|
|
|
|
let F = c.pos2Tile(j.pos);
|
|
|
|
(j.tilePos.x != F.x || j.tilePos.y != F.y) &&
|
|
|
|
((E = !0),
|
|
|
|
B(j),
|
|
|
|
(j.tilePos.x = F.x),
|
|
|
|
(j.tilePos.y = F.y),
|
|
|
|
U(j));
|
|
|
|
}
|
|
|
|
E && c.trigger("spatial_map_changed");
|
|
|
|
}, "updateSpatialMap"),
|
|
|
|
G = i(() => {
|
|
|
|
let E = c.getSpatialMap(),
|
|
|
|
j = c.numRows() * c.numColumns();
|
|
|
|
b ? (b.length = j) : (b = new Array(j)), b.fill(1, 0, j);
|
|
|
|
for (let F = 0; F < E.length; F++) {
|
|
|
|
let H = E[F];
|
|
|
|
if (H) {
|
|
|
|
let W = 0;
|
|
|
|
for (let Q of H)
|
|
|
|
if (Q.isObstacle) {
|
|
|
|
W = 1 / 0;
|
|
|
|
break;
|
|
|
|
} else W += Q.cost;
|
|
|
|
b[F] = W || 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, "createCostMap"),
|
|
|
|
I = i(() => {
|
|
|
|
let E = c.getSpatialMap(),
|
|
|
|
j = c.numRows() * c.numColumns();
|
|
|
|
D ? (D.length = j) : (D = new Array(j)), D.fill(15, 0, j);
|
|
|
|
for (let F = 0; F < E.length; F++) {
|
|
|
|
let H = E[F];
|
|
|
|
if (H) {
|
|
|
|
let W = H.length,
|
|
|
|
Q = 15;
|
|
|
|
for (let be = 0; be < W; be++) Q |= H[be].edgeMask;
|
|
|
|
D[F] = Q;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, "createEdgeMap"),
|
|
|
|
te = i(() => {
|
|
|
|
let E = c.numRows() * c.numColumns(),
|
|
|
|
j = i((H, W) => {
|
|
|
|
let Q = [];
|
|
|
|
for (Q.push(H); Q.length > 0; ) {
|
|
|
|
let be = Q.pop();
|
|
|
|
q(be).forEach((Te) => {
|
|
|
|
R[Te] < 0 && ((R[Te] = W), Q.push(Te));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, "traverse");
|
|
|
|
R ? (R.length = E) : (R = new Array(E)), R.fill(-1, 0, E);
|
|
|
|
let F = 0;
|
|
|
|
for (let H = 0; H < b.length; H++) {
|
|
|
|
if (R[H] >= 0) {
|
|
|
|
F++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
j(H, F), F++;
|
|
|
|
}
|
|
|
|
}, "createConnectivityMap"),
|
|
|
|
Z = i((E, j) => b[j], "getCost"),
|
|
|
|
ne = i((E, j) => {
|
|
|
|
let F = A(E),
|
|
|
|
H = A(j);
|
|
|
|
return F.dist(H);
|
|
|
|
}, "getHeuristic"),
|
|
|
|
q = i((E, j) => {
|
|
|
|
let F = [],
|
|
|
|
H = Math.floor(E % d),
|
|
|
|
W = H > 0 && D[E] & 1 && b[E - 1] !== 1 / 0,
|
|
|
|
Q = E >= d && D[E] & 2 && b[E - d] !== 1 / 0,
|
|
|
|
be = H < d - 1 && D[E] & 4 && b[E + 1] !== 1 / 0,
|
|
|
|
Te = E < d * h - d - 1 && D[E] & 8 && b[E + d] !== 1 / 0;
|
|
|
|
return (
|
|
|
|
j
|
|
|
|
? (W &&
|
|
|
|
(Q && F.push(E - d - 1),
|
|
|
|
F.push(E - 1),
|
|
|
|
Te && F.push(E + d - 1)),
|
|
|
|
Q && F.push(E - d),
|
|
|
|
be &&
|
|
|
|
(Q && F.push(E - d + 1),
|
|
|
|
F.push(E + 1),
|
|
|
|
Te && F.push(E + d + 1)),
|
|
|
|
Te && F.push(E + d))
|
|
|
|
: (W && F.push(E - 1),
|
|
|
|
Q && F.push(E - d),
|
|
|
|
be && F.push(E + 1),
|
|
|
|
Te && F.push(E + d)),
|
|
|
|
F
|
|
|
|
);
|
|
|
|
}, "getNeighbours"),
|
|
|
|
Me = {
|
|
|
|
id: "level",
|
|
|
|
tileWidth() {
|
|
|
|
return o.tileWidth;
|
|
|
|
},
|
|
|
|
tileHeight() {
|
|
|
|
return o.tileHeight;
|
|
|
|
},
|
|
|
|
spawn(E, ...j) {
|
|
|
|
let F = C(...j),
|
|
|
|
H = (() => {
|
|
|
|
if (typeof E == "string") {
|
|
|
|
if (o.tiles[E]) {
|
|
|
|
if (typeof o.tiles[E] != "function")
|
|
|
|
throw new Error(
|
|
|
|
"Level symbol def must be a function returning a component list"
|
|
|
|
);
|
|
|
|
return o.tiles[E](F);
|
|
|
|
} else if (o.wildcardTile) return o.wildcardTile(E, F);
|
|
|
|
} else {
|
|
|
|
if (Array.isArray(E)) return E;
|
|
|
|
throw new Error("Expected a symbol or a component list");
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
})();
|
|
|
|
if (!H) return null;
|
|
|
|
let W = !1,
|
|
|
|
Q = !1;
|
|
|
|
for (let Te of H)
|
|
|
|
Te.id === "tile" && (Q = !0), Te.id === "pos" && (W = !0);
|
|
|
|
W || H.push(qt()), Q || H.push(gr());
|
|
|
|
let be = c.add(H);
|
|
|
|
return (
|
|
|
|
W && (be.tilePosOffset = be.pos.clone()),
|
|
|
|
(be.tilePos = F),
|
|
|
|
v &&
|
|
|
|
(U(be),
|
|
|
|
this.trigger("spatial_map_changed"),
|
|
|
|
this.trigger("navigation_map_invalid")),
|
|
|
|
be
|
|
|
|
);
|
|
|
|
},
|
|
|
|
numColumns() {
|
|
|
|
return d;
|
|
|
|
},
|
|
|
|
numRows() {
|
|
|
|
return h;
|
|
|
|
},
|
|
|
|
levelWidth() {
|
|
|
|
return d * this.tileWidth();
|
|
|
|
},
|
|
|
|
levelHeight() {
|
|
|
|
return h * this.tileHeight();
|
|
|
|
},
|
|
|
|
tile2Pos(...E) {
|
|
|
|
return C(...E).scale(this.tileWidth(), this.tileHeight());
|
|
|
|
},
|
|
|
|
pos2Tile(...E) {
|
|
|
|
let j = C(...E);
|
|
|
|
return C(
|
|
|
|
Math.floor(j.x / this.tileWidth()),
|
|
|
|
Math.floor(j.y / this.tileHeight())
|
|
|
|
);
|
|
|
|
},
|
|
|
|
getSpatialMap() {
|
|
|
|
return v || k(), v;
|
|
|
|
},
|
|
|
|
onSpatialMapChanged(E) {
|
|
|
|
return this.on("spatial_map_changed", E);
|
|
|
|
},
|
|
|
|
onNavigationMapInvalid(E) {
|
|
|
|
return this.on("navigation_map_invalid", E);
|
|
|
|
},
|
|
|
|
getAt(E) {
|
|
|
|
v || k();
|
|
|
|
let j = g(E);
|
|
|
|
return v[j] || [];
|
|
|
|
},
|
|
|
|
raycast(E, j) {
|
|
|
|
E = E.scale(1 / this.tileWidth(), 1 / this.tileHeight());
|
|
|
|
let F = Qr(
|
|
|
|
E,
|
|
|
|
j,
|
|
|
|
(H) => {
|
|
|
|
if (this.getAt(H).some((Q) => Q.isObstacle)) return !0;
|
|
|
|
},
|
|
|
|
64
|
|
|
|
);
|
|
|
|
return (
|
|
|
|
F &&
|
|
|
|
(F.point = F.point.scale(
|
|
|
|
this.tileWidth(),
|
|
|
|
this.tileHeight()
|
|
|
|
)),
|
|
|
|
F
|
|
|
|
);
|
|
|
|
},
|
|
|
|
update() {
|
|
|
|
v && M();
|
|
|
|
},
|
|
|
|
invalidateNavigationMap() {
|
|
|
|
(b = null), (D = null), (R = null);
|
|
|
|
},
|
|
|
|
onNavigationMapChanged(E) {
|
|
|
|
return this.on("navigation_map_changed", E);
|
|
|
|
},
|
|
|
|
getTilePath(E, j, F = {}) {
|
|
|
|
if (
|
|
|
|
(b || G(),
|
|
|
|
D || I(),
|
|
|
|
R || te(),
|
|
|
|
E.x < 0 ||
|
|
|
|
E.x >= d ||
|
|
|
|
E.y < 0 ||
|
|
|
|
E.y >= h ||
|
|
|
|
j.x < 0 ||
|
|
|
|
j.x >= d ||
|
|
|
|
j.y < 0 ||
|
|
|
|
j.y >= h)
|
|
|
|
)
|
|
|
|
return null;
|
|
|
|
let H = g(E),
|
|
|
|
W = g(j);
|
|
|
|
if (b[W] === 1 / 0) return null;
|
|
|
|
if (H === W) return [];
|
|
|
|
if (R[H] != -1 && R[H] !== R[W]) return null;
|
|
|
|
let Q = new ln((Ze, Hn) => Ze.cost < Hn.cost);
|
|
|
|
Q.insert({ cost: 0, node: H });
|
|
|
|
let be = new Map();
|
|
|
|
be.set(H, H);
|
|
|
|
let Te = new Map();
|
|
|
|
for (Te.set(H, 0); Q.length !== 0; ) {
|
|
|
|
let Ze = Q.remove()?.node;
|
|
|
|
if (Ze === W) break;
|
|
|
|
let Hn = q(Ze, F.allowDiagonals);
|
|
|
|
for (let gt of Hn) {
|
|
|
|
let Kn = (Te.get(Ze) || 0) + Z(Ze, gt) + ne(gt, W);
|
|
|
|
(!Te.has(gt) || Kn < Te.get(gt)) &&
|
|
|
|
(Te.set(gt, Kn),
|
|
|
|
Q.insert({ cost: Kn, node: gt }),
|
|
|
|
be.set(gt, Ze));
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
let _n = [],
|
|
|
|
Ft = W,
|
|
|
|
li = A(Ft);
|
|
|
|
for (_n.push(li); Ft !== H; ) {
|
|
|
|
Ft = be.get(Ft);
|
|
|
|
let Ze = A(Ft);
|
|
|
|
_n.push(Ze);
|
|
|
|
}
|
|
|
|
return _n.reverse();
|
|
|
|
},
|
|
|
|
getPath(E, j, F = {}) {
|
|
|
|
let H = this.tileWidth(),
|
|
|
|
W = this.tileHeight(),
|
|
|
|
Q = this.getTilePath(this.pos2Tile(E), this.pos2Tile(j), F);
|
|
|
|
return Q
|
|
|
|
? [
|
|
|
|
E,
|
|
|
|
...Q.slice(1, -1).map((be) =>
|
|
|
|
be.scale(H, W).add(H / 2, W / 2)
|
|
|
|
),
|
|
|
|
j,
|
|
|
|
]
|
|
|
|
: null;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
return (
|
|
|
|
c.use(Me),
|
|
|
|
c.onNavigationMapInvalid(() => {
|
|
|
|
c.invalidateNavigationMap(), c.trigger("navigation_map_changed");
|
|
|
|
}),
|
|
|
|
n.forEach((E, j) => {
|
|
|
|
let F = E.split("");
|
|
|
|
(d = Math.max(F.length, d)),
|
|
|
|
F.forEach((H, W) => {
|
|
|
|
c.spawn(H, C(W, j));
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
c
|
|
|
|
);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(_s, "addLevel");
|
|
|
|
function Hs(n) {
|
|
|
|
let o = m.canvas.captureStream(n),
|
|
|
|
c = z.ctx.createMediaStreamDestination();
|
|
|
|
z.masterNode.connect(c);
|
|
|
|
let h = new MediaRecorder(o),
|
|
|
|
d = [];
|
|
|
|
return (
|
|
|
|
(h.ondataavailable = (v) => {
|
|
|
|
v.data.size > 0 && d.push(v.data);
|
2024-06-01 06:31:08 +00:00
|
|
|
}),
|
2024-06-02 05:39:23 +00:00
|
|
|
(h.onerror = () => {
|
|
|
|
z.masterNode.disconnect(c), o.getTracks().forEach((v) => v.stop());
|
2024-06-01 06:31:08 +00:00
|
|
|
}),
|
2024-06-02 05:39:23 +00:00
|
|
|
h.start(),
|
|
|
|
{
|
|
|
|
resume() {
|
|
|
|
h.resume();
|
|
|
|
},
|
|
|
|
pause() {
|
|
|
|
h.pause();
|
|
|
|
},
|
|
|
|
stop() {
|
|
|
|
return (
|
|
|
|
h.stop(),
|
|
|
|
z.masterNode.disconnect(c),
|
|
|
|
o.getTracks().forEach((v) => v.stop()),
|
|
|
|
new Promise((v) => {
|
|
|
|
h.onstop = () => {
|
|
|
|
v(new Blob(d, { type: "video/mp4" }));
|
|
|
|
};
|
|
|
|
})
|
|
|
|
);
|
|
|
|
},
|
|
|
|
download(v = "kaboom.mp4") {
|
|
|
|
this.stop().then((b) => ir(v, b));
|
|
|
|
},
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
i(Hs, "record");
|
|
|
|
function Ks() {
|
|
|
|
return document.activeElement === m.canvas;
|
|
|
|
}
|
|
|
|
i(Ks, "isFocused");
|
|
|
|
function qs(n) {
|
|
|
|
n.destroy();
|
|
|
|
}
|
|
|
|
i(qs, "destroy");
|
|
|
|
let Bt = O.root.add.bind(O.root),
|
|
|
|
zs = O.root.readd.bind(O.root),
|
|
|
|
Ys = O.root.removeAll.bind(O.root),
|
|
|
|
kn = O.root.get.bind(O.root),
|
|
|
|
Xs = O.root.wait.bind(O.root),
|
|
|
|
Ws = O.root.loop.bind(O.root),
|
|
|
|
$s = O.root.tween.bind(O.root);
|
|
|
|
function Vr(n = 2, o = 1) {
|
|
|
|
let c = 0;
|
|
|
|
return {
|
|
|
|
require: ["scale"],
|
|
|
|
update() {
|
|
|
|
let h = Math.sin(c * n) * o;
|
|
|
|
h < 0 && this.destroy(), (this.scale = C(h)), (c += Fn());
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
i(Vr, "boom");
|
|
|
|
let Qs = Ee(null, es),
|
|
|
|
Js = Ee(null, Jo);
|
|
|
|
function Zs(n, o = {}) {
|
|
|
|
let c = Bt([qt(n), br()]),
|
|
|
|
h = (o.speed || 1) * 5,
|
|
|
|
d = o.scale || 1;
|
|
|
|
c.add([wn(Js), zt(0), Tn("center"), Vr(h, d), ...(o.comps ?? [])]);
|
|
|
|
let v = c.add([wn(Qs), zt(0), Tn("center"), Cn(), ...(o.comps ?? [])]);
|
|
|
|
return (
|
|
|
|
v.wait(0.4 / h, () => v.use(Vr(h, d))),
|
|
|
|
v.onDestroy(() => c.destroy()),
|
|
|
|
c
|
|
|
|
);
|
|
|
|
}
|
|
|
|
i(Zs, "addKaboom");
|
|
|
|
function Pr() {
|
|
|
|
O.root.update();
|
|
|
|
}
|
|
|
|
i(Pr, "updateFrame");
|
|
|
|
class Nn {
|
|
|
|
static {
|
|
|
|
i(this, "Collision");
|
|
|
|
}
|
|
|
|
source;
|
|
|
|
target;
|
|
|
|
displacement;
|
|
|
|
resolved = !1;
|
|
|
|
constructor(o, c, h, d = !1) {
|
|
|
|
(this.source = o),
|
|
|
|
(this.target = c),
|
|
|
|
(this.displacement = h),
|
|
|
|
(this.resolved = d);
|
|
|
|
}
|
|
|
|
reverse() {
|
|
|
|
return new Nn(
|
|
|
|
this.target,
|
|
|
|
this.source,
|
|
|
|
this.displacement.scale(-1),
|
|
|
|
this.resolved
|
2024-06-01 06:31:08 +00:00
|
|
|
);
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
hasOverlap() {
|
|
|
|
return !this.displacement.isZero();
|
|
|
|
}
|
|
|
|
isLeft() {
|
|
|
|
return this.displacement.cross(O.gravity || C(0, 1)) > 0;
|
|
|
|
}
|
|
|
|
isRight() {
|
|
|
|
return this.displacement.cross(O.gravity || C(0, 1)) < 0;
|
|
|
|
}
|
|
|
|
isTop() {
|
|
|
|
return this.displacement.dot(O.gravity || C(0, 1)) > 0;
|
|
|
|
}
|
|
|
|
isBottom() {
|
|
|
|
return this.displacement.dot(O.gravity || C(0, 1)) < 0;
|
|
|
|
}
|
|
|
|
preventResolution() {
|
|
|
|
this.resolved = !0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function ei() {
|
|
|
|
let n = {},
|
|
|
|
o = t.hashGridSize || 64,
|
|
|
|
c = new Ge(),
|
|
|
|
h = [];
|
|
|
|
function d(v) {
|
|
|
|
if (
|
|
|
|
(h.push(c.clone()),
|
|
|
|
v.pos && c.translate(v.pos),
|
|
|
|
v.scale && c.scale(v.scale),
|
|
|
|
v.angle && c.rotate(v.angle),
|
|
|
|
(v.transform = c.clone()),
|
|
|
|
v.c("area") && !v.paused)
|
|
|
|
) {
|
|
|
|
let b = v,
|
|
|
|
R = b.worldArea().bbox(),
|
|
|
|
g = Math.floor(R.pos.x / o),
|
|
|
|
A = Math.floor(R.pos.y / o),
|
|
|
|
k = Math.ceil((R.pos.x + R.width) / o),
|
|
|
|
U = Math.ceil((R.pos.y + R.height) / o),
|
|
|
|
B = new Set();
|
|
|
|
for (let M = g; M <= k; M++)
|
|
|
|
for (let G = A; G <= U; G++)
|
|
|
|
if (!n[M]) (n[M] = {}), (n[M][G] = [b]);
|
|
|
|
else if (!n[M][G]) n[M][G] = [b];
|
|
|
|
else {
|
|
|
|
let I = n[M][G];
|
|
|
|
e: for (let te of I) {
|
|
|
|
if (te.paused || !te.exists() || B.has(te.id)) continue;
|
|
|
|
for (let ne of b.collisionIgnore) if (te.is(ne)) continue e;
|
|
|
|
for (let ne of te.collisionIgnore) if (b.is(ne)) continue e;
|
|
|
|
let Z = Jr(b.worldArea(), te.worldArea());
|
|
|
|
if (Z) {
|
|
|
|
let ne = new Nn(b, te, Z);
|
|
|
|
b.trigger("collideUpdate", te, ne);
|
|
|
|
let q = ne.reverse();
|
|
|
|
(q.resolved = ne.resolved),
|
|
|
|
te.trigger("collideUpdate", b, q);
|
|
|
|
}
|
|
|
|
B.add(te.id);
|
|
|
|
}
|
|
|
|
I.push(b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
v.children.forEach(d), (c = h.pop());
|
|
|
|
}
|
|
|
|
i(d, "checkObj"), d(O.root);
|
|
|
|
}
|
|
|
|
i(ei, "checkFrame");
|
|
|
|
function ti() {
|
|
|
|
let n = O.cam,
|
|
|
|
o = T.fromAngle(Lt(0, 360)).scale(n.shake);
|
|
|
|
(n.shake = Je(n.shake, 0, 5 * Fn())),
|
|
|
|
(n.transform = new Ge()
|
|
|
|
.translate(rn())
|
|
|
|
.scale(n.scale)
|
|
|
|
.rotate(n.angle)
|
|
|
|
.translate((n.pos ?? rn()).scale(-1).add(o))),
|
|
|
|
O.root.draw(),
|
|
|
|
Pe();
|
|
|
|
}
|
|
|
|
i(ti, "drawFrame");
|
|
|
|
function ni() {
|
|
|
|
let n = _();
|
|
|
|
O.events.numListeners("loading") > 0
|
|
|
|
? O.events.trigger("loading", n)
|
|
|
|
: ct(() => {
|
|
|
|
let o = De() / 2,
|
|
|
|
c = 24,
|
|
|
|
h = C(De() / 2, ke() / 2).sub(C(o / 2, c / 2));
|
|
|
|
p({ pos: C(0), width: De(), height: ke(), color: oe(0, 0, 0) }),
|
|
|
|
p({
|
|
|
|
pos: h,
|
|
|
|
width: o,
|
|
|
|
height: c,
|
|
|
|
fill: !1,
|
|
|
|
outline: { width: 4 },
|
|
|
|
}),
|
|
|
|
p({ pos: h, width: o * n, height: c });
|
2024-06-01 06:31:08 +00:00
|
|
|
});
|
2024-06-02 05:39:23 +00:00
|
|
|
}
|
|
|
|
i(ni, "drawLoadScreen");
|
|
|
|
function Dr(n, o) {
|
|
|
|
ct(() => {
|
|
|
|
let c = C(8);
|
|
|
|
xe(), de(n);
|
|
|
|
let h = St({
|
|
|
|
text: o,
|
|
|
|
font: Ht,
|
|
|
|
size: 16,
|
|
|
|
pos: c,
|
|
|
|
color: oe(255, 255, 255),
|
|
|
|
fixed: !0,
|
|
|
|
}),
|
|
|
|
d = h.width + c.x * 2,
|
|
|
|
v = h.height + c.x * 2;
|
|
|
|
n.x + d >= De() && de(C(-d, 0)),
|
|
|
|
n.y + v >= ke() && de(C(0, -v)),
|
|
|
|
p({
|
|
|
|
width: d,
|
|
|
|
height: v,
|
|
|
|
color: oe(0, 0, 0),
|
|
|
|
radius: 4,
|
|
|
|
opacity: 0.8,
|
|
|
|
fixed: !0,
|
|
|
|
}),
|
|
|
|
At(h),
|
|
|
|
Ae();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
i(Dr, "drawInspectText");
|
|
|
|
function ri() {
|
|
|
|
if (le.inspect) {
|
|
|
|
let n = null;
|
|
|
|
for (let o of O.root.get("*", { recursive: !0 }))
|
|
|
|
if (o.c("area") && o.isHovering()) {
|
|
|
|
n = o;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((O.root.drawInspect(), n)) {
|
|
|
|
let o = [],
|
|
|
|
c = n.inspect();
|
|
|
|
for (let h in c) c[h] ? o.push(`${h}: ${c[h]}`) : o.push(`${h}`);
|
|
|
|
Dr(
|
|
|
|
ms(Tr()),
|
|
|
|
o.join(`
|
|
|
|
`)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
Dr(C(8), `FPS: ${le.fps()}`);
|
|
|
|
}
|
|
|
|
le.paused &&
|
|
|
|
ct(() => {
|
|
|
|
xe(), de(De(), 0), de(-8, 8);
|
|
|
|
let n = 32;
|
|
|
|
p({
|
|
|
|
width: n,
|
|
|
|
height: n,
|
|
|
|
anchor: "topright",
|
|
|
|
color: oe(0, 0, 0),
|
2024-06-01 06:31:08 +00:00
|
|
|
opacity: 0.8,
|
|
|
|
radius: 4,
|
|
|
|
fixed: !0,
|
|
|
|
});
|
2024-06-02 05:39:23 +00:00
|
|
|
for (let o = 1; o <= 2; o++)
|
|
|
|
p({
|
|
|
|
width: 4,
|
|
|
|
height: n * 0.6,
|
|
|
|
anchor: "center",
|
|
|
|
pos: C((-n / 3) * o, n * 0.5),
|
|
|
|
color: oe(255, 255, 255),
|
|
|
|
radius: 2,
|
2024-06-01 06:31:08 +00:00
|
|
|
fixed: !0,
|
|
|
|
});
|
2024-06-02 05:39:23 +00:00
|
|
|
Ae();
|
2024-06-01 06:31:08 +00:00
|
|
|
}),
|
2024-06-02 05:39:23 +00:00
|
|
|
le.timeScale !== 1 &&
|
|
|
|
ct(() => {
|
|
|
|
xe(), de(De(), ke()), de(-8, -8);
|
|
|
|
let n = 8,
|
|
|
|
o = St({
|
|
|
|
text: le.timeScale.toFixed(1),
|
|
|
|
font: Ht,
|
|
|
|
size: 16,
|
|
|
|
color: oe(255, 255, 255),
|
|
|
|
pos: C(-n),
|
|
|
|
anchor: "botright",
|
2024-06-01 06:31:08 +00:00
|
|
|
fixed: !0,
|
2024-06-02 05:39:23 +00:00
|
|
|
});
|
|
|
|
p({
|
|
|
|
width: o.width + n * 2 + n * 4,
|
|
|
|
height: o.height + n * 2,
|
|
|
|
anchor: "botright",
|
|
|
|
color: oe(0, 0, 0),
|
|
|
|
opacity: 0.8,
|
|
|
|
radius: 4,
|
2024-06-01 06:31:08 +00:00
|
|
|
fixed: !0,
|
|
|
|
});
|
2024-06-02 05:39:23 +00:00
|
|
|
for (let c = 0; c < 2; c++) {
|
|
|
|
let h = le.timeScale < 1;
|
|
|
|
tn({
|
|
|
|
p1: C(-o.width - n * (h ? 2 : 3.5), -n),
|
|
|
|
p2: C(-o.width - n * (h ? 2 : 3.5), -n - o.height),
|
|
|
|
p3: C(-o.width - n * (h ? 3.5 : 2), -n - o.height / 2),
|
|
|
|
pos: C(-c * n * 1 + (h ? -n * 0.5 : 0), 0),
|
|
|
|
color: oe(255, 255, 255),
|
|
|
|
fixed: !0,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
At(o), Ae();
|
|
|
|
}),
|
|
|
|
le.curRecording &&
|
|
|
|
ct(() => {
|
|
|
|
xe(),
|
|
|
|
de(0, ke()),
|
|
|
|
de(24, -24),
|
|
|
|
Xe({
|
|
|
|
radius: 12,
|
|
|
|
color: oe(255, 0, 0),
|
|
|
|
opacity: Yn(0, 1, m.time() * 4),
|
2024-06-01 06:31:08 +00:00
|
|
|
fixed: !0,
|
|
|
|
}),
|
2024-06-02 05:39:23 +00:00
|
|
|
Ae();
|
2024-06-01 06:31:08 +00:00
|
|
|
}),
|
2024-06-02 05:39:23 +00:00
|
|
|
le.showLog &&
|
|
|
|
O.logs.length > 0 &&
|
|
|
|
ct(() => {
|
|
|
|
xe(), de(0, ke()), de(8, -8);
|
|
|
|
let n = 8,
|
|
|
|
o = [];
|
|
|
|
for (let h of O.logs) {
|
|
|
|
let d = "",
|
|
|
|
v = h.msg instanceof Error ? "error" : "info";
|
|
|
|
(d += `[time]${h.time.toFixed(2)}[/time]`),
|
|
|
|
(d += " "),
|
|
|
|
(d += `[${v}]${
|
|
|
|
h.msg?.toString ? h.msg.toString() : h.msg
|
|
|
|
}[/${v}]`),
|
|
|
|
o.push(d);
|
|
|
|
}
|
|
|
|
O.logs = O.logs.filter(
|
|
|
|
(h) => m.time() - h.time < (t.logTime || 4)
|
|
|
|
);
|
|
|
|
let c = St({
|
|
|
|
text: o.join(`
|
|
|
|
`),
|
|
|
|
font: Ht,
|
|
|
|
pos: C(n, -n),
|
|
|
|
anchor: "botleft",
|
|
|
|
size: 16,
|
|
|
|
width: De() * 0.6,
|
|
|
|
lineSpacing: n / 2,
|
|
|
|
fixed: !0,
|
|
|
|
styles: {
|
|
|
|
time: { color: oe(127, 127, 127) },
|
|
|
|
info: { color: oe(255, 255, 255) },
|
|
|
|
error: { color: oe(255, 0, 127) },
|
|
|
|
},
|
|
|
|
});
|
|
|
|
p({
|
|
|
|
width: c.width + n * 2,
|
|
|
|
height: c.height + n * 2,
|
|
|
|
anchor: "botleft",
|
|
|
|
color: oe(0, 0, 0),
|
|
|
|
radius: 4,
|
|
|
|
opacity: 0.8,
|
|
|
|
fixed: !0,
|
|
|
|
}),
|
|
|
|
At(c),
|
|
|
|
Ae();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
i(ri, "drawDebug");
|
|
|
|
function oi(n) {
|
|
|
|
O.events.on("loading", n);
|
|
|
|
}
|
|
|
|
i(oi, "onLoading");
|
|
|
|
function si(n) {
|
|
|
|
m.onResize(n);
|
|
|
|
}
|
|
|
|
i(si, "onResize");
|
|
|
|
function ii(n) {
|
|
|
|
O.events.on("error", n);
|
|
|
|
}
|
|
|
|
i(ii, "onError");
|
|
|
|
function ai(n) {
|
|
|
|
console.error(n),
|
|
|
|
z.ctx.suspend(),
|
|
|
|
m.run(() => {
|
|
|
|
Ct(),
|
|
|
|
ct(() => {
|
|
|
|
let h = De(),
|
|
|
|
d = ke(),
|
|
|
|
v = {
|
|
|
|
size: 36,
|
|
|
|
width: h - 32 * 2,
|
|
|
|
letterSpacing: 4,
|
|
|
|
lineSpacing: 4,
|
|
|
|
font: Ht,
|
|
|
|
fixed: !0,
|
|
|
|
};
|
|
|
|
p({ width: h, height: d, color: oe(0, 0, 255), fixed: !0 });
|
|
|
|
let b = St({
|
|
|
|
...v,
|
|
|
|
text: "Error",
|
|
|
|
pos: C(32),
|
|
|
|
color: oe(255, 128, 0),
|
|
|
|
fixed: !0,
|
|
|
|
});
|
|
|
|
At(b),
|
|
|
|
Cr({
|
|
|
|
...v,
|
|
|
|
text: n.message,
|
|
|
|
pos: C(32, 32 + b.height + 16),
|
|
|
|
fixed: !0,
|
|
|
|
}),
|
|
|
|
Ae(),
|
|
|
|
O.events.trigger("error", n);
|
|
|
|
}),
|
|
|
|
Mt();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
i(ai, "handleErr");
|
|
|
|
function ci(n) {
|
|
|
|
V.push(n);
|
|
|
|
}
|
|
|
|
i(ci, "onCleanup");
|
|
|
|
function ui() {
|
|
|
|
O.events.onOnce("frameEnd", () => {
|
|
|
|
m.quit(),
|
|
|
|
x.clear(
|
|
|
|
x.COLOR_BUFFER_BIT | x.DEPTH_BUFFER_BIT | x.STENCIL_BUFFER_BIT
|
|
|
|
);
|
|
|
|
let n = x.getParameter(x.MAX_TEXTURE_IMAGE_UNITS);
|
|
|
|
for (let o = 0; o < n; o++)
|
|
|
|
x.activeTexture(x.TEXTURE0 + o),
|
|
|
|
x.bindTexture(x.TEXTURE_2D, null),
|
|
|
|
x.bindTexture(x.TEXTURE_CUBE_MAP, null);
|
|
|
|
x.bindBuffer(x.ARRAY_BUFFER, null),
|
|
|
|
x.bindBuffer(x.ELEMENT_ARRAY_BUFFER, null),
|
|
|
|
x.bindRenderbuffer(x.RENDERBUFFER, null),
|
|
|
|
x.bindFramebuffer(x.FRAMEBUFFER, null),
|
|
|
|
P.destroy(),
|
|
|
|
V.forEach((o) => o());
|
2024-06-01 06:31:08 +00:00
|
|
|
});
|
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
i(ui, "quit");
|
|
|
|
let on = !0;
|
|
|
|
m.run(() => {
|
|
|
|
try {
|
|
|
|
N.loaded ||
|
|
|
|
(_() === 1 && !on && ((N.loaded = !0), O.events.trigger("load"))),
|
|
|
|
(!N.loaded && t.loadingScreen !== !1) || on
|
|
|
|
? (Ct(), ni(), Mt())
|
|
|
|
: (le.paused || Pr(),
|
|
|
|
ei(),
|
|
|
|
Ct(),
|
|
|
|
ti(),
|
|
|
|
t.debug !== !1 && ri(),
|
|
|
|
Mt()),
|
|
|
|
on && (on = !1),
|
|
|
|
O.events.trigger("frameEnd");
|
|
|
|
} catch (n) {
|
|
|
|
ai(n);
|
2024-06-01 06:31:08 +00:00
|
|
|
}
|
2024-06-02 05:39:23 +00:00
|
|
|
});
|
|
|
|
function Mr() {
|
|
|
|
let n = u,
|
|
|
|
o = x.drawingBufferWidth / n,
|
|
|
|
c = x.drawingBufferHeight / n;
|
|
|
|
if (t.letterbox) {
|
|
|
|
if (!t.width || !t.height)
|
|
|
|
throw new Error("Letterboxing requires width and height defined.");
|
|
|
|
let h = o / c,
|
|
|
|
d = t.width / t.height;
|
|
|
|
if (h > d) {
|
|
|
|
let v = c * d,
|
|
|
|
b = (o - v) / 2;
|
|
|
|
w.viewport = { x: b, y: 0, width: v, height: c };
|
|
|
|
} else {
|
|
|
|
let v = o / d,
|
|
|
|
b = (c - v) / 2;
|
|
|
|
w.viewport = { x: 0, y: b, width: o, height: v };
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (t.stretch && (!t.width || !t.height))
|
|
|
|
throw new Error("Stretching requires width and height defined.");
|
|
|
|
w.viewport = { x: 0, y: 0, width: o, height: c };
|
|
|
|
}
|
|
|
|
i(Mr, "updateViewport");
|
|
|
|
function Gr() {
|
|
|
|
m.onHide(() => {
|
|
|
|
t.backgroundAudio || z.ctx.suspend();
|
2024-06-01 06:31:08 +00:00
|
|
|
}),
|
2024-06-02 05:39:23 +00:00
|
|
|
m.onShow(() => {
|
|
|
|
!t.backgroundAudio && !le.paused && z.ctx.resume();
|
2024-06-01 06:31:08 +00:00
|
|
|
}),
|
2024-06-02 05:39:23 +00:00
|
|
|
m.onResize(() => {
|
|
|
|
if (m.isFullscreen()) return;
|
|
|
|
let n = t.width && t.height;
|
|
|
|
(n && !t.stretch && !t.letterbox) ||
|
|
|
|
((r.width = r.offsetWidth * u),
|
|
|
|
(r.height = r.offsetHeight * u),
|
|
|
|
Mr(),
|
|
|
|
n ||
|
|
|
|
(w.frameBuffer.free(),
|
|
|
|
(w.frameBuffer = new yt(
|
|
|
|
P,
|
|
|
|
x.drawingBufferWidth,
|
|
|
|
x.drawingBufferHeight
|
|
|
|
)),
|
|
|
|
(w.width = x.drawingBufferWidth / u / s),
|
|
|
|
(w.height = x.drawingBufferHeight / u / s)));
|
2024-06-01 06:31:08 +00:00
|
|
|
}),
|
2024-06-02 05:39:23 +00:00
|
|
|
t.debug !== !1 &&
|
|
|
|
(m.onKeyPress(t.debugKey ?? "f1", () => (le.inspect = !le.inspect)),
|
|
|
|
m.onKeyPress("f2", () => le.clearLog()),
|
|
|
|
m.onKeyPress("f8", () => (le.paused = !le.paused)),
|
|
|
|
m.onKeyPress("f7", () => {
|
|
|
|
le.timeScale = jn(Qe(le.timeScale - 0.2, 0, 2), 1);
|
|
|
|
}),
|
|
|
|
m.onKeyPress("f9", () => {
|
|
|
|
le.timeScale = jn(Qe(le.timeScale + 0.2, 0, 2), 1);
|
|
|
|
}),
|
|
|
|
m.onKeyPress("f10", () => le.stepFrame())),
|
|
|
|
t.burp && m.onKeyPress("b", () => Jt());
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
(i(Gr, "initEvents"),
|
|
|
|
Mr(),
|
|
|
|
Gr(),
|
|
|
|
($e = {
|
|
|
|
_k: {
|
|
|
|
kaboomCtx: $e,
|
|
|
|
app: m,
|
|
|
|
game: O,
|
|
|
|
isFixed: Or,
|
|
|
|
toFixed: jn,
|
|
|
|
getViewportScale: cs,
|
|
|
|
getRenderProps: Gs,
|
|
|
|
resolveSprite: Wt,
|
|
|
|
drawTexture: Gt,
|
|
|
|
calcTransform: Sr,
|
|
|
|
},
|
|
|
|
VERSION: na,
|
|
|
|
loadRoot: ae,
|
|
|
|
loadProgress: _,
|
|
|
|
loadSprite: Ee,
|
|
|
|
loadSpriteAtlas: Le,
|
|
|
|
loadSound: Se,
|
|
|
|
loadMusic: Ve,
|
|
|
|
loadBitmapFont: Ue,
|
|
|
|
loadFont: ge,
|
|
|
|
loadShader: He,
|
|
|
|
loadShaderURL: pt,
|
|
|
|
loadAseprite: _e,
|
|
|
|
loadPedit: Ne,
|
|
|
|
loadBean: ze,
|
|
|
|
loadJSON: re,
|
|
|
|
load: se,
|
|
|
|
getSprite: rt,
|
|
|
|
getSound: ot,
|
|
|
|
getFont: wt,
|
|
|
|
getBitmapFont: Yt,
|
|
|
|
getShader: Xt,
|
|
|
|
getAsset: An,
|
|
|
|
Asset: Re,
|
|
|
|
SpriteData: K,
|
|
|
|
SoundData: X,
|
|
|
|
width: De,
|
|
|
|
height: ke,
|
|
|
|
center: rn,
|
|
|
|
dt: Fn,
|
|
|
|
time: m.time,
|
|
|
|
screenshot: m.screenshot,
|
|
|
|
record: Hs,
|
|
|
|
isFocused: Ks,
|
|
|
|
setCursor: m.setCursor,
|
|
|
|
getCursor: m.getCursor,
|
|
|
|
setCursorLocked: m.setCursorLocked,
|
|
|
|
isCursorLocked: m.isCursorLocked,
|
|
|
|
setFullscreen: m.setFullscreen,
|
|
|
|
isFullscreen: m.isFullscreen,
|
|
|
|
isTouchscreen: m.isTouchscreen,
|
|
|
|
onLoad: Bs,
|
|
|
|
onLoading: oi,
|
|
|
|
onResize: si,
|
|
|
|
onGamepadConnect: m.onGamepadConnect,
|
|
|
|
onGamepadDisconnect: m.onGamepadDisconnect,
|
|
|
|
onError: ii,
|
|
|
|
onCleanup: ci,
|
|
|
|
camPos: ds,
|
|
|
|
camScale: hs,
|
|
|
|
camRot: ps,
|
|
|
|
shake: fs,
|
|
|
|
toScreen: gs,
|
|
|
|
toWorld: bs,
|
|
|
|
setGravity: Os,
|
|
|
|
getGravity: Rs,
|
|
|
|
setGravityDirection: Us,
|
|
|
|
getGravityDirection: Vs,
|
|
|
|
setBackground: Ps,
|
|
|
|
getBackground: Ds,
|
|
|
|
getGamepads: m.getGamepads,
|
|
|
|
add: Bt,
|
|
|
|
make: In,
|
|
|
|
destroy: qs,
|
|
|
|
destroyAll: Ys,
|
|
|
|
get: kn,
|
|
|
|
readd: zs,
|
|
|
|
pos: qt,
|
|
|
|
scale: zt,
|
|
|
|
rotate: Wo,
|
|
|
|
color: Ms,
|
|
|
|
opacity: Uo,
|
|
|
|
anchor: Tn,
|
|
|
|
area: No,
|
|
|
|
sprite: wn,
|
|
|
|
text: Bo,
|
|
|
|
polygon: Po,
|
|
|
|
rect: Mo,
|
|
|
|
circle: So,
|
|
|
|
uvquad: Fo,
|
|
|
|
outline: Vo,
|
|
|
|
body: _o,
|
|
|
|
doubleJump: Ho,
|
|
|
|
shader: Go,
|
|
|
|
timer: Cn,
|
|
|
|
fixed: Ko,
|
|
|
|
stay: br,
|
|
|
|
health: Lo,
|
|
|
|
lifespan: jo,
|
|
|
|
state: ko,
|
|
|
|
z: $o,
|
|
|
|
move: zo,
|
|
|
|
offscreen: Yo,
|
|
|
|
follow: qo,
|
|
|
|
fadeIn: Oo,
|
|
|
|
mask: Ro,
|
|
|
|
drawon: Ao,
|
|
|
|
raycast: Do,
|
|
|
|
tile: gr,
|
|
|
|
agent: Io,
|
|
|
|
on: ut,
|
|
|
|
onUpdate: vs,
|
|
|
|
onDraw: xs,
|
|
|
|
onAdd: Ln,
|
|
|
|
onDestroy: Ar,
|
|
|
|
onClick: Ts,
|
|
|
|
onCollide: ys,
|
|
|
|
onCollideUpdate: ws,
|
|
|
|
onCollideEnd: Cs,
|
|
|
|
onHover: Es,
|
|
|
|
onHoverUpdate: Ss,
|
|
|
|
onHoverEnd: As,
|
|
|
|
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: Tr,
|
|
|
|
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: Ws,
|
|
|
|
wait: Xs,
|
|
|
|
play: Qt,
|
|
|
|
volume: Un,
|
|
|
|
burp: Jt,
|
|
|
|
audioCtx: z.ctx,
|
|
|
|
Line: Be,
|
|
|
|
Rect: ue,
|
|
|
|
Circle: Fe,
|
|
|
|
Ellipse: We,
|
|
|
|
Polygon: Oe,
|
|
|
|
Vec2: T,
|
|
|
|
Color: ee,
|
|
|
|
Mat4: Ge,
|
|
|
|
Quad: me,
|
|
|
|
RNG: It,
|
|
|
|
rand: Lt,
|
|
|
|
randi: Xn,
|
|
|
|
randSeed: jr,
|
|
|
|
vec2: C,
|
|
|
|
rgb: oe,
|
|
|
|
hsl2rgb: Lr,
|
|
|
|
quad: pe,
|
|
|
|
choose: _r,
|
|
|
|
chooseMultiple: Nr,
|
|
|
|
shuffle: Wn,
|
|
|
|
chance: kr,
|
|
|
|
lerp: Je,
|
|
|
|
tween: $s,
|
|
|
|
easings: Pt,
|
|
|
|
map: dt,
|
|
|
|
mapc: Ir,
|
|
|
|
wave: Yn,
|
|
|
|
deg2rad: ve,
|
|
|
|
rad2deg: lt,
|
|
|
|
clamp: Qe,
|
|
|
|
evaluateBezier: nr,
|
|
|
|
testLineLine: cn,
|
|
|
|
testRectRect: $n,
|
|
|
|
testRectLine: un,
|
|
|
|
testRectPoint: Qn,
|
|
|
|
testCirclePolygon: jt,
|
|
|
|
testLinePoint: Jn,
|
|
|
|
testLineCircle: Rt,
|
|
|
|
isConvex: or,
|
|
|
|
triangulate: rr,
|
|
|
|
drawSprite: en,
|
|
|
|
drawText: Cr,
|
|
|
|
formatText: St,
|
|
|
|
drawRect: p,
|
|
|
|
drawLine: S,
|
|
|
|
drawLines: ie,
|
|
|
|
drawTriangle: tn,
|
|
|
|
drawCircle: Xe,
|
|
|
|
drawEllipse: Tt,
|
|
|
|
drawUVQuad: it,
|
|
|
|
drawPolygon: Et,
|
|
|
|
drawCurve: Ye,
|
|
|
|
drawBezier: ft,
|
|
|
|
drawFormattedText: At,
|
|
|
|
drawMasked: xr,
|
|
|
|
drawSubtracted: yr,
|
|
|
|
pushTransform: xe,
|
|
|
|
popTransform: Ae,
|
|
|
|
pushTranslate: de,
|
|
|
|
pushScale: he,
|
|
|
|
pushRotate: Ke,
|
|
|
|
pushMatrix: Gn,
|
|
|
|
usePostEffect: Mn,
|
|
|
|
makeCanvas: Pn,
|
|
|
|
debug: le,
|
|
|
|
scene: Fs,
|
|
|
|
getSceneName: js,
|
|
|
|
go: Is,
|
|
|
|
onSceneLeave: Ls,
|
|
|
|
addLevel: _s,
|
|
|
|
getData: ks,
|
|
|
|
setData: Rr,
|
|
|
|
download: dn,
|
|
|
|
downloadJSON: no,
|
|
|
|
downloadText: sr,
|
|
|
|
downloadBlob: ir,
|
|
|
|
plug: Ur,
|
|
|
|
ASCII_CHARS: pr,
|
|
|
|
canvas: m.canvas,
|
|
|
|
addKaboom: Zs,
|
|
|
|
LEFT: T.LEFT,
|
|
|
|
RIGHT: T.RIGHT,
|
|
|
|
UP: T.UP,
|
|
|
|
DOWN: T.DOWN,
|
|
|
|
RED: ee.RED,
|
|
|
|
GREEN: ee.GREEN,
|
|
|
|
BLUE: ee.BLUE,
|
|
|
|
YELLOW: ee.YELLOW,
|
|
|
|
MAGENTA: ee.MAGENTA,
|
|
|
|
CYAN: ee.CYAN,
|
|
|
|
WHITE: ee.WHITE,
|
|
|
|
BLACK: ee.BLACK,
|
|
|
|
quit: ui,
|
|
|
|
Event: we,
|
|
|
|
EventHandler: tt,
|
|
|
|
EventController: et,
|
|
|
|
}),
|
|
|
|
t.plugins && t.plugins.forEach(Ur),
|
|
|
|
t.global !== !1)
|
|
|
|
)
|
|
|
|
for (let n in $e) window[n] = $e[n];
|
|
|
|
return t.focus !== !1 && m.canvas.focus(), $e;
|
|
|
|
}, "kaplay"),
|
|
|
|
ia = sa;
|
|
|
|
return gi(aa);
|
2024-06-01 06:31:08 +00:00
|
|
|
})();
|
|
|
|
export default kaplay.default;
|
2024-06-02 05:39:23 +00:00
|
|
|
//# sourceMappingURL=kaboom.js.map
|