feat: add poc
This commit is contained in:
parent
43d27b04d9
commit
4a4fa05ce4
53 changed files with 6191 additions and 0 deletions
57
src/core/EventBus.js
Normal file
57
src/core/EventBus.js
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/**
|
||||
* Lightweight EventBus for pub/sub communication between systems
|
||||
*/
|
||||
export const Events = {
|
||||
// Combat Events
|
||||
DAMAGE_DEALT: 'combat:damage_dealt',
|
||||
ENTITY_DIED: 'combat:entity_died',
|
||||
|
||||
// Evolution Events
|
||||
EVOLVED: 'evolution:evolved',
|
||||
MUTATION_GAINED: 'evolution:mutation_gained',
|
||||
|
||||
// Leveling Events
|
||||
EXP_GAINED: 'stats:exp_gained',
|
||||
LEVEL_UP: 'stats:level_up',
|
||||
|
||||
// Skill Events
|
||||
SKILL_LEARNED: 'skills:learned',
|
||||
SKILL_COOLDOWN_STARTED: 'skills:cooldown_started'
|
||||
};
|
||||
|
||||
export class EventBus {
|
||||
constructor() {
|
||||
this.listeners = new Map();
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribe to an event
|
||||
*/
|
||||
on(event, callback) {
|
||||
if (!this.listeners.has(event)) {
|
||||
this.listeners.set(event, []);
|
||||
}
|
||||
this.listeners.get(event).push(callback);
|
||||
return () => this.off(event, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsubscribe from an event
|
||||
*/
|
||||
off(event, callback) {
|
||||
if (!this.listeners.has(event)) return;
|
||||
const callbacks = this.listeners.get(event);
|
||||
const index = callbacks.indexOf(callback);
|
||||
if (index > -1) {
|
||||
callbacks.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit an event
|
||||
*/
|
||||
emit(event, data) {
|
||||
if (!this.listeners.has(event)) return;
|
||||
this.listeners.get(event).forEach(callback => callback(data));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue