dopaminejs 2.1.0 → 2.2.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/dist/dopamine.js +166 -93
- package/dist/dopamine.umd.cjs +2 -2
- package/package.json +6 -3
- package/src/dopamine/core/RewardSystem.js +81 -7
- package/src/index.js +6 -0
- package/src/systems/Input.js +8 -4
- package/src/systems/Loader.js +7 -3
- package/src/systems/Physics.js +7 -3
- package/src/systems/deprecate.js +38 -0
- package/types/index.d.ts +588 -0
package/dist/dopamine.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class D {
|
|
2
2
|
constructor() {
|
|
3
3
|
this.listeners = /* @__PURE__ */ new Map();
|
|
4
4
|
}
|
|
@@ -40,9 +40,41 @@ class C {
|
|
|
40
40
|
this.listeners.clear();
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
class O extends
|
|
43
|
+
class O extends D {
|
|
44
|
+
/**
|
|
45
|
+
* @param {Object} dataService - Persistence, see DataService
|
|
46
|
+
* @param {Object} [config]
|
|
47
|
+
* @param {Object} [config.achievements] - Extra achievement definitions
|
|
48
|
+
* @param {Object} [config.events] - Kernel EventBus to mirror events onto
|
|
49
|
+
* @param {Object} [config.kernel] - Kernel; its `events` bus is used if present
|
|
50
|
+
*/
|
|
44
51
|
constructor(e, t = {}) {
|
|
45
|
-
|
|
52
|
+
var s;
|
|
53
|
+
super(), this.dataService = e, this.player = null, this.achievements = { ...this._initAchievements(), ...t.achievements || {} }, this.events = t.events || ((s = t.kernel) == null ? void 0 : s.events) || null, this._batchDepth = 0, this._pendingSave = !1;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Emit locally, and mirror onto the kernel bus when one is attached.
|
|
57
|
+
* @private
|
|
58
|
+
*/
|
|
59
|
+
_publish(e, t) {
|
|
60
|
+
this.emit(e, t), this.events && this.events.emit(e, t);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Run `fn` with saves collapsed into a single write at the end.
|
|
64
|
+
*
|
|
65
|
+
* Nested batches are counted, so an inner operation that batches on its
|
|
66
|
+
* own still results in exactly one write for the outermost call.
|
|
67
|
+
*
|
|
68
|
+
* @param {Function} fn
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
71
|
+
async _batch(e) {
|
|
72
|
+
this._batchDepth++;
|
|
73
|
+
try {
|
|
74
|
+
return await e();
|
|
75
|
+
} finally {
|
|
76
|
+
this._batchDepth--, this._batchDepth === 0 && this._pendingSave && (this._pendingSave = !1, await this._write());
|
|
77
|
+
}
|
|
46
78
|
}
|
|
47
79
|
/**
|
|
48
80
|
* Initialize the reward system for current player
|
|
@@ -100,7 +132,20 @@ class O extends C {
|
|
|
100
132
|
* Save player data
|
|
101
133
|
*/
|
|
102
134
|
async save() {
|
|
103
|
-
|
|
135
|
+
if (this.player) {
|
|
136
|
+
if (this._batchDepth > 0) {
|
|
137
|
+
this._pendingSave = !0;
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
await this._write();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* The actual persistence call. Bypasses batching.
|
|
145
|
+
* @private
|
|
146
|
+
*/
|
|
147
|
+
async _write() {
|
|
148
|
+
this.player.lastPlayedAt = Date.now(), await this.dataService.save("player", this.player);
|
|
104
149
|
}
|
|
105
150
|
/**
|
|
106
151
|
* Add XP and handle level ups
|
|
@@ -114,7 +159,7 @@ class O extends C {
|
|
|
114
159
|
const s = this.player.level;
|
|
115
160
|
this.player.xp += e;
|
|
116
161
|
const i = this._calculateLevel(this.player.xp), r = i > s;
|
|
117
|
-
return r && (this.player.level = i), await this.save(), this.
|
|
162
|
+
return r && (this.player.level = i), await this.save(), this._publish("xp_gained", { amount: e, reason: t, leveledUp: r, newLevel: i }), r && this._publish("level_up", { oldLevel: s, newLevel: i }), { leveledUp: r, newLevel: i, xpGained: e };
|
|
118
163
|
}
|
|
119
164
|
/**
|
|
120
165
|
* Calculate level from XP (exponential curve)
|
|
@@ -140,9 +185,15 @@ class O extends C {
|
|
|
140
185
|
* @param {Object} result - Game-specific result data
|
|
141
186
|
*/
|
|
142
187
|
async recordGame(e, t) {
|
|
188
|
+
return this._batch(() => this._recordGame(e, t));
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* @private
|
|
192
|
+
*/
|
|
193
|
+
async _recordGame(e, t) {
|
|
143
194
|
this.player.stats[e] || (this.player.stats[e] = { totalPlays: 0, highScore: 0 });
|
|
144
195
|
const s = this.player.stats[e];
|
|
145
|
-
s.totalPlays++, this.player.totalGamesPlayed++, t.score !== void 0 && t.score > s.highScore && (s.highScore = t.score, this.
|
|
196
|
+
s.totalPlays++, this.player.totalGamesPlayed++, t.score !== void 0 && t.score > s.highScore && (s.highScore = t.score, this._publish("new_high_score", { gameName: e, score: t.score })), Object.keys(t).forEach((r) => {
|
|
146
197
|
r !== "score" && (s[r] = (s[r] || 0) + (typeof t[r] == "number" ? t[r] : 0));
|
|
147
198
|
});
|
|
148
199
|
let i = 10;
|
|
@@ -177,7 +228,7 @@ class O extends C {
|
|
|
177
228
|
}, await this.addXP(
|
|
178
229
|
Number.isFinite(t.xp) ? t.xp : 0,
|
|
179
230
|
`Achievement: ${t.name}`
|
|
180
|
-
), this.
|
|
231
|
+
), this._publish("achievement_unlocked", t), await this.save(), !0) : !1;
|
|
181
232
|
}
|
|
182
233
|
/**
|
|
183
234
|
* Get all unlocked achievements
|
|
@@ -293,7 +344,7 @@ class O extends C {
|
|
|
293
344
|
};
|
|
294
345
|
}
|
|
295
346
|
}
|
|
296
|
-
function
|
|
347
|
+
function S() {
|
|
297
348
|
const a = /* @__PURE__ */ new Map();
|
|
298
349
|
return {
|
|
299
350
|
getItem: (e) => a.has(e) ? a.get(e) : null,
|
|
@@ -308,19 +359,19 @@ function w() {
|
|
|
308
359
|
}
|
|
309
360
|
};
|
|
310
361
|
}
|
|
311
|
-
function
|
|
362
|
+
function b() {
|
|
312
363
|
try {
|
|
313
364
|
if (typeof localStorage > "u")
|
|
314
|
-
return
|
|
365
|
+
return S();
|
|
315
366
|
const a = "__dopamine_probe__";
|
|
316
367
|
return localStorage.setItem(a, "1"), localStorage.removeItem(a), localStorage;
|
|
317
368
|
} catch {
|
|
318
|
-
return
|
|
369
|
+
return S();
|
|
319
370
|
}
|
|
320
371
|
}
|
|
321
372
|
class A {
|
|
322
373
|
constructor(e = {}) {
|
|
323
|
-
this.storage = e.storage ||
|
|
374
|
+
this.storage = e.storage || b(), this.prefix = e.prefix || "dopamine_";
|
|
324
375
|
}
|
|
325
376
|
/**
|
|
326
377
|
* Save data to local storage
|
|
@@ -357,7 +408,7 @@ class A {
|
|
|
357
408
|
}
|
|
358
409
|
}
|
|
359
410
|
const k = "game-ui-overlay";
|
|
360
|
-
class
|
|
411
|
+
class T {
|
|
361
412
|
constructor(e) {
|
|
362
413
|
this.particleSystem = e, this.container = null, this.xpBar = null, this.levelDisplay = null, this.streakDisplay = null, this._timers = /* @__PURE__ */ new Set(), this._detached = [], this.init();
|
|
363
414
|
}
|
|
@@ -570,7 +621,7 @@ class D {
|
|
|
570
621
|
this._detached = [], (e = this.container) == null || e.remove(), this.container = null, this.xpBar = null, this.xpText = null, this.levelBadge = null, this.streakBadge = null, this.levelDisplay = null, this.streakDisplay = null;
|
|
571
622
|
}
|
|
572
623
|
}
|
|
573
|
-
class
|
|
624
|
+
class I {
|
|
574
625
|
constructor(e = {}) {
|
|
575
626
|
this.container = e.container ? typeof e.container == "string" ? document.querySelector(e.container) : e.container : document.body, this.canvasId = e.canvasId || "dopamine-particle-canvas", this.canvas = document.createElement("canvas"), this.canvas.classList.add("dopamine-particle-canvas"), document.getElementById(this.canvasId) || (this.canvas.id = this.canvasId), this.canvas.style.pointerEvents = "none", this.canvas.style.zIndex = e.zIndex || "9999", this.container === document.body ? (this.canvas.style.position = "fixed", this.canvas.style.top = "0", this.canvas.style.left = "0") : (this.canvas.style.position = "absolute", this.canvas.style.top = "0", this.canvas.style.left = "0", window.getComputedStyle(this.container).position === "static" && (this.container.style.position = "relative")), this.container.appendChild(this.canvas), this.ctx = this.canvas.getContext("2d"), this.particles = [], this.pool = [], this.sprites = /* @__PURE__ */ new Map(), this.customEffects = /* @__PURE__ */ new Map(), this.isAnimating = !1, this._onResize = () => this._resize(), this._resizeObserver = null, this._frameHandle = null, this._resize(), window.ResizeObserver && this.container !== document.body ? (this._resizeObserver = new ResizeObserver(this._onResize), this._resizeObserver.observe(this.container)) : window.addEventListener("resize", this._onResize);
|
|
576
627
|
}
|
|
@@ -622,8 +673,8 @@ class T {
|
|
|
622
673
|
size: f = 5
|
|
623
674
|
} = e;
|
|
624
675
|
for (let v = 0; v < i; v++) {
|
|
625
|
-
const d = this._getParticle(),
|
|
626
|
-
d.x = t, d.y = s, d.vx = Math.cos(
|
|
676
|
+
const d = this._getParticle(), x = m + (Math.random() - 0.5) * u, w = Math.random() * r;
|
|
677
|
+
d.x = t, d.y = s, d.vx = Math.cos(x) * w, d.vy = Math.sin(x) * w, d.life = c, d.decay = o * (0.8 + Math.random() * 0.4), d.gravity = n, d.color = Array.isArray(h) ? h[Math.floor(Math.random() * h.length)] : h, d.size = f * (0.8 + Math.random() * 0.4), d.sprite = l, d.rotation = Math.random() * Math.PI * 2, d.rotationSpeed = (Math.random() - 0.5) * 0.2, this.particles.push(d);
|
|
627
678
|
}
|
|
628
679
|
this._startAnimation();
|
|
629
680
|
}
|
|
@@ -738,9 +789,9 @@ class T {
|
|
|
738
789
|
this.clear(), this.isAnimating = !1, this._frameHandle !== null && (cancelAnimationFrame(this._frameHandle), this._frameHandle = null), this._resizeObserver && (this._resizeObserver.disconnect(), this._resizeObserver = null), window.removeEventListener("resize", this._onResize), this.canvas.remove(), this.sprites.clear(), this.customEffects.clear(), this.pool = [];
|
|
739
790
|
}
|
|
740
791
|
}
|
|
741
|
-
class
|
|
792
|
+
class L {
|
|
742
793
|
constructor(e = {}) {
|
|
743
|
-
this.audioContext = null, this.storageKey = e.storageKey || "dopamineSoundsMuted", this.storage = e.storage ||
|
|
794
|
+
this.audioContext = null, this.storageKey = e.storageKey || "dopamineSoundsMuted", this.storage = e.storage || b(), this.muted = this.storage.getItem(this.storageKey) === "true", this.assets = /* @__PURE__ */ new Map(), this.customSounds = e.customSounds || {}, this.masterGain = null, this._volume = e.volume ?? 1, Object.keys(this.customSounds).length > 0 && this.preloadSounds(this.customSounds);
|
|
744
795
|
}
|
|
745
796
|
/**
|
|
746
797
|
* Initialize Audio Context (must be called after user interaction)
|
|
@@ -874,9 +925,9 @@ class I {
|
|
|
874
925
|
this.playTone(200, 0.2, "sawtooth", 0.3);
|
|
875
926
|
}
|
|
876
927
|
}
|
|
877
|
-
class
|
|
928
|
+
class H {
|
|
878
929
|
constructor(e = {}) {
|
|
879
|
-
this.config = e, this.dataService = new A(e.data || {}), this.rewardSystem = new O(this.dataService, e.rewards || {}), this.soundManager = new
|
|
930
|
+
this.config = e, this.dataService = new A(e.data || {}), this.rewardSystem = new O(this.dataService, e.rewards || {}), this.soundManager = new L(e.sound || {}), this.particleSystem = new I(e.particles || {}), this.gameUI = new T(this.particleSystem), this._bindEvents();
|
|
880
931
|
}
|
|
881
932
|
async init() {
|
|
882
933
|
return await this.rewardSystem.init(), {
|
|
@@ -1018,7 +1069,7 @@ p.Events = {
|
|
|
1018
1069
|
PLUGIN_LOADED: "plugin_loaded",
|
|
1019
1070
|
PLUGIN_UNLOADED: "plugin_unloaded"
|
|
1020
1071
|
};
|
|
1021
|
-
class
|
|
1072
|
+
class U {
|
|
1022
1073
|
constructor(e) {
|
|
1023
1074
|
this.kernel = e, this._systems = /* @__PURE__ */ new Map(), this._updateOrder = [], this._fixedUpdateOrder = [], this._needsRecompute = !1;
|
|
1024
1075
|
}
|
|
@@ -1134,7 +1185,7 @@ class L {
|
|
|
1134
1185
|
this.unregister(e);
|
|
1135
1186
|
}
|
|
1136
1187
|
}
|
|
1137
|
-
class
|
|
1188
|
+
class R {
|
|
1138
1189
|
constructor(e) {
|
|
1139
1190
|
this.kernel = e, this._plugins = /* @__PURE__ */ new Map(), this._loadOrder = [];
|
|
1140
1191
|
}
|
|
@@ -1252,7 +1303,7 @@ class U {
|
|
|
1252
1303
|
this.remove(this._loadOrder[e]);
|
|
1253
1304
|
}
|
|
1254
1305
|
}
|
|
1255
|
-
class
|
|
1306
|
+
class z {
|
|
1256
1307
|
constructor(e = {}) {
|
|
1257
1308
|
this.width = e.width || 800, this.height = e.height || 600, this.backgroundColor = e.backgroundColor || "#000000", e.canvas ? (this.canvas = e.canvas, this.canvas.width = this.width, this.canvas.height = this.height) : (this.canvas = document.createElement("canvas"), this.canvas.width = this.width, this.canvas.height = this.height, (e.parent ? typeof e.parent == "string" ? document.querySelector(e.parent) : e.parent : document.body).appendChild(this.canvas)), this.ctx = this.canvas.getContext("2d");
|
|
1258
1309
|
}
|
|
@@ -1266,7 +1317,7 @@ class R {
|
|
|
1266
1317
|
this.width = e, this.height = t, this.canvas.width = e, this.canvas.height = t;
|
|
1267
1318
|
}
|
|
1268
1319
|
}
|
|
1269
|
-
class
|
|
1320
|
+
class G {
|
|
1270
1321
|
constructor() {
|
|
1271
1322
|
this.running = !1, this.lastTime = 0, this.callbacks = /* @__PURE__ */ new Set(), this._frameHandle = null, this._tick = this._tick.bind(this);
|
|
1272
1323
|
}
|
|
@@ -1306,6 +1357,19 @@ class z {
|
|
|
1306
1357
|
this.running && (this._frameHandle = requestAnimationFrame(this._tick));
|
|
1307
1358
|
}
|
|
1308
1359
|
}
|
|
1360
|
+
function g(a, e) {
|
|
1361
|
+
let t = !1;
|
|
1362
|
+
return new Proxy(a, {
|
|
1363
|
+
get(s, i, r) {
|
|
1364
|
+
t || (t = !0, console.warn(e));
|
|
1365
|
+
const n = Reflect.get(s, i, r);
|
|
1366
|
+
return typeof n == "function" ? n.bind(s) : n;
|
|
1367
|
+
},
|
|
1368
|
+
set(s, i, r) {
|
|
1369
|
+
return t || (t = !0, console.warn(e)), Reflect.set(s, i, r);
|
|
1370
|
+
}
|
|
1371
|
+
});
|
|
1372
|
+
}
|
|
1309
1373
|
class y {
|
|
1310
1374
|
constructor() {
|
|
1311
1375
|
this.gameObject = null, this.kernel = null;
|
|
@@ -1338,7 +1402,7 @@ class y {
|
|
|
1338
1402
|
render(e) {
|
|
1339
1403
|
}
|
|
1340
1404
|
}
|
|
1341
|
-
class
|
|
1405
|
+
class $ extends y {
|
|
1342
1406
|
constructor(e = "box", t = 50, s = 50, i = 25) {
|
|
1343
1407
|
super(), this.type = e, this.width = t, this.height = s, this.radius = i, this.tag = null;
|
|
1344
1408
|
}
|
|
@@ -1365,7 +1429,7 @@ class H extends y {
|
|
|
1365
1429
|
};
|
|
1366
1430
|
}
|
|
1367
1431
|
}
|
|
1368
|
-
class
|
|
1432
|
+
class M {
|
|
1369
1433
|
constructor() {
|
|
1370
1434
|
this.colliders = [], this.kernel = null;
|
|
1371
1435
|
}
|
|
@@ -1449,9 +1513,11 @@ class b {
|
|
|
1449
1513
|
setGravity(e, t) {
|
|
1450
1514
|
}
|
|
1451
1515
|
}
|
|
1452
|
-
const
|
|
1453
|
-
|
|
1454
|
-
|
|
1516
|
+
const q = g(
|
|
1517
|
+
new M(),
|
|
1518
|
+
"[DopamineJS] GlobalPhysics is deprecated. Use kernel.physics instead."
|
|
1519
|
+
);
|
|
1520
|
+
class E {
|
|
1455
1521
|
constructor() {
|
|
1456
1522
|
this.keys = /* @__PURE__ */ new Map(), this.mouse = { x: 0, y: 0, buttons: /* @__PURE__ */ new Map() }, this.kernel = null, this._onKeyDown = this._onKeyDown.bind(this), this._onKeyUp = this._onKeyUp.bind(this), this._onMouseMove = this._onMouseMove.bind(this), this._onMouseDown = this._onMouseDown.bind(this), this._onMouseUp = this._onMouseUp.bind(this);
|
|
1457
1523
|
}
|
|
@@ -1489,9 +1555,11 @@ class M {
|
|
|
1489
1555
|
return this.mouse.buttons.get(e) || !1;
|
|
1490
1556
|
}
|
|
1491
1557
|
}
|
|
1492
|
-
const
|
|
1493
|
-
|
|
1494
|
-
|
|
1558
|
+
const K = g(
|
|
1559
|
+
new E(),
|
|
1560
|
+
"[DopamineJS] GlobalInput is deprecated. Use kernel.input instead."
|
|
1561
|
+
);
|
|
1562
|
+
class P {
|
|
1495
1563
|
constructor() {
|
|
1496
1564
|
this.assets = /* @__PURE__ */ new Map(), this.kernel = null;
|
|
1497
1565
|
}
|
|
@@ -1519,11 +1587,13 @@ class E {
|
|
|
1519
1587
|
return this.assets.get(e);
|
|
1520
1588
|
}
|
|
1521
1589
|
}
|
|
1522
|
-
const
|
|
1523
|
-
|
|
1590
|
+
const X = g(
|
|
1591
|
+
new P(),
|
|
1592
|
+
"[DopamineJS] GlobalLoader is deprecated. Use kernel.loader instead."
|
|
1593
|
+
);
|
|
1524
1594
|
class B {
|
|
1525
1595
|
constructor(e = {}) {
|
|
1526
|
-
this.config = e, this._boundUpdate = this._update.bind(this), this.events = new p(), this.systems = new
|
|
1596
|
+
this.config = e, this._boundUpdate = this._update.bind(this), this.events = new p(), this.systems = new U(this), this.plugins = new R(this), this._registerCoreSystems(e), this.fixedTimestep = e.fixedTimestep || 1 / 60, this._accumulator = 0, this._maxAccumulator = this.fixedTimestep * 5;
|
|
1527
1597
|
}
|
|
1528
1598
|
/**
|
|
1529
1599
|
* Register core engine systems
|
|
@@ -1531,7 +1601,7 @@ class B {
|
|
|
1531
1601
|
* @private
|
|
1532
1602
|
*/
|
|
1533
1603
|
_registerCoreSystems(e) {
|
|
1534
|
-
this.systems.register("ticker", new
|
|
1604
|
+
this.systems.register("ticker", new G(), {
|
|
1535
1605
|
priority: 100
|
|
1536
1606
|
});
|
|
1537
1607
|
const t = {
|
|
@@ -1541,13 +1611,13 @@ class B {
|
|
|
1541
1611
|
canvas: e.canvas,
|
|
1542
1612
|
...e.renderer
|
|
1543
1613
|
};
|
|
1544
|
-
this.systems.register("renderer", new
|
|
1614
|
+
this.systems.register("renderer", new z(t), {
|
|
1545
1615
|
priority: 90
|
|
1546
|
-
}), this.systems.register("input", new
|
|
1616
|
+
}), this.systems.register("input", new E(), {
|
|
1547
1617
|
priority: 80
|
|
1548
|
-
}), this.systems.register("loader", new
|
|
1618
|
+
}), this.systems.register("loader", new P(), {
|
|
1549
1619
|
priority: 70
|
|
1550
|
-
}), this.systems.register("physics", new
|
|
1620
|
+
}), this.systems.register("physics", new M(), {
|
|
1551
1621
|
priority: 60
|
|
1552
1622
|
});
|
|
1553
1623
|
}
|
|
@@ -1601,7 +1671,7 @@ class B {
|
|
|
1601
1671
|
e && e.remove(this._boundUpdate), this.plugins.clear(), this.systems.clear(), this.events.clear();
|
|
1602
1672
|
}
|
|
1603
1673
|
}
|
|
1604
|
-
const
|
|
1674
|
+
const _ = {
|
|
1605
1675
|
/**
|
|
1606
1676
|
* Called when system is registered to the kernel
|
|
1607
1677
|
* @param {DopamineKernel} kernel - The kernel instance
|
|
@@ -1626,7 +1696,7 @@ const g = {
|
|
|
1626
1696
|
destroy() {
|
|
1627
1697
|
}
|
|
1628
1698
|
};
|
|
1629
|
-
class
|
|
1699
|
+
class J {
|
|
1630
1700
|
constructor() {
|
|
1631
1701
|
this.kernel = null;
|
|
1632
1702
|
}
|
|
@@ -1640,8 +1710,8 @@ class X {
|
|
|
1640
1710
|
destroy() {
|
|
1641
1711
|
}
|
|
1642
1712
|
}
|
|
1643
|
-
const
|
|
1644
|
-
...
|
|
1713
|
+
const W = {
|
|
1714
|
+
..._,
|
|
1645
1715
|
/**
|
|
1646
1716
|
* Add a physics body to the simulation
|
|
1647
1717
|
* @param {Object} body - Physics body (implementation-specific)
|
|
@@ -1684,8 +1754,8 @@ const J = {
|
|
|
1684
1754
|
*/
|
|
1685
1755
|
step(a) {
|
|
1686
1756
|
}
|
|
1687
|
-
},
|
|
1688
|
-
...
|
|
1757
|
+
}, Y = {
|
|
1758
|
+
..._,
|
|
1689
1759
|
/**
|
|
1690
1760
|
* Register a sound with a key
|
|
1691
1761
|
* @param {string} key - Sound identifier
|
|
@@ -1734,8 +1804,8 @@ const J = {
|
|
|
1734
1804
|
*/
|
|
1735
1805
|
setVolume(a) {
|
|
1736
1806
|
}
|
|
1737
|
-
},
|
|
1738
|
-
...
|
|
1807
|
+
}, V = {
|
|
1808
|
+
..._,
|
|
1739
1809
|
/**
|
|
1740
1810
|
* Register a sprite for particles
|
|
1741
1811
|
* @param {string} key - Sprite identifier
|
|
@@ -1782,7 +1852,7 @@ const J = {
|
|
|
1782
1852
|
starBurst(a, e, t) {
|
|
1783
1853
|
}
|
|
1784
1854
|
};
|
|
1785
|
-
class
|
|
1855
|
+
class Q {
|
|
1786
1856
|
constructor() {
|
|
1787
1857
|
this.gameObjects = [], this.kernel = null;
|
|
1788
1858
|
}
|
|
@@ -1828,7 +1898,7 @@ class V {
|
|
|
1828
1898
|
t.render(e);
|
|
1829
1899
|
}
|
|
1830
1900
|
}
|
|
1831
|
-
class
|
|
1901
|
+
class j {
|
|
1832
1902
|
constructor(e) {
|
|
1833
1903
|
this.game = e, this.currentScene = null;
|
|
1834
1904
|
}
|
|
@@ -1840,9 +1910,9 @@ class G {
|
|
|
1840
1910
|
this.currentScene && this.currentScene.onExit(), this.currentScene = e, this.currentScene.game = this.game, this.game.scene = e, e.onEnter();
|
|
1841
1911
|
}
|
|
1842
1912
|
}
|
|
1843
|
-
class
|
|
1913
|
+
class Z {
|
|
1844
1914
|
constructor(e = {}) {
|
|
1845
|
-
this.config = e, this.kernel = new B(e), this.director = new
|
|
1915
|
+
this.config = e, this.kernel = new B(e), this.director = new j(this), this.kernel.systems.register("director", this.director), this.kernel.events.on(p.Events.TICK, this._update.bind(this), 10), this.kernel.events.on(p.Events.RENDER, this._render.bind(this), 10);
|
|
1846
1916
|
}
|
|
1847
1917
|
/**
|
|
1848
1918
|
* Backward compatibility accessors
|
|
@@ -1891,7 +1961,7 @@ class Q {
|
|
|
1891
1961
|
this.kernel.destroy();
|
|
1892
1962
|
}
|
|
1893
1963
|
}
|
|
1894
|
-
class
|
|
1964
|
+
class ee {
|
|
1895
1965
|
constructor(e = 0, t = 0) {
|
|
1896
1966
|
this.x = e, this.y = t, this.rotation = 0, this.scale = { x: 1, y: 1 }, this.components = [], this.children = [], this.parent = null, this._kernel = null;
|
|
1897
1967
|
}
|
|
@@ -1941,7 +2011,7 @@ class Z {
|
|
|
1941
2011
|
e.restore();
|
|
1942
2012
|
}
|
|
1943
2013
|
}
|
|
1944
|
-
class
|
|
2014
|
+
class C {
|
|
1945
2015
|
constructor(e = 0, t = 0) {
|
|
1946
2016
|
this.x = e, this.y = t;
|
|
1947
2017
|
}
|
|
@@ -1963,13 +2033,13 @@ class P {
|
|
|
1963
2033
|
return e > 0 && (this.x /= e, this.y /= e), this;
|
|
1964
2034
|
}
|
|
1965
2035
|
clone() {
|
|
1966
|
-
return new
|
|
2036
|
+
return new C(this.x, this.y);
|
|
1967
2037
|
}
|
|
1968
2038
|
static distance(e, t) {
|
|
1969
2039
|
return Math.sqrt(Math.pow(t.x - e.x, 2) + Math.pow(t.y - e.y, 2));
|
|
1970
2040
|
}
|
|
1971
2041
|
}
|
|
1972
|
-
class
|
|
2042
|
+
class F extends y {
|
|
1973
2043
|
constructor(e) {
|
|
1974
2044
|
super(), this.image = e, this.anchor = { x: 0.5, y: 0.5 }, this.width = e ? e.width : 0, this.height = e ? e.height : 0, this.frame = { x: 0, y: 0, w: this.width, h: this.height };
|
|
1975
2045
|
}
|
|
@@ -1997,12 +2067,12 @@ class j extends y {
|
|
|
1997
2067
|
);
|
|
1998
2068
|
}
|
|
1999
2069
|
}
|
|
2000
|
-
class
|
|
2070
|
+
class te extends y {
|
|
2001
2071
|
constructor() {
|
|
2002
2072
|
super(), this.animations = {}, this.currentAnim = null, this.timer = 0, this.currentFrameIndex = 0, this.sprite = null;
|
|
2003
2073
|
}
|
|
2004
2074
|
onAttach() {
|
|
2005
|
-
this.sprite = this.gameObject.getComponent(
|
|
2075
|
+
this.sprite = this.gameObject.getComponent(F), this.sprite || console.warn("Animator attached to GameObject without a Sprite component.");
|
|
2006
2076
|
}
|
|
2007
2077
|
addAnimation(e, t, s = 10, i = !0) {
|
|
2008
2078
|
this.animations[e] = { frames: t, fps: s, loop: i };
|
|
@@ -2021,7 +2091,7 @@ class ee extends y {
|
|
|
2021
2091
|
this.sprite.setFrame(e.x, e.y, e.w, e.h);
|
|
2022
2092
|
}
|
|
2023
2093
|
}
|
|
2024
|
-
class
|
|
2094
|
+
class se {
|
|
2025
2095
|
static createGround(e, t, s = "#333") {
|
|
2026
2096
|
const i = document.createElement("canvas");
|
|
2027
2097
|
i.width = e, i.height = t;
|
|
@@ -2045,15 +2115,15 @@ class te {
|
|
|
2045
2115
|
const n = r.getContext("2d");
|
|
2046
2116
|
for (let o = 0; o < 4; o++) {
|
|
2047
2117
|
const c = o * 64, h = 0, l = c + 64 / 2, u = h + 64 / 2, m = o % 2 === 0 ? 0 : -2, f = o === 1 ? 5 : o === 3 ? -5 : 0;
|
|
2048
|
-
n.fillStyle = e, n.beginPath(), n.arc(l, u + m, 20, 0, Math.PI * 2), n.fill(), n.fillStyle = t, n.beginPath(), n.arc(l - 15, u + m + f, 8, 0, Math.PI * 2), n.arc(l + 15, u + m - f, 8, 0, Math.PI * 2), n.fill(), n.fillStyle =
|
|
2118
|
+
n.fillStyle = e, n.beginPath(), n.arc(l, u + m, 20, 0, Math.PI * 2), n.fill(), n.fillStyle = t, n.beginPath(), n.arc(l - 15, u + m + f, 8, 0, Math.PI * 2), n.arc(l + 15, u + m - f, 8, 0, Math.PI * 2), n.fill(), n.fillStyle = N(e), n.beginPath(), n.arc(l, u + m, 15, 0, Math.PI * 2), n.fill(), t === "#333" && (n.fillStyle = "#000", n.fillRect(l + 10, u + m - 5, 25, 6));
|
|
2049
2119
|
}
|
|
2050
2120
|
return r;
|
|
2051
2121
|
}
|
|
2052
2122
|
}
|
|
2053
|
-
function
|
|
2123
|
+
function N(a, e) {
|
|
2054
2124
|
return a;
|
|
2055
2125
|
}
|
|
2056
|
-
class
|
|
2126
|
+
class ie extends y {
|
|
2057
2127
|
constructor(e) {
|
|
2058
2128
|
super(), this.system = e;
|
|
2059
2129
|
}
|
|
@@ -2094,7 +2164,7 @@ class se extends y {
|
|
|
2094
2164
|
}
|
|
2095
2165
|
}
|
|
2096
2166
|
}
|
|
2097
|
-
class
|
|
2167
|
+
class re extends y {
|
|
2098
2168
|
constructor() {
|
|
2099
2169
|
super(), this.intensity = 0, this.duration = 0, this.timer = 0, this.originalPos = { x: 0, y: 0 }, this.isShaking = !1;
|
|
2100
2170
|
}
|
|
@@ -2112,39 +2182,42 @@ class ie extends y {
|
|
|
2112
2182
|
}
|
|
2113
2183
|
}
|
|
2114
2184
|
export {
|
|
2115
|
-
|
|
2116
|
-
|
|
2185
|
+
te as Animator,
|
|
2186
|
+
$ as Collider,
|
|
2117
2187
|
y as Component,
|
|
2118
2188
|
A as DataService,
|
|
2119
|
-
|
|
2189
|
+
j as Director,
|
|
2120
2190
|
B as DopamineKernel,
|
|
2121
2191
|
p as EventBus,
|
|
2122
|
-
|
|
2123
|
-
Z as
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
K as
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
Y as
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
E as
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
R as
|
|
2192
|
+
D as EventEmitter,
|
|
2193
|
+
Z as Game,
|
|
2194
|
+
ee as GameObject,
|
|
2195
|
+
T as GameUI,
|
|
2196
|
+
K as GlobalInput,
|
|
2197
|
+
X as GlobalLoader,
|
|
2198
|
+
q as GlobalPhysics,
|
|
2199
|
+
Y as IAudioSystem,
|
|
2200
|
+
V as IParticleSystem,
|
|
2201
|
+
W as IPhysicsSystem,
|
|
2202
|
+
_ as ISystem,
|
|
2203
|
+
E as Input,
|
|
2204
|
+
P as Loader,
|
|
2205
|
+
ie as ParticleEmitter,
|
|
2206
|
+
I as ParticleSystem,
|
|
2207
|
+
M as Physics,
|
|
2208
|
+
R as PluginRegistry,
|
|
2209
|
+
z as Renderer,
|
|
2139
2210
|
O as RewardSystem,
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2211
|
+
Q as Scene,
|
|
2212
|
+
re as ScreenShake,
|
|
2213
|
+
L as SoundManager,
|
|
2214
|
+
F as Sprite,
|
|
2215
|
+
J as System,
|
|
2216
|
+
U as SystemRegistry,
|
|
2217
|
+
se as TextureGenerator,
|
|
2218
|
+
G as Ticker,
|
|
2219
|
+
C as Vector2,
|
|
2220
|
+
S as createMemoryStorage,
|
|
2221
|
+
H as default,
|
|
2222
|
+
b as resolveStorage
|
|
2150
2223
|
};
|