dopaminejs 2.3.1 → 2.4.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/dist/style.css CHANGED
@@ -1 +1,2 @@
1
- #game-ui-overlay,.game-ui-overlay{position:fixed;top:0;left:0;width:100%;pointer-events:none;z-index:1000;font-family:Inter,-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif}.game-ui-top-bar{display:flex;align-items:center;gap:12px;padding:12px 16px;background:#0000004d;-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px)}.level-badge{display:flex;flex-direction:column;align-items:center;background:linear-gradient(135deg,#667eea,#764ba2);padding:8px 12px;border-radius:12px;box-shadow:0 4px 12px #667eea66;min-width:60px}.level-label{font-size:10px;font-weight:600;color:#fffc;letter-spacing:.5px}.level-number{font-size:24px;font-weight:800;color:#fff;line-height:1}.xp-container{flex:1;display:flex;flex-direction:column;gap:4px}.xp-bar-bg{height:12px;background:#fff3;border-radius:6px;overflow:hidden;box-shadow:inset 0 2px 4px #0003}.xp-bar-fill{height:100%;background:linear-gradient(90deg,#4facfe,#00f2fe);border-radius:6px;transition:width .5s ease-out;box-shadow:0 0 10px #4facfe99}.xp-text{font-size:11px;color:#fff;font-weight:600;text-align:center;text-shadow:0 1px 2px rgba(0,0,0,.5)}.streak-badge{display:flex;align-items:center;gap:6px;background:linear-gradient(135deg,#f80,#f40);padding:8px 12px;border-radius:12px;box-shadow:0 4px 12px #f806}.streak-icon{font-size:20px;animation:flicker 2s infinite}.streak-number{font-size:18px;font-weight:800;color:#fff}.achievement-popup{position:fixed;top:80px;right:20px;background:linear-gradient(135deg,#667eea,#764ba2);border-radius:16px;padding:16px;box-shadow:0 8px 32px #0006;animation:slideIn .5s cubic-bezier(.68,-.55,.265,1.55);z-index:10000;max-width:320px;overflow:hidden}.achievement-shine{position:absolute;top:0;left:-100%;width:100%;height:100%;background:linear-gradient(90deg,transparent,rgba(255,255,255,.3),transparent);animation:shine 2s infinite}.achievement-content{position:relative;display:flex;gap:12px;align-items:center}.achievement-icon{font-size:48px;animation:bounce .6s ease-out}.achievement-info{flex:1}.achievement-title{font-size:12px;font-weight:600;color:#ffffffe6;text-transform:uppercase;letter-spacing:.5px}.achievement-name{font-size:18px;font-weight:800;color:#fff;margin:2px 0}.achievement-desc{font-size:13px;color:#fffc;margin-bottom:4px}.achievement-xp{display:inline-block;background:#fff3;padding:4px 8px;border-radius:8px;font-size:12px;font-weight:700;color:gold}.level-up-overlay{position:fixed;top:0;left:0;width:100%;height:100%;background:#000000d9;display:flex;align-items:center;justify-content:center;z-index:10001;animation:fadeIn .3s ease-out}.level-up-content{text-align:center;animation:scaleIn .5s cubic-bezier(.68,-.55,.265,1.55)}.level-up-title{font-size:32px;font-weight:800;background:linear-gradient(135deg,gold,#ffed4e);-webkit-background-clip:text;-webkit-text-fill-color:transparent;background-clip:text;text-transform:uppercase;letter-spacing:4px;margin-bottom:16px}.level-up-number{font-size:120px;font-weight:900;color:#fff;text-shadow:0 0 20px rgba(255,215,0,.8),0 0 40px rgba(255,215,0,.6),0 0 60px rgba(255,215,0,.4);animation:glow 1s ease-in-out infinite alternate}.level-up-subtitle{font-size:24px;color:#fffc;font-weight:600;margin-top:16px}.floating-text{position:fixed;font-weight:800;text-shadow:2px 2px 0 #000,-1px -1px 0 #000,1px -1px 0 #000,-1px 1px 0 #000;pointer-events:none;z-index:9998;animation:floatUp 2s ease-out forwards}@keyframes slideIn{0%{transform:translate(400px);opacity:0}to{transform:translate(0);opacity:1}}@keyframes slideOut{0%{transform:translate(0);opacity:1}to{transform:translate(400px);opacity:0}}@keyframes fadeIn{0%{opacity:0}to{opacity:1}}@keyframes scaleIn{0%{transform:scale(.5);opacity:0}to{transform:scale(1);opacity:1}}@keyframes bounce{0%,to{transform:translateY(0)}50%{transform:translateY(-10px)}}@keyframes glow{0%{text-shadow:0 0 20px rgba(255,215,0,.8),0 0 40px rgba(255,215,0,.6),0 0 60px rgba(255,215,0,.4)}to{text-shadow:0 0 30px rgba(255,215,0,1),0 0 60px rgba(255,215,0,.8),0 0 90px rgba(255,215,0,.6)}}@keyframes shine{0%{left:-100%}30%{left:100%}to{left:100%}}@keyframes flicker{0%,to{opacity:1}50%{opacity:.8}}@keyframes floatUp{0%{transform:translateY(0);opacity:1}to{transform:translateY(-100px);opacity:0}}@keyframes xp-pulse{0%{transform:scaleY(1)}50%{transform:scaleY(1.2)}to{transform:scaleY(1)}}@keyframes level-pulse{0%{transform:scale(1)}50%{transform:scale(1.1)}to{transform:scale(1)}}@media(max-width:480px){.game-ui-top-bar{gap:8px;padding:10px 12px}.level-badge{padding:6px 10px;min-width:50px}.level-number{font-size:20px}.xp-bar-bg{height:10px}.xp-text{font-size:10px}.achievement-popup{right:12px;max-width:calc(100% - 24px)}.level-up-number{font-size:80px}}@media(prefers-reduced-motion:reduce){.game-ui-overlay *,.achievement-popup,.achievement-popup *,.level-up-overlay,.level-up-overlay *{animation:none!important;transition:none!important}.floating-text{animation:none!important}}
1
+ #game-ui-overlay,.game-ui-overlay{pointer-events:none;z-index:1000;width:100%;font-family:Inter,-apple-system,BlinkMacSystemFont,Segoe UI,sans-serif;position:fixed;top:0;left:0}.game-ui-top-bar{-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px);background:#0000004d;align-items:center;gap:12px;padding:12px 16px;display:flex}.level-badge{background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);border-radius:12px;flex-direction:column;align-items:center;min-width:60px;padding:8px 12px;display:flex;box-shadow:0 4px 12px #667eea66}.level-label{color:#fffc;letter-spacing:.5px;font-size:10px;font-weight:600}.level-number{color:#fff;font-size:24px;font-weight:800;line-height:1}.xp-container{flex-direction:column;flex:1;gap:4px;display:flex}.xp-bar-bg{background:#fff3;border-radius:6px;height:12px;overflow:hidden;box-shadow:inset 0 2px 4px #0003}.xp-bar-fill{background:linear-gradient(90deg,#4facfe 0%,#00f2fe 100%);border-radius:6px;height:100%;transition:width .5s ease-out;box-shadow:0 0 10px #4facfe99}.xp-text{color:#fff;text-align:center;text-shadow:0 1px 2px #00000080;font-size:11px;font-weight:600}.streak-badge{background:linear-gradient(135deg,#f80 0%,#f40 100%);border-radius:12px;align-items:center;gap:6px;padding:8px 12px;display:flex;box-shadow:0 4px 12px #f806}.streak-icon{font-size:20px;animation:2s infinite flicker}.streak-number{color:#fff;font-size:18px;font-weight:800}.achievement-popup{z-index:10000;background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);border-radius:16px;max-width:320px;padding:16px;animation:.5s cubic-bezier(.68,-.55,.265,1.55) slideIn;position:fixed;top:80px;right:20px;overflow:hidden;box-shadow:0 8px 32px #0006}.achievement-shine{background:linear-gradient(90deg,#0000,#ffffff4d,#0000);width:100%;height:100%;animation:2s infinite shine;position:absolute;top:0;left:-100%}.achievement-content{align-items:center;gap:12px;display:flex;position:relative}.achievement-icon{font-size:48px;animation:.6s ease-out bounce}.achievement-info{flex:1}.achievement-title{color:#ffffffe6;text-transform:uppercase;letter-spacing:.5px;font-size:12px;font-weight:600}.achievement-name{color:#fff;margin:2px 0;font-size:18px;font-weight:800}.achievement-desc{color:#fffc;margin-bottom:4px;font-size:13px}.achievement-xp{color:gold;background:#fff3;border-radius:8px;padding:4px 8px;font-size:12px;font-weight:700;display:inline-block}.level-up-overlay{z-index:10001;background:#000000d9;justify-content:center;align-items:center;width:100%;height:100%;animation:.3s ease-out fadeIn;display:flex;position:fixed;top:0;left:0}.level-up-content{text-align:center;animation:.5s cubic-bezier(.68,-.55,.265,1.55) scaleIn}.level-up-title{background:linear-gradient(135deg,gold 0%,#ffed4e 100%);-webkit-text-fill-color:transparent;text-transform:uppercase;letter-spacing:4px;-webkit-background-clip:text;background-clip:text;margin-bottom:16px;font-size:32px;font-weight:800}.level-up-number{color:#fff;text-shadow:0 0 20px #ffd700cc,0 0 40px #ffd70099,0 0 60px #ffd70066;font-size:120px;font-weight:900;animation:1s ease-in-out infinite alternate glow}.level-up-subtitle{color:#fffc;margin-top:16px;font-size:24px;font-weight:600}.floating-text{text-shadow:2px 2px #000,-1px -1px #000,1px -1px #000,-1px 1px #000;pointer-events:none;z-index:9998;font-weight:800;animation:2s ease-out forwards floatUp;position:fixed}@keyframes slideIn{0%{opacity:0;transform:translate(400px)}to{opacity:1;transform:translate(0)}}@keyframes slideOut{0%{opacity:1;transform:translate(0)}to{opacity:0;transform:translate(400px)}}@keyframes fadeIn{0%{opacity:0}to{opacity:1}}@keyframes scaleIn{0%{opacity:0;transform:scale(.5)}to{opacity:1;transform:scale(1)}}@keyframes bounce{0%,to{transform:translateY(0)}50%{transform:translateY(-10px)}}@keyframes glow{0%{text-shadow:0 0 20px #ffd700cc,0 0 40px #ffd70099,0 0 60px #ffd70066}to{text-shadow:0 0 30px gold,0 0 60px #ffd700cc,0 0 90px #ffd70099}}@keyframes shine{0%{left:-100%}30%{left:100%}to{left:100%}}@keyframes flicker{0%,to{opacity:1}50%{opacity:.8}}@keyframes floatUp{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(-100px)}}@keyframes xp-pulse{0%{transform:scaleY(1)}50%{transform:scaleY(1.2)}to{transform:scaleY(1)}}@keyframes level-pulse{0%{transform:scale(1)}50%{transform:scale(1.1)}to{transform:scale(1)}}@media (width<=480px){.game-ui-top-bar{gap:8px;padding:10px 12px}.level-badge{min-width:50px;padding:6px 10px}.level-number{font-size:20px}.xp-bar-bg{height:10px}.xp-text{font-size:10px}.achievement-popup{max-width:calc(100% - 24px);right:12px}.level-up-number{font-size:80px}}@media (prefers-reduced-motion:reduce){.game-ui-overlay *,.achievement-popup,.achievement-popup *,.level-up-overlay,.level-up-overlay *{transition:none!important;animation:none!important}.floating-text{animation:none!important}}
2
+ /*$vite$:1*/
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dopaminejs",
3
- "version": "2.3.1",
3
+ "version": "2.4.0",
4
4
  "description": "Progression mechanics for web apps: XP, levels, achievements and timezone-correct daily streaks, with the particles and sound to make them land. Zero dependencies.",
