]> git.r.bdr.sh - rbdr/sumo/blob - lib/systems/draw_dash.js
Deploy to Pages
[rbdr/sumo] / lib / systems / draw_dash.js
1 import { System } from '@serpentity/serpentity';
2
3 import DrawnDasherNode from '../nodes/drawn_dasher';
4
5 /**
6 * Shows a different graphic during the duration of lock
7 *
8 * @extends {external:Serpentity.System}
9 * @class DrawDashSystem
10 * @param {object} config a configuration object to extend.
11 */
12 export default class DrawDashSystem extends System {
13
14 constructor(config = {}) {
15
16 super();
17
18 /**
19 * The node collection of dashers
20 *
21 * @property {external:Serpentity.NodeCollection} drawnDashers
22 * @instance
23 * @memberof DrawDashSystem
24 */
25 this.drawnDashers = null;
26 }
27
28 /**
29 * Initializes system when added. Requests drawn dasher nodes
30 *
31 * @function added
32 * @memberof DrawDashSystem
33 * @instance
34 * @param {external:Serpentity.Engine} engine the serpentity engine to
35 * which we are getting added
36 */
37 added(engine) {
38
39 this.drawnDashers = engine.getNodes(DrawnDasherNode);
40 }
41
42 /**
43 * Clears system resources when removed.
44 *
45 * @function removed
46 * @instance
47 * @memberof DrawDashSystem
48 */
49 removed() {
50
51 this.drawnDashers = null;
52 }
53
54 /**
55 * Runs on every update of the loop. Updates image depending on if
56 * dash is locked
57 *
58 * @function update
59 * @instance
60 * @param {Number} currentFrameDuration the duration of the current
61 * frame
62 * @memberof DrawDashSystem
63 */
64 update(currentFrameDuration) {
65
66 for (const drawnDasher of this.drawnDashers) {
67
68 const dash = drawnDasher.dash;
69 const container = drawnDasher.container.container;
70
71 if (dash.locked) {
72 this._drawDashFace(container);
73 continue;
74 }
75
76 this._removeDashFace(container);
77 }
78 }
79
80 // Draws the dash face
81
82 _drawDashFace(container) {
83
84 const blush = container.getChildByName('blush');
85 const smile = container.getChildByName('smile');
86 const frown = container.getChildByName('frown');
87 blush.visible = true;
88 frown.visible = true;
89 smile.visible = false;
90 }
91
92 // Removes the dash face
93
94 _removeDashFace(container) {
95
96 const blush = container.getChildByName('blush');
97 const smile = container.getChildByName('smile');
98 const frown = container.getChildByName('frown');
99 blush.visible = false;
100 frown.visible = false;
101 smile.visible = true;
102 }
103 };