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
package/spec/schema.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://github.com/BaryoDev/dopaminejs/spec/schema.json",
|
|
4
|
+
"title": "DopamineJS player document, contract 3",
|
|
5
|
+
"description": "What export() returns and what validate() and merge() accept. Only v is required on input; validate fills in the rest. Keys inside the per-device maps are device ids, which are never __proto__, constructor or prototype, and a document holds at most 20 of them across xpBy, xpSpentBy, gamesBy, playsBy and sumsBy.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"required": ["v"],
|
|
8
|
+
"additionalProperties": false,
|
|
9
|
+
"properties": {
|
|
10
|
+
"v": { "const": 3 },
|
|
11
|
+
"name": { "type": "string" },
|
|
12
|
+
"createdAt": { "type": "number" },
|
|
13
|
+
"lastPlayedAt": { "type": "number" },
|
|
14
|
+
"level": { "type": "integer", "minimum": 1 },
|
|
15
|
+
"longest": { "type": "integer", "minimum": 0 },
|
|
16
|
+
"playDates": {
|
|
17
|
+
"type": "array",
|
|
18
|
+
"items": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$" }
|
|
19
|
+
},
|
|
20
|
+
"xpBy": { "$ref": "#/$defs/amounts" },
|
|
21
|
+
"xpSpentBy": { "$ref": "#/$defs/amounts" },
|
|
22
|
+
"gamesBy": { "$ref": "#/$defs/counts" },
|
|
23
|
+
"playsBy": {
|
|
24
|
+
"type": "object",
|
|
25
|
+
"additionalProperties": { "$ref": "#/$defs/counts" }
|
|
26
|
+
},
|
|
27
|
+
"best": { "$ref": "#/$defs/amounts" },
|
|
28
|
+
"sumsBy": {
|
|
29
|
+
"type": "object",
|
|
30
|
+
"additionalProperties": {
|
|
31
|
+
"type": "object",
|
|
32
|
+
"additionalProperties": {
|
|
33
|
+
"type": "object",
|
|
34
|
+
"additionalProperties": { "type": "number" }
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"achievements": {
|
|
39
|
+
"type": "object",
|
|
40
|
+
"additionalProperties": {
|
|
41
|
+
"type": "object",
|
|
42
|
+
"additionalProperties": false,
|
|
43
|
+
"properties": {
|
|
44
|
+
"unlockedAt": { "type": "number" },
|
|
45
|
+
"seen": { "type": "boolean" },
|
|
46
|
+
"reward": { "type": "number", "minimum": 0 }
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"$defs": {
|
|
52
|
+
"amounts": {
|
|
53
|
+
"type": "object",
|
|
54
|
+
"additionalProperties": { "type": "number", "minimum": 0 }
|
|
55
|
+
},
|
|
56
|
+
"counts": {
|
|
57
|
+
"type": "object",
|
|
58
|
+
"additionalProperties": { "type": "integer", "minimum": 0 }
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -30,6 +30,9 @@ export class SoundManager {
|
|
|
30
30
|
// Queued follow-up tones, so destroy() can cancel them.
|
|
31
31
|
this._timers = new Set();
|
|
32
32
|
|
|
33
|
+
// Synth keys added by plugins, by own key.
|
|
34
|
+
this._synths = new Map();
|
|
35
|
+
|
|
33
36
|
// unlockOn removers, so destroy() takes listeners that never fired off too.
|
|
34
37
|
this._unlocks = new Set();
|
|
35
38
|
}
|
|
@@ -149,6 +152,29 @@ export class SoundManager {
|
|
|
149
152
|
}
|
|
150
153
|
}
|
|
151
154
|
|
|
155
|
+
/**
|
|
156
|
+
* Add a sound key. A string is a file URL. A function is a synth,
|
|
157
|
+
* called as `(sound, later)` when the key plays; `later(fn, ms)` is a
|
|
158
|
+
* timeout that destroy() cancels. Returns a remover.
|
|
159
|
+
* @param {string} key
|
|
160
|
+
* @param {string|Function} source
|
|
161
|
+
*/
|
|
162
|
+
register(key, source) {
|
|
163
|
+
if (typeof key !== 'string' || key === '') return () => {};
|
|
164
|
+
if (typeof source === 'string') {
|
|
165
|
+
this.registerSound(key, source);
|
|
166
|
+
return () => {
|
|
167
|
+
if (this.customSounds[key] === source) delete this.customSounds[key];
|
|
168
|
+
this.assets.delete(key);
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
if (typeof source !== 'function') return () => {};
|
|
172
|
+
this._synths.set(key, source);
|
|
173
|
+
return () => {
|
|
174
|
+
if (this._synths.get(key) === source) this._synths.delete(key);
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
152
178
|
/**
|
|
153
179
|
* Register and load multiple sounds. Before the audio context exists the
|
|
154
180
|
* files cannot be decoded, so they load when initAudio() creates it.
|
|
@@ -207,7 +233,8 @@ export class SoundManager {
|
|
|
207
233
|
|
|
208
234
|
/**
|
|
209
235
|
* Play a sound by key (custom) or fallback to synth
|
|
210
|
-
* @param {string} key - '
|
|
236
|
+
* @param {string} key - A preset ('xp', 'level_up', 'achievement', 'personal_best',
|
|
237
|
+
* 'click', 'error'), a registered key, or a synth name. An unknown key is ignored.
|
|
211
238
|
*/
|
|
212
239
|
async play(key) {
|
|
213
240
|
if (this.muted) return;
|
|
@@ -236,15 +263,17 @@ export class SoundManager {
|
|
|
236
263
|
|
|
237
264
|
// 3. Fallback to synth based on key name
|
|
238
265
|
const synthMap = {
|
|
239
|
-
'
|
|
240
|
-
'
|
|
241
|
-
'
|
|
266
|
+
'xp': () => this.playXP(true),
|
|
267
|
+
'level_up': () => this.playLevelUp(true),
|
|
268
|
+
'achievement': () => this.playAchievement(true),
|
|
269
|
+
'personal_best': () => this.playPersonalBest(true),
|
|
242
270
|
'click': () => this.playClick(true),
|
|
243
|
-
'error': () => this.playError(true)
|
|
244
|
-
'gameover': () => this.playGameOver(true)
|
|
271
|
+
'error': () => this.playError(true)
|
|
245
272
|
};
|
|
246
273
|
|
|
247
|
-
if (
|
|
274
|
+
if (this._synths.has(key)) {
|
|
275
|
+
this._synths.get(key)(this, (fn, delay) => this._later(fn, delay));
|
|
276
|
+
} else if (hasOwn(synthMap, key)) {
|
|
248
277
|
synthMap[key]();
|
|
249
278
|
}
|
|
250
279
|
}
|
|
@@ -283,31 +312,31 @@ export class SoundManager {
|
|
|
283
312
|
|
|
284
313
|
// --- Presets (Synth) ---
|
|
285
314
|
|
|
286
|
-
|
|
287
|
-
if (!force && this.assets.has('
|
|
288
|
-
this.playTone(
|
|
315
|
+
playClick(force = false) {
|
|
316
|
+
if (!force && this.assets.has('click')) return this.play('click');
|
|
317
|
+
this.playTone(600, 0.05, 'sine', 0.1);
|
|
289
318
|
}
|
|
290
319
|
|
|
291
|
-
|
|
292
|
-
if (!force && this.assets.has('
|
|
293
|
-
this.playTone(
|
|
294
|
-
this._later(() => this.playTone(1000, 0.15, 'sine', 0.25), 50);
|
|
320
|
+
playXP(force = false) {
|
|
321
|
+
if (!force && this.assets.has('xp')) return this.play('xp');
|
|
322
|
+
this.playTone(700, 0.06, 'sine', 0.12);
|
|
295
323
|
}
|
|
296
324
|
|
|
297
|
-
|
|
298
|
-
if (!force && this.assets.has('
|
|
299
|
-
this.playTone(
|
|
300
|
-
this._later(() => this.playTone(
|
|
301
|
-
this._later(() => this.playTone(
|
|
325
|
+
playLevelUp(force = false) {
|
|
326
|
+
if (!force && this.assets.has('level_up')) return this.play('level_up');
|
|
327
|
+
this.playTone(500, 0.12, 'sine', 0.2);
|
|
328
|
+
this._later(() => this.playTone(700, 0.12, 'sine', 0.2), 110);
|
|
329
|
+
this._later(() => this.playTone(900, 0.25, 'sine', 0.2), 220);
|
|
302
330
|
}
|
|
303
331
|
|
|
304
|
-
|
|
305
|
-
if (!force && this.assets.has('
|
|
306
|
-
this.playTone(
|
|
332
|
+
playAchievement(force = false) {
|
|
333
|
+
if (!force && this.assets.has('achievement')) return this.play('achievement');
|
|
334
|
+
this.playTone(660, 0.1, 'triangle', 0.2);
|
|
335
|
+
this._later(() => this.playTone(990, 0.25, 'triangle', 0.2), 100);
|
|
307
336
|
}
|
|
308
337
|
|
|
309
|
-
|
|
310
|
-
if (!force && this.assets.has('
|
|
338
|
+
playPersonalBest(force = false) {
|
|
339
|
+
if (!force && this.assets.has('personal_best')) return this.play('personal_best');
|
|
311
340
|
this.playTone(600, 0.1, 'sine', 0.2);
|
|
312
341
|
this._later(() => this.playTone(800, 0.2, 'sine', 0.2), 100);
|
|
313
342
|
}
|
|
@@ -338,5 +367,6 @@ export class SoundManager {
|
|
|
338
367
|
this.masterGain = null;
|
|
339
368
|
this.assets.clear();
|
|
340
369
|
this._loading.clear();
|
|
370
|
+
this._synths.clear();
|
|
341
371
|
}
|
|
342
372
|
}
|