Class World

Hierarchy

  • World

Constructors

Properties

capacity: number

The maximum number of entities the world can hold

version: "__VERSION__" = VERSION

Miski version

Accessors

  • get residents(): number
  • Returns

    the number of active entities

    Returns number

  • get vacancies(): number
  • Returns

    the number of available entities

    Returns number

Methods

  • Creates a function to add a given set of components to an entity

    Returns

    A function which takes an entity and optional properties object

    Throws

    if one or more components are not registered in this world

    Parameters

    • Rest ...components: Component<any>[]

      One or more components to add

    Returns ((entity: Entity, properties?: Record<string, SchemaProps<unknown>>) => World)

  • Returns

    the next available Entity or undefined if no Entity is available

    Returns undefined | Entity

  • Remove and recycle an Entity

    Returns

    the world

    Throws

    if the entity is invalid

    Parameters

    • entity: Entity

      the entity to destroy

    Returns World

  • Get all the changed entities from a set of components

    Returns

    An array of entities

    Throws

    if one or more components are not registered in this world

    Parameters

    • Rest ...components: Component<any>[]

      The components to collect changed entities from

    Returns Entity[]

  • Get all the changed entities from a query

    Returns

    an array of entities

    Throws

    if query is invalid

    Parameters

    • query: Query

      the query to collect changed entities from

    • arr: Entity[] = []

      an optional array to be emptied and recycled

    Returns Entity[]

  • Get this world's instance of a component

    Returns

    The component instance or undefined if the component is not registered

    Type Parameters

    Parameters

    • component: Component<T>

      The component to retrieve the instance of

    Returns undefined | ComponentInstance<T>

  • Get this world's instances of a set of components

    Returns

    An array of component instances or undefined if the component is not registered

    Parameters

    Returns (undefined | ComponentInstance<any>)[]

  • Get all of the component properties of a given entity

    Returns

    An object where keys are component names and properties are the entity's properties

    Parameters

    • entity: Entity

      The entity to retrieve the properties of

    Returns Record<string, SchemaProps<unknown>>

  • Get all the components positively associated with a query

    Returns

    An object where keys are component names and properties are component instances

    Throws

    If the query is invalid

    Parameters

    • query: Query

      The query to get the components from

    Returns ComponentRecord

  • Get all the entities which have entered the query since the last refresh

    Returns

    An array of entities

    Throws

    If the query is invalid

    Parameters

    • query: Query

      The query to get the entities from

    • arr: Entity[] = []

      An optional array to be emptied and recycled

    Returns Entity[]

  • Get all the entities which match a query

    Returns

    An array of entities

    Throws

    If the query is invalid

    Parameters

    • query: Query

      The query to get the entities from

    • arr: Entity[] = []

      An optional array to be emptied and recycled

    Returns Entity[]

  • Get all the entities which have exited the query since the last refresh

    Returns

    An array of entities

    Throws

    If the query is invalid

    Parameters

    • query: Query

      The query to get the entities from

    • arr: Entity[] = []

      An optional array to be emptied and recycled

    Returns Entity[]

  • Create a function to test entities for a given component

    Returns

    A function which takes an entity and returns true if the entity has the component, false if it does not or null if the entity does not exist.

    Throws

    if the component is not registered in this world

    Type Parameters

    Parameters

    • component: Component<T>

      The component to test for

    Returns ((entity: Entity) => null | boolean)

      • (entity: Entity): null | boolean
      • Create a function to test entities for a given component

        Returns

        A function which takes an entity and returns true if the entity has the component, false if it does not or null if the entity does not exist.

        Throws

        if the component is not registered in this world

        Parameters

        Returns null | boolean

  • Create a function to test entities for a given component

    Returns

    A function which takes an entity and returns an array of true if the entity has the component, false if it does not or null if the entity does not exist.

    Throws

    if one or more component is not registered in this world

    Parameters

    • Rest ...components: Component<any>[]

      The components to test for

    Returns ((entity: Entity) => (null | boolean)[])

      • (entity: Entity): (null | boolean)[]
      • Create a function to test entities for a given component

        Returns

        A function which takes an entity and returns an array of true if the entity has the component, false if it does not or null if the entity does not exist.

        Throws

        if one or more component is not registered in this world

        Parameters

        Returns (null | boolean)[]

  • Test if an entity is active in the world

    Returns

    a boolean or null if the entity is invalid

    Parameters

    Returns null | boolean

  • Swap the ComponentBuffer of one world with this world

    Returns

    the world

    Throws

    if the capacity or version of the data to load is mismatched

    Parameters

    Returns World

  • Creates a function to remove a given set of components from an entity

    Returns

    A function which takes an entity

    Throws

    if one or more components are not registered in this world

    Parameters

    • Rest ...components: Component<any>[]

      One or more components to remove

    Returns ((entity: Entity) => World)

      • (entity: Entity): World
      • Creates a function to remove a given set of components from an entity

        Returns

        A function which takes an entity

        Throws

        if one or more components are not registered in this world

        Parameters

        Returns World

Generated using TypeDoc