aboutsummaryrefslogtreecommitdiff
path: root/lib/systems/draw_grab.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/systems/draw_grab.js')
-rw-r--r--lib/systems/draw_grab.js115
1 files changed, 115 insertions, 0 deletions
diff --git a/lib/systems/draw_grab.js b/lib/systems/draw_grab.js
new file mode 100644
index 0000000..21ffdcd
--- /dev/null
+++ b/lib/systems/draw_grab.js
@@ -0,0 +1,115 @@
+import { System } from '@serpentity/serpentity';
+
+import DrawnGrabberNode from '../nodes/drawn_grabber';
+
+/**
+ * Shows a different graphic during the duration of lock
+ *
+ * @extends {external:Serpentity.System}
+ * @class DrawGrabSystem
+ * @param {object} config a configuration object to extend.
+ */
+export default class DrawGrabSystem extends System {
+
+ constructor(config = {}) {
+
+ super();
+
+ /**
+ * The node collection of grabbers
+ *
+ * @property {external:Serpentity.NodeCollection} drawnGrabbers
+ * @instance
+ * @memberof DrawGrabSystem
+ */
+ this.drawnGrabbers = null;
+ }
+
+ /**
+ * Initializes system when added. Requests drawn grabber nodes
+ *
+ * @function added
+ * @memberof DrawGrabSystem
+ * @instance
+ * @param {external:Serpentity.Engine} engine the serpentity engine to
+ * which we are getting added
+ */
+ added(engine) {
+
+ this.drawnGrabbers = engine.getNodes(DrawnGrabberNode);
+ }
+
+ /**
+ * Clears system resources when removed.
+ *
+ * @function removed
+ * @instance
+ * @memberof DrawGrabSystem
+ */
+ removed() {
+
+ this.drawnGrabbers = null;
+ }
+
+ /**
+ * Runs on every update of the loop. Updates image depending on if
+ * grab is locked and active
+ *
+ * @function update
+ * @instance
+ * @param {Number} currentFrameDuration the duration of the current
+ * frame
+ * @memberof DrawGrabSystem
+ */
+ update(currentFrameDuration) {
+
+ for (const drawnGrabber of this.drawnGrabbers) {
+
+ const grab = drawnGrabber.grab;
+ const container = drawnGrabber.container.container;
+
+ if (grab.locked && grab.constraint) {
+ this._drawGrabFace(container);
+ continue;
+ }
+
+ if (grab.locked) {
+ this._drawGrabCooldownFace(container);
+ continue;
+ }
+
+ this._removeGrabFace(container);
+ }
+ }
+
+ // Draws the grab face
+
+ _drawGrabFace(container) {
+
+ const effort = container.getChildByName('effort');
+ const shadow = container.getChildByName('shadow');
+ effort.visible = true;
+ shadow.visible = false;
+ }
+
+ // Draws the grab cooldown face
+
+ _drawGrabCooldownFace(container) {
+
+ const effort = container.getChildByName('effort');
+ const shadow = container.getChildByName('shadow');
+ effort.visible = false;
+ shadow.visible = true;
+ }
+
+ // Removes the dash face
+
+ _removeGrabFace(container) {
+
+ const effort = container.getChildByName('effort');
+ const shadow = container.getChildByName('shadow');
+ effort.visible = false;
+ shadow.visible = false;
+ }
+};
+