|
@@ -76,6 +76,64 @@ class CodeBox {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Parse the initial code box
|
|
|
+ *
|
|
|
+ * Transforms the textual code box into usable matrix
|
|
|
+ */
|
|
|
+ ParseCodeBox() {
|
|
|
+ const cbRaw = this.codeBoxDOM.value;
|
|
|
+ const rows = cbRaw.split("\n").filter((r) => r.length);
|
|
|
+
|
|
|
+ let maxRowLength = 0;
|
|
|
+ for(const row of rows) {
|
|
|
+ const rowSplit = row.split("");
|
|
|
+
|
|
|
+ // Store this for later processing
|
|
|
+ while(rowSplit.length > maxRowLength) {
|
|
|
+ maxRowLength = rowSplit.length
|
|
|
+ }
|
|
|
+
|
|
|
+ this.box.push(rowSplit);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.EqualizeBoxWidth(maxRowLength);
|
|
|
+
|
|
|
+ let fin = null;
|
|
|
+
|
|
|
+ try {
|
|
|
+ while(!fin) {
|
|
|
+ fin = this.Swim();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(e) {
|
|
|
+ console.error(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Make all the rows in the code box the same length
|
|
|
+ *
|
|
|
+ * All rows not long enough will have NOPs added until they're uniform in size.
|
|
|
+ *
|
|
|
+ * @param {int} [rowLength] The longest row in the code box
|
|
|
+ */
|
|
|
+ EqualizeBoxWidth(rowLength = null) {
|
|
|
+ if(!rowLength) {
|
|
|
+ for(const row of this.box) {
|
|
|
+ if(row.length > rowLength) {
|
|
|
+ rowLength = row.length;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for(const row of this.box) {
|
|
|
+ while(row.length < rowLength) {
|
|
|
+ row.push(" ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Print the value to the display
|
|
|
*
|