Преглед изворни кода

Add Input function

This function takes a value from an external source and pushes it onto
the runtimeInput array. If the computer is on but awaiting input, its
Run function is called to start it again.
ApisNecros пре 1 година
родитељ
комит
5427eacf12
1 измењених фајлова са 14 додато и 0 уклоњено
  1. 14 0
      IntComp/Computer.js

+ 14 - 0
IntComp/Computer.js

@@ -484,6 +484,20 @@ module.exports = class Computer {
         return this.HasOutput() ? this.outputValues.shift() : undefined;
     }
 
+    /**
+     * Accept input from an external source
+     *
+     * The input given here is pushed onto the end of the computer's runtime
+     * input array.
+     *
+     * @param {number} inputValue The number to push onto the runtime input array
+     * @returns {void}
+     */
+    Input(inputValue) {
+        this.runtimeInput.push(inputValue);
+        if (this.running && this.awaitingInput) { this.Run(); }
+    }
+
     /**
      * Resets the computer's memory to the value it was created with
      *