5
5
  "type": "module",
6
6
  "main": "./dist/dopamine.cjs",
@@ -20,6 +20,19 @@ export class PluginRegistry {
20
20
  // Async inits in flight. Each notes the systems other plugins added
21
21
  // meanwhile, so a failed one removes only its own.
22
22
  this._inFlight = new Set();
23
+
24
+ // Map<pluginName, Map<systemName, system>>: what each plugin
25
+ // registered during init, so remove() can unregister it.
26
+ this._owned = new Map();
27
+ }
28
+
29
+ /**
30
+ * Every registered system by name.
31
+ * @private
32
+ */
33
+ _snapshot() {
34
+ const systems = this.kernel.systems;
35
+ return new Map(systems.getSystemNames().map((name) => [name, systems.get(name)]));
23
36
  }
24
37
 
25
38
  /**
@@ -29,6 +42,57 @@ export class PluginRegistry {
29
42
  return this.kernel.systems.getSystemNames().filter((name) => !before.has(name));
30
43
  }
31
44
 
45
+ /**
46
+ * Names of the systems added or replaced since a snapshot. A plugin that
47
+ * swaps in its own 'audio' adds no new name, so names alone miss it.
48
+ * @private
49
+ */
50
+ _changedSince(before) {
51
+ const systems = this.kernel.systems;
52
+ return systems.getSystemNames().filter((name) => systems.get(name) !== before.get(name));
53
+ }
54
+
55
+ /**
56
+ * Remember the systems a plugin registered during init.
57
+ * @private
58
+ */
59
+ _own(pluginName, names) {
60
+ const systems = this.kernel.systems;
61
+ const owned = new Map();
62
+
63
+ for (const name of names) {
64
+ const system = systems.get(name);
65
+
66
+ // A plugin loaded from inside this one's init() already owns it.
67
+ const taken = [...this._owned.values()].some((other) => other.get(name) === system);
68
+ if (!taken) owned.set(name, system);
69
+ }
70
+
71
+ this._owned.set(pluginName, owned);
72
+ }
73
+
74
+ /**
75
+ * Unregister the systems a removed plugin registered during init.
76
+ * @private
77
+ */
78
+ _release(pluginName) {
79
+ const owned = this._owned.get(pluginName);
80
+ if (!owned) return;
81
+
82
+ this._owned.delete(pluginName);
83
+
84
+ for (const [name, system] of owned) {
85
+ // Replaced or unregistered since. It is no longer this plugin's.
86
+ if (this.kernel.systems.get(name) !== system) continue;
87
+
88
+ try {
89
+ this.kernel.systems.unregister(name);
90
+ } catch (error) {
91
+ console.error(`[PluginRegistry] Error removing system "${name}":`, error);
92
+ }
93
+ }
94
+ }
95
+
32
96
  /**
33
97
  * Mark systems as belonging to a plugin that loaded.
34
98
  * @private
@@ -107,18 +171,20 @@ export class PluginRegistry {
107
171
  this._loadOrder.push(plugin.name);
108
172
 
109
173
  // Initialize plugin
110
- const systemsBefore = new Set(this.kernel.systems.getSystemNames());
174
+ const systemsBefore = this._snapshot();
111
175
 
112
176
  try {
113
177
  plugin.init(this.kernel);
114
178
 
179
+ const mine = this._changedSince(systemsBefore);
180
+ this._own(plugin.name, mine);
181
+ this._claim(mine);
182
+
115
183
  // Emit event
116
184
  this.kernel.events.emit('plugin_loaded', {
117
185
  name: plugin.name,
118
186
  version: plugin.version
119
187
  });
120
-
121
- this._claim(this._systemsSince(systemsBefore));
122
188
  } catch (error) {
123
189
  console.error(`[PluginRegistry] Failed to initialize plugin "${plugin.name}":`, error);
124
190
  this._forget(plugin.name);
@@ -156,7 +222,7 @@ export class PluginRegistry {
156
222
  this._loadOrder.push(plugin.name);
157
223
 
158
224
  const pending = {
159
- before: new Set(this.kernel.systems.getSystemNames()),
225
+ before: this._snapshot(),
160
226
  foreign: new Set()
161
227
  };
162
228
  const own = () => this._systemsSince(pending.before).filter((name) => !pending.foreign.has(name));
@@ -167,7 +233,18 @@ export class PluginRegistry {
167
233
  await plugin.init(this.kernel);
168
234
 
169
235
  this._inFlight.delete(pending);
170
- this._claim(own());
236
+
237
+ const systems = this.kernel.systems;
238
+ const mine = this._changedSince(pending.before).filter((name) => !pending.foreign.has(name));
239
+
240
+ // With another init still running, a system that appeared after
241
+ // that one began could be its work. Nobody owns those, so they
242
+ // stay registered when either plugin is removed.
243
+ const others = [...this._inFlight];
244
+ this._own(plugin.name, mine.filter(
245
+ (name) => others.every((other) => other.before.get(name) === systems.get(name))
246
+ ));
247
+ this._claim(mine);
171
248
 
172
249
  // Emit event
173
250
  this.kernel.events.emit('plugin_loaded', {
@@ -196,6 +273,12 @@ export class PluginRegistry {
196
273
 
197
274
  /**
198
275
  * Remove a plugin
276
+ *
277
+ * Calls the plugin's destroy(), then unregisters the systems it
278
+ * registered during init() that are still in place. Not tracked, and so
279
+ * the plugin's to unregister in destroy(): a system it registers after
280
+ * init(), and one registered while two useAsync() inits overlapped.
281
+ *
199
282
  * @param {string} name - Plugin name
200
283
  * @returns {boolean} - True if plugin was found and removed
201
284
  */
