• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

excaliburjs / Excalibur / 14804036802

02 May 2025 09:58PM UTC coverage: 5.927% (-83.4%) from 89.28%
14804036802

Pull #3404

github

web-flow
Merge 5c103d7f8 into 0f2ccaeb2
Pull Request #3404: feat: added Graph module to Math

234 of 8383 branches covered (2.79%)

229 of 246 new or added lines in 1 file covered. (93.09%)

13145 existing lines in 208 files now uncovered.

934 of 15759 relevant lines covered (5.93%)

4.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/engine/EntityComponentSystem/TagQuery.ts
1
import { Observable } from '../Util/Observable';
2
import { Entity } from './Entity';
3

4
export class TagQuery<TKnownTags extends string = never> {
5
  public readonly id: string;
UNCOV
6
  public tags = new Set<TKnownTags>();
×
UNCOV
7
  public entities: Entity<any>[] = [];
×
8
  /**
9
   * This fires right after the component is added
10
   */
UNCOV
11
  public entityAdded$ = new Observable<Entity<any>>();
×
12
  /**
13
   * This fires right before the component is actually removed from the entity, it will still be available for cleanup purposes
14
   */
UNCOV
15
  public entityRemoved$ = new Observable<Entity<any>>();
×
16

UNCOV
17
  constructor(public readonly requiredTags: TKnownTags[]) {
×
UNCOV
18
    if (requiredTags.length === 0) {
×
19
      throw new Error('Cannot create tag query without tags');
×
20
    }
UNCOV
21
    for (const tag of requiredTags) {
×
UNCOV
22
      this.tags.add(tag);
×
23
    }
24

UNCOV
25
    this.id = TagQuery.createId(requiredTags);
×
26
  }
27

28
  static createId(requiredComponents: string[]) {
UNCOV
29
    return requiredComponents.slice().sort().join('-');
×
30
  }
31

32
  checkAndAdd(entity: Entity) {
UNCOV
33
    if (!this.entities.includes(entity) && entity.hasAllTags(Array.from(this.tags))) {
×
UNCOV
34
      this.entities.push(entity);
×
UNCOV
35
      this.entityAdded$.notifyAll(entity);
×
UNCOV
36
      return true;
×
37
    }
UNCOV
38
    return false;
×
39
  }
40

41
  removeEntity(entity: Entity) {
UNCOV
42
    const index = this.entities.indexOf(entity);
×
UNCOV
43
    if (index > -1) {
×
UNCOV
44
      this.entities.splice(index, 1);
×
UNCOV
45
      this.entityRemoved$.notifyAll(entity);
×
46
    }
47
  }
48

49
  /**
50
   * Returns a list of entities that match the query
51
   * @param sort Optional sorting function to sort entities returned from the query
52
   */
53
  public getEntities(sort?: (a: Entity, b: Entity) => number): Entity<any>[] {
UNCOV
54
    if (sort) {
×
55
      this.entities.sort(sort);
×
56
    }
UNCOV
57
    return this.entities;
×
58
  }
59
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc