// space.js, a full (not sparse data storage object) with some utilities. // This includes from/to fetch, write, files, and ad-hoc strings. [DONE] [DONE] [DONE] [DONE] [DONE] // It provides combination between Spaces. [DONE] // It also gives a search utility and a utility to grab an arbitrary section [DONE] [DONE] const fs = require('fs') const vec = require('./utils/vec'); function chop(string, n){ // chops a string into n-sized chunks. Assumed to be perfect multiple let arr = []; for (let sec = 0; sec < string.length; sec++){ arr.push(string.slice(sec*n,(sec+1)*n)); } return arr; } function replace(text, old, repl){ //replaces, in an array `text`, the instances of `old` with `repl` for (let i=0; i parseInt(linenum)) // 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<8; line++){ curline = line+8*tilerow; if (conform && incl.includes(line)){ for (let i=0; i<16; i++) this.data[curline].push(' '); } else { Array.prototype.push.apply(this.data[curline],cont[read].split('')); read++; } } } } this.towrite = function(){ // Does no splitting or anything like that. Just returns a list of triplets for the write function let writes = []; for (let line = 0; line < this.data.length; line++) for (let chr = 0; chr < this.data[line].length; chr++){ if (this.data[line][chr] == '') continue; // Internal coding for "do not write" writes.push([[this.loc[0]+line, this.loc[1]+chr],this.data[line][chr]]); } return writes; } this.tofile = function(filename){ fs.writeFileSync(filename, this.print()); }; this.print = function(){ return this.data.map(row => replace(replace(replace(row,'&','\\&'),'\\','\\\\'),'','&').join('')).join('\n'); } this.fromfile = function(filename){ //Reads an external file into internal data this.adhoc(fs.readFileSync(filename,'utf8')); } this.adhoc = function(text){ text = text.split('\n') text = text.map(row => row.split('')); this.data = text.map(row => { for (let i = 0; i