aboutsummaryrefslogtreecommitdiff
path: root/space.js
diff options
context:
space:
mode:
authorHolden Rohrer <holden.rohrer@gmail.com>2019-12-27 14:13:48 -0500
committerHolden Rohrer <holden.rohrer@gmail.com>2019-12-27 14:13:48 -0500
commit790a01a32aa37684a5c39e5af6cb17d892212e79 (patch)
treebd413e7ada66ed2554b4d119ec33df6fcc2a5fd6 /space.js
parent639ec59f1913a903dee3bb9068108b78c193d616 (diff)
added proto-.loc functionality to space.js
Diffstat (limited to 'space.js')
-rw-r--r--space.js25
1 files changed, 15 insertions, 10 deletions
diff --git a/space.js b/space.js
index 50ae16c..c0cce60 100644
--- a/space.js
+++ b/space.js
@@ -3,6 +3,7 @@
// 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 = [];
@@ -11,6 +12,7 @@ function chop(string, n){ // chops a string into n-sized chunks. Assumed to be p
}
return arr;
}
+
function replace(text, old, repl){ //replaces, in an array `text`, the instances of `old` with `repl`
for (let i=0; i<text.length; i++){
if (text[i] == old) text[i] = repl;
@@ -18,16 +20,17 @@ function replace(text, old, repl){ //replaces, in an array `text`, the instances
return text;
}
-function Space(){ // CLASS
- this.data = []; //
- self = this;
- this.fromfetch = function(tiles, dimension, conform=true){ //tiles is straight from fetch/tileUpdate function, dimension is a quadruplet; conform is false for tileUpdate because the cell_props don't actually mean anything; all data is still included
- for (let y=dimension[0]; y<=dimension[2]; y++){
+function Space(){
+ this.data = [];
+ this.loc = []; // Coordinates to represent topleft location of spaces, and aid with .comb
+ this.fromfetch = function(tiles, dimension, conform=true){ //tiles is straight from fetch/tileUpdate function, dimension is a min/max pair of y/x coordinates; conform is false for tileUpdate because the cell_props don't actually mean anything; all data is still included
+ this.loc = vec.tileToChar(dimension[0]);
+ for (let y=dimension[0][0]; y<=dimension[1][0]; y++){
for (let line=0; line<8; line++)
this.data.push([]); // Adds lines
- for (let x=dimension[1]; x<=dimension[3]; x++){
- if (! tiles[[y,x]]) tilein({"content":' '.repeat(16*8),"properties":{"cell_props":{}}}); // Insert a null tile
- else tilein(tiles[[y,x]],y-dimension[0]);
+ for (let x=dimension[0][1]; x<=dimension[1][1]; x++){
+ if (! tiles[[y,x]]) tilein({"content":' '.repeat(16*8),"properties":{"cell_props":{}}}); // Insert a null tile if server sends null
+ else tilein.call(this, tiles[[y,x]], y-dimension[0][0]);
}
}
@@ -38,9 +41,9 @@ function Space(){ // CLASS
for (let line=0; line<8; line++){
curline = line+8*tilerow;
if (conform && incl.includes(line)){
- for (let i=0; i<16; i++) self.data[curline].push(' ');
+ for (let i=0; i<16; i++) this.data[curline].push(' ');
} else {
- Array.prototype.push.apply(self.data[curline],cont[read].split(''));
+ Array.prototype.push.apply(this.data[curline],cont[read].split(''));
read++;
}
}
@@ -54,12 +57,14 @@ function Space(){ // CLASS
}
return writes;
}
+
this.tofile = function(filename){
fs.writeFileSync(filename, this.print());
};
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(''));