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/src/games.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Game feedback as a plugin: combo, near miss, lucky moment and the run
|
|
3
|
+
* summary, drawn through the ui and particles parts, plus the jump, score and
|
|
4
|
+
* gameover sounds. Nothing here runs at import time.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const TEXT = {
|
|
8
|
+
combo: '{n}× COMBO!',
|
|
9
|
+
nearMiss: 'CLOSE CALL!',
|
|
10
|
+
luckyMoment: 'LUCKY {n}×!',
|
|
11
|
+
gameOver: 'Game Over',
|
|
12
|
+
playAgain: 'Play Again',
|
|
13
|
+
exit: 'Exit'
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const hasOwn = (object, key) => Object.prototype.hasOwnProperty.call(object, key);
|
|
17
|
+
|
|
18
|
+
const SOUNDS = {
|
|
19
|
+
jump: (s) => s.playTone(400, 0.1, 'square', 0.2),
|
|
20
|
+
score: (s, later) => {
|
|
21
|
+
s.playTone(800, 0.15, 'sine', 0.25);
|
|
22
|
+
later(() => s.playTone(1000, 0.15, 'sine', 0.25), 50);
|
|
23
|
+
},
|
|
24
|
+
gameover: (s, later) => {
|
|
25
|
+
s.playTone(300, 0.2, 'sawtooth', 0.3);
|
|
26
|
+
later(() => s.playTone(200, 0.2, 'sawtooth', 0.3), 100);
|
|
27
|
+
later(() => s.playTone(150, 0.3, 'sawtooth', 0.3), 200);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const el = (tag, text, css) => {
|
|
32
|
+
const node = document.createElement(tag);
|
|
33
|
+
if (text !== undefined) node.textContent = text;
|
|
34
|
+
if (css) node.style.cssText = css;
|
|
35
|
+
return node;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param {Object} [options]
|
|
40
|
+
* @param {{combo?: string, nearMiss?: string, luckyMoment?: string,
|
|
41
|
+
* gameOver?: string, playAgain?: string, exit?: string}} [options.text]
|
|
42
|
+
* Replaces the built-in strings. `{n}` is the multiplier. An empty string
|
|
43
|
+
* hides that text.
|
|
44
|
+
*/
|
|
45
|
+
export function gameFeedback(options) {
|
|
46
|
+
const strings = { ...TEXT };
|
|
47
|
+
const custom = options !== null && typeof options === 'object' && hasOwn(options, 'text') ? options.text : null;
|
|
48
|
+
for (const key of Object.keys(TEXT)) {
|
|
49
|
+
if (custom !== null && typeof custom === 'object' && hasOwn(custom, key) && typeof custom[key] === 'string') {
|
|
50
|
+
strings[key] = custom[key];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let ctx = null;
|
|
55
|
+
const overlays = new Set();
|
|
56
|
+
|
|
57
|
+
const text = (key, n, x, y, color, size) => {
|
|
58
|
+
const label = strings[key].replace('{n}', () => String(n));
|
|
59
|
+
if (label !== '') ctx.parts.ui.text({ text: label, x, y, color, size });
|
|
60
|
+
};
|
|
61
|
+
const burst = (kind, x, y, opts) => ctx.parts.particles?.burst(kind, { x, y }, opts);
|
|
62
|
+
|
|
63
|
+
const feedback = {
|
|
64
|
+
name: 'games',
|
|
65
|
+
version: '1.0.0',
|
|
66
|
+
api: 3,
|
|
67
|
+
requires: ['ui'],
|
|
68
|
+
|
|
69
|
+
combo(multiplier, x, y) {
|
|
70
|
+
if (!ctx) return;
|
|
71
|
+
text('combo', multiplier, x, y, '#ff6b6b', '32px');
|
|
72
|
+
burst('fire', x, y, { count: 20 });
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
nearMiss(x, y) {
|
|
76
|
+
if (!ctx) return;
|
|
77
|
+
text('nearMiss', '', x, y, '#45b7d1', '20px');
|
|
78
|
+
burst('sparkle', x, y, { count: 15, color: '#45b7d1' });
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
luckyMoment(multiplier, x, y) {
|
|
82
|
+
if (!ctx) return;
|
|
83
|
+
text('luckyMoment', multiplier, x, y, '#ffd700', '36px');
|
|
84
|
+
burst('stars', x, y, { count: 12 });
|
|
85
|
+
burst('confetti', x, y, { count: 25 });
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @param {{ score: number|string, metrics?: Object, onReplay?: Function, onExit?: Function }} data
|
|
90
|
+
* @returns {HTMLElement|null} The overlay, removed when the plugin is disposed.
|
|
91
|
+
*/
|
|
92
|
+
summary(data) {
|
|
93
|
+
if (!ctx || !ctx.env.hasDom || data === null || typeof data !== 'object') return null;
|
|
94
|
+
const box = el('div', undefined, 'display:flex;flex-direction:column;align-items:center;position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);z-index:1000');
|
|
95
|
+
box.className = 'message-box';
|
|
96
|
+
if (strings.gameOver !== '') box.append(el('h1', strings.gameOver));
|
|
97
|
+
box.append(el('div', data.score, 'font-size:3rem;font-weight:bold;color:#e06020;margin:10px 0'));
|
|
98
|
+
|
|
99
|
+
const metrics = el('div', undefined, 'width:100%;margin-bottom:20px');
|
|
100
|
+
const list = data.metrics !== null && typeof data.metrics === 'object' ? data.metrics : {};
|
|
101
|
+
for (const [label, value] of Object.entries(list)) {
|
|
102
|
+
const row = el('div', undefined, 'display:flex;justify-content:space-between;width:100%');
|
|
103
|
+
row.append(el('span', `${label}:`), el('strong', value));
|
|
104
|
+
metrics.append(row);
|
|
105
|
+
}
|
|
106
|
+
box.append(metrics);
|
|
107
|
+
|
|
108
|
+
// Listeners, not onclick attributes, so a script-src CSP allows it.
|
|
109
|
+
const button = (label, handler) => {
|
|
110
|
+
const b = el('button', label);
|
|
111
|
+
b.className = 'btn';
|
|
112
|
+
b.addEventListener('click', handler);
|
|
113
|
+
box.append(b);
|
|
114
|
+
};
|
|
115
|
+
if (strings.playAgain !== '') {
|
|
116
|
+
button(strings.playAgain, typeof data.onReplay === 'function' ? data.onReplay : () => window.location.reload());
|
|
117
|
+
}
|
|
118
|
+
if (typeof data.onExit === 'function' && strings.exit !== '') button(strings.exit, data.onExit);
|
|
119
|
+
|
|
120
|
+
document.body.append(box);
|
|
121
|
+
overlays.add(box);
|
|
122
|
+
return box;
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
install(context) {
|
|
126
|
+
ctx = context;
|
|
127
|
+
const removers = Object.keys(SOUNDS).map((key) => ctx.parts.sound?.register?.(key, SOUNDS[key]));
|
|
128
|
+
context.expose(feedback);
|
|
129
|
+
return () => {
|
|
130
|
+
for (const remove of removers) remove?.();
|
|
131
|
+
for (const box of overlays) box.remove();
|
|
132
|
+
overlays.clear();
|
|
133
|
+
ctx = null;
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
return feedback;
|
|
138
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
11
|
-
|
|
12
|
-
// Export System Interfaces
|
|
13
|
-
export * from './interfaces/index.js';
|
|
1
|
+
// Importing this module does nothing. Styles come from `dopaminejs/style.css`
|
|
2
|
+
// or RewardUI's `injectCss` option.
|
|
3
|
+
export { createDopamine, HOST_API } from './dopamine/host.js';
|
|
4
|
+
export { RewardSystem } from './dopamine/core/RewardSystem.js';
|
|
5
|
+
export { DataService } from './dopamine/core/DataService.js';
|
|
6
|
+
export { DopamineError } from './dopamine/core/DopamineError.js';
|
|
7
|
+
export { merge } from './dopamine/core/merge.js';
|
|
8
|
+
export { validate } from './dopamine/core/store.js';
|
|
9
|
+
export { RewardUI } from './dopamine/ui/RewardUI.js';
|
|
10
|
+
export { ParticleSystem } from './dopamine/effects/ParticleSystem.js';
|
|
11
|
+
export { SoundManager } from './dopamine/audio/SoundManager.js';
|
|
14
12
|
|
|
15
13
|
// The emitter RewardSystem extends, so consumers can type their listeners.
|
|
16
14
|
export { EventEmitter } from './dopamine/core/EventEmitter.js';
|
|
@@ -18,23 +16,6 @@ export { EventEmitter } from './dopamine/core/EventEmitter.js';
|
|
|
18
16
|
// Storage resolution, useful for tests and for SSR where localStorage is absent.
|
|
19
17
|
export { createMemoryStorage, resolveStorage } from './dopamine/utils/storage.js';
|
|
20
18
|
|
|
21
|
-
//
|
|
22
|
-
export {
|
|
23
|
-
export {
|
|
24
|
-
export { GameObject } from './core/GameObject.js';
|
|
25
|
-
export { Component } from './core/Component.js';
|
|
26
|
-
export { Renderer } from './renderer/Renderer.js';
|
|
27
|
-
export { Ticker } from './systems/Ticker.js';
|
|
28
|
-
export { Loader, GlobalLoader } from './systems/Loader.js';
|
|
29
|
-
export { Input, GlobalInput } from './systems/Input.js';
|
|
30
|
-
export { Director } from './systems/Director.js';
|
|
31
|
-
export { Physics, GlobalPhysics } from './systems/Physics.js';
|
|
32
|
-
export { Vector2 } from './core/Vector2.js';
|
|
33
|
-
export { Collider } from './core/Collider.js';
|
|
34
|
-
export { Sprite } from './core/Sprite.js';
|
|
35
|
-
export { Animator } from './core/Animator.js';
|
|
36
|
-
export { TextureGenerator } from './dopamine/utils/TextureGenerator.js';
|
|
37
|
-
export { ParticleEmitter, ScreenShake } from './dopamine/components/index.js';
|
|
38
|
-
|
|
39
|
-
// Export default for backward compatibility
|
|
40
|
-
export default Dopamine;
|
|
19
|
+
// Feel helpers: vibration and the reduced-motion preference
|
|
20
|
+
export { createHaptics } from './dopamine/feel/haptics.js';
|
|
21
|
+
export { prefersReducedMotion } from './dopamine/feel/motion.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core subpath export: `import { RewardSystem } from 'dopaminejs/core'`
|
|
3
|
+
*
|
|
4
|
+
* The progression API with no UI, effects, sound or engine behind it, so it
|
|
5
|
+
* loads in React Native, Expo and other runtimes that have no browser. Nothing
|
|
6
|
+
* reachable from here may touch window, document, localStorage or navigator
|
|
7
|
+
* at import time. scripts/check-core-import.js enforces that against the build.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export { RewardSystem } from './dopamine/core/RewardSystem.js';
|
|
11
|
+
export { DopamineError } from './dopamine/core/DopamineError.js';
|
|
12
|
+
export { merge } from './dopamine/core/merge.js';
|
|
13
|
+
export { validate } from './dopamine/core/store.js';
|
|
14
|
+
export { DataService } from './dopamine/core/DataService.js';
|
|
15
|
+
export { EventEmitter } from './dopamine/core/EventEmitter.js';
|
|
16
|
+
export { createMemoryStorage, resolveStorage } from './dopamine/utils/storage.js';
|