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

excaliburjs / Excalibur / 26695878420

30 May 2026 09:52PM UTC coverage: 88.18% (+0.006%) from 88.174%
26695878420

Pull #3755

github

web-flow
Merge 214356112 into 3c2d14e00
Pull Request #3755: fix: ActionQueue used incorrect splice to remove

5400 of 7267 branches covered (74.31%)

1 of 2 new or added lines in 1 file covered. (50.0%)

15301 of 17352 relevant lines covered (88.18%)

24015.94 hits per line

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

87.5
/src/engine/actions/action-queue.ts
1
import { ActionCompleteEvent, ActionStartEvent } from '../events';
2
import type { Entity } from '../entity-component-system/entity';
3
import type { Action } from './action';
4

5
/**
6
 * Action Queues represent an ordered sequence of actions
7
 *
8
 * Action queues are part of the {@apilink ActionContext | `Action API`} and
9
 * store the list of actions to be executed for an {@apilink Actor}.
10
 *
11
 * Actors implement {@apilink Actor.actions} which can be manipulated by
12
 * advanced users to adjust the actions currently being executed in the
13
 * queue.
14
 */
15
export class ActionQueue {
16
  private _entity: Entity;
17
  private _actions: Action[] = [];
925✔
18
  private _currentAction: Action | null = null;
925✔
19
  private _completedActions: Action[] = [];
925✔
20
  constructor(entity: Entity) {
21
    this._entity = entity;
925✔
22
  }
23

24
  /**
25
   * Add an action to the sequence
26
   * @param action
27
   */
28
  public add(action: Action) {
29
    this._actions.push(action);
292✔
30
  }
31

32
  /**
33
   * Remove an action by reference from the sequence
34
   * @param action
35
   */
36
  public remove(action: Action) {
37
    const index = this._actions.indexOf(action);
1✔
38
    if (index > -1) {
1!
NEW
39
      this._actions.splice(index, 1);
×
40
    }
41
  }
42

43
  /**
44
   * Removes all actions from this sequence
45
   */
46
  public clearActions(): void {
47
    this._actions.length = 0;
128✔
48
    this._completedActions.length = 0;
128✔
49
    if (this._currentAction) {
128!
50
      this._currentAction.stop();
128✔
51
    }
52
  }
53

54
  /**
55
   *
56
   * @returns The total list of actions in this sequence complete or not
57
   */
58
  public getActions(): Action[] {
59
    return this._actions.concat(this._completedActions);
16✔
60
  }
61

62
  public getIncompleteActions(): Action[] {
63
    return this._actions;
×
64
  }
65

66
  public getCurrentAction(): Action | null {
67
    return this._currentAction;
×
68
  }
69

70
  /**
71
   *
72
   * @returns `true` if there are more actions to process in the sequence
73
   */
74
  public hasNext(): boolean {
75
    return this._actions.length > 0;
×
76
  }
77

78
  /**
79
   * @returns `true` if the current sequence of actions is done
80
   */
81
  public isComplete(): boolean {
82
    return this._actions.length === 0;
340✔
83
  }
84

85
  /**
86
   * Resets the sequence of actions, this is used to restart a sequence from the beginning
87
   */
88
  public reset(): void {
89
    this._actions = this.getActions();
10✔
90

91
    const len = this._actions.length;
10✔
92
    for (let i = 0; i < len; i++) {
10✔
93
      this._actions[i].reset();
22✔
94
    }
95
    this._completedActions = [];
10✔
96
  }
97

98
  /**
99
   * Update the queue which updates actions and handles completing actions
100
   * @param elapsed
101
   */
102
  public update(elapsed: number) {
103
    if (this._actions.length > 0) {
2,504✔
104
      if (this._currentAction !== this._actions[0]) {
868✔
105
        this._currentAction = this._actions[0];
281✔
106
        this._entity.emit('actionstart', new ActionStartEvent(this._currentAction, this._entity));
281✔
107
      }
108

109
      this._currentAction.update(elapsed);
868✔
110

111
      if (this._currentAction.isComplete(this._entity)) {
868✔
112
        this._entity.emit('actioncomplete', new ActionCompleteEvent(this._currentAction, this._entity));
229✔
113
        const complete = this._actions.shift();
229✔
114
        if (complete) {
229✔
115
          this._completedActions.push(complete);
227✔
116
        }
117
      }
118
    }
119
  }
120
}
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