plinkit 1.0.0-dev.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -91
- package/dist/index.cjs +4 -4
- package/dist/index.d.ts +10 -32
- package/dist/index.es.js +1444 -1609
- package/dist/plinkit.umd.js +4 -4
- package/package.json +5 -5
package/dist/index.es.js
CHANGED
|
@@ -1,452 +1,305 @@
|
|
|
1
|
-
var
|
|
2
|
-
ctx = null;
|
|
3
|
-
masterGain = null;
|
|
4
|
-
buffers = /* @__PURE__ */ new Map();
|
|
5
|
-
lastHitByBall = /* @__PURE__ */ new Map();
|
|
6
|
-
activePegVoices = 0;
|
|
7
|
-
muted;
|
|
8
|
-
volume;
|
|
9
|
-
destroyed = !1;
|
|
10
|
-
unlockedOnce = !1;
|
|
11
|
-
pendingUiTap = !1;
|
|
12
|
-
gestureCleanup = null;
|
|
13
|
-
visibilityCleanup = null;
|
|
14
|
-
config;
|
|
15
|
-
constructor(d) {
|
|
16
|
-
this.config = d, this.muted = d.muted, this.volume = me(d.masterVolume), this.installGestureUnlock(), this.installVisibilityHandler();
|
|
17
|
-
}
|
|
18
|
-
setMuted(d) {
|
|
19
|
-
this.muted = d, this.masterGain && (this.masterGain.gain.value = d ? 0 : this.volume), d || this.tryUnlock();
|
|
20
|
-
}
|
|
21
|
-
isMuted() {
|
|
22
|
-
return this.muted;
|
|
23
|
-
}
|
|
24
|
-
setVolume(d) {
|
|
25
|
-
this.volume = me(d), this.masterGain && !this.muted && (this.masterGain.gain.value = this.volume);
|
|
26
|
-
}
|
|
27
|
-
resume() {
|
|
28
|
-
this.tryUnlock();
|
|
29
|
-
}
|
|
30
|
-
playPegHit(d, E) {
|
|
31
|
-
if (this.destroyed || this.muted || !this.unlockedOnce) return;
|
|
32
|
-
const T = this.ctx;
|
|
33
|
-
if (!T) return;
|
|
34
|
-
const A = T.currentTime * 1e3, f = this.lastHitByBall.get(d);
|
|
35
|
-
if (f !== void 0 && A - f < Ee || (this.lastHitByBall.set(d, A), this.maybeCleanupLastHits(A), this.activePegVoices >= Ae)) return;
|
|
36
|
-
const e = Math.max(Ie, Math.min(1, E / Le));
|
|
37
|
-
this.playSample("peg", e, !0);
|
|
38
|
-
}
|
|
39
|
-
playBucketHit() {
|
|
40
|
-
this.playSample("bucket", Re, !1);
|
|
41
|
-
}
|
|
42
|
-
playUiTap() {
|
|
43
|
-
if (!(this.destroyed || this.muted)) {
|
|
44
|
-
if (this.ensureContext(), this.unlockedOnce) {
|
|
45
|
-
this.playSample("uiTap", pe, !1);
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
this.pendingUiTap = !0, this.tryUnlock();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
playSample(d, E, T) {
|
|
52
|
-
if (this.destroyed || this.muted || !this.unlockedOnce) return;
|
|
53
|
-
const A = this.ctx, f = this.masterGain;
|
|
54
|
-
if (!A || !f) return;
|
|
55
|
-
const e = this.buffers.get(d);
|
|
56
|
-
if (!e) return;
|
|
57
|
-
const o = A.createBufferSource();
|
|
58
|
-
o.buffer = e, o.playbackRate.value = be + Math.random() * ke;
|
|
59
|
-
const a = A.createGain();
|
|
60
|
-
a.gain.value = E, o.connect(a), a.connect(f), T && (this.activePegVoices += 1), o.onended = () => {
|
|
61
|
-
T && (this.activePegVoices = Math.max(0, this.activePegVoices - 1)), o.disconnect(), a.disconnect();
|
|
62
|
-
}, o.start();
|
|
63
|
-
}
|
|
64
|
-
destroy() {
|
|
65
|
-
this.destroyed || (this.destroyed = !0, this.gestureCleanup?.(), this.gestureCleanup = null, this.visibilityCleanup?.(), this.visibilityCleanup = null, this.buffers.clear(), this.lastHitByBall.clear(), this.ctx && (this.ctx.close().catch(ae), this.ctx = null, this.masterGain = null));
|
|
66
|
-
}
|
|
67
|
-
ensureContext() {
|
|
68
|
-
if (this.destroyed || this.ctx || typeof window > "u") return;
|
|
69
|
-
const d = window.AudioContext ?? window.webkitAudioContext;
|
|
70
|
-
d && (this.ctx = new d(), this.masterGain = this.ctx.createGain(), this.masterGain.gain.value = this.muted ? 0 : this.volume, this.masterGain.connect(this.ctx.destination), this.loadBuffers());
|
|
71
|
-
}
|
|
72
|
-
tryUnlock() {
|
|
73
|
-
if (this.destroyed) return;
|
|
74
|
-
this.ensureContext();
|
|
75
|
-
const d = this.ctx;
|
|
76
|
-
if (d) {
|
|
77
|
-
if (d.state === "running") {
|
|
78
|
-
this.markUnlocked();
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
d.resume().then(() => this.markUnlocked()).catch(ae);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
markUnlocked() {
|
|
85
|
-
this.destroyed || this.unlockedOnce || (this.unlockedOnce = !0, this.playSilentPing(), this.gestureCleanup?.(), this.gestureCleanup = null, this.pendingUiTap && (this.pendingUiTap = !1, this.playSample("uiTap", pe, !1)));
|
|
86
|
-
}
|
|
87
|
-
playSilentPing() {
|
|
88
|
-
const d = this.ctx;
|
|
89
|
-
if (d)
|
|
90
|
-
try {
|
|
91
|
-
const E = d.createBuffer(1, 1, Math.max(22050, d.sampleRate)), T = d.createBufferSource();
|
|
92
|
-
T.buffer = E;
|
|
93
|
-
const A = d.createGain();
|
|
94
|
-
A.gain.value = 1e-5, T.connect(A), A.connect(d.destination);
|
|
95
|
-
try {
|
|
96
|
-
T.start(0);
|
|
97
|
-
} catch {
|
|
98
|
-
}
|
|
99
|
-
try {
|
|
100
|
-
T.stop(0);
|
|
101
|
-
} catch {
|
|
102
|
-
}
|
|
103
|
-
} catch {
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
installGestureUnlock() {
|
|
107
|
-
if (typeof window > "u") return;
|
|
108
|
-
const d = {
|
|
109
|
-
passive: !0,
|
|
110
|
-
capture: !0
|
|
111
|
-
}, E = !0, T = () => this.tryUnlock();
|
|
112
|
-
window.addEventListener("pointerdown", T, d), window.addEventListener("pointerup", T, d), window.addEventListener("touchstart", T, d), window.addEventListener("touchend", T, d), window.addEventListener("keydown", T, E), this.gestureCleanup = () => {
|
|
113
|
-
window.removeEventListener("pointerdown", T, d), window.removeEventListener("pointerup", T, d), window.removeEventListener("touchstart", T, d), window.removeEventListener("touchend", T, d), window.removeEventListener("keydown", T, E);
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
installVisibilityHandler() {
|
|
117
|
-
if (typeof document > "u") return;
|
|
118
|
-
const d = () => {
|
|
119
|
-
this.destroyed || document.hidden || this.unlockedOnce && this.ctx?.resume().catch(ae);
|
|
120
|
-
};
|
|
121
|
-
document.addEventListener("visibilitychange", d), this.visibilityCleanup = () => document.removeEventListener("visibilitychange", d);
|
|
122
|
-
}
|
|
123
|
-
async loadBuffers() {
|
|
124
|
-
const d = [];
|
|
125
|
-
this.config.pegHitUrl && d.push(this.loadBuffer("peg", this.config.pegHitUrl)), this.config.bucketHitUrl && d.push(this.loadBuffer("bucket", this.config.bucketHitUrl)), this.config.uiTapUrl && d.push(this.loadBuffer("uiTap", this.config.uiTapUrl)), await Promise.allSettled(d);
|
|
126
|
-
}
|
|
127
|
-
async loadBuffer(d, E) {
|
|
128
|
-
const T = this.ctx;
|
|
129
|
-
if (T)
|
|
130
|
-
try {
|
|
131
|
-
const A = await fetch(E);
|
|
132
|
-
if (!A.ok) return;
|
|
133
|
-
const f = await A.arrayBuffer(), e = await T.decodeAudioData(f);
|
|
134
|
-
this.destroyed || this.buffers.set(d, e);
|
|
135
|
-
} catch {
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
maybeCleanupLastHits(d) {
|
|
139
|
-
if (!(this.lastHitByBall.size <= De))
|
|
140
|
-
for (const [E, T] of this.lastHitByBall) d - T > Ue && this.lastHitByBall.delete(E);
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
function me(d) {
|
|
144
|
-
return !Number.isFinite(d) || d < 0 ? 0 : d > 1 ? 1 : d;
|
|
145
|
-
}
|
|
146
|
-
function ae() {
|
|
147
|
-
}
|
|
148
|
-
var Oe = class {
|
|
1
|
+
var Ce = (p, B) => () => (B || (p((B = { exports: {} }).exports, B), p = null), B.exports), Me = class {
|
|
149
2
|
rafId = null;
|
|
150
3
|
step;
|
|
151
|
-
constructor(
|
|
152
|
-
this.step =
|
|
4
|
+
constructor(p) {
|
|
5
|
+
this.step = p;
|
|
153
6
|
}
|
|
154
7
|
start() {
|
|
155
8
|
if (this.rafId !== null) return;
|
|
156
|
-
const
|
|
157
|
-
this.step(
|
|
9
|
+
const p = (B) => {
|
|
10
|
+
this.step(B), this.rafId = window.requestAnimationFrame(p);
|
|
158
11
|
};
|
|
159
|
-
this.rafId = window.requestAnimationFrame(
|
|
12
|
+
this.rafId = window.requestAnimationFrame(p);
|
|
160
13
|
}
|
|
161
14
|
stop() {
|
|
162
15
|
this.rafId !== null && (window.cancelAnimationFrame(this.rafId), this.rafId = null);
|
|
163
16
|
}
|
|
164
17
|
};
|
|
165
|
-
function
|
|
166
|
-
const
|
|
18
|
+
function me(p, B) {
|
|
19
|
+
const A = p.bottomPegCount - p.topPegCount + 1, E = p.radius + p.sidePaddingPx, c = (B - E * 2) / Math.max(p.bottomPegCount - 1, 1);
|
|
167
20
|
return {
|
|
168
|
-
rows:
|
|
169
|
-
sidePadding:
|
|
170
|
-
baseSpacing:
|
|
171
|
-
targetVerticalStep:
|
|
21
|
+
rows: A,
|
|
22
|
+
sidePadding: E,
|
|
23
|
+
baseSpacing: c,
|
|
24
|
+
targetVerticalStep: c * p.verticalStepRatio
|
|
172
25
|
};
|
|
173
26
|
}
|
|
174
|
-
function
|
|
175
|
-
const { width:
|
|
176
|
-
if (
|
|
177
|
-
const
|
|
178
|
-
for (let l = 0; l <
|
|
179
|
-
const t =
|
|
27
|
+
function Te(p) {
|
|
28
|
+
const { width: B, height: A, topPegCount: E } = p;
|
|
29
|
+
if (p.bottomPegCount < E) throw new Error("bottomPegCount must be greater than or equal to topPegCount");
|
|
30
|
+
const c = me(p, B), e = B * 0.5, o = p.topPaddingPx, r = Math.max(o + 60, A - p.bottomPaddingPx), a = c.rows > 1 ? (r - o) / (c.rows - 1) : 0, u = Math.min(c.targetVerticalStep, a), n = r - u * Math.max(c.rows - 1, 0), h = [];
|
|
31
|
+
for (let l = 0; l < c.rows; l++) {
|
|
32
|
+
const t = E + l, i = n + l * u, s = (t - 1) * c.baseSpacing, f = e - s * 0.5;
|
|
180
33
|
h.push({
|
|
181
34
|
row: l,
|
|
182
35
|
count: t,
|
|
183
36
|
y: i,
|
|
184
|
-
startX:
|
|
37
|
+
startX: f,
|
|
185
38
|
rowWidth: s,
|
|
186
|
-
leftX:
|
|
187
|
-
rightX:
|
|
39
|
+
leftX: f,
|
|
40
|
+
rightX: f + s
|
|
188
41
|
});
|
|
189
42
|
}
|
|
190
43
|
return {
|
|
191
|
-
rows:
|
|
44
|
+
rows: c.rows,
|
|
192
45
|
center: e,
|
|
193
46
|
minTopY: o,
|
|
194
|
-
bottomY:
|
|
195
|
-
sidePadding:
|
|
196
|
-
baseSpacing:
|
|
197
|
-
verticalStep:
|
|
47
|
+
bottomY: r,
|
|
48
|
+
sidePadding: c.sidePadding,
|
|
49
|
+
baseSpacing: c.baseSpacing,
|
|
50
|
+
verticalStep: u,
|
|
198
51
|
startY: n,
|
|
199
52
|
rowAnchors: h
|
|
200
53
|
};
|
|
201
54
|
}
|
|
202
|
-
function
|
|
203
|
-
const
|
|
204
|
-
for (const
|
|
205
|
-
x:
|
|
206
|
-
y:
|
|
207
|
-
radius:
|
|
55
|
+
function Ae(p, B) {
|
|
56
|
+
const A = [];
|
|
57
|
+
for (const E of p.rowAnchors) for (let c = 0; c < E.count; c++) A.push({
|
|
58
|
+
x: E.startX + c * p.baseSpacing,
|
|
59
|
+
y: E.y,
|
|
60
|
+
radius: B
|
|
208
61
|
});
|
|
209
|
-
return
|
|
62
|
+
return A;
|
|
210
63
|
}
|
|
211
|
-
function
|
|
212
|
-
if (
|
|
213
|
-
const
|
|
64
|
+
function Be(p, B, A) {
|
|
65
|
+
if (p.rows < 2) return [];
|
|
66
|
+
const E = [], c = (A.spread - 1) * p.baseSpacing, e = (t) => t < p.center ? t - c : t > p.center ? t + c : t, o = p.rowAnchors[0], r = o.leftX, a = o.rightX, u = p.startY - p.minTopY, n = B * 2.5, h = Math.min(p.verticalStep, Math.max(n, u / 3)), l = u >= n ? Math.min(3, Math.floor(u / h)) : 0;
|
|
214
67
|
for (let t = 1; t <= l; t++) {
|
|
215
|
-
const i =
|
|
216
|
-
|
|
68
|
+
const i = p.startY - t * h + A.yOffset, s = r - t * p.baseSpacing * 0.5, f = a + t * p.baseSpacing * 0.5;
|
|
69
|
+
E.push({
|
|
217
70
|
x: e(s),
|
|
218
71
|
y: i,
|
|
219
|
-
radius:
|
|
72
|
+
radius: B
|
|
220
73
|
}, {
|
|
221
|
-
x: e(
|
|
74
|
+
x: e(f),
|
|
222
75
|
y: i,
|
|
223
|
-
radius:
|
|
76
|
+
radius: B
|
|
224
77
|
});
|
|
225
78
|
}
|
|
226
79
|
for (let t = 0; t < l; t++) {
|
|
227
|
-
const i =
|
|
228
|
-
|
|
229
|
-
x: e((
|
|
230
|
-
y: (i + s) / 2 +
|
|
231
|
-
radius:
|
|
80
|
+
const i = p.startY - t * h, s = p.startY - (t + 1) * h, f = r - t * p.baseSpacing * 0.5, m = r - (t + 1) * p.baseSpacing * 0.5, x = a + t * p.baseSpacing * 0.5, P = a + (t + 1) * p.baseSpacing * 0.5;
|
|
81
|
+
E.push({
|
|
82
|
+
x: e((f + m) / 2),
|
|
83
|
+
y: (i + s) / 2 + A.yOffset,
|
|
84
|
+
radius: B
|
|
232
85
|
}, {
|
|
233
86
|
x: e((x + P) / 2),
|
|
234
|
-
y: (i + s) / 2 +
|
|
235
|
-
radius:
|
|
87
|
+
y: (i + s) / 2 + A.yOffset,
|
|
88
|
+
radius: B
|
|
236
89
|
});
|
|
237
90
|
}
|
|
238
|
-
for (let t = 0; t <
|
|
239
|
-
const i =
|
|
240
|
-
|
|
91
|
+
for (let t = 0; t < p.rows - 1; t++) {
|
|
92
|
+
const i = p.rowAnchors[t], s = p.rowAnchors[t + 1], f = (i.y + s.y) / 2 + A.yOffset;
|
|
93
|
+
E.push({
|
|
241
94
|
x: e((i.leftX + s.leftX) / 2),
|
|
242
|
-
y:
|
|
243
|
-
radius:
|
|
95
|
+
y: f,
|
|
96
|
+
radius: B
|
|
244
97
|
}, {
|
|
245
98
|
x: e((i.rightX + s.rightX) / 2),
|
|
246
|
-
y:
|
|
247
|
-
radius:
|
|
99
|
+
y: f,
|
|
100
|
+
radius: B
|
|
248
101
|
});
|
|
249
102
|
}
|
|
250
|
-
return
|
|
103
|
+
return E;
|
|
251
104
|
}
|
|
252
|
-
var
|
|
253
|
-
function
|
|
254
|
-
const { mainPegs:
|
|
255
|
-
if (
|
|
256
|
-
const
|
|
257
|
-
if (
|
|
258
|
-
const { rows: e, baseSpacing: o, targetVerticalStep:
|
|
105
|
+
var Ee = -1, Ie = 8;
|
|
106
|
+
function Le(p) {
|
|
107
|
+
const { mainPegs: B, ballRadius: A, heightPolicy: E } = p;
|
|
108
|
+
if (ke(E), be(B), !Number.isFinite(A) || A <= 0) throw new Error("ballRadius must be greater than 0");
|
|
109
|
+
const c = me(B, 600);
|
|
110
|
+
if (c.baseSpacing <= 0) throw new Error("mainPegs produce non-positive base spacing; reduce sidePaddingPx or peg counts");
|
|
111
|
+
const { rows: e, baseSpacing: o, targetVerticalStep: r } = c, a = r * Math.max(e - 1, 0), u = E.topPaddingPx, n = r * 2, h = A * 2 + Ie, l = B.radius + A + Ee, t = Math.max(E.bottomPaddingPx, l + h);
|
|
259
112
|
return {
|
|
260
|
-
worldHeight:
|
|
113
|
+
worldHeight: u + n + a + t,
|
|
261
114
|
resolvedMainPegs: {
|
|
262
|
-
...
|
|
263
|
-
topPaddingPx:
|
|
115
|
+
...B,
|
|
116
|
+
topPaddingPx: u,
|
|
264
117
|
bottomPaddingPx: t
|
|
265
118
|
},
|
|
266
119
|
rows: e,
|
|
267
120
|
baseSpacing: o,
|
|
268
|
-
verticalStep:
|
|
121
|
+
verticalStep: r,
|
|
269
122
|
requiredBottomPaddingPx: t
|
|
270
123
|
};
|
|
271
124
|
}
|
|
272
|
-
function
|
|
273
|
-
const { parentWidthPx:
|
|
274
|
-
if (
|
|
275
|
-
if (!Number.isFinite(
|
|
276
|
-
const
|
|
125
|
+
function Re(p) {
|
|
126
|
+
const { parentWidthPx: B, viewport: A, worldHeight: E } = p;
|
|
127
|
+
if (De(A), !Number.isFinite(B) || B <= 0) throw new Error("Parent width must be greater than 0");
|
|
128
|
+
if (!Number.isFinite(E) || E <= 0) throw new Error("World height must be greater than 0");
|
|
129
|
+
const c = B;
|
|
277
130
|
return {
|
|
278
|
-
displayWidth:
|
|
279
|
-
displayHeight:
|
|
280
|
-
worldScale:
|
|
131
|
+
displayWidth: c,
|
|
132
|
+
displayHeight: c * (E / 600),
|
|
133
|
+
worldScale: c / 600
|
|
281
134
|
};
|
|
282
135
|
}
|
|
283
|
-
function
|
|
284
|
-
if (!Number.isFinite(
|
|
285
|
-
if (!Number.isFinite(
|
|
136
|
+
function ke(p) {
|
|
137
|
+
if (!Number.isFinite(p.topPaddingPx) || p.topPaddingPx < 0) throw new Error("viewport.heightPolicy.topPaddingPx must be >= 0");
|
|
138
|
+
if (!Number.isFinite(p.bottomPaddingPx) || p.bottomPaddingPx < 0) throw new Error("viewport.heightPolicy.bottomPaddingPx must be >= 0");
|
|
286
139
|
}
|
|
287
|
-
function
|
|
288
|
-
if (!Number.isFinite(
|
|
140
|
+
function De(p) {
|
|
141
|
+
if (!Number.isFinite(p.dprCap) || p.dprCap <= 0) throw new Error("viewport.dprCap must be greater than 0");
|
|
289
142
|
}
|
|
290
|
-
function
|
|
291
|
-
if (!Number.isFinite(
|
|
292
|
-
if (!Number.isFinite(
|
|
293
|
-
if (!Number.isFinite(
|
|
294
|
-
if (!Number.isFinite(
|
|
295
|
-
if (!Number.isFinite(
|
|
143
|
+
function be(p) {
|
|
144
|
+
if (!Number.isFinite(p.radius) || p.radius <= 0) throw new Error("layout.mainPegs.radius must be greater than 0");
|
|
145
|
+
if (!Number.isFinite(p.topPegCount) || p.topPegCount < 1) throw new Error("layout.mainPegs.topPegCount must be >= 1");
|
|
146
|
+
if (!Number.isFinite(p.bottomPegCount) || p.bottomPegCount < p.topPegCount) throw new Error("layout.mainPegs.bottomPegCount must be >= topPegCount");
|
|
147
|
+
if (!Number.isFinite(p.verticalStepRatio) || p.verticalStepRatio <= 0) throw new Error("layout.mainPegs.verticalStepRatio must be > 0");
|
|
148
|
+
if (!Number.isFinite(p.sidePaddingPx) || p.sidePaddingPx < 0) throw new Error("layout.mainPegs.sidePaddingPx must be >= 0");
|
|
296
149
|
}
|
|
297
|
-
var
|
|
298
|
-
(function(
|
|
299
|
-
typeof
|
|
300
|
-
})(
|
|
301
|
-
return (function(
|
|
302
|
-
var
|
|
303
|
-
function
|
|
304
|
-
if (
|
|
305
|
-
var o =
|
|
150
|
+
var Fe = /* @__PURE__ */ Ce(((p, B) => {
|
|
151
|
+
(function(E, c) {
|
|
152
|
+
typeof p == "object" && typeof B == "object" ? B.exports = c() : typeof define == "function" && define.amd ? define("Matter", [], c) : typeof p == "object" ? p.Matter = c() : E.Matter = c();
|
|
153
|
+
})(p, function() {
|
|
154
|
+
return (function(A) {
|
|
155
|
+
var E = {};
|
|
156
|
+
function c(e) {
|
|
157
|
+
if (E[e]) return E[e].exports;
|
|
158
|
+
var o = E[e] = {
|
|
306
159
|
i: e,
|
|
307
160
|
l: !1,
|
|
308
161
|
exports: {}
|
|
309
162
|
};
|
|
310
|
-
return
|
|
163
|
+
return A[e].call(o.exports, o, o.exports, c), o.l = !0, o.exports;
|
|
311
164
|
}
|
|
312
|
-
return
|
|
313
|
-
|
|
165
|
+
return c.m = A, c.c = E, c.d = function(e, o, r) {
|
|
166
|
+
c.o(e, o) || Object.defineProperty(e, o, {
|
|
314
167
|
enumerable: !0,
|
|
315
|
-
get:
|
|
168
|
+
get: r
|
|
316
169
|
});
|
|
317
|
-
},
|
|
170
|
+
}, c.r = function(e) {
|
|
318
171
|
typeof Symbol < "u" && Symbol.toStringTag && Object.defineProperty(e, Symbol.toStringTag, { value: "Module" }), Object.defineProperty(e, "__esModule", { value: !0 });
|
|
319
|
-
},
|
|
320
|
-
if (o & 1 && (e =
|
|
321
|
-
var
|
|
322
|
-
if (
|
|
172
|
+
}, c.t = function(e, o) {
|
|
173
|
+
if (o & 1 && (e = c(e)), o & 8 || o & 4 && typeof e == "object" && e && e.__esModule) return e;
|
|
174
|
+
var r = /* @__PURE__ */ Object.create(null);
|
|
175
|
+
if (c.r(r), Object.defineProperty(r, "default", {
|
|
323
176
|
enumerable: !0,
|
|
324
177
|
value: e
|
|
325
|
-
}), o & 2 && typeof e != "string") for (var
|
|
326
|
-
return e[
|
|
327
|
-
}.bind(null,
|
|
328
|
-
return
|
|
329
|
-
},
|
|
178
|
+
}), o & 2 && typeof e != "string") for (var a in e) c.d(r, a, function(u) {
|
|
179
|
+
return e[u];
|
|
180
|
+
}.bind(null, a));
|
|
181
|
+
return r;
|
|
182
|
+
}, c.n = function(e) {
|
|
330
183
|
var o = e && e.__esModule ? function() {
|
|
331
184
|
return e.default;
|
|
332
185
|
} : function() {
|
|
333
186
|
return e;
|
|
334
187
|
};
|
|
335
|
-
return
|
|
336
|
-
},
|
|
188
|
+
return c.d(o, "a", o), o;
|
|
189
|
+
}, c.o = function(e, o) {
|
|
337
190
|
return Object.prototype.hasOwnProperty.call(e, o);
|
|
338
|
-
},
|
|
191
|
+
}, c.p = "", c(c.s = 20);
|
|
339
192
|
})([
|
|
340
|
-
(function(
|
|
341
|
-
var
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
var
|
|
345
|
-
typeof
|
|
346
|
-
for (var n =
|
|
193
|
+
(function(A, E) {
|
|
194
|
+
var c = {};
|
|
195
|
+
A.exports = c, (function() {
|
|
196
|
+
c._baseDelta = 1e3 / 60, c._nextId = 0, c._seed = 0, c._nowStartTime = +/* @__PURE__ */ new Date(), c._warnedOnce = {}, c._decomp = null, c.extend = function(o, r) {
|
|
197
|
+
var a, u;
|
|
198
|
+
typeof r == "boolean" ? (a = 2, u = r) : (a = 1, u = !0);
|
|
199
|
+
for (var n = a; n < arguments.length; n++) {
|
|
347
200
|
var h = arguments[n];
|
|
348
|
-
if (h) for (var l in h)
|
|
201
|
+
if (h) for (var l in h) u && h[l] && h[l].constructor === Object && (!o[l] || o[l].constructor === Object) ? (o[l] = o[l] || {}, c.extend(o[l], u, h[l])) : o[l] = h[l];
|
|
349
202
|
}
|
|
350
203
|
return o;
|
|
351
|
-
},
|
|
352
|
-
return
|
|
353
|
-
},
|
|
204
|
+
}, c.clone = function(o, r) {
|
|
205
|
+
return c.extend({}, r, o);
|
|
206
|
+
}, c.keys = function(o) {
|
|
354
207
|
if (Object.keys) return Object.keys(o);
|
|
355
|
-
var
|
|
356
|
-
for (var
|
|
357
|
-
return
|
|
358
|
-
},
|
|
359
|
-
var
|
|
208
|
+
var r = [];
|
|
209
|
+
for (var a in o) r.push(a);
|
|
210
|
+
return r;
|
|
211
|
+
}, c.values = function(o) {
|
|
212
|
+
var r = [];
|
|
360
213
|
if (Object.keys) {
|
|
361
|
-
for (var
|
|
362
|
-
return
|
|
214
|
+
for (var a = Object.keys(o), u = 0; u < a.length; u++) r.push(o[a[u]]);
|
|
215
|
+
return r;
|
|
363
216
|
}
|
|
364
|
-
for (var n in o)
|
|
365
|
-
return
|
|
366
|
-
},
|
|
367
|
-
|
|
368
|
-
for (var n = 0; n <
|
|
217
|
+
for (var n in o) r.push(o[n]);
|
|
218
|
+
return r;
|
|
219
|
+
}, c.get = function(o, r, a, u) {
|
|
220
|
+
r = r.split(".").slice(a, u);
|
|
221
|
+
for (var n = 0; n < r.length; n += 1) o = o[r[n]];
|
|
369
222
|
return o;
|
|
370
|
-
},
|
|
371
|
-
var h =
|
|
372
|
-
return
|
|
373
|
-
},
|
|
374
|
-
for (var
|
|
375
|
-
var
|
|
376
|
-
o[
|
|
223
|
+
}, c.set = function(o, r, a, u, n) {
|
|
224
|
+
var h = r.split(".").slice(u, n);
|
|
225
|
+
return c.get(o, r, 0, -1)[h[h.length - 1]] = a, a;
|
|
226
|
+
}, c.shuffle = function(o) {
|
|
227
|
+
for (var r = o.length - 1; r > 0; r--) {
|
|
228
|
+
var a = Math.floor(c.random() * (r + 1)), u = o[r];
|
|
229
|
+
o[r] = o[a], o[a] = u;
|
|
377
230
|
}
|
|
378
231
|
return o;
|
|
379
|
-
},
|
|
380
|
-
return o[Math.floor(
|
|
381
|
-
},
|
|
232
|
+
}, c.choose = function(o) {
|
|
233
|
+
return o[Math.floor(c.random() * o.length)];
|
|
234
|
+
}, c.isElement = function(o) {
|
|
382
235
|
return typeof HTMLElement < "u" ? o instanceof HTMLElement : !!(o && o.nodeType && o.nodeName);
|
|
383
|
-
},
|
|
236
|
+
}, c.isArray = function(o) {
|
|
384
237
|
return Object.prototype.toString.call(o) === "[object Array]";
|
|
385
|
-
},
|
|
238
|
+
}, c.isFunction = function(o) {
|
|
386
239
|
return typeof o == "function";
|
|
387
|
-
},
|
|
240
|
+
}, c.isPlainObject = function(o) {
|
|
388
241
|
return typeof o == "object" && o.constructor === Object;
|
|
389
|
-
},
|
|
242
|
+
}, c.isString = function(o) {
|
|
390
243
|
return toString.call(o) === "[object String]";
|
|
391
|
-
},
|
|
392
|
-
return o <
|
|
393
|
-
},
|
|
244
|
+
}, c.clamp = function(o, r, a) {
|
|
245
|
+
return o < r ? r : o > a ? a : o;
|
|
246
|
+
}, c.sign = function(o) {
|
|
394
247
|
return o < 0 ? -1 : 1;
|
|
395
|
-
},
|
|
248
|
+
}, c.now = function() {
|
|
396
249
|
if (typeof window < "u" && window.performance) {
|
|
397
250
|
if (window.performance.now) return window.performance.now();
|
|
398
251
|
if (window.performance.webkitNow) return window.performance.webkitNow();
|
|
399
252
|
}
|
|
400
|
-
return Date.now ? Date.now() : /* @__PURE__ */ new Date() -
|
|
401
|
-
},
|
|
402
|
-
return o = typeof o < "u" ? o : 0,
|
|
253
|
+
return Date.now ? Date.now() : /* @__PURE__ */ new Date() - c._nowStartTime;
|
|
254
|
+
}, c.random = function(o, r) {
|
|
255
|
+
return o = typeof o < "u" ? o : 0, r = typeof r < "u" ? r : 1, o + e() * (r - o);
|
|
403
256
|
};
|
|
404
257
|
var e = function() {
|
|
405
|
-
return
|
|
258
|
+
return c._seed = (c._seed * 9301 + 49297) % 233280, c._seed / 233280;
|
|
406
259
|
};
|
|
407
|
-
|
|
260
|
+
c.colorToNumber = function(o) {
|
|
408
261
|
return o = o.replace("#", ""), o.length == 3 && (o = o.charAt(0) + o.charAt(0) + o.charAt(1) + o.charAt(1) + o.charAt(2) + o.charAt(2)), parseInt(o, 16);
|
|
409
|
-
},
|
|
410
|
-
console &&
|
|
411
|
-
},
|
|
412
|
-
console &&
|
|
413
|
-
},
|
|
414
|
-
console &&
|
|
415
|
-
},
|
|
262
|
+
}, c.logLevel = 1, c.log = function() {
|
|
263
|
+
console && c.logLevel > 0 && c.logLevel <= 3 && console.log.apply(console, ["matter-js:"].concat(Array.prototype.slice.call(arguments)));
|
|
264
|
+
}, c.info = function() {
|
|
265
|
+
console && c.logLevel > 0 && c.logLevel <= 2 && console.info.apply(console, ["matter-js:"].concat(Array.prototype.slice.call(arguments)));
|
|
266
|
+
}, c.warn = function() {
|
|
267
|
+
console && c.logLevel > 0 && c.logLevel <= 3 && console.warn.apply(console, ["matter-js:"].concat(Array.prototype.slice.call(arguments)));
|
|
268
|
+
}, c.warnOnce = function() {
|
|
416
269
|
var o = Array.prototype.slice.call(arguments).join(" ");
|
|
417
|
-
|
|
418
|
-
},
|
|
419
|
-
o[
|
|
420
|
-
|
|
421
|
-
}, o[
|
|
422
|
-
},
|
|
423
|
-
return
|
|
424
|
-
},
|
|
425
|
-
if (o.indexOf) return o.indexOf(
|
|
426
|
-
for (var
|
|
270
|
+
c._warnedOnce[o] || (c.warn(o), c._warnedOnce[o] = !0);
|
|
271
|
+
}, c.deprecated = function(o, r, a) {
|
|
272
|
+
o[r] = c.chain(function() {
|
|
273
|
+
c.warnOnce("🔅 deprecated 🔅", a);
|
|
274
|
+
}, o[r]);
|
|
275
|
+
}, c.nextId = function() {
|
|
276
|
+
return c._nextId++;
|
|
277
|
+
}, c.indexOf = function(o, r) {
|
|
278
|
+
if (o.indexOf) return o.indexOf(r);
|
|
279
|
+
for (var a = 0; a < o.length; a++) if (o[a] === r) return a;
|
|
427
280
|
return -1;
|
|
428
|
-
},
|
|
429
|
-
if (o.map) return o.map(
|
|
430
|
-
for (var
|
|
431
|
-
return r;
|
|
432
|
-
}, f.topologicalSort = function(o) {
|
|
433
|
-
var a = [], r = [], c = [];
|
|
434
|
-
for (var n in o) !r[n] && !c[n] && f._topologicalSort(n, r, c, o, a);
|
|
281
|
+
}, c.map = function(o, r) {
|
|
282
|
+
if (o.map) return o.map(r);
|
|
283
|
+
for (var a = [], u = 0; u < o.length; u += 1) a.push(r(o[u]));
|
|
435
284
|
return a;
|
|
436
|
-
},
|
|
437
|
-
var
|
|
438
|
-
|
|
285
|
+
}, c.topologicalSort = function(o) {
|
|
286
|
+
var r = [], a = [], u = [];
|
|
287
|
+
for (var n in o) !a[n] && !u[n] && c._topologicalSort(n, a, u, o, r);
|
|
288
|
+
return r;
|
|
289
|
+
}, c._topologicalSort = function(o, r, a, u, n) {
|
|
290
|
+
var h = u[o] || [];
|
|
291
|
+
a[o] = !0;
|
|
439
292
|
for (var l = 0; l < h.length; l += 1) {
|
|
440
293
|
var t = h[l];
|
|
441
|
-
|
|
294
|
+
a[t] || r[t] || c._topologicalSort(t, r, a, u, n);
|
|
442
295
|
}
|
|
443
|
-
|
|
444
|
-
},
|
|
445
|
-
for (var o = [],
|
|
446
|
-
var
|
|
447
|
-
|
|
296
|
+
a[o] = !1, r[o] = !0, n.push(o);
|
|
297
|
+
}, c.chain = function() {
|
|
298
|
+
for (var o = [], r = 0; r < arguments.length; r += 1) {
|
|
299
|
+
var a = arguments[r];
|
|
300
|
+
a._chained ? o.push.apply(o, a._chained) : o.push(a);
|
|
448
301
|
}
|
|
449
|
-
var
|
|
302
|
+
var u = function() {
|
|
450
303
|
for (var n, h = new Array(arguments.length), l = 0, t = arguments.length; l < t; l++) h[l] = arguments[l];
|
|
451
304
|
for (l = 0; l < o.length; l += 1) {
|
|
452
305
|
var i = o[l].apply(n, h);
|
|
@@ -454,15 +307,15 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
454
307
|
}
|
|
455
308
|
return n;
|
|
456
309
|
};
|
|
457
|
-
return
|
|
458
|
-
},
|
|
459
|
-
return
|
|
460
|
-
},
|
|
461
|
-
return
|
|
462
|
-
},
|
|
463
|
-
|
|
464
|
-
},
|
|
465
|
-
var o =
|
|
310
|
+
return u._chained = o, u;
|
|
311
|
+
}, c.chainPathBefore = function(o, r, a) {
|
|
312
|
+
return c.set(o, r, c.chain(a, c.get(o, r)));
|
|
313
|
+
}, c.chainPathAfter = function(o, r, a) {
|
|
314
|
+
return c.set(o, r, c.chain(c.get(o, r), a));
|
|
315
|
+
}, c.setDecomp = function(o) {
|
|
316
|
+
c._decomp = o;
|
|
317
|
+
}, c.getDecomp = function() {
|
|
318
|
+
var o = c._decomp;
|
|
466
319
|
try {
|
|
467
320
|
!o && typeof window < "u" && (o = window.decomp), !o && typeof global < "u" && (o = global.decomp);
|
|
468
321
|
} catch {
|
|
@@ -472,10 +325,10 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
472
325
|
};
|
|
473
326
|
})();
|
|
474
327
|
}),
|
|
475
|
-
(function(
|
|
476
|
-
var
|
|
477
|
-
|
|
478
|
-
|
|
328
|
+
(function(A, E) {
|
|
329
|
+
var c = {};
|
|
330
|
+
A.exports = c, (function() {
|
|
331
|
+
c.create = function(e) {
|
|
479
332
|
var o = {
|
|
480
333
|
min: {
|
|
481
334
|
x: 0,
|
|
@@ -486,55 +339,55 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
486
339
|
y: 0
|
|
487
340
|
}
|
|
488
341
|
};
|
|
489
|
-
return e &&
|
|
490
|
-
},
|
|
342
|
+
return e && c.update(o, e), o;
|
|
343
|
+
}, c.update = function(e, o, r) {
|
|
491
344
|
e.min.x = 1 / 0, e.max.x = -1 / 0, e.min.y = 1 / 0, e.max.y = -1 / 0;
|
|
492
|
-
for (var
|
|
493
|
-
var
|
|
494
|
-
|
|
345
|
+
for (var a = 0; a < o.length; a++) {
|
|
346
|
+
var u = o[a];
|
|
347
|
+
u.x > e.max.x && (e.max.x = u.x), u.x < e.min.x && (e.min.x = u.x), u.y > e.max.y && (e.max.y = u.y), u.y < e.min.y && (e.min.y = u.y);
|
|
495
348
|
}
|
|
496
|
-
|
|
497
|
-
},
|
|
349
|
+
r && (r.x > 0 ? e.max.x += r.x : e.min.x += r.x, r.y > 0 ? e.max.y += r.y : e.min.y += r.y);
|
|
350
|
+
}, c.contains = function(e, o) {
|
|
498
351
|
return o.x >= e.min.x && o.x <= e.max.x && o.y >= e.min.y && o.y <= e.max.y;
|
|
499
|
-
},
|
|
352
|
+
}, c.overlaps = function(e, o) {
|
|
500
353
|
return e.min.x <= o.max.x && e.max.x >= o.min.x && e.max.y >= o.min.y && e.min.y <= o.max.y;
|
|
501
|
-
},
|
|
354
|
+
}, c.translate = function(e, o) {
|
|
502
355
|
e.min.x += o.x, e.max.x += o.x, e.min.y += o.y, e.max.y += o.y;
|
|
503
|
-
},
|
|
504
|
-
var
|
|
505
|
-
e.min.x = o.x, e.max.x = o.x +
|
|
356
|
+
}, c.shift = function(e, o) {
|
|
357
|
+
var r = e.max.x - e.min.x, a = e.max.y - e.min.y;
|
|
358
|
+
e.min.x = o.x, e.max.x = o.x + r, e.min.y = o.y, e.max.y = o.y + a;
|
|
506
359
|
};
|
|
507
360
|
})();
|
|
508
361
|
}),
|
|
509
|
-
(function(
|
|
510
|
-
var
|
|
511
|
-
|
|
512
|
-
|
|
362
|
+
(function(A, E) {
|
|
363
|
+
var c = {};
|
|
364
|
+
A.exports = c, (function() {
|
|
365
|
+
c.create = function(e, o) {
|
|
513
366
|
return {
|
|
514
367
|
x: e || 0,
|
|
515
368
|
y: o || 0
|
|
516
369
|
};
|
|
517
|
-
},
|
|
370
|
+
}, c.clone = function(e) {
|
|
518
371
|
return {
|
|
519
372
|
x: e.x,
|
|
520
373
|
y: e.y
|
|
521
374
|
};
|
|
522
|
-
},
|
|
375
|
+
}, c.magnitude = function(e) {
|
|
523
376
|
return Math.sqrt(e.x * e.x + e.y * e.y);
|
|
524
|
-
},
|
|
377
|
+
}, c.magnitudeSquared = function(e) {
|
|
525
378
|
return e.x * e.x + e.y * e.y;
|
|
526
|
-
},
|
|
527
|
-
var
|
|
528
|
-
a || (a = {});
|
|
529
|
-
var n = e.x * r - e.y * c;
|
|
530
|
-
return a.y = e.x * c + e.y * r, a.x = n, a;
|
|
531
|
-
}, f.rotateAbout = function(e, o, a, r) {
|
|
532
|
-
var c = Math.cos(o), n = Math.sin(o);
|
|
379
|
+
}, c.rotate = function(e, o, r) {
|
|
380
|
+
var a = Math.cos(o), u = Math.sin(o);
|
|
533
381
|
r || (r = {});
|
|
534
|
-
var
|
|
535
|
-
return r.y =
|
|
536
|
-
},
|
|
537
|
-
var o =
|
|
382
|
+
var n = e.x * a - e.y * u;
|
|
383
|
+
return r.y = e.x * u + e.y * a, r.x = n, r;
|
|
384
|
+
}, c.rotateAbout = function(e, o, r, a) {
|
|
385
|
+
var u = Math.cos(o), n = Math.sin(o);
|
|
386
|
+
a || (a = {});
|
|
387
|
+
var h = r.x + ((e.x - r.x) * u - (e.y - r.y) * n);
|
|
388
|
+
return a.y = r.y + ((e.x - r.x) * n + (e.y - r.y) * u), a.x = h, a;
|
|
389
|
+
}, c.normalise = function(e) {
|
|
390
|
+
var o = c.magnitude(e);
|
|
538
391
|
return o === 0 ? {
|
|
539
392
|
x: 0,
|
|
540
393
|
y: 0
|
|
@@ -542,175 +395,175 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
542
395
|
x: e.x / o,
|
|
543
396
|
y: e.y / o
|
|
544
397
|
};
|
|
545
|
-
},
|
|
398
|
+
}, c.dot = function(e, o) {
|
|
546
399
|
return e.x * o.x + e.y * o.y;
|
|
547
|
-
},
|
|
400
|
+
}, c.cross = function(e, o) {
|
|
548
401
|
return e.x * o.y - e.y * o.x;
|
|
549
|
-
},
|
|
550
|
-
return (o.x - e.x) * (
|
|
551
|
-
},
|
|
552
|
-
return
|
|
553
|
-
},
|
|
554
|
-
return
|
|
555
|
-
},
|
|
402
|
+
}, c.cross3 = function(e, o, r) {
|
|
403
|
+
return (o.x - e.x) * (r.y - e.y) - (o.y - e.y) * (r.x - e.x);
|
|
404
|
+
}, c.add = function(e, o, r) {
|
|
405
|
+
return r || (r = {}), r.x = e.x + o.x, r.y = e.y + o.y, r;
|
|
406
|
+
}, c.sub = function(e, o, r) {
|
|
407
|
+
return r || (r = {}), r.x = e.x - o.x, r.y = e.y - o.y, r;
|
|
408
|
+
}, c.mult = function(e, o) {
|
|
556
409
|
return {
|
|
557
410
|
x: e.x * o,
|
|
558
411
|
y: e.y * o
|
|
559
412
|
};
|
|
560
|
-
},
|
|
413
|
+
}, c.div = function(e, o) {
|
|
561
414
|
return {
|
|
562
415
|
x: e.x / o,
|
|
563
416
|
y: e.y / o
|
|
564
417
|
};
|
|
565
|
-
},
|
|
418
|
+
}, c.perp = function(e, o) {
|
|
566
419
|
return o = o === !0 ? -1 : 1, {
|
|
567
420
|
x: o * -e.y,
|
|
568
421
|
y: o * e.x
|
|
569
422
|
};
|
|
570
|
-
},
|
|
423
|
+
}, c.neg = function(e) {
|
|
571
424
|
return {
|
|
572
425
|
x: -e.x,
|
|
573
426
|
y: -e.y
|
|
574
427
|
};
|
|
575
|
-
},
|
|
428
|
+
}, c.angle = function(e, o) {
|
|
576
429
|
return Math.atan2(o.y - e.y, o.x - e.x);
|
|
577
|
-
},
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
430
|
+
}, c._temp = [
|
|
431
|
+
c.create(),
|
|
432
|
+
c.create(),
|
|
433
|
+
c.create(),
|
|
434
|
+
c.create(),
|
|
435
|
+
c.create(),
|
|
436
|
+
c.create()
|
|
584
437
|
];
|
|
585
438
|
})();
|
|
586
439
|
}),
|
|
587
|
-
(function(
|
|
440
|
+
(function(A, E, c) {
|
|
588
441
|
var e = {};
|
|
589
|
-
|
|
590
|
-
var o =
|
|
442
|
+
A.exports = e;
|
|
443
|
+
var o = c(2), r = c(0);
|
|
591
444
|
(function() {
|
|
592
|
-
e.create = function(
|
|
593
|
-
for (var n = [], h = 0; h <
|
|
594
|
-
var l =
|
|
445
|
+
e.create = function(a, u) {
|
|
446
|
+
for (var n = [], h = 0; h < a.length; h++) {
|
|
447
|
+
var l = a[h], t = {
|
|
595
448
|
x: l.x,
|
|
596
449
|
y: l.y,
|
|
597
450
|
index: h,
|
|
598
|
-
body:
|
|
451
|
+
body: u,
|
|
599
452
|
isInternal: !1
|
|
600
453
|
};
|
|
601
454
|
n.push(t);
|
|
602
455
|
}
|
|
603
456
|
return n;
|
|
604
|
-
}, e.fromPath = function(
|
|
457
|
+
}, e.fromPath = function(a, u) {
|
|
605
458
|
var n = /L?\s*([-\d.e]+)[\s,]*([-\d.e]+)*/gi, h = [];
|
|
606
|
-
return
|
|
459
|
+
return a.replace(n, function(l, t, i) {
|
|
607
460
|
h.push({
|
|
608
461
|
x: parseFloat(t),
|
|
609
462
|
y: parseFloat(i)
|
|
610
463
|
});
|
|
611
|
-
}), e.create(h,
|
|
612
|
-
}, e.centre = function(
|
|
613
|
-
for (var
|
|
464
|
+
}), e.create(h, u);
|
|
465
|
+
}, e.centre = function(a) {
|
|
466
|
+
for (var u = e.area(a, !0), n = {
|
|
614
467
|
x: 0,
|
|
615
468
|
y: 0
|
|
616
|
-
}, h, l, t, i = 0; i <
|
|
617
|
-
t = (i + 1) %
|
|
618
|
-
return o.div(n, 6 *
|
|
619
|
-
}, e.mean = function(
|
|
620
|
-
for (var
|
|
469
|
+
}, h, l, t, i = 0; i < a.length; i++)
|
|
470
|
+
t = (i + 1) % a.length, h = o.cross(a[i], a[t]), l = o.mult(o.add(a[i], a[t]), h), n = o.add(n, l);
|
|
471
|
+
return o.div(n, 6 * u);
|
|
472
|
+
}, e.mean = function(a) {
|
|
473
|
+
for (var u = {
|
|
621
474
|
x: 0,
|
|
622
475
|
y: 0
|
|
623
|
-
}, n = 0; n <
|
|
624
|
-
|
|
625
|
-
return o.div(
|
|
626
|
-
}, e.area = function(
|
|
627
|
-
for (var n = 0, h =
|
|
628
|
-
n += (
|
|
629
|
-
return
|
|
630
|
-
}, e.inertia = function(
|
|
631
|
-
for (var n = 0, h = 0, l =
|
|
476
|
+
}, n = 0; n < a.length; n++)
|
|
477
|
+
u.x += a[n].x, u.y += a[n].y;
|
|
478
|
+
return o.div(u, a.length);
|
|
479
|
+
}, e.area = function(a, u) {
|
|
480
|
+
for (var n = 0, h = a.length - 1, l = 0; l < a.length; l++)
|
|
481
|
+
n += (a[h].x - a[l].x) * (a[h].y + a[l].y), h = l;
|
|
482
|
+
return u ? n / 2 : Math.abs(n) / 2;
|
|
483
|
+
}, e.inertia = function(a, u) {
|
|
484
|
+
for (var n = 0, h = 0, l = a, t, i, s = 0; s < l.length; s++)
|
|
632
485
|
i = (s + 1) % l.length, t = Math.abs(o.cross(l[i], l[s])), n += t * (o.dot(l[i], l[i]) + o.dot(l[i], l[s]) + o.dot(l[s], l[s])), h += t;
|
|
633
|
-
return
|
|
634
|
-
}, e.translate = function(
|
|
486
|
+
return u / 6 * (n / h);
|
|
487
|
+
}, e.translate = function(a, u, n) {
|
|
635
488
|
n = typeof n < "u" ? n : 1;
|
|
636
|
-
var h =
|
|
489
|
+
var h = a.length, l = u.x * n, t = u.y * n, i;
|
|
637
490
|
for (i = 0; i < h; i++)
|
|
638
|
-
|
|
639
|
-
return
|
|
640
|
-
}, e.rotate = function(
|
|
641
|
-
if (
|
|
642
|
-
var h = Math.cos(
|
|
491
|
+
a[i].x += l, a[i].y += t;
|
|
492
|
+
return a;
|
|
493
|
+
}, e.rotate = function(a, u, n) {
|
|
494
|
+
if (u !== 0) {
|
|
495
|
+
var h = Math.cos(u), l = Math.sin(u), t = n.x, i = n.y, s = a.length, f, m, x, P;
|
|
643
496
|
for (P = 0; P < s; P++)
|
|
644
|
-
|
|
645
|
-
return
|
|
497
|
+
f = a[P], m = f.x - t, x = f.y - i, f.x = t + (m * h - x * l), f.y = i + (m * l + x * h);
|
|
498
|
+
return a;
|
|
646
499
|
}
|
|
647
|
-
}, e.contains = function(
|
|
648
|
-
for (var n =
|
|
649
|
-
if (i =
|
|
500
|
+
}, e.contains = function(a, u) {
|
|
501
|
+
for (var n = u.x, h = u.y, l = a.length, t = a[l - 1], i, s = 0; s < l; s++) {
|
|
502
|
+
if (i = a[s], (n - t.x) * (i.y - t.y) + (h - t.y) * (t.x - i.x) > 0) return !1;
|
|
650
503
|
t = i;
|
|
651
504
|
}
|
|
652
505
|
return !0;
|
|
653
|
-
}, e.scale = function(
|
|
654
|
-
if (
|
|
655
|
-
h = h || e.centre(
|
|
656
|
-
for (var l, t, i = 0; i <
|
|
657
|
-
l =
|
|
658
|
-
return
|
|
659
|
-
}, e.chamfer = function(
|
|
660
|
-
typeof
|
|
661
|
-
for (var t = [], i = 0; i <
|
|
662
|
-
var s =
|
|
506
|
+
}, e.scale = function(a, u, n, h) {
|
|
507
|
+
if (u === 1 && n === 1) return a;
|
|
508
|
+
h = h || e.centre(a);
|
|
509
|
+
for (var l, t, i = 0; i < a.length; i++)
|
|
510
|
+
l = a[i], t = o.sub(l, h), a[i].x = h.x + t.x * u, a[i].y = h.y + t.y * n;
|
|
511
|
+
return a;
|
|
512
|
+
}, e.chamfer = function(a, u, n, h, l) {
|
|
513
|
+
typeof u == "number" ? u = [u] : u = u || [8], n = typeof n < "u" ? n : -1, h = h || 2, l = l || 14;
|
|
514
|
+
for (var t = [], i = 0; i < a.length; i++) {
|
|
515
|
+
var s = a[i - 1 >= 0 ? i - 1 : a.length - 1], f = a[i], m = a[(i + 1) % a.length], x = u[i < u.length ? i : u.length - 1];
|
|
663
516
|
if (x === 0) {
|
|
664
|
-
t.push(
|
|
517
|
+
t.push(f);
|
|
665
518
|
continue;
|
|
666
519
|
}
|
|
667
520
|
var P = o.normalise({
|
|
668
|
-
x:
|
|
669
|
-
y: s.x -
|
|
670
|
-
}),
|
|
671
|
-
x: m.y -
|
|
672
|
-
y:
|
|
673
|
-
}), g = Math.sqrt(2 * Math.pow(x, 2)),
|
|
674
|
-
n === -1 && (w = Math.pow(x, 0.32) * 1.75), w =
|
|
675
|
-
for (var S = Math.acos(o.dot(P,
|
|
521
|
+
x: f.y - s.y,
|
|
522
|
+
y: s.x - f.x
|
|
523
|
+
}), T = o.normalise({
|
|
524
|
+
x: m.y - f.y,
|
|
525
|
+
y: f.x - m.x
|
|
526
|
+
}), g = Math.sqrt(2 * Math.pow(x, 2)), d = o.mult(r.clone(P), x), y = o.normalise(o.mult(o.add(P, T), 0.5)), v = o.sub(f, o.mult(y, g)), w = n;
|
|
527
|
+
n === -1 && (w = Math.pow(x, 0.32) * 1.75), w = r.clamp(w, h, l), w % 2 === 1 && (w += 1);
|
|
528
|
+
for (var S = Math.acos(o.dot(P, T)) / w, C = 0; C < w; C++) t.push(o.add(o.rotate(d, S * C), v));
|
|
676
529
|
}
|
|
677
530
|
return t;
|
|
678
|
-
}, e.clockwiseSort = function(
|
|
679
|
-
var
|
|
680
|
-
return
|
|
681
|
-
return o.angle(
|
|
682
|
-
}),
|
|
683
|
-
}, e.isConvex = function(
|
|
684
|
-
var
|
|
531
|
+
}, e.clockwiseSort = function(a) {
|
|
532
|
+
var u = e.mean(a);
|
|
533
|
+
return a.sort(function(n, h) {
|
|
534
|
+
return o.angle(u, n) - o.angle(u, h);
|
|
535
|
+
}), a;
|
|
536
|
+
}, e.isConvex = function(a) {
|
|
537
|
+
var u = 0, n = a.length, h, l, t, i;
|
|
685
538
|
if (n < 3) return null;
|
|
686
539
|
for (h = 0; h < n; h++)
|
|
687
|
-
if (l = (h + 1) % n, t = (h + 2) % n, i = (
|
|
688
|
-
return
|
|
689
|
-
}, e.hull = function(
|
|
690
|
-
var
|
|
691
|
-
for (
|
|
540
|
+
if (l = (h + 1) % n, t = (h + 2) % n, i = (a[l].x - a[h].x) * (a[t].y - a[l].y), i -= (a[l].y - a[h].y) * (a[t].x - a[l].x), i < 0 ? u |= 1 : i > 0 && (u |= 2), u === 3) return !1;
|
|
541
|
+
return u !== 0 ? !0 : null;
|
|
542
|
+
}, e.hull = function(a) {
|
|
543
|
+
var u = [], n = [], h, l;
|
|
544
|
+
for (a = a.slice(0), a.sort(function(t, i) {
|
|
692
545
|
var s = t.x - i.x;
|
|
693
546
|
return s !== 0 ? s : t.y - i.y;
|
|
694
|
-
}), l = 0; l <
|
|
695
|
-
for (h =
|
|
547
|
+
}), l = 0; l < a.length; l += 1) {
|
|
548
|
+
for (h = a[l]; n.length >= 2 && o.cross3(n[n.length - 2], n[n.length - 1], h) <= 0; ) n.pop();
|
|
696
549
|
n.push(h);
|
|
697
550
|
}
|
|
698
|
-
for (l =
|
|
699
|
-
for (h =
|
|
700
|
-
|
|
551
|
+
for (l = a.length - 1; l >= 0; l -= 1) {
|
|
552
|
+
for (h = a[l]; u.length >= 2 && o.cross3(u[u.length - 2], u[u.length - 1], h) <= 0; ) u.pop();
|
|
553
|
+
u.push(h);
|
|
701
554
|
}
|
|
702
|
-
return
|
|
555
|
+
return u.pop(), n.pop(), u.concat(n);
|
|
703
556
|
};
|
|
704
557
|
})();
|
|
705
558
|
}),
|
|
706
|
-
(function(
|
|
559
|
+
(function(A, E, c) {
|
|
707
560
|
var e = {};
|
|
708
|
-
|
|
709
|
-
var o =
|
|
561
|
+
A.exports = e;
|
|
562
|
+
var o = c(3), r = c(2), a = c(7), u = c(0), n = c(1), h = c(11);
|
|
710
563
|
(function() {
|
|
711
564
|
e._timeCorrection = !0, e._inertiaScale = 4, e._nextCollidingGroupId = 1, e._nextNonCollidingGroupId = -1, e._nextCategory = 1, e._baseDelta = 1e3 / 60, e.create = function(t) {
|
|
712
565
|
var i = {
|
|
713
|
-
id:
|
|
566
|
+
id: u.nextId(),
|
|
714
567
|
type: "body",
|
|
715
568
|
label: "Body",
|
|
716
569
|
parts: [],
|
|
@@ -786,7 +639,7 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
786
639
|
inertia: 0,
|
|
787
640
|
deltaTime: 16.666666666666668,
|
|
788
641
|
_original: null
|
|
789
|
-
}, s =
|
|
642
|
+
}, s = u.extend(i, t);
|
|
790
643
|
return l(s, t), s;
|
|
791
644
|
}, e.nextGroup = function(t) {
|
|
792
645
|
return t ? e._nextNonCollidingGroupId-- : e._nextCollidingGroupId++;
|
|
@@ -796,7 +649,7 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
796
649
|
var l = function(t, i) {
|
|
797
650
|
i = i || {}, e.set(t, {
|
|
798
651
|
bounds: t.bounds || n.create(t.vertices),
|
|
799
|
-
positionPrev: t.positionPrev ||
|
|
652
|
+
positionPrev: t.positionPrev || r.clone(t.position),
|
|
800
653
|
anglePrev: t.anglePrev || t.angle,
|
|
801
654
|
vertices: t.vertices,
|
|
802
655
|
parts: t.parts || [t],
|
|
@@ -809,26 +662,26 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
809
662
|
mass: i.mass || t.mass,
|
|
810
663
|
inertia: i.inertia || t.inertia
|
|
811
664
|
});
|
|
812
|
-
var s = t.isStatic ? "#14151f" :
|
|
665
|
+
var s = t.isStatic ? "#14151f" : u.choose([
|
|
813
666
|
"#f19648",
|
|
814
667
|
"#f5d259",
|
|
815
668
|
"#f55a3c",
|
|
816
669
|
"#063e7b",
|
|
817
670
|
"#ececd1"
|
|
818
|
-
]),
|
|
819
|
-
t.render.fillStyle = t.render.fillStyle || s, t.render.strokeStyle = t.render.strokeStyle ||
|
|
671
|
+
]), f = t.isStatic ? "#555" : "#ccc", m = t.isStatic && t.render.fillStyle === null ? 1 : 0;
|
|
672
|
+
t.render.fillStyle = t.render.fillStyle || s, t.render.strokeStyle = t.render.strokeStyle || f, t.render.lineWidth = t.render.lineWidth || m, t.render.sprite.xOffset += -(t.bounds.min.x - t.position.x) / (t.bounds.max.x - t.bounds.min.x), t.render.sprite.yOffset += -(t.bounds.min.y - t.position.y) / (t.bounds.max.y - t.bounds.min.y);
|
|
820
673
|
};
|
|
821
674
|
e.set = function(t, i, s) {
|
|
822
|
-
var
|
|
823
|
-
typeof i == "string" && (
|
|
824
|
-
for (
|
|
825
|
-
if (Object.prototype.hasOwnProperty.call(i,
|
|
826
|
-
switch (s = i[
|
|
675
|
+
var f;
|
|
676
|
+
typeof i == "string" && (f = i, i = {}, i[f] = s);
|
|
677
|
+
for (f in i)
|
|
678
|
+
if (Object.prototype.hasOwnProperty.call(i, f))
|
|
679
|
+
switch (s = i[f], f) {
|
|
827
680
|
case "isStatic":
|
|
828
681
|
e.setStatic(t, s);
|
|
829
682
|
break;
|
|
830
683
|
case "isSleeping":
|
|
831
|
-
|
|
684
|
+
a.set(t, s);
|
|
832
685
|
break;
|
|
833
686
|
case "mass":
|
|
834
687
|
e.setMass(t, s);
|
|
@@ -867,20 +720,20 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
867
720
|
e.setCentre(t, s);
|
|
868
721
|
break;
|
|
869
722
|
default:
|
|
870
|
-
t[
|
|
723
|
+
t[f] = s;
|
|
871
724
|
}
|
|
872
725
|
}, e.setStatic = function(t, i) {
|
|
873
726
|
for (var s = 0; s < t.parts.length; s++) {
|
|
874
|
-
var
|
|
875
|
-
i ? (
|
|
876
|
-
restitution:
|
|
877
|
-
friction:
|
|
878
|
-
mass:
|
|
879
|
-
inertia:
|
|
880
|
-
density:
|
|
881
|
-
inverseMass:
|
|
882
|
-
inverseInertia:
|
|
883
|
-
}),
|
|
727
|
+
var f = t.parts[s];
|
|
728
|
+
i ? (f.isStatic || (f._original = {
|
|
729
|
+
restitution: f.restitution,
|
|
730
|
+
friction: f.friction,
|
|
731
|
+
mass: f.mass,
|
|
732
|
+
inertia: f.inertia,
|
|
733
|
+
density: f.density,
|
|
734
|
+
inverseMass: f.inverseMass,
|
|
735
|
+
inverseInertia: f.inverseInertia
|
|
736
|
+
}), f.restitution = 0, f.friction = 1, f.mass = f.inertia = f.density = 1 / 0, f.inverseMass = f.inverseInertia = 0, f.positionPrev.x = f.position.x, f.positionPrev.y = f.position.y, f.anglePrev = f.angle, f.angularVelocity = 0, f.speed = 0, f.angularSpeed = 0, f.motion = 0) : f._original && (f.restitution = f._original.restitution, f.friction = f._original.friction, f.mass = f._original.mass, f.inertia = f._original.inertia, f.density = f._original.density, f.inverseMass = f._original.inverseMass, f.inverseInertia = f._original.inverseInertia, f._original = null), f.isStatic = i;
|
|
884
737
|
}
|
|
885
738
|
}, e.setMass = function(t, i) {
|
|
886
739
|
t.inertia = t.inertia / (t.mass / 6) * (i / 6), t.inverseInertia = 1 / t.inertia, t.mass = i, t.inverseMass = 1 / t.mass, t.density = t.mass / t.area;
|
|
@@ -893,18 +746,18 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
893
746
|
var s = o.centre(t.vertices);
|
|
894
747
|
o.translate(t.vertices, s, -1), e.setInertia(t, e._inertiaScale * o.inertia(t.vertices, t.mass)), o.translate(t.vertices, t.position), n.update(t.bounds, t.vertices, t.velocity);
|
|
895
748
|
}, e.setParts = function(t, i, s) {
|
|
896
|
-
var
|
|
897
|
-
for (i = i.slice(0), t.parts.length = 0, t.parts.push(t), t.parent = t,
|
|
898
|
-
var m = i[
|
|
749
|
+
var f;
|
|
750
|
+
for (i = i.slice(0), t.parts.length = 0, t.parts.push(t), t.parent = t, f = 0; f < i.length; f++) {
|
|
751
|
+
var m = i[f];
|
|
899
752
|
m !== t && (m.parent = t, t.parts.push(m));
|
|
900
753
|
}
|
|
901
754
|
if (t.parts.length !== 1) {
|
|
902
755
|
if (s = typeof s < "u" ? s : !0, s) {
|
|
903
756
|
var x = [];
|
|
904
|
-
for (
|
|
757
|
+
for (f = 0; f < i.length; f++) x = x.concat(i[f].vertices);
|
|
905
758
|
o.clockwiseSort(x);
|
|
906
|
-
var P = o.hull(x),
|
|
907
|
-
e.setVertices(t, P), o.translate(t.vertices,
|
|
759
|
+
var P = o.hull(x), T = o.centre(P);
|
|
760
|
+
e.setVertices(t, P), o.translate(t.vertices, T);
|
|
908
761
|
}
|
|
909
762
|
var g = e._totalProperties(t);
|
|
910
763
|
t.area = g.area, t.parent = t, t.position.x = g.centre.x, t.position.y = g.centre.y, t.positionPrev.x = g.centre.x, t.positionPrev.y = g.centre.y, e.setMass(t, g.mass), e.setInertia(t, g.inertia), e.setPosition(t, g.centre);
|
|
@@ -912,22 +765,22 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
912
765
|
}, e.setCentre = function(t, i, s) {
|
|
913
766
|
s ? (t.positionPrev.x += i.x, t.positionPrev.y += i.y, t.position.x += i.x, t.position.y += i.y) : (t.positionPrev.x = i.x - (t.position.x - t.positionPrev.x), t.positionPrev.y = i.y - (t.position.y - t.positionPrev.y), t.position.x = i.x, t.position.y = i.y);
|
|
914
767
|
}, e.setPosition = function(t, i, s) {
|
|
915
|
-
var
|
|
916
|
-
s ? (t.positionPrev.x = t.position.x, t.positionPrev.y = t.position.y, t.velocity.x =
|
|
768
|
+
var f = r.sub(i, t.position);
|
|
769
|
+
s ? (t.positionPrev.x = t.position.x, t.positionPrev.y = t.position.y, t.velocity.x = f.x, t.velocity.y = f.y, t.speed = r.magnitude(f)) : (t.positionPrev.x += f.x, t.positionPrev.y += f.y);
|
|
917
770
|
for (var m = 0; m < t.parts.length; m++) {
|
|
918
771
|
var x = t.parts[m];
|
|
919
|
-
x.position.x +=
|
|
772
|
+
x.position.x += f.x, x.position.y += f.y, o.translate(x.vertices, f), n.update(x.bounds, x.vertices, t.velocity);
|
|
920
773
|
}
|
|
921
774
|
}, e.setAngle = function(t, i, s) {
|
|
922
|
-
var
|
|
923
|
-
s ? (t.anglePrev = t.angle, t.angularVelocity =
|
|
775
|
+
var f = i - t.angle;
|
|
776
|
+
s ? (t.anglePrev = t.angle, t.angularVelocity = f, t.angularSpeed = Math.abs(f)) : t.anglePrev += f;
|
|
924
777
|
for (var m = 0; m < t.parts.length; m++) {
|
|
925
778
|
var x = t.parts[m];
|
|
926
|
-
x.angle +=
|
|
779
|
+
x.angle += f, o.rotate(x.vertices, f, t.position), h.rotate(x.axes, f), n.update(x.bounds, x.vertices, t.velocity), m > 0 && r.rotateAbout(x.position, f, t.position, x.position);
|
|
927
780
|
}
|
|
928
781
|
}, e.setVelocity = function(t, i) {
|
|
929
782
|
var s = t.deltaTime / e._baseDelta;
|
|
930
|
-
t.positionPrev.x = t.position.x - i.x * s, t.positionPrev.y = t.position.y - i.y * s, t.velocity.x = (t.position.x - t.positionPrev.x) / s, t.velocity.y = (t.position.y - t.positionPrev.y) / s, t.speed =
|
|
783
|
+
t.positionPrev.x = t.position.x - i.x * s, t.positionPrev.y = t.position.y - i.y * s, t.velocity.x = (t.position.x - t.positionPrev.x) / s, t.velocity.y = (t.position.y - t.positionPrev.y) / s, t.speed = r.magnitude(t.velocity);
|
|
931
784
|
}, e.getVelocity = function(t) {
|
|
932
785
|
var i = e._baseDelta / t.deltaTime;
|
|
933
786
|
return {
|
|
@@ -935,9 +788,9 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
935
788
|
y: (t.position.y - t.positionPrev.y) * i
|
|
936
789
|
};
|
|
937
790
|
}, e.getSpeed = function(t) {
|
|
938
|
-
return
|
|
791
|
+
return r.magnitude(e.getVelocity(t));
|
|
939
792
|
}, e.setSpeed = function(t, i) {
|
|
940
|
-
e.setVelocity(t,
|
|
793
|
+
e.setVelocity(t, r.mult(r.normalise(e.getVelocity(t)), i));
|
|
941
794
|
}, e.setAngularVelocity = function(t, i) {
|
|
942
795
|
var s = t.deltaTime / e._baseDelta;
|
|
943
796
|
t.anglePrev = t.angle - i * s, t.angularVelocity = (t.angle - t.anglePrev) / s, t.angularSpeed = Math.abs(t.angularVelocity);
|
|
@@ -946,49 +799,49 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
946
799
|
}, e.getAngularSpeed = function(t) {
|
|
947
800
|
return Math.abs(e.getAngularVelocity(t));
|
|
948
801
|
}, e.setAngularSpeed = function(t, i) {
|
|
949
|
-
e.setAngularVelocity(t,
|
|
802
|
+
e.setAngularVelocity(t, u.sign(e.getAngularVelocity(t)) * i);
|
|
950
803
|
}, e.translate = function(t, i, s) {
|
|
951
|
-
e.setPosition(t,
|
|
952
|
-
}, e.rotate = function(t, i, s,
|
|
953
|
-
if (!s) e.setAngle(t, t.angle + i,
|
|
804
|
+
e.setPosition(t, r.add(t.position, i), s);
|
|
805
|
+
}, e.rotate = function(t, i, s, f) {
|
|
806
|
+
if (!s) e.setAngle(t, t.angle + i, f);
|
|
954
807
|
else {
|
|
955
|
-
var m = Math.cos(i), x = Math.sin(i), P = t.position.x - s.x,
|
|
808
|
+
var m = Math.cos(i), x = Math.sin(i), P = t.position.x - s.x, T = t.position.y - s.y;
|
|
956
809
|
e.setPosition(t, {
|
|
957
|
-
x: s.x + (P * m -
|
|
958
|
-
y: s.y + (P * x +
|
|
959
|
-
},
|
|
810
|
+
x: s.x + (P * m - T * x),
|
|
811
|
+
y: s.y + (P * x + T * m)
|
|
812
|
+
}, f), e.setAngle(t, t.angle + i, f);
|
|
960
813
|
}
|
|
961
|
-
}, e.scale = function(t, i, s,
|
|
814
|
+
}, e.scale = function(t, i, s, f) {
|
|
962
815
|
var m = 0, x = 0;
|
|
963
|
-
|
|
816
|
+
f = f || t.position;
|
|
964
817
|
for (var P = 0; P < t.parts.length; P++) {
|
|
965
|
-
var
|
|
966
|
-
o.scale(
|
|
967
|
-
x: -
|
|
968
|
-
y: -
|
|
969
|
-
}), e.setInertia(
|
|
970
|
-
x:
|
|
971
|
-
y:
|
|
972
|
-
}), P > 0 && (m +=
|
|
818
|
+
var T = t.parts[P];
|
|
819
|
+
o.scale(T.vertices, i, s, f), T.axes = h.fromVertices(T.vertices), T.area = o.area(T.vertices), e.setMass(T, t.density * T.area), o.translate(T.vertices, {
|
|
820
|
+
x: -T.position.x,
|
|
821
|
+
y: -T.position.y
|
|
822
|
+
}), e.setInertia(T, e._inertiaScale * o.inertia(T.vertices, T.mass)), o.translate(T.vertices, {
|
|
823
|
+
x: T.position.x,
|
|
824
|
+
y: T.position.y
|
|
825
|
+
}), P > 0 && (m += T.area, x += T.inertia), T.position.x = f.x + (T.position.x - f.x) * i, T.position.y = f.y + (T.position.y - f.y) * s, n.update(T.bounds, T.vertices, t.velocity);
|
|
973
826
|
}
|
|
974
827
|
t.parts.length > 1 && (t.area = m, t.isStatic || (e.setMass(t, t.density * m), e.setInertia(t, x))), t.circleRadius && (i === s ? t.circleRadius *= i : t.circleRadius = null);
|
|
975
828
|
}, e.update = function(t, i) {
|
|
976
829
|
i = (typeof i < "u" ? i : 1e3 / 60) * t.timeScale;
|
|
977
|
-
var s = i * i,
|
|
978
|
-
t.velocity.x = x * m + t.force.x / t.mass * s, t.velocity.y = P * m + t.force.y / t.mass * s, t.positionPrev.x = t.position.x, t.positionPrev.y = t.position.y, t.position.x += t.velocity.x, t.position.y += t.velocity.y, t.deltaTime = i, t.angularVelocity = (t.angle - t.anglePrev) * m *
|
|
979
|
-
for (var
|
|
980
|
-
var g = t.parts[
|
|
981
|
-
o.translate(g.vertices, t.velocity),
|
|
830
|
+
var s = i * i, f = e._timeCorrection ? i / (t.deltaTime || i) : 1, m = 1 - t.frictionAir * (i / u._baseDelta), x = (t.position.x - t.positionPrev.x) * f, P = (t.position.y - t.positionPrev.y) * f;
|
|
831
|
+
t.velocity.x = x * m + t.force.x / t.mass * s, t.velocity.y = P * m + t.force.y / t.mass * s, t.positionPrev.x = t.position.x, t.positionPrev.y = t.position.y, t.position.x += t.velocity.x, t.position.y += t.velocity.y, t.deltaTime = i, t.angularVelocity = (t.angle - t.anglePrev) * m * f + t.torque / t.inertia * s, t.anglePrev = t.angle, t.angle += t.angularVelocity;
|
|
832
|
+
for (var T = 0; T < t.parts.length; T++) {
|
|
833
|
+
var g = t.parts[T];
|
|
834
|
+
o.translate(g.vertices, t.velocity), T > 0 && (g.position.x += t.velocity.x, g.position.y += t.velocity.y), t.angularVelocity !== 0 && (o.rotate(g.vertices, t.angularVelocity, t.position), h.rotate(g.axes, t.angularVelocity), T > 0 && r.rotateAbout(g.position, t.angularVelocity, t.position, g.position)), n.update(g.bounds, g.vertices, t.velocity);
|
|
982
835
|
}
|
|
983
836
|
}, e.updateVelocities = function(t) {
|
|
984
837
|
var i = e._baseDelta / t.deltaTime, s = t.velocity;
|
|
985
838
|
s.x = (t.position.x - t.positionPrev.x) * i, s.y = (t.position.y - t.positionPrev.y) * i, t.speed = Math.sqrt(s.x * s.x + s.y * s.y), t.angularVelocity = (t.angle - t.anglePrev) * i, t.angularSpeed = Math.abs(t.angularVelocity);
|
|
986
839
|
}, e.applyForce = function(t, i, s) {
|
|
987
|
-
var
|
|
840
|
+
var f = {
|
|
988
841
|
x: i.x - t.position.x,
|
|
989
842
|
y: i.y - t.position.y
|
|
990
843
|
};
|
|
991
|
-
t.force.x += s.x, t.force.y += s.y, t.torque +=
|
|
844
|
+
t.force.x += s.x, t.force.y += s.y, t.torque += f.x * s.y - f.y * s.x;
|
|
992
845
|
}, e._totalProperties = function(t) {
|
|
993
846
|
for (var i = {
|
|
994
847
|
mass: 0,
|
|
@@ -999,55 +852,55 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
999
852
|
y: 0
|
|
1000
853
|
}
|
|
1001
854
|
}, s = t.parts.length === 1 ? 0 : 1; s < t.parts.length; s++) {
|
|
1002
|
-
var
|
|
1003
|
-
i.mass += m, i.area +=
|
|
855
|
+
var f = t.parts[s], m = f.mass !== 1 / 0 ? f.mass : 1;
|
|
856
|
+
i.mass += m, i.area += f.area, i.inertia += f.inertia, i.centre = r.add(i.centre, r.mult(f.position, m));
|
|
1004
857
|
}
|
|
1005
|
-
return i.centre =
|
|
858
|
+
return i.centre = r.div(i.centre, i.mass), i;
|
|
1006
859
|
};
|
|
1007
860
|
})();
|
|
1008
861
|
}),
|
|
1009
|
-
(function(
|
|
862
|
+
(function(A, E, c) {
|
|
1010
863
|
var e = {};
|
|
1011
|
-
|
|
1012
|
-
var o =
|
|
864
|
+
A.exports = e;
|
|
865
|
+
var o = c(0);
|
|
1013
866
|
(function() {
|
|
1014
|
-
e.on = function(
|
|
1015
|
-
for (var n =
|
|
1016
|
-
h = n[l],
|
|
1017
|
-
return
|
|
1018
|
-
}, e.off = function(
|
|
1019
|
-
if (!
|
|
1020
|
-
|
|
867
|
+
e.on = function(r, a, u) {
|
|
868
|
+
for (var n = a.split(" "), h, l = 0; l < n.length; l++)
|
|
869
|
+
h = n[l], r.events = r.events || {}, r.events[h] = r.events[h] || [], r.events[h].push(u);
|
|
870
|
+
return u;
|
|
871
|
+
}, e.off = function(r, a, u) {
|
|
872
|
+
if (!a) {
|
|
873
|
+
r.events = {};
|
|
1021
874
|
return;
|
|
1022
875
|
}
|
|
1023
|
-
typeof
|
|
1024
|
-
for (var n =
|
|
1025
|
-
var l =
|
|
1026
|
-
if (
|
|
1027
|
-
for (var i = 0; i < l.length; i++) l[i] !==
|
|
1028
|
-
|
|
876
|
+
typeof a == "function" && (u = a, a = o.keys(r.events).join(" "));
|
|
877
|
+
for (var n = a.split(" "), h = 0; h < n.length; h++) {
|
|
878
|
+
var l = r.events[n[h]], t = [];
|
|
879
|
+
if (u && l)
|
|
880
|
+
for (var i = 0; i < l.length; i++) l[i] !== u && t.push(l[i]);
|
|
881
|
+
r.events[n[h]] = t;
|
|
1029
882
|
}
|
|
1030
|
-
}, e.trigger = function(
|
|
1031
|
-
var n, h, l, t, i =
|
|
883
|
+
}, e.trigger = function(r, a, u) {
|
|
884
|
+
var n, h, l, t, i = r.events;
|
|
1032
885
|
if (i && o.keys(i).length > 0) {
|
|
1033
|
-
|
|
886
|
+
u || (u = {}), n = a.split(" ");
|
|
1034
887
|
for (var s = 0; s < n.length; s++)
|
|
1035
888
|
if (h = n[s], l = i[h], l) {
|
|
1036
|
-
t = o.clone(
|
|
1037
|
-
for (var
|
|
889
|
+
t = o.clone(u, !1), t.name = h, t.source = r;
|
|
890
|
+
for (var f = 0; f < l.length; f++) l[f].apply(r, [t]);
|
|
1038
891
|
}
|
|
1039
892
|
}
|
|
1040
893
|
};
|
|
1041
894
|
})();
|
|
1042
895
|
}),
|
|
1043
|
-
(function(
|
|
896
|
+
(function(A, E, c) {
|
|
1044
897
|
var e = {};
|
|
1045
|
-
|
|
1046
|
-
var o =
|
|
898
|
+
A.exports = e;
|
|
899
|
+
var o = c(5), r = c(0), a = c(1), u = c(4);
|
|
1047
900
|
(function() {
|
|
1048
901
|
e.create = function(n) {
|
|
1049
|
-
return
|
|
1050
|
-
id:
|
|
902
|
+
return r.extend({
|
|
903
|
+
id: r.nextId(),
|
|
1051
904
|
type: "composite",
|
|
1052
905
|
parent: null,
|
|
1053
906
|
isModified: !1,
|
|
@@ -1075,7 +928,7 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
1075
928
|
switch (i.type) {
|
|
1076
929
|
case "body":
|
|
1077
930
|
if (i.parent !== i) {
|
|
1078
|
-
|
|
931
|
+
r.warn("Composite.add: skipped adding a compound body part (you must add its parent instead)");
|
|
1079
932
|
break;
|
|
1080
933
|
}
|
|
1081
934
|
e.addBody(n, i);
|
|
@@ -1116,7 +969,7 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
1116
969
|
}, e.addComposite = function(n, h) {
|
|
1117
970
|
return n.composites.push(h), h.parent = n, e.setModified(n, !0, !0, !1), n;
|
|
1118
971
|
}, e.removeComposite = function(n, h, l) {
|
|
1119
|
-
var t =
|
|
972
|
+
var t = r.indexOf(n.composites, h);
|
|
1120
973
|
if (t !== -1) {
|
|
1121
974
|
var i = e.allBodies(h);
|
|
1122
975
|
e.removeCompositeAt(n, t);
|
|
@@ -1129,7 +982,7 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
1129
982
|
}, e.addBody = function(n, h) {
|
|
1130
983
|
return n.bodies.push(h), e.setModified(n, !0, !0, !1), n;
|
|
1131
984
|
}, e.removeBody = function(n, h, l) {
|
|
1132
|
-
var t =
|
|
985
|
+
var t = r.indexOf(n.bodies, h);
|
|
1133
986
|
if (t !== -1 && (e.removeBodyAt(n, t), h.sleepCounter = 0), l) for (var i = 0; i < n.composites.length; i++) e.removeBody(n.composites[i], h, !0);
|
|
1134
987
|
return n;
|
|
1135
988
|
}, e.removeBodyAt = function(n, h) {
|
|
@@ -1137,7 +990,7 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
1137
990
|
}, e.addConstraint = function(n, h) {
|
|
1138
991
|
return n.constraints.push(h), e.setModified(n, !0, !0, !1), n;
|
|
1139
992
|
}, e.removeConstraint = function(n, h, l) {
|
|
1140
|
-
var t =
|
|
993
|
+
var t = r.indexOf(n.constraints, h);
|
|
1141
994
|
if (t !== -1 && e.removeConstraintAt(n, t), l) for (var i = 0; i < n.composites.length; i++) e.removeConstraint(n.composites[i], h, !0);
|
|
1142
995
|
return n;
|
|
1143
996
|
}, e.removeConstraintAt = function(n, h) {
|
|
@@ -1178,27 +1031,27 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
1178
1031
|
}, e.move = function(n, h, l) {
|
|
1179
1032
|
return e.remove(n, h), e.add(l, h), n;
|
|
1180
1033
|
}, e.rebase = function(n) {
|
|
1181
|
-
for (var h = e.allBodies(n).concat(e.allConstraints(n)).concat(e.allComposites(n)), l = 0; l < h.length; l++) h[l].id =
|
|
1034
|
+
for (var h = e.allBodies(n).concat(e.allConstraints(n)).concat(e.allComposites(n)), l = 0; l < h.length; l++) h[l].id = r.nextId();
|
|
1182
1035
|
return n;
|
|
1183
1036
|
}, e.translate = function(n, h, l) {
|
|
1184
|
-
for (var t = l ? e.allBodies(n) : n.bodies, i = 0; i < t.length; i++)
|
|
1037
|
+
for (var t = l ? e.allBodies(n) : n.bodies, i = 0; i < t.length; i++) u.translate(t[i], h);
|
|
1185
1038
|
return n;
|
|
1186
1039
|
}, e.rotate = function(n, h, l, t) {
|
|
1187
|
-
for (var i = Math.cos(h), s = Math.sin(h),
|
|
1188
|
-
var x =
|
|
1189
|
-
|
|
1190
|
-
x: l.x + (P * i -
|
|
1191
|
-
y: l.y + (P * s +
|
|
1192
|
-
}),
|
|
1040
|
+
for (var i = Math.cos(h), s = Math.sin(h), f = t ? e.allBodies(n) : n.bodies, m = 0; m < f.length; m++) {
|
|
1041
|
+
var x = f[m], P = x.position.x - l.x, T = x.position.y - l.y;
|
|
1042
|
+
u.setPosition(x, {
|
|
1043
|
+
x: l.x + (P * i - T * s),
|
|
1044
|
+
y: l.y + (P * s + T * i)
|
|
1045
|
+
}), u.rotate(x, h);
|
|
1193
1046
|
}
|
|
1194
1047
|
return n;
|
|
1195
1048
|
}, e.scale = function(n, h, l, t, i) {
|
|
1196
|
-
for (var s = i ? e.allBodies(n) : n.bodies,
|
|
1197
|
-
var m = s[
|
|
1198
|
-
|
|
1049
|
+
for (var s = i ? e.allBodies(n) : n.bodies, f = 0; f < s.length; f++) {
|
|
1050
|
+
var m = s[f], x = m.position.x - t.x, P = m.position.y - t.y;
|
|
1051
|
+
u.setPosition(m, {
|
|
1199
1052
|
x: t.x + x * h,
|
|
1200
1053
|
y: t.y + P * l
|
|
1201
|
-
}),
|
|
1054
|
+
}), u.scale(m, h, l);
|
|
1202
1055
|
}
|
|
1203
1056
|
return n;
|
|
1204
1057
|
}, e.bounds = function(n) {
|
|
@@ -1206,18 +1059,18 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
1206
1059
|
var i = h[t];
|
|
1207
1060
|
l.push(i.bounds.min, i.bounds.max);
|
|
1208
1061
|
}
|
|
1209
|
-
return
|
|
1062
|
+
return a.create(l);
|
|
1210
1063
|
};
|
|
1211
1064
|
})();
|
|
1212
1065
|
}),
|
|
1213
|
-
(function(
|
|
1066
|
+
(function(A, E, c) {
|
|
1214
1067
|
var e = {};
|
|
1215
|
-
|
|
1216
|
-
var o =
|
|
1068
|
+
A.exports = e;
|
|
1069
|
+
var o = c(4), r = c(5), a = c(0);
|
|
1217
1070
|
(function() {
|
|
1218
|
-
e._motionWakeThreshold = 0.18, e._motionSleepThreshold = 0.08, e._minBias = 0.9, e.update = function(
|
|
1219
|
-
for (var h = n /
|
|
1220
|
-
var i =
|
|
1071
|
+
e._motionWakeThreshold = 0.18, e._motionSleepThreshold = 0.08, e._minBias = 0.9, e.update = function(u, n) {
|
|
1072
|
+
for (var h = n / a._baseDelta, l = e._motionSleepThreshold, t = 0; t < u.length; t++) {
|
|
1073
|
+
var i = u[t], s = o.getSpeed(i), f = o.getAngularSpeed(i), m = s * s + f * f;
|
|
1221
1074
|
if (i.force.x !== 0 || i.force.y !== 0) {
|
|
1222
1075
|
e.set(i, !1);
|
|
1223
1076
|
continue;
|
|
@@ -1225,29 +1078,29 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
1225
1078
|
var x = Math.min(i.motion, m), P = Math.max(i.motion, m);
|
|
1226
1079
|
i.motion = e._minBias * x + (1 - e._minBias) * P, i.sleepThreshold > 0 && i.motion < l ? (i.sleepCounter += 1, i.sleepCounter >= i.sleepThreshold / h && e.set(i, !0)) : i.sleepCounter > 0 && (i.sleepCounter -= 1);
|
|
1227
1080
|
}
|
|
1228
|
-
}, e.afterCollisions = function(
|
|
1229
|
-
for (var n = e._motionSleepThreshold, h = 0; h <
|
|
1230
|
-
var l =
|
|
1081
|
+
}, e.afterCollisions = function(u) {
|
|
1082
|
+
for (var n = e._motionSleepThreshold, h = 0; h < u.length; h++) {
|
|
1083
|
+
var l = u[h];
|
|
1231
1084
|
if (l.isActive) {
|
|
1232
1085
|
var t = l.collision, i = t.bodyA.parent, s = t.bodyB.parent;
|
|
1233
1086
|
if (!(i.isSleeping && s.isSleeping || i.isStatic || s.isStatic) && (i.isSleeping || s.isSleeping)) {
|
|
1234
|
-
var
|
|
1235
|
-
!
|
|
1087
|
+
var f = i.isSleeping && !i.isStatic ? i : s, m = f === i ? s : i;
|
|
1088
|
+
!f.isStatic && m.motion > n && e.set(f, !1);
|
|
1236
1089
|
}
|
|
1237
1090
|
}
|
|
1238
1091
|
}
|
|
1239
|
-
}, e.set = function(
|
|
1240
|
-
var h =
|
|
1241
|
-
n ? (
|
|
1092
|
+
}, e.set = function(u, n) {
|
|
1093
|
+
var h = u.isSleeping;
|
|
1094
|
+
n ? (u.isSleeping = !0, u.sleepCounter = u.sleepThreshold, u.positionImpulse.x = 0, u.positionImpulse.y = 0, u.positionPrev.x = u.position.x, u.positionPrev.y = u.position.y, u.anglePrev = u.angle, u.speed = 0, u.angularSpeed = 0, u.motion = 0, h || r.trigger(u, "sleepStart")) : (u.isSleeping = !1, u.sleepCounter = 0, h && r.trigger(u, "sleepEnd"));
|
|
1242
1095
|
};
|
|
1243
1096
|
})();
|
|
1244
1097
|
}),
|
|
1245
|
-
(function(
|
|
1098
|
+
(function(A, E, c) {
|
|
1246
1099
|
var e = {};
|
|
1247
|
-
|
|
1248
|
-
var o =
|
|
1100
|
+
A.exports = e;
|
|
1101
|
+
var o = c(3), r = c(9);
|
|
1249
1102
|
(function() {
|
|
1250
|
-
var
|
|
1103
|
+
var a = [], u = {
|
|
1251
1104
|
overlap: 0,
|
|
1252
1105
|
axis: null
|
|
1253
1106
|
}, n = {
|
|
@@ -1279,80 +1132,80 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
1279
1132
|
supportCount: 0
|
|
1280
1133
|
};
|
|
1281
1134
|
}, e.collides = function(h, l, t) {
|
|
1282
|
-
if (e._overlapAxes(
|
|
1283
|
-
var i = t && t.table[
|
|
1135
|
+
if (e._overlapAxes(u, h.vertices, l.vertices, h.axes), u.overlap <= 0 || (e._overlapAxes(n, l.vertices, h.vertices, l.axes), n.overlap <= 0)) return null;
|
|
1136
|
+
var i = t && t.table[r.id(h, l)], s;
|
|
1284
1137
|
i ? s = i.collision : (s = e.create(h, l), s.collided = !0, s.bodyA = h.id < l.id ? h : l, s.bodyB = h.id < l.id ? l : h, s.parentA = s.bodyA.parent, s.parentB = s.bodyB.parent), h = s.bodyA, l = s.bodyB;
|
|
1285
|
-
var
|
|
1286
|
-
|
|
1287
|
-
var m = s.normal, x = s.tangent, P = s.penetration,
|
|
1138
|
+
var f;
|
|
1139
|
+
u.overlap < n.overlap ? f = u : f = n;
|
|
1140
|
+
var m = s.normal, x = s.tangent, P = s.penetration, T = s.supports, g = f.overlap, d = f.axis, y = d.x, v = d.y, w = l.position.x - h.position.x, S = l.position.y - h.position.y;
|
|
1288
1141
|
y * w + v * S >= 0 && (y = -y, v = -v), m.x = y, m.y = v, x.x = -v, x.y = y, P.x = y * g, P.y = v * g, s.depth = g;
|
|
1289
1142
|
var C = e._findSupports(h, l, m, 1), M = 0;
|
|
1290
|
-
if (o.contains(h.vertices, C[0]) && (
|
|
1143
|
+
if (o.contains(h.vertices, C[0]) && (T[M++] = C[0]), o.contains(h.vertices, C[1]) && (T[M++] = C[1]), M < 2) {
|
|
1291
1144
|
var I = e._findSupports(l, h, m, -1);
|
|
1292
|
-
o.contains(l.vertices, I[0]) && (
|
|
1145
|
+
o.contains(l.vertices, I[0]) && (T[M++] = I[0]), M < 2 && o.contains(l.vertices, I[1]) && (T[M++] = I[1]);
|
|
1293
1146
|
}
|
|
1294
|
-
return M === 0 && (
|
|
1147
|
+
return M === 0 && (T[M++] = C[0]), s.supportCount = M, s;
|
|
1295
1148
|
}, e._overlapAxes = function(h, l, t, i) {
|
|
1296
|
-
var s = l.length,
|
|
1149
|
+
var s = l.length, f = t.length, m = l[0].x, x = l[0].y, P = t[0].x, T = t[0].y, g = i.length, d = Number.MAX_VALUE, y = 0, v, w, S, C, M, I;
|
|
1297
1150
|
for (M = 0; M < g; M++) {
|
|
1298
|
-
var R = i[M], L = R.x,
|
|
1151
|
+
var R = i[M], L = R.x, D = R.y, k = m * L + x * D, b = P * L + T * D, O = k, W = b;
|
|
1299
1152
|
for (I = 1; I < s; I += 1)
|
|
1300
|
-
C = l[I].x * L + l[I].y *
|
|
1301
|
-
for (I = 1; I <
|
|
1302
|
-
C = t[I].x * L + t[I].y *
|
|
1303
|
-
if (w =
|
|
1153
|
+
C = l[I].x * L + l[I].y * D, C > O ? O = C : C < k && (k = C);
|
|
1154
|
+
for (I = 1; I < f; I += 1)
|
|
1155
|
+
C = t[I].x * L + t[I].y * D, C > W ? W = C : C < b && (b = C);
|
|
1156
|
+
if (w = O - b, S = W - k, v = w < S ? w : S, v < d && (d = v, y = M, v <= 0))
|
|
1304
1157
|
break;
|
|
1305
1158
|
}
|
|
1306
|
-
h.axis = i[y], h.overlap =
|
|
1159
|
+
h.axis = i[y], h.overlap = d;
|
|
1307
1160
|
}, e._findSupports = function(h, l, t, i) {
|
|
1308
|
-
var s = l.vertices,
|
|
1309
|
-
for (S = 1; S <
|
|
1310
|
-
|
|
1311
|
-
return v = s[(
|
|
1161
|
+
var s = l.vertices, f = s.length, m = h.position.x, x = h.position.y, P = t.x * i, T = t.y * i, g = s[0], d = g, y = P * (m - d.x) + T * (x - d.y), v, w, S;
|
|
1162
|
+
for (S = 1; S < f; S += 1)
|
|
1163
|
+
d = s[S], w = P * (m - d.x) + T * (x - d.y), w < y && (y = w, g = d);
|
|
1164
|
+
return v = s[(f + g.index - 1) % f], y = P * (m - v.x) + T * (x - v.y), d = s[(g.index + 1) % f], P * (m - d.x) + T * (x - d.y) < y ? (a[0] = g, a[1] = d, a) : (a[0] = g, a[1] = v, a);
|
|
1312
1165
|
};
|
|
1313
1166
|
})();
|
|
1314
1167
|
}),
|
|
1315
|
-
(function(
|
|
1168
|
+
(function(A, E, c) {
|
|
1316
1169
|
var e = {};
|
|
1317
|
-
|
|
1318
|
-
var o =
|
|
1170
|
+
A.exports = e;
|
|
1171
|
+
var o = c(16);
|
|
1319
1172
|
(function() {
|
|
1320
|
-
e.create = function(
|
|
1321
|
-
var
|
|
1322
|
-
id: e.id(
|
|
1323
|
-
bodyA:
|
|
1173
|
+
e.create = function(r, a) {
|
|
1174
|
+
var u = r.bodyA, n = r.bodyB, h = {
|
|
1175
|
+
id: e.id(u, n),
|
|
1176
|
+
bodyA: u,
|
|
1324
1177
|
bodyB: n,
|
|
1325
|
-
collision:
|
|
1178
|
+
collision: r,
|
|
1326
1179
|
contacts: [o.create(), o.create()],
|
|
1327
1180
|
contactCount: 0,
|
|
1328
1181
|
separation: 0,
|
|
1329
1182
|
isActive: !0,
|
|
1330
|
-
isSensor:
|
|
1331
|
-
timeCreated:
|
|
1332
|
-
timeUpdated:
|
|
1183
|
+
isSensor: u.isSensor || n.isSensor,
|
|
1184
|
+
timeCreated: a,
|
|
1185
|
+
timeUpdated: a,
|
|
1333
1186
|
inverseMass: 0,
|
|
1334
1187
|
friction: 0,
|
|
1335
1188
|
frictionStatic: 0,
|
|
1336
1189
|
restitution: 0,
|
|
1337
1190
|
slop: 0
|
|
1338
1191
|
};
|
|
1339
|
-
return e.update(h,
|
|
1340
|
-
}, e.update = function(
|
|
1341
|
-
var n =
|
|
1342
|
-
|
|
1343
|
-
var s = n[0],
|
|
1344
|
-
(x.vertex === s ||
|
|
1345
|
-
}, e.setActive = function(
|
|
1346
|
-
|
|
1347
|
-
}, e.id = function(
|
|
1348
|
-
return
|
|
1192
|
+
return e.update(h, r, a), h;
|
|
1193
|
+
}, e.update = function(r, a, u) {
|
|
1194
|
+
var n = a.supports, h = a.supportCount, l = r.contacts, t = a.parentA, i = a.parentB;
|
|
1195
|
+
r.isActive = !0, r.timeUpdated = u, r.collision = a, r.separation = a.depth, r.inverseMass = t.inverseMass + i.inverseMass, r.friction = t.friction < i.friction ? t.friction : i.friction, r.frictionStatic = t.frictionStatic > i.frictionStatic ? t.frictionStatic : i.frictionStatic, r.restitution = t.restitution > i.restitution ? t.restitution : i.restitution, r.slop = t.slop > i.slop ? t.slop : i.slop, r.contactCount = h, a.pair = r;
|
|
1196
|
+
var s = n[0], f = l[0], m = n[1], x = l[1];
|
|
1197
|
+
(x.vertex === s || f.vertex === m) && (l[1] = f, l[0] = f = x, x = l[1]), f.vertex = s, x.vertex = m;
|
|
1198
|
+
}, e.setActive = function(r, a, u) {
|
|
1199
|
+
a ? (r.isActive = !0, r.timeUpdated = u) : (r.isActive = !1, r.contactCount = 0);
|
|
1200
|
+
}, e.id = function(r, a) {
|
|
1201
|
+
return r.id < a.id ? r.id.toString(36) + ":" + a.id.toString(36) : a.id.toString(36) + ":" + r.id.toString(36);
|
|
1349
1202
|
};
|
|
1350
1203
|
})();
|
|
1351
1204
|
}),
|
|
1352
|
-
(function(
|
|
1205
|
+
(function(A, E, c) {
|
|
1353
1206
|
var e = {};
|
|
1354
|
-
|
|
1355
|
-
var o =
|
|
1207
|
+
A.exports = e;
|
|
1208
|
+
var o = c(3), r = c(2), a = c(7), u = c(1), n = c(11), h = c(0);
|
|
1356
1209
|
(function() {
|
|
1357
1210
|
e._warming = 0.4, e._torqueDampen = 1, e._minLength = 1e-6, e.create = function(l) {
|
|
1358
1211
|
var t = l;
|
|
@@ -1363,8 +1216,8 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
1363
1216
|
x: 0,
|
|
1364
1217
|
y: 0
|
|
1365
1218
|
});
|
|
1366
|
-
var i = t.bodyA ?
|
|
1367
|
-
t.length = typeof t.length < "u" ? t.length :
|
|
1219
|
+
var i = t.bodyA ? r.add(t.bodyA.position, t.pointA) : t.pointA, s = t.bodyB ? r.add(t.bodyB.position, t.pointB) : t.pointB, f = r.magnitude(r.sub(i, s));
|
|
1220
|
+
t.length = typeof t.length < "u" ? t.length : f, t.id = t.id || h.nextId(), t.label = t.label || "Constraint", t.type = "constraint", t.stiffness = t.stiffness || (t.length > 0 ? 1 : 0.7), t.damping = t.damping || 0, t.angularStiffness = t.angularStiffness || 0, t.angleA = t.bodyA ? t.bodyA.angle : t.angleA, t.angleB = t.bodyB ? t.bodyB.angle : t.angleB, t.plugin = {};
|
|
1368
1221
|
var m = {
|
|
1369
1222
|
visible: !0,
|
|
1370
1223
|
lineWidth: 2,
|
|
@@ -1380,35 +1233,35 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
1380
1233
|
}
|
|
1381
1234
|
}, e.solveAll = function(l, t) {
|
|
1382
1235
|
for (var i = h.clamp(t / h._baseDelta, 0, 1), s = 0; s < l.length; s += 1) {
|
|
1383
|
-
var
|
|
1236
|
+
var f = l[s], m = !f.bodyA || f.bodyA && f.bodyA.isStatic, x = !f.bodyB || f.bodyB && f.bodyB.isStatic;
|
|
1384
1237
|
(m || x) && e.solve(l[s], i);
|
|
1385
1238
|
}
|
|
1386
1239
|
for (s = 0; s < l.length; s += 1)
|
|
1387
|
-
|
|
1240
|
+
f = l[s], m = !f.bodyA || f.bodyA && f.bodyA.isStatic, x = !f.bodyB || f.bodyB && f.bodyB.isStatic, !m && !x && e.solve(l[s], i);
|
|
1388
1241
|
}, e.solve = function(l, t) {
|
|
1389
|
-
var i = l.bodyA, s = l.bodyB,
|
|
1242
|
+
var i = l.bodyA, s = l.bodyB, f = l.pointA, m = l.pointB;
|
|
1390
1243
|
if (!(!i && !s)) {
|
|
1391
|
-
i && !i.isStatic && (
|
|
1392
|
-
var x =
|
|
1393
|
-
if (i && (x =
|
|
1394
|
-
var
|
|
1244
|
+
i && !i.isStatic && (r.rotate(f, i.angle - l.angleA, f), l.angleA = i.angle), s && !s.isStatic && (r.rotate(m, s.angle - l.angleB, m), l.angleB = s.angle);
|
|
1245
|
+
var x = f, P = m;
|
|
1246
|
+
if (i && (x = r.add(i.position, f)), s && (P = r.add(s.position, m)), !(!x || !P)) {
|
|
1247
|
+
var T = r.sub(x, P), g = r.magnitude(T);
|
|
1395
1248
|
g < e._minLength && (g = e._minLength);
|
|
1396
|
-
var
|
|
1249
|
+
var d = (g - l.length) / g, y = l.stiffness >= 1 || l.length === 0 ? l.stiffness * t : l.stiffness * t * t, v = l.damping * t, w = r.mult(T, d * y), S = (i ? i.inverseMass : 0) + (s ? s.inverseMass : 0), C = S + ((i ? i.inverseInertia : 0) + (s ? s.inverseInertia : 0)), M, I, R, L, D;
|
|
1397
1250
|
if (v > 0) {
|
|
1398
|
-
var k =
|
|
1399
|
-
R =
|
|
1251
|
+
var k = r.create();
|
|
1252
|
+
R = r.div(T, g), D = r.sub(s && r.sub(s.position, s.positionPrev) || k, i && r.sub(i.position, i.positionPrev) || k), L = r.dot(R, D);
|
|
1400
1253
|
}
|
|
1401
|
-
i && !i.isStatic && (I = i.inverseMass / S, i.constraintImpulse.x -= w.x * I, i.constraintImpulse.y -= w.y * I, i.position.x -= w.x * I, i.position.y -= w.y * I, v > 0 && (i.positionPrev.x -= v * R.x * L * I, i.positionPrev.y -= v * R.y * L * I), M =
|
|
1254
|
+
i && !i.isStatic && (I = i.inverseMass / S, i.constraintImpulse.x -= w.x * I, i.constraintImpulse.y -= w.y * I, i.position.x -= w.x * I, i.position.y -= w.y * I, v > 0 && (i.positionPrev.x -= v * R.x * L * I, i.positionPrev.y -= v * R.y * L * I), M = r.cross(f, w) / C * e._torqueDampen * i.inverseInertia * (1 - l.angularStiffness), i.constraintImpulse.angle -= M, i.angle -= M), s && !s.isStatic && (I = s.inverseMass / S, s.constraintImpulse.x += w.x * I, s.constraintImpulse.y += w.y * I, s.position.x += w.x * I, s.position.y += w.y * I, v > 0 && (s.positionPrev.x += v * R.x * L * I, s.positionPrev.y += v * R.y * L * I), M = r.cross(m, w) / C * e._torqueDampen * s.inverseInertia * (1 - l.angularStiffness), s.constraintImpulse.angle += M, s.angle += M);
|
|
1402
1255
|
}
|
|
1403
1256
|
}
|
|
1404
1257
|
}, e.postSolveAll = function(l) {
|
|
1405
1258
|
for (var t = 0; t < l.length; t++) {
|
|
1406
1259
|
var i = l[t], s = i.constraintImpulse;
|
|
1407
1260
|
if (!(i.isStatic || s.x === 0 && s.y === 0 && s.angle === 0)) {
|
|
1408
|
-
|
|
1409
|
-
for (var
|
|
1410
|
-
var m = i.parts[
|
|
1411
|
-
o.translate(m.vertices, s),
|
|
1261
|
+
a.set(i, !1);
|
|
1262
|
+
for (var f = 0; f < i.parts.length; f++) {
|
|
1263
|
+
var m = i.parts[f];
|
|
1264
|
+
o.translate(m.vertices, s), f > 0 && (m.position.x += s.x, m.position.y += s.y), s.angle !== 0 && (o.rotate(m.vertices, s.angle, i.position), n.rotate(m.axes, s.angle), f > 0 && r.rotateAbout(m.position, s.angle, i.position, m.position)), u.update(m.bounds, m.vertices, i.velocity);
|
|
1412
1265
|
}
|
|
1413
1266
|
s.angle *= e._warming, s.x *= e._warming, s.y *= e._warming;
|
|
1414
1267
|
}
|
|
@@ -1424,42 +1277,42 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
1424
1277
|
y: (l.bodyB ? l.bodyB.position.y : 0) + (l.pointB ? l.pointB.y : 0)
|
|
1425
1278
|
};
|
|
1426
1279
|
}, e.currentLength = function(l) {
|
|
1427
|
-
var t = (l.bodyA ? l.bodyA.position.x : 0) + (l.pointA ? l.pointA.x : 0), i = (l.bodyA ? l.bodyA.position.y : 0) + (l.pointA ? l.pointA.y : 0), s = (l.bodyB ? l.bodyB.position.x : 0) + (l.pointB ? l.pointB.x : 0),
|
|
1280
|
+
var t = (l.bodyA ? l.bodyA.position.x : 0) + (l.pointA ? l.pointA.x : 0), i = (l.bodyA ? l.bodyA.position.y : 0) + (l.pointA ? l.pointA.y : 0), s = (l.bodyB ? l.bodyB.position.x : 0) + (l.pointB ? l.pointB.x : 0), f = (l.bodyB ? l.bodyB.position.y : 0) + (l.pointB ? l.pointB.y : 0), m = t - s, x = i - f;
|
|
1428
1281
|
return Math.sqrt(m * m + x * x);
|
|
1429
1282
|
};
|
|
1430
1283
|
})();
|
|
1431
1284
|
}),
|
|
1432
|
-
(function(
|
|
1285
|
+
(function(A, E, c) {
|
|
1433
1286
|
var e = {};
|
|
1434
|
-
|
|
1435
|
-
var o =
|
|
1287
|
+
A.exports = e;
|
|
1288
|
+
var o = c(2), r = c(0);
|
|
1436
1289
|
(function() {
|
|
1437
|
-
e.fromVertices = function(
|
|
1438
|
-
for (var
|
|
1439
|
-
var h = (n + 1) %
|
|
1440
|
-
x:
|
|
1441
|
-
y:
|
|
1290
|
+
e.fromVertices = function(a) {
|
|
1291
|
+
for (var u = {}, n = 0; n < a.length; n++) {
|
|
1292
|
+
var h = (n + 1) % a.length, l = o.normalise({
|
|
1293
|
+
x: a[h].y - a[n].y,
|
|
1294
|
+
y: a[n].x - a[h].x
|
|
1442
1295
|
}), t = l.y === 0 ? 1 / 0 : l.x / l.y;
|
|
1443
|
-
t = t.toFixed(3).toString(),
|
|
1296
|
+
t = t.toFixed(3).toString(), u[t] = l;
|
|
1444
1297
|
}
|
|
1445
|
-
return
|
|
1446
|
-
}, e.rotate = function(
|
|
1447
|
-
if (
|
|
1448
|
-
for (var n = Math.cos(
|
|
1449
|
-
var t =
|
|
1298
|
+
return r.values(u);
|
|
1299
|
+
}, e.rotate = function(a, u) {
|
|
1300
|
+
if (u !== 0)
|
|
1301
|
+
for (var n = Math.cos(u), h = Math.sin(u), l = 0; l < a.length; l++) {
|
|
1302
|
+
var t = a[l], i = t.x * n - t.y * h;
|
|
1450
1303
|
t.y = t.x * h + t.y * n, t.x = i;
|
|
1451
1304
|
}
|
|
1452
1305
|
};
|
|
1453
1306
|
})();
|
|
1454
1307
|
}),
|
|
1455
|
-
(function(
|
|
1308
|
+
(function(A, E, c) {
|
|
1456
1309
|
var e = {};
|
|
1457
|
-
|
|
1458
|
-
var o =
|
|
1310
|
+
A.exports = e;
|
|
1311
|
+
var o = c(3), r = c(0), a = c(4), u = c(1), n = c(2);
|
|
1459
1312
|
(function() {
|
|
1460
1313
|
e.rectangle = function(h, l, t, i, s) {
|
|
1461
1314
|
s = s || {};
|
|
1462
|
-
var
|
|
1315
|
+
var f = {
|
|
1463
1316
|
label: "Rectangle Body",
|
|
1464
1317
|
position: {
|
|
1465
1318
|
x: h,
|
|
@@ -1469,14 +1322,14 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
1469
1322
|
};
|
|
1470
1323
|
if (s.chamfer) {
|
|
1471
1324
|
var m = s.chamfer;
|
|
1472
|
-
|
|
1473
|
-
}
|
|
1474
|
-
return
|
|
1475
|
-
}, e.trapezoid = function(h, l, t, i, s,
|
|
1476
|
-
|
|
1477
|
-
var m = (1 - s * 2) * t, x = t * s, P = x + m,
|
|
1478
|
-
s < 0.5 ? g = "L 0 0 L " + x + " " + -i + " L " + P + " " + -i + " L " +
|
|
1479
|
-
var
|
|
1325
|
+
f.vertices = o.chamfer(f.vertices, m.radius, m.quality, m.qualityMin, m.qualityMax), delete s.chamfer;
|
|
1326
|
+
}
|
|
1327
|
+
return a.create(r.extend({}, f, s));
|
|
1328
|
+
}, e.trapezoid = function(h, l, t, i, s, f) {
|
|
1329
|
+
f = f || {}, s >= 1 && r.warn("Bodies.trapezoid: slope parameter must be < 1."), s *= 0.5;
|
|
1330
|
+
var m = (1 - s * 2) * t, x = t * s, P = x + m, T = P + x, g;
|
|
1331
|
+
s < 0.5 ? g = "L 0 0 L " + x + " " + -i + " L " + P + " " + -i + " L " + T + " 0" : g = "L 0 0 L " + P + " " + -i + " L " + T + " 0";
|
|
1332
|
+
var d = {
|
|
1480
1333
|
label: "Trapezoid Body",
|
|
1481
1334
|
position: {
|
|
1482
1335
|
x: h,
|
|
@@ -1484,25 +1337,25 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
1484
1337
|
},
|
|
1485
1338
|
vertices: o.fromPath(g)
|
|
1486
1339
|
};
|
|
1487
|
-
if (
|
|
1488
|
-
var y =
|
|
1489
|
-
|
|
1340
|
+
if (f.chamfer) {
|
|
1341
|
+
var y = f.chamfer;
|
|
1342
|
+
d.vertices = o.chamfer(d.vertices, y.radius, y.quality, y.qualityMin, y.qualityMax), delete f.chamfer;
|
|
1490
1343
|
}
|
|
1491
|
-
return
|
|
1344
|
+
return a.create(r.extend({}, d, f));
|
|
1492
1345
|
}, e.circle = function(h, l, t, i, s) {
|
|
1493
1346
|
i = i || {};
|
|
1494
|
-
var
|
|
1347
|
+
var f = {
|
|
1495
1348
|
label: "Circle Body",
|
|
1496
1349
|
circleRadius: t
|
|
1497
1350
|
};
|
|
1498
1351
|
s = s || 25;
|
|
1499
1352
|
var m = Math.ceil(Math.max(10, Math.min(s, t)));
|
|
1500
|
-
return m % 2 === 1 && (m += 1), e.polygon(h, l, m, t,
|
|
1353
|
+
return m % 2 === 1 && (m += 1), e.polygon(h, l, m, t, r.extend({}, f, i));
|
|
1501
1354
|
}, e.polygon = function(h, l, t, i, s) {
|
|
1502
1355
|
if (s = s || {}, t < 3) return e.circle(h, l, i, s);
|
|
1503
|
-
for (var
|
|
1504
|
-
var
|
|
1505
|
-
m += "L " + g.toFixed(3) + " " +
|
|
1356
|
+
for (var f = 2 * Math.PI / t, m = "", x = f * 0.5, P = 0; P < t; P += 1) {
|
|
1357
|
+
var T = x + P * f, g = Math.cos(T) * i, d = Math.sin(T) * i;
|
|
1358
|
+
m += "L " + g.toFixed(3) + " " + d.toFixed(3) + " ";
|
|
1506
1359
|
}
|
|
1507
1360
|
var y = {
|
|
1508
1361
|
label: "Polygon Body",
|
|
@@ -1516,12 +1369,12 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
1516
1369
|
var v = s.chamfer;
|
|
1517
1370
|
y.vertices = o.chamfer(y.vertices, v.radius, v.quality, v.qualityMin, v.qualityMax), delete s.chamfer;
|
|
1518
1371
|
}
|
|
1519
|
-
return
|
|
1520
|
-
}, e.fromVertices = function(h, l, t, i, s,
|
|
1521
|
-
var P =
|
|
1522
|
-
for (i = i || {},
|
|
1523
|
-
if (w = t[I], y = o.isConvex(w), v = !y, v && !
|
|
1524
|
-
y ? w = o.clockwiseSort(w) : w = o.hull(w),
|
|
1372
|
+
return a.create(r.extend({}, y, s));
|
|
1373
|
+
}, e.fromVertices = function(h, l, t, i, s, f, m, x) {
|
|
1374
|
+
var P = r.getDecomp(), T = !!(P && P.quickDecomp), g, d, y, v, w, S, C, M, I, R;
|
|
1375
|
+
for (i = i || {}, d = [], s = typeof s < "u" ? s : !1, f = typeof f < "u" ? f : 0.01, m = typeof m < "u" ? m : 10, x = typeof x < "u" ? x : 0.01, r.isArray(t[0]) || (t = [t]), I = 0; I < t.length; I += 1)
|
|
1376
|
+
if (w = t[I], y = o.isConvex(w), v = !y, v && !T && r.warnOnce("Bodies.fromVertices: Install the 'poly-decomp' library and use Common.setDecomp or provide 'decomp' as a global to decompose concave vertices."), y || !T)
|
|
1377
|
+
y ? w = o.clockwiseSort(w) : w = o.hull(w), d.push({
|
|
1525
1378
|
position: {
|
|
1526
1379
|
x: h,
|
|
1527
1380
|
y: l
|
|
@@ -1529,81 +1382,81 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
1529
1382
|
vertices: w
|
|
1530
1383
|
});
|
|
1531
1384
|
else {
|
|
1532
|
-
var L = w.map(function(
|
|
1533
|
-
return [
|
|
1385
|
+
var L = w.map(function(F) {
|
|
1386
|
+
return [F.x, F.y];
|
|
1534
1387
|
});
|
|
1535
|
-
P.makeCCW(L),
|
|
1536
|
-
var
|
|
1537
|
-
for (S = 0; S <
|
|
1538
|
-
var k =
|
|
1388
|
+
P.makeCCW(L), f !== !1 && P.removeCollinearPoints(L, f), x !== !1 && P.removeDuplicatePoints && P.removeDuplicatePoints(L, x);
|
|
1389
|
+
var D = P.quickDecomp(L);
|
|
1390
|
+
for (S = 0; S < D.length; S++) {
|
|
1391
|
+
var k = D[S].map(function(F) {
|
|
1539
1392
|
return {
|
|
1540
|
-
x:
|
|
1541
|
-
y:
|
|
1393
|
+
x: F[0],
|
|
1394
|
+
y: F[1]
|
|
1542
1395
|
};
|
|
1543
1396
|
});
|
|
1544
|
-
m > 0 && o.area(k) < m ||
|
|
1397
|
+
m > 0 && o.area(k) < m || d.push({
|
|
1545
1398
|
position: o.centre(k),
|
|
1546
1399
|
vertices: k
|
|
1547
1400
|
});
|
|
1548
1401
|
}
|
|
1549
1402
|
}
|
|
1550
|
-
for (S = 0; S <
|
|
1403
|
+
for (S = 0; S < d.length; S++) d[S] = a.create(r.extend(d[S], i));
|
|
1551
1404
|
if (s) {
|
|
1552
|
-
var
|
|
1553
|
-
for (S = 0; S <
|
|
1554
|
-
var
|
|
1555
|
-
for (C = S + 1; C <
|
|
1556
|
-
var
|
|
1557
|
-
if (
|
|
1558
|
-
var G =
|
|
1559
|
-
for (M = 0; M <
|
|
1560
|
-
var Q = n.magnitudeSquared(n.sub(G[(M + 1) % G.length],
|
|
1561
|
-
Q <
|
|
1405
|
+
var b = 5;
|
|
1406
|
+
for (S = 0; S < d.length; S++) {
|
|
1407
|
+
var O = d[S];
|
|
1408
|
+
for (C = S + 1; C < d.length; C++) {
|
|
1409
|
+
var W = d[C];
|
|
1410
|
+
if (u.overlaps(O.bounds, W.bounds)) {
|
|
1411
|
+
var G = O.vertices, N = W.vertices;
|
|
1412
|
+
for (M = 0; M < O.vertices.length; M++) for (R = 0; R < W.vertices.length; R++) {
|
|
1413
|
+
var Q = n.magnitudeSquared(n.sub(G[(M + 1) % G.length], N[R])), X = n.magnitudeSquared(n.sub(G[M], N[(R + 1) % N.length]));
|
|
1414
|
+
Q < b && X < b && (G[M].isInternal = !0, N[R].isInternal = !0);
|
|
1562
1415
|
}
|
|
1563
1416
|
}
|
|
1564
1417
|
}
|
|
1565
1418
|
}
|
|
1566
1419
|
}
|
|
1567
|
-
return
|
|
1420
|
+
return d.length > 1 ? (g = a.create(r.extend({ parts: d.slice(0) }, i)), a.setPosition(g, {
|
|
1568
1421
|
x: h,
|
|
1569
1422
|
y: l
|
|
1570
|
-
}), g) :
|
|
1423
|
+
}), g) : d[0];
|
|
1571
1424
|
};
|
|
1572
1425
|
})();
|
|
1573
1426
|
}),
|
|
1574
|
-
(function(
|
|
1427
|
+
(function(A, E, c) {
|
|
1575
1428
|
var e = {};
|
|
1576
|
-
|
|
1577
|
-
var o =
|
|
1429
|
+
A.exports = e;
|
|
1430
|
+
var o = c(0), r = c(8);
|
|
1578
1431
|
(function() {
|
|
1579
|
-
e.create = function(
|
|
1432
|
+
e.create = function(a) {
|
|
1580
1433
|
return o.extend({
|
|
1581
1434
|
bodies: [],
|
|
1582
1435
|
collisions: [],
|
|
1583
1436
|
pairs: null
|
|
1584
|
-
},
|
|
1585
|
-
}, e.setBodies = function(
|
|
1586
|
-
|
|
1587
|
-
}, e.clear = function(
|
|
1588
|
-
|
|
1589
|
-
}, e.collisions = function(
|
|
1590
|
-
var
|
|
1591
|
-
for (n.sort(e._compareBoundsX),
|
|
1592
|
-
var x = n[
|
|
1593
|
-
for (m =
|
|
1437
|
+
}, a);
|
|
1438
|
+
}, e.setBodies = function(a, u) {
|
|
1439
|
+
a.bodies = u.slice(0);
|
|
1440
|
+
}, e.clear = function(a) {
|
|
1441
|
+
a.bodies = [], a.collisions = [];
|
|
1442
|
+
}, e.collisions = function(a) {
|
|
1443
|
+
var u = a.pairs, n = a.bodies, h = n.length, l = e.canCollide, t = r.collides, i = a.collisions, s = 0, f, m;
|
|
1444
|
+
for (n.sort(e._compareBoundsX), f = 0; f < h; f++) {
|
|
1445
|
+
var x = n[f], P = x.bounds, T = x.bounds.max.x, g = x.bounds.max.y, d = x.bounds.min.y, y = x.isStatic || x.isSleeping, v = x.parts.length, w = v === 1;
|
|
1446
|
+
for (m = f + 1; m < h; m++) {
|
|
1594
1447
|
var S = n[m], C = S.bounds;
|
|
1595
|
-
if (C.min.x >
|
|
1596
|
-
if (!(g < C.min.y ||
|
|
1448
|
+
if (C.min.x > T) break;
|
|
1449
|
+
if (!(g < C.min.y || d > C.max.y) && !(y && (S.isStatic || S.isSleeping)) && l(x.collisionFilter, S.collisionFilter)) {
|
|
1597
1450
|
var M = S.parts.length;
|
|
1598
1451
|
if (w && M === 1) {
|
|
1599
|
-
var I = t(x, S,
|
|
1452
|
+
var I = t(x, S, u);
|
|
1600
1453
|
I && (i[s++] = I);
|
|
1601
1454
|
} else
|
|
1602
|
-
for (var R = v > 1 ? 1 : 0, L = M > 1 ? 1 : 0,
|
|
1603
|
-
for (var k = x.parts[
|
|
1604
|
-
var
|
|
1455
|
+
for (var R = v > 1 ? 1 : 0, L = M > 1 ? 1 : 0, D = R; D < v; D++)
|
|
1456
|
+
for (var k = x.parts[D], P = k.bounds, b = L; b < M; b++) {
|
|
1457
|
+
var O = S.parts[b], C = O.bounds;
|
|
1605
1458
|
if (!(P.min.x > C.max.x || P.max.x < C.min.x || P.max.y < C.min.y || P.min.y > C.max.y)) {
|
|
1606
|
-
var I = t(k,
|
|
1459
|
+
var I = t(k, O, u);
|
|
1607
1460
|
I && (i[s++] = I);
|
|
1608
1461
|
}
|
|
1609
1462
|
}
|
|
@@ -1611,137 +1464,137 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
1611
1464
|
}
|
|
1612
1465
|
}
|
|
1613
1466
|
return i.length !== s && (i.length = s), i;
|
|
1614
|
-
}, e.canCollide = function(
|
|
1615
|
-
return
|
|
1616
|
-
}, e._compareBoundsX = function(
|
|
1617
|
-
return
|
|
1467
|
+
}, e.canCollide = function(a, u) {
|
|
1468
|
+
return a.group === u.group && a.group !== 0 ? a.group > 0 : (a.mask & u.category) !== 0 && (u.mask & a.category) !== 0;
|
|
1469
|
+
}, e._compareBoundsX = function(a, u) {
|
|
1470
|
+
return a.bounds.min.x - u.bounds.min.x;
|
|
1618
1471
|
};
|
|
1619
1472
|
})();
|
|
1620
1473
|
}),
|
|
1621
|
-
(function(
|
|
1474
|
+
(function(A, E, c) {
|
|
1622
1475
|
var e = {};
|
|
1623
|
-
|
|
1624
|
-
var o =
|
|
1476
|
+
A.exports = e;
|
|
1477
|
+
var o = c(0);
|
|
1625
1478
|
(function() {
|
|
1626
|
-
e.create = function(
|
|
1627
|
-
var
|
|
1628
|
-
return
|
|
1479
|
+
e.create = function(r) {
|
|
1480
|
+
var a = {};
|
|
1481
|
+
return r || o.log("Mouse.create: element was undefined, defaulting to document.body", "warn"), a.element = r || document.body, a.absolute = {
|
|
1629
1482
|
x: 0,
|
|
1630
1483
|
y: 0
|
|
1631
|
-
},
|
|
1484
|
+
}, a.position = {
|
|
1632
1485
|
x: 0,
|
|
1633
1486
|
y: 0
|
|
1634
|
-
},
|
|
1487
|
+
}, a.mousedownPosition = {
|
|
1635
1488
|
x: 0,
|
|
1636
1489
|
y: 0
|
|
1637
|
-
},
|
|
1490
|
+
}, a.mouseupPosition = {
|
|
1638
1491
|
x: 0,
|
|
1639
1492
|
y: 0
|
|
1640
|
-
},
|
|
1493
|
+
}, a.offset = {
|
|
1641
1494
|
x: 0,
|
|
1642
1495
|
y: 0
|
|
1643
|
-
},
|
|
1496
|
+
}, a.scale = {
|
|
1644
1497
|
x: 1,
|
|
1645
1498
|
y: 1
|
|
1646
|
-
},
|
|
1499
|
+
}, a.wheelDelta = 0, a.button = -1, a.pixelRatio = parseInt(a.element.getAttribute("data-pixel-ratio"), 10) || 1, a.sourceEvents = {
|
|
1647
1500
|
mousemove: null,
|
|
1648
1501
|
mousedown: null,
|
|
1649
1502
|
mouseup: null,
|
|
1650
1503
|
mousewheel: null
|
|
1651
|
-
},
|
|
1652
|
-
var n = e._getRelativeMousePosition(
|
|
1653
|
-
|
|
1654
|
-
},
|
|
1655
|
-
var n = e._getRelativeMousePosition(
|
|
1656
|
-
|
|
1657
|
-
},
|
|
1658
|
-
var n = e._getRelativeMousePosition(
|
|
1659
|
-
|
|
1660
|
-
},
|
|
1661
|
-
|
|
1662
|
-
}, e.setElement(
|
|
1663
|
-
}, e.setElement = function(
|
|
1664
|
-
|
|
1665
|
-
}, e.clearSourceEvents = function(
|
|
1666
|
-
|
|
1667
|
-
}, e.setOffset = function(
|
|
1668
|
-
|
|
1669
|
-
}, e.setScale = function(
|
|
1670
|
-
|
|
1671
|
-
}, e._getRelativeMousePosition = function(
|
|
1672
|
-
var n =
|
|
1673
|
-
return i ? (s = i[0].pageX - n.left - l,
|
|
1674
|
-
x: s / (
|
|
1675
|
-
y:
|
|
1504
|
+
}, a.mousemove = function(u) {
|
|
1505
|
+
var n = e._getRelativeMousePosition(u, a.element, a.pixelRatio);
|
|
1506
|
+
u.changedTouches && (a.button = 0, u.preventDefault()), a.absolute.x = n.x, a.absolute.y = n.y, a.position.x = a.absolute.x * a.scale.x + a.offset.x, a.position.y = a.absolute.y * a.scale.y + a.offset.y, a.sourceEvents.mousemove = u;
|
|
1507
|
+
}, a.mousedown = function(u) {
|
|
1508
|
+
var n = e._getRelativeMousePosition(u, a.element, a.pixelRatio);
|
|
1509
|
+
u.changedTouches ? (a.button = 0, u.preventDefault()) : a.button = u.button, a.absolute.x = n.x, a.absolute.y = n.y, a.position.x = a.absolute.x * a.scale.x + a.offset.x, a.position.y = a.absolute.y * a.scale.y + a.offset.y, a.mousedownPosition.x = a.position.x, a.mousedownPosition.y = a.position.y, a.sourceEvents.mousedown = u;
|
|
1510
|
+
}, a.mouseup = function(u) {
|
|
1511
|
+
var n = e._getRelativeMousePosition(u, a.element, a.pixelRatio);
|
|
1512
|
+
u.changedTouches && u.preventDefault(), a.button = -1, a.absolute.x = n.x, a.absolute.y = n.y, a.position.x = a.absolute.x * a.scale.x + a.offset.x, a.position.y = a.absolute.y * a.scale.y + a.offset.y, a.mouseupPosition.x = a.position.x, a.mouseupPosition.y = a.position.y, a.sourceEvents.mouseup = u;
|
|
1513
|
+
}, a.mousewheel = function(u) {
|
|
1514
|
+
a.wheelDelta = Math.max(-1, Math.min(1, u.wheelDelta || -u.detail)), u.preventDefault(), a.sourceEvents.mousewheel = u;
|
|
1515
|
+
}, e.setElement(a, a.element), a;
|
|
1516
|
+
}, e.setElement = function(r, a) {
|
|
1517
|
+
r.element = a, a.addEventListener("mousemove", r.mousemove, { passive: !0 }), a.addEventListener("mousedown", r.mousedown, { passive: !0 }), a.addEventListener("mouseup", r.mouseup, { passive: !0 }), a.addEventListener("wheel", r.mousewheel, { passive: !1 }), a.addEventListener("touchmove", r.mousemove, { passive: !1 }), a.addEventListener("touchstart", r.mousedown, { passive: !1 }), a.addEventListener("touchend", r.mouseup, { passive: !1 });
|
|
1518
|
+
}, e.clearSourceEvents = function(r) {
|
|
1519
|
+
r.sourceEvents.mousemove = null, r.sourceEvents.mousedown = null, r.sourceEvents.mouseup = null, r.sourceEvents.mousewheel = null, r.wheelDelta = 0;
|
|
1520
|
+
}, e.setOffset = function(r, a) {
|
|
1521
|
+
r.offset.x = a.x, r.offset.y = a.y, r.position.x = r.absolute.x * r.scale.x + r.offset.x, r.position.y = r.absolute.y * r.scale.y + r.offset.y;
|
|
1522
|
+
}, e.setScale = function(r, a) {
|
|
1523
|
+
r.scale.x = a.x, r.scale.y = a.y, r.position.x = r.absolute.x * r.scale.x + r.offset.x, r.position.y = r.absolute.y * r.scale.y + r.offset.y;
|
|
1524
|
+
}, e._getRelativeMousePosition = function(r, a, u) {
|
|
1525
|
+
var n = a.getBoundingClientRect(), h = document.documentElement || document.body.parentNode || document.body, l = window.pageXOffset !== void 0 ? window.pageXOffset : h.scrollLeft, t = window.pageYOffset !== void 0 ? window.pageYOffset : h.scrollTop, i = r.changedTouches, s, f;
|
|
1526
|
+
return i ? (s = i[0].pageX - n.left - l, f = i[0].pageY - n.top - t) : (s = r.pageX - n.left - l, f = r.pageY - n.top - t), {
|
|
1527
|
+
x: s / (a.clientWidth / (a.width || a.clientWidth) * u),
|
|
1528
|
+
y: f / (a.clientHeight / (a.height || a.clientHeight) * u)
|
|
1676
1529
|
};
|
|
1677
1530
|
};
|
|
1678
1531
|
})();
|
|
1679
1532
|
}),
|
|
1680
|
-
(function(
|
|
1533
|
+
(function(A, E, c) {
|
|
1681
1534
|
var e = {};
|
|
1682
|
-
|
|
1683
|
-
var o =
|
|
1535
|
+
A.exports = e;
|
|
1536
|
+
var o = c(0);
|
|
1684
1537
|
(function() {
|
|
1685
|
-
e._registry = {}, e.register = function(
|
|
1686
|
-
if (e.isPlugin(
|
|
1687
|
-
var
|
|
1688
|
-
|
|
1689
|
-
} else e._registry[
|
|
1690
|
-
return
|
|
1691
|
-
}, e.resolve = function(
|
|
1692
|
-
return e._registry[e.dependencyParse(
|
|
1693
|
-
}, e.toString = function(
|
|
1694
|
-
return typeof
|
|
1695
|
-
}, e.isPlugin = function(
|
|
1696
|
-
return
|
|
1697
|
-
}, e.isUsed = function(
|
|
1698
|
-
return
|
|
1699
|
-
}, e.isFor = function(
|
|
1700
|
-
var
|
|
1701
|
-
return !
|
|
1702
|
-
}, e.use = function(
|
|
1703
|
-
if (
|
|
1704
|
-
o.warn("Plugin.use:", e.toString(
|
|
1538
|
+
e._registry = {}, e.register = function(r) {
|
|
1539
|
+
if (e.isPlugin(r) || o.warn("Plugin.register:", e.toString(r), "does not implement all required fields."), r.name in e._registry) {
|
|
1540
|
+
var a = e._registry[r.name], u = e.versionParse(r.version).number, n = e.versionParse(a.version).number;
|
|
1541
|
+
u > n ? (o.warn("Plugin.register:", e.toString(a), "was upgraded to", e.toString(r)), e._registry[r.name] = r) : u < n ? o.warn("Plugin.register:", e.toString(a), "can not be downgraded to", e.toString(r)) : r !== a && o.warn("Plugin.register:", e.toString(r), "is already registered to different plugin object");
|
|
1542
|
+
} else e._registry[r.name] = r;
|
|
1543
|
+
return r;
|
|
1544
|
+
}, e.resolve = function(r) {
|
|
1545
|
+
return e._registry[e.dependencyParse(r).name];
|
|
1546
|
+
}, e.toString = function(r) {
|
|
1547
|
+
return typeof r == "string" ? r : (r.name || "anonymous") + "@" + (r.version || r.range || "0.0.0");
|
|
1548
|
+
}, e.isPlugin = function(r) {
|
|
1549
|
+
return r && r.name && r.version && r.install;
|
|
1550
|
+
}, e.isUsed = function(r, a) {
|
|
1551
|
+
return r.used.indexOf(a) > -1;
|
|
1552
|
+
}, e.isFor = function(r, a) {
|
|
1553
|
+
var u = r.for && e.dependencyParse(r.for);
|
|
1554
|
+
return !r.for || a.name === u.name && e.versionSatisfies(a.version, u.range);
|
|
1555
|
+
}, e.use = function(r, a) {
|
|
1556
|
+
if (r.uses = (r.uses || []).concat(a || []), r.uses.length === 0) {
|
|
1557
|
+
o.warn("Plugin.use:", e.toString(r), "does not specify any dependencies to install.");
|
|
1705
1558
|
return;
|
|
1706
1559
|
}
|
|
1707
|
-
for (var
|
|
1708
|
-
if (n[l] !==
|
|
1560
|
+
for (var u = e.dependencies(r), n = o.topologicalSort(u), h = [], l = 0; l < n.length; l += 1)
|
|
1561
|
+
if (n[l] !== r.name) {
|
|
1709
1562
|
var t = e.resolve(n[l]);
|
|
1710
1563
|
if (!t) {
|
|
1711
1564
|
h.push("❌ " + n[l]);
|
|
1712
1565
|
continue;
|
|
1713
1566
|
}
|
|
1714
|
-
e.isUsed(
|
|
1567
|
+
e.isUsed(r, t.name) || (e.isFor(t, r) || (o.warn("Plugin.use:", e.toString(t), "is for", t.for, "but installed on", e.toString(r) + "."), t._warned = !0), t.install ? t.install(r) : (o.warn("Plugin.use:", e.toString(t), "does not specify an install function."), t._warned = !0), t._warned ? (h.push("🔶 " + e.toString(t)), delete t._warned) : h.push("✅ " + e.toString(t)), r.used.push(t.name));
|
|
1715
1568
|
}
|
|
1716
1569
|
h.length > 0 && o.info(h.join(" "));
|
|
1717
|
-
}, e.dependencies = function(
|
|
1718
|
-
var
|
|
1719
|
-
if (
|
|
1720
|
-
|
|
1570
|
+
}, e.dependencies = function(r, a) {
|
|
1571
|
+
var u = e.dependencyParse(r), n = u.name;
|
|
1572
|
+
if (a = a || {}, !(n in a)) {
|
|
1573
|
+
r = e.resolve(r) || r, a[n] = o.map(r.uses || [], function(l) {
|
|
1721
1574
|
e.isPlugin(l) && e.register(l);
|
|
1722
1575
|
var t = e.dependencyParse(l), i = e.resolve(l);
|
|
1723
|
-
return i && !e.versionSatisfies(i.version, t.range) ? (o.warn("Plugin.dependencies:", e.toString(i), "does not satisfy", e.toString(t), "used by", e.toString(
|
|
1576
|
+
return i && !e.versionSatisfies(i.version, t.range) ? (o.warn("Plugin.dependencies:", e.toString(i), "does not satisfy", e.toString(t), "used by", e.toString(u) + "."), i._warned = !0, r._warned = !0) : i || (o.warn("Plugin.dependencies:", e.toString(l), "used by", e.toString(u), "could not be resolved."), r._warned = !0), t.name;
|
|
1724
1577
|
});
|
|
1725
|
-
for (var h = 0; h <
|
|
1726
|
-
return
|
|
1578
|
+
for (var h = 0; h < a[n].length; h += 1) e.dependencies(a[n][h], a);
|
|
1579
|
+
return a;
|
|
1727
1580
|
}
|
|
1728
|
-
}, e.dependencyParse = function(
|
|
1729
|
-
return o.isString(
|
|
1730
|
-
name:
|
|
1731
|
-
range:
|
|
1581
|
+
}, e.dependencyParse = function(r) {
|
|
1582
|
+
return o.isString(r) ? (/^[\w-]+(@(\*|[\^~]?\d+\.\d+\.\d+(-[0-9A-Za-z-+]+)?))?$/.test(r) || o.warn("Plugin.dependencyParse:", r, "is not a valid dependency string."), {
|
|
1583
|
+
name: r.split("@")[0],
|
|
1584
|
+
range: r.split("@")[1] || "*"
|
|
1732
1585
|
}) : {
|
|
1733
|
-
name:
|
|
1734
|
-
range:
|
|
1586
|
+
name: r.name,
|
|
1587
|
+
range: r.range || r.version
|
|
1735
1588
|
};
|
|
1736
|
-
}, e.versionParse = function(
|
|
1737
|
-
var
|
|
1738
|
-
|
|
1739
|
-
var
|
|
1589
|
+
}, e.versionParse = function(r) {
|
|
1590
|
+
var a = /^(\*)|(\^|~|>=|>)?\s*((\d+)\.(\d+)\.(\d+))(-[0-9A-Za-z-+]+)?$/;
|
|
1591
|
+
a.test(r) || o.warn("Plugin.versionParse:", r, "is not a valid version or range.");
|
|
1592
|
+
var u = a.exec(r), n = Number(u[4]), h = Number(u[5]), l = Number(u[6]);
|
|
1740
1593
|
return {
|
|
1741
|
-
isRange: !!(
|
|
1742
|
-
version:
|
|
1743
|
-
range:
|
|
1744
|
-
operator:
|
|
1594
|
+
isRange: !!(u[1] || u[2]),
|
|
1595
|
+
version: u[3],
|
|
1596
|
+
range: r,
|
|
1597
|
+
operator: u[1] || u[2] || "",
|
|
1745
1598
|
major: n,
|
|
1746
1599
|
minor: h,
|
|
1747
1600
|
patch: l,
|
|
@@ -1750,28 +1603,28 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
1750
1603
|
h,
|
|
1751
1604
|
l
|
|
1752
1605
|
],
|
|
1753
|
-
prerelease:
|
|
1606
|
+
prerelease: u[7],
|
|
1754
1607
|
number: n * 1e8 + h * 1e4 + l
|
|
1755
1608
|
};
|
|
1756
|
-
}, e.versionSatisfies = function(
|
|
1757
|
-
|
|
1758
|
-
var
|
|
1759
|
-
if (
|
|
1760
|
-
if (
|
|
1761
|
-
if (
|
|
1762
|
-
if (
|
|
1763
|
-
if (
|
|
1764
|
-
if (
|
|
1765
|
-
return
|
|
1766
|
-
}
|
|
1767
|
-
return
|
|
1609
|
+
}, e.versionSatisfies = function(r, a) {
|
|
1610
|
+
a = a || "*";
|
|
1611
|
+
var u = e.versionParse(a), n = e.versionParse(r);
|
|
1612
|
+
if (u.isRange) {
|
|
1613
|
+
if (u.operator === "*" || r === "*") return !0;
|
|
1614
|
+
if (u.operator === ">") return n.number > u.number;
|
|
1615
|
+
if (u.operator === ">=") return n.number >= u.number;
|
|
1616
|
+
if (u.operator === "~") return n.major === u.major && n.minor === u.minor && n.patch >= u.patch;
|
|
1617
|
+
if (u.operator === "^")
|
|
1618
|
+
return u.major > 0 ? n.major === u.major && n.number >= u.number : u.minor > 0 ? n.minor === u.minor && n.patch >= u.patch : n.patch === u.patch;
|
|
1619
|
+
}
|
|
1620
|
+
return r === a || r === "*";
|
|
1768
1621
|
};
|
|
1769
1622
|
})();
|
|
1770
1623
|
}),
|
|
1771
|
-
(function(
|
|
1772
|
-
var
|
|
1773
|
-
|
|
1774
|
-
|
|
1624
|
+
(function(A, E) {
|
|
1625
|
+
var c = {};
|
|
1626
|
+
A.exports = c, (function() {
|
|
1627
|
+
c.create = function(e) {
|
|
1775
1628
|
return {
|
|
1776
1629
|
vertex: e,
|
|
1777
1630
|
normalImpulse: 0,
|
|
@@ -1780,14 +1633,14 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
1780
1633
|
};
|
|
1781
1634
|
})();
|
|
1782
1635
|
}),
|
|
1783
|
-
(function(
|
|
1636
|
+
(function(A, E, c) {
|
|
1784
1637
|
var e = {};
|
|
1785
|
-
|
|
1786
|
-
var o =
|
|
1638
|
+
A.exports = e;
|
|
1639
|
+
var o = c(7), r = c(18), a = c(13), u = c(19), n = c(5), h = c(6), l = c(10), t = c(0), i = c(4);
|
|
1787
1640
|
(function() {
|
|
1788
1641
|
e._deltaMax = 1e3 / 60, e.create = function(s) {
|
|
1789
1642
|
s = s || {};
|
|
1790
|
-
var
|
|
1643
|
+
var f = t.extend({
|
|
1791
1644
|
positionIterations: 6,
|
|
1792
1645
|
velocityIterations: 4,
|
|
1793
1646
|
constraintIterations: 2,
|
|
@@ -1807,284 +1660,284 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
1807
1660
|
lastUpdatesPerFrame: 0
|
|
1808
1661
|
}
|
|
1809
1662
|
}, s);
|
|
1810
|
-
return
|
|
1811
|
-
}, e.update = function(s,
|
|
1812
|
-
var m = t.now(), x = s.world, P = s.detector,
|
|
1813
|
-
|
|
1663
|
+
return f.world = s.world || h.create({ label: "World" }), f.pairs = s.pairs || u.create(), f.detector = s.detector || a.create(), f.detector.pairs = f.pairs, f.grid = { buckets: [] }, f.world.gravity = f.gravity, f.broadphase = f.grid, f.metrics = {}, f;
|
|
1664
|
+
}, e.update = function(s, f) {
|
|
1665
|
+
var m = t.now(), x = s.world, P = s.detector, T = s.pairs, g = s.timing, d = g.timestamp, y;
|
|
1666
|
+
f > e._deltaMax && t.warnOnce("Matter.Engine.update: delta argument is recommended to be less than or equal to", e._deltaMax.toFixed(3), "ms."), f = typeof f < "u" ? f : t._baseDelta, f *= g.timeScale, g.timestamp += f, g.lastDelta = f;
|
|
1814
1667
|
var v = {
|
|
1815
1668
|
timestamp: g.timestamp,
|
|
1816
|
-
delta:
|
|
1669
|
+
delta: f
|
|
1817
1670
|
};
|
|
1818
1671
|
n.trigger(s, "beforeUpdate", v);
|
|
1819
1672
|
var w = h.allBodies(x), S = h.allConstraints(x);
|
|
1820
|
-
for (x.isModified && (
|
|
1673
|
+
for (x.isModified && (a.setBodies(P, w), h.setModified(x, !1, !1, !0)), s.enableSleeping && o.update(w, f), e._bodiesApplyGravity(w, s.gravity), f > 0 && e._bodiesUpdate(w, f), n.trigger(s, "beforeSolve", v), l.preSolveAll(w), y = 0; y < s.constraintIterations; y++) l.solveAll(S, f);
|
|
1821
1674
|
l.postSolveAll(w);
|
|
1822
|
-
var C =
|
|
1823
|
-
|
|
1824
|
-
pairs:
|
|
1675
|
+
var C = a.collisions(P);
|
|
1676
|
+
u.update(T, C, d), s.enableSleeping && o.afterCollisions(T.list), T.collisionStart.length > 0 && n.trigger(s, "collisionStart", {
|
|
1677
|
+
pairs: T.collisionStart,
|
|
1825
1678
|
timestamp: g.timestamp,
|
|
1826
|
-
delta:
|
|
1679
|
+
delta: f
|
|
1827
1680
|
});
|
|
1828
1681
|
var M = t.clamp(20 / s.positionIterations, 0, 1);
|
|
1829
|
-
for (
|
|
1830
|
-
for (
|
|
1831
|
-
for (l.postSolveAll(w),
|
|
1832
|
-
return e._bodiesUpdateVelocities(w),
|
|
1833
|
-
pairs:
|
|
1682
|
+
for (r.preSolvePosition(T.list), y = 0; y < s.positionIterations; y++) r.solvePosition(T.list, f, M);
|
|
1683
|
+
for (r.postSolvePosition(w), l.preSolveAll(w), y = 0; y < s.constraintIterations; y++) l.solveAll(S, f);
|
|
1684
|
+
for (l.postSolveAll(w), r.preSolveVelocity(T.list), y = 0; y < s.velocityIterations; y++) r.solveVelocity(T.list, f);
|
|
1685
|
+
return e._bodiesUpdateVelocities(w), T.collisionActive.length > 0 && n.trigger(s, "collisionActive", {
|
|
1686
|
+
pairs: T.collisionActive,
|
|
1834
1687
|
timestamp: g.timestamp,
|
|
1835
|
-
delta:
|
|
1836
|
-
}),
|
|
1837
|
-
pairs:
|
|
1688
|
+
delta: f
|
|
1689
|
+
}), T.collisionEnd.length > 0 && n.trigger(s, "collisionEnd", {
|
|
1690
|
+
pairs: T.collisionEnd,
|
|
1838
1691
|
timestamp: g.timestamp,
|
|
1839
|
-
delta:
|
|
1692
|
+
delta: f
|
|
1840
1693
|
}), e._bodiesClearForces(w), n.trigger(s, "afterUpdate", v), s.timing.lastElapsed = t.now() - m, s;
|
|
1841
|
-
}, e.merge = function(s,
|
|
1842
|
-
if (t.extend(s,
|
|
1843
|
-
s.world =
|
|
1694
|
+
}, e.merge = function(s, f) {
|
|
1695
|
+
if (t.extend(s, f), f.world) {
|
|
1696
|
+
s.world = f.world, e.clear(s);
|
|
1844
1697
|
for (var m = h.allBodies(s.world), x = 0; x < m.length; x++) {
|
|
1845
1698
|
var P = m[x];
|
|
1846
1699
|
o.set(P, !1), P.id = t.nextId();
|
|
1847
1700
|
}
|
|
1848
1701
|
}
|
|
1849
1702
|
}, e.clear = function(s) {
|
|
1850
|
-
|
|
1703
|
+
u.clear(s.pairs), a.clear(s.detector);
|
|
1851
1704
|
}, e._bodiesClearForces = function(s) {
|
|
1852
|
-
for (var
|
|
1705
|
+
for (var f = s.length, m = 0; m < f; m++) {
|
|
1853
1706
|
var x = s[m];
|
|
1854
1707
|
x.force.x = 0, x.force.y = 0, x.torque = 0;
|
|
1855
1708
|
}
|
|
1856
|
-
}, e._bodiesApplyGravity = function(s,
|
|
1857
|
-
var m = typeof
|
|
1858
|
-
if (!(
|
|
1709
|
+
}, e._bodiesApplyGravity = function(s, f) {
|
|
1710
|
+
var m = typeof f.scale < "u" ? f.scale : 1e-3, x = s.length;
|
|
1711
|
+
if (!(f.x === 0 && f.y === 0 || m === 0))
|
|
1859
1712
|
for (var P = 0; P < x; P++) {
|
|
1860
|
-
var
|
|
1861
|
-
|
|
1713
|
+
var T = s[P];
|
|
1714
|
+
T.isStatic || T.isSleeping || (T.force.y += T.mass * f.y * m, T.force.x += T.mass * f.x * m);
|
|
1862
1715
|
}
|
|
1863
|
-
}, e._bodiesUpdate = function(s,
|
|
1716
|
+
}, e._bodiesUpdate = function(s, f) {
|
|
1864
1717
|
for (var m = s.length, x = 0; x < m; x++) {
|
|
1865
1718
|
var P = s[x];
|
|
1866
|
-
P.isStatic || P.isSleeping || i.update(P,
|
|
1719
|
+
P.isStatic || P.isSleeping || i.update(P, f);
|
|
1867
1720
|
}
|
|
1868
1721
|
}, e._bodiesUpdateVelocities = function(s) {
|
|
1869
|
-
for (var
|
|
1722
|
+
for (var f = s.length, m = 0; m < f; m++) i.updateVelocities(s[m]);
|
|
1870
1723
|
};
|
|
1871
1724
|
})();
|
|
1872
1725
|
}),
|
|
1873
|
-
(function(
|
|
1726
|
+
(function(A, E, c) {
|
|
1874
1727
|
var e = {};
|
|
1875
|
-
|
|
1876
|
-
var o =
|
|
1728
|
+
A.exports = e;
|
|
1729
|
+
var o = c(3), r = c(0), a = c(1);
|
|
1877
1730
|
(function() {
|
|
1878
|
-
e._restingThresh = 2, e._restingThreshTangent = Math.sqrt(6), e._positionDampen = 0.9, e._positionWarming = 0.8, e._frictionNormalMultiplier = 5, e._frictionMaxStatic = Number.MAX_VALUE, e.preSolvePosition = function(
|
|
1879
|
-
var n, h, l, t =
|
|
1731
|
+
e._restingThresh = 2, e._restingThreshTangent = Math.sqrt(6), e._positionDampen = 0.9, e._positionWarming = 0.8, e._frictionNormalMultiplier = 5, e._frictionMaxStatic = Number.MAX_VALUE, e.preSolvePosition = function(u) {
|
|
1732
|
+
var n, h, l, t = u.length;
|
|
1880
1733
|
for (n = 0; n < t; n++)
|
|
1881
|
-
h =
|
|
1882
|
-
}, e.solvePosition = function(
|
|
1883
|
-
var l, t, i, s,
|
|
1884
|
-
for (l = 0; l <
|
|
1885
|
-
t =
|
|
1886
|
-
for (l = 0; l <
|
|
1887
|
-
t =
|
|
1888
|
-
}, e.postSolvePosition = function(
|
|
1889
|
-
for (var n = e._positionWarming, h =
|
|
1890
|
-
var s =
|
|
1734
|
+
h = u[n], h.isActive && (l = h.contactCount, h.collision.parentA.totalContacts += l, h.collision.parentB.totalContacts += l);
|
|
1735
|
+
}, e.solvePosition = function(u, n, h) {
|
|
1736
|
+
var l, t, i, s, f, m, x, P, T = e._positionDampen * (h || 1), g = r.clamp(n / r._baseDelta, 0, 1), d = u.length;
|
|
1737
|
+
for (l = 0; l < d; l++)
|
|
1738
|
+
t = u[l], !(!t.isActive || t.isSensor) && (i = t.collision, s = i.parentA, f = i.parentB, m = i.normal, t.separation = i.depth + m.x * (f.positionImpulse.x - s.positionImpulse.x) + m.y * (f.positionImpulse.y - s.positionImpulse.y));
|
|
1739
|
+
for (l = 0; l < d; l++)
|
|
1740
|
+
t = u[l], !(!t.isActive || t.isSensor) && (i = t.collision, s = i.parentA, f = i.parentB, m = i.normal, P = t.separation - t.slop * g, (s.isStatic || f.isStatic) && (P *= 2), s.isStatic || s.isSleeping || (x = T / s.totalContacts, s.positionImpulse.x += m.x * P * x, s.positionImpulse.y += m.y * P * x), f.isStatic || f.isSleeping || (x = T / f.totalContacts, f.positionImpulse.x -= m.x * P * x, f.positionImpulse.y -= m.y * P * x));
|
|
1741
|
+
}, e.postSolvePosition = function(u) {
|
|
1742
|
+
for (var n = e._positionWarming, h = u.length, l = o.translate, t = a.update, i = 0; i < h; i++) {
|
|
1743
|
+
var s = u[i], f = s.positionImpulse, m = f.x, x = f.y, P = s.velocity;
|
|
1891
1744
|
if (s.totalContacts = 0, m !== 0 || x !== 0) {
|
|
1892
|
-
for (var
|
|
1893
|
-
var g = s.parts[
|
|
1894
|
-
l(g.vertices,
|
|
1745
|
+
for (var T = 0; T < s.parts.length; T++) {
|
|
1746
|
+
var g = s.parts[T];
|
|
1747
|
+
l(g.vertices, f), t(g.bounds, g.vertices, P), g.position.x += m, g.position.y += x;
|
|
1895
1748
|
}
|
|
1896
|
-
s.positionPrev.x += m, s.positionPrev.y += x, m * P.x + x * P.y < 0 ? (
|
|
1749
|
+
s.positionPrev.x += m, s.positionPrev.y += x, m * P.x + x * P.y < 0 ? (f.x = 0, f.y = 0) : (f.x *= n, f.y *= n);
|
|
1897
1750
|
}
|
|
1898
1751
|
}
|
|
1899
|
-
}, e.preSolveVelocity = function(
|
|
1900
|
-
var n =
|
|
1752
|
+
}, e.preSolveVelocity = function(u) {
|
|
1753
|
+
var n = u.length, h, l;
|
|
1901
1754
|
for (h = 0; h < n; h++) {
|
|
1902
|
-
var t =
|
|
1755
|
+
var t = u[h];
|
|
1903
1756
|
if (!(!t.isActive || t.isSensor)) {
|
|
1904
|
-
var i = t.contacts, s = t.contactCount,
|
|
1757
|
+
var i = t.contacts, s = t.contactCount, f = t.collision, m = f.parentA, x = f.parentB, P = f.normal, T = f.tangent;
|
|
1905
1758
|
for (l = 0; l < s; l++) {
|
|
1906
|
-
var g = i[l],
|
|
1759
|
+
var g = i[l], d = g.vertex, y = g.normalImpulse, v = g.tangentImpulse;
|
|
1907
1760
|
if (y !== 0 || v !== 0) {
|
|
1908
|
-
var w = P.x * y +
|
|
1909
|
-
m.isStatic || m.isSleeping || (m.positionPrev.x += w * m.inverseMass, m.positionPrev.y += S * m.inverseMass, m.anglePrev += m.inverseInertia * ((
|
|
1761
|
+
var w = P.x * y + T.x * v, S = P.y * y + T.y * v;
|
|
1762
|
+
m.isStatic || m.isSleeping || (m.positionPrev.x += w * m.inverseMass, m.positionPrev.y += S * m.inverseMass, m.anglePrev += m.inverseInertia * ((d.x - m.position.x) * S - (d.y - m.position.y) * w)), x.isStatic || x.isSleeping || (x.positionPrev.x -= w * x.inverseMass, x.positionPrev.y -= S * x.inverseMass, x.anglePrev -= x.inverseInertia * ((d.x - x.position.x) * S - (d.y - x.position.y) * w));
|
|
1910
1763
|
}
|
|
1911
1764
|
}
|
|
1912
1765
|
}
|
|
1913
1766
|
}
|
|
1914
|
-
}, e.solveVelocity = function(
|
|
1915
|
-
var h = n /
|
|
1916
|
-
for (
|
|
1917
|
-
var
|
|
1918
|
-
if (!(!
|
|
1919
|
-
var y =
|
|
1767
|
+
}, e.solveVelocity = function(u, n) {
|
|
1768
|
+
var h = n / r._baseDelta, l = h * h * h, t = -e._restingThresh * h, i = e._restingThreshTangent, s = e._frictionNormalMultiplier * h, f = e._frictionMaxStatic, m = u.length, x, P, T, g;
|
|
1769
|
+
for (T = 0; T < m; T++) {
|
|
1770
|
+
var d = u[T];
|
|
1771
|
+
if (!(!d.isActive || d.isSensor)) {
|
|
1772
|
+
var y = d.collision, v = y.parentA, w = y.parentB, S = y.normal.x, C = y.normal.y, M = y.tangent.x, I = y.tangent.y, R = d.inverseMass, L = d.friction * d.frictionStatic * s, D = d.contacts, k = d.contactCount, b = 1 / k, O = v.position.x - v.positionPrev.x, W = v.position.y - v.positionPrev.y, G = v.angle - v.anglePrev, N = w.position.x - w.positionPrev.x, Q = w.position.y - w.positionPrev.y, X = w.angle - w.anglePrev;
|
|
1920
1773
|
for (g = 0; g < k; g++) {
|
|
1921
|
-
var
|
|
1922
|
-
|
|
1923
|
-
var
|
|
1924
|
-
$ < -
|
|
1925
|
-
var
|
|
1926
|
-
if (x *= ve, se < t)
|
|
1774
|
+
var F = D[g], H = F.vertex, V = H.x - v.position.x, J = H.y - v.position.y, Y = H.x - w.position.x, K = H.y - w.position.y, z = O - J * G, xe = W + V * G, ye = N - K * X, Se = Q + Y * X, le = z - ye, fe = xe - Se, se = S * le + C * fe, $ = M * le + I * fe, ce = d.separation + se, ae = Math.min(ce, 1);
|
|
1775
|
+
ae = ce < 0 ? 0 : ae;
|
|
1776
|
+
var ue = ae * L;
|
|
1777
|
+
$ < -ue || $ > ue ? (P = $ > 0 ? $ : -$, x = d.friction * ($ > 0 ? 1 : -1) * l, x < -P ? x = -P : x > P && (x = P)) : (x = $, P = f);
|
|
1778
|
+
var he = V * C - J * S, ge = Y * C - K * S, ve = b / (R + v.inverseInertia * he * he + w.inverseInertia * ge * ge), j = (1 + d.restitution) * se * ve;
|
|
1779
|
+
if (x *= ve, se < t) F.normalImpulse = 0;
|
|
1927
1780
|
else {
|
|
1928
|
-
var
|
|
1929
|
-
|
|
1781
|
+
var we = F.normalImpulse;
|
|
1782
|
+
F.normalImpulse += j, F.normalImpulse > 0 && (F.normalImpulse = 0), j = F.normalImpulse - we;
|
|
1930
1783
|
}
|
|
1931
|
-
if ($ < -i || $ > i)
|
|
1784
|
+
if ($ < -i || $ > i) F.tangentImpulse = 0;
|
|
1932
1785
|
else {
|
|
1933
|
-
var
|
|
1934
|
-
|
|
1786
|
+
var Pe = F.tangentImpulse;
|
|
1787
|
+
F.tangentImpulse += x, F.tangentImpulse < -P && (F.tangentImpulse = -P), F.tangentImpulse > P && (F.tangentImpulse = P), x = F.tangentImpulse - Pe;
|
|
1935
1788
|
}
|
|
1936
1789
|
var q = S * j + M * x, _ = C * j + I * x;
|
|
1937
|
-
v.isStatic || v.isSleeping || (v.positionPrev.x += q * v.inverseMass, v.positionPrev.y += _ * v.inverseMass, v.anglePrev += (
|
|
1790
|
+
v.isStatic || v.isSleeping || (v.positionPrev.x += q * v.inverseMass, v.positionPrev.y += _ * v.inverseMass, v.anglePrev += (V * _ - J * q) * v.inverseInertia), w.isStatic || w.isSleeping || (w.positionPrev.x -= q * w.inverseMass, w.positionPrev.y -= _ * w.inverseMass, w.anglePrev -= (Y * _ - K * q) * w.inverseInertia);
|
|
1938
1791
|
}
|
|
1939
1792
|
}
|
|
1940
1793
|
}
|
|
1941
1794
|
};
|
|
1942
1795
|
})();
|
|
1943
1796
|
}),
|
|
1944
|
-
(function(
|
|
1797
|
+
(function(A, E, c) {
|
|
1945
1798
|
var e = {};
|
|
1946
|
-
|
|
1947
|
-
var o =
|
|
1799
|
+
A.exports = e;
|
|
1800
|
+
var o = c(9), r = c(0);
|
|
1948
1801
|
(function() {
|
|
1949
|
-
e.create = function(
|
|
1950
|
-
return
|
|
1802
|
+
e.create = function(a) {
|
|
1803
|
+
return r.extend({
|
|
1951
1804
|
table: {},
|
|
1952
1805
|
list: [],
|
|
1953
1806
|
collisionStart: [],
|
|
1954
1807
|
collisionActive: [],
|
|
1955
1808
|
collisionEnd: []
|
|
1956
|
-
},
|
|
1957
|
-
}, e.update = function(
|
|
1958
|
-
var h = o.update, l = o.create, t = o.setActive, i =
|
|
1809
|
+
}, a);
|
|
1810
|
+
}, e.update = function(a, u, n) {
|
|
1811
|
+
var h = o.update, l = o.create, t = o.setActive, i = a.table, s = a.list, f = s.length, m = f, x = a.collisionStart, P = a.collisionEnd, T = a.collisionActive, g = u.length, d = 0, y = 0, v = 0, w, S, C;
|
|
1959
1812
|
for (C = 0; C < g; C++)
|
|
1960
|
-
w =
|
|
1961
|
-
for (m = 0,
|
|
1813
|
+
w = u[C], S = w.pair, S ? (S.isActive && (T[v++] = S), h(S, w, n)) : (S = l(w, n), i[S.id] = S, x[d++] = S, s[m++] = S);
|
|
1814
|
+
for (m = 0, f = s.length, C = 0; C < f; C++)
|
|
1962
1815
|
S = s[C], S.timeUpdated >= n ? s[m++] = S : (t(S, !1, n), S.collision.bodyA.sleepCounter > 0 && S.collision.bodyB.sleepCounter > 0 ? s[m++] = S : (P[y++] = S, delete i[S.id]));
|
|
1963
|
-
s.length !== m && (s.length = m), x.length !==
|
|
1964
|
-
}, e.clear = function(
|
|
1965
|
-
return
|
|
1816
|
+
s.length !== m && (s.length = m), x.length !== d && (x.length = d), P.length !== y && (P.length = y), T.length !== v && (T.length = v);
|
|
1817
|
+
}, e.clear = function(a) {
|
|
1818
|
+
return a.table = {}, a.list.length = 0, a.collisionStart.length = 0, a.collisionActive.length = 0, a.collisionEnd.length = 0, a;
|
|
1966
1819
|
};
|
|
1967
1820
|
})();
|
|
1968
1821
|
}),
|
|
1969
|
-
(function(
|
|
1970
|
-
var e =
|
|
1971
|
-
e.Axes =
|
|
1822
|
+
(function(A, E, c) {
|
|
1823
|
+
var e = A.exports = c(21);
|
|
1824
|
+
e.Axes = c(11), e.Bodies = c(12), e.Body = c(4), e.Bounds = c(1), e.Collision = c(8), e.Common = c(0), e.Composite = c(6), e.Composites = c(22), e.Constraint = c(10), e.Contact = c(16), e.Detector = c(13), e.Engine = c(17), e.Events = c(5), e.Grid = c(23), e.Mouse = c(14), e.MouseConstraint = c(24), e.Pair = c(9), e.Pairs = c(19), e.Plugin = c(15), e.Query = c(25), e.Render = c(26), e.Resolver = c(18), e.Runner = c(27), e.SAT = c(28), e.Sleeping = c(7), e.Svg = c(29), e.Vector = c(2), e.Vertices = c(3), e.World = c(30), e.Engine.run = e.Runner.run, e.Common.deprecated(e.Engine, "run", "Engine.run ➤ use Matter.Runner.run(engine) instead");
|
|
1972
1825
|
}),
|
|
1973
|
-
(function(
|
|
1826
|
+
(function(A, E, c) {
|
|
1974
1827
|
var e = {};
|
|
1975
|
-
|
|
1976
|
-
var o =
|
|
1828
|
+
A.exports = e;
|
|
1829
|
+
var o = c(15), r = c(0);
|
|
1977
1830
|
(function() {
|
|
1978
1831
|
e.name = "matter-js", e.version = "0.20.0", e.uses = [], e.used = [], e.use = function() {
|
|
1979
1832
|
o.use(e, Array.prototype.slice.call(arguments));
|
|
1980
|
-
}, e.before = function(
|
|
1981
|
-
return
|
|
1982
|
-
}, e.after = function(
|
|
1983
|
-
return
|
|
1833
|
+
}, e.before = function(a, u) {
|
|
1834
|
+
return a = a.replace(/^Matter./, ""), r.chainPathBefore(e, a, u);
|
|
1835
|
+
}, e.after = function(a, u) {
|
|
1836
|
+
return a = a.replace(/^Matter./, ""), r.chainPathAfter(e, a, u);
|
|
1984
1837
|
};
|
|
1985
1838
|
})();
|
|
1986
1839
|
}),
|
|
1987
|
-
(function(
|
|
1840
|
+
(function(A, E, c) {
|
|
1988
1841
|
var e = {};
|
|
1989
|
-
|
|
1990
|
-
var o =
|
|
1842
|
+
A.exports = e;
|
|
1843
|
+
var o = c(6), r = c(10), a = c(0), u = c(4), n = c(12), h = a.deprecated;
|
|
1991
1844
|
(function() {
|
|
1992
|
-
e.stack = function(l, t, i, s,
|
|
1993
|
-
for (var P = o.create({ label: "Stack" }),
|
|
1845
|
+
e.stack = function(l, t, i, s, f, m, x) {
|
|
1846
|
+
for (var P = o.create({ label: "Stack" }), T = l, g = t, d, y = 0, v = 0; v < s; v++) {
|
|
1994
1847
|
for (var w = 0, S = 0; S < i; S++) {
|
|
1995
|
-
var C = x(
|
|
1848
|
+
var C = x(T, g, S, v, d, y);
|
|
1996
1849
|
if (C) {
|
|
1997
1850
|
var M = C.bounds.max.y - C.bounds.min.y, I = C.bounds.max.x - C.bounds.min.x;
|
|
1998
|
-
M > w && (w = M),
|
|
1851
|
+
M > w && (w = M), u.translate(C, {
|
|
1999
1852
|
x: I * 0.5,
|
|
2000
1853
|
y: M * 0.5
|
|
2001
|
-
}),
|
|
2002
|
-
} else
|
|
1854
|
+
}), T = C.bounds.max.x + f, o.addBody(P, C), d = C, y += 1;
|
|
1855
|
+
} else T += f;
|
|
2003
1856
|
}
|
|
2004
|
-
g += w + m,
|
|
1857
|
+
g += w + m, T = l;
|
|
2005
1858
|
}
|
|
2006
1859
|
return P;
|
|
2007
|
-
}, e.chain = function(l, t, i, s,
|
|
1860
|
+
}, e.chain = function(l, t, i, s, f, m) {
|
|
2008
1861
|
for (var x = l.bodies, P = 1; P < x.length; P++) {
|
|
2009
|
-
var
|
|
2010
|
-
bodyA:
|
|
1862
|
+
var T = x[P - 1], g = x[P], d = T.bounds.max.y - T.bounds.min.y, y = T.bounds.max.x - T.bounds.min.x, v = g.bounds.max.y - g.bounds.min.y, w = g.bounds.max.x - g.bounds.min.x, S = {
|
|
1863
|
+
bodyA: T,
|
|
2011
1864
|
pointA: {
|
|
2012
1865
|
x: y * t,
|
|
2013
|
-
y:
|
|
1866
|
+
y: d * i
|
|
2014
1867
|
},
|
|
2015
1868
|
bodyB: g,
|
|
2016
1869
|
pointB: {
|
|
2017
1870
|
x: w * s,
|
|
2018
|
-
y: v *
|
|
1871
|
+
y: v * f
|
|
2019
1872
|
}
|
|
2020
|
-
}, C =
|
|
2021
|
-
o.addConstraint(l,
|
|
1873
|
+
}, C = a.extend(S, m);
|
|
1874
|
+
o.addConstraint(l, r.create(C));
|
|
2022
1875
|
}
|
|
2023
1876
|
return l.label += " Chain", l;
|
|
2024
|
-
}, e.mesh = function(l, t, i, s,
|
|
2025
|
-
var m = l.bodies, x, P,
|
|
1877
|
+
}, e.mesh = function(l, t, i, s, f) {
|
|
1878
|
+
var m = l.bodies, x, P, T, g, d;
|
|
2026
1879
|
for (x = 0; x < i; x++) {
|
|
2027
1880
|
for (P = 1; P < t; P++)
|
|
2028
|
-
|
|
2029
|
-
bodyA:
|
|
1881
|
+
T = m[P - 1 + x * t], g = m[P + x * t], o.addConstraint(l, r.create(a.extend({
|
|
1882
|
+
bodyA: T,
|
|
2030
1883
|
bodyB: g
|
|
2031
|
-
},
|
|
1884
|
+
}, f)));
|
|
2032
1885
|
if (x > 0) for (P = 0; P < t; P++)
|
|
2033
|
-
|
|
2034
|
-
bodyA:
|
|
1886
|
+
T = m[P + (x - 1) * t], g = m[P + x * t], o.addConstraint(l, r.create(a.extend({
|
|
1887
|
+
bodyA: T,
|
|
2035
1888
|
bodyB: g
|
|
2036
|
-
},
|
|
2037
|
-
bodyA:
|
|
1889
|
+
}, f))), s && P > 0 && (d = m[P - 1 + (x - 1) * t], o.addConstraint(l, r.create(a.extend({
|
|
1890
|
+
bodyA: d,
|
|
2038
1891
|
bodyB: g
|
|
2039
|
-
},
|
|
2040
|
-
bodyA:
|
|
1892
|
+
}, f)))), s && P < t - 1 && (d = m[P + 1 + (x - 1) * t], o.addConstraint(l, r.create(a.extend({
|
|
1893
|
+
bodyA: d,
|
|
2041
1894
|
bodyB: g
|
|
2042
|
-
},
|
|
1895
|
+
}, f))));
|
|
2043
1896
|
}
|
|
2044
1897
|
return l.label += " Mesh", l;
|
|
2045
|
-
}, e.pyramid = function(l, t, i, s,
|
|
2046
|
-
return e.stack(l, t, i, s,
|
|
1898
|
+
}, e.pyramid = function(l, t, i, s, f, m, x) {
|
|
1899
|
+
return e.stack(l, t, i, s, f, m, function(P, T, g, d, y, v) {
|
|
2047
1900
|
var w = Math.min(s, Math.ceil(i / 2)), S = y ? y.bounds.max.x - y.bounds.min.x : 0;
|
|
2048
|
-
if (!(
|
|
2049
|
-
|
|
2050
|
-
var C =
|
|
1901
|
+
if (!(d > w)) {
|
|
1902
|
+
d = w - d;
|
|
1903
|
+
var C = d, M = i - 1 - d;
|
|
2051
1904
|
if (!(g < C || g > M))
|
|
2052
|
-
return v === 1 &&
|
|
1905
|
+
return v === 1 && u.translate(y, {
|
|
2053
1906
|
x: (g + (i % 2 === 1 ? 1 : -1)) * S,
|
|
2054
1907
|
y: 0
|
|
2055
|
-
}), x(l + (y ? g * S : 0) + g *
|
|
1908
|
+
}), x(l + (y ? g * S : 0) + g * f, T, g, d, y, v);
|
|
2056
1909
|
}
|
|
2057
1910
|
});
|
|
2058
|
-
}, e.newtonsCradle = function(l, t, i, s,
|
|
1911
|
+
}, e.newtonsCradle = function(l, t, i, s, f) {
|
|
2059
1912
|
for (var m = o.create({ label: "Newtons Cradle" }), x = 0; x < i; x++) {
|
|
2060
|
-
var P = 1.9,
|
|
1913
|
+
var P = 1.9, T = n.circle(l + x * (s * P), t + f, s, {
|
|
2061
1914
|
inertia: 1 / 0,
|
|
2062
1915
|
restitution: 1,
|
|
2063
1916
|
friction: 0,
|
|
2064
1917
|
frictionAir: 1e-4,
|
|
2065
1918
|
slop: 1
|
|
2066
|
-
}), g =
|
|
1919
|
+
}), g = r.create({
|
|
2067
1920
|
pointA: {
|
|
2068
1921
|
x: l + x * (s * P),
|
|
2069
1922
|
y: t
|
|
2070
1923
|
},
|
|
2071
|
-
bodyB:
|
|
1924
|
+
bodyB: T
|
|
2072
1925
|
});
|
|
2073
|
-
o.addBody(m,
|
|
1926
|
+
o.addBody(m, T), o.addConstraint(m, g);
|
|
2074
1927
|
}
|
|
2075
1928
|
return m;
|
|
2076
|
-
}, h(e, "newtonsCradle", "Composites.newtonsCradle ➤ moved to newtonsCradle example"), e.car = function(l, t, i, s,
|
|
2077
|
-
var m =
|
|
1929
|
+
}, h(e, "newtonsCradle", "Composites.newtonsCradle ➤ moved to newtonsCradle example"), e.car = function(l, t, i, s, f) {
|
|
1930
|
+
var m = u.nextGroup(!0), x = 20, P = -i * 0.5 + x, T = i * 0.5 - x, g = 0, d = o.create({ label: "Car" }), y = n.rectangle(l, t, i, s, {
|
|
2078
1931
|
collisionFilter: { group: m },
|
|
2079
1932
|
chamfer: { radius: s * 0.5 },
|
|
2080
1933
|
density: 2e-4
|
|
2081
|
-
}), v = n.circle(l + P, t + g,
|
|
1934
|
+
}), v = n.circle(l + P, t + g, f, {
|
|
2082
1935
|
collisionFilter: { group: m },
|
|
2083
1936
|
friction: 0.8
|
|
2084
|
-
}), w = n.circle(l +
|
|
1937
|
+
}), w = n.circle(l + T, t + g, f, {
|
|
2085
1938
|
collisionFilter: { group: m },
|
|
2086
1939
|
friction: 0.8
|
|
2087
|
-
}), S =
|
|
1940
|
+
}), S = r.create({
|
|
2088
1941
|
bodyB: y,
|
|
2089
1942
|
pointB: {
|
|
2090
1943
|
x: P,
|
|
@@ -2093,122 +1946,122 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
2093
1946
|
bodyA: v,
|
|
2094
1947
|
stiffness: 1,
|
|
2095
1948
|
length: 0
|
|
2096
|
-
}), C =
|
|
1949
|
+
}), C = r.create({
|
|
2097
1950
|
bodyB: y,
|
|
2098
1951
|
pointB: {
|
|
2099
|
-
x:
|
|
1952
|
+
x: T,
|
|
2100
1953
|
y: g
|
|
2101
1954
|
},
|
|
2102
1955
|
bodyA: w,
|
|
2103
1956
|
stiffness: 1,
|
|
2104
1957
|
length: 0
|
|
2105
1958
|
});
|
|
2106
|
-
return o.addBody(
|
|
2107
|
-
}, h(e, "car", "Composites.car ➤ moved to car example"), e.softBody = function(l, t, i, s,
|
|
2108
|
-
|
|
1959
|
+
return o.addBody(d, y), o.addBody(d, v), o.addBody(d, w), o.addConstraint(d, S), o.addConstraint(d, C), d;
|
|
1960
|
+
}, h(e, "car", "Composites.car ➤ moved to car example"), e.softBody = function(l, t, i, s, f, m, x, P, T, g) {
|
|
1961
|
+
T = a.extend({ inertia: 1 / 0 }, T), g = a.extend({
|
|
2109
1962
|
stiffness: 0.2,
|
|
2110
1963
|
render: {
|
|
2111
1964
|
type: "line",
|
|
2112
1965
|
anchors: !1
|
|
2113
1966
|
}
|
|
2114
1967
|
}, g);
|
|
2115
|
-
var
|
|
2116
|
-
return n.circle(y, v, P,
|
|
1968
|
+
var d = e.stack(l, t, i, s, f, m, function(y, v) {
|
|
1969
|
+
return n.circle(y, v, P, T);
|
|
2117
1970
|
});
|
|
2118
|
-
return e.mesh(
|
|
1971
|
+
return e.mesh(d, i, s, x, g), d.label = "Soft Body", d;
|
|
2119
1972
|
}, h(e, "softBody", "Composites.softBody ➤ moved to softBody and cloth examples");
|
|
2120
1973
|
})();
|
|
2121
1974
|
}),
|
|
2122
|
-
(function(
|
|
1975
|
+
(function(A, E, c) {
|
|
2123
1976
|
var e = {};
|
|
2124
|
-
|
|
2125
|
-
var o =
|
|
1977
|
+
A.exports = e;
|
|
1978
|
+
var o = c(9), r = c(0), a = r.deprecated;
|
|
2126
1979
|
(function() {
|
|
2127
|
-
e.create = function(
|
|
2128
|
-
return
|
|
1980
|
+
e.create = function(u) {
|
|
1981
|
+
return r.extend({
|
|
2129
1982
|
buckets: {},
|
|
2130
1983
|
pairs: {},
|
|
2131
1984
|
pairsList: [],
|
|
2132
1985
|
bucketWidth: 48,
|
|
2133
1986
|
bucketHeight: 48
|
|
2134
|
-
},
|
|
2135
|
-
}, e.update = function(
|
|
2136
|
-
var t, i, s,
|
|
1987
|
+
}, u);
|
|
1988
|
+
}, e.update = function(u, n, h, l) {
|
|
1989
|
+
var t, i, s, f = h.world, m = u.buckets, x, P, T = !1;
|
|
2137
1990
|
for (t = 0; t < n.length; t++) {
|
|
2138
1991
|
var g = n[t];
|
|
2139
|
-
if (!(g.isSleeping && !l) && !(
|
|
2140
|
-
var
|
|
2141
|
-
if (!g.region ||
|
|
2142
|
-
(!g.region || l) && (g.region =
|
|
2143
|
-
var y = e._regionUnion(
|
|
1992
|
+
if (!(g.isSleeping && !l) && !(f.bounds && (g.bounds.max.x < f.bounds.min.x || g.bounds.min.x > f.bounds.max.x || g.bounds.max.y < f.bounds.min.y || g.bounds.min.y > f.bounds.max.y))) {
|
|
1993
|
+
var d = e._getRegion(u, g);
|
|
1994
|
+
if (!g.region || d.id !== g.region.id || l) {
|
|
1995
|
+
(!g.region || l) && (g.region = d);
|
|
1996
|
+
var y = e._regionUnion(d, g.region);
|
|
2144
1997
|
for (i = y.startCol; i <= y.endCol; i++) for (s = y.startRow; s <= y.endRow; s++) {
|
|
2145
1998
|
P = e._getBucketId(i, s), x = m[P];
|
|
2146
|
-
var v = i >=
|
|
2147
|
-
!v && w && w && x && e._bucketRemoveBody(
|
|
1999
|
+
var v = i >= d.startCol && i <= d.endCol && s >= d.startRow && s <= d.endRow, w = i >= g.region.startCol && i <= g.region.endCol && s >= g.region.startRow && s <= g.region.endRow;
|
|
2000
|
+
!v && w && w && x && e._bucketRemoveBody(u, x, g), (g.region === d || v && !w || l) && (x || (x = e._createBucket(m, P)), e._bucketAddBody(u, x, g));
|
|
2148
2001
|
}
|
|
2149
|
-
g.region =
|
|
2002
|
+
g.region = d, T = !0;
|
|
2150
2003
|
}
|
|
2151
2004
|
}
|
|
2152
2005
|
}
|
|
2153
|
-
|
|
2154
|
-
},
|
|
2155
|
-
|
|
2156
|
-
},
|
|
2157
|
-
var h = Math.min(
|
|
2006
|
+
T && (u.pairsList = e._createActivePairsList(u));
|
|
2007
|
+
}, a(e, "update", "Grid.update ➤ replaced by Matter.Detector"), e.clear = function(u) {
|
|
2008
|
+
u.buckets = {}, u.pairs = {}, u.pairsList = [];
|
|
2009
|
+
}, a(e, "clear", "Grid.clear ➤ replaced by Matter.Detector"), e._regionUnion = function(u, n) {
|
|
2010
|
+
var h = Math.min(u.startCol, n.startCol), l = Math.max(u.endCol, n.endCol), t = Math.min(u.startRow, n.startRow), i = Math.max(u.endRow, n.endRow);
|
|
2158
2011
|
return e._createRegion(h, l, t, i);
|
|
2159
|
-
}, e._getRegion = function(
|
|
2160
|
-
var h = n.bounds, l = Math.floor(h.min.x /
|
|
2012
|
+
}, e._getRegion = function(u, n) {
|
|
2013
|
+
var h = n.bounds, l = Math.floor(h.min.x / u.bucketWidth), t = Math.floor(h.max.x / u.bucketWidth), i = Math.floor(h.min.y / u.bucketHeight), s = Math.floor(h.max.y / u.bucketHeight);
|
|
2161
2014
|
return e._createRegion(l, t, i, s);
|
|
2162
|
-
}, e._createRegion = function(
|
|
2015
|
+
}, e._createRegion = function(u, n, h, l) {
|
|
2163
2016
|
return {
|
|
2164
|
-
id:
|
|
2165
|
-
startCol:
|
|
2017
|
+
id: u + "," + n + "," + h + "," + l,
|
|
2018
|
+
startCol: u,
|
|
2166
2019
|
endCol: n,
|
|
2167
2020
|
startRow: h,
|
|
2168
2021
|
endRow: l
|
|
2169
2022
|
};
|
|
2170
|
-
}, e._getBucketId = function(
|
|
2171
|
-
return "C" +
|
|
2172
|
-
}, e._createBucket = function(
|
|
2173
|
-
return
|
|
2174
|
-
}, e._bucketAddBody = function(
|
|
2175
|
-
var l =
|
|
2023
|
+
}, e._getBucketId = function(u, n) {
|
|
2024
|
+
return "C" + u + "R" + n;
|
|
2025
|
+
}, e._createBucket = function(u, n) {
|
|
2026
|
+
return u[n] = [];
|
|
2027
|
+
}, e._bucketAddBody = function(u, n, h) {
|
|
2028
|
+
var l = u.pairs, t = o.id, i = n.length, s;
|
|
2176
2029
|
for (s = 0; s < i; s++) {
|
|
2177
|
-
var
|
|
2178
|
-
if (!(h.id ===
|
|
2179
|
-
var m = t(h,
|
|
2030
|
+
var f = n[s];
|
|
2031
|
+
if (!(h.id === f.id || h.isStatic && f.isStatic)) {
|
|
2032
|
+
var m = t(h, f), x = l[m];
|
|
2180
2033
|
x ? x[2] += 1 : l[m] = [
|
|
2181
2034
|
h,
|
|
2182
|
-
|
|
2035
|
+
f,
|
|
2183
2036
|
1
|
|
2184
2037
|
];
|
|
2185
2038
|
}
|
|
2186
2039
|
}
|
|
2187
2040
|
n.push(h);
|
|
2188
|
-
}, e._bucketRemoveBody = function(
|
|
2189
|
-
var l =
|
|
2190
|
-
n.splice(
|
|
2041
|
+
}, e._bucketRemoveBody = function(u, n, h) {
|
|
2042
|
+
var l = u.pairs, t = o.id, i;
|
|
2043
|
+
n.splice(r.indexOf(n, h), 1);
|
|
2191
2044
|
var s = n.length;
|
|
2192
2045
|
for (i = 0; i < s; i++) {
|
|
2193
|
-
var
|
|
2194
|
-
|
|
2046
|
+
var f = l[t(h, n[i])];
|
|
2047
|
+
f && (f[2] -= 1);
|
|
2195
2048
|
}
|
|
2196
|
-
}, e._createActivePairsList = function(
|
|
2197
|
-
var n, h =
|
|
2049
|
+
}, e._createActivePairsList = function(u) {
|
|
2050
|
+
var n, h = u.pairs, l = r.keys(h), t = l.length, i = [], s;
|
|
2198
2051
|
for (s = 0; s < t; s++)
|
|
2199
2052
|
n = h[l[s]], n[2] > 0 ? i.push(n) : delete h[l[s]];
|
|
2200
2053
|
return i;
|
|
2201
2054
|
};
|
|
2202
2055
|
})();
|
|
2203
2056
|
}),
|
|
2204
|
-
(function(
|
|
2057
|
+
(function(A, E, c) {
|
|
2205
2058
|
var e = {};
|
|
2206
|
-
|
|
2207
|
-
var o =
|
|
2059
|
+
A.exports = e;
|
|
2060
|
+
var o = c(3), r = c(7), a = c(14), u = c(5), n = c(13), h = c(10), l = c(6), t = c(0), i = c(1);
|
|
2208
2061
|
(function() {
|
|
2209
|
-
e.create = function(s,
|
|
2210
|
-
var m = (s ? s.mouse : null) || (
|
|
2211
|
-
m || (s && s.render && s.render.canvas ? m =
|
|
2062
|
+
e.create = function(s, f) {
|
|
2063
|
+
var m = (s ? s.mouse : null) || (f ? f.mouse : null);
|
|
2064
|
+
m || (s && s.render && s.render.canvas ? m = a.create(s.render.canvas) : f && f.element ? m = a.create(f.element) : (m = a.create(), t.warn("MouseConstraint.create: options.mouse was undefined, options.element was undefined, may not function as expected")));
|
|
2212
2065
|
var x = h.create({
|
|
2213
2066
|
label: "Mouse Constraint",
|
|
2214
2067
|
pointA: m.position,
|
|
@@ -2234,24 +2087,24 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
2234
2087
|
mask: 4294967295,
|
|
2235
2088
|
group: 0
|
|
2236
2089
|
}
|
|
2237
|
-
},
|
|
2238
|
-
return
|
|
2090
|
+
}, T = t.extend(P, f);
|
|
2091
|
+
return u.on(s, "beforeUpdate", function() {
|
|
2239
2092
|
var g = l.allBodies(s.world);
|
|
2240
|
-
e.update(
|
|
2241
|
-
}),
|
|
2242
|
-
}, e.update = function(s,
|
|
2093
|
+
e.update(T, g), e._triggerEvents(T);
|
|
2094
|
+
}), T;
|
|
2095
|
+
}, e.update = function(s, f) {
|
|
2243
2096
|
var m = s.mouse, x = s.constraint, P = s.body;
|
|
2244
2097
|
if (m.button === 0) {
|
|
2245
|
-
if (x.bodyB)
|
|
2098
|
+
if (x.bodyB) r.set(x.bodyB, !1), x.pointA = m.position;
|
|
2246
2099
|
else
|
|
2247
|
-
for (var
|
|
2248
|
-
if (P =
|
|
2249
|
-
var
|
|
2250
|
-
if (o.contains(
|
|
2100
|
+
for (var T = 0; T < f.length; T++)
|
|
2101
|
+
if (P = f[T], i.contains(P.bounds, m.position) && n.canCollide(P.collisionFilter, s.collisionFilter)) for (var g = P.parts.length > 1 ? 1 : 0; g < P.parts.length; g++) {
|
|
2102
|
+
var d = P.parts[g];
|
|
2103
|
+
if (o.contains(d.vertices, m.position)) {
|
|
2251
2104
|
x.pointA = m.position, x.bodyB = s.body = P, x.pointB = {
|
|
2252
2105
|
x: m.position.x - P.position.x,
|
|
2253
2106
|
y: m.position.y - P.position.y
|
|
2254
|
-
}, x.angleB = P.angle,
|
|
2107
|
+
}, x.angleB = P.angle, r.set(P, !1), u.trigger(s, "startdrag", {
|
|
2255
2108
|
mouse: m,
|
|
2256
2109
|
body: P
|
|
2257
2110
|
});
|
|
@@ -2259,28 +2112,28 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
2259
2112
|
}
|
|
2260
2113
|
}
|
|
2261
2114
|
} else
|
|
2262
|
-
x.bodyB = s.body = null, x.pointB = null, P &&
|
|
2115
|
+
x.bodyB = s.body = null, x.pointB = null, P && u.trigger(s, "enddrag", {
|
|
2263
2116
|
mouse: m,
|
|
2264
2117
|
body: P
|
|
2265
2118
|
});
|
|
2266
2119
|
}, e._triggerEvents = function(s) {
|
|
2267
|
-
var
|
|
2268
|
-
m.mousemove &&
|
|
2120
|
+
var f = s.mouse, m = f.sourceEvents;
|
|
2121
|
+
m.mousemove && u.trigger(s, "mousemove", { mouse: f }), m.mousedown && u.trigger(s, "mousedown", { mouse: f }), m.mouseup && u.trigger(s, "mouseup", { mouse: f }), a.clearSourceEvents(f);
|
|
2269
2122
|
};
|
|
2270
2123
|
})();
|
|
2271
2124
|
}),
|
|
2272
|
-
(function(
|
|
2125
|
+
(function(A, E, c) {
|
|
2273
2126
|
var e = {};
|
|
2274
|
-
|
|
2275
|
-
var o =
|
|
2127
|
+
A.exports = e;
|
|
2128
|
+
var o = c(2), r = c(8), a = c(1), u = c(12), n = c(3);
|
|
2276
2129
|
(function() {
|
|
2277
2130
|
e.collides = function(h, l) {
|
|
2278
|
-
for (var t = [], i = l.length, s = h.bounds,
|
|
2279
|
-
var P = l[x],
|
|
2280
|
-
if (m(P.bounds, s)) for (var
|
|
2281
|
-
var y = P.parts[
|
|
2131
|
+
for (var t = [], i = l.length, s = h.bounds, f = r.collides, m = a.overlaps, x = 0; x < i; x++) {
|
|
2132
|
+
var P = l[x], T = P.parts.length, g = T === 1 ? 0 : 1;
|
|
2133
|
+
if (m(P.bounds, s)) for (var d = g; d < T; d++) {
|
|
2134
|
+
var y = P.parts[d];
|
|
2282
2135
|
if (m(y.bounds, s)) {
|
|
2283
|
-
var v =
|
|
2136
|
+
var v = f(y, h);
|
|
2284
2137
|
if (v) {
|
|
2285
2138
|
t.push(v);
|
|
2286
2139
|
break;
|
|
@@ -2291,23 +2144,23 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
2291
2144
|
return t;
|
|
2292
2145
|
}, e.ray = function(h, l, t, i) {
|
|
2293
2146
|
i = i || 1e-100;
|
|
2294
|
-
for (var s = o.angle(l, t),
|
|
2295
|
-
var
|
|
2296
|
-
|
|
2147
|
+
for (var s = o.angle(l, t), f = o.magnitude(o.sub(l, t)), m = (t.x + l.x) * 0.5, x = (t.y + l.y) * 0.5, P = u.rectangle(m, x, f, i, { angle: s }), T = e.collides(P, h), g = 0; g < T.length; g += 1) {
|
|
2148
|
+
var d = T[g];
|
|
2149
|
+
d.body = d.bodyB = d.bodyA;
|
|
2297
2150
|
}
|
|
2298
|
-
return
|
|
2151
|
+
return T;
|
|
2299
2152
|
}, e.region = function(h, l, t) {
|
|
2300
2153
|
for (var i = [], s = 0; s < h.length; s++) {
|
|
2301
|
-
var
|
|
2302
|
-
(m && !t || !m && t) && i.push(
|
|
2154
|
+
var f = h[s], m = a.overlaps(f.bounds, l);
|
|
2155
|
+
(m && !t || !m && t) && i.push(f);
|
|
2303
2156
|
}
|
|
2304
2157
|
return i;
|
|
2305
2158
|
}, e.point = function(h, l) {
|
|
2306
2159
|
for (var t = [], i = 0; i < h.length; i++) {
|
|
2307
2160
|
var s = h[i];
|
|
2308
|
-
if (
|
|
2309
|
-
var m = s.parts[
|
|
2310
|
-
if (
|
|
2161
|
+
if (a.contains(s.bounds, l)) for (var f = s.parts.length === 1 ? 0 : 1; f < s.parts.length; f++) {
|
|
2162
|
+
var m = s.parts[f];
|
|
2163
|
+
if (a.contains(m.bounds, l) && n.contains(m.vertices, l)) {
|
|
2311
2164
|
t.push(s);
|
|
2312
2165
|
break;
|
|
2313
2166
|
}
|
|
@@ -2317,18 +2170,18 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
2317
2170
|
};
|
|
2318
2171
|
})();
|
|
2319
2172
|
}),
|
|
2320
|
-
(function(
|
|
2173
|
+
(function(A, E, c) {
|
|
2321
2174
|
var e = {};
|
|
2322
|
-
|
|
2323
|
-
var o =
|
|
2175
|
+
A.exports = e;
|
|
2176
|
+
var o = c(4), r = c(0), a = c(6), u = c(1), n = c(5), h = c(2), l = c(14);
|
|
2324
2177
|
(function() {
|
|
2325
2178
|
var t, i;
|
|
2326
2179
|
typeof window < "u" && (t = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.msRequestAnimationFrame || function(g) {
|
|
2327
2180
|
window.setTimeout(function() {
|
|
2328
|
-
g(
|
|
2181
|
+
g(r.now());
|
|
2329
2182
|
}, 1e3 / 60);
|
|
2330
2183
|
}, i = window.cancelAnimationFrame || window.mozCancelAnimationFrame || window.webkitCancelAnimationFrame || window.msCancelAnimationFrame), e._goodFps = 30, e._goodDelta = 1e3 / 60, e.create = function(g) {
|
|
2331
|
-
var
|
|
2184
|
+
var d = {
|
|
2332
2185
|
engine: null,
|
|
2333
2186
|
element: null,
|
|
2334
2187
|
canvas: null,
|
|
@@ -2375,7 +2228,7 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
2375
2228
|
showInternalEdges: !1,
|
|
2376
2229
|
showMousePosition: !1
|
|
2377
2230
|
}
|
|
2378
|
-
}, y =
|
|
2231
|
+
}, y = r.extend(d, g);
|
|
2379
2232
|
return y.canvas && (y.canvas.width = y.options.width || y.canvas.width, y.canvas.height = y.options.height || y.canvas.height), y.mouse = g.mouse, y.engine = g.engine, y.canvas = y.canvas || m(y.options.width, y.options.height), y.context = y.canvas.getContext("2d"), y.textures = {}, y.bounds = y.bounds || {
|
|
2380
2233
|
min: {
|
|
2381
2234
|
x: 0,
|
|
@@ -2385,20 +2238,20 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
2385
2238
|
x: y.canvas.width,
|
|
2386
2239
|
y: y.canvas.height
|
|
2387
2240
|
}
|
|
2388
|
-
}, y.controller = e, y.options.showBroadphase = !1, y.options.pixelRatio !== 1 && e.setPixelRatio(y, y.options.pixelRatio),
|
|
2241
|
+
}, y.controller = e, y.options.showBroadphase = !1, y.options.pixelRatio !== 1 && e.setPixelRatio(y, y.options.pixelRatio), r.isElement(y.element) && y.element.appendChild(y.canvas), y;
|
|
2389
2242
|
}, e.run = function(g) {
|
|
2390
|
-
(function
|
|
2391
|
-
g.frameRequestId = t(
|
|
2243
|
+
(function d(y) {
|
|
2244
|
+
g.frameRequestId = t(d), s(g, y), e.world(g, y), g.context.setTransform(g.options.pixelRatio, 0, 0, g.options.pixelRatio, 0, 0), (g.options.showStats || g.options.showDebug) && e.stats(g, g.context, y), (g.options.showPerformance || g.options.showDebug) && e.performance(g, g.context, y), g.context.setTransform(1, 0, 0, 1, 0, 0);
|
|
2392
2245
|
})();
|
|
2393
2246
|
}, e.stop = function(g) {
|
|
2394
2247
|
i(g.frameRequestId);
|
|
2395
|
-
}, e.setPixelRatio = function(g,
|
|
2248
|
+
}, e.setPixelRatio = function(g, d) {
|
|
2396
2249
|
var y = g.options, v = g.canvas;
|
|
2397
|
-
|
|
2398
|
-
}, e.setSize = function(g,
|
|
2399
|
-
g.options.width =
|
|
2400
|
-
}, e.lookAt = function(g,
|
|
2401
|
-
v = typeof v < "u" ? v : !0,
|
|
2250
|
+
d === "auto" && (d = x(v)), y.pixelRatio = d, v.setAttribute("data-pixel-ratio", d), v.width = y.width * d, v.height = y.height * d, v.style.width = y.width + "px", v.style.height = y.height + "px";
|
|
2251
|
+
}, e.setSize = function(g, d, y) {
|
|
2252
|
+
g.options.width = d, g.options.height = y, g.bounds.max.x = g.bounds.min.x + d, g.bounds.max.y = g.bounds.min.y + y, g.options.pixelRatio !== 1 ? e.setPixelRatio(g, g.options.pixelRatio) : (g.canvas.width = d, g.canvas.height = y);
|
|
2253
|
+
}, e.lookAt = function(g, d, y, v) {
|
|
2254
|
+
v = typeof v < "u" ? v : !0, d = r.isArray(d) ? d : [d], y = y || {
|
|
2402
2255
|
x: 0,
|
|
2403
2256
|
y: 0
|
|
2404
2257
|
};
|
|
@@ -2411,73 +2264,73 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
2411
2264
|
x: -1 / 0,
|
|
2412
2265
|
y: -1 / 0
|
|
2413
2266
|
}
|
|
2414
|
-
}, S = 0; S <
|
|
2415
|
-
var C =
|
|
2267
|
+
}, S = 0; S < d.length; S += 1) {
|
|
2268
|
+
var C = d[S], M = C.bounds ? C.bounds.min : C.min || C.position || C, I = C.bounds ? C.bounds.max : C.max || C.position || C;
|
|
2416
2269
|
M && I && (M.x < w.min.x && (w.min.x = M.x), I.x > w.max.x && (w.max.x = I.x), M.y < w.min.y && (w.min.y = M.y), I.y > w.max.y && (w.max.y = I.y));
|
|
2417
2270
|
}
|
|
2418
|
-
var R = w.max.x - w.min.x + 2 * y.x, L = w.max.y - w.min.y + 2 * y.y,
|
|
2419
|
-
|
|
2271
|
+
var R = w.max.x - w.min.x + 2 * y.x, L = w.max.y - w.min.y + 2 * y.y, D = g.canvas.height, k = g.canvas.width / D, b = R / L, O = 1, W = 1;
|
|
2272
|
+
b > k ? W = b / k : O = k / b, g.options.hasBounds = !0, g.bounds.min.x = w.min.x, g.bounds.max.x = w.min.x + R * O, g.bounds.min.y = w.min.y, g.bounds.max.y = w.min.y + L * W, v && (g.bounds.min.x += R * 0.5 - R * O * 0.5, g.bounds.max.x += R * 0.5 - R * O * 0.5, g.bounds.min.y += L * 0.5 - L * W * 0.5, g.bounds.max.y += L * 0.5 - L * W * 0.5), g.bounds.min.x -= y.x, g.bounds.max.x -= y.x, g.bounds.min.y -= y.y, g.bounds.max.y -= y.y, g.mouse && (l.setScale(g.mouse, {
|
|
2420
2273
|
x: (g.bounds.max.x - g.bounds.min.x) / g.canvas.width,
|
|
2421
2274
|
y: (g.bounds.max.y - g.bounds.min.y) / g.canvas.height
|
|
2422
2275
|
}), l.setOffset(g.mouse, g.bounds.min));
|
|
2423
2276
|
}, e.startViewTransform = function(g) {
|
|
2424
|
-
var
|
|
2277
|
+
var d = g.bounds.max.x - g.bounds.min.x, y = g.bounds.max.y - g.bounds.min.y, v = d / g.options.width, w = y / g.options.height;
|
|
2425
2278
|
g.context.setTransform(g.options.pixelRatio / v, 0, 0, g.options.pixelRatio / w, 0, 0), g.context.translate(-g.bounds.min.x, -g.bounds.min.y);
|
|
2426
2279
|
}, e.endViewTransform = function(g) {
|
|
2427
2280
|
g.context.setTransform(g.options.pixelRatio, 0, 0, g.options.pixelRatio, 0, 0);
|
|
2428
|
-
}, e.world = function(g,
|
|
2429
|
-
var y =
|
|
2430
|
-
if (n.trigger(g, "beforeRender",
|
|
2431
|
-
for (
|
|
2432
|
-
var G = R[
|
|
2433
|
-
|
|
2281
|
+
}, e.world = function(g, d) {
|
|
2282
|
+
var y = r.now(), v = g.engine, w = v.world, S = g.canvas, C = g.context, M = g.options, I = g.timing, R = a.allBodies(w), L = a.allConstraints(w), D = M.wireframes ? M.wireframeBackground : M.background, k = [], b = [], O, W = { timestamp: v.timing.timestamp };
|
|
2283
|
+
if (n.trigger(g, "beforeRender", W), g.currentBackground !== D && T(g, D), C.globalCompositeOperation = "source-in", C.fillStyle = "transparent", C.fillRect(0, 0, S.width, S.height), C.globalCompositeOperation = "source-over", M.hasBounds) {
|
|
2284
|
+
for (O = 0; O < R.length; O++) {
|
|
2285
|
+
var G = R[O];
|
|
2286
|
+
u.overlaps(G.bounds, g.bounds) && k.push(G);
|
|
2434
2287
|
}
|
|
2435
|
-
for (
|
|
2436
|
-
var
|
|
2437
|
-
Q && (
|
|
2288
|
+
for (O = 0; O < L.length; O++) {
|
|
2289
|
+
var N = L[O], Q = N.bodyA, X = N.bodyB, F = N.pointA, H = N.pointB;
|
|
2290
|
+
Q && (F = h.add(Q.position, N.pointA)), X && (H = h.add(X.position, N.pointB)), !(!F || !H) && (u.contains(g.bounds, F) || u.contains(g.bounds, H)) && b.push(N);
|
|
2438
2291
|
}
|
|
2439
2292
|
e.startViewTransform(g), g.mouse && (l.setScale(g.mouse, {
|
|
2440
2293
|
x: (g.bounds.max.x - g.bounds.min.x) / g.options.width,
|
|
2441
2294
|
y: (g.bounds.max.y - g.bounds.min.y) / g.options.height
|
|
2442
2295
|
}), l.setOffset(g.mouse, g.bounds.min));
|
|
2443
2296
|
} else
|
|
2444
|
-
|
|
2445
|
-
!M.wireframes || v.enableSleeping && M.showSleeping ? e.bodies(g, k, C) : (M.showConvexHulls && e.bodyConvexHulls(g, k, C), e.bodyWireframes(g, k, C)), M.showBounds && e.bodyBounds(g, k, C), (M.showAxes || M.showAngleIndicator) && e.bodyAxes(g, k, C), M.showPositions && e.bodyPositions(g, k, C), M.showVelocity && e.bodyVelocity(g, k, C), M.showIds && e.bodyIds(g, k, C), M.showSeparations && e.separations(g, v.pairs.list, C), M.showCollisions && e.collisions(g, v.pairs.list, C), M.showVertexNumbers && e.vertexNumbers(g, k, C), M.showMousePosition && e.mousePosition(g, g.mouse, C), e.constraints(
|
|
2446
|
-
}, e.stats = function(g,
|
|
2447
|
-
for (var v = g.engine, w = v.world, S =
|
|
2297
|
+
b = L, k = R, g.options.pixelRatio !== 1 && g.context.setTransform(g.options.pixelRatio, 0, 0, g.options.pixelRatio, 0, 0);
|
|
2298
|
+
!M.wireframes || v.enableSleeping && M.showSleeping ? e.bodies(g, k, C) : (M.showConvexHulls && e.bodyConvexHulls(g, k, C), e.bodyWireframes(g, k, C)), M.showBounds && e.bodyBounds(g, k, C), (M.showAxes || M.showAngleIndicator) && e.bodyAxes(g, k, C), M.showPositions && e.bodyPositions(g, k, C), M.showVelocity && e.bodyVelocity(g, k, C), M.showIds && e.bodyIds(g, k, C), M.showSeparations && e.separations(g, v.pairs.list, C), M.showCollisions && e.collisions(g, v.pairs.list, C), M.showVertexNumbers && e.vertexNumbers(g, k, C), M.showMousePosition && e.mousePosition(g, g.mouse, C), e.constraints(b, C), M.hasBounds && e.endViewTransform(g), n.trigger(g, "afterRender", W), I.lastElapsed = r.now() - y;
|
|
2299
|
+
}, e.stats = function(g, d, y) {
|
|
2300
|
+
for (var v = g.engine, w = v.world, S = a.allBodies(w), C = 0, M = 55, I = 44, R = 0, L = 0, D = 0; D < S.length; D += 1) C += S[D].parts.length;
|
|
2448
2301
|
var k = {
|
|
2449
2302
|
Part: C,
|
|
2450
2303
|
Body: S.length,
|
|
2451
|
-
Cons:
|
|
2452
|
-
Comp:
|
|
2304
|
+
Cons: a.allConstraints(w).length,
|
|
2305
|
+
Comp: a.allComposites(w).length,
|
|
2453
2306
|
Pair: v.pairs.list.length
|
|
2454
2307
|
};
|
|
2455
|
-
|
|
2456
|
-
for (var
|
|
2457
|
-
var
|
|
2458
|
-
|
|
2459
|
-
}
|
|
2460
|
-
}, e.performance = function(g,
|
|
2461
|
-
var y = g.engine, v = g.timing, w = v.deltaHistory, S = v.elapsedHistory, C = v.timestampElapsedHistory, M = v.engineDeltaHistory, I = v.engineUpdatesHistory, R = v.engineElapsedHistory, L = y.timing.lastUpdatesPerFrame,
|
|
2462
|
-
|
|
2308
|
+
d.fillStyle = "#0e0f19", d.fillRect(R, L, M * 5.5, I), d.font = "12px Arial", d.textBaseline = "top", d.textAlign = "right";
|
|
2309
|
+
for (var b in k) {
|
|
2310
|
+
var O = k[b];
|
|
2311
|
+
d.fillStyle = "#aaa", d.fillText(b, R + M, L + 8), d.fillStyle = "#eee", d.fillText(O, R + M, L + 26), R += M;
|
|
2312
|
+
}
|
|
2313
|
+
}, e.performance = function(g, d) {
|
|
2314
|
+
var y = g.engine, v = g.timing, w = v.deltaHistory, S = v.elapsedHistory, C = v.timestampElapsedHistory, M = v.engineDeltaHistory, I = v.engineUpdatesHistory, R = v.engineElapsedHistory, L = y.timing.lastUpdatesPerFrame, D = y.timing.lastDelta, k = f(w), b = f(S), O = f(M), W = f(I), G = f(R), N = f(C) / k || 0, Q = Math.round(k / D), X = 1e3 / k || 0, F = 4, H = 12, V = 60, J = 34, Y = 10, K = 69;
|
|
2315
|
+
d.fillStyle = "#0e0f19", d.fillRect(0, 50, H * 5 + V * 6 + 22, J), e.status(d, Y, K, V, F, w.length, Math.round(X) + " fps", X / e._goodFps, function(z) {
|
|
2463
2316
|
return w[z] / k - 1;
|
|
2464
|
-
}), e.status(
|
|
2465
|
-
return M[z] /
|
|
2466
|
-
}), e.status(
|
|
2467
|
-
return I[z] /
|
|
2468
|
-
}), e.status(
|
|
2317
|
+
}), e.status(d, Y + H + V, K, V, F, M.length, D.toFixed(2) + " dt", e._goodDelta / D, function(z) {
|
|
2318
|
+
return M[z] / O - 1;
|
|
2319
|
+
}), e.status(d, Y + (H + V) * 2, K, V, F, I.length, L + " upf", Math.pow(r.clamp(W / Q || 1, 0, 1), 4), function(z) {
|
|
2320
|
+
return I[z] / W - 1;
|
|
2321
|
+
}), e.status(d, Y + (H + V) * 3, K, V, F, R.length, G.toFixed(2) + " ut", 1 - L * G / e._goodFps, function(z) {
|
|
2469
2322
|
return R[z] / G - 1;
|
|
2470
|
-
}), e.status(
|
|
2471
|
-
return S[z] /
|
|
2472
|
-
}), e.status(
|
|
2473
|
-
return (C[z] / w[z] /
|
|
2323
|
+
}), e.status(d, Y + (H + V) * 4, K, V, F, S.length, b.toFixed(2) + " rt", 1 - b / e._goodFps, function(z) {
|
|
2324
|
+
return S[z] / b - 1;
|
|
2325
|
+
}), e.status(d, Y + (H + V) * 5, K, V, F, C.length, N.toFixed(2) + " x", N * N * N, function(z) {
|
|
2326
|
+
return (C[z] / w[z] / N || 0) - 1;
|
|
2474
2327
|
});
|
|
2475
|
-
}, e.status = function(g,
|
|
2476
|
-
g.strokeStyle = "#888", g.fillStyle = "#444", g.lineWidth = 1, g.fillRect(
|
|
2477
|
-
for (var R = 0; R < v; R += 1) g.lineTo(
|
|
2478
|
-
g.stroke(), g.fillStyle = "hsl(" +
|
|
2479
|
-
}, e.constraints = function(g,
|
|
2480
|
-
for (var y =
|
|
2328
|
+
}, e.status = function(g, d, y, v, w, S, C, M, I) {
|
|
2329
|
+
g.strokeStyle = "#888", g.fillStyle = "#444", g.lineWidth = 1, g.fillRect(d, y + 7, v, 1), g.beginPath(), g.moveTo(d, y + 7 - w * r.clamp(0.4 * I(0), -2, 2));
|
|
2330
|
+
for (var R = 0; R < v; R += 1) g.lineTo(d + R, y + 7 - (R < S ? w * r.clamp(0.4 * I(R), -2, 2) : 0));
|
|
2331
|
+
g.stroke(), g.fillStyle = "hsl(" + r.clamp(25 + 95 * M, 0, 120) + ",100%,60%)", g.fillRect(d, y - 7, 4, 4), g.font = "12px Arial", g.textBaseline = "middle", g.textAlign = "right", g.fillStyle = "#eee", g.fillText(C, d + v, y - 5);
|
|
2332
|
+
}, e.constraints = function(g, d) {
|
|
2333
|
+
for (var y = d, v = 0; v < g.length; v++) {
|
|
2481
2334
|
var w = g[v];
|
|
2482
2335
|
if (!(!w.render.visible || !w.pointA || !w.pointB)) {
|
|
2483
2336
|
var S = w.bodyA, C = w.bodyB, M, I;
|
|
@@ -2485,24 +2338,24 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
2485
2338
|
y.beginPath(), y.arc(M.x, M.y, 3, 0, 2 * Math.PI), y.closePath();
|
|
2486
2339
|
else {
|
|
2487
2340
|
if (C ? I = h.add(C.position, w.pointB) : I = w.pointB, y.beginPath(), y.moveTo(M.x, M.y), w.render.type === "spring")
|
|
2488
|
-
for (var R = h.sub(I, M), L = h.perp(h.normalise(R)),
|
|
2489
|
-
k =
|
|
2341
|
+
for (var R = h.sub(I, M), L = h.perp(h.normalise(R)), D = Math.ceil(r.clamp(w.length / 5, 12, 20)), k, b = 1; b < D; b += 1)
|
|
2342
|
+
k = b % 2 === 0 ? 1 : -1, y.lineTo(M.x + R.x * (b / D) + L.x * k * 4, M.y + R.y * (b / D) + L.y * k * 4);
|
|
2490
2343
|
y.lineTo(I.x, I.y);
|
|
2491
2344
|
}
|
|
2492
2345
|
w.render.lineWidth && (y.lineWidth = w.render.lineWidth, y.strokeStyle = w.render.strokeStyle, y.stroke()), w.render.anchors && (y.fillStyle = w.render.strokeStyle, y.beginPath(), y.arc(M.x, M.y, 3, 0, 2 * Math.PI), y.arc(I.x, I.y, 3, 0, 2 * Math.PI), y.closePath(), y.fill());
|
|
2493
2346
|
}
|
|
2494
2347
|
}
|
|
2495
|
-
}, e.bodies = function(g,
|
|
2348
|
+
}, e.bodies = function(g, d, y) {
|
|
2496
2349
|
var v = y;
|
|
2497
2350
|
g.engine;
|
|
2498
2351
|
var w = g.options, S = w.showInternalEdges || !w.wireframes, C, M, I, R;
|
|
2499
|
-
for (I = 0; I <
|
|
2500
|
-
if (C =
|
|
2352
|
+
for (I = 0; I < d.length; I++)
|
|
2353
|
+
if (C = d[I], !!C.render.visible) {
|
|
2501
2354
|
for (R = C.parts.length > 1 ? 1 : 0; R < C.parts.length; R++)
|
|
2502
2355
|
if (M = C.parts[R], !!M.render.visible) {
|
|
2503
2356
|
if (w.showSleeping && C.isSleeping ? v.globalAlpha = 0.5 * M.render.opacity : M.render.opacity !== 1 && (v.globalAlpha = M.render.opacity), M.render.sprite && M.render.sprite.texture && !w.wireframes) {
|
|
2504
|
-
var L = M.render.sprite,
|
|
2505
|
-
v.translate(M.position.x, M.position.y), v.rotate(M.angle), v.drawImage(
|
|
2357
|
+
var L = M.render.sprite, D = P(g, L.texture);
|
|
2358
|
+
v.translate(M.position.x, M.position.y), v.rotate(M.angle), v.drawImage(D, D.width * -L.xOffset * L.xScale, D.height * -L.yOffset * L.yScale, D.width * L.xScale, D.height * L.yScale), v.rotate(-M.angle), v.translate(-M.position.x, -M.position.y);
|
|
2506
2359
|
} else {
|
|
2507
2360
|
if (M.circleRadius)
|
|
2508
2361
|
v.beginPath(), v.arc(M.position.x, M.position.y, M.circleRadius, 0, 2 * Math.PI);
|
|
@@ -2517,174 +2370,174 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
2517
2370
|
v.globalAlpha = 1;
|
|
2518
2371
|
}
|
|
2519
2372
|
}
|
|
2520
|
-
}, e.bodyWireframes = function(g,
|
|
2373
|
+
}, e.bodyWireframes = function(g, d, y) {
|
|
2521
2374
|
var v = y, w = g.options.showInternalEdges, S, C, M, I, R;
|
|
2522
|
-
for (v.beginPath(), M = 0; M <
|
|
2523
|
-
if (S =
|
|
2375
|
+
for (v.beginPath(), M = 0; M < d.length; M++)
|
|
2376
|
+
if (S = d[M], !!S.render.visible)
|
|
2524
2377
|
for (R = S.parts.length > 1 ? 1 : 0; R < S.parts.length; R++) {
|
|
2525
2378
|
for (C = S.parts[R], v.moveTo(C.vertices[0].x, C.vertices[0].y), I = 1; I < C.vertices.length; I++)
|
|
2526
2379
|
!C.vertices[I - 1].isInternal || w ? v.lineTo(C.vertices[I].x, C.vertices[I].y) : v.moveTo(C.vertices[I].x, C.vertices[I].y), C.vertices[I].isInternal && !w && v.moveTo(C.vertices[(I + 1) % C.vertices.length].x, C.vertices[(I + 1) % C.vertices.length].y);
|
|
2527
2380
|
v.lineTo(C.vertices[0].x, C.vertices[0].y);
|
|
2528
2381
|
}
|
|
2529
2382
|
v.lineWidth = 1, v.strokeStyle = g.options.wireframeStrokeStyle, v.stroke();
|
|
2530
|
-
}, e.bodyConvexHulls = function(g,
|
|
2383
|
+
}, e.bodyConvexHulls = function(g, d, y) {
|
|
2531
2384
|
var v = y, w, S, C;
|
|
2532
|
-
for (v.beginPath(), S = 0; S <
|
|
2533
|
-
if (w =
|
|
2385
|
+
for (v.beginPath(), S = 0; S < d.length; S++)
|
|
2386
|
+
if (w = d[S], !(!w.render.visible || w.parts.length === 1)) {
|
|
2534
2387
|
for (v.moveTo(w.vertices[0].x, w.vertices[0].y), C = 1; C < w.vertices.length; C++) v.lineTo(w.vertices[C].x, w.vertices[C].y);
|
|
2535
2388
|
v.lineTo(w.vertices[0].x, w.vertices[0].y);
|
|
2536
2389
|
}
|
|
2537
2390
|
v.lineWidth = 1, v.strokeStyle = "rgba(255,255,255,0.2)", v.stroke();
|
|
2538
|
-
}, e.vertexNumbers = function(g,
|
|
2391
|
+
}, e.vertexNumbers = function(g, d, y) {
|
|
2539
2392
|
var v = y, w, S, C;
|
|
2540
|
-
for (w = 0; w <
|
|
2541
|
-
var M =
|
|
2393
|
+
for (w = 0; w < d.length; w++) {
|
|
2394
|
+
var M = d[w].parts;
|
|
2542
2395
|
for (C = M.length > 1 ? 1 : 0; C < M.length; C++) {
|
|
2543
2396
|
var I = M[C];
|
|
2544
2397
|
for (S = 0; S < I.vertices.length; S++)
|
|
2545
2398
|
v.fillStyle = "rgba(255,255,255,0.2)", v.fillText(w + "_" + S, I.position.x + (I.vertices[S].x - I.position.x) * 0.8, I.position.y + (I.vertices[S].y - I.position.y) * 0.8);
|
|
2546
2399
|
}
|
|
2547
2400
|
}
|
|
2548
|
-
}, e.mousePosition = function(g,
|
|
2401
|
+
}, e.mousePosition = function(g, d, y) {
|
|
2549
2402
|
var v = y;
|
|
2550
|
-
v.fillStyle = "rgba(255,255,255,0.8)", v.fillText(
|
|
2551
|
-
}, e.bodyBounds = function(g,
|
|
2403
|
+
v.fillStyle = "rgba(255,255,255,0.8)", v.fillText(d.position.x + " " + d.position.y, d.position.x + 5, d.position.y - 5);
|
|
2404
|
+
}, e.bodyBounds = function(g, d, y) {
|
|
2552
2405
|
var v = y;
|
|
2553
2406
|
g.engine;
|
|
2554
2407
|
var w = g.options;
|
|
2555
2408
|
v.beginPath();
|
|
2556
|
-
for (var S = 0; S <
|
|
2557
|
-
for (var C =
|
|
2409
|
+
for (var S = 0; S < d.length; S++) if (d[S].render.visible)
|
|
2410
|
+
for (var C = d[S].parts, M = C.length > 1 ? 1 : 0; M < C.length; M++) {
|
|
2558
2411
|
var I = C[M];
|
|
2559
2412
|
v.rect(I.bounds.min.x, I.bounds.min.y, I.bounds.max.x - I.bounds.min.x, I.bounds.max.y - I.bounds.min.y);
|
|
2560
2413
|
}
|
|
2561
2414
|
w.wireframes ? v.strokeStyle = "rgba(255,255,255,0.08)" : v.strokeStyle = "rgba(0,0,0,0.1)", v.lineWidth = 1, v.stroke();
|
|
2562
|
-
}, e.bodyAxes = function(g,
|
|
2415
|
+
}, e.bodyAxes = function(g, d, y) {
|
|
2563
2416
|
var v = y;
|
|
2564
2417
|
g.engine;
|
|
2565
2418
|
var w = g.options, S, C, M, I;
|
|
2566
|
-
for (v.beginPath(), C = 0; C <
|
|
2567
|
-
var R =
|
|
2419
|
+
for (v.beginPath(), C = 0; C < d.length; C++) {
|
|
2420
|
+
var R = d[C], L = R.parts;
|
|
2568
2421
|
if (R.render.visible)
|
|
2569
2422
|
if (w.showAxes) for (M = L.length > 1 ? 1 : 0; M < L.length; M++)
|
|
2570
2423
|
for (S = L[M], I = 0; I < S.axes.length; I++) {
|
|
2571
|
-
var
|
|
2572
|
-
v.moveTo(S.position.x, S.position.y), v.lineTo(S.position.x +
|
|
2424
|
+
var D = S.axes[I];
|
|
2425
|
+
v.moveTo(S.position.x, S.position.y), v.lineTo(S.position.x + D.x * 20, S.position.y + D.y * 20);
|
|
2573
2426
|
}
|
|
2574
2427
|
else for (M = L.length > 1 ? 1 : 0; M < L.length; M++)
|
|
2575
2428
|
for (S = L[M], I = 0; I < S.axes.length; I++)
|
|
2576
2429
|
v.moveTo(S.position.x, S.position.y), v.lineTo((S.vertices[0].x + S.vertices[S.vertices.length - 1].x) / 2, (S.vertices[0].y + S.vertices[S.vertices.length - 1].y) / 2);
|
|
2577
2430
|
}
|
|
2578
2431
|
w.wireframes ? (v.strokeStyle = "indianred", v.lineWidth = 1) : (v.strokeStyle = "rgba(255, 255, 255, 0.4)", v.globalCompositeOperation = "overlay", v.lineWidth = 2), v.stroke(), v.globalCompositeOperation = "source-over";
|
|
2579
|
-
}, e.bodyPositions = function(g,
|
|
2432
|
+
}, e.bodyPositions = function(g, d, y) {
|
|
2580
2433
|
var v = y;
|
|
2581
2434
|
g.engine;
|
|
2582
2435
|
var w = g.options, S, C, M, I;
|
|
2583
|
-
for (v.beginPath(), M = 0; M <
|
|
2584
|
-
if (S =
|
|
2436
|
+
for (v.beginPath(), M = 0; M < d.length; M++)
|
|
2437
|
+
if (S = d[M], !!S.render.visible)
|
|
2585
2438
|
for (I = 0; I < S.parts.length; I++)
|
|
2586
2439
|
C = S.parts[I], v.arc(C.position.x, C.position.y, 3, 0, 2 * Math.PI, !1), v.closePath();
|
|
2587
|
-
for (w.wireframes ? v.fillStyle = "indianred" : v.fillStyle = "rgba(0,0,0,0.5)", v.fill(), v.beginPath(), M = 0; M <
|
|
2588
|
-
S =
|
|
2440
|
+
for (w.wireframes ? v.fillStyle = "indianred" : v.fillStyle = "rgba(0,0,0,0.5)", v.fill(), v.beginPath(), M = 0; M < d.length; M++)
|
|
2441
|
+
S = d[M], S.render.visible && (v.arc(S.positionPrev.x, S.positionPrev.y, 2, 0, 2 * Math.PI, !1), v.closePath());
|
|
2589
2442
|
v.fillStyle = "rgba(255,165,0,0.8)", v.fill();
|
|
2590
|
-
}, e.bodyVelocity = function(g,
|
|
2443
|
+
}, e.bodyVelocity = function(g, d, y) {
|
|
2591
2444
|
var v = y;
|
|
2592
2445
|
v.beginPath();
|
|
2593
|
-
for (var w = 0; w <
|
|
2594
|
-
var S =
|
|
2446
|
+
for (var w = 0; w < d.length; w++) {
|
|
2447
|
+
var S = d[w];
|
|
2595
2448
|
if (S.render.visible) {
|
|
2596
2449
|
var C = o.getVelocity(S);
|
|
2597
2450
|
v.moveTo(S.position.x, S.position.y), v.lineTo(S.position.x + C.x, S.position.y + C.y);
|
|
2598
2451
|
}
|
|
2599
2452
|
}
|
|
2600
2453
|
v.lineWidth = 3, v.strokeStyle = "cornflowerblue", v.stroke();
|
|
2601
|
-
}, e.bodyIds = function(g,
|
|
2454
|
+
}, e.bodyIds = function(g, d, y) {
|
|
2602
2455
|
var v = y, w, S;
|
|
2603
|
-
for (w = 0; w <
|
|
2604
|
-
if (
|
|
2605
|
-
var C =
|
|
2456
|
+
for (w = 0; w < d.length; w++)
|
|
2457
|
+
if (d[w].render.visible) {
|
|
2458
|
+
var C = d[w].parts;
|
|
2606
2459
|
for (S = C.length > 1 ? 1 : 0; S < C.length; S++) {
|
|
2607
2460
|
var M = C[S];
|
|
2608
2461
|
v.font = "12px Arial", v.fillStyle = "rgba(255,255,255,0.5)", v.fillText(M.id, M.position.x + 10, M.position.y - 10);
|
|
2609
2462
|
}
|
|
2610
2463
|
}
|
|
2611
|
-
}, e.collisions = function(g,
|
|
2464
|
+
}, e.collisions = function(g, d, y) {
|
|
2612
2465
|
var v = y, w = g.options, S, C, M, I;
|
|
2613
|
-
for (v.beginPath(), M = 0; M <
|
|
2614
|
-
if (S =
|
|
2466
|
+
for (v.beginPath(), M = 0; M < d.length; M++)
|
|
2467
|
+
if (S = d[M], !!S.isActive)
|
|
2615
2468
|
for (C = S.collision, I = 0; I < S.contactCount; I++) {
|
|
2616
2469
|
var R = S.contacts[I].vertex;
|
|
2617
2470
|
v.rect(R.x - 1.5, R.y - 1.5, 3.5, 3.5);
|
|
2618
2471
|
}
|
|
2619
|
-
for (w.wireframes ? v.fillStyle = "rgba(255,255,255,0.7)" : v.fillStyle = "orange", v.fill(), v.beginPath(), M = 0; M <
|
|
2620
|
-
if (S =
|
|
2621
|
-
var L = S.contacts[0].vertex.x,
|
|
2622
|
-
S.contactCount === 2 && (L = (S.contacts[0].vertex.x + S.contacts[1].vertex.x) / 2,
|
|
2472
|
+
for (w.wireframes ? v.fillStyle = "rgba(255,255,255,0.7)" : v.fillStyle = "orange", v.fill(), v.beginPath(), M = 0; M < d.length; M++)
|
|
2473
|
+
if (S = d[M], !!S.isActive && (C = S.collision, S.contactCount > 0)) {
|
|
2474
|
+
var L = S.contacts[0].vertex.x, D = S.contacts[0].vertex.y;
|
|
2475
|
+
S.contactCount === 2 && (L = (S.contacts[0].vertex.x + S.contacts[1].vertex.x) / 2, D = (S.contacts[0].vertex.y + S.contacts[1].vertex.y) / 2), C.bodyB === C.supports[0].body || C.bodyA.isStatic === !0 ? v.moveTo(L - C.normal.x * 8, D - C.normal.y * 8) : v.moveTo(L + C.normal.x * 8, D + C.normal.y * 8), v.lineTo(L, D);
|
|
2623
2476
|
}
|
|
2624
2477
|
w.wireframes ? v.strokeStyle = "rgba(255,165,0,0.7)" : v.strokeStyle = "orange", v.lineWidth = 1, v.stroke();
|
|
2625
|
-
}, e.separations = function(g,
|
|
2478
|
+
}, e.separations = function(g, d, y) {
|
|
2626
2479
|
var v = y, w = g.options, S, C, M, I, R;
|
|
2627
|
-
for (v.beginPath(), R = 0; R <
|
|
2628
|
-
if (S =
|
|
2480
|
+
for (v.beginPath(), R = 0; R < d.length; R++)
|
|
2481
|
+
if (S = d[R], !!S.isActive) {
|
|
2629
2482
|
C = S.collision, M = C.bodyA, I = C.bodyB;
|
|
2630
2483
|
var L = 1;
|
|
2631
2484
|
!I.isStatic && !M.isStatic && (L = 0.5), I.isStatic && (L = 0), v.moveTo(I.position.x, I.position.y), v.lineTo(I.position.x - C.penetration.x * L, I.position.y - C.penetration.y * L), L = 1, !I.isStatic && !M.isStatic && (L = 0.5), M.isStatic && (L = 0), v.moveTo(M.position.x, M.position.y), v.lineTo(M.position.x + C.penetration.x * L, M.position.y + C.penetration.y * L);
|
|
2632
2485
|
}
|
|
2633
2486
|
w.wireframes ? v.strokeStyle = "rgba(255,165,0,0.5)" : v.strokeStyle = "orange", v.stroke();
|
|
2634
|
-
}, e.inspector = function(g,
|
|
2487
|
+
}, e.inspector = function(g, d) {
|
|
2635
2488
|
g.engine;
|
|
2636
2489
|
var y = g.selected, v = g.render, w = v.options, S;
|
|
2637
2490
|
if (w.hasBounds) {
|
|
2638
2491
|
var C = v.bounds.max.x - v.bounds.min.x, M = v.bounds.max.y - v.bounds.min.y, I = C / v.options.width, R = M / v.options.height;
|
|
2639
|
-
|
|
2492
|
+
d.scale(1 / I, 1 / R), d.translate(-v.bounds.min.x, -v.bounds.min.y);
|
|
2640
2493
|
}
|
|
2641
2494
|
for (var L = 0; L < y.length; L++) {
|
|
2642
|
-
var
|
|
2643
|
-
switch (
|
|
2495
|
+
var D = y[L].data;
|
|
2496
|
+
switch (d.translate(0.5, 0.5), d.lineWidth = 1, d.strokeStyle = "rgba(255,165,0,0.9)", d.setLineDash([1, 2]), D.type) {
|
|
2644
2497
|
case "body":
|
|
2645
|
-
S =
|
|
2498
|
+
S = D.bounds, d.beginPath(), d.rect(Math.floor(S.min.x - 3), Math.floor(S.min.y - 3), Math.floor(S.max.x - S.min.x + 6), Math.floor(S.max.y - S.min.y + 6)), d.closePath(), d.stroke();
|
|
2646
2499
|
break;
|
|
2647
2500
|
case "constraint":
|
|
2648
|
-
var k =
|
|
2649
|
-
|
|
2501
|
+
var k = D.pointA;
|
|
2502
|
+
D.bodyA && (k = D.pointB), d.beginPath(), d.arc(k.x, k.y, 10, 0, 2 * Math.PI), d.closePath(), d.stroke();
|
|
2650
2503
|
break;
|
|
2651
2504
|
}
|
|
2652
|
-
|
|
2505
|
+
d.setLineDash([]), d.translate(-0.5, -0.5);
|
|
2653
2506
|
}
|
|
2654
|
-
g.selectStart !== null && (
|
|
2507
|
+
g.selectStart !== null && (d.translate(0.5, 0.5), d.lineWidth = 1, d.strokeStyle = "rgba(255,165,0,0.6)", d.fillStyle = "rgba(255,165,0,0.1)", S = g.selectBounds, d.beginPath(), d.rect(Math.floor(S.min.x), Math.floor(S.min.y), Math.floor(S.max.x - S.min.x), Math.floor(S.max.y - S.min.y)), d.closePath(), d.stroke(), d.fill(), d.translate(-0.5, -0.5)), w.hasBounds && d.setTransform(1, 0, 0, 1, 0, 0);
|
|
2655
2508
|
};
|
|
2656
|
-
var s = function(g,
|
|
2509
|
+
var s = function(g, d) {
|
|
2657
2510
|
var y = g.engine, v = g.timing, w = v.historySize, S = y.timing.timestamp;
|
|
2658
|
-
v.delta =
|
|
2659
|
-
},
|
|
2660
|
-
for (var
|
|
2661
|
-
return
|
|
2662
|
-
}, m = function(g,
|
|
2511
|
+
v.delta = d - v.lastTime || e._goodDelta, v.lastTime = d, v.timestampElapsed = S - v.lastTimestamp || 0, v.lastTimestamp = S, v.deltaHistory.unshift(v.delta), v.deltaHistory.length = Math.min(v.deltaHistory.length, w), v.engineDeltaHistory.unshift(y.timing.lastDelta), v.engineDeltaHistory.length = Math.min(v.engineDeltaHistory.length, w), v.timestampElapsedHistory.unshift(v.timestampElapsed), v.timestampElapsedHistory.length = Math.min(v.timestampElapsedHistory.length, w), v.engineUpdatesHistory.unshift(y.timing.lastUpdatesPerFrame), v.engineUpdatesHistory.length = Math.min(v.engineUpdatesHistory.length, w), v.engineElapsedHistory.unshift(y.timing.lastElapsed), v.engineElapsedHistory.length = Math.min(v.engineElapsedHistory.length, w), v.elapsedHistory.unshift(v.lastElapsed), v.elapsedHistory.length = Math.min(v.elapsedHistory.length, w);
|
|
2512
|
+
}, f = function(g) {
|
|
2513
|
+
for (var d = 0, y = 0; y < g.length; y += 1) d += g[y];
|
|
2514
|
+
return d / g.length || 0;
|
|
2515
|
+
}, m = function(g, d) {
|
|
2663
2516
|
var y = document.createElement("canvas");
|
|
2664
|
-
return y.width = g, y.height =
|
|
2517
|
+
return y.width = g, y.height = d, y.oncontextmenu = function() {
|
|
2665
2518
|
return !1;
|
|
2666
2519
|
}, y.onselectstart = function() {
|
|
2667
2520
|
return !1;
|
|
2668
2521
|
}, y;
|
|
2669
2522
|
}, x = function(g) {
|
|
2670
|
-
var
|
|
2671
|
-
return (window.devicePixelRatio || 1) / (
|
|
2672
|
-
}, P = function(g,
|
|
2673
|
-
var y = g.textures[
|
|
2674
|
-
return y || (y = g.textures[
|
|
2675
|
-
},
|
|
2676
|
-
var y =
|
|
2677
|
-
/(jpg|gif|png)$/.test(
|
|
2523
|
+
var d = g.getContext("2d");
|
|
2524
|
+
return (window.devicePixelRatio || 1) / (d.webkitBackingStorePixelRatio || d.mozBackingStorePixelRatio || d.msBackingStorePixelRatio || d.oBackingStorePixelRatio || d.backingStorePixelRatio || 1);
|
|
2525
|
+
}, P = function(g, d) {
|
|
2526
|
+
var y = g.textures[d];
|
|
2527
|
+
return y || (y = g.textures[d] = new Image(), y.src = d, y);
|
|
2528
|
+
}, T = function(g, d) {
|
|
2529
|
+
var y = d;
|
|
2530
|
+
/(jpg|gif|png)$/.test(d) && (y = "url(" + d + ")"), g.canvas.style.background = y, g.canvas.style.backgroundSize = "contain", g.currentBackground = d;
|
|
2678
2531
|
};
|
|
2679
2532
|
})();
|
|
2680
2533
|
}),
|
|
2681
|
-
(function(
|
|
2534
|
+
(function(A, E, c) {
|
|
2682
2535
|
var e = {};
|
|
2683
|
-
|
|
2684
|
-
var o =
|
|
2536
|
+
A.exports = e;
|
|
2537
|
+
var o = c(5), r = c(17), a = c(0);
|
|
2685
2538
|
(function() {
|
|
2686
2539
|
e._maxFrameDelta = 1e3 / 15, e._frameDeltaFallback = 1e3 / 60, e._timeBufferMargin = 1.5, e._elapsedNextEstimate = 1, e._smoothingLowerBound = 0.1, e._smoothingUpperBound = 0.9, e.create = function(n) {
|
|
2687
|
-
var h =
|
|
2540
|
+
var h = a.extend({
|
|
2688
2541
|
delta: 16.666666666666668,
|
|
2689
2542
|
frameDelta: null,
|
|
2690
2543
|
frameDeltaSmoothing: !0,
|
|
@@ -2705,24 +2558,24 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
2705
2558
|
n.frameRequestId = e._onNextFrame(n, l), t && n.enabled && e.tick(n, h, t);
|
|
2706
2559
|
})(), n;
|
|
2707
2560
|
}, e.tick = function(n, h, l) {
|
|
2708
|
-
var t =
|
|
2709
|
-
if ((!
|
|
2710
|
-
n.frameDeltaHistory.push(
|
|
2561
|
+
var t = a.now(), i = n.delta, s = 0, f = l - n.timeLastTick;
|
|
2562
|
+
if ((!f || !n.timeLastTick || f > Math.max(e._maxFrameDelta, n.maxFrameTime)) && (f = n.frameDelta || e._frameDeltaFallback), n.frameDeltaSmoothing) {
|
|
2563
|
+
n.frameDeltaHistory.push(f), n.frameDeltaHistory = n.frameDeltaHistory.slice(-n.frameDeltaHistorySize);
|
|
2711
2564
|
var m = n.frameDeltaHistory.slice(0).sort();
|
|
2712
|
-
|
|
2565
|
+
f = u(n.frameDeltaHistory.slice(m.length * e._smoothingLowerBound, m.length * e._smoothingUpperBound)) || f;
|
|
2713
2566
|
}
|
|
2714
|
-
n.frameDeltaSnapping && (
|
|
2567
|
+
n.frameDeltaSnapping && (f = 1e3 / Math.round(1e3 / f)), n.frameDelta = f, n.timeLastTick = l, n.timeBuffer += n.frameDelta, n.timeBuffer = a.clamp(n.timeBuffer, 0, n.frameDelta + i * e._timeBufferMargin), n.lastUpdatesDeferred = 0;
|
|
2715
2568
|
var x = n.maxUpdates || Math.ceil(n.maxFrameTime / i), P = { timestamp: h.timing.timestamp };
|
|
2716
2569
|
o.trigger(n, "beforeTick", P), o.trigger(n, "tick", P);
|
|
2717
|
-
for (var
|
|
2718
|
-
o.trigger(n, "beforeUpdate", P),
|
|
2719
|
-
var g =
|
|
2570
|
+
for (var T = a.now(); i > 0 && n.timeBuffer >= i * e._timeBufferMargin; ) {
|
|
2571
|
+
o.trigger(n, "beforeUpdate", P), r.update(h, i), o.trigger(n, "afterUpdate", P), n.timeBuffer -= i, s += 1;
|
|
2572
|
+
var g = a.now() - t, d = a.now() - T, y = g + e._elapsedNextEstimate * d / s;
|
|
2720
2573
|
if (s >= x || y > n.maxFrameTime) {
|
|
2721
2574
|
n.lastUpdatesDeferred = Math.round(Math.max(0, n.timeBuffer / i - e._timeBufferMargin));
|
|
2722
2575
|
break;
|
|
2723
2576
|
}
|
|
2724
2577
|
}
|
|
2725
|
-
h.timing.lastUpdatesPerFrame = s, o.trigger(n, "afterTick", P), n.frameDeltaHistory.length >= 100 && (n.lastUpdatesDeferred && Math.round(n.frameDelta / i) > x ?
|
|
2578
|
+
h.timing.lastUpdatesPerFrame = s, o.trigger(n, "afterTick", P), n.frameDeltaHistory.length >= 100 && (n.lastUpdatesDeferred && Math.round(n.frameDelta / i) > x ? a.warnOnce("Matter.Runner: runner reached runner.maxUpdates, see docs.") : n.lastUpdatesDeferred && a.warnOnce("Matter.Runner: runner reached runner.maxFrameTime, see docs."), typeof n.isFixed < "u" && a.warnOnce("Matter.Runner: runner.isFixed is now redundant, see docs."), (n.deltaMin || n.deltaMax) && a.warnOnce("Matter.Runner: runner.deltaMin and runner.deltaMax were removed, see docs."), n.fps !== 0 && a.warnOnce("Matter.Runner: runner.fps was replaced by runner.delta, see docs."));
|
|
2726
2579
|
}, e.stop = function(n) {
|
|
2727
2580
|
e._cancelNextFrame(n);
|
|
2728
2581
|
}, e._onNextFrame = function(n, h) {
|
|
@@ -2733,40 +2586,40 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
2733
2586
|
if (typeof window < "u" && window.cancelAnimationFrame) window.cancelAnimationFrame(n.frameRequestId);
|
|
2734
2587
|
else throw new Error("Matter.Runner: missing required global window.cancelAnimationFrame.");
|
|
2735
2588
|
};
|
|
2736
|
-
var
|
|
2589
|
+
var u = function(n) {
|
|
2737
2590
|
for (var h = 0, l = n.length, t = 0; t < l; t += 1) h += n[t];
|
|
2738
2591
|
return h / l || 0;
|
|
2739
2592
|
};
|
|
2740
2593
|
})();
|
|
2741
2594
|
}),
|
|
2742
|
-
(function(
|
|
2595
|
+
(function(A, E, c) {
|
|
2743
2596
|
var e = {};
|
|
2744
|
-
|
|
2745
|
-
var o =
|
|
2597
|
+
A.exports = e;
|
|
2598
|
+
var o = c(8), r = c(0).deprecated;
|
|
2746
2599
|
(function() {
|
|
2747
|
-
e.collides = function(
|
|
2748
|
-
return o.collides(
|
|
2749
|
-
},
|
|
2600
|
+
e.collides = function(a, u) {
|
|
2601
|
+
return o.collides(a, u);
|
|
2602
|
+
}, r(e, "collides", "SAT.collides ➤ replaced by Collision.collides");
|
|
2750
2603
|
})();
|
|
2751
2604
|
}),
|
|
2752
|
-
(function(
|
|
2605
|
+
(function(A, E, c) {
|
|
2753
2606
|
var e = {};
|
|
2754
|
-
|
|
2755
|
-
var o =
|
|
2607
|
+
A.exports = e, c(1);
|
|
2608
|
+
var o = c(0);
|
|
2756
2609
|
(function() {
|
|
2757
|
-
e.pathToVertices = function(
|
|
2610
|
+
e.pathToVertices = function(r, a) {
|
|
2758
2611
|
typeof window < "u" && !("SVGPathSeg" in window) && o.warn("Svg.pathToVertices: SVGPathSeg not defined, a polyfill is required.");
|
|
2759
|
-
var
|
|
2760
|
-
|
|
2612
|
+
var u, n, h, l, t, i, s, f, m, x, P = [], T, g, d = 0, y = 0, v = 0;
|
|
2613
|
+
a = a || 15;
|
|
2761
2614
|
var w = function(C, M, I) {
|
|
2762
2615
|
var R = I % 2 === 1 && I > 1;
|
|
2763
2616
|
if (!m || C != m.x || M != m.y) {
|
|
2764
|
-
m && R ? (
|
|
2617
|
+
m && R ? (T = m.x, g = m.y) : (T = 0, g = 0);
|
|
2765
2618
|
var L = {
|
|
2766
|
-
x:
|
|
2619
|
+
x: T + C,
|
|
2767
2620
|
y: g + M
|
|
2768
2621
|
};
|
|
2769
|
-
(R || !m) && (m = L), P.push(L), y =
|
|
2622
|
+
(R || !m) && (m = L), P.push(L), y = T + C, v = g + M;
|
|
2770
2623
|
}
|
|
2771
2624
|
}, S = function(C) {
|
|
2772
2625
|
var M = C.pathSegTypeAsLetter.toUpperCase();
|
|
@@ -2790,11 +2643,11 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
2790
2643
|
w(y, v, C.pathSegType);
|
|
2791
2644
|
}
|
|
2792
2645
|
};
|
|
2793
|
-
for (e._svgPathToAbsolute(
|
|
2794
|
-
for (s = i.concat();
|
|
2795
|
-
if (x =
|
|
2646
|
+
for (e._svgPathToAbsolute(r), h = r.getTotalLength(), i = [], u = 0; u < r.pathSegList.numberOfItems; u += 1) i.push(r.pathSegList.getItem(u));
|
|
2647
|
+
for (s = i.concat(); d < h; ) {
|
|
2648
|
+
if (x = r.getPathSegAtLength(d), t = i[x], t != f) {
|
|
2796
2649
|
for (; s.length && s[0] != t; ) S(s.shift());
|
|
2797
|
-
|
|
2650
|
+
f = t;
|
|
2798
2651
|
}
|
|
2799
2652
|
switch (t.pathSegTypeAsLetter.toUpperCase()) {
|
|
2800
2653
|
case "C":
|
|
@@ -2802,189 +2655,189 @@ var Qe = /* @__PURE__ */ Be(((d, E) => {
|
|
|
2802
2655
|
case "S":
|
|
2803
2656
|
case "Q":
|
|
2804
2657
|
case "A":
|
|
2805
|
-
l =
|
|
2658
|
+
l = r.getPointAtLength(d), w(l.x, l.y, 0);
|
|
2806
2659
|
break;
|
|
2807
2660
|
}
|
|
2808
|
-
|
|
2661
|
+
d += a;
|
|
2809
2662
|
}
|
|
2810
|
-
for (
|
|
2663
|
+
for (u = 0, n = s.length; u < n; ++u) S(s[u]);
|
|
2811
2664
|
return P;
|
|
2812
|
-
}, e._svgPathToAbsolute = function(
|
|
2813
|
-
for (var
|
|
2814
|
-
var P = i.getItem(x),
|
|
2815
|
-
if (/[MLHVCSQTA]/.test(
|
|
2816
|
-
"x" in P && (s = P.x), "y" in P && (
|
|
2665
|
+
}, e._svgPathToAbsolute = function(r) {
|
|
2666
|
+
for (var a, u, n, h, l, t, i = r.pathSegList, s = 0, f = 0, m = i.numberOfItems, x = 0; x < m; ++x) {
|
|
2667
|
+
var P = i.getItem(x), T = P.pathSegTypeAsLetter;
|
|
2668
|
+
if (/[MLHVCSQTA]/.test(T))
|
|
2669
|
+
"x" in P && (s = P.x), "y" in P && (f = P.y);
|
|
2817
2670
|
else
|
|
2818
|
-
switch ("x1" in P && (n = s + P.x1), "x2" in P && (l = s + P.x2), "y1" in P && (h =
|
|
2671
|
+
switch ("x1" in P && (n = s + P.x1), "x2" in P && (l = s + P.x2), "y1" in P && (h = f + P.y1), "y2" in P && (t = f + P.y2), "x" in P && (s += P.x), "y" in P && (f += P.y), T) {
|
|
2819
2672
|
case "m":
|
|
2820
|
-
i.replaceItem(
|
|
2673
|
+
i.replaceItem(r.createSVGPathSegMovetoAbs(s, f), x);
|
|
2821
2674
|
break;
|
|
2822
2675
|
case "l":
|
|
2823
|
-
i.replaceItem(
|
|
2676
|
+
i.replaceItem(r.createSVGPathSegLinetoAbs(s, f), x);
|
|
2824
2677
|
break;
|
|
2825
2678
|
case "h":
|
|
2826
|
-
i.replaceItem(
|
|
2679
|
+
i.replaceItem(r.createSVGPathSegLinetoHorizontalAbs(s), x);
|
|
2827
2680
|
break;
|
|
2828
2681
|
case "v":
|
|
2829
|
-
i.replaceItem(
|
|
2682
|
+
i.replaceItem(r.createSVGPathSegLinetoVerticalAbs(f), x);
|
|
2830
2683
|
break;
|
|
2831
2684
|
case "c":
|
|
2832
|
-
i.replaceItem(
|
|
2685
|
+
i.replaceItem(r.createSVGPathSegCurvetoCubicAbs(s, f, n, h, l, t), x);
|
|
2833
2686
|
break;
|
|
2834
2687
|
case "s":
|
|
2835
|
-
i.replaceItem(
|
|
2688
|
+
i.replaceItem(r.createSVGPathSegCurvetoCubicSmoothAbs(s, f, l, t), x);
|
|
2836
2689
|
break;
|
|
2837
2690
|
case "q":
|
|
2838
|
-
i.replaceItem(
|
|
2691
|
+
i.replaceItem(r.createSVGPathSegCurvetoQuadraticAbs(s, f, n, h), x);
|
|
2839
2692
|
break;
|
|
2840
2693
|
case "t":
|
|
2841
|
-
i.replaceItem(
|
|
2694
|
+
i.replaceItem(r.createSVGPathSegCurvetoQuadraticSmoothAbs(s, f), x);
|
|
2842
2695
|
break;
|
|
2843
2696
|
case "a":
|
|
2844
|
-
i.replaceItem(
|
|
2697
|
+
i.replaceItem(r.createSVGPathSegArcAbs(s, f, P.r1, P.r2, P.angle, P.largeArcFlag, P.sweepFlag), x);
|
|
2845
2698
|
break;
|
|
2846
2699
|
case "z":
|
|
2847
2700
|
case "Z":
|
|
2848
|
-
s =
|
|
2701
|
+
s = a, f = u;
|
|
2849
2702
|
break;
|
|
2850
2703
|
}
|
|
2851
|
-
(
|
|
2704
|
+
(T == "M" || T == "m") && (a = s, u = f);
|
|
2852
2705
|
}
|
|
2853
2706
|
};
|
|
2854
2707
|
})();
|
|
2855
2708
|
}),
|
|
2856
|
-
(function(
|
|
2709
|
+
(function(A, E, c) {
|
|
2857
2710
|
var e = {};
|
|
2858
|
-
|
|
2859
|
-
var o =
|
|
2860
|
-
|
|
2711
|
+
A.exports = e;
|
|
2712
|
+
var o = c(6);
|
|
2713
|
+
c(0), (function() {
|
|
2861
2714
|
e.create = o.create, e.add = o.add, e.remove = o.remove, e.clear = o.clear, e.addComposite = o.addComposite, e.addBody = o.addBody, e.addConstraint = o.addConstraint;
|
|
2862
2715
|
})();
|
|
2863
2716
|
})
|
|
2864
2717
|
]);
|
|
2865
2718
|
});
|
|
2866
|
-
})),
|
|
2867
|
-
function
|
|
2868
|
-
return
|
|
2719
|
+
})), U = Fe();
|
|
2720
|
+
function Oe(p, B, A) {
|
|
2721
|
+
return p < B ? B : p > A ? A : p;
|
|
2869
2722
|
}
|
|
2870
|
-
function Z(
|
|
2871
|
-
const
|
|
2872
|
-
return typeof
|
|
2723
|
+
function Z(p) {
|
|
2724
|
+
const B = p.plugin.ballId;
|
|
2725
|
+
return typeof B == "number" ? B : p.id;
|
|
2873
2726
|
}
|
|
2874
|
-
function
|
|
2875
|
-
return
|
|
2727
|
+
function Ue(p, B, A, E) {
|
|
2728
|
+
return Oe(Math.floor((p - B) / A), 0, E - 1);
|
|
2876
2729
|
}
|
|
2877
|
-
var
|
|
2878
|
-
function
|
|
2730
|
+
var We = 0.18, Ne = 0.12, Ve = 420, He = 0.12, Ge = 180, ze = 2, Xe = 5, Ye = 600, Ke = 2, $e = 25e3, Qe = 0.15;
|
|
2731
|
+
function pe(p, B) {
|
|
2879
2732
|
return {
|
|
2880
|
-
x:
|
|
2881
|
-
y:
|
|
2733
|
+
x: p,
|
|
2734
|
+
y: B,
|
|
2882
2735
|
stuckMs: 0,
|
|
2883
2736
|
kickCooldownMs: 0,
|
|
2884
2737
|
kickCount: 0,
|
|
2885
|
-
anchorY:
|
|
2738
|
+
anchorY: B,
|
|
2886
2739
|
anchorAgeMs: 0,
|
|
2887
2740
|
aliveMs: 0
|
|
2888
2741
|
};
|
|
2889
2742
|
}
|
|
2890
|
-
var
|
|
2743
|
+
var Ze = class {
|
|
2891
2744
|
tracker = /* @__PURE__ */ new Map();
|
|
2892
|
-
track(
|
|
2893
|
-
this.tracker.set(
|
|
2745
|
+
track(p, B, A) {
|
|
2746
|
+
this.tracker.set(p, pe(B, A));
|
|
2894
2747
|
}
|
|
2895
|
-
untrack(
|
|
2896
|
-
this.tracker.delete(
|
|
2748
|
+
untrack(p) {
|
|
2749
|
+
this.tracker.delete(p);
|
|
2897
2750
|
}
|
|
2898
2751
|
clear() {
|
|
2899
2752
|
this.tracker.clear();
|
|
2900
2753
|
}
|
|
2901
|
-
process(
|
|
2902
|
-
const
|
|
2903
|
-
for (const o of
|
|
2904
|
-
const
|
|
2905
|
-
|
|
2906
|
-
const
|
|
2907
|
-
if (
|
|
2908
|
-
|
|
2754
|
+
process(p, B, A) {
|
|
2755
|
+
const E = [], c = /* @__PURE__ */ new Set(), e = [];
|
|
2756
|
+
for (const o of B) {
|
|
2757
|
+
const r = Z(o);
|
|
2758
|
+
c.add(r);
|
|
2759
|
+
const a = this.tracker.get(r) ?? pe(o.position.x, o.position.y), u = a.aliveMs + p;
|
|
2760
|
+
if (u >= $e || a.kickCount >= Xe) {
|
|
2761
|
+
E.push(o), this.tracker.delete(r);
|
|
2909
2762
|
continue;
|
|
2910
2763
|
}
|
|
2911
|
-
const n = o.position.x -
|
|
2912
|
-
let
|
|
2913
|
-
o.position.y >
|
|
2914
|
-
const x = s && (i <
|
|
2915
|
-
this.tracker.set(
|
|
2764
|
+
const n = o.position.x - a.x, h = o.position.y - a.y, l = Math.sqrt(n * n + h * h), t = o.velocity, i = Math.sqrt(t.x * t.x + t.y * t.y), s = o.position.y > A.worldHeight * He;
|
|
2765
|
+
let f = a.anchorY, m = a.anchorAgeMs + p;
|
|
2766
|
+
o.position.y > f + Ke && (f = o.position.y, m = 0);
|
|
2767
|
+
const x = s && (i < We && l < Ne || m > Ye) ? a.stuckMs + p : Math.max(0, a.stuckMs - p * 2), P = Math.max(0, a.kickCooldownMs - p);
|
|
2768
|
+
this.tracker.set(r, {
|
|
2916
2769
|
x: o.position.x,
|
|
2917
2770
|
y: o.position.y,
|
|
2918
2771
|
stuckMs: x,
|
|
2919
2772
|
kickCooldownMs: P,
|
|
2920
|
-
kickCount:
|
|
2921
|
-
anchorY:
|
|
2773
|
+
kickCount: a.kickCount,
|
|
2774
|
+
anchorY: f,
|
|
2922
2775
|
anchorAgeMs: m,
|
|
2923
|
-
aliveMs:
|
|
2924
|
-
}), x >=
|
|
2776
|
+
aliveMs: u
|
|
2777
|
+
}), x >= Ve && P <= 0 && e.push({
|
|
2925
2778
|
ball: o,
|
|
2926
|
-
id:
|
|
2779
|
+
id: r,
|
|
2927
2780
|
stuckMs: x
|
|
2928
2781
|
});
|
|
2929
2782
|
}
|
|
2930
|
-
this.applyKicks(e,
|
|
2931
|
-
for (const o of this.tracker.keys())
|
|
2932
|
-
return
|
|
2783
|
+
this.applyKicks(e, A);
|
|
2784
|
+
for (const o of this.tracker.keys()) c.has(o) || this.tracker.delete(o);
|
|
2785
|
+
return E;
|
|
2933
2786
|
}
|
|
2934
|
-
applyKicks(
|
|
2935
|
-
if (
|
|
2936
|
-
|
|
2937
|
-
const
|
|
2938
|
-
for (let
|
|
2939
|
-
const { ball:
|
|
2787
|
+
applyKicks(p, B) {
|
|
2788
|
+
if (p.length === 0) return;
|
|
2789
|
+
p.sort((E, c) => Math.abs(c.ball.position.y - E.ball.position.y) > 0.1 ? c.ball.position.y - E.ball.position.y : c.stuckMs - E.stuckMs);
|
|
2790
|
+
const A = Math.min(ze, p.length);
|
|
2791
|
+
for (let E = 0; E < A; E++) {
|
|
2792
|
+
const { ball: c, id: e } = p[E], o = this.tracker.get(e);
|
|
2940
2793
|
if (!o) continue;
|
|
2941
|
-
const
|
|
2942
|
-
|
|
2943
|
-
x:
|
|
2944
|
-
y: Math.max(
|
|
2945
|
-
}),
|
|
2946
|
-
x:
|
|
2794
|
+
const r = c.velocity, a = Math.abs(c.position.x - B.center) / B.halfWidth < Qe ? Math.random() < 0.5 ? 1 : -1 : c.position.x < B.center ? 1 : -1, u = a * (0.35 + Math.random() * 0.35) + (Math.random() - 0.5) * 0.25, n = 1.1 + Math.random() * 0.5;
|
|
2795
|
+
U.Body.setVelocity(c, {
|
|
2796
|
+
x: r.x + u,
|
|
2797
|
+
y: Math.max(r.y + n, n)
|
|
2798
|
+
}), U.Body.translate(c, {
|
|
2799
|
+
x: a * (0.2 + Math.random() * 0.4),
|
|
2947
2800
|
y: 0.25 + Math.random() * 0.35
|
|
2948
2801
|
}), this.tracker.set(e, {
|
|
2949
2802
|
...o,
|
|
2950
|
-
x:
|
|
2951
|
-
y:
|
|
2803
|
+
x: c.position.x,
|
|
2804
|
+
y: c.position.y,
|
|
2952
2805
|
stuckMs: 0,
|
|
2953
|
-
kickCooldownMs:
|
|
2806
|
+
kickCooldownMs: Ge,
|
|
2954
2807
|
kickCount: o.kickCount + 1
|
|
2955
2808
|
});
|
|
2956
2809
|
}
|
|
2957
2810
|
}
|
|
2958
2811
|
};
|
|
2959
|
-
function
|
|
2960
|
-
const
|
|
2812
|
+
function Je(p) {
|
|
2813
|
+
const B = Math.max(0, Math.min(1, p)), A = B ** 1.3;
|
|
2961
2814
|
return {
|
|
2962
|
-
windStrength:
|
|
2963
|
-
collisionNudge:
|
|
2964
|
-
spawnSigmaRatio:
|
|
2815
|
+
windStrength: A * 4e-7,
|
|
2816
|
+
collisionNudge: A * 0.13,
|
|
2817
|
+
spawnSigmaRatio: B > 0 ? 0.04 - A * 0.035 : 0
|
|
2965
2818
|
};
|
|
2966
2819
|
}
|
|
2967
|
-
var
|
|
2968
|
-
function
|
|
2969
|
-
if (!(
|
|
2970
|
-
for (const
|
|
2971
|
-
if (Math.sqrt(
|
|
2972
|
-
const
|
|
2973
|
-
|
|
2974
|
-
x: -
|
|
2820
|
+
var je = 0.4;
|
|
2821
|
+
function qe(p, B, A) {
|
|
2822
|
+
if (!(A <= 0))
|
|
2823
|
+
for (const E of p) {
|
|
2824
|
+
if (Math.sqrt(E.velocity.x * E.velocity.x + E.velocity.y * E.velocity.y) < je) continue;
|
|
2825
|
+
const c = E.position.x - B;
|
|
2826
|
+
U.Body.applyForce(E, E.position, {
|
|
2827
|
+
x: -A * c,
|
|
2975
2828
|
y: 0
|
|
2976
2829
|
});
|
|
2977
2830
|
}
|
|
2978
2831
|
}
|
|
2979
2832
|
var ne = "plinkit-ball";
|
|
2980
|
-
function
|
|
2981
|
-
const
|
|
2982
|
-
return Math.sqrt(-2 * Math.log(
|
|
2833
|
+
function _e() {
|
|
2834
|
+
const p = Math.random(), B = Math.random();
|
|
2835
|
+
return Math.sqrt(-2 * Math.log(p || 1e-15)) * Math.cos(2 * Math.PI * B);
|
|
2983
2836
|
}
|
|
2984
|
-
function
|
|
2985
|
-
const
|
|
2986
|
-
let
|
|
2987
|
-
return
|
|
2837
|
+
function et(p, B) {
|
|
2838
|
+
const A = Math.max(p.radius + 8, p.height * 0.06);
|
|
2839
|
+
let E;
|
|
2840
|
+
return B && B > 0 ? E = _e() * p.width * B : E = (Math.random() - 0.5) * p.width * 0.08, U.Bodies.circle(p.width * 0.5 + E, A, p.radius, {
|
|
2988
2841
|
label: ne,
|
|
2989
2842
|
restitution: 0.65,
|
|
2990
2843
|
frictionAir: 1e-3,
|
|
@@ -2992,7 +2845,7 @@ function gt(d, E) {
|
|
|
2992
2845
|
frictionStatic: 0
|
|
2993
2846
|
});
|
|
2994
2847
|
}
|
|
2995
|
-
var ee = "plinkit-peg", te = "plinkit-guide",
|
|
2848
|
+
var ee = "plinkit-peg", te = "plinkit-guide", re = "plinkit-wall", tt = 0.22, it = 4, nt = class {
|
|
2996
2849
|
engine;
|
|
2997
2850
|
config;
|
|
2998
2851
|
pegs = [];
|
|
@@ -3003,188 +2856,188 @@ var ee = "plinkit-peg", te = "plinkit-guide", oe = "plinkit-wall", dt = 0.22, vt
|
|
|
3003
2856
|
pegBaseY = 0;
|
|
3004
2857
|
center = 0;
|
|
3005
2858
|
layoutGeometry = null;
|
|
3006
|
-
antiStuck = new
|
|
2859
|
+
antiStuck = new Ze();
|
|
3007
2860
|
dist;
|
|
3008
2861
|
removeCollisionNudge = null;
|
|
3009
2862
|
removeCollisionStart = null;
|
|
3010
|
-
constructor(
|
|
3011
|
-
this.engine =
|
|
2863
|
+
constructor(p) {
|
|
2864
|
+
this.engine = U.Engine.create({ gravity: {
|
|
3012
2865
|
x: 0,
|
|
3013
|
-
y:
|
|
2866
|
+
y: p.gravityY,
|
|
3014
2867
|
scale: 1e-3
|
|
3015
|
-
} }), this.config =
|
|
3016
|
-
const
|
|
3017
|
-
if (
|
|
3018
|
-
const
|
|
3019
|
-
const
|
|
3020
|
-
for (const o of
|
|
3021
|
-
const
|
|
3022
|
-
if (!
|
|
3023
|
-
const
|
|
3024
|
-
|
|
3025
|
-
x:
|
|
3026
|
-
y:
|
|
2868
|
+
} }), this.config = p, this.dist = Je(p.houseEdge ?? 0), this.rebuildStaticBodies(p.width, p.height);
|
|
2869
|
+
const B = this.dist.collisionNudge;
|
|
2870
|
+
if (B > 0) {
|
|
2871
|
+
const A = (E) => {
|
|
2872
|
+
const c = this.center, e = this.config.width * 0.5;
|
|
2873
|
+
for (const o of E.pairs) {
|
|
2874
|
+
const r = o.bodyA.label === "plinkit-ball" ? o.bodyA : o.bodyB.label === "plinkit-ball" ? o.bodyB : null;
|
|
2875
|
+
if (!r || r.plugin.settled || !(o.bodyA.label === ee || o.bodyB.label === ee || o.bodyA.label === te || o.bodyB.label === te)) continue;
|
|
2876
|
+
const a = (r.position.x - c) / e;
|
|
2877
|
+
U.Body.setVelocity(r, {
|
|
2878
|
+
x: r.velocity.x - B * a,
|
|
2879
|
+
y: r.velocity.y
|
|
3027
2880
|
});
|
|
3028
2881
|
}
|
|
3029
2882
|
};
|
|
3030
|
-
|
|
2883
|
+
U.Events.on(this.engine, "collisionEnd", A), this.removeCollisionNudge = () => U.Events.off(this.engine, "collisionEnd", A);
|
|
3031
2884
|
}
|
|
3032
|
-
if (
|
|
3033
|
-
const
|
|
3034
|
-
for (const e of
|
|
2885
|
+
if (p.onCollision) {
|
|
2886
|
+
const A = p.onCollision, E = (c) => {
|
|
2887
|
+
for (const e of c.pairs) {
|
|
3035
2888
|
const o = e.bodyA.label === "plinkit-ball" ? e.bodyA : e.bodyB.label === "plinkit-ball" ? e.bodyB : null;
|
|
3036
2889
|
if (!o || o.plugin.settled) continue;
|
|
3037
|
-
const
|
|
3038
|
-
let
|
|
3039
|
-
if (
|
|
3040
|
-
const
|
|
3041
|
-
|
|
2890
|
+
const r = e.bodyA === o ? e.bodyB.label : e.bodyA.label;
|
|
2891
|
+
let a = null;
|
|
2892
|
+
if (r === ee ? a = "peg" : r === te && (a = "guide"), !a) continue;
|
|
2893
|
+
const u = Math.hypot(o.velocity.x, o.velocity.y);
|
|
2894
|
+
A({
|
|
3042
2895
|
ballId: Z(o),
|
|
3043
|
-
target:
|
|
3044
|
-
speed:
|
|
2896
|
+
target: a,
|
|
2897
|
+
speed: u
|
|
3045
2898
|
});
|
|
3046
2899
|
}
|
|
3047
2900
|
};
|
|
3048
|
-
|
|
2901
|
+
U.Events.on(this.engine, "collisionStart", E), this.removeCollisionStart = () => U.Events.off(this.engine, "collisionStart", E);
|
|
3049
2902
|
}
|
|
3050
2903
|
}
|
|
3051
|
-
resize(
|
|
2904
|
+
resize(p, B) {
|
|
3052
2905
|
this.config = {
|
|
3053
2906
|
...this.config,
|
|
3054
|
-
width:
|
|
3055
|
-
height:
|
|
3056
|
-
}, this.rebuildStaticBodies(
|
|
2907
|
+
width: p,
|
|
2908
|
+
height: B
|
|
2909
|
+
}, this.rebuildStaticBodies(p, B);
|
|
3057
2910
|
}
|
|
3058
|
-
setBallCost(
|
|
2911
|
+
setBallCost(p) {
|
|
3059
2912
|
this.config = {
|
|
3060
2913
|
...this.config,
|
|
3061
|
-
ballCost:
|
|
2914
|
+
ballCost: p
|
|
3062
2915
|
};
|
|
3063
2916
|
}
|
|
3064
2917
|
spawnBall() {
|
|
3065
|
-
const
|
|
2918
|
+
const p = et({
|
|
3066
2919
|
width: this.config.width,
|
|
3067
2920
|
height: this.config.height,
|
|
3068
2921
|
radius: this.config.ballRadius
|
|
3069
2922
|
}, this.dist.spawnSigmaRatio);
|
|
3070
|
-
|
|
2923
|
+
p.plugin.ballId = this.nextBallId, p.plugin.wager = this.config.ballCost, this.nextBallId += 1, this.antiStuck.track(Z(p), p.position.x, p.position.y), U.World.add(this.engine.world, p);
|
|
3071
2924
|
}
|
|
3072
2925
|
canSpawnBall() {
|
|
3073
|
-
const
|
|
3074
|
-
let
|
|
3075
|
-
const
|
|
3076
|
-
for (const
|
|
3077
|
-
if (!
|
|
2926
|
+
const p = this.config.height * tt;
|
|
2927
|
+
let B = 0;
|
|
2928
|
+
const A = U.Composite.allBodies(this.engine.world).filter((E) => E.label === ne);
|
|
2929
|
+
for (const E of A)
|
|
2930
|
+
if (!E.plugin.settled && E.position.y <= p && (B += 1, B >= it))
|
|
3078
2931
|
return !1;
|
|
3079
2932
|
return !0;
|
|
3080
2933
|
}
|
|
3081
|
-
step(
|
|
3082
|
-
|
|
3083
|
-
const
|
|
3084
|
-
|
|
3085
|
-
const
|
|
2934
|
+
step(p) {
|
|
2935
|
+
U.Engine.update(this.engine, p);
|
|
2936
|
+
const B = U.Composite.allBodies(this.engine.world).filter((e) => e.label === ne), A = B.filter((e) => !e.plugin.settled);
|
|
2937
|
+
qe(A, this.center, this.dist.windStrength);
|
|
2938
|
+
const E = this.antiStuck.process(p, A, {
|
|
3086
2939
|
center: this.center,
|
|
3087
2940
|
halfWidth: this.config.width * 0.5,
|
|
3088
2941
|
worldHeight: this.config.height
|
|
3089
|
-
}).map((e) => this.settleBall(e)),
|
|
3090
|
-
return
|
|
2942
|
+
}).map((e) => this.settleBall(e)), c = this.cleanupBalls(B);
|
|
2943
|
+
return E.length > 0 ? [...E, ...c] : c;
|
|
3091
2944
|
}
|
|
3092
2945
|
snapshot() {
|
|
3093
|
-
const
|
|
2946
|
+
const p = this.config.layout.mainPegs.radius;
|
|
3094
2947
|
return {
|
|
3095
|
-
pegs: this.pegs.map((
|
|
3096
|
-
x:
|
|
3097
|
-
y:
|
|
3098
|
-
radius:
|
|
2948
|
+
pegs: this.pegs.map((B) => ({
|
|
2949
|
+
x: B.position.x,
|
|
2950
|
+
y: B.position.y,
|
|
2951
|
+
radius: B.circleRadius ?? p
|
|
3099
2952
|
})),
|
|
3100
|
-
guidePegs: this.guidePegs.map((
|
|
3101
|
-
x:
|
|
3102
|
-
y:
|
|
3103
|
-
radius:
|
|
2953
|
+
guidePegs: this.guidePegs.map((B) => ({
|
|
2954
|
+
x: B.position.x,
|
|
2955
|
+
y: B.position.y,
|
|
2956
|
+
radius: B.circleRadius ?? p
|
|
3104
2957
|
})),
|
|
3105
|
-
balls:
|
|
3106
|
-
id: Z(
|
|
3107
|
-
x:
|
|
3108
|
-
y:
|
|
3109
|
-
radius:
|
|
2958
|
+
balls: U.Composite.allBodies(this.engine.world).filter((B) => B.label === ne).map((B) => ({
|
|
2959
|
+
id: Z(B),
|
|
2960
|
+
x: B.position.x,
|
|
2961
|
+
y: B.position.y,
|
|
2962
|
+
radius: B.circleRadius ?? this.config.ballRadius
|
|
3110
2963
|
})),
|
|
3111
2964
|
walls: this.getWallRects(),
|
|
3112
2965
|
buckets: this.buckets
|
|
3113
2966
|
};
|
|
3114
2967
|
}
|
|
3115
2968
|
destroy() {
|
|
3116
|
-
this.removeCollisionNudge?.(), this.removeCollisionStart?.(),
|
|
2969
|
+
this.removeCollisionNudge?.(), this.removeCollisionStart?.(), U.World.clear(this.engine.world, !1), U.Engine.clear(this.engine);
|
|
3117
2970
|
}
|
|
3118
|
-
cleanupBalls(
|
|
3119
|
-
const
|
|
3120
|
-
for (const
|
|
3121
|
-
if (
|
|
3122
|
-
this.antiStuck.untrack(Z(
|
|
2971
|
+
cleanupBalls(p) {
|
|
2972
|
+
const B = [], A = this.config.height + this.config.ballRadius, E = this.getBucketTop();
|
|
2973
|
+
for (const c of p) {
|
|
2974
|
+
if (c.position.y > A) {
|
|
2975
|
+
this.antiStuck.untrack(Z(c)), U.World.remove(this.engine.world, c);
|
|
3123
2976
|
continue;
|
|
3124
2977
|
}
|
|
3125
|
-
if (!
|
|
3126
|
-
|
|
2978
|
+
if (!c.plugin.settled && c.position.y >= E) {
|
|
2979
|
+
B.push(this.settleBall(c));
|
|
3127
2980
|
continue;
|
|
3128
2981
|
}
|
|
3129
|
-
const e =
|
|
3130
|
-
!
|
|
2982
|
+
const e = c.circleRadius ?? this.config.ballRadius, o = this.config.height - e - 1;
|
|
2983
|
+
!c.plugin.settled && c.position.y >= o && B.push(this.settleBall(c));
|
|
3131
2984
|
}
|
|
3132
|
-
return
|
|
2985
|
+
return B;
|
|
3133
2986
|
}
|
|
3134
|
-
rebuildStaticBodies(
|
|
3135
|
-
this.antiStuck.clear(), this.pegs.length > 0 && (
|
|
2987
|
+
rebuildStaticBodies(p, B) {
|
|
2988
|
+
this.antiStuck.clear(), this.pegs.length > 0 && (U.World.remove(this.engine.world, this.pegs), this.pegs = []), this.guidePegs.length > 0 && (U.World.remove(this.engine.world, this.guidePegs), this.guidePegs = []), this.walls && (U.World.remove(this.engine.world, [
|
|
3136
2989
|
this.walls.leftWall,
|
|
3137
2990
|
this.walls.rightWall,
|
|
3138
2991
|
this.walls.floor
|
|
3139
|
-
]), this.walls = null), this.center =
|
|
3140
|
-
const
|
|
3141
|
-
...
|
|
3142
|
-
width:
|
|
3143
|
-
height:
|
|
2992
|
+
]), this.walls = null), this.center = p * 0.5;
|
|
2993
|
+
const A = Math.max(18, p * 0.02), E = p / this.config.multipliers.length, c = this.config.layout.mainPegs, e = Te({
|
|
2994
|
+
...c,
|
|
2995
|
+
width: p,
|
|
2996
|
+
height: B
|
|
3144
2997
|
});
|
|
3145
2998
|
this.layoutGeometry = e;
|
|
3146
|
-
const o =
|
|
3147
|
-
this.pegs =
|
|
2999
|
+
const o = c.radius, r = this.config.layout.edgeGuides.radius;
|
|
3000
|
+
this.pegs = Ae(e, o).map((t) => U.Bodies.circle(t.x, t.y, t.radius, {
|
|
3148
3001
|
isStatic: !0,
|
|
3149
3002
|
label: ee,
|
|
3150
3003
|
restitution: 0.3
|
|
3151
3004
|
})), this.pegBaseY = this.pegs.reduce((t, i) => Math.max(t, i.position.y), 0);
|
|
3152
|
-
const
|
|
3005
|
+
const a = this.getBucketTop(), u = U.Bodies.rectangle(-A * 0.5, B * 0.5, A, B * 2, {
|
|
3153
3006
|
isStatic: !0,
|
|
3154
|
-
label:
|
|
3007
|
+
label: re,
|
|
3155
3008
|
restitution: 0.4
|
|
3156
|
-
}), n =
|
|
3009
|
+
}), n = U.Bodies.rectangle(p + A * 0.5, B * 0.5, A, B * 2, {
|
|
3157
3010
|
isStatic: !0,
|
|
3158
|
-
label:
|
|
3011
|
+
label: re,
|
|
3159
3012
|
restitution: 0.4
|
|
3160
|
-
}), h =
|
|
3013
|
+
}), h = U.Bodies.rectangle(p * 0.5, B + A * 0.5, p, A, {
|
|
3161
3014
|
isStatic: !0,
|
|
3162
3015
|
isSensor: !0,
|
|
3163
|
-
label:
|
|
3016
|
+
label: re
|
|
3164
3017
|
});
|
|
3165
3018
|
this.walls = {
|
|
3166
|
-
leftWall:
|
|
3019
|
+
leftWall: u,
|
|
3167
3020
|
rightWall: n,
|
|
3168
3021
|
floor: h
|
|
3169
|
-
},
|
|
3170
|
-
|
|
3022
|
+
}, U.World.add(this.engine.world, [
|
|
3023
|
+
u,
|
|
3171
3024
|
n,
|
|
3172
3025
|
h
|
|
3173
|
-
]), this.guidePegs =
|
|
3026
|
+
]), this.guidePegs = Be(e, r, {
|
|
3174
3027
|
spread: this.config.layout.edgeGuides.spread,
|
|
3175
3028
|
yOffset: this.config.layout.edgeGuides.yOffset
|
|
3176
|
-
}).map((t) =>
|
|
3029
|
+
}).map((t) => U.Bodies.circle(t.x, t.y, t.radius, {
|
|
3177
3030
|
isStatic: !0,
|
|
3178
3031
|
label: te,
|
|
3179
3032
|
restitution: 0.3
|
|
3180
|
-
})),
|
|
3181
|
-
const l =
|
|
3033
|
+
})), U.World.add(this.engine.world, this.pegs), U.World.add(this.engine.world, this.guidePegs);
|
|
3034
|
+
const l = B - a;
|
|
3182
3035
|
this.buckets = this.config.multipliers.map((t, i) => ({
|
|
3183
3036
|
index: i,
|
|
3184
3037
|
multiplier: t,
|
|
3185
|
-
x:
|
|
3186
|
-
y:
|
|
3187
|
-
width:
|
|
3038
|
+
x: E * i,
|
|
3039
|
+
y: a,
|
|
3040
|
+
width: E,
|
|
3188
3041
|
height: l
|
|
3189
3042
|
}));
|
|
3190
3043
|
}
|
|
@@ -3193,29 +3046,29 @@ var ee = "plinkit-peg", te = "plinkit-guide", oe = "plinkit-wall", dt = 0.22, vt
|
|
|
3193
3046
|
this.walls.leftWall,
|
|
3194
3047
|
this.walls.rightWall,
|
|
3195
3048
|
this.walls.floor
|
|
3196
|
-
].map((
|
|
3197
|
-
x:
|
|
3198
|
-
y:
|
|
3199
|
-
width:
|
|
3200
|
-
height:
|
|
3049
|
+
].map((p) => ({
|
|
3050
|
+
x: p.position.x,
|
|
3051
|
+
y: p.position.y,
|
|
3052
|
+
width: p.bounds.max.x - p.bounds.min.x,
|
|
3053
|
+
height: p.bounds.max.y - p.bounds.min.y
|
|
3201
3054
|
})) : [];
|
|
3202
3055
|
}
|
|
3203
3056
|
getBucketTop() {
|
|
3204
|
-
const
|
|
3205
|
-
return this.pegBaseY > 0 ? Math.min(this.config.height - 6, this.pegBaseY +
|
|
3057
|
+
const p = this.config.layout.mainPegs.radius + this.config.ballRadius - 1;
|
|
3058
|
+
return this.pegBaseY > 0 ? Math.min(this.config.height - 6, this.pegBaseY + p) : this.config.height * 0.85;
|
|
3206
3059
|
}
|
|
3207
|
-
settleBall(
|
|
3208
|
-
|
|
3209
|
-
const
|
|
3060
|
+
settleBall(p) {
|
|
3061
|
+
p.plugin.settled = !0, U.Body.set(p, "isSensor", !0);
|
|
3062
|
+
const B = this.layoutGeometry, A = this.config.layout.mainPegs, E = B?.sidePadding ?? A.radius + A.sidePaddingPx, c = B?.baseSpacing ?? (this.config.width - E * 2) / Math.max(A.bottomPegCount - 1, 1), e = Ue(p.position.x, E, c, this.config.multipliers.length), o = this.config.multipliers[e] ?? 0, r = typeof p.plugin.wager == "number" ? p.plugin.wager : this.config.ballCost;
|
|
3210
3063
|
return {
|
|
3211
|
-
ballId: Z(
|
|
3064
|
+
ballId: Z(p),
|
|
3212
3065
|
bucketIndex: e,
|
|
3213
3066
|
multiplier: o,
|
|
3214
|
-
wager:
|
|
3215
|
-
payout:
|
|
3067
|
+
wager: r,
|
|
3068
|
+
payout: r * o
|
|
3216
3069
|
};
|
|
3217
3070
|
}
|
|
3218
|
-
},
|
|
3071
|
+
}, st = `
|
|
3219
3072
|
precision highp float;
|
|
3220
3073
|
in vec2 a_position;
|
|
3221
3074
|
uniform vec2 u_resolution;
|
|
@@ -3231,7 +3084,7 @@ void main() {
|
|
|
3231
3084
|
v_local = a_position;
|
|
3232
3085
|
v_uv = a_position * 0.5 + 0.5;
|
|
3233
3086
|
}
|
|
3234
|
-
`,
|
|
3087
|
+
`, at = `
|
|
3235
3088
|
precision highp float;
|
|
3236
3089
|
uniform vec4 u_color;
|
|
3237
3090
|
uniform float u_shapeMode;
|
|
@@ -3258,7 +3111,7 @@ void main() {
|
|
|
3258
3111
|
outColor = vec4(u_color.rgb, u_color.a * a);
|
|
3259
3112
|
}
|
|
3260
3113
|
}
|
|
3261
|
-
`,
|
|
3114
|
+
`, rt = class {
|
|
3262
3115
|
canvas;
|
|
3263
3116
|
gl;
|
|
3264
3117
|
program;
|
|
@@ -3277,19 +3130,19 @@ void main() {
|
|
|
3277
3130
|
ballTexture = null;
|
|
3278
3131
|
pegTextureReady = !1;
|
|
3279
3132
|
ballTextureReady = !1;
|
|
3280
|
-
constructor(
|
|
3281
|
-
this.canvas =
|
|
3282
|
-
const
|
|
3133
|
+
constructor(p, B) {
|
|
3134
|
+
this.canvas = p;
|
|
3135
|
+
const A = p.getContext("webgl2", {
|
|
3283
3136
|
antialias: !0,
|
|
3284
3137
|
alpha: !0
|
|
3285
3138
|
});
|
|
3286
|
-
if (!
|
|
3287
|
-
this.gl =
|
|
3288
|
-
const
|
|
3289
|
-
this.program =
|
|
3290
|
-
const e = this.gl.getAttribLocation(this.program, "a_position"), o = this.gl.getUniformLocation(this.program, "u_resolution"),
|
|
3291
|
-
if (e < 0 || !o || !
|
|
3292
|
-
this.positionLocation = e, this.resolutionLocation = o, this.centerLocation =
|
|
3139
|
+
if (!A) throw new Error("WebGL2 is not supported by this browser");
|
|
3140
|
+
this.gl = A;
|
|
3141
|
+
const E = de(this.gl, this.gl.VERTEX_SHADER, st), c = de(this.gl, this.gl.FRAGMENT_SHADER, at);
|
|
3142
|
+
this.program = ft(this.gl, E, c);
|
|
3143
|
+
const e = this.gl.getAttribLocation(this.program, "a_position"), o = this.gl.getUniformLocation(this.program, "u_resolution"), r = this.gl.getUniformLocation(this.program, "u_center"), a = this.gl.getUniformLocation(this.program, "u_size"), u = this.gl.getUniformLocation(this.program, "u_color"), n = this.gl.getUniformLocation(this.program, "u_shapeMode"), h = this.gl.getUniformLocation(this.program, "u_useTexture"), l = this.gl.getUniformLocation(this.program, "u_texture");
|
|
3144
|
+
if (e < 0 || !o || !r || !a || !u || !n || !h || !l) throw new Error("Unable to initialize WebGL program locations");
|
|
3145
|
+
this.positionLocation = e, this.resolutionLocation = o, this.centerLocation = r, this.sizeLocation = a, this.colorLocation = u, this.shapeModeLocation = n, this.useTextureLocation = h, this.textureLocation = l, this.gl.useProgram(this.program), this.gl.uniform1i(this.textureLocation, 0);
|
|
3293
3146
|
const t = this.gl.createBuffer();
|
|
3294
3147
|
if (!t) throw new Error("Unable to create WebGL buffer");
|
|
3295
3148
|
this.positionBuffer = t, this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.positionBuffer), this.gl.bufferData(this.gl.ARRAY_BUFFER, new Float32Array([
|
|
@@ -3306,82 +3159,82 @@ void main() {
|
|
|
3306
3159
|
1,
|
|
3307
3160
|
1
|
|
3308
3161
|
]), this.gl.STATIC_DRAW), this.gl.enable(this.gl.BLEND), this.gl.blendFunc(this.gl.SRC_ALPHA, this.gl.ONE_MINUS_SRC_ALPHA);
|
|
3309
|
-
const i =
|
|
3162
|
+
const i = B?.appearance;
|
|
3310
3163
|
i?.pegTextureUrl && this.startTextureLoad(i.pegTextureUrl, i.textureCrossOrigin, "peg"), i?.ballTextureUrl && this.startTextureLoad(i.ballTextureUrl, i.textureCrossOrigin, "ball");
|
|
3311
3164
|
}
|
|
3312
|
-
resize(
|
|
3313
|
-
this.scale =
|
|
3165
|
+
resize(p, B, A, E = 1) {
|
|
3166
|
+
this.scale = A * E, this.canvas.width = Math.floor(p * A), this.canvas.height = Math.floor(B * A), this.gl.viewport(0, 0, this.canvas.width, this.canvas.height);
|
|
3314
3167
|
}
|
|
3315
|
-
render(
|
|
3168
|
+
render(p) {
|
|
3316
3169
|
this.gl.clearColor(0, 0, 0, 0), this.gl.clear(this.gl.COLOR_BUFFER_BIT), this.gl.useProgram(this.program), this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.positionBuffer), this.gl.enableVertexAttribArray(this.positionLocation), this.gl.vertexAttribPointer(this.positionLocation, 2, this.gl.FLOAT, !1, 0, 0), this.gl.uniform2f(this.resolutionLocation, this.canvas.width, this.canvas.height), this.gl.uniform1i(this.textureLocation, 0);
|
|
3317
|
-
for (const
|
|
3318
|
-
for (const
|
|
3319
|
-
for (const
|
|
3320
|
-
for (const
|
|
3170
|
+
for (const B of p.walls) this.drawRect(B, ie(54, 68, 102));
|
|
3171
|
+
for (const B of p.pegs) this.drawCircle(B.x, B.y, B.radius, ie(141, 226, 255), "peg");
|
|
3172
|
+
for (const B of p.guidePegs) this.drawCircle(B.x, B.y, B.radius, ie(255, 90, 120), "peg");
|
|
3173
|
+
for (const B of p.balls) this.drawCircle(B.x, B.y, B.radius, ie(250, 201, 95), "ball");
|
|
3321
3174
|
}
|
|
3322
3175
|
destroy() {
|
|
3323
3176
|
this.destroyed = !0, this.gl.bindBuffer(this.gl.ARRAY_BUFFER, null), this.pegTexture && (this.gl.deleteTexture(this.pegTexture), this.pegTexture = null), this.ballTexture && (this.gl.deleteTexture(this.ballTexture), this.ballTexture = null), this.pegTextureReady = !1, this.ballTextureReady = !1, this.gl.deleteBuffer(this.positionBuffer), this.gl.deleteProgram(this.program);
|
|
3324
3177
|
}
|
|
3325
|
-
startTextureLoad(
|
|
3326
|
-
|
|
3178
|
+
startTextureLoad(p, B, A) {
|
|
3179
|
+
lt(p, B).then((E) => {
|
|
3327
3180
|
if (this.destroyed) return;
|
|
3328
|
-
const
|
|
3181
|
+
const c = ot(this.gl, E);
|
|
3329
3182
|
if (this.destroyed) {
|
|
3330
|
-
this.gl.deleteTexture(
|
|
3183
|
+
this.gl.deleteTexture(c);
|
|
3331
3184
|
return;
|
|
3332
3185
|
}
|
|
3333
|
-
|
|
3186
|
+
A === "peg" ? (this.pegTexture && this.gl.deleteTexture(this.pegTexture), this.pegTexture = c, this.pegTextureReady = !0) : (this.ballTexture && this.gl.deleteTexture(this.ballTexture), this.ballTexture = c, this.ballTextureReady = !0);
|
|
3334
3187
|
}).catch(() => {
|
|
3335
3188
|
});
|
|
3336
3189
|
}
|
|
3337
|
-
drawRect(
|
|
3338
|
-
this.gl.uniform2f(this.centerLocation,
|
|
3190
|
+
drawRect(p, B) {
|
|
3191
|
+
this.gl.uniform2f(this.centerLocation, p.x * this.scale, p.y * this.scale), this.gl.uniform2f(this.sizeLocation, p.width * this.scale * 0.5, p.height * this.scale * 0.5), this.gl.uniform4f(this.colorLocation, B.r, B.g, B.b, B.a), this.gl.uniform1f(this.shapeModeLocation, 0), this.gl.uniform1f(this.useTextureLocation, 0), this.gl.drawArrays(this.gl.TRIANGLES, 0, 6);
|
|
3339
3192
|
}
|
|
3340
|
-
drawCircle(
|
|
3341
|
-
this.gl.uniform2f(this.centerLocation,
|
|
3342
|
-
const e =
|
|
3193
|
+
drawCircle(p, B, A, E, c) {
|
|
3194
|
+
this.gl.uniform2f(this.centerLocation, p * this.scale, B * this.scale), this.gl.uniform2f(this.sizeLocation, A * this.scale, A * this.scale), this.gl.uniform4f(this.colorLocation, E.r, E.g, E.b, E.a), this.gl.uniform1f(this.shapeModeLocation, 1);
|
|
3195
|
+
const e = c === "peg" ? this.pegTexture : this.ballTexture, o = c === "peg" ? this.pegTextureReady : this.ballTextureReady;
|
|
3343
3196
|
e && o ? (this.gl.activeTexture(this.gl.TEXTURE0), this.gl.bindTexture(this.gl.TEXTURE_2D, e), this.gl.uniform1f(this.useTextureLocation, 1)) : this.gl.uniform1f(this.useTextureLocation, 0), this.gl.drawArrays(this.gl.TRIANGLES, 0, 6);
|
|
3344
3197
|
}
|
|
3345
3198
|
};
|
|
3346
|
-
function ie(
|
|
3199
|
+
function ie(p, B, A, E = 1) {
|
|
3347
3200
|
return {
|
|
3348
|
-
r:
|
|
3349
|
-
g:
|
|
3350
|
-
b:
|
|
3351
|
-
a:
|
|
3201
|
+
r: p / 255,
|
|
3202
|
+
g: B / 255,
|
|
3203
|
+
b: A / 255,
|
|
3204
|
+
a: E
|
|
3352
3205
|
};
|
|
3353
3206
|
}
|
|
3354
|
-
function
|
|
3355
|
-
const
|
|
3356
|
-
if (!
|
|
3357
|
-
return
|
|
3207
|
+
function ot(p, B) {
|
|
3208
|
+
const A = p.createTexture();
|
|
3209
|
+
if (!A) throw new Error("Unable to create WebGL texture");
|
|
3210
|
+
return p.bindTexture(p.TEXTURE_2D, A), p.texImage2D(p.TEXTURE_2D, 0, p.RGBA, p.RGBA, p.UNSIGNED_BYTE, B), p.texParameteri(p.TEXTURE_2D, p.TEXTURE_WRAP_S, p.CLAMP_TO_EDGE), p.texParameteri(p.TEXTURE_2D, p.TEXTURE_WRAP_T, p.CLAMP_TO_EDGE), p.texParameteri(p.TEXTURE_2D, p.TEXTURE_MIN_FILTER, p.LINEAR), p.texParameteri(p.TEXTURE_2D, p.TEXTURE_MAG_FILTER, p.LINEAR), p.bindTexture(p.TEXTURE_2D, null), A;
|
|
3358
3211
|
}
|
|
3359
|
-
function
|
|
3360
|
-
return new Promise((
|
|
3361
|
-
const
|
|
3362
|
-
typeof
|
|
3212
|
+
function lt(p, B) {
|
|
3213
|
+
return new Promise((A, E) => {
|
|
3214
|
+
const c = new Image();
|
|
3215
|
+
typeof B == "string" && B.length > 0 && (c.crossOrigin = B), c.onload = () => A(c), c.onerror = () => E(/* @__PURE__ */ new Error(`Failed to load image: ${p}`)), c.src = p;
|
|
3363
3216
|
});
|
|
3364
3217
|
}
|
|
3365
|
-
function
|
|
3366
|
-
const
|
|
3367
|
-
if (!
|
|
3368
|
-
if (
|
|
3369
|
-
${
|
|
3370
|
-
const
|
|
3371
|
-
throw
|
|
3372
|
-
}
|
|
3373
|
-
return
|
|
3218
|
+
function de(p, B, A) {
|
|
3219
|
+
const E = p.createShader(B);
|
|
3220
|
+
if (!E) throw new Error("Unable to create shader");
|
|
3221
|
+
if (p.shaderSource(E, `#version 300 es
|
|
3222
|
+
${A}`), p.compileShader(E), !p.getShaderParameter(E, p.COMPILE_STATUS)) {
|
|
3223
|
+
const c = p.getShaderInfoLog(E);
|
|
3224
|
+
throw p.deleteShader(E), new Error(`Shader compile error: ${c ?? "unknown"}`);
|
|
3225
|
+
}
|
|
3226
|
+
return E;
|
|
3374
3227
|
}
|
|
3375
|
-
function
|
|
3376
|
-
const
|
|
3377
|
-
if (!
|
|
3378
|
-
if (
|
|
3379
|
-
const
|
|
3380
|
-
throw
|
|
3381
|
-
}
|
|
3382
|
-
return
|
|
3228
|
+
function ft(p, B, A) {
|
|
3229
|
+
const E = p.createProgram();
|
|
3230
|
+
if (!E) throw new Error("Unable to create program");
|
|
3231
|
+
if (p.attachShader(E, B), p.attachShader(E, A), p.linkProgram(E), !p.getProgramParameter(E, p.LINK_STATUS)) {
|
|
3232
|
+
const c = p.getProgramInfoLog(E);
|
|
3233
|
+
throw p.deleteProgram(E), new Error(`Program link error: ${c ?? "unknown"}`);
|
|
3234
|
+
}
|
|
3235
|
+
return p.deleteShader(B), p.deleteShader(A), E;
|
|
3383
3236
|
}
|
|
3384
|
-
var
|
|
3237
|
+
var oe = 1e3 / 120, ct = 50, ut = 8, ht = 300, gt = class {
|
|
3385
3238
|
canvas;
|
|
3386
3239
|
viewport;
|
|
3387
3240
|
renderer;
|
|
@@ -3400,49 +3253,43 @@ var le = 1e3 / 120, Ct = 50, Mt = 8, Tt = 300, Bt = class {
|
|
|
3400
3253
|
showGuidePegs;
|
|
3401
3254
|
balance;
|
|
3402
3255
|
lastSpawnAtMs = -1 / 0;
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
}, this.ballCost =
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
mainPegs: d.layout.mainPegs,
|
|
3417
|
-
ballRadius: d.ballRadius,
|
|
3418
|
-
heightPolicy: d.viewport.heightPolicy
|
|
3419
|
-
}), T = {
|
|
3420
|
-
...d.layout,
|
|
3421
|
-
mainPegs: E.resolvedMainPegs
|
|
3256
|
+
constructor(p) {
|
|
3257
|
+
this.canvas = p.canvas, this.viewport = p.viewport, this.width = 1, this.height = 1, this.callbacks = {
|
|
3258
|
+
onBalanceChange: p.onBalanceChange,
|
|
3259
|
+
onBallSettled: p.onBallSettled,
|
|
3260
|
+
onCollision: p.onCollision
|
|
3261
|
+
}, this.ballCost = p.ballCost, this.showGuidePegs = p.showGuidePegs, this.balance = p.initialBalance, this.onDprChange = () => this.listenDpr();
|
|
3262
|
+
const B = Le({
|
|
3263
|
+
mainPegs: p.layout.mainPegs,
|
|
3264
|
+
ballRadius: p.ballRadius,
|
|
3265
|
+
heightPolicy: p.viewport.heightPolicy
|
|
3266
|
+
}), A = {
|
|
3267
|
+
...p.layout,
|
|
3268
|
+
mainPegs: B.resolvedMainPegs
|
|
3422
3269
|
};
|
|
3423
|
-
this.worldHeight =
|
|
3270
|
+
this.worldHeight = B.worldHeight, this.canvas.style.maxWidth = "100%", this.renderer = new rt(this.canvas, { appearance: p.appearance }), this.world = new nt({
|
|
3424
3271
|
width: 600,
|
|
3425
3272
|
height: this.worldHeight,
|
|
3426
|
-
gravityY:
|
|
3427
|
-
layout:
|
|
3428
|
-
ballRadius:
|
|
3429
|
-
multipliers:
|
|
3273
|
+
gravityY: p.gravityY,
|
|
3274
|
+
layout: A,
|
|
3275
|
+
ballRadius: p.ballRadius,
|
|
3276
|
+
multipliers: p.multipliers,
|
|
3430
3277
|
ballCost: this.ballCost,
|
|
3431
|
-
houseEdge:
|
|
3432
|
-
onCollision: this.
|
|
3433
|
-
}), this.resize(), this.loop = new
|
|
3434
|
-
const
|
|
3435
|
-
if (!
|
|
3436
|
-
this.resizeObserver = new ResizeObserver((
|
|
3437
|
-
const e =
|
|
3278
|
+
houseEdge: p.houseEdge,
|
|
3279
|
+
onCollision: this.callbacks.onCollision ? (c) => this.handleCollision(c) : void 0
|
|
3280
|
+
}), this.resize(), this.loop = new Me((c) => this.frame(c)), this.loop.start();
|
|
3281
|
+
const E = this.canvas.parentElement;
|
|
3282
|
+
if (!E) throw new Error("Canvas must have a parent element for viewport sizing");
|
|
3283
|
+
this.resizeObserver = new ResizeObserver((c) => {
|
|
3284
|
+
const e = c[0];
|
|
3438
3285
|
if (!e) return;
|
|
3439
|
-
const o = e.contentBoxSize?.[0]?.inlineSize,
|
|
3440
|
-
this.syncViewport(
|
|
3441
|
-
}), this.resizeObserver.observe(
|
|
3286
|
+
const o = e.contentBoxSize?.[0]?.inlineSize, r = o != null && o > 0 ? o : E.getBoundingClientRect().width;
|
|
3287
|
+
this.syncViewport(r);
|
|
3288
|
+
}), this.resizeObserver.observe(E), this.listenDpr(), this.emitBalanceChange();
|
|
3442
3289
|
}
|
|
3443
3290
|
spawnBall() {
|
|
3444
|
-
const
|
|
3445
|
-
return
|
|
3291
|
+
const p = performance.now();
|
|
3292
|
+
return p - this.lastSpawnAtMs < ht ? {
|
|
3446
3293
|
ok: !1,
|
|
3447
3294
|
reason: "SPAWN_COOLDOWN",
|
|
3448
3295
|
state: this.getStateSnapshot()
|
|
@@ -3450,7 +3297,7 @@ var le = 1e3 / 120, Ct = 50, Mt = 8, Tt = 300, Bt = class {
|
|
|
3450
3297
|
ok: !1,
|
|
3451
3298
|
reason: "INSUFFICIENT_BALANCE",
|
|
3452
3299
|
state: this.getStateSnapshot()
|
|
3453
|
-
} : (this.balance -= this.ballCost, this.lastSpawnAtMs =
|
|
3300
|
+
} : (this.balance -= this.ballCost, this.lastSpawnAtMs = p, this.emitBalanceChange(), this.world.spawnBall(), {
|
|
3454
3301
|
ok: !0,
|
|
3455
3302
|
state: this.getStateSnapshot()
|
|
3456
3303
|
}) : {
|
|
@@ -3460,74 +3307,62 @@ var le = 1e3 / 120, Ct = 50, Mt = 8, Tt = 300, Bt = class {
|
|
|
3460
3307
|
};
|
|
3461
3308
|
}
|
|
3462
3309
|
resize() {
|
|
3463
|
-
const
|
|
3464
|
-
|
|
3310
|
+
const p = this.canvas.parentElement;
|
|
3311
|
+
p && this.syncViewport(p.getBoundingClientRect().width);
|
|
3465
3312
|
}
|
|
3466
3313
|
destroy() {
|
|
3467
|
-
this.loop.stop(), this.resizeObserver.disconnect(), this.dprQuery?.removeEventListener("change", this.onDprChange), this.dprQuery = null, this.world.destroy(), this.renderer.destroy()
|
|
3314
|
+
this.loop.stop(), this.resizeObserver.disconnect(), this.dprQuery?.removeEventListener("change", this.onDprChange), this.dprQuery = null, this.world.destroy(), this.renderer.destroy();
|
|
3468
3315
|
}
|
|
3469
3316
|
getState() {
|
|
3470
3317
|
return this.getStateSnapshot();
|
|
3471
3318
|
}
|
|
3472
|
-
setBallCost(
|
|
3473
|
-
if (!Number.isFinite(
|
|
3474
|
-
this.ballCost !==
|
|
3475
|
-
}
|
|
3476
|
-
setMuted(d) {
|
|
3477
|
-
this.audio?.setMuted(d);
|
|
3478
|
-
}
|
|
3479
|
-
isMuted() {
|
|
3480
|
-
return this.audio?.isMuted() ?? !0;
|
|
3481
|
-
}
|
|
3482
|
-
setVolume(d) {
|
|
3483
|
-
this.audio?.setVolume(d);
|
|
3484
|
-
}
|
|
3485
|
-
playUiTap() {
|
|
3486
|
-
this.audio?.playUiTap();
|
|
3319
|
+
setBallCost(p) {
|
|
3320
|
+
if (!Number.isFinite(p) || p < 0) throw new TypeError(`Plinkit.setBallCost: expected a non-negative finite number, got ${p}`);
|
|
3321
|
+
this.ballCost !== p && (this.ballCost = p, this.world.setBallCost(p), this.emitBalanceChange());
|
|
3487
3322
|
}
|
|
3488
|
-
handleCollision(
|
|
3489
|
-
this.
|
|
3323
|
+
handleCollision(p) {
|
|
3324
|
+
this.callbacks.onCollision?.(p, this.getStateSnapshot());
|
|
3490
3325
|
}
|
|
3491
|
-
frame(
|
|
3326
|
+
frame(p) {
|
|
3492
3327
|
if (this.lastFrameTime === 0) {
|
|
3493
|
-
this.lastFrameTime =
|
|
3328
|
+
this.lastFrameTime = p, this.renderSnapshot();
|
|
3494
3329
|
return;
|
|
3495
3330
|
}
|
|
3496
|
-
const
|
|
3497
|
-
this.lastFrameTime =
|
|
3498
|
-
let
|
|
3499
|
-
for (; this.accumulatorMs >=
|
|
3500
|
-
const
|
|
3501
|
-
for (const
|
|
3502
|
-
this.balance +=
|
|
3331
|
+
const B = Math.min(ct, p - this.lastFrameTime);
|
|
3332
|
+
this.lastFrameTime = p, this.accumulatorMs += B;
|
|
3333
|
+
let A = 0;
|
|
3334
|
+
for (; this.accumulatorMs >= oe && A < ut; ) {
|
|
3335
|
+
const E = this.world.step(oe);
|
|
3336
|
+
for (const c of E) {
|
|
3337
|
+
this.balance += c.payout;
|
|
3503
3338
|
const e = this.getStateSnapshot();
|
|
3504
|
-
this.callbacks.onBallSettled?.(
|
|
3339
|
+
this.callbacks.onBallSettled?.(c, e), this.callbacks.onBalanceChange?.(e);
|
|
3505
3340
|
}
|
|
3506
|
-
this.accumulatorMs -=
|
|
3341
|
+
this.accumulatorMs -= oe, A += 1;
|
|
3507
3342
|
}
|
|
3508
3343
|
this.renderSnapshot();
|
|
3509
3344
|
}
|
|
3510
3345
|
renderSnapshot() {
|
|
3511
|
-
const
|
|
3512
|
-
this.showGuidePegs || (
|
|
3346
|
+
const p = this.world.snapshot();
|
|
3347
|
+
this.showGuidePegs || (p.guidePegs = []), this.renderer.render(p);
|
|
3513
3348
|
}
|
|
3514
3349
|
emitBalanceChange() {
|
|
3515
3350
|
this.callbacks.onBalanceChange?.(this.getStateSnapshot());
|
|
3516
3351
|
}
|
|
3517
|
-
syncViewport(
|
|
3518
|
-
const
|
|
3519
|
-
parentWidthPx:
|
|
3352
|
+
syncViewport(p) {
|
|
3353
|
+
const B = Re({
|
|
3354
|
+
parentWidthPx: p,
|
|
3520
3355
|
viewport: this.viewport,
|
|
3521
3356
|
worldHeight: this.worldHeight
|
|
3522
3357
|
});
|
|
3523
|
-
this.width = Math.max(1,
|
|
3524
|
-
const
|
|
3525
|
-
this.renderer.resize(this.width, this.height,
|
|
3358
|
+
this.width = Math.max(1, B.displayWidth), this.height = Math.max(1, B.displayHeight), this.canvas.style.width = `${this.width}px`, this.canvas.style.height = `${this.height}px`;
|
|
3359
|
+
const A = Math.min(window.devicePixelRatio || 1, this.viewport.dprCap);
|
|
3360
|
+
this.renderer.resize(this.width, this.height, A, B.worldScale);
|
|
3526
3361
|
}
|
|
3527
3362
|
listenDpr() {
|
|
3528
3363
|
this.dprQuery?.removeEventListener("change", this.onDprChange);
|
|
3529
|
-
const
|
|
3530
|
-
|
|
3364
|
+
const p = window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`);
|
|
3365
|
+
p.addEventListener("change", this.onDprChange), this.dprQuery = p, this.resize();
|
|
3531
3366
|
}
|
|
3532
3367
|
getStateSnapshot() {
|
|
3533
3368
|
return {
|
|
@@ -3537,5 +3372,5 @@ var le = 1e3 / 120, Ct = 50, Mt = 8, Tt = 300, Bt = class {
|
|
|
3537
3372
|
}
|
|
3538
3373
|
};
|
|
3539
3374
|
export {
|
|
3540
|
-
|
|
3375
|
+
gt as Plinkit
|
|
3541
3376
|
};
|