UNPKG

@willyuum/pixi-gameobject-system

Version:
44 lines (43 loc) 1.48 kB
/** * This module handles the management and operation of all components in the system. * Components are managed through internal and public APIs for adding, removing, updating, and awakening components. * * **Internal API**: * - Handles the internal operations of adding and removing components to/from the collection. * - Should not be accessed directly by consumers of the module. * * **Public API**: * - Provides external methods for updating and awakening all components in the collection. * - These methods are safe to call from other parts of the codebase. */ const components = new Set(); const compsToAwake = new Set(); export const internal_ComponentManager = { addComponent: (component) => { compsToAwake.add(component); components.add(component); }, removeComponent: (component) => { const isInAwakeSet = compsToAwake.has(component); if (isInAwakeSet) { compsToAwake.delete(component); } components.delete(component); }, }; export const public_ComponentManager = { AwakeAvailableComponents: () => { const noNeedToAwake = compsToAwake.size === 0; if (noNeedToAwake) return; for (let component of compsToAwake) { component.onAwake(); } compsToAwake.clear(); }, UpdateComponents: (deltaTime) => { for (let component of components) { component.onUpdate(deltaTime); } } };