Class
Optional
View sourceExtendsQueryFilter
Represents a filter that makes a component descriptor optional in a
Query while retaining its position in the result tuple.
Use optional when constructing this filter through the factory API.
Examples
import { Optional, Query, World } from '@wimaengine/ecs'
class Position {}
class Velocity {}
const world = new World()
world.spawn([new Position()])
const query = new Query(world, [Position, Velocity], [new Optional(Velocity)])
query.single() // [Position instance, undefined]Constructor
View source
Properties
readonlytypeid: TypeId
View sourceType ID of the component descriptor made optional by this filter.
Optional#isRequired compares each query descriptor with
this value. The ID is derived from the constructor supplied to
Optional#constructor and is not a component value or an archetype
ID.
Methods
isRequired(type: TypeId): boolean
View sourceMakes only this filter’s component descriptor non-required.
Query calls this method for every descriptor while building its
required-descriptor list. It returns false when type equals
Optional#typeid, and true for every other descriptor.
The targeted descriptor stays in the query tuple and is read as
undefined when the matching archetype has no such component; this method
does not inspect an archetype or alter other filters.
archetype(_types: readonly TypeId[]): boolean
View sourceReturns whether an archetype’s component layout matches this filter.
Query#update passes the complete, read-only TypeId list from the
Archetype. The method does not receive an entity, row, or
component value. The default accepts every archetype; a query includes an
archetype only when this method returns true for every configured filter.
