dopaminejs 2.5.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.
Files changed (81) hide show
  1. package/README.md +40 -50
  2. package/dist/DataService-E4pGQ1V3.cjs +1 -0
  3. package/dist/DataService-MfmvkqXR.js +737 -0
  4. package/dist/core.cjs +1 -1
  5. package/dist/core.js +2 -2
  6. package/dist/dopamine.cjs +1 -37
  7. package/dist/dopamine.js +3 -635
  8. package/dist/games.cjs +1 -0
  9. package/dist/games.js +82 -0
  10. package/dist/host-CkRL74ck.js +814 -0
  11. package/dist/host-Pzb-QBPU.cjs +37 -0
  12. package/dist/style.css +395 -2
  13. package/dist/testing.cjs +1 -0
  14. package/dist/testing.js +474 -0
  15. package/package.json +24 -9
  16. package/spec/README.md +227 -0
  17. package/spec/VERSION +1 -0
  18. package/spec/fixtures/achievements.json +611 -0
  19. package/spec/fixtures/levels.json +421 -0
  20. package/spec/fixtures/merge.json +1739 -0
  21. package/spec/fixtures/migrate.json +916 -0
  22. package/spec/fixtures/scores.json +755 -0
  23. package/spec/fixtures/streaks.json +924 -0
  24. package/spec/schema.json +61 -0
  25. package/src/dopamine/audio/SoundManager.js +54 -24
  26. package/src/dopamine/core/DopamineError.js +7 -0
  27. package/src/dopamine/core/RewardSystem.js +323 -373
  28. package/src/dopamine/core/achievements.js +49 -0
  29. package/src/dopamine/core/clock.js +11 -0
  30. package/src/dopamine/core/levels.js +4 -0
  31. package/src/dopamine/core/merge.js +68 -0
  32. package/src/dopamine/core/middleware.js +58 -0
  33. package/src/dopamine/core/store.js +261 -0
  34. package/src/dopamine/core/streaks.js +55 -0
  35. package/src/dopamine/effects/ParticleSystem.js +30 -0
  36. package/src/dopamine/host.js +358 -0
  37. package/src/dopamine/ui/{GameUI.js → RewardUI.js} +166 -202
  38. package/src/games.js +138 -0
  39. package/src/index.js +11 -34
  40. package/src/progression.js +3 -0
  41. package/src/testing.js +489 -0
  42. package/types/core.d.ts +9 -1
  43. package/types/games.d.ts +46 -0
  44. package/types/index.d.ts +291 -384
  45. package/types/testing.d.ts +96 -0
  46. package/dist/DataService-BPXCldpo.cjs +0 -1
  47. package/dist/DataService-CH9_gv_8.js +0 -398
  48. package/dist/ScreenShake-9jgNXPS6.cjs +0 -1
  49. package/dist/ScreenShake-CLvO1wx4.js +0 -827
  50. package/dist/engine.cjs +0 -1
  51. package/dist/engine.js +0 -2
  52. package/src/core/Animator.js +0 -62
  53. package/src/core/Collider.js +0 -86
  54. package/src/core/Component.js +0 -38
  55. package/src/core/DopamineKernel.js +0 -170
  56. package/src/core/EventBus.js +0 -206
  57. package/src/core/Game.js +0 -90
  58. package/src/core/GameObject.js +0 -99
  59. package/src/core/PluginRegistry.js +0 -359
  60. package/src/core/Scene.js +0 -107
  61. package/src/core/Sprite.js +0 -51
  62. package/src/core/SystemRegistry.js +0 -263
  63. package/src/core/Vector2.js +0 -50
  64. package/src/dopamine/components/ParticleEmitter.js +0 -50
  65. package/src/dopamine/components/ScreenShake.js +0 -50
  66. package/src/dopamine/components/index.js +0 -2
  67. package/src/dopamine/index.js +0 -93
  68. package/src/dopamine/utils/TextureGenerator.js +0 -90
  69. package/src/engine.js +0 -38
  70. package/src/interfaces/IAudioSystem.js +0 -58
  71. package/src/interfaces/IParticleSystem.js +0 -51
  72. package/src/interfaces/IPhysicsSystem.js +0 -52
  73. package/src/interfaces/ISystem.js +0 -48
  74. package/src/interfaces/index.js +0 -7
  75. package/src/renderer/Renderer.js +0 -45
  76. package/src/systems/Director.js +0 -34
  77. package/src/systems/Input.js +0 -81
  78. package/src/systems/Loader.js +0 -48
  79. package/src/systems/Physics.js +0 -210
  80. package/src/systems/Ticker.js +0 -91
  81. package/src/systems/deprecate.js +0 -38
