UNPKG

playcanvas

Version:

Open-source WebGL/WebGPU 3D engine for the web

217 lines (216 loc) 5.92 kB
var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); import { EventHandler } from "../../core/event-handler.js"; class ComponentSystemRegistry extends EventHandler { /** * Create a new ComponentSystemRegistry instance. */ constructor() { super(); /** * Gets the {@link AnimComponentSystem} from the registry. * * @type {AnimComponentSystem|undefined} * @readonly */ __publicField(this, "anim"); /** * Gets the {@link AnimationComponentSystem} from the registry. * * @type {AnimationComponentSystem|undefined} * @readonly */ __publicField(this, "animation"); /** * Gets the {@link AudioListenerComponentSystem} from the registry. * * @type {AudioListenerComponentSystem|undefined} * @readonly */ __publicField(this, "audiolistener"); /** * Gets the {@link ButtonComponentSystem} from the registry. * * @type {ButtonComponentSystem|undefined} * @readonly */ __publicField(this, "button"); /** * Gets the {@link CameraComponentSystem} from the registry. * * @type {CameraComponentSystem|undefined} * @readonly */ __publicField(this, "camera"); /** * Gets the {@link CollisionComponentSystem} from the registry. * * @type {CollisionComponentSystem|undefined} * @readonly */ __publicField(this, "collision"); /** * Gets the {@link ElementComponentSystem} from the registry. * * @type {ElementComponentSystem|undefined} * @readonly */ __publicField(this, "element"); /** * Gets the {@link GSplatComponentSystem} from the registry. * * @type {GSplatComponentSystem|undefined} * @readonly */ __publicField(this, "gsplat"); /** * Gets the {@link JointComponentSystem} from the registry. * * @type {JointComponentSystem|undefined} * @readonly * @ignore */ __publicField(this, "joint"); /** * Gets the {@link LayoutChildComponentSystem} from the registry. * * @type {LayoutChildComponentSystem|undefined} * @readonly */ __publicField(this, "layoutchild"); /** * Gets the {@link LayoutGroupComponentSystem} from the registry. * * @type {LayoutGroupComponentSystem|undefined} * @readonly */ __publicField(this, "layoutgroup"); /** * Gets the {@link LightComponentSystem} from the registry. * * @type {LightComponentSystem|undefined} * @readonly */ __publicField(this, "light"); /** * Gets the {@link ModelComponentSystem} from the registry. * * @type {ModelComponentSystem|undefined} * @readonly */ __publicField(this, "model"); /** * Gets the {@link ParticleSystemComponentSystem} from the registry. * * @type {ParticleSystemComponentSystem|undefined} * @readonly */ __publicField(this, "particlesystem"); /** * Gets the {@link RenderComponentSystem} from the registry. * * @type {RenderComponentSystem|undefined} * @readonly */ __publicField(this, "render"); /** * Gets the {@link RigidBodyComponentSystem} from the registry. * * @type {RigidBodyComponentSystem|undefined} * @readonly */ __publicField(this, "rigidbody"); /** * Gets the {@link ScreenComponentSystem} from the registry. * * @type {ScreenComponentSystem|undefined} * @readonly */ __publicField(this, "screen"); /** * Gets the {@link ScriptComponentSystem} from the registry. * * @type {ScriptComponentSystem|undefined} * @readonly */ __publicField(this, "script"); /** * Gets the {@link ScrollbarComponentSystem} from the registry. * * @type {ScrollbarComponentSystem|undefined} * @readonly */ __publicField(this, "scrollbar"); /** * Gets the {@link ScrollViewComponentSystem} from the registry. * * @type {ScrollViewComponentSystem|undefined} * @readonly */ __publicField(this, "scrollview"); /** * Gets the {@link SoundComponentSystem} from the registry. * * @type {SoundComponentSystem|undefined} * @readonly */ __publicField(this, "sound"); /** * Gets the {@link SpriteComponentSystem} from the registry. * * @type {SpriteComponentSystem|undefined} * @readonly */ __publicField(this, "sprite"); /** * Gets the {@link ZoneComponentSystem} from the registry. * * @type {ZoneComponentSystem|undefined} * @readonly * @ignore */ __publicField(this, "zone"); this.list = []; } /** * Add a component system to the registry. * * @param {object} system - The {@link ComponentSystem} instance. * @ignore */ 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 a component system from the registry. * * @param {object} system - The {@link ComponentSystem} instance. * @ignore */ 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 };