blob: 27e7807de7e84dd63651827af3a5b1f13bd5cb41 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
|