package/dist/dopamine.js CHANGED
@@ -1,635 +1,3 @@
1
- import { a as e, i as t, n, r, t as i } from "./DataService-CH9_gv_8.js";
2
- import { C as a, S as o, _ as s, a as c, b as l, c as u, d, f, g as p, h as m, i as ee, l as h, m as g, n as _, o as v, p as y, r as b, s as x, t as S, u as C, v as w, x as T, y as E } from "./ScreenShake-CLvO1wx4.js";
3
- //#region src/dopamine/ui/GameUI.js
4
- var D = "game-ui-overlay", O = {
5
- levelUp: "LEVEL UP!",
6
- achievementUnlocked: "Achievement Unlocked!",
7
- nearMiss: "CLOSE CALL!"
8
- }, k = "🔥", te = (e, t) => Object.prototype.hasOwnProperty.call(e, t), A = (e, t) => typeof e == "object" && e && te(e, t) ? e[t] : void 0, j = "http://www.w3.org/2000/svg", M = /* @__PURE__ */ new Set([
9
- "svg",
10
- "g",
11
- "path",
12
- "circle",
13
- "ellipse",
14
- "rect",
15
- "line",
16
- "polyline",
17
- "polygon",
18
- "text",
19
- "tspan",
20
- "title",
21
- "desc",
22
- "defs",
23
- "linearGradient",
24
- "radialGradient",
25
- "stop",
26
- "clipPath",
27
- "mask"
28
- ]), N = /* @__PURE__ */ new Set(/* @__PURE__ */ "viewBox.width.height.x.y.x1.y1.x2.y2.cx.cy.r.rx.ry.d.points.transform.fill.fill-opacity.fill-rule.stroke.stroke-width.stroke-linecap.stroke-linejoin.stroke-opacity.opacity.offset.stop-color.stop-opacity.gradientUnits.gradientTransform.clip-path.mask.clip-rule.font-size.font-family.font-weight.text-anchor.id.aria-hidden.aria-label.role".split(".")), P = /* @__PURE__ */ new Set([
29
- "fill",
30
- "stroke",
31
- "clip-path",
32
- "mask"
33
- ]), F = /* @__PURE__ */ new Set(["transform", "gradientTransform"]), I = /^url\(\s*#([A-Za-z][\w.:-]*)\s*\)$/, L = /^[#a-zA-Z0-9(),.%\s-]+$/, R = /^[a-zA-Z0-9(),.\s-]+$/, z = /^[A-Za-z][\w.:-]*$/, B = 0;
34
- function V(e, t) {
35
- if (e.nodeType !== 1 || e.namespaceURI !== j || !M.has(e.localName)) return;
36
- let n = e.getAttribute("id");
37
- n && z.test(n) && t.add(n);
38
- for (let n of Array.from(e.childNodes)) V(n, t);
39
- }
40
- function H(e, t, n) {
41
- if (t.includes("\\")) return null;
42
- let r = t.trim();
43
- if (e === "id") return z.test(r) ? n.prefix + r : null;
44
- if (P.has(e)) {
45
- let e = I.exec(r);
46
- return e ? n.ids.has(e[1]) ? `url(#${n.prefix}${e[1]})` : null : L.test(r) && !/url/i.test(r) ? r : null;
47
- }
48
- return F.has(e) ? R.test(r) && !/url/i.test(r) ? r : null : t.includes("(") ? e === "stop-color" && L.test(r) && !/url/i.test(r) ? r : null : t;
49
- }
50
- function U(e, t) {
51
- if (e.nodeType === 3 || e.nodeType === 4) return document.createTextNode(e.data);
52
- if (e.nodeType !== 1 || e.namespaceURI !== j || !M.has(e.localName)) return null;
53
- let n = document.createElementNS(j, e.localName);
54
- for (let r of Array.from(e.attributes)) {
55
- if (r.namespaceURI !== null || !N.has(r.name)) continue;
56
- let e = H(r.name, r.value, t);
57
- e !== null && n.setAttribute(r.name, e);
58
- }
59
- for (let r of Array.from(e.childNodes)) {
60
- let e = U(r, t);
61
- e && n.appendChild(e);
62
- }
63
- return n;
64
- }
65
- function W(e) {
66
- let t, n = /^\s*<svg[\s>]/.test(e) && !/^\s*<svg\b[^>]*\sxmlns\s*=/.test(e) ? e.replace(/^(\s*<svg)/, `$1 xmlns="${j}"`) : e;
67
- try {
68
- t = new DOMParser().parseFromString(n, "image/svg+xml");
69
- } catch {
70
- return null;
71
- }
72
- let r = t.documentElement;
73
- if (!r || r.localName !== "svg" || t.getElementsByTagName("parsererror").length > 0) return null;
74
- let i = /* @__PURE__ */ new Set();
75
- return V(r, i), U(r, {
76
- ids: i,
77
- prefix: `dj-icon-${++B}-`
78
- });
79
- }
80
- var G = class {
81
- constructor(e, t = {}) {
82
- this.particleSystem = e;
83
- let n = A(t, "text");
84
- this.text = { ...O };
85
- for (let e of Object.keys(O)) {
86
- let t = A(n, e);
87
- typeof t == "string" && (this.text[e] = t);
88
- }
89
- this.safeIcons = A(t, "safeIcons") === !0, this._streakIcon = A(A(t, "icons"), "streak") ?? k, this.container = null, this.xpBar = null, this.levelDisplay = null, this.streakDisplay = null, this._timers = /* @__PURE__ */ new Set(), this._detached = [], this.init();
90
- }
91
- init() {
92
- this.container = document.createElement("div"), this.container.className = "game-ui-overlay", document.getElementById(D) || (this.container.id = D), 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, {
93
- position: "absolute",
94
- width: "1px",
95
- height: "1px",
96
- overflow: "hidden",
97
- clipPath: "inset(50%)",
98
- whiteSpace: "nowrap"
99
- }), 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"), this._setIcon(this.container.querySelector(".streak-icon"), this._streakIcon);
100
- }
101
- _setIcon(e, t) {
102
- if (e.textContent = "", typeof Node < "u" && t instanceof Node) e.appendChild(t);
103
- else if (typeof t != "string") return;
104
- else if (!this.safeIcons) e.innerHTML = t;
105
- else {
106
- let n = W(t);
107
- n ? e.appendChild(n) : e.textContent = t;
108
- }
109
- }
110
- _defer(e, t) {
111
- let n = setTimeout(() => {
112
- this._timers.delete(n), e();
113
- }, t);
114
- return this._timers.add(n), n;
115
- }
116
- _mount(e) {
117
- return document.body.appendChild(e), this._detached.push(e), e;
118
- }
119
- _announce(e) {
120
- this.liveRegion && (this.liveRegion.textContent = e);
121
- }
122
- _replayAnimation(e, t) {
123
- e && (e.style.animation = "none", this._defer(() => {
124
- e.style.animation = t;
125
- }, 10));
126
- }
127
- updateXP(e, t, n, r) {
128
- let i = Number.isFinite(r) ? r : n > 0 ? e / n : 0;
129
- 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");
130
- }
131
- updateLevel(e) {
132
- this.levelDisplay.textContent = e, this._replayAnimation(this.levelBadge, "level-pulse 0.5s ease-out");
133
- }
134
- updateStreak(e) {
135
- 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 = "";
136
- }
137
- showAchievement(e) {
138
- let t = document.createElement("div");
139
- 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\"></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-title").textContent = this.text.achievementUnlocked, this._setIcon(t.querySelector(".achievement-icon"), 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(() => {
140
- let e = t.getBoundingClientRect();
141
- this.particleSystem.confetti(e.left + e.width / 2, e.top + e.height / 2, 40);
142
- }, 300), this._defer(() => {
143
- t.style.animation = "slideOut 0.3s ease-in forwards", this._defer(() => this._remove(t), 300);
144
- }, 4e3);
145
- }
146
- showLevelUp(e, t) {
147
- let n = document.createElement("div");
148
- n.className = "level-up-overlay", n.innerHTML = "\n <div class=\"level-up-content\">\n <div class=\"level-up-title\"></div>\n <div class=\"level-up-number\"></div>\n <div class=\"level-up-subtitle\">Amazing progress!</div>\n </div>\n ", n.querySelector(".level-up-title").textContent = this.text.levelUp, n.querySelector(".level-up-number").textContent = t, this._mount(n), this._announce(`Level up: ${t}`), this._defer(() => {
149
- for (let e = 0; e < 5; e++) this._defer(() => {
150
- let e = Math.random() * window.innerWidth, t = Math.random() * window.innerHeight * .6;
151
- this.particleSystem.confetti(e, t, 30);
152
- }, e * 200);
153
- }, 300), this._defer(() => {
154
- n.style.opacity = "0", this._defer(() => this._remove(n), 500);
155
- }, 2500);
156
- }
157
- showFloatingText(e, t, n, r = "#ffd700", i = "24px") {
158
- let a = document.createElement("div");
159
- 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);
160
- }
161
- showCombo(e, t, n) {
162
- this.showFloatingText(`${e}× COMBO!`, t, n, "#ff6b6b", "32px"), this.particleSystem.fire(t, n, 20);
163
- }
164
- showNearMiss(e, t) {
165
- this.showFloatingText(this.text.nearMiss, e, t, "#45b7d1", "20px"), this.particleSystem.sparkle(e, t, 15, "#45b7d1");
166
- }
167
- showLuckyMoment(e, t, n) {
168
- this.showFloatingText(`LUCKY ${e}×!`, t, n, "#ffd700", "36px"), this.particleSystem.starBurst(t, n, 12), this.particleSystem.confetti(t, n, 25);
169
- }
170
- showNotification(e, t = "normal") {
171
- let n = window.innerWidth / 2, r = window.innerHeight / 3;
172
- 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);
173
- }
174
- showSummary(e) {
175
- let t = document.createElement("div");
176
- 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";
177
- let n = document.createElement("h1");
178
- n.textContent = "Game Over";
179
- let r = document.createElement("div");
180
- r.className = "summary-score", r.style.cssText = "font-size: 3rem; font-weight: bold; color: #e06020; margin: 10px 0;", r.textContent = e.score;
181
- let i = document.createElement("div");
182
- i.className = "summary-metrics", i.style.cssText = "width: 100%; margin-bottom: 20px;";
183
- for (let [t, n] of Object.entries(e.metrics || {})) {
184
- let e = document.createElement("div");
185
- e.style.cssText = "display:flex;justify-content:space-between;width:100%";
186
- let r = document.createElement("span");
187
- r.textContent = `${t}:`;
188
- let a = document.createElement("strong");
189
- a.textContent = n, e.append(r, a), i.appendChild(e);
190
- }
191
- t.append(n, r, i);
192
- let a = document.createElement("button");
193
- if (a.className = "btn", a.textContent = "Play Again", a.addEventListener("click", e.onReplay || (() => window.location.reload())), t.appendChild(a), e.onExit) {
194
- let n = document.createElement("button");
195
- n.className = "btn", n.textContent = "Exit", n.style.cssText = "margin-top: 10px; background: #543847;", n.addEventListener("click", e.onExit), t.appendChild(n);
196
- }
197
- return this._mount(t), t;
198
- }
199
- _remove(e) {
200
- e.remove();
201
- let t = this._detached.indexOf(e);
202
- t > -1 && this._detached.splice(t, 1);
203
- }
204
- destroy() {
205
- for (let e of this._timers) clearTimeout(e);
206
- this._timers.clear();
207
- for (let e of this._detached) e.remove();
208
- 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, this._streakIcon = null;
209
- }
210
- }, K = Object.freeze({ matches: !1 });
211
- function q(e = globalThis.window) {
212
- return typeof e?.matchMedia == "function" && e.matchMedia("(prefers-reduced-motion: reduce)") || K;
213
- }
214
- //#endregion
215
- //#region src/dopamine/effects/ParticleSystem.js
216
- var J = class {
217
- constructor(e = {}) {
218
- 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 ? null : q(window), 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);
219
- }
220
- _resize() {
221
- 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;
222
- 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);
223
- }
224
- registerSprite(e, t) {
225
- let n = new Image();
226
- n.src = t, this.sprites.set(e, n);
227
- }
228
- registerEffect(e, t) {
229
- this.customEffects.set(e, t);
230
- }
231
- play(e, t, n, ...r) {
232
- let i = this.customEffects.get(e);
233
- i ? i(t, n, ...r) : console.warn(`[DopamineJS] Effect '${e}' not found.`);
234
- }
235
- emit(e) {
236
- 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);
237
- for (let e = 0; e < m; e++) {
238
- let e = this._getParticle(), r = d + (Math.random() - .5) * u, m = Math.random() * i;
239
- 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);
240
- }
241
- m > 0 && this._startAnimation();
242
- }
243
- _allowed(e) {
244
- if (this._reducedMotion?.matches || !Number.isFinite(e)) return 0;
245
- let t = this.maxParticles - this.particles.length;
246
- return Math.max(0, Math.min(Math.floor(e), t));
247
- }
248
- _getParticle() {
249
- return this.pool.length > 0 ? this.pool.pop() : {};
250
- }
251
- _recycleParticle(e) {
252
- this.pool.push(e);
253
- }
254
- confetti(e, t, n = 50) {
255
- this.emit({
256
- x: e,
257
- y: t,
258
- count: n,
259
- color: [
260
- "#ff6b6b",
261
- "#4ecdc4",
262
- "#45b7d1",
263
- "#f7dc6f",
264
- "#c06c84",
265
- "#6c5ce7"
266
- ],
267
- speed: 10,
268
- gravity: .3,
269
- decay: .015,
270
- size: 8,
271
- spread: Math.PI * 2
272
- });
273
- }
274
- coinShower(e, t, n = 10) {
275
- this.emit({
276
- x: e,
277
- y: t,
278
- count: n,
279
- color: "#ffd700",
280
- speed: 4,
281
- gravity: .4,
282
- decay: .012,
283
- size: 12,
284
- angle: -Math.PI / 2,
285
- spread: Math.PI / 2
286
- });
287
- }
288
- sparkle(e, t, n = 20, r = "#ffd700") {
289
- this.emit({
290
- x: e,
291
- y: t,
292
- count: n,
293
- color: r,
294
- speed: 3,
295
- gravity: -.05,
296
- decay: .03,
297
- size: 3
298
- });
299
- }
300
- fire(e, t, n = 15) {
301
- this.emit({
302
- x: e,
303
- y: t,
304
- count: n,
305
- color: [
306
- "#ff6b00",
307
- "#ff8800",
308
- "#ffaa00",
309
- "#ff4400"
310
- ],
311
- speed: 3,
312
- gravity: -.2,
313
- decay: .04,
314
- size: 5,
315
- angle: -Math.PI / 2,
316
- spread: Math.PI / 4
317
- });
318
- }
319
- starBurst(e, t, n = 8) {
320
- let r = this._allowed(n);
321
- for (let n = 0; n < r; n++) {
322
- let i = this._getParticle(), a = Math.PI * 2 / r * n;
323
- 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);
324
- }
325
- r > 0 && this._startAnimation();
326
- }
327
- _startAnimation() {
328
- this.isAnimating || (this.isAnimating = !0, this._lastFrameTime = null, this._animate());
329
- }
330
- _animate(e) {
331
- this._frameHandle = null, this.ctx.clearRect(0, 0, this.width, this.height);
332
- let t = 1;
333
- Number.isFinite(e) && (this._lastFrameTime !== null && (t = Math.max(0, Math.min(3, (e - this._lastFrameTime) / (1e3 / 60)))), this._lastFrameTime = e);
334
- for (let e = this.particles.length - 1; e >= 0; e--) {
335
- let n = this.particles[e];
336
- 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) {
337
- this._recycleParticle(n);
338
- let t = this.particles.pop();
339
- e < this.particles.length && (this.particles[e] = t);
340
- continue;
341
- }
342
- 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)) {
343
- let e = this.sprites.get(n.sprite);
344
- e.complete && this.ctx.drawImage(e, -n.size / 2, -n.size / 2, n.size, n.size);
345
- } 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());
346
- this.ctx.restore();
347
- }
348
- this.particles.length > 0 ? this._frameHandle = requestAnimationFrame((e) => this._animate(e)) : this.isAnimating = !1;
349
- }
350
- _drawStarPath(e, t, n, r, i) {
351
- let a = Math.PI / 2 * 3, o = e, s = t, c = Math.PI / n;
352
- this.ctx.beginPath(), this.ctx.moveTo(e, t - r);
353
- 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;
354
- this.ctx.lineTo(e, t - r), this.ctx.closePath();
355
- }
356
- clear() {
357
- this.particles.forEach((e) => this._recycleParticle(e)), this.particles = [], this.ctx.clearRect(0, 0, this.width, this.height);
358
- }
359
- destroy() {
360
- 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 = [];
361
- }
362
- }, Y = (e, t) => Object.prototype.hasOwnProperty.call(e, t), X = class {
363
- constructor(e = {}) {
364
- this.audioContext = null, this.storageKey = e.storageKey || "dopamineSoundsMuted", this.storage = e.storage || r(), 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(), this._unlocks = /* @__PURE__ */ new Set();
365
- }
366
- unlockOn(e, t = [
367
- "pointerup",
368
- "touchend",
369
- "keydown"
370
- ]) {
371
- let n = () => {
372
- for (let n of t) e.removeEventListener(n, r);
373
- this._unlocks.delete(n);
374
- }, r = () => {
375
- n(), this.initAudio();
376
- };
377
- for (let n of t) e.addEventListener(n, r);
378
- return this._unlocks.add(n), n;
379
- }
380
- _later(e, t) {
381
- let n = setTimeout(() => {
382
- this._timers.delete(n), e();
383
- }, t);
384
- this._timers.add(n);
385
- }
386
- initAudio() {
387
- if (!this.audioContext) {
388
- let e = typeof window < "u" ? window.AudioContext || window.webkitAudioContext : void 0;
389
- if (!e) return !1;
390
- 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);
391
- }
392
- return this.audioContext.state === "suspended" && this.audioContext.resume(), !0;
393
- }
394
- setVolume(e) {
395
- 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;
396
- }
397
- getVolume() {
398
- return this._volume;
399
- }
400
- _output() {
401
- return this.masterGain || this.audioContext.destination;
402
- }
403
- toggleMute() {
404
- return this.muted = !this.muted, this.storage.setItem(this.storageKey, this.muted), this.muted;
405
- }
406
- registerSound(e, t) {
407
- this.customSounds[e] = t, this.audioContext && this.loadSound(e, t);
408
- }
409
- async preloadSounds(e) {
410
- let t = Object.entries(e).map(([e, t]) => (this.customSounds[e] = t, this.loadSound(e, t)));
411
- await Promise.allSettled(t);
412
- }
413
- async loadSound(e, t) {
414
- if (!this.audioContext) return;
415
- if (this._loading.has(e)) return this._loading.get(e);
416
- let n = this._load(e, t).finally(() => this._loading.delete(e));
417
- return this._loading.set(e, n), n;
418
- }
419
- async _load(e, t) {
420
- try {
421
- let n = this.audioContext, r = await fetch(t);
422
- if (r.ok === !1) throw Error(`HTTP ${r.status}`);
423
- let i = await r.arrayBuffer(), a = await n.decodeAudioData(i);
424
- this.audioContext === n && this.assets.set(e, a);
425
- } catch (t) {
426
- console.warn(`[DopamineJS] Failed to load sound '${e}':`, t);
427
- }
428
- }
429
- async play(e) {
430
- if (this.muted || !this.initAudio()) return;
431
- if (this.assets.has(e)) {
432
- this._playBuffer(this.assets.get(e));
433
- return;
434
- }
435
- if (Y(this.customSounds, e) && !this.assets.has(e)) {
436
- let t = this.audioContext;
437
- if (await this.loadSound(e, this.customSounds[e]), this.audioContext !== t) return;
438
- if (this.assets.has(e)) {
439
- this._playBuffer(this.assets.get(e));
440
- return;
441
- }
442
- }
443
- let t = {
444
- jump: () => this.playJump(!0),
445
- score: () => this.playScore(!0),
446
- success: () => this.playSuccess(!0),
447
- click: () => this.playClick(!0),
448
- error: () => this.playError(!0),
449
- gameover: () => this.playGameOver(!0)
450
- };
451
- Y(t, e) && t[e]();
452
- }
453
- _playBuffer(e) {
454
- let t = this.audioContext.createBufferSource();
455
- t.buffer = e, t.connect(this._output()), t.start(0);
456
- }
457
- playTone(e, t, n = "sine", r = .3) {
458
- if (this.muted || !this.initAudio()) return;
459
- let i = this.audioContext.createOscillator(), a = this.audioContext.createGain();
460
- i.connect(a), a.connect(this._output()), i.frequency.value = e, i.type = n;
461
- let o = Math.max(1e-4, r);
462
- 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);
463
- }
464
- playJump(e = !1) {
465
- if (!e && this.assets.has("jump")) return this.play("jump");
466
- this.playTone(400, .1, "square", .2);
467
- }
468
- playScore(e = !1) {
469
- if (!e && this.assets.has("score")) return this.play("score");
470
- this.playTone(800, .15, "sine", .25), this._later(() => this.playTone(1e3, .15, "sine", .25), 50);
471
- }
472
- playGameOver(e = !1) {
473
- if (!e && this.assets.has("gameover")) return this.play("gameover");
474
- this.playTone(300, .2, "sawtooth", .3), this._later(() => this.playTone(200, .2, "sawtooth", .3), 100), this._later(() => this.playTone(150, .3, "sawtooth", .3), 200);
475
- }
476
- playClick(e = !1) {
477
- if (!e && this.assets.has("click")) return this.play("click");
478
- this.playTone(600, .05, "sine", .1);
479
- }
480
- playSuccess(e = !1) {
481
- if (!e && this.assets.has("success")) return this.play("success");
482
- this.playTone(600, .1, "sine", .2), this._later(() => this.playTone(800, .2, "sine", .2), 100);
483
- }
484
- playError(e = !1) {
485
- if (!e && this.assets.has("error")) return this.play("error");
486
- this.playTone(200, .2, "sawtooth", .3);
487
- }
488
- destroy() {
489
- for (let e of [...this._unlocks]) e();
490
- for (let e of this._timers) clearTimeout(e);
491
- this._timers.clear(), this.audioContext && (this.audioContext.close?.())?.catch?.(() => {}), this.audioContext = null, this.masterGain = null, this.assets.clear(), this._loading.clear();
492
- }
493
- }, Z = class {
494
- constructor(e = {}) {
495
- this.config = e, this.dataService = new i(e.data || {}), this.rewardSystem = new t(this.dataService, e.rewards || {}), this.soundManager = new X(e.sound || {}), this.particleSystem = new J(e.particles || {}), this.gameUI = new G(this.particleSystem), this._bindEvents();
496
- }
497
- async init() {
498
- return await this.rewardSystem.init(), this._syncUI(), {
499
- rewardSystem: this.rewardSystem,
500
- gameUI: this.gameUI,
501
- particleSystem: this.particleSystem,
502
- soundManager: this.soundManager
503
- };
504
- }
505
- _syncUI() {
506
- let { player: e } = this.rewardSystem, { total: t, needed: n, progress: r } = this.rewardSystem.getXPForNextLevel();
507
- this.gameUI.updateXP(e.xp, n, t, r), this.gameUI.updateLevel(e.level), this.gameUI.updateStreak(e.streak.current);
508
- }
509
- _bindEvents() {
510
- let e = this.rewardSystem;
511
- this._unsubscribe = [
512
- e.on("xp_gained", () => {
513
- let { total: t, needed: n, progress: r } = e.getXPForNextLevel();
514
- this.gameUI.updateXP(e.player.xp, n, t, r);
515
- }),
516
- e.on("level_up", (e) => {
517
- this.gameUI.updateLevel(e.newLevel), this.gameUI.showLevelUp(e.oldLevel, e.newLevel);
518
- }),
519
- e.on("achievement_unlocked", (e) => {
520
- this.gameUI.showAchievement(e);
521
- }),
522
- e.on("streak_updated", (e) => {
523
- this.gameUI.updateStreak(e.current);
524
- }),
525
- e.on("new_high_score", (e) => {
526
- this.gameUI.showNotification(`New High Score: ${e.score}!`, "legendary"), this.soundManager.playSuccess();
527
- })
528
- ];
529
- }
530
- destroy() {
531
- for (let e of this._unsubscribe) e();
532
- this._unsubscribe = [], this.gameUI.destroy(), this.particleSystem.destroy(), this.soundManager.destroy();
533
- }
534
- }, Q = {
535
- init(e) {},
536
- update(e) {},
537
- fixedUpdate(e) {},
538
- destroy() {}
539
- }, ne = class {
540
- constructor() {
541
- this.kernel = null;
542
- }
543
- init(e) {
544
- this.kernel = e;
545
- }
546
- update(e) {}
547
- fixedUpdate(e) {}
548
- destroy() {}
549
- }, re = {
550
- ...Q,
551
- addBody(e) {},
552
- removeBody(e) {},
553
- checkCollision(e, t) {},
554
- raycast(e, t, n) {},
555
- setGravity(e, t) {},
556
- step(e) {}
557
- }, $ = {
558
- ...Q,
559
- registerSound(e, t) {},
560
- preloadSounds(e) {},
561
- play(e, t) {},
562
- playTone(e, t, n, r) {},
563
- stop(e) {},
564
- toggleMute() {},
565
- setVolume(e) {}
566
- }, ie = {
567
- ...Q,
568
- registerSprite(e, t) {},
569
- registerEffect(e, t) {},
570
- play(e, t, n, ...r) {},
571
- emit(e) {},
572
- clear() {},
573
- confetti(e, t, n) {},
574
- coinShower(e, t, n) {},
575
- sparkle(e, t, n, r) {},
576
- fire(e, t, n) {},
577
- starBurst(e, t, n) {}
578
- };
579
- //#endregion
580
- //#region src/dopamine/feel/haptics.js
581
- function ae({ nav: e = globalThis.navigator, enabled: t = !0 } = {}) {
582
- let n = !!t, r = (t) => {
583
- if (n) try {
584
- e.vibrate(t);
585
- } catch {}
586
- };
587
- return {
588
- tap: () => r(10),
589
- double: () => r([
590
- 10,
591
- 40,
592
- 10
593
- ]),
594
- setEnabled(e) {
595
- n = !!e;
596
- }
597
- };
598
- }
599
- //#endregion
600
- //#region src/dopamine/utils/TextureGenerator.js
601
- var oe = class {
602
- static createGround(e, t, n = "#333") {
603
- let r = document.createElement("canvas");
604
- r.width = e, r.height = t;
605
- let i = r.getContext("2d");
606
- i.fillStyle = n, i.fillRect(0, 0, e, t);
607
- for (let n = 0; n < 1e3; n++) {
608
- i.fillStyle = Math.random() > .5 ? "#444" : "#222";
609
- let n = Math.random() * 4 + 2;
610
- i.fillRect(Math.random() * e, Math.random() * t, n, n);
611
- }
612
- i.strokeStyle = "rgba(255,255,255,0.05)", i.lineWidth = 2, i.beginPath();
613
- for (let n = 0; n <= e; n += 64) i.moveTo(n, 0), i.lineTo(n, t);
614
- for (let n = 0; n <= t; n += 64) i.moveTo(0, n), i.lineTo(e, n);
615
- return i.stroke(), r;
616
- }
617
- static createCharacterSheet(e, t) {
618
- let n = document.createElement("canvas");
619
- n.width = 256, n.height = 64;
620
- let r = n.getContext("2d");
621
- for (let n = 0; n < 4; n++) {
622
- let i = n * 64 + 32, a = n % 2 == 0 ? 0 : -2, o = n === 1 ? 5 : n === 3 ? -5 : 0;
623
- 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 = se(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));
624
- }
625
- return n;
626
- }
627
- };
628
- function se(e, t) {
629
- return e;
630
- }
631
- //#endregion
632
- //#region src/index.js
633
- var ce = Z;
634
- //#endregion
635
- export { b as Animator, s as Collider, w as Component, i as DataService, u as Director, C as DopamineKernel, a as EventBus, e as EventEmitter, x as Game, v as GameObject, G as GameUI, y as GlobalInput, d as GlobalLoader, m as GlobalPhysics, $ as IAudioSystem, ie as IParticleSystem, re as IPhysicsSystem, Q as ISystem, g as Input, f as Loader, _ as ParticleEmitter, J as ParticleSystem, p as Physics, T as PluginRegistry, l as Renderer, t as RewardSystem, h as Scene, S as ScreenShake, X as SoundManager, ee as Sprite, ne as System, o as SystemRegistry, oe as TextureGenerator, E as Ticker, c as Vector2, ae as createHaptics, n as createMemoryStorage, ce as default, q as prefersReducedMotion, r 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 };
package/dist/games.cjs ADDED
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e={combo:`{n}× COMBO!`,nearMiss:`CLOSE CALL!`,luckyMoment:`LUCKY {n}×!`,gameOver:`Game Over`,playAgain:`Play Again`,exit:`Exit`},t=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n={jump:e=>e.playTone(400,.1,`square`,.2),score:(e,t)=>{e.playTone(800,.15,`sine`,.25),t(()=>e.playTone(1e3,.15,`sine`,.25),50)},gameover:(e,t)=>{e.playTone(300,.2,`sawtooth`,.3),t(()=>e.playTone(200,.2,`sawtooth`,.3),100),t(()=>e.playTone(150,.3,`sawtooth`,.3),200)}},r=(e,t,n)=>{let r=document.createElement(e);return t!==void 0&&(r.textContent=t),n&&(r.style.cssText=n),r};function i(i){let a={...e},o=typeof i==`object`&&i&&t(i,`text`)?i.text:null;for(let n of Object.keys(e))typeof o==`object`&&o&&t(o,n)&&typeof o[n]==`string`&&(a[n]=o[n]);let s=null,c=new Set,l=(e,t,n,r,i,o)=>{let c=a[e].replace(`{n}`,()=>String(t));c!==``&&s.parts.ui.text({text:c,x:n,y:r,color:i,size:o})},u=(e,t,n,r)=>s.parts.particles?.burst(e,{x:t,y:n},r),d={name:`games`,version:`1.0.0`,api:3,requires:[`ui`],combo(e,t,n){s&&(l(`combo`,e,t,n,`#ff6b6b`,`32px`),u(`fire`,t,n,{count:20}))},nearMiss(e,t){s&&(l(`nearMiss`,``,e,t,`#45b7d1`,`20px`),u(`sparkle`,e,t,{count:15,color:`#45b7d1`}))},luckyMoment(e,t,n){s&&(l(`luckyMoment`,e,t,n,`#ffd700`,`36px`),u(`stars`,t,n,{count:12}),u(`confetti`,t,n,{count:25}))},summary(e){if(!s||!s.env.hasDom||typeof e!=`object`||!e)return null;let t=r(`div`,void 0,`display:flex;flex-direction:column;align-items:center;position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);z-index:1000`);t.className=`message-box`,a.gameOver!==``&&t.append(r(`h1`,a.gameOver)),t.append(r(`div`,e.score,`font-size:3rem;font-weight:bold;color:#e06020;margin:10px 0`));let n=r(`div`,void 0,`width:100%;margin-bottom:20px`),i=e.metrics!==null&&typeof e.metrics==`object`?e.metrics:{};for(let[e,t]of Object.entries(i)){let i=r(`div`,void 0,`display:flex;justify-content:space-between;width:100%`);i.append(r(`span`,`${e}:`),r(`strong`,t)),n.append(i)}t.append(n);let o=(e,n)=>{let i=r(`button`,e);i.className=`btn`,i.addEventListener(`click`,n),t.append(i)};return a.playAgain!==``&&o(a.playAgain,typeof e.onReplay==`function`?e.onReplay:()=>window.location.reload()),typeof e.onExit==`function`&&a.exit!==``&&o(a.exit,e.onExit),document.body.append(t),c.add(t),t},install(e){s=e;let t=Object.keys(n).map(e=>s.parts.sound?.register?.(e,n[e]));return e.expose(d),()=>{for(let e of t)e?.();for(let e of c)e.remove();c.clear(),s=null}}};return d}exports.gameFeedback=i;