@ujjwalvivek/tinyts
    Preparing search index...

    Class Registry

    Central ECS registry that manages entities, components, views, and hierarchy.

    Supports component pooling, cached archetype views, event hooks, and JSON serialization.

    Index

    Constructors

    Methods

    • Attach a component instance to an entity, triggering onAdded listeners.

      Type Parameters

      • T

      Parameters

      • entity: number
      • componentClass: new (...args: any[]) => T
      • component: T

      Returns T

    • Remove all entities, components, caches, pools, and listeners.

      Returns void

    • Create a new entity, reusing a recycled ID when available.

      Returns number

    • Clear the registry and restore state from a JSON string produced by serialize().

      Parameters

      • json: string

      Returns void

    • Destroy an entity, removing all its components and hierarchy links.

      Parameters

      • entity: number

      Returns void

    • Retrieve a component from an entity, or undefined if not present.

      Type Parameters

      • T

      Parameters

      • entity: number
      • componentClass: new (...args: any[]) => T

      Returns T | undefined

    • Check whether an entity has a given component type.

      Parameters

      • entity: number
      • componentClass: new (...args: any[]) => any

      Returns boolean

    • Get a pooled component instance, or create a new one.

      Reused instances have their init() or reset() method called with the provided args.

      Type Parameters

      • T

      Parameters

      • componentClass: new (...args: any[]) => T
      • ...args: any[]

      Returns T

    • Register a callback invoked whenever a component of this type is added.

      Type Parameters

      • T

      Parameters

      • componentClass: new (...args: any[]) => T
      • callback: (entity: number, component: T) => void

      Returns () => void

      Unsubscribe function.

    • Register a callback invoked whenever a component of this type is removed.

      Type Parameters

      • T

      Parameters

      • componentClass: new (...args: any[]) => T
      • callback: (entity: number, component: T) => void

      Returns () => void

      Unsubscribe function.

    • Register a component class for serialization under the given name.

      Parameters

      • name: string
      • constructor: new (...args: any[]) => any

      Returns void

    • Remove a component from an entity, triggering onRemoved listeners and pooling the instance.

      Parameters

      • entity: number
      • componentClass: new (...args: any[]) => any

      Returns void

    • Serialize all entities and registered components to a JSON string.

      Returns string

    • Set or clear an entity's parent, updating Parent/Children components on both sides.

      Parameters

      • child: number
      • parent: number | null

      Returns void

    • Query entities matching a set of component types. Results are cached.

      Accepts either component classes as rest args, or a QueryConfig with with/without arrays.

      Type Parameters

      • T extends any[]

      Parameters

      • ...componentClasses: { [K in string | number | symbol]: new (...args: any[]) => T[K] }

      Returns number[]

    • Query entities matching a set of component types. Results are cached.

      Accepts either component classes as rest args, or a QueryConfig with with/without arrays.

      Parameters

      • config: QueryConfig

      Returns number[]