has

View sourcehas<T>(component: Constructor<T>): Has<T>

Creates a Has filter for a component constructor.

The returned QueryFilter accepts an archetype only when its complete component TypeId list includes the TypeId derived from component. Extra components are allowed. Its identity type transform preserves the query’s component tuple while the filter narrows which archetypes Query visits.

The factory only creates the filter; it does not mutate a Query or World.

Examples

import { Query, World, has } from '@wimaengine/ecs'

class Position {}
class Visible {}

const world = new World()
world.spawn([new Position(), new Visible()])
world.spawn([new Position()])

const query = new Query(world, [Position], [has(Visible)])
query.each(([position]) => {
  // Only the entity with Visible is visited; the tuple contains Position.
  console.log(position)
})

Type Parameters

T

Parameters

NameDescriptionDefault
component

Component constructor that must be present.

—

Returns

A query filter with an identity component transform.