dopaminejs 2.4.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -50
- package/dist/DataService-E4pGQ1V3.cjs +1 -0
- package/dist/DataService-MfmvkqXR.js +737 -0
- package/dist/core.cjs +1 -0
- package/dist/core.js +2 -0
- package/dist/dopamine.cjs +1 -37
- package/dist/dopamine.js +3 -858
- package/dist/games.cjs +1 -0
- package/dist/games.js +82 -0
- package/dist/host-CkRL74ck.js +814 -0
- package/dist/host-Pzb-QBPU.cjs +37 -0
- package/dist/style.css +395 -2
- package/dist/testing.cjs +1 -0
- package/dist/testing.js +474 -0
- package/package.json +28 -8
- package/spec/README.md +227 -0
- package/spec/VERSION +1 -0
- package/spec/fixtures/achievements.json +611 -0
- package/spec/fixtures/levels.json +421 -0
- package/spec/fixtures/merge.json +1739 -0
- package/spec/fixtures/migrate.json +916 -0
- package/spec/fixtures/scores.json +755 -0
- package/spec/fixtures/streaks.json +924 -0
- package/spec/schema.json +61 -0
- package/src/dopamine/audio/SoundManager.js +78 -24
- package/src/dopamine/core/DataService.js +25 -5
- package/src/dopamine/core/DopamineError.js +7 -0
- package/src/dopamine/core/RewardSystem.js +366 -368
- package/src/dopamine/core/achievements.js +49 -0
- package/src/dopamine/core/clock.js +11 -0
- package/src/dopamine/core/levels.js +4 -0
- package/src/dopamine/core/merge.js +68 -0
- package/src/dopamine/core/middleware.js +58 -0
- package/src/dopamine/core/store.js +261 -0
- package/src/dopamine/core/streaks.js +55 -0
- package/src/dopamine/effects/ParticleSystem.js +33 -3
- package/src/dopamine/feel/haptics.js +21 -0
- package/src/dopamine/feel/motion.js +9 -0
- package/src/dopamine/host.js +358 -0
- package/src/dopamine/ui/RewardUI.js +569 -0
- package/src/games.js +138 -0
- package/src/index.js +14 -33
- package/src/progression.js +16 -0
- package/src/testing.js +489 -0
- package/types/core.d.ts +35 -0
- package/types/games.d.ts +46 -0
- package/types/index.d.ts +348 -373
- package/types/testing.d.ts +96 -0
- package/dist/ScreenShake-9jgNXPS6.cjs +0 -1
- package/dist/ScreenShake-CLvO1wx4.js +0 -827
- package/dist/engine.cjs +0 -1
- package/dist/engine.js +0 -2
- package/src/core/Animator.js +0 -62
- package/src/core/Collider.js +0 -86
- package/src/core/Component.js +0 -38
- package/src/core/DopamineKernel.js +0 -170
- package/src/core/EventBus.js +0 -206
- package/src/core/Game.js +0 -90
- package/src/core/GameObject.js +0 -99
- package/src/core/PluginRegistry.js +0 -359
- package/src/core/Scene.js +0 -107
- package/src/core/Sprite.js +0 -51
- package/src/core/SystemRegistry.js +0 -263
- package/src/core/Vector2.js +0 -50
- package/src/dopamine/components/ParticleEmitter.js +0 -50
- package/src/dopamine/components/ScreenShake.js +0 -50
- package/src/dopamine/components/index.js +0 -2
- package/src/dopamine/index.js +0 -93
- package/src/dopamine/ui/GameUI.js +0 -420
- package/src/dopamine/utils/TextureGenerator.js +0 -90
- package/src/engine.js +0 -38
- package/src/interfaces/IAudioSystem.js +0 -58
- package/src/interfaces/IParticleSystem.js +0 -51
- package/src/interfaces/IPhysicsSystem.js +0 -52
- package/src/interfaces/ISystem.js +0 -48
- package/src/interfaces/index.js +0 -7
- package/src/renderer/Renderer.js +0 -45
- package/src/systems/Director.js +0 -34
- package/src/systems/Input.js +0 -81
- package/src/systems/Loader.js +0 -48
- package/src/systems/Physics.js +0 -210
- package/src/systems/Ticker.js +0 -91
- package/src/systems/deprecate.js +0 -38
package/dist/dopamine.js
CHANGED
|
@@ -1,858 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
constructor() {
|
|
5
|
-
this.listeners = /* @__PURE__ */ new Map();
|
|
6
|
-
}
|
|
7
|
-
on(e, t) {
|
|
8
|
-
return this.listeners.has(e) || this.listeners.set(e, /* @__PURE__ */ new Set()), this.listeners.get(e).add(t), () => this.off(e, t);
|
|
9
|
-
}
|
|
10
|
-
off(e, t) {
|
|
11
|
-
this.listeners.has(e) && this.listeners.get(e).delete(t);
|
|
12
|
-
}
|
|
13
|
-
emit(e, t) {
|
|
14
|
-
this.listeners.has(e) && this.listeners.get(e).forEach((n) => {
|
|
15
|
-
try {
|
|
16
|
-
n(t);
|
|
17
|
-
} catch (t) {
|
|
18
|
-
console.error(`Error in listener for event '${e}':`, t);
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
clear() {
|
|
23
|
-
this.listeners.clear();
|
|
24
|
-
}
|
|
25
|
-
}, w = /* @__PURE__ */ new Set([
|
|
26
|
-
"__proto__",
|
|
27
|
-
"constructor",
|
|
28
|
-
"prototype"
|
|
29
|
-
]), T = (e) => typeof e == "string" && e.length > 0 && !w.has(e), E = (e, t) => Object.prototype.hasOwnProperty.call(e, t), D = (e) => typeof e == "object" && !!e && !Array.isArray(e), O = (e, t, n = 0) => {
|
|
30
|
-
let r = Number(e);
|
|
31
|
-
return Number.isInteger(r) && r >= n ? r : t;
|
|
32
|
-
}, k = class extends C {
|
|
33
|
-
constructor(e, t = {}) {
|
|
34
|
-
super(), this.dataService = e, this.player = null, this.achievements = {
|
|
35
|
-
...this._initAchievements(),
|
|
36
|
-
...t.achievements || {}
|
|
37
|
-
}, this.events = t.events || t.kernel?.events || null, this._batchDepth = 0, this._pendingSave = !1;
|
|
38
|
-
}
|
|
39
|
-
_publish(e, t) {
|
|
40
|
-
this.emit(e, t), this.events && this.events.emit(e, t);
|
|
41
|
-
}
|
|
42
|
-
async _batch(e) {
|
|
43
|
-
this._batchDepth++;
|
|
44
|
-
try {
|
|
45
|
-
return await e();
|
|
46
|
-
} finally {
|
|
47
|
-
this._batchDepth--, this._batchDepth === 0 && this._pendingSave && (this._pendingSave = !1, await this._write());
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
async init() {
|
|
51
|
-
let e = await this.dataService.load("player", null);
|
|
52
|
-
this.player = this._migrate(e);
|
|
53
|
-
let t = this._updateDailyStreak();
|
|
54
|
-
return await this.save(), t && this._publishStreak(), this.player;
|
|
55
|
-
}
|
|
56
|
-
_requirePlayer() {
|
|
57
|
-
if (!this.player) throw Error("[DopamineJS] RewardSystem.init() must be awaited before use");
|
|
58
|
-
}
|
|
59
|
-
_publishStreak() {
|
|
60
|
-
let { current: e, longest: t } = this.player.streak;
|
|
61
|
-
this._publish("streak_updated", {
|
|
62
|
-
current: e,
|
|
63
|
-
longest: t
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
_getDefaultPlayer() {
|
|
67
|
-
return {
|
|
68
|
-
name: "Player",
|
|
69
|
-
xp: 0,
|
|
70
|
-
level: 1,
|
|
71
|
-
totalGamesPlayed: 0,
|
|
72
|
-
createdAt: Date.now(),
|
|
73
|
-
lastPlayedAt: Date.now(),
|
|
74
|
-
streak: {
|
|
75
|
-
current: 1,
|
|
76
|
-
longest: 1,
|
|
77
|
-
lastPlayDate: this._getTodayDateString()
|
|
78
|
-
},
|
|
79
|
-
achievements: {},
|
|
80
|
-
stats: {}
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
_migrate(e) {
|
|
84
|
-
let t = this._getDefaultPlayer();
|
|
85
|
-
if (!D(e)) return t;
|
|
86
|
-
let n = Number(e.xp), r = Number.isFinite(n) && n >= 0 ? n : 0, i = this._calculateLevel(r), a = D(e.streak) ? e.streak : {}, o = O(a.current, 1, 1), s = typeof a.lastPlayDate == "string" && /^\d{4}-\d{2}-\d{2}$/.test(a.lastPlayDate) ? a.lastPlayDate : t.streak.lastPlayDate;
|
|
87
|
-
return {
|
|
88
|
-
...t,
|
|
89
|
-
...e,
|
|
90
|
-
name: typeof e.name == "string" ? e.name : t.name,
|
|
91
|
-
xp: r,
|
|
92
|
-
level: Math.max(i, O(e.level, i, 1)),
|
|
93
|
-
totalGamesPlayed: O(e.totalGamesPlayed, 0),
|
|
94
|
-
createdAt: Number.isFinite(e.createdAt) ? e.createdAt : t.createdAt,
|
|
95
|
-
lastPlayedAt: Number.isFinite(e.lastPlayedAt) ? e.lastPlayedAt : t.lastPlayedAt,
|
|
96
|
-
streak: {
|
|
97
|
-
current: o,
|
|
98
|
-
longest: Math.max(o, O(a.longest, o, 1)),
|
|
99
|
-
lastPlayDate: s
|
|
100
|
-
},
|
|
101
|
-
achievements: this._migrateAchievements(e.achievements),
|
|
102
|
-
stats: this._migrateStats(e.stats)
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
_migrateAchievements(e) {
|
|
106
|
-
let t = {};
|
|
107
|
-
if (!D(e)) return t;
|
|
108
|
-
for (let n of Object.keys(e)) {
|
|
109
|
-
let r = e[n];
|
|
110
|
-
T(n) && D(r) && (t[n] = {
|
|
111
|
-
unlockedAt: Number.isFinite(r.unlockedAt) ? r.unlockedAt : Date.now(),
|
|
112
|
-
seen: r.seen === !0
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
return t;
|
|
116
|
-
}
|
|
117
|
-
_migrateStats(e) {
|
|
118
|
-
let t = {};
|
|
119
|
-
if (!D(e)) return t;
|
|
120
|
-
for (let n of Object.keys(e)) {
|
|
121
|
-
let r = e[n];
|
|
122
|
-
if (!T(n) || !D(r)) continue;
|
|
123
|
-
let i = {};
|
|
124
|
-
for (let e of Object.keys(r)) T(e) && Number.isFinite(r[e]) && (i[e] = r[e]);
|
|
125
|
-
i.totalPlays = O(r.totalPlays, 0), i.highScore = Number.isFinite(r.highScore) ? r.highScore : 0, t[n] = i;
|
|
126
|
-
}
|
|
127
|
-
return t;
|
|
128
|
-
}
|
|
129
|
-
async save() {
|
|
130
|
-
if (this.player) {
|
|
131
|
-
if (this._batchDepth > 0) {
|
|
132
|
-
this._pendingSave = !0;
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
await this._write();
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
async _write() {
|
|
139
|
-
this.player.lastPlayedAt = Date.now(), await this.dataService.save("player", this.player) === !1 && this._publish("save_failed", { key: "player" });
|
|
140
|
-
}
|
|
141
|
-
async addXP(e, t = "") {
|
|
142
|
-
if (!Number.isFinite(e)) throw TypeError(`[DopamineJS] addXP expects a finite number, received ${e}`);
|
|
143
|
-
this._requirePlayer();
|
|
144
|
-
let n = this.player.level;
|
|
145
|
-
e = Math.max(e, -this.player.xp), this.player.xp += e;
|
|
146
|
-
let r = Math.max(n, this._calculateLevel(this.player.xp)), i = r > n;
|
|
147
|
-
i && (this.player.level = r), await this.save();
|
|
148
|
-
let a = this.player.xp;
|
|
149
|
-
return this._publish("xp_gained", {
|
|
150
|
-
amount: e,
|
|
151
|
-
reason: t,
|
|
152
|
-
leveledUp: i,
|
|
153
|
-
newLevel: r,
|
|
154
|
-
total: a
|
|
155
|
-
}), i && this._publish("level_up", {
|
|
156
|
-
oldLevel: n,
|
|
157
|
-
newLevel: r,
|
|
158
|
-
totalXP: a
|
|
159
|
-
}), {
|
|
160
|
-
leveledUp: i,
|
|
161
|
-
newLevel: r,
|
|
162
|
-
xpGained: e
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
_calculateLevel(e) {
|
|
166
|
-
if (!(e > 0)) return 1;
|
|
167
|
-
let t = Math.floor((1 + Math.sqrt(1 + 4 * e / 50)) / 2);
|
|
168
|
-
return Math.max(1, t);
|
|
169
|
-
}
|
|
170
|
-
getXPForNextLevel() {
|
|
171
|
-
this._requirePlayer();
|
|
172
|
-
let e = this.player.level + 1, t = 50 * e * (e - 1), n = 50 * this.player.level * (this.player.level - 1), r = t - n, i = r > 0 ? Math.max(0, Math.min(1, (this.player.xp - n) / r)) : 0;
|
|
173
|
-
return {
|
|
174
|
-
total: t,
|
|
175
|
-
needed: Math.max(0, t - this.player.xp),
|
|
176
|
-
progress: i
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
async recordGame(e, t = {}) {
|
|
180
|
-
if (this._requirePlayer(), !T(e)) throw TypeError(`[DopamineJS] recordGame expects a game name, received ${String(e)}`);
|
|
181
|
-
if (!D(t)) throw TypeError("[DopamineJS] recordGame expects a result object");
|
|
182
|
-
if (t.score !== void 0 && !Number.isFinite(t.score)) throw TypeError(`[DopamineJS] recordGame expects a finite score, received ${String(t.score)}`);
|
|
183
|
-
return this._batch(() => this._recordGame(e, t));
|
|
184
|
-
}
|
|
185
|
-
async _recordGame(e, t) {
|
|
186
|
-
this._updateDailyStreak() && this._publishStreak(), E(this.player.stats, e) || (this.player.stats[e] = {
|
|
187
|
-
totalPlays: 0,
|
|
188
|
-
highScore: 0
|
|
189
|
-
});
|
|
190
|
-
let n = this.player.stats[e];
|
|
191
|
-
n.totalPlays++, this.player.totalGamesPlayed++, t.score !== void 0 && t.score > n.highScore && (n.highScore = t.score, this._publish("new_high_score", {
|
|
192
|
-
gameName: e,
|
|
193
|
-
score: t.score
|
|
194
|
-
})), Object.keys(t).forEach((e) => {
|
|
195
|
-
if (e !== "score" && T(e)) {
|
|
196
|
-
let r = E(n, e) && Number.isFinite(n[e]) ? n[e] : 0;
|
|
197
|
-
n[e] = r + (Number.isFinite(t[e]) ? t[e] : 0);
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
let r = 10;
|
|
201
|
-
t.score && (r += Math.max(0, Math.floor(t.score / 5))), r = Math.floor(r * this.getStreakMultiplier()), await this.addXP(r, `Played ${e}`), await this.checkAchievements(e, t), await this.save();
|
|
202
|
-
}
|
|
203
|
-
async checkAchievements(e, t) {
|
|
204
|
-
let n = [];
|
|
205
|
-
for (let [r, i] of Object.entries(this.achievements)) {
|
|
206
|
-
if (E(this.player.achievements, r)) continue;
|
|
207
|
-
let a = !1;
|
|
208
|
-
try {
|
|
209
|
-
a = i.check(this.player, e, t);
|
|
210
|
-
} catch (e) {
|
|
211
|
-
console.error(`[DopamineJS] Achievement "${r}" check threw:`, e);
|
|
212
|
-
continue;
|
|
213
|
-
}
|
|
214
|
-
a && await this.unlockAchievement(r) && n.push(i);
|
|
215
|
-
}
|
|
216
|
-
return n;
|
|
217
|
-
}
|
|
218
|
-
async unlockAchievement(e) {
|
|
219
|
-
if (this._requirePlayer(), !T(e) || !E(this.achievements, e) || E(this.player.achievements, e)) return !1;
|
|
220
|
-
let t = this.achievements[e];
|
|
221
|
-
return t ? (this.player.achievements[e] = {
|
|
222
|
-
unlockedAt: Date.now(),
|
|
223
|
-
seen: !1
|
|
224
|
-
}, await this.addXP(Number.isFinite(t.xp) ? t.xp : 0, `Achievement: ${t.name}`), this._publish("achievement_unlocked", {
|
|
225
|
-
...t,
|
|
226
|
-
id: e
|
|
227
|
-
}), await this.save(), !0) : !1;
|
|
228
|
-
}
|
|
229
|
-
getUnlockedAchievements() {
|
|
230
|
-
return Object.entries(this.player.achievements).map(([e, t]) => ({
|
|
231
|
-
...this.achievements[e],
|
|
232
|
-
id: e,
|
|
233
|
-
...t
|
|
234
|
-
}));
|
|
235
|
-
}
|
|
236
|
-
getUnseenAchievements() {
|
|
237
|
-
return this.getUnlockedAchievements().filter((e) => !e.seen);
|
|
238
|
-
}
|
|
239
|
-
async markAchievementsSeen(e) {
|
|
240
|
-
for (let t of e) E(this.player.achievements, t) && (this.player.achievements[t].seen = !0);
|
|
241
|
-
await this.save();
|
|
242
|
-
}
|
|
243
|
-
_updateDailyStreak() {
|
|
244
|
-
let e = this._getTodayDateString(), t = this.player.streak.lastPlayDate;
|
|
245
|
-
return t !== e && (t === this._getYesterdayDateString() ? (this.player.streak.current++, this.player.streak.current > this.player.streak.longest && (this.player.streak.longest = this.player.streak.current)) : this.player.streak.current = 1, this.player.streak.lastPlayDate = e, !0);
|
|
246
|
-
}
|
|
247
|
-
getStreakMultiplier() {
|
|
248
|
-
let e = this.player.streak.current;
|
|
249
|
-
return e >= 7 ? 2 : e >= 5 ? 1.5 : e >= 3 ? 1.25 : 1;
|
|
250
|
-
}
|
|
251
|
-
_toLocalDateString(e) {
|
|
252
|
-
return `${e.getFullYear()}-${String(e.getMonth() + 1).padStart(2, "0")}-${String(e.getDate()).padStart(2, "0")}`;
|
|
253
|
-
}
|
|
254
|
-
_getTodayDateString() {
|
|
255
|
-
return this._toLocalDateString(/* @__PURE__ */ new Date());
|
|
256
|
-
}
|
|
257
|
-
_getYesterdayDateString() {
|
|
258
|
-
let e = /* @__PURE__ */ new Date();
|
|
259
|
-
return e.setDate(e.getDate() - 1), this._toLocalDateString(e);
|
|
260
|
-
}
|
|
261
|
-
_initAchievements() {
|
|
262
|
-
return {
|
|
263
|
-
first_game: {
|
|
264
|
-
name: "First Steps",
|
|
265
|
-
description: "Play your first game",
|
|
266
|
-
icon: "🎮",
|
|
267
|
-
xp: 50,
|
|
268
|
-
check: (e) => e.totalGamesPlayed >= 1
|
|
269
|
-
},
|
|
270
|
-
level_5: {
|
|
271
|
-
name: "Rising Star",
|
|
272
|
-
description: "Reach level 5",
|
|
273
|
-
icon: "⭐",
|
|
274
|
-
xp: 100,
|
|
275
|
-
check: (e) => e.level >= 5
|
|
276
|
-
},
|
|
277
|
-
level_10: {
|
|
278
|
-
name: "Expert Player",
|
|
279
|
-
description: "Reach level 10",
|
|
280
|
-
icon: "🏆",
|
|
281
|
-
xp: 250,
|
|
282
|
-
check: (e) => e.level >= 10
|
|
283
|
-
},
|
|
284
|
-
streak_3: {
|
|
285
|
-
name: "Dedicated",
|
|
286
|
-
description: "Play 3 days in a row",
|
|
287
|
-
icon: "🔥",
|
|
288
|
-
xp: 100,
|
|
289
|
-
check: (e) => e.streak.current >= 3
|
|
290
|
-
},
|
|
291
|
-
streak_7: {
|
|
292
|
-
name: "Unstoppable",
|
|
293
|
-
description: "Play 7 days in a row",
|
|
294
|
-
icon: "💥",
|
|
295
|
-
xp: 300,
|
|
296
|
-
check: (e) => e.streak.current >= 7
|
|
297
|
-
}
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
};
|
|
301
|
-
//#endregion
|
|
302
|
-
//#region src/dopamine/utils/storage.js
|
|
303
|
-
function A() {
|
|
304
|
-
let e = /* @__PURE__ */ new Map();
|
|
305
|
-
return {
|
|
306
|
-
getItem: (t) => e.has(t) ? e.get(t) : null,
|
|
307
|
-
setItem: (t, n) => {
|
|
308
|
-
e.set(t, String(n));
|
|
309
|
-
},
|
|
310
|
-
removeItem: (t) => {
|
|
311
|
-
e.delete(t);
|
|
312
|
-
},
|
|
313
|
-
clear: () => {
|
|
314
|
-
e.clear();
|
|
315
|
-
}
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
function j() {
|
|
319
|
-
try {
|
|
320
|
-
if (typeof localStorage > "u") return A();
|
|
321
|
-
let e = "__dopamine_probe__";
|
|
322
|
-
return localStorage.setItem(e, "1"), localStorage.removeItem(e), localStorage;
|
|
323
|
-
} catch {
|
|
324
|
-
return A();
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
//#endregion
|
|
328
|
-
//#region src/dopamine/core/DataService.js
|
|
329
|
-
var M = class {
|
|
330
|
-
constructor(e = {}) {
|
|
331
|
-
this.storage = e.storage || j(), this.prefix = e.prefix || "dopamine_", this._tail = null;
|
|
332
|
-
}
|
|
333
|
-
_write(e) {
|
|
334
|
-
let t = this._tail ? this._tail.then(e) : e();
|
|
335
|
-
if (typeof t?.then == "function") {
|
|
336
|
-
let e = Promise.resolve(t).catch(() => {}).then(() => {
|
|
337
|
-
this._tail === e && (this._tail = null);
|
|
338
|
-
});
|
|
339
|
-
this._tail = e;
|
|
340
|
-
}
|
|
341
|
-
return t;
|
|
342
|
-
}
|
|
343
|
-
async save(e, t) {
|
|
344
|
-
try {
|
|
345
|
-
let n = JSON.stringify(t);
|
|
346
|
-
return await this._write(() => this.storage.setItem(this.prefix + e, n)), !0;
|
|
347
|
-
} catch (e) {
|
|
348
|
-
return console.error("Error saving data:", e), !1;
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
async load(e, t = null) {
|
|
352
|
-
try {
|
|
353
|
-
await this._tail;
|
|
354
|
-
let n = await this.storage.getItem(this.prefix + e);
|
|
355
|
-
return n ? JSON.parse(n) : t;
|
|
356
|
-
} catch (e) {
|
|
357
|
-
return console.error("Error loading data:", e), t;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
async clear(e) {
|
|
361
|
-
await this._write(() => this.storage.removeItem(this.prefix + e));
|
|
362
|
-
}
|
|
363
|
-
}, N = "game-ui-overlay", P = class {
|
|
364
|
-
constructor(e) {
|
|
365
|
-
this.particleSystem = e, this.container = null, this.xpBar = null, this.levelDisplay = null, this.streakDisplay = null, this._timers = /* @__PURE__ */ new Set(), this._detached = [], this.init();
|
|
366
|
-
}
|
|
367
|
-
init() {
|
|
368
|
-
this.container = document.createElement("div"), this.container.className = "game-ui-overlay", document.getElementById(N) || (this.container.id = N), this.container.innerHTML = "\n <div class=\"game-ui-top-bar\">\n <div class=\"level-badge\">\n <span class=\"level-label\">LVL</span>\n <span class=\"level-number\">1</span>\n </div>\n\n <div class=\"xp-container\">\n <div class=\"xp-bar-bg\">\n <div class=\"xp-bar-fill\" style=\"width: 0%\"></div>\n </div>\n <div class=\"xp-text\">0 / 100 XP</div>\n </div>\n\n <div class=\"streak-badge\">\n <span class=\"streak-icon\">🔥</span>\n <span class=\"streak-number\">1</span>\n </div>\n </div>\n ", this.liveRegion = document.createElement("div"), this.liveRegion.className = "dopamine-live-region", this.liveRegion.setAttribute("aria-live", "polite"), this.liveRegion.setAttribute("role", "status"), Object.assign(this.liveRegion.style, {
|
|
369
|
-
position: "absolute",
|
|
370
|
-
width: "1px",
|
|
371
|
-
height: "1px",
|
|
372
|
-
overflow: "hidden",
|
|
373
|
-
clipPath: "inset(50%)",
|
|
374
|
-
whiteSpace: "nowrap"
|
|
375
|
-
}), this.container.appendChild(this.liveRegion), document.body.appendChild(this.container), this.levelBadge = this.container.querySelector(".level-badge"), this.streakBadge = this.container.querySelector(".streak-badge"), this.xpBar = this.container.querySelector(".xp-bar-fill"), this.xpText = this.container.querySelector(".xp-text"), this.levelDisplay = this.container.querySelector(".level-number"), this.streakDisplay = this.container.querySelector(".streak-number");
|
|
376
|
-
}
|
|
377
|
-
_defer(e, t) {
|
|
378
|
-
let n = setTimeout(() => {
|
|
379
|
-
this._timers.delete(n), e();
|
|
380
|
-
}, t);
|
|
381
|
-
return this._timers.add(n), n;
|
|
382
|
-
}
|
|
383
|
-
_mount(e) {
|
|
384
|
-
return document.body.appendChild(e), this._detached.push(e), e;
|
|
385
|
-
}
|
|
386
|
-
_announce(e) {
|
|
387
|
-
this.liveRegion && (this.liveRegion.textContent = e);
|
|
388
|
-
}
|
|
389
|
-
_replayAnimation(e, t) {
|
|
390
|
-
e && (e.style.animation = "none", this._defer(() => {
|
|
391
|
-
e.style.animation = t;
|
|
392
|
-
}, 10));
|
|
393
|
-
}
|
|
394
|
-
updateXP(e, t, n, r) {
|
|
395
|
-
let i = Number.isFinite(r) ? r : n > 0 ? e / n : 0;
|
|
396
|
-
this.xpBar.style.width = `${Math.max(0, Math.min(100, i * 100))}%`, this.xpText.textContent = `${e} / ${n} XP`, this._replayAnimation(this.xpBar, "xp-pulse 0.3s ease-out");
|
|
397
|
-
}
|
|
398
|
-
updateLevel(e) {
|
|
399
|
-
this.levelDisplay.textContent = e, this._replayAnimation(this.levelBadge, "level-pulse 0.5s ease-out");
|
|
400
|
-
}
|
|
401
|
-
updateStreak(e) {
|
|
402
|
-
this.streakDisplay.textContent = e, e >= 7 ? this.streakBadge.style.background = "linear-gradient(135deg, #ff6b00 0%, #ff4400 100%)" : e >= 3 ? this.streakBadge.style.background = "linear-gradient(135deg, #ff8800 0%, #ff6b00 100%)" : this.streakBadge.style.background = "";
|
|
403
|
-
}
|
|
404
|
-
showAchievement(e) {
|
|
405
|
-
let t = document.createElement("div");
|
|
406
|
-
t.className = "achievement-popup", t.innerHTML = "\n <div class=\"achievement-shine\"></div>\n <div class=\"achievement-content\">\n <div class=\"achievement-icon\"></div>\n <div class=\"achievement-info\">\n <div class=\"achievement-title\">Achievement Unlocked!</div>\n <div class=\"achievement-name\"></div>\n <div class=\"achievement-desc\"></div>\n <div class=\"achievement-xp\"></div>\n </div>\n </div>\n ", t.querySelector(".achievement-icon").innerHTML = e.icon ?? "", t.querySelector(".achievement-name").textContent = e.name ?? "", t.querySelector(".achievement-desc").textContent = e.description ?? "", t.querySelector(".achievement-xp").textContent = `+${e.xp ?? 0} XP`, this._mount(t), this._announce(`Achievement unlocked: ${e.name ?? ""}`), this._defer(() => {
|
|
407
|
-
let e = t.getBoundingClientRect();
|
|
408
|
-
this.particleSystem.confetti(e.left + e.width / 2, e.top + e.height / 2, 40);
|
|
409
|
-
}, 300), this._defer(() => {
|
|
410
|
-
t.style.animation = "slideOut 0.3s ease-in forwards", this._defer(() => this._remove(t), 300);
|
|
411
|
-
}, 4e3);
|
|
412
|
-
}
|
|
413
|
-
showLevelUp(e, t) {
|
|
414
|
-
let n = document.createElement("div");
|
|
415
|
-
n.className = "level-up-overlay", n.innerHTML = "\n <div class=\"level-up-content\">\n <div class=\"level-up-title\">LEVEL UP!</div>\n <div class=\"level-up-number\"></div>\n <div class=\"level-up-subtitle\">Amazing progress!</div>\n </div>\n ", n.querySelector(".level-up-number").textContent = t, this._mount(n), this._announce(`Level up: ${t}`), this._defer(() => {
|
|
416
|
-
for (let e = 0; e < 5; e++) this._defer(() => {
|
|
417
|
-
let e = Math.random() * window.innerWidth, t = Math.random() * window.innerHeight * .6;
|
|
418
|
-
this.particleSystem.confetti(e, t, 30);
|
|
419
|
-
}, e * 200);
|
|
420
|
-
}, 300), this._defer(() => {
|
|
421
|
-
n.style.opacity = "0", this._defer(() => this._remove(n), 500);
|
|
422
|
-
}, 2500);
|
|
423
|
-
}
|
|
424
|
-
showFloatingText(e, t, n, r = "#ffd700", i = "24px") {
|
|
425
|
-
let a = document.createElement("div");
|
|
426
|
-
a.className = "floating-text", a.textContent = e, a.style.left = t + "px", a.style.top = n + "px", a.style.color = r, a.style.fontSize = i, this._mount(a), this._defer(() => this._remove(a), 2e3);
|
|
427
|
-
}
|
|
428
|
-
showCombo(e, t, n) {
|
|
429
|
-
this.showFloatingText(`${e}× COMBO!`, t, n, "#ff6b6b", "32px"), this.particleSystem.fire(t, n, 20);
|
|
430
|
-
}
|
|
431
|
-
showNearMiss(e, t) {
|
|
432
|
-
this.showFloatingText("CLOSE CALL!", e, t, "#45b7d1", "20px"), this.particleSystem.sparkle(e, t, 15, "#45b7d1");
|
|
433
|
-
}
|
|
434
|
-
showLuckyMoment(e, t, n) {
|
|
435
|
-
this.showFloatingText(`LUCKY ${e}×!`, t, n, "#ffd700", "36px"), this.particleSystem.starBurst(t, n, 12), this.particleSystem.confetti(t, n, 25);
|
|
436
|
-
}
|
|
437
|
-
showNotification(e, t = "normal") {
|
|
438
|
-
let n = window.innerWidth / 2, r = window.innerHeight / 3;
|
|
439
|
-
t === "legendary" ? (this.showFloatingText(e, n, r, "#ffd700", "36px"), this.particleSystem.starBurst(n, r, 12), this.particleSystem.confetti(n, r, 25)) : t === "rare" ? (this.showFloatingText(e, n, r, "#ff6b6b", "32px"), this.particleSystem.fire(n, r, 20)) : this.showFloatingText(e, n, r, "#fff", "24px"), this._announce(e);
|
|
440
|
-
}
|
|
441
|
-
showSummary(e) {
|
|
442
|
-
let t = document.createElement("div");
|
|
443
|
-
t.className = "message-box", t.style.display = "flex", t.style.position = "absolute", t.style.top = "50%", t.style.left = "50%", t.style.transform = "translate(-50%, -50%)", t.style.zIndex = "1000";
|
|
444
|
-
let n = document.createElement("h1");
|
|
445
|
-
n.textContent = "Game Over";
|
|
446
|
-
let r = document.createElement("div");
|
|
447
|
-
r.className = "summary-score", r.style.cssText = "font-size: 3rem; font-weight: bold; color: #e06020; margin: 10px 0;", r.textContent = e.score;
|
|
448
|
-
let i = document.createElement("div");
|
|
449
|
-
i.className = "summary-metrics", i.style.cssText = "width: 100%; margin-bottom: 20px;";
|
|
450
|
-
for (let [t, n] of Object.entries(e.metrics || {})) {
|
|
451
|
-
let e = document.createElement("div");
|
|
452
|
-
e.style.cssText = "display:flex;justify-content:space-between;width:100%";
|
|
453
|
-
let r = document.createElement("span");
|
|
454
|
-
r.textContent = `${t}:`;
|
|
455
|
-
let a = document.createElement("strong");
|
|
456
|
-
a.textContent = n, e.append(r, a), i.appendChild(e);
|
|
457
|
-
}
|
|
458
|
-
t.append(n, r, i);
|
|
459
|
-
let a = document.createElement("button");
|
|
460
|
-
if (a.className = "btn", a.textContent = "Play Again", a.addEventListener("click", e.onReplay || (() => window.location.reload())), t.appendChild(a), e.onExit) {
|
|
461
|
-
let n = document.createElement("button");
|
|
462
|
-
n.className = "btn", n.textContent = "Exit", n.style.cssText = "margin-top: 10px; background: #543847;", n.addEventListener("click", e.onExit), t.appendChild(n);
|
|
463
|
-
}
|
|
464
|
-
return this._mount(t), t;
|
|
465
|
-
}
|
|
466
|
-
_remove(e) {
|
|
467
|
-
e.remove();
|
|
468
|
-
let t = this._detached.indexOf(e);
|
|
469
|
-
t > -1 && this._detached.splice(t, 1);
|
|
470
|
-
}
|
|
471
|
-
destroy() {
|
|
472
|
-
for (let e of this._timers) clearTimeout(e);
|
|
473
|
-
this._timers.clear();
|
|
474
|
-
for (let e of this._detached) e.remove();
|
|
475
|
-
this._detached = [], this.container?.remove(), this.container = null, this.liveRegion = null, this.xpBar = null, this.xpText = null, this.levelBadge = null, this.streakBadge = null, this.levelDisplay = null, this.streakDisplay = null;
|
|
476
|
-
}
|
|
477
|
-
}, F = class {
|
|
478
|
-
constructor(e = {}) {
|
|
479
|
-
this.container = e.container ? typeof e.container == "string" ? document.querySelector(e.container) : e.container : document.body, this.container ||= (console.warn(`[DopamineJS] Particle container '${e.container}' not found. Using document.body.`), document.body), this.maxParticles = Number.isFinite(e.maxParticles) ? Math.max(0, Math.floor(e.maxParticles)) : 5e3, this._reducedMotion = e.respectReducedMotion !== !1 && typeof window.matchMedia == "function" ? window.matchMedia("(prefers-reduced-motion: reduce)") : null, 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._lastFrameTime = 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);
|
|
480
|
-
}
|
|
481
|
-
_resize() {
|
|
482
|
-
let e = this.container === document.body ? window.innerWidth : this.container.clientWidth, t = this.container === document.body ? window.innerHeight : this.container.clientHeight, n = window.devicePixelRatio || 1;
|
|
483
|
-
this.width = e, this.height = t, this.canvas.width = Math.round(e * n), this.canvas.height = Math.round(t * n), this.canvas.style.width = `${e}px`, this.canvas.style.height = `${t}px`, this.ctx.setTransform(n, 0, 0, n, 0, 0);
|
|
484
|
-
}
|
|
485
|
-
registerSprite(e, t) {
|
|
486
|
-
let n = new Image();
|
|
487
|
-
n.src = t, this.sprites.set(e, n);
|
|
488
|
-
}
|
|
489
|
-
registerEffect(e, t) {
|
|
490
|
-
this.customEffects.set(e, t);
|
|
491
|
-
}
|
|
492
|
-
play(e, t, n, ...r) {
|
|
493
|
-
let i = this.customEffects.get(e);
|
|
494
|
-
i ? i(t, n, ...r) : console.warn(`[DopamineJS] Effect '${e}' not found.`);
|
|
495
|
-
}
|
|
496
|
-
emit(e) {
|
|
497
|
-
let { x: t, y: n, count: r = 10, speed: i = 5, gravity: a = .1, decay: o = .02, life: s = 1, color: c = "#ffd700", sprite: l = null, spread: u = Math.PI * 2, angle: d = 0, size: f = 5, type: p = null } = e, m = this._allowed(r);
|
|
498
|
-
for (let e = 0; e < m; e++) {
|
|
499
|
-
let e = this._getParticle(), r = d + (Math.random() - .5) * u, m = Math.random() * i;
|
|
500
|
-
e.x = t, e.y = n, e.vx = Math.cos(r) * m, e.vy = Math.sin(r) * m, e.life = s, e.decay = o * (.8 + Math.random() * .4), e.gravity = a, e.color = Array.isArray(c) ? c[Math.floor(Math.random() * c.length)] : c, e.size = f * (.8 + Math.random() * .4), e.sprite = l, e.type = p, e.rotation = Math.random() * Math.PI * 2, e.rotationSpeed = (Math.random() - .5) * .2, this.particles.push(e);
|
|
501
|
-
}
|
|
502
|
-
m > 0 && this._startAnimation();
|
|
503
|
-
}
|
|
504
|
-
_allowed(e) {
|
|
505
|
-
if (this._reducedMotion?.matches || !Number.isFinite(e)) return 0;
|
|
506
|
-
let t = this.maxParticles - this.particles.length;
|
|
507
|
-
return Math.max(0, Math.min(Math.floor(e), t));
|
|
508
|
-
}
|
|
509
|
-
_getParticle() {
|
|
510
|
-
return this.pool.length > 0 ? this.pool.pop() : {};
|
|
511
|
-
}
|
|
512
|
-
_recycleParticle(e) {
|
|
513
|
-
this.pool.push(e);
|
|
514
|
-
}
|
|
515
|
-
confetti(e, t, n = 50) {
|
|
516
|
-
this.emit({
|
|
517
|
-
x: e,
|
|
518
|
-
y: t,
|
|
519
|
-
count: n,
|
|
520
|
-
color: [
|
|
521
|
-
"#ff6b6b",
|
|
522
|
-
"#4ecdc4",
|
|
523
|
-
"#45b7d1",
|
|
524
|
-
"#f7dc6f",
|
|
525
|
-
"#c06c84",
|
|
526
|
-
"#6c5ce7"
|
|
527
|
-
],
|
|
528
|
-
speed: 10,
|
|
529
|
-
gravity: .3,
|
|
530
|
-
decay: .015,
|
|
531
|
-
size: 8,
|
|
532
|
-
spread: Math.PI * 2
|
|
533
|
-
});
|
|
534
|
-
}
|
|
535
|
-
coinShower(e, t, n = 10) {
|
|
536
|
-
this.emit({
|
|
537
|
-
x: e,
|
|
538
|
-
y: t,
|
|
539
|
-
count: n,
|
|
540
|
-
color: "#ffd700",
|
|
541
|
-
speed: 4,
|
|
542
|
-
gravity: .4,
|
|
543
|
-
decay: .012,
|
|
544
|
-
size: 12,
|
|
545
|
-
angle: -Math.PI / 2,
|
|
546
|
-
spread: Math.PI / 2
|
|
547
|
-
});
|
|
548
|
-
}
|
|
549
|
-
sparkle(e, t, n = 20, r = "#ffd700") {
|
|
550
|
-
this.emit({
|
|
551
|
-
x: e,
|
|
552
|
-
y: t,
|
|
553
|
-
count: n,
|
|
554
|
-
color: r,
|
|
555
|
-
speed: 3,
|
|
556
|
-
gravity: -.05,
|
|
557
|
-
decay: .03,
|
|
558
|
-
size: 3
|
|
559
|
-
});
|
|
560
|
-
}
|
|
561
|
-
fire(e, t, n = 15) {
|
|
562
|
-
this.emit({
|
|
563
|
-
x: e,
|
|
564
|
-
y: t,
|
|
565
|
-
count: n,
|
|
566
|
-
color: [
|
|
567
|
-
"#ff6b00",
|
|
568
|
-
"#ff8800",
|
|
569
|
-
"#ffaa00",
|
|
570
|
-
"#ff4400"
|
|
571
|
-
],
|
|
572
|
-
speed: 3,
|
|
573
|
-
gravity: -.2,
|
|
574
|
-
decay: .04,
|
|
575
|
-
size: 5,
|
|
576
|
-
angle: -Math.PI / 2,
|
|
577
|
-
spread: Math.PI / 4
|
|
578
|
-
});
|
|
579
|
-
}
|
|
580
|
-
starBurst(e, t, n = 8) {
|
|
581
|
-
let r = this._allowed(n);
|
|
582
|
-
for (let n = 0; n < r; n++) {
|
|
583
|
-
let i = this._getParticle(), a = Math.PI * 2 / r * n;
|
|
584
|
-
i.x = e, i.y = t, i.vx = Math.cos(a) * 4, i.vy = Math.sin(a) * 4, i.life = 1, i.decay = .03, i.gravity = 0, i.color = "#ffffff", i.size = 15, i.sprite = null, i.type = "star", i.rotation = a, i.rotationSpeed = 0, this.particles.push(i);
|
|
585
|
-
}
|
|
586
|
-
r > 0 && this._startAnimation();
|
|
587
|
-
}
|
|
588
|
-
_startAnimation() {
|
|
589
|
-
this.isAnimating || (this.isAnimating = !0, this._lastFrameTime = null, this._animate());
|
|
590
|
-
}
|
|
591
|
-
_animate(e) {
|
|
592
|
-
this._frameHandle = null, this.ctx.clearRect(0, 0, this.width, this.height);
|
|
593
|
-
let t = 1;
|
|
594
|
-
Number.isFinite(e) && (this._lastFrameTime !== null && (t = Math.max(0, Math.min(3, (e - this._lastFrameTime) / (1e3 / 60)))), this._lastFrameTime = e);
|
|
595
|
-
for (let e = this.particles.length - 1; e >= 0; e--) {
|
|
596
|
-
let n = this.particles[e];
|
|
597
|
-
if (n.vy += n.gravity * t, n.x += n.vx * t, n.y += n.vy * t, n.life -= n.decay * t, n.rotationSpeed && (n.rotation += n.rotationSpeed * t), n.life <= 0) {
|
|
598
|
-
this._recycleParticle(n);
|
|
599
|
-
let t = this.particles.pop();
|
|
600
|
-
e < this.particles.length && (this.particles[e] = t);
|
|
601
|
-
continue;
|
|
602
|
-
}
|
|
603
|
-
if (this.ctx.save(), this.ctx.globalAlpha = n.life, this.ctx.translate(n.x, n.y), this.ctx.rotate(n.rotation), n.sprite && this.sprites.has(n.sprite)) {
|
|
604
|
-
let e = this.sprites.get(n.sprite);
|
|
605
|
-
e.complete && this.ctx.drawImage(e, -n.size / 2, -n.size / 2, n.size, n.size);
|
|
606
|
-
} else n.type === "star" ? (this.ctx.fillStyle = n.color, this._drawStarPath(0, 0, 5, n.size, n.size / 2), this.ctx.fill()) : (this.ctx.fillStyle = n.color, this.ctx.beginPath(), this.ctx.arc(0, 0, n.size, 0, Math.PI * 2), this.ctx.fill());
|
|
607
|
-
this.ctx.restore();
|
|
608
|
-
}
|
|
609
|
-
this.particles.length > 0 ? this._frameHandle = requestAnimationFrame((e) => this._animate(e)) : this.isAnimating = !1;
|
|
610
|
-
}
|
|
611
|
-
_drawStarPath(e, t, n, r, i) {
|
|
612
|
-
let a = Math.PI / 2 * 3, o = e, s = t, c = Math.PI / n;
|
|
613
|
-
this.ctx.beginPath(), this.ctx.moveTo(e, t - r);
|
|
614
|
-
for (let l = 0; l < n; l++) o = e + Math.cos(a) * r, s = t + Math.sin(a) * r, this.ctx.lineTo(o, s), a += c, o = e + Math.cos(a) * i, s = t + Math.sin(a) * i, this.ctx.lineTo(o, s), a += c;
|
|
615
|
-
this.ctx.lineTo(e, t - r), this.ctx.closePath();
|
|
616
|
-
}
|
|
617
|
-
clear() {
|
|
618
|
-
this.particles.forEach((e) => this._recycleParticle(e)), this.particles = [], this.ctx.clearRect(0, 0, this.width, this.height);
|
|
619
|
-
}
|
|
620
|
-
destroy() {
|
|
621
|
-
this.clear(), this.isAnimating = !1, this._frameHandle !== null && (cancelAnimationFrame(this._frameHandle), this._frameHandle = null), this._resizeObserver &&= (this._resizeObserver.disconnect(), null), window.removeEventListener("resize", this._onResize), this.canvas.remove(), this.sprites.clear(), this.customEffects.clear(), this.pool = [];
|
|
622
|
-
}
|
|
623
|
-
}, I = (e, t) => Object.prototype.hasOwnProperty.call(e, t), L = class {
|
|
624
|
-
constructor(e = {}) {
|
|
625
|
-
this.audioContext = null, this.storageKey = e.storageKey || "dopamineSoundsMuted", this.storage = e.storage || j(), this.muted = this.storage.getItem(this.storageKey) === "true", this.assets = /* @__PURE__ */ new Map(), this.customSounds = e.customSounds || {}, this.masterGain = null, this._volume = 1, this.setVolume(e.volume ?? 1), this._loading = /* @__PURE__ */ new Map(), this._timers = /* @__PURE__ */ new Set();
|
|
626
|
-
}
|
|
627
|
-
_later(e, t) {
|
|
628
|
-
let n = setTimeout(() => {
|
|
629
|
-
this._timers.delete(n), e();
|
|
630
|
-
}, t);
|
|
631
|
-
this._timers.add(n);
|
|
632
|
-
}
|
|
633
|
-
initAudio() {
|
|
634
|
-
if (!this.audioContext) {
|
|
635
|
-
let e = typeof window < "u" ? window.AudioContext || window.webkitAudioContext : void 0;
|
|
636
|
-
if (!e) return !1;
|
|
637
|
-
this.audioContext = new e(), this.masterGain = this.audioContext.createGain(), this.masterGain.gain.value = this._volume, this.masterGain.connect(this.audioContext.destination), this.preloadSounds(this.customSounds);
|
|
638
|
-
}
|
|
639
|
-
return this.audioContext.state === "suspended" && this.audioContext.resume(), !0;
|
|
640
|
-
}
|
|
641
|
-
setVolume(e) {
|
|
642
|
-
return Number.isFinite(e) ? (this._volume = Math.max(0, Math.min(1, e)), this.masterGain && (this.masterGain.gain.value = this._volume), this._volume) : this._volume;
|
|
643
|
-
}
|
|
644
|
-
getVolume() {
|
|
645
|
-
return this._volume;
|
|
646
|
-
}
|
|
647
|
-
_output() {
|
|
648
|
-
return this.masterGain || this.audioContext.destination;
|
|
649
|
-
}
|
|
650
|
-
toggleMute() {
|
|
651
|
-
return this.muted = !this.muted, this.storage.setItem(this.storageKey, this.muted), this.muted;
|
|
652
|
-
}
|
|
653
|
-
registerSound(e, t) {
|
|
654
|
-
this.customSounds[e] = t, this.audioContext && this.loadSound(e, t);
|
|
655
|
-
}
|
|
656
|
-
async preloadSounds(e) {
|
|
657
|
-
let t = Object.entries(e).map(([e, t]) => (this.customSounds[e] = t, this.loadSound(e, t)));
|
|
658
|
-
await Promise.allSettled(t);
|
|
659
|
-
}
|
|
660
|
-
async loadSound(e, t) {
|
|
661
|
-
if (!this.audioContext) return;
|
|
662
|
-
if (this._loading.has(e)) return this._loading.get(e);
|
|
663
|
-
let n = this._load(e, t).finally(() => this._loading.delete(e));
|
|
664
|
-
return this._loading.set(e, n), n;
|
|
665
|
-
}
|
|
666
|
-
async _load(e, t) {
|
|
667
|
-
try {
|
|
668
|
-
let n = this.audioContext, r = await fetch(t);
|
|
669
|
-
if (r.ok === !1) throw Error(`HTTP ${r.status}`);
|
|
670
|
-
let i = await r.arrayBuffer(), a = await n.decodeAudioData(i);
|
|
671
|
-
this.audioContext === n && this.assets.set(e, a);
|
|
672
|
-
} catch (t) {
|
|
673
|
-
console.warn(`[DopamineJS] Failed to load sound '${e}':`, t);
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
async play(e) {
|
|
677
|
-
if (this.muted || !this.initAudio()) return;
|
|
678
|
-
if (this.assets.has(e)) {
|
|
679
|
-
this._playBuffer(this.assets.get(e));
|
|
680
|
-
return;
|
|
681
|
-
}
|
|
682
|
-
if (I(this.customSounds, e) && !this.assets.has(e)) {
|
|
683
|
-
let t = this.audioContext;
|
|
684
|
-
if (await this.loadSound(e, this.customSounds[e]), this.audioContext !== t) return;
|
|
685
|
-
if (this.assets.has(e)) {
|
|
686
|
-
this._playBuffer(this.assets.get(e));
|
|
687
|
-
return;
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
let t = {
|
|
691
|
-
jump: () => this.playJump(!0),
|
|
692
|
-
score: () => this.playScore(!0),
|
|
693
|
-
success: () => this.playSuccess(!0),
|
|
694
|
-
click: () => this.playClick(!0),
|
|
695
|
-
error: () => this.playError(!0),
|
|
696
|
-
gameover: () => this.playGameOver(!0)
|
|
697
|
-
};
|
|
698
|
-
I(t, e) && t[e]();
|
|
699
|
-
}
|
|
700
|
-
_playBuffer(e) {
|
|
701
|
-
let t = this.audioContext.createBufferSource();
|
|
702
|
-
t.buffer = e, t.connect(this._output()), t.start(0);
|
|
703
|
-
}
|
|
704
|
-
playTone(e, t, n = "sine", r = .3) {
|
|
705
|
-
if (this.muted || !this.initAudio()) return;
|
|
706
|
-
let i = this.audioContext.createOscillator(), a = this.audioContext.createGain();
|
|
707
|
-
i.connect(a), a.connect(this._output()), i.frequency.value = e, i.type = n;
|
|
708
|
-
let o = Math.max(1e-4, r);
|
|
709
|
-
a.gain.setValueAtTime(o, this.audioContext.currentTime), a.gain.exponentialRampToValueAtTime(.01, this.audioContext.currentTime + t), i.start(this.audioContext.currentTime), i.stop(this.audioContext.currentTime + t);
|
|
710
|
-
}
|
|
711
|
-
playJump(e = !1) {
|
|
712
|
-
if (!e && this.assets.has("jump")) return this.play("jump");
|
|
713
|
-
this.playTone(400, .1, "square", .2);
|
|
714
|
-
}
|
|
715
|
-
playScore(e = !1) {
|
|
716
|
-
if (!e && this.assets.has("score")) return this.play("score");
|
|
717
|
-
this.playTone(800, .15, "sine", .25), this._later(() => this.playTone(1e3, .15, "sine", .25), 50);
|
|
718
|
-
}
|
|
719
|
-
playGameOver(e = !1) {
|
|
720
|
-
if (!e && this.assets.has("gameover")) return this.play("gameover");
|
|
721
|
-
this.playTone(300, .2, "sawtooth", .3), this._later(() => this.playTone(200, .2, "sawtooth", .3), 100), this._later(() => this.playTone(150, .3, "sawtooth", .3), 200);
|
|
722
|
-
}
|
|
723
|
-
playClick(e = !1) {
|
|
724
|
-
if (!e && this.assets.has("click")) return this.play("click");
|
|
725
|
-
this.playTone(600, .05, "sine", .1);
|
|
726
|
-
}
|
|
727
|
-
playSuccess(e = !1) {
|
|
728
|
-
if (!e && this.assets.has("success")) return this.play("success");
|
|
729
|
-
this.playTone(600, .1, "sine", .2), this._later(() => this.playTone(800, .2, "sine", .2), 100);
|
|
730
|
-
}
|
|
731
|
-
playError(e = !1) {
|
|
732
|
-
if (!e && this.assets.has("error")) return this.play("error");
|
|
733
|
-
this.playTone(200, .2, "sawtooth", .3);
|
|
734
|
-
}
|
|
735
|
-
destroy() {
|
|
736
|
-
for (let e of this._timers) clearTimeout(e);
|
|
737
|
-
this._timers.clear(), this.audioContext && (this.audioContext.close?.())?.catch?.(() => {}), this.audioContext = null, this.masterGain = null, this.assets.clear(), this._loading.clear();
|
|
738
|
-
}
|
|
739
|
-
}, R = class {
|
|
740
|
-
constructor(e = {}) {
|
|
741
|
-
this.config = e, this.dataService = new M(e.data || {}), this.rewardSystem = new k(this.dataService, e.rewards || {}), this.soundManager = new L(e.sound || {}), this.particleSystem = new F(e.particles || {}), this.gameUI = new P(this.particleSystem), this._bindEvents();
|
|
742
|
-
}
|
|
743
|
-
async init() {
|
|
744
|
-
return await this.rewardSystem.init(), this._syncUI(), {
|
|
745
|
-
rewardSystem: this.rewardSystem,
|
|
746
|
-
gameUI: this.gameUI,
|
|
747
|
-
particleSystem: this.particleSystem,
|
|
748
|
-
soundManager: this.soundManager
|
|
749
|
-
};
|
|
750
|
-
}
|
|
751
|
-
_syncUI() {
|
|
752
|
-
let { player: e } = this.rewardSystem, { total: t, needed: n, progress: r } = this.rewardSystem.getXPForNextLevel();
|
|
753
|
-
this.gameUI.updateXP(e.xp, n, t, r), this.gameUI.updateLevel(e.level), this.gameUI.updateStreak(e.streak.current);
|
|
754
|
-
}
|
|
755
|
-
_bindEvents() {
|
|
756
|
-
let e = this.rewardSystem;
|
|
757
|
-
this._unsubscribe = [
|
|
758
|
-
e.on("xp_gained", () => {
|
|
759
|
-
let { total: t, needed: n, progress: r } = e.getXPForNextLevel();
|
|
760
|
-
this.gameUI.updateXP(e.player.xp, n, t, r);
|
|
761
|
-
}),
|
|
762
|
-
e.on("level_up", (e) => {
|
|
763
|
-
this.gameUI.updateLevel(e.newLevel), this.gameUI.showLevelUp(e.oldLevel, e.newLevel);
|
|
764
|
-
}),
|
|
765
|
-
e.on("achievement_unlocked", (e) => {
|
|
766
|
-
this.gameUI.showAchievement(e);
|
|
767
|
-
}),
|
|
768
|
-
e.on("streak_updated", (e) => {
|
|
769
|
-
this.gameUI.updateStreak(e.current);
|
|
770
|
-
}),
|
|
771
|
-
e.on("new_high_score", (e) => {
|
|
772
|
-
this.gameUI.showNotification(`New High Score: ${e.score}!`, "legendary"), this.soundManager.playSuccess();
|
|
773
|
-
})
|
|
774
|
-
];
|
|
775
|
-
}
|
|
776
|
-
destroy() {
|
|
777
|
-
for (let e of this._unsubscribe) e();
|
|
778
|
-
this._unsubscribe = [], this.gameUI.destroy(), this.particleSystem.destroy(), this.soundManager.destroy();
|
|
779
|
-
}
|
|
780
|
-
}, z = {
|
|
781
|
-
init(e) {},
|
|
782
|
-
update(e) {},
|
|
783
|
-
fixedUpdate(e) {},
|
|
784
|
-
destroy() {}
|
|
785
|
-
}, B = class {
|
|
786
|
-
constructor() {
|
|
787
|
-
this.kernel = null;
|
|
788
|
-
}
|
|
789
|
-
init(e) {
|
|
790
|
-
this.kernel = e;
|
|
791
|
-
}
|
|
792
|
-
update(e) {}
|
|
793
|
-
fixedUpdate(e) {}
|
|
794
|
-
destroy() {}
|
|
795
|
-
}, V = {
|
|
796
|
-
...z,
|
|
797
|
-
addBody(e) {},
|
|
798
|
-
removeBody(e) {},
|
|
799
|
-
checkCollision(e, t) {},
|
|
800
|
-
raycast(e, t, n) {},
|
|
801
|
-
setGravity(e, t) {},
|
|
802
|
-
step(e) {}
|
|
803
|
-
}, H = {
|
|
804
|
-
...z,
|
|
805
|
-
registerSound(e, t) {},
|
|
806
|
-
preloadSounds(e) {},
|
|
807
|
-
play(e, t) {},
|
|
808
|
-
playTone(e, t, n, r) {},
|
|
809
|
-
stop(e) {},
|
|
810
|
-
toggleMute() {},
|
|
811
|
-
setVolume(e) {}
|
|
812
|
-
}, U = {
|
|
813
|
-
...z,
|
|
814
|
-
registerSprite(e, t) {},
|
|
815
|
-
registerEffect(e, t) {},
|
|
816
|
-
play(e, t, n, ...r) {},
|
|
817
|
-
emit(e) {},
|
|
818
|
-
clear() {},
|
|
819
|
-
confetti(e, t, n) {},
|
|
820
|
-
coinShower(e, t, n) {},
|
|
821
|
-
sparkle(e, t, n, r) {},
|
|
822
|
-
fire(e, t, n) {},
|
|
823
|
-
starBurst(e, t, n) {}
|
|
824
|
-
}, W = class {
|
|
825
|
-
static createGround(e, t, n = "#333") {
|
|
826
|
-
let r = document.createElement("canvas");
|
|
827
|
-
r.width = e, r.height = t;
|
|
828
|
-
let i = r.getContext("2d");
|
|
829
|
-
i.fillStyle = n, i.fillRect(0, 0, e, t);
|
|
830
|
-
for (let n = 0; n < 1e3; n++) {
|
|
831
|
-
i.fillStyle = Math.random() > .5 ? "#444" : "#222";
|
|
832
|
-
let n = Math.random() * 4 + 2;
|
|
833
|
-
i.fillRect(Math.random() * e, Math.random() * t, n, n);
|
|
834
|
-
}
|
|
835
|
-
i.strokeStyle = "rgba(255,255,255,0.05)", i.lineWidth = 2, i.beginPath();
|
|
836
|
-
for (let n = 0; n <= e; n += 64) i.moveTo(n, 0), i.lineTo(n, t);
|
|
837
|
-
for (let n = 0; n <= t; n += 64) i.moveTo(0, n), i.lineTo(e, n);
|
|
838
|
-
return i.stroke(), r;
|
|
839
|
-
}
|
|
840
|
-
static createCharacterSheet(e, t) {
|
|
841
|
-
let n = document.createElement("canvas");
|
|
842
|
-
n.width = 256, n.height = 64;
|
|
843
|
-
let r = n.getContext("2d");
|
|
844
|
-
for (let n = 0; n < 4; n++) {
|
|
845
|
-
let i = n * 64 + 32, a = n % 2 == 0 ? 0 : -2, o = n === 1 ? 5 : n === 3 ? -5 : 0;
|
|
846
|
-
r.fillStyle = e, r.beginPath(), r.arc(i, 32 + a, 20, 0, Math.PI * 2), r.fill(), r.fillStyle = t, r.beginPath(), r.arc(i - 15, 32 + a + o, 8, 0, Math.PI * 2), r.arc(i + 15, 32 + a - o, 8, 0, Math.PI * 2), r.fill(), r.fillStyle = G(e, -20), r.beginPath(), r.arc(i, 32 + a, 15, 0, Math.PI * 2), r.fill(), t === "#333" && (r.fillStyle = "#000", r.fillRect(i + 10, 32 + a - 5, 25, 6));
|
|
847
|
-
}
|
|
848
|
-
return n;
|
|
849
|
-
}
|
|
850
|
-
};
|
|
851
|
-
function G(e, t) {
|
|
852
|
-
return e;
|
|
853
|
-
}
|
|
854
|
-
//#endregion
|
|
855
|
-
//#region src/index.js
|
|
856
|
-
var K = R;
|
|
857
|
-
//#endregion
|
|
858
|
-
export { g as Animator, n as Collider, b as Component, M as DataService, a as Director, y as DopamineKernel, e as EventBus, C as EventEmitter, _ as Game, m as GameObject, P as GameUI, h as GlobalInput, o as GlobalLoader, l as GlobalPhysics, H as IAudioSystem, U as IParticleSystem, V as IPhysicsSystem, z as ISystem, f as Input, s as Loader, p as ParticleEmitter, F as ParticleSystem, c as Physics, x as PluginRegistry, i as Renderer, k as RewardSystem, d as Scene, v as ScreenShake, L as SoundManager, u as Sprite, B as System, t as SystemRegistry, W as TextureGenerator, S as Ticker, r as Vector2, A as createMemoryStorage, K as default, j as resolveStorage };
|
|
1
|
+
import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, t as s } from "./DataService-MfmvkqXR.js";
|
|
2
|
+
import { a as c, i as l, n as u, o as d, r as f, s as p, t as m } from "./host-CkRL74ck.js";
|
|
3
|
+
export { s as DataService, t as DopamineError, r as EventEmitter, m as HOST_API, c as ParticleSystem, n as RewardSystem, p as RewardUI, l as SoundManager, u as createDopamine, f as createHaptics, i as createMemoryStorage, e as merge, d as prefersReducedMotion, o as resolveStorage, a as validate };
|