playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
109 lines (108 loc) • 4.38 kB
TypeScript
/**
* @import { AppBase } from '../app-base.js'
* @import { Component } from './component.js'
* @import { Entity } from '../entity.js'
*/
/**
* Component Systems contain the logic and functionality to update all Components of a particular
* type.
*/
export class ComponentSystem extends EventHandler {
/**
* Create a new ComponentSystem instance.
*
* @param {AppBase} app - The application managing this system.
*/
constructor(app: AppBase);
/**
* The id type of the ComponentSystem.
*
* @type {string}
* @readonly
*/
readonly id: string;
/**
* A list of option names accepted by {@link ComponentSystem#addComponent} that are not settable
* properties of the component itself - for example keys the system consumes to build derived
* state (such as `aabbCenter`) or deprecated aliases. Used only by debug-build validation to
* avoid false-positive warnings; subclasses that accept such options should override this.
*
* @type {string[]}
* @ignore
*/
extraDataProperties: string[];
/**
* Cache of option names already validated as acceptable by {@link ComponentSystem#addComponent},
* lazily populated the first time each option is seen. Debug builds only.
*
* @type {Set<string>|null}
* @ignore
*/
_validProps: Set<string> | null;
app: AppBase;
store: {};
schema: any[];
/**
* Create new {@link Component} and component data instances and attach them to the entity.
*
* @param {Entity} entity - The Entity to attach this component to.
* @param {object} [data] - The source data with which to create the component.
* @returns {Component} Returns a Component of type defined by the component system.
* @example
* const entity = new Entity(app);
* app.systems.model.addComponent(entity, { type: 'box' });
* // entity.model is now set to a ModelComponent
* @ignore
*/
addComponent(entity: Entity, data?: object): Component;
/**
* Remove the {@link Component} from the entity and delete the associated component data.
*
* @param {Entity} entity - The entity to remove the component from.
* @example
* app.systems.model.removeComponent(entity);
* // entity.model === undefined
* @ignore
*/
removeComponent(entity: Entity): void;
/**
* Create a clone of component. This creates a copy of all component data variables.
*
* @param {Entity} entity - The entity to clone the component from.
* @param {Entity} clone - The entity to clone the component into.
* @returns {Component} The newly cloned component.
* @ignore
*/
cloneComponent(entity: Entity, clone: Entity): Component;
/**
* Called during {@link addComponent} to initialize the component data in the store. This can
* be overridden by derived Component Systems and either called by the derived System or
* replaced entirely.
*
* @param {Component} component - The component being initialized.
* @param {object} data - The data block used to initialize the component.
* @param {Array<string | {name: string, type: string}>} [properties] - The array of property
* descriptors to initialize from the data block. A descriptor can be either a plain property
* name, or an object specifying the name and type. This is a legacy path for external
* schema-based components - when omitted, the enabled state is initialized from the data
* block instead. Callers that handle the enabled state themselves pass an empty array.
* @ignore
*/
initializeComponentData(component: Component, data?: object, properties?: Array<string | {
name: string;
type: string;
}>): void;
/**
* Searches the component schema for properties that match the specified type.
*
* @param {string} type - The type to search for.
* @returns {string[]|object[]} An array of property descriptors matching the specified type.
* @ignore
*/
getPropertiesOfType(type: string): string[] | object[];
destroy(): void;
}
import { EventHandler } from '../../core/event-handler.js';
import type { AppBase } from '../app-base.js';
import type { Entity } from '../entity.js';
import type { Component } from './component.js';