playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
59 lines (58 loc) • 1 kB
JavaScript
import { EventHandler } from "../../core/event-handler.js";
class ComponentSystemRegistry extends EventHandler {
anim;
animation;
audiolistener;
button;
camera;
collision;
element;
gsplat;
joint;
layoutchild;
layoutgroup;
light;
model;
particlesystem;
render;
rigidbody;
screen;
script;
scrollbar;
scrollview;
sound;
sprite;
zone;
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
};