Sfoglia il codice sorgente

Add input, codebox, and output storage to CodeBox

CodeBox class now keeps a reference to the UI elements used for input
and output.
ApisNecros 1 anno fa
parent
commit
ca277e5086
1 ha cambiato i file con 17 aggiunte e 2 eliminazioni
  1. 17 2
      starfish.js

+ 17 - 2
starfish.js

@@ -2,7 +2,7 @@
  * The code box class
  */
 class CodeBox {
-    constructor() {
+    constructor(codeBoxID, initialStackID, outputID) {
         /**
          * Possible vectors the pointer can move in
          * @type {Object}
@@ -59,6 +59,21 @@ class CodeBox {
          * @type {Stack}
          */
         this.stack = new Stack();
+
+        this.codeBoxDOM = document.getElementById(codeBoxID);
+        if(!this.codeBoxDOM) {
+            throw new Error(`Failed to find textarea with ID: ${codeBoxID}`);
+        }
+
+        this.outputDOM = document.getElementById(outputID);
+        if(!this.outputDOM) {
+            throw new Error(`Failed to find textarea with ID: ${outputID}`);
+        }
+
+        this.initialStackDOM = document.getElementById(initialStackID);
+        if(!this.initialStackDOM) {
+            throw new Error(`Failed to find input with ID: ${initialStackID}`);
+        }
     }
 
     /**
@@ -68,7 +83,7 @@ class CodeBox {
      * @param {*} value 
      */
     Output(value) {
-        console.log(value);
+        this.outputDOM.value += value;
     }
 
     Execute(instruction) {