aboutsummaryrefslogtreecommitdiff
path: root/lib/systems/draw_dash.js
blob: cb04eb59e133f8e4d93a4fab8f9a245ab523dfa6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { System } from '@serpentity/serpentity';

import DrawnDasherNode from '../nodes/drawn_dasher';

/**
 * Shows a different graphic during the duration of lock
 *
 * @extends {external:Serpentity.System}
 * @class DrawDashSystem
 * @param {object} config a configuration object to extend.
 */
export default class DrawDashSystem extends System {

  constructor(config = {}) {

    super();

    /**
     * The node collection of dashers
     *
     * @property {external:Serpentity.NodeCollection} drawnDashers
     * @instance
     * @memberof DrawDashSystem
     */
    this.drawnDashers = null;
  }

  /**
   * Initializes system when added. Requests drawn dasher nodes
   *
   * @function added
   * @memberof DrawDashSystem
   * @instance
   * @param {external:Serpentity.Engine} engine the serpentity engine to
   * which we are getting added
   */
  added(engine) {

    this.drawnDashers = engine.getNodes(DrawnDasherNode);
  }

  /**
   * Clears system resources when removed.
   *
   * @function removed
   * @instance
   * @memberof DrawDashSystem
   */
  removed() {

    this.drawnDashers = null;
  }

  /**
   * Runs on every update of the loop. Updates image depending on if
   * dash is locked
   *
   * @function update
   * @instance
   * @param {Number} currentFrameDuration the duration of the current
   * frame
   * @memberof DrawDashSystem
   */
  update(currentFrameDuration) {

    for (const drawnDasher of this.drawnDashers) {

      const dash = drawnDasher.dash;
      const container = drawnDasher.container.container;

      if (dash.locked) {
        this._drawDashFace(container);
        continue;
      }

      this._removeDashFace(container);
    }
  }

  // Draws the dash face

  _drawDashFace(container) {

    const blush = container.getChildByName('blush');
    const smile = container.getChildByName('smile');
    const frown = container.getChildByName('frown');
    blush.visible = true;
    frown.visible = true;
    smile.visible = false;
  }

  // Removes the dash face

  _removeDashFace(container) {

    const blush = container.getChildByName('blush');
    const smile = container.getChildByName('smile');
    const frown = container.getChildByName('frown');
    blush.visible = false;
    frown.visible = false;
    smile.visible = true;
  }
}