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