diff options
| -rw-r--r-- | space.js | 40 | 
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  | 
