]> git.r.bdr.sh - rbdr/sumo/blame_incremental - lib/systems/draw_grab.js
Merge branch 'feature/rbdr-gitlab-pipeline' into 'develop'
[rbdr/sumo] / lib / systems / draw_grab.js
... / ...
CommitLineData
1import { System } from '@serpentity/serpentity';
2
3import DrawnGrabberNode from '../nodes/drawn_grabber';
4
5/**
6 * Shows a different graphic during the duration of lock
7 *
8 * @extends {external:Serpentity.System}
9 * @class DrawGrabSystem
10 * @param {object} config a configuration object to extend.
11 */
12export default class DrawGrabSystem extends System {
13
14 constructor(config = {}) {
15
16 super();
17
18 /**
19 * The node collection of grabbers
20 *
21 * @property {external:Serpentity.NodeCollection} drawnGrabbers
22 * @instance
23 * @memberof DrawGrabSystem
24 */
25 this.drawnGrabbers = null;
26 }
27
28 /**
29 * Initializes system when added. Requests drawn grabber nodes
30 *
31 * @function added
32 * @memberof DrawGrabSystem
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.drawnGrabbers = engine.getNodes(DrawnGrabberNode);
40 }
41
42 /**
43 * Clears system resources when removed.
44 *
45 * @function removed
46 * @instance
47 * @memberof DrawGrabSystem
48 */
49 removed() {
50
51 this.drawnGrabbers = null;
52 }
53
54 /**
55 * Runs on every update of the loop. Updates image depending on if
56 * grab is locked and active
57 *
58 * @function update
59 * @instance
60 * @param {Number} currentFrameDuration the duration of the current
61 * frame
62 * @memberof DrawGrabSystem
63 */
64 update(currentFrameDuration) {
65
66 for (const drawnGrabber of this.drawnGrabbers) {
67
68 const grab = drawnGrabber.grab;
69 const container = drawnGrabber.container.container;
70
71 if (grab.locked && grab.constraint) {
72 this._drawGrabFace(container);
73 continue;
74 }
75
76 if (grab.locked) {
77 this._drawGrabCooldownFace(container);
78 continue;
79 }
80
81 this._removeGrabFace(container);
82 }
83 }
84
85 // Draws the grab face
86
87 _drawGrabFace(container) {
88
89 const effort = container.getChildByName('effort');
90 const shadow = container.getChildByName('shadow');
91 effort.visible = true;
92 shadow.visible = false;
93 }
94
95 // Draws the grab cooldown face
96
97 _drawGrabCooldownFace(container) {
98
99 const effort = container.getChildByName('effort');
100 const shadow = container.getChildByName('shadow');
101 effort.visible = false;
102 shadow.visible = true;
103 }
104
105 // Removes the dash face
106
107 _removeGrabFace(container) {
108
109 const effort = container.getChildByName('effort');
110 const shadow = container.getChildByName('shadow');
111 effort.visible = false;
112 shadow.visible = false;
113 }
114};
115