Skip to content

Matcher API

MethodDescriptionExample
Matcher.all(...types)Must include all specified componentsMatcher.all(Position, Velocity)
Matcher.any(...types)Include at least one specified componentMatcher.any(Health, Shield)
Matcher.none(...types)Must not include any specified componentsMatcher.none(Dead)
Matcher.byTag(tag)Query by tagMatcher.byTag(1)
Matcher.byName(name)Query by nameMatcher.byName("Player")
Matcher.byComponent(type)Query by single componentMatcher.byComponent(Health)
Matcher.empty()Create empty matcher (matches all entities)Matcher.empty()
Matcher.nothing()Match no entitiesMatcher.nothing()
Matcher.complex()Create complex query builderMatcher.complex()
MethodDescriptionExample
.all(...types)Add required components.all(Position)
.any(...types)Add optional components (at least one).any(Weapon, Magic)
.none(...types)Add excluded components.none(Dead)
.exclude(...types)Alias for .none().exclude(Disabled)
.one(...types)Alias for .any().one(Player, Enemy)
.withTag(tag)Add tag condition.withTag(1)
.withName(name)Add name condition.withName("Boss")
.withComponent(type)Add single component condition.withComponent(Health)
MethodDescription
.getCondition()Get query condition (read-only)
.isEmpty()Check if empty condition
.isNothing()Check if nothing matcher
.clone()Clone matcher
.reset()Reset all conditions
.toString()Get string representation
// Basic movement system
Matcher.all(Position, Velocity)
// Attackable living entities
Matcher.all(Position, Health)
.any(Weapon, Magic)
.none(Dead, Disabled)
// All tagged enemies
Matcher.byTag(Tags.ENEMY)
.all(AIComponent)
// System only needing lifecycle
Matcher.nothing()
class PlayerSystem extends EntitySystem {
constructor() {
// Query entities with specific tag
super(Matcher.empty().withTag(Tags.PLAYER));
}
protected process(entities: readonly Entity[]): void {
// Only process player entities
}
}
class BossSystem extends EntitySystem {
constructor() {
// Query entities with specific name
super(Matcher.empty().withName('Boss'));
}
protected process(entities: readonly Entity[]): void {
// Only process entities named 'Boss'
}
}
const matcher = Matcher.empty().all(PositionComponent);
// Chain calls return new Matcher instances
const matcher2 = matcher.any(VelocityComponent);
// Original matcher unchanged
console.log(matcher === matcher2); // false
const result = querySystem.queryAll(PositionComponent);
// Don't modify returned array
result.entities.push(someEntity); // Wrong!
// If modification needed, copy first
const mutableArray = [...result.entities];
mutableArray.push(someEntity); // Correct