/** * Resolves to `A` when the types `X` and `Y` are identical, otherwise to `B`. */ export type IfEquals = (() => T extends X ? 1 : 2) extends (() => T extends Y ? 1 : 2) ? A : B; /** * The names of the writable (not readonly) properties of `T`. */ export type WritableKeys = { [P in keyof T]-?: IfEquals<{ [Q in P]: T[P]; }, { -readonly [Q in P]: T[P]; }, P>; }[keyof T]; /** * The names of the properties of component class `C` that {@link Entity#addComponent} accepts as * options based on the class alone: its public, writable, non-function properties. Getter-only and * `@readonly` properties, methods and callbacks, underscore-prefixed internals and the `system` * and `entity` references are excluded. */ export type ComponentOptionKeys = { [K in WritableKeys]: K extends "system" | "entity" | `_${string}` ? never : NonNullable extends Function ? never : K; }[WritableKeys]; /** * The options derived from component class `C` alone: each {@link ComponentOptionKeys} property, * optional, with the type of the property. */ export type ComponentOptionsOf = Partial, keyof C>>>; /** * The system-level option overrides of the component named `K` (see * {@link ComponentOptionsOverrides}), or an empty object type when it has none, as for an * application-defined component. */ export type ComponentOptionsOverridesOf = K extends keyof ComponentOptionsOverrides ? ComponentOptionsOverrides[K] : {}; /** * The options of the component named `K`: those derived from its component class, with the * system-level overrides replacing same-named properties. {@link ComponentOptions} flattens this * into a single object type. */ export type MergedComponentOptions = Omit, keyof ComponentOptionsOverridesOf> & ComponentOptionsOverridesOf; /** * @import { ComponentMap } from '../entity.js' * @import { ComponentName } from '../entity.js' * @import { ComponentOptionsOverrides } from './registry.js' * @import { ComponentSystem } from './system.js' * @import { Entity } from '../entity.js' */ /** * Resolves to `A` when the types `X` and `Y` are identical, otherwise to `B`. * * @template X * @template Y * @template [A=X] * @template [B=never] * @typedef {(() => T extends X ? 1 : 2) extends (() => T extends Y ? 1 : 2) ? A : B} IfEquals * @ignore */ /** * The names of the writable (not readonly) properties of `T`. * * @template T * @typedef {{ [P in keyof T]-?: IfEquals<{ [Q in P]: T[P] }, { -readonly [Q in P]: T[P] }, P> }[keyof T]} WritableKeys * @ignore */ /** * The names of the properties of component class `C` that {@link Entity#addComponent} accepts as * options based on the class alone: its public, writable, non-function properties. Getter-only and * `@readonly` properties, methods and callbacks, underscore-prefixed internals and the `system` * and `entity` references are excluded. * * @template C * @typedef {{ [K in WritableKeys]: K extends 'system' | 'entity' | `_${string}` ? never : NonNullable extends Function ? never : K }[WritableKeys]} ComponentOptionKeys * @ignore */ /** * The options derived from component class `C` alone: each {@link ComponentOptionKeys} property, * optional, with the type of the property. * * @template C * @typedef {Partial, keyof C>>>} ComponentOptionsOf * @ignore */ /** * The system-level option overrides of the component named `K` (see * {@link ComponentOptionsOverrides}), or an empty object type when it has none, as for an * application-defined component. * * @template {ComponentName} K * @typedef {K extends keyof ComponentOptionsOverrides ? ComponentOptionsOverrides[K] : {}} ComponentOptionsOverridesOf * @ignore */ /** * The options of the component named `K`: those derived from its component class, with the * system-level overrides replacing same-named properties. {@link ComponentOptions} flattens this * into a single object type. * * @template {ComponentName} K * @typedef {Omit, keyof ComponentOptionsOverridesOf> & ComponentOptionsOverridesOf} MergedComponentOptions * @ignore */ /** * Components are used to attach functionality on a {@link Entity}. Components can receive update * events each frame, and expose properties to the PlayCanvas Editor. * * @hideconstructor * @category Framework */ export class Component extends EventHandler { /** * Component order. When an entity with multiple components gets enabled, this order specifies * in which order the components get enabled. The lowest number gets enabled first. * * @type {number} - Component order number. * @private */ private static order; /** * Legacy path for external components (e.g. playcanvas-spine) that store their properties in * a ComponentData object: creates data-backed accessors for each schema property. * * @ignore */ static _buildAccessors(obj: any, schema: any): void; /** * Base constructor for a Component. * * @param {ComponentSystem} system - The ComponentSystem used to create this component. * @param {Entity} entity - The Entity that this Component is attached to. */ constructor(system: ComponentSystem, entity: Entity); /** * The ComponentSystem used to create this Component. * * @type {ComponentSystem} */ system: ComponentSystem; /** * The Entity that this Component is attached to. * * @type {Entity} */ entity: Entity; /** * The enabled state of the component. * * @type {boolean} * @private */ private _enabled; /** @ignore */ buildAccessors(schema: any): void; /** @ignore */ onSetEnabled(name: any, oldValue: any, newValue: any): void; /** @ignore */ onEnable(): void; /** @ignore */ onDisable(): void; /** @ignore */ onPostStateChange(): void; /** * Access the component data directly. Usually you should access the data properties via the * individual properties as modifying this data directly will not fire 'set' events. This is a * legacy path for external components that still store their properties in a ComponentData * object - engine components no longer store any data here. * * @type {*} * @ignore */ get data(): any; /** * Sets the enabled state of the component. * * @type {boolean} */ set enabled(value: boolean); /** * Gets the enabled state of the component. * * @type {boolean} */ get enabled(): boolean; } import type { ComponentName } from '../entity.js'; import type { ComponentOptionsOverrides } from './registry.js'; import type { ComponentMap } from '../entity.js'; import { EventHandler } from '../../core/event-handler.js'; import type { ComponentSystem } from './system.js'; import type { Entity } from '../entity.js';