I'm working on a relatively simple (but hopefully useful) event system for miniSphere influenced by Node.js's EventEmitter class, so if you're familiar with that, this should be fairly simple to get used to.
Some examples:
import { Thread } from 'sphere-runtime';
import { EventEmitter } from 'events';
const maxListeners = 32;
const escOnlyOnce = true;
let ei = new EventEmitter(maxListeners);
export default class Game extends Thread {
constructor() {
super();
ei.addListener("escEvent", () => {
Sphere.shutDown();
}, escOnlyOnce);
}
on_update() {
if(kb.isPressed(Key.Escape)) ei.emit("escEvent");
}
}
The `event#addListener` function also takes an optional parameter that emits the listener when it equals true or is a function that returns true.
ei.addListener("escEvent", Sphere.shutDown, escOnlyOnce, () => {
return kb.isPressed(Key.Escape);
});
I'm also working on a class for handling key press/release events
GitHub repo: https://github.com/eggbertx/eventemitter-sphere