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