UNPKG

playcanvas

Version:

PlayCanvas WebGL game engine

36 lines (33 loc) 814 B
import { EventHandler } from '../../core/event-handler.js'; class ComponentSystemRegistry extends EventHandler { constructor(){ super(); this.list = []; } add(system) { const id = system.id; if (this[id]) { throw new Error(`ComponentSystem name '${id}' already registered or not allowed`); } this[id] = system; this.list.push(system); } remove(system) { const id = system.id; if (!this[id]) { throw new Error(`No ComponentSystem named '${id}' registered`); } delete this[id]; const index = this.list.indexOf(this[id]); if (index !== -1) { this.list.splice(index, 1); } } destroy() { this.off(); for(let i = 0; i < this.list.length; i++){ this.list[i].destroy(); } } } export { ComponentSystemRegistry };