UNPKG

phaser4-rex-plugins

Version:
61 lines (52 loc) 1.38 kB
class WaitEvents { constructor(completeCallback, scope) { this.setCompleteCallback(completeCallback, scope); this.events = new Set(); } shutdown() { this.setCompleteCallback(undefined, undefined); this.events.clear(); this.event = undefined; return this; } destroy() { this.shutdown(); return this; } setCompleteCallback(callback, scope) { this.completeCallback = callback; this.scope = scope; return this; } waitCallback() { var self = this; var callback = function () { self.remove(callback); } this.events.add(callback); return callback; } waitEvent(eventEmitter, eventName) { eventEmitter.once(eventName, this.waitCallback()); return this; } remove(callback) { this.events.delete(callback); if (this.noWaitEvent) { if (this.scope) { this.completeCallback.call(this.scope); } else { this.completeCallback(); } } return this; } clear() { this.events.clear(); return this; } get noWaitEvent() { return this.events.size === 0; } } export default WaitEvents;