Has

View source

Filters a Query to archetypes that contain a component type.

Use has when constructing this filter through the factory API.

Examples

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

class Position {}
class Visible {}

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

Constructor


constructor<T>(component: Constructor<T>)

View source

Creates a filter that requires a component type in matching archetypes.

The component constructor is converted to a TypeId with typeid and stored in Has#typeid. This does not add the component to a Query; pass the filter to the query directly or use has.

Type Parameters

T

Parameters

NameDescriptionDefault
component

Component constructor whose TypeId must be present.

—

Properties


typeid: TypeId

View source

TypeId of the component that a matching archetype must contain.

The constructor stores typeid(component) here. The Has#archetype method compares this value with the archetype’s complete component TypeId list.

Methods


archetype(types: readonly TypeId[]): boolean

View source

Checks whether an archetype contains the configured component type.

This method receives the archetype’s complete TypeId list. Extra types are allowed; the result depends only on whether this filter’s TypeId is included.

Parameters

NameDescriptionDefault
types

Complete component TypeIds in the archetype.

—

Returns

true when the archetype includes Has#typeid.