UNPKG

@fuwu-yuan/bgew

Version:

Baguette Game Engine Web is a french 2D Web game engine

32 lines (31 loc) 970 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DispatcherEvent = void 0; class DispatcherEvent { constructor(eventName) { this.eventName = eventName; this.callbacks = []; } registerCallback(callback, options = { once: false }) { this.callbacks.push({ callback: callback, options: options }); } unregisterCallback(callback) { const index = this.callbacks.findIndex((e) => { return e.callback === callback; }); if (index > -1) { this.callbacks.splice(index, 1); } } fire(...args) { /*const callbacks = this.callbacks.slice(0); callbacks.forEach((callback) => { callback.callback(...args); });*/ this.callbacks = this.callbacks.filter((c) => { c.callback(...args); return c.options.once === false; }); } } exports.DispatcherEvent = DispatcherEvent;