dopaminejs 2.5.0 → 3.1.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 +55 -50
- package/dist/DataService-D1uL6E8R.cjs +1 -0
- package/dist/DataService-DN6xwvXU.js +745 -0
- package/dist/core.cjs +1 -1
- package/dist/core.js +2 -2
- package/dist/dopamine.cjs +1 -37
- package/dist/dopamine.js +3 -635
- package/dist/games.cjs +1 -0
- package/dist/games.js +82 -0
- package/dist/host-7FzZ-yO7.cjs +37 -0
- package/dist/host-CdjhXPy-.js +815 -0
- package/dist/style.css +395 -2
- package/dist/testing.cjs +1 -0
- package/dist/testing.js +475 -0
- package/package.json +24 -9
- package/spec/README.md +228 -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 +957 -0
- package/spec/fixtures/scores.json +755 -0
- package/spec/fixtures/streaks.json +967 -0
- package/spec/schema.json +61 -0
- package/src/dopamine/audio/SoundManager.js +54 -24
- package/src/dopamine/core/DopamineError.js +7 -0
- package/src/dopamine/core/RewardSystem.js +359 -374
- 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 +30 -0
- package/src/dopamine/host.js +360 -0
- package/src/dopamine/ui/{GameUI.js → RewardUI.js} +166 -202
- package/src/games.js +138 -0
- package/src/index.js +11 -34
- package/src/progression.js +3 -0
- package/src/testing.js +490 -0
- package/types/core.d.ts +9 -1
- package/types/games.d.ts +46 -0
- package/types/index.d.ts +311 -385
- package/types/testing.d.ts +96 -0
- package/dist/DataService-BPXCldpo.cjs +0 -1
- package/dist/DataService-CH9_gv_8.js +0 -398
- 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/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
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SystemRegistry - Manages system lifecycle and dependency resolution
|
|
3
|
-
*
|
|
4
|
-
* Systems are registered with names and can have dependencies on other systems.
|
|
5
|
-
* The registry ensures systems are updated in the correct order based on dependencies.
|
|
6
|
-
*/
|
|
7
|
-
export class SystemRegistry {
|
|
8
|
-
constructor(kernel) {
|
|
9
|
-
this.kernel = kernel;
|
|
10
|
-
|
|
11
|
-
// Map<systemName, { system, priority, dependencies }>
|
|
12
|
-
this._systems = new Map();
|
|
13
|
-
|
|
14
|
-
// Pre-computed update order for performance
|
|
15
|
-
this._updateOrder = [];
|
|
16
|
-
this._fixedUpdateOrder = [];
|
|
17
|
-
|
|
18
|
-
// Flag to track if order needs recomputation
|
|
19
|
-
this._needsRecompute = false;
|
|
20
|
-
|
|
21
|
-
// Systems that have thrown from an update, so each is logged once
|
|
22
|
-
// instead of sixty times a second.
|
|
23
|
-
this._failed = new WeakSet();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Run one system's update without letting a throw stop the others.
|
|
28
|
-
* @private
|
|
29
|
-
*/
|
|
30
|
-
_run(system, method, dt) {
|
|
31
|
-
try {
|
|
32
|
-
system[method](dt);
|
|
33
|
-
} catch (error) {
|
|
34
|
-
if (!this._failed.has(system)) {
|
|
35
|
-
this._failed.add(system);
|
|
36
|
-
console.error(`[SystemRegistry] System ${method}() threw:`, error);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Register a system
|
|
43
|
-
* @param {string} name - Unique system name
|
|
44
|
-
* @param {Object} system - System instance (must implement ISystem interface)
|
|
45
|
-
* @param {Object} options - Configuration options
|
|
46
|
-
* @param {number} options.priority - Update priority (higher = earlier, default: 0)
|
|
47
|
-
* @param {string[]} options.dependencies - System names this depends on
|
|
48
|
-
* @returns {SystemRegistry} - For chaining
|
|
49
|
-
*/
|
|
50
|
-
register(name, system, { priority = 0, dependencies = [] } = {}) {
|
|
51
|
-
if (this._systems.has(name)) {
|
|
52
|
-
console.warn(`[SystemRegistry] System "${name}" already registered. Replacing.`);
|
|
53
|
-
this.unregister(name);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Validate dependencies exist
|
|
57
|
-
for (const dep of dependencies) {
|
|
58
|
-
if (!this._systems.has(dep)) {
|
|
59
|
-
console.warn(`[SystemRegistry] Dependency "${dep}" not found for system "${name}"`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Store system metadata
|
|
64
|
-
this._systems.set(name, {
|
|
65
|
-
system,
|
|
66
|
-
priority,
|
|
67
|
-
dependencies,
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
// Initialize the system
|
|
71
|
-
if (system.init) {
|
|
72
|
-
system.init(this.kernel);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Mark for recomputation
|
|
76
|
-
this._needsRecompute = true;
|
|
77
|
-
|
|
78
|
-
// Emit event
|
|
79
|
-
this.kernel.events.emit('system_registered', { name, system });
|
|
80
|
-
|
|
81
|
-
return this;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Get a system by name
|
|
86
|
-
* @param {string} name - System name
|
|
87
|
-
* @returns {Object|undefined} - System instance
|
|
88
|
-
*/
|
|
89
|
-
get(name) {
|
|
90
|
-
const entry = this._systems.get(name);
|
|
91
|
-
return entry ? entry.system : undefined;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Check if a system is registered
|
|
96
|
-
* @param {string} name - System name
|
|
97
|
-
* @returns {boolean}
|
|
98
|
-
*/
|
|
99
|
-
has(name) {
|
|
100
|
-
return this._systems.has(name);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Unregister a system
|
|
105
|
-
* @param {string} name - System name
|
|
106
|
-
* @returns {boolean} - True if system was found and removed
|
|
107
|
-
*/
|
|
108
|
-
unregister(name) {
|
|
109
|
-
const entry = this._systems.get(name);
|
|
110
|
-
if (!entry) {
|
|
111
|
-
return false;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// A destroy that throws must not leave the system registered.
|
|
115
|
-
try {
|
|
116
|
-
if (entry.system.destroy) {
|
|
117
|
-
entry.system.destroy();
|
|
118
|
-
}
|
|
119
|
-
} finally {
|
|
120
|
-
this._systems.delete(name);
|
|
121
|
-
this._needsRecompute = true;
|
|
122
|
-
|
|
123
|
-
// Emit event
|
|
124
|
-
this.kernel.events.emit('system_unregistered', { name });
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Update all systems (called each frame)
|
|
132
|
-
* @param {number} dt - Delta time in seconds
|
|
133
|
-
*/
|
|
134
|
-
update(dt) {
|
|
135
|
-
if (this._needsRecompute) {
|
|
136
|
-
this._recomputeUpdateOrder();
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Fast iteration - no lookups, just array access
|
|
140
|
-
for (let i = 0; i < this._updateOrder.length; i++) {
|
|
141
|
-
const system = this._updateOrder[i];
|
|
142
|
-
if (system.update) {
|
|
143
|
-
this._run(system, 'update', dt);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Fixed update for physics (called at fixed timestep)
|
|
150
|
-
* @param {number} dt - Fixed delta time
|
|
151
|
-
*/
|
|
152
|
-
fixedUpdate(dt) {
|
|
153
|
-
if (this._needsRecompute) {
|
|
154
|
-
this._recomputeUpdateOrder();
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
for (let i = 0; i < this._fixedUpdateOrder.length; i++) {
|
|
158
|
-
const system = this._fixedUpdateOrder[i];
|
|
159
|
-
if (system.fixedUpdate) {
|
|
160
|
-
this._run(system, 'fixedUpdate', dt);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Recompute the update order based on dependencies and priorities
|
|
167
|
-
* Uses topological sort for dependencies
|
|
168
|
-
* @private
|
|
169
|
-
*/
|
|
170
|
-
_recomputeUpdateOrder() {
|
|
171
|
-
const systems = Array.from(this._systems.entries());
|
|
172
|
-
|
|
173
|
-
// Build dependency graph
|
|
174
|
-
const graph = new Map();
|
|
175
|
-
const inDegree = new Map();
|
|
176
|
-
|
|
177
|
-
for (const [name, entry] of systems) {
|
|
178
|
-
graph.set(name, entry.dependencies);
|
|
179
|
-
inDegree.set(name, 0);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// Calculate in-degrees
|
|
183
|
-
for (const [name, deps] of graph) {
|
|
184
|
-
for (const dep of deps) {
|
|
185
|
-
if (inDegree.has(dep)) {
|
|
186
|
-
inDegree.set(name, inDegree.get(name) + 1);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// Topological sort (Kahn's algorithm)
|
|
192
|
-
const queue = [];
|
|
193
|
-
const sorted = [];
|
|
194
|
-
|
|
195
|
-
// Start with systems that have no dependencies
|
|
196
|
-
for (const [name, degree] of inDegree) {
|
|
197
|
-
if (degree === 0) {
|
|
198
|
-
queue.push(name);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
while (queue.length > 0) {
|
|
203
|
-
// Sort queue by priority before processing
|
|
204
|
-
queue.sort((a, b) => {
|
|
205
|
-
const priorityA = this._systems.get(a).priority;
|
|
206
|
-
const priorityB = this._systems.get(b).priority;
|
|
207
|
-
return priorityB - priorityA; // Higher priority first
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
const name = queue.shift();
|
|
211
|
-
sorted.push(name);
|
|
212
|
-
|
|
213
|
-
// Reduce in-degree for dependent systems
|
|
214
|
-
for (const [otherName, deps] of graph) {
|
|
215
|
-
if (deps.includes(name)) {
|
|
216
|
-
const newDegree = inDegree.get(otherName) - 1;
|
|
217
|
-
inDegree.set(otherName, newDegree);
|
|
218
|
-
if (newDegree === 0) {
|
|
219
|
-
queue.push(otherName);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// Check for circular dependencies
|
|
226
|
-
if (sorted.length !== systems.length) {
|
|
227
|
-
console.error('[SystemRegistry] Circular dependency detected in systems!');
|
|
228
|
-
// Fallback: just use priority order
|
|
229
|
-
sorted.length = 0;
|
|
230
|
-
sorted.push(...systems.map(([name]) => name).sort((a, b) => {
|
|
231
|
-
return this._systems.get(b).priority - this._systems.get(a).priority;
|
|
232
|
-
}));
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// Convert to system instances
|
|
236
|
-
this._updateOrder = sorted
|
|
237
|
-
.map(name => this._systems.get(name).system)
|
|
238
|
-
.filter(system => system.update);
|
|
239
|
-
|
|
240
|
-
this._fixedUpdateOrder = sorted
|
|
241
|
-
.map(name => this._systems.get(name).system)
|
|
242
|
-
.filter(system => system.fixedUpdate);
|
|
243
|
-
|
|
244
|
-
this._needsRecompute = false;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Get all registered system names
|
|
249
|
-
* @returns {string[]}
|
|
250
|
-
*/
|
|
251
|
-
getSystemNames() {
|
|
252
|
-
return Array.from(this._systems.keys());
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Clear all systems
|
|
257
|
-
*/
|
|
258
|
-
clear() {
|
|
259
|
-
for (const name of this._systems.keys()) {
|
|
260
|
-
this.unregister(name);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
package/src/core/Vector2.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 2D Vector class for position, velocity, and physics calculations.
|
|
3
|
-
*/
|
|
4
|
-
export class Vector2 {
|
|
5
|
-
constructor(x = 0, y = 0) {
|
|
6
|
-
this.x = x;
|
|
7
|
-
this.y = y;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
add(v) {
|
|
11
|
-
this.x += v.x;
|
|
12
|
-
this.y += v.y;
|
|
13
|
-
return this;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
sub(v) {
|
|
17
|
-
this.x -= v.x;
|
|
18
|
-
this.y -= v.y;
|
|
19
|
-
return this;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
scale(s) {
|
|
23
|
-
this.x *= s;
|
|
24
|
-
this.y *= s;
|
|
25
|
-
return this;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
distance(v) {
|
|
29
|
-
const dx = this.x - v.x;
|
|
30
|
-
const dy = this.y - v.y;
|
|
31
|
-
return Math.sqrt(dx * dx + dy * dy);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
normalize() {
|
|
35
|
-
const len = Math.sqrt(this.x * this.x + this.y * this.y);
|
|
36
|
-
if (len > 0) {
|
|
37
|
-
this.x /= len;
|
|
38
|
-
this.y /= len;
|
|
39
|
-
}
|
|
40
|
-
return this;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
clone() {
|
|
44
|
-
return new Vector2(this.x, this.y);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
static distance(a, b) {
|
|
48
|
-
return Math.sqrt(Math.pow(b.x - a.x, 2) + Math.pow(b.y - a.y, 2));
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { Component } from '../../core/Component.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Wraps the Dopamine ParticleSystem for a GameObject.
|
|
5
|
-
* Allows easy "Emit at my position" logic.
|
|
6
|
-
*/
|
|
7
|
-
export class ParticleEmitter extends Component {
|
|
8
|
-
constructor(particleSystem) {
|
|
9
|
-
super();
|
|
10
|
-
this.system = particleSystem;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Trigger an effect at the GameObject's current position.
|
|
15
|
-
* @param {string} effectName - 'confetti', 'fire', 'sparkle', etc.
|
|
16
|
-
* @param {object} options - override options
|
|
17
|
-
*/
|
|
18
|
-
play(effectName, options = {}) {
|
|
19
|
-
const x = this.gameObject.x;
|
|
20
|
-
const y = this.gameObject.y;
|
|
21
|
-
|
|
22
|
-
switch (effectName) {
|
|
23
|
-
case 'confetti':
|
|
24
|
-
this.system.confetti(x, y, options.count);
|
|
25
|
-
break;
|
|
26
|
-
case 'fire':
|
|
27
|
-
this.system.fire(x, y, options.count);
|
|
28
|
-
break;
|
|
29
|
-
case 'sparkle':
|
|
30
|
-
this.system.sparkle(x, y, options.count, options.color);
|
|
31
|
-
break;
|
|
32
|
-
case 'blood': // Custom shortcut for our game
|
|
33
|
-
this.system.emit({
|
|
34
|
-
x, y,
|
|
35
|
-
count: 10,
|
|
36
|
-
color: ['#8a0303', '#ff0000'],
|
|
37
|
-
speed: 4,
|
|
38
|
-
gravity: 0.1,
|
|
39
|
-
decay: 0.05
|
|
40
|
-
});
|
|
41
|
-
break;
|
|
42
|
-
default:
|
|
43
|
-
// Direct emit fallback
|
|
44
|
-
this.system.emit({
|
|
45
|
-
x, y,
|
|
46
|
-
...options
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { Component } from '../../core/Component.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Adds screen shake capability.
|
|
5
|
-
* Usually attached to the Camera or the Root Scene object.
|
|
6
|
-
*/
|
|
7
|
-
export class ScreenShake extends Component {
|
|
8
|
-
constructor() {
|
|
9
|
-
super();
|
|
10
|
-
this.intensity = 0;
|
|
11
|
-
this.duration = 0;
|
|
12
|
-
this.timer = 0;
|
|
13
|
-
this.originalPos = { x: 0, y: 0 };
|
|
14
|
-
this.isShaking = false;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
shake(intensity = 5, duration = 0.2) {
|
|
18
|
-
// Save original if not already shaking. Mid-shake the object sits at
|
|
19
|
-
// an offset, and saving that would move its resting position.
|
|
20
|
-
if (!this.isShaking) {
|
|
21
|
-
this.originalPos.x = this.gameObject.x;
|
|
22
|
-
this.originalPos.y = this.gameObject.y;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
this.intensity = intensity;
|
|
26
|
-
this.duration = duration;
|
|
27
|
-
this.timer = 0;
|
|
28
|
-
this.isShaking = true;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
update(dt) {
|
|
32
|
-
if (!this.isShaking) return;
|
|
33
|
-
|
|
34
|
-
this.timer += dt;
|
|
35
|
-
|
|
36
|
-
if (this.timer >= this.duration) {
|
|
37
|
-
this.isShaking = false;
|
|
38
|
-
this.gameObject.x = this.originalPos.x;
|
|
39
|
-
this.gameObject.y = this.originalPos.y;
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Random offset
|
|
44
|
-
const offsetX = (Math.random() - 0.5) * 2 * this.intensity;
|
|
45
|
-
const offsetY = (Math.random() - 0.5) * 2 * this.intensity;
|
|
46
|
-
|
|
47
|
-
this.gameObject.x = this.originalPos.x + offsetX;
|
|
48
|
-
this.gameObject.y = this.originalPos.y + offsetY;
|
|
49
|
-
}
|
|
50
|
-
}
|
package/src/dopamine/index.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { RewardSystem } from './core/RewardSystem.js';
|
|
2
|
-
import { DataService } from './core/DataService.js';
|
|
3
|
-
import { GameUI } from './ui/GameUI.js';
|
|
4
|
-
import { ParticleSystem } from './effects/ParticleSystem.js';
|
|
5
|
-
import { SoundManager } from './audio/SoundManager.js';
|
|
6
|
-
import './ui/dopamine.css';
|
|
7
|
-
|
|
8
|
-
export { RewardSystem, DataService, GameUI, ParticleSystem, SoundManager };
|
|
9
|
-
|
|
10
|
-
export default class Dopamine {
|
|
11
|
-
constructor(config = {}) {
|
|
12
|
-
this.config = config;
|
|
13
|
-
|
|
14
|
-
// Initialize subsystems with config
|
|
15
|
-
this.dataService = new DataService(config.data || {});
|
|
16
|
-
this.rewardSystem = new RewardSystem(this.dataService, config.rewards || {});
|
|
17
|
-
this.soundManager = new SoundManager(config.sound || {});
|
|
18
|
-
this.particleSystem = new ParticleSystem(config.particles || {});
|
|
19
|
-
this.gameUI = new GameUI(this.particleSystem);
|
|
20
|
-
|
|
21
|
-
// Bind UI to RewardSystem events
|
|
22
|
-
this._bindEvents();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async init() {
|
|
26
|
-
await this.rewardSystem.init();
|
|
27
|
-
this._syncUI();
|
|
28
|
-
return {
|
|
29
|
-
rewardSystem: this.rewardSystem,
|
|
30
|
-
gameUI: this.gameUI,
|
|
31
|
-
particleSystem: this.particleSystem,
|
|
32
|
-
soundManager: this.soundManager
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Draw the loaded player. Without this the overlay keeps its placeholder
|
|
38
|
-
* (level 1, 0 XP, streak 1) until the first event arrives.
|
|
39
|
-
* @private
|
|
40
|
-
*/
|
|
41
|
-
_syncUI() {
|
|
42
|
-
const { player } = this.rewardSystem;
|
|
43
|
-
const { total, needed, progress } = this.rewardSystem.getXPForNextLevel();
|
|
44
|
-
|
|
45
|
-
this.gameUI.updateXP(player.xp, needed, total, progress);
|
|
46
|
-
this.gameUI.updateLevel(player.level);
|
|
47
|
-
this.gameUI.updateStreak(player.streak.current);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
_bindEvents() {
|
|
51
|
-
const rewards = this.rewardSystem;
|
|
52
|
-
|
|
53
|
-
this._unsubscribe = [
|
|
54
|
-
rewards.on('xp_gained', () => {
|
|
55
|
-
const { total, needed, progress } = rewards.getXPForNextLevel();
|
|
56
|
-
this.gameUI.updateXP(rewards.player.xp, needed, total, progress);
|
|
57
|
-
}),
|
|
58
|
-
|
|
59
|
-
rewards.on('level_up', (data) => {
|
|
60
|
-
this.gameUI.updateLevel(data.newLevel);
|
|
61
|
-
this.gameUI.showLevelUp(data.oldLevel, data.newLevel);
|
|
62
|
-
}),
|
|
63
|
-
|
|
64
|
-
rewards.on('achievement_unlocked', (achievement) => {
|
|
65
|
-
this.gameUI.showAchievement(achievement);
|
|
66
|
-
}),
|
|
67
|
-
|
|
68
|
-
rewards.on('streak_updated', (data) => {
|
|
69
|
-
this.gameUI.updateStreak(data.current);
|
|
70
|
-
}),
|
|
71
|
-
|
|
72
|
-
rewards.on('new_high_score', (data) => {
|
|
73
|
-
this.gameUI.showNotification(`New High Score: ${data.score}!`, 'legendary');
|
|
74
|
-
this.soundManager.playSuccess();
|
|
75
|
-
})
|
|
76
|
-
];
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Remove the overlay and canvas, stop audio, and detach from the reward
|
|
81
|
-
* system. The reward system itself stays usable.
|
|
82
|
-
*/
|
|
83
|
-
destroy() {
|
|
84
|
-
for (const unsubscribe of this._unsubscribe) {
|
|
85
|
-
unsubscribe();
|
|
86
|
-
}
|
|
87
|
-
this._unsubscribe = [];
|
|
88
|
-
|
|
89
|
-
this.gameUI.destroy();
|
|
90
|
-
this.particleSystem.destroy();
|
|
91
|
-
this.soundManager.destroy();
|
|
92
|
-
}
|
|
93
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generates procedural textures for prototyping.
|
|
3
|
-
*/
|
|
4
|
-
export class TextureGenerator {
|
|
5
|
-
static createGround(width, height, color = '#333') {
|
|
6
|
-
const canvas = document.createElement('canvas');
|
|
7
|
-
canvas.width = width;
|
|
8
|
-
canvas.height = height;
|
|
9
|
-
const ctx = canvas.getContext('2d');
|
|
10
|
-
|
|
11
|
-
ctx.fillStyle = color;
|
|
12
|
-
ctx.fillRect(0, 0, width, height);
|
|
13
|
-
|
|
14
|
-
// Noise / Grit
|
|
15
|
-
for (let i = 0; i < 1000; i++) {
|
|
16
|
-
ctx.fillStyle = Math.random() > 0.5 ? '#444' : '#222';
|
|
17
|
-
const size = Math.random() * 4 + 2;
|
|
18
|
-
ctx.fillRect(Math.random() * width, Math.random() * height, size, size);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Grid lines overlay (faint)
|
|
22
|
-
ctx.strokeStyle = 'rgba(255,255,255,0.05)';
|
|
23
|
-
ctx.lineWidth = 2;
|
|
24
|
-
ctx.beginPath();
|
|
25
|
-
for (let i = 0; i <= width; i += 64) {
|
|
26
|
-
ctx.moveTo(i, 0); ctx.lineTo(i, height);
|
|
27
|
-
}
|
|
28
|
-
for (let i = 0; i <= height; i += 64) {
|
|
29
|
-
ctx.moveTo(0, i); ctx.lineTo(width, i);
|
|
30
|
-
}
|
|
31
|
-
ctx.stroke();
|
|
32
|
-
|
|
33
|
-
return canvas;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
static createCharacterSheet(colorBody, colorDetail) {
|
|
37
|
-
// Create a 4-frame walk cycle strip (Vertical or Horizontal)
|
|
38
|
-
// Let's do Horizontal: 64x64 frames, 4 frames -> 256x64 image
|
|
39
|
-
const cellW = 64;
|
|
40
|
-
const cellH = 64;
|
|
41
|
-
const canvas = document.createElement('canvas');
|
|
42
|
-
canvas.width = cellW * 4;
|
|
43
|
-
canvas.height = cellH;
|
|
44
|
-
const ctx = canvas.getContext('2d');
|
|
45
|
-
|
|
46
|
-
for (let i = 0; i < 4; i++) {
|
|
47
|
-
const x = i * cellW;
|
|
48
|
-
const y = 0;
|
|
49
|
-
const cx = x + cellW / 2;
|
|
50
|
-
const cy = y + cellH / 2;
|
|
51
|
-
|
|
52
|
-
// -- Frame Animation Variances --
|
|
53
|
-
// Bobbing effect
|
|
54
|
-
const bob = (i % 2 === 0) ? 0 : -2;
|
|
55
|
-
// Leg swing (simulated by shape change or just simple offset)
|
|
56
|
-
const legOffset = (i === 1) ? 5 : (i === 3 ? -5 : 0);
|
|
57
|
-
|
|
58
|
-
// Body
|
|
59
|
-
ctx.fillStyle = colorBody;
|
|
60
|
-
ctx.beginPath();
|
|
61
|
-
ctx.arc(cx, cy + bob, 20, 0, Math.PI * 2);
|
|
62
|
-
ctx.fill();
|
|
63
|
-
|
|
64
|
-
// Shoulders/Hands (Top Down)
|
|
65
|
-
ctx.fillStyle = colorDetail;
|
|
66
|
-
ctx.beginPath();
|
|
67
|
-
ctx.arc(cx - 15, cy + bob + legOffset, 8, 0, Math.PI * 2); // Left hand
|
|
68
|
-
ctx.arc(cx + 15, cy + bob - legOffset, 8, 0, Math.PI * 2); // Right hand
|
|
69
|
-
ctx.fill();
|
|
70
|
-
|
|
71
|
-
// Head/Helmet
|
|
72
|
-
ctx.fillStyle = adjustColor(colorBody, -20);
|
|
73
|
-
ctx.beginPath();
|
|
74
|
-
ctx.arc(cx, cy + bob, 15, 0, Math.PI * 2);
|
|
75
|
-
ctx.fill();
|
|
76
|
-
|
|
77
|
-
// Gun (if soldier)
|
|
78
|
-
if (colorDetail === '#333') { // Hacky check
|
|
79
|
-
ctx.fillStyle = '#000';
|
|
80
|
-
ctx.fillRect(cx + 10, cy + bob - 5, 25, 6);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return canvas;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function adjustColor(color, amount) {
|
|
89
|
-
return color; // Placeholder for color darkening logic
|
|
90
|
-
}
|
package/src/engine.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Engine subpath export — `import { Game, Scene } from 'dopaminejs/engine'`
|
|
3
|
-
*
|
|
4
|
-
* The game engine that DopamineJS is built on. Use this subpath if your project
|
|
5
|
-
* only needs the entity/component system, renderer, or physics, and not the
|
|
6
|
-
* progression mechanics (RewardSystem, GameUI, DataService).
|
|
7
|
-
*
|
|
8
|
-
* The root `dopaminejs` export continues to re-export everything, so nothing breaks.
|
|
9
|
-
* This subpath makes the README's distinction between the engine and the progression
|
|
10
|
-
* layer real in code and gives bundlers a clear surface to tree-shake against.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
// Entity / component system
|
|
14
|
-
export { Game } from './core/Game.js';
|
|
15
|
-
export { Scene } from './core/Scene.js';
|
|
16
|
-
export { GameObject } from './core/GameObject.js';
|
|
17
|
-
export { Component } from './core/Component.js';
|
|
18
|
-
export { Vector2 } from './core/Vector2.js';
|
|
19
|
-
export { Collider } from './core/Collider.js';
|
|
20
|
-
export { Sprite } from './core/Sprite.js';
|
|
21
|
-
export { Animator } from './core/Animator.js';
|
|
22
|
-
|
|
23
|
-
// Kernel and plugin infrastructure
|
|
24
|
-
export { DopamineKernel } from './core/DopamineKernel.js';
|
|
25
|
-
export { EventBus } from './core/EventBus.js';
|
|
26
|
-
export { SystemRegistry } from './core/SystemRegistry.js';
|
|
27
|
-
export { PluginRegistry } from './core/PluginRegistry.js';
|
|
28
|
-
|
|
29
|
-
// Built-in systems
|
|
30
|
-
export { Renderer } from './renderer/Renderer.js';
|
|
31
|
-
export { Ticker } from './systems/Ticker.js';
|
|
32
|
-
export { Loader, GlobalLoader } from './systems/Loader.js';
|
|
33
|
-
export { Input, GlobalInput } from './systems/Input.js';
|
|
34
|
-
export { Director } from './systems/Director.js';
|
|
35
|
-
export { Physics, GlobalPhysics } from './systems/Physics.js';
|
|
36
|
-
|
|
37
|
-
// Engine-level components
|
|
38
|
-
export { ParticleEmitter, ScreenShake } from './dopamine/components/index.js';
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { ISystem } from './ISystem.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* IAudioSystem - Interface for audio implementations
|
|
5
|
-
*
|
|
6
|
-
* Allows different audio engines (Web Audio, Howler.js, etc.) to be swapped
|
|
7
|
-
*/
|
|
8
|
-
export const IAudioSystem = {
|
|
9
|
-
...ISystem,
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Register a sound with a key
|
|
13
|
-
* @param {string} key - Sound identifier
|
|
14
|
-
* @param {string} url - Path to audio file
|
|
15
|
-
*/
|
|
16
|
-
registerSound(key, url) { },
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Preload multiple sounds
|
|
20
|
-
* @param {Object} soundMap - Map of key -> url
|
|
21
|
-
* @returns {Promise<void>}
|
|
22
|
-
*/
|
|
23
|
-
preloadSounds(soundMap) { },
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Play a sound by key
|
|
27
|
-
* @param {string} key - Sound identifier
|
|
28
|
-
* @param {Object} options - Playback options (volume, loop, etc.)
|
|
29
|
-
*/
|
|
30
|
-
play(key, options) { },
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Play a synthesized tone
|
|
34
|
-
* @param {number} frequency - Frequency in Hz
|
|
35
|
-
* @param {number} duration - Duration in seconds
|
|
36
|
-
* @param {string} type - Waveform type ('sine', 'square', etc.)
|
|
37
|
-
* @param {number} volume - Volume (0-1)
|
|
38
|
-
*/
|
|
39
|
-
playTone(frequency, duration, type, volume) { },
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Stop a playing sound
|
|
43
|
-
* @param {string} key - Sound identifier
|
|
44
|
-
*/
|
|
45
|
-
stop(key) { },
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Toggle mute state
|
|
49
|
-
* @returns {boolean} - New mute state
|
|
50
|
-
*/
|
|
51
|
-
toggleMute() { },
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Set master volume
|
|
55
|
-
* @param {number} volume - Volume (0-1)
|
|
56
|
-
*/
|
|
57
|
-
setVolume(volume) { },
|
|
58
|
-
};
|