@@ -222,6 +305,8 @@ export class PluginRegistry {
222
305
  this._loadOrder.splice(index, 1);
223
306
  }
224
307
 
308
+ this._release(name);
309
+
225
310
  // Emit event
226
311
  this.kernel.events.emit('plugin_unloaded', { name });
227
312
 
@@ -128,11 +128,16 @@ export class SoundManager {
128
128
  }
129
129
 
130
130
  /**
131
- * Preload multiple sounds
131
+ * Register and load multiple sounds. Before the audio context exists the
132
+ * files cannot be decoded, so they load when initAudio() creates it.
132
133
  * @param {Object} soundMap - { key: url }
133
134
  */
134
135
  async preloadSounds(soundMap) {
135
- const promises = Object.entries(soundMap).map(([key, url]) => this.loadSound(key, url));
136
+ const promises = Object.entries(soundMap).map(([key, url]) => {
137
+ // play() only loads keys it finds here.
138
+ this.customSounds[key] = url;
139
+ return this.loadSound(key, url);
140
+ });
136
141
  await Promise.allSettled(promises);
137
142
  }
138
143
 
@@ -1,11 +1,18 @@
1
1
  import { deprecatedGlobal } from './deprecate.js';
2
2
 
3
3
  import { Collider } from '../core/Collider.js';
