Strata - v1.4.10
    Preparing search index...

    Class World<E>

    Type Parameters

    • E extends {} = any

    Hierarchy

    • Bucket<E>
      • World

    Implements

    • IQueryableBucket<E>
    Index

    Constructors

    • Type Parameters

      • E extends {} = any

      Parameters

      • Optionalentities: E[]

      Returns World<E>

    Properties

    onEntityAdded: Event<[entity: E]>

    Fired when an entity has been added to the bucket.

    onEntityRemoved: Event<[entity: E]>

    Fired when an entity is about to be removed from the bucket.

    Accessors

    • get entities(): E[]

      An array of all entities within the bucket. Please note that for iterating over the entities in this bucket, it is recommended that you use the for (const entity of bucket) iterator form.

      Returns E[]

    • get first(): E | undefined

      Returns the first entity in the bucket, or undefined if the bucket is empty.

      Returns E | undefined

    • get size(): number

      Returns the total size of the bucket, i.e. the number of entities it contains.

      Returns number

    • get version(): number

      The current version of the bucket. Increases every time an entity is added or removed.

      Returns number

    Methods

    • Returns { next: () => { done: boolean; value: E } }

    • Adds the given entity to the bucket. If the entity is already in the bucket, it is not added again.

      Type Parameters

      • D extends {}

      Parameters

      • entity: D

        The entity to add to the bucket.

      Returns D & E

      The entity passed into this function (regardless of whether it was added or not).

    • Adds a component to an entity. If the entity already has the component, the existing component will not be overwritten.

      After the component was added, the entity will be reindexed, causing it to be added to or removed from any queries depending on their criteria.

      Type Parameters

      • C extends string | number | symbol

      Parameters

      • entity: E

        The entity to modify.

      • component: C

        The name of the component to add.

      • value: E[C]

        The value of the component to add.

      Returns void

    • Removes all entities from the bucket. Will cause the onEntityRemoved event to be fired for each entity.

      Returns void

    • Given an entity ID that was previously generated through the id(entity) function, returns the entity matching that ID, or undefined if no such entity exists.

      Parameters

      • id: number

        The ID of the entity to retrieve.

      Returns E | undefined

      The entity with the given ID, or undefined if no such entity exists.

    • Returns true if the bucket contains the given entity.

      Parameters

      • entity: any

        The entity to check for.

      Returns entity is E

      true if the specificed entity is in this bucket, false otherwise.

    • Generate and return a numerical identifier for the given entity. The ID can later be used to retrieve the entity again through the entity(id) method.

      Parameters

      • entity: E

        The entity to get the ID for.

      Returns number | undefined

      An ID for the entity, or undefined if the entity is not in the world.

    • Creates (or reuses) a query that matches the given configuration.

      Type Parameters

      • D

      Parameters

      • config: QueryConfiguration

        The query configuration.

      Returns Query<D>

      A query that matches the given configuration.

    • Reindexes the specified entity. This will iteratere over all registered queries and ask them to reevaluate the entity.

      If the future parameter is specified, it will be used in the evaluation instead of the entity itself. This is useful if you are about to perform a destructive change on the entity (like removing a component), but want emitted events to still have access to the unmodified entity before the change.

      Parameters

      • entity: E

        The entity to reindex.

      • Optionalfuture: E

        The entity that the entity will become in the future.

      Returns void

    • Removes the given entity from the bucket. If the entity is not in the bucket, nothing happens.

      Parameters

      • entity: E

        The entity to remove from the bucket.

      Returns E

      The entity passed into this function (regardless of whether it was removed or not).

    • Removes a component from an entity. If the entity does not have the component, this function does nothing.

      After the component was removed, the entity will be reindexed, causing it to be added to or removed from any queries depending on their criteria.

      Parameters

      • entity: E

        The entity to modify.

      • component: keyof E

        The name of the component to remove.

      Returns void

    • Parameters

      • entity: E

      Returns E

    • Type Parameters

      • C extends string | number | symbol

      Parameters

      • entity: E
      • component: C
      • value: E[C]

      Returns E

    • Parameters

      • entity: E
      • update: Partial<E>

      Returns E

    • Parameters

      • entity: E
      • fun: (entity: E) => void | Partial<E>

      Returns E

    • Creates (or reuses) a query that holds entities that match the given predicate. Please note that as soon as you are building queries that use predicates, you will need to explicitly reindex entities when their properties change.

      Type Parameters

      • D extends {}

      Parameters

      • predicate: Predicate<E, D>

        The predicate that entities must match.

      Returns Query<D>

      A query that holds entities that match the given predicate.

    • Creates (or reuses) a query that holds entities that have all of the specified components.

      Type Parameters

      • C extends string | number | symbol

      Parameters

      • ...components: C[]

        One or more component names to query for.

      Returns Query<With<E, C>>

      A query that holds entities that have all of the given components.

    • Creates (or reuses) a query that holds entities that do not have any of the specified components.

      Type Parameters

      • C extends string | number | symbol

      Parameters

      • ...components: C[]

        One or more component names to query for.

      Returns Query<Without<E, C>>

      A query that holds entities that do not have any of the given components.