aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHolden Rohrer <holden.rohrer@gmail.com>2019-12-17 21:46:16 -0500
committerHolden Rohrer <holden.rohrer@gmail.com>2019-12-17 21:46:16 -0500
commitdaacfba1adfb0a32c9168088bf6c928f82438582 (patch)
treefbc7c4ea08a2a364c2a4b70d49dcb2b3910d66d4
parentd362969d840db3b2e157655c1b2a6325fec2aacc (diff)
created space.js with fetch function
-rw-r--r--space.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/space.js b/space.js
new file mode 100644
index 0000000..27e7807
--- /dev/null
+++ b/space.js
@@ -0,0 +1,40 @@
+// space.js, a full (not sparse data storage object) with some utilities.
+// This includes from/to fetch, write, tile, and files.
+// It provides combination between Spaces.
+// It also gives a search utility.
+const fs = require('fs')
+
+function chop(string, n){ // chops a string into n-sized chunks. Assumed to be perfect multiple
+ arr = []
+ while (string.length > 0){
+ arr += string.slice(0,16);
+ }
+}
+
+class Space{
+ this.data = []; //
+ this.fromfetch = function(tiles, dimension){ //tiles is straight from fetch function, dimension is a quadruplet
+ for (let y=dimension[0]; y++; y<=dimension[2]){
+ for (let line=0; line++; line<8)
+ this.data.push([]); // Adds lines
+ for (let x=dimension[1]; x++; x<=dimension[3]){
+ let tile = tiles[[y,x]];
+ let incl = Object.keys(tile.properties.cell_props).map(linenum => linenum.parseInt()); // list of included lines in the content
+ let cont = chop(tile.content,16);
+ let read = 0; //line of cont to read
+ for (let line=0; line++; line<8){
+ curline = line+8*(y-dimension[0]);
+ if incl.includes(line){
+ this.data[curline] += cont[read];
+ read++;
+ } else {
+ this.data[curline] += ' '.repeat(16);
+ }
+ }
+ }
+ }
+ }
+}
+
+
+exports.Space = Space