Rooms, items and some player stuff

This commit is contained in:
2021-11-04 20:58:37 +01:00
parent 36bb9264b3
commit a745ff299e
277 changed files with 14665 additions and 5 deletions

View File

@@ -0,0 +1,30 @@
export class EventBus {
constructor() {
this.events = new Map();
}
emit(id, data) {
let ev = this.events.get(id);
if (!ev) {
let ev = new EventItem(id);
this.events.set(id, ev);
return;
}
ev.subscribers.forEach((subscriber) => {
subscriber(data);
});
}
subscribe(id, subscriber) {
let ev = this.events.get(id);
if (!ev) {
ev = new EventItem(id);
this.events.set(id, ev);
}
ev.subscribers.push(subscriber);
}
}
export class EventItem {
constructor(id) {
this.id = id;
this.subscribers = [];
}
}