4
+ import { EventBus } from '../core/EventBus.js';
4
5
 
5
6
  export class Physics {
6
7
  constructor() {
7
8
  this.colliders = [];
8
9
  this.kernel = null;
10
+
11
+ // Map<Collider, Map<Collider, step>>: the pairs that overlapped as of
12
+ // the last step, each with the step that last saw it. Without it
13
+ // there is no telling a new overlap from one that is still going.
14
+ this._pairs = new Map();
15
+ this._step = 0;
9
16
  }
10
17
 
11
18
  /**
@@ -27,6 +34,7 @@ export class Physics {
27
34
  */
28
35
  destroy() {
29
36
  this.colliders = [];
37
+ this._pairs.clear();
30
38
  }
31
39
 
32
40
  add(collider) {
@@ -36,13 +44,41 @@ export class Physics {
36
44
  remove(collider) {
37
45
  const idx = this.colliders.indexOf(collider);
38
46
  if (idx > -1) this.colliders.splice(idx, 1);
47
+
48
+ // A removed collider overlaps nothing, so its pairs end here. Left
49
+ // in the map they would also keep the collider alive.
50
+ const others = this._pairs.get(collider);
51
+ if (others) {
52
+ this._pairs.delete(collider);
53
+
54
+ // Emptied before emitting: step() may be part way through this
55
+ // map when an exit listener removes the collider, and would end
56
+ // the same pairs again.
57
+ const ended = [...others.keys()];
58
+ others.clear();
59
+ for (const other of ended) {
60
+ this._emit(EventBus.Events.COLLISION_EXIT, collider, other);
61
+ }
62
+ }
63
+ for (const [first, seconds] of this._pairs) {
64
+ if (seconds.delete(collider)) {
65
+ this._emit(EventBus.Events.COLLISION_EXIT, first, collider);
66
+ }
67
+ }
39
68
  }
40
69
 
41
70
  /**
42
71
  * Main Physics Step.
43
72
  * Checks all pairs and triggers callbacks.
73
+ *
74
+ * Emits `collision_enter` on the kernel event bus when a pair starts to
75
+ * overlap and `collision_exit` when it stops, each with `{ a, b }` (the
76
+ * two colliders). `onCollisionEnter` on a component is older and runs on
77
+ * every step while the pair overlaps.
44
78
  */
45
79
  step() {
80
+ const step = ++this._step;
81
+
46
82
  // Naive O(N^2)
47
83
  for (let i = 0; i < this.colliders.length; i++) {
48
84
  for (let j = i + 1; j < this.colliders.length; j++) {
@@ -50,12 +86,65 @@ export class Physics {
50
86
  const b = this.colliders[j];
51
87
 
52
88
  if (this._intersects(a, a.getBounds(), b, b.getBounds())) {
89
+ this._seen(a, b, step);
90
+
53
91
  // Notify GameObjects
54
92
  this._notifyCollision(a.gameObject, b.gameObject);
55
93
  this._notifyCollision(b.gameObject, a.gameObject);
56
94
  }
57
95
  }
58
96
  }
97
+
98
+ for (const [a, others] of this._pairs) {
99
+ for (const [b, seen] of others) {
100
+ if (seen === step) continue;
101
+
102
+ // A collider removed during the loop above shifts the list,
103
+ // and the loop then passes over some pairs. Not being seen
104
+ // is not enough to end one.
105
+ if (this._intersects(a, a.getBounds(), b, b.getBounds())) {
106
+ others.set(b, step);
107
+ continue;
108
+ }
109
+
110
+ others.delete(b);
111
+ this._emit(EventBus.Events.COLLISION_EXIT, a, b);
112
+ }
113
+ if (others.size === 0) this._pairs.delete(a);
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Record that a pair overlaps on this step. Emits `collision_enter` when
119
+ * it did not overlap on the step before.
120
+ * @private
121
+ */
122
+ _seen(a, b, step) {
123
+ // A pair is stored under the collider that was first in the list
124
+ // when it began. `colliders` is public and can be reordered, so look
125
+ // under the other one too.
126
+ if (this._pairs.get(b)?.has(a)) {
127
+ this._pairs.get(b).set(a, step);
128
+ return;
129
+ }
130
+
131
+ let others = this._pairs.get(a);
132
+ if (!others) {
133
+ others = new Map();
134
+ this._pairs.set(a, others);
135
+ }
136
+
137
+ const known = others.has(b);
138
+ others.set(b, step);
139
+ if (!known) this._emit(EventBus.Events.COLLISION_ENTER, a, b);
140
+ }
141
+
142
+ /**
143
+ * @private
144
+ */
145
+ _emit(event, a, b) {
146
+ // GlobalPhysics and a Physics built by hand have no kernel.
147
+ this.kernel?.events?.emit(event, { a, b });
59
148
  }
60
149
 
61
150
  _notifyCollision(go, other) {
package/types/index.d.ts CHANGED
@@ -284,6 +284,7 @@ export class SoundManager {
284
284
  toggleMute(): boolean;
285
285
 
286
286
  registerSound(key: string, url: string): void;
287
+ /** Registers every key, then loads the files. Before the audio context exists they load when it is created. */
287
288
  preloadSounds(soundMap: Record<string, string>): Promise<void>;
288
289
  loadSound(key: string, url: string): Promise<void>;
289
290
  play(key: string): Promise<void>;
@@ -372,6 +373,7 @@ export class PluginRegistry {
372
373
  constructor(kernel: DopamineKernel);
373
374
  use(plugin: Plugin): this;
374
375
  useAsync(plugin: Plugin): Promise<this>;
376
+ /** Calls the plugin's `destroy()`, then unregisters the systems it registered during `init()`. */
375
377
  remove(name: string): boolean;
376
378
  get(name: string): Plugin | undefined;
377
379
  has(name: string): boolean;
@@ -535,12 +537,24 @@ export class Input {
535
537
  mouse: { x: number; y: number };
536
538
  }
537
539
 
540
+ /** Payload of `collision_enter` and `collision_exit` on the kernel event bus. */
541
+ export interface CollisionEvent {
542
+ a: Collider;
543
+ b: Collider;
544
+ }
545
+
538
546
  export class Physics {
539
547
  init(kernel: DopamineKernel): void;
540
548
  fixedUpdate(dt: number): void;
541
549
  destroy(): void;
542
550
  add(collider: Collider): void;
551
+ /** Emits `collision_exit` for each pair the collider was overlapping in. */
543
552
  remove(collider: Collider): void;
553
+ /**
554
+ * Emits `collision_enter` once when a pair starts to overlap and
555
+ * `collision_exit` once when it stops. `onCollisionEnter` on a component
556
+ * runs on every step while the pair overlaps.
557
+ */
544
558
  step(): void;
545
559
  /** Every collider that overlaps `source`. With a tag, only colliders carrying it. */
546
560
  checkOverlap(source: Collider, targetTag?: string): Collider[];