aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--socket.js6
-rw-r--r--space.js40
2 files changed, 25 insertions, 21 deletions
diff --git a/socket.js b/socket.js
index 0e84222..29bab25 100644
--- a/socket.js
+++ b/socket.js
@@ -26,7 +26,6 @@ class retryws extends EventEmitter{ // a wrapper on ws that retries on failure
}
}
-
class Socket extends retryws {
constructor(world='') { // Takes the name of the world, which can be an empty string.
let loc = (world == '') ? '' : `/${world}`;
@@ -59,8 +58,9 @@ class Socket extends retryws {
throw "Too many characters to write";
}
for (var i=0; i<chars.length; i++){
- chars[i] = chars[i].flat();
- chars[i].splice(4,0,0); //
+ let char = chars[i]
+ chars[i] = [char[0][0],char[0][1],char[1][0],char[1][1],char[2]];
+ chars[i].splice(4,0,0);
chars[i].push(i);
}
this.send(`{"edits":${JSON.stringify(chars)},"kind":"write"}`);
diff --git a/space.js b/space.js
index b6ec069..89d2830 100644
--- a/space.js
+++ b/space.js
@@ -11,62 +11,66 @@ function chop(string, n){ // chops a string into n-sized chunks. Assumed to be p
}
}
function replace(text, old, repl){ //replaces, in an array `text`, the instances of `old` with `repl`
- for (let i=0; i++; i<text.length){
+ for (let i=0; i<text.length; i++){
if (text[i] == old) text[i] = repl;
}
return text;
}
-class Space{
+function Space(){ // CLASS
this.data = []; //
self = this;
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)
+ for (let y=dimension[0]; y<=dimension[2]; y++){
+ for (let line=0; line<8; line++)
this.data.push([]); // Adds lines
- for (let x=dimension[1]; x++; x<=dimension[3]){
+ for (let x=dimension[1]; x<=dimension[3]; x++){
tilein(tiles[[y,x]],y-dimension[0]);
}
}
- function tilein = function(tile, tilerow){ //tile is one of the tiles from `tiles`, and tilerow is y-dimension[0]; helper function
+ function tilein(tile, tilerow){ //tile is one of the tiles from `tiles`, and tilerow is y-dimension[0]; helper function
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){
+ for (let line=0; line<8; line++){
curline = line+8*tilerow;
- if incl.includes(line){
+ if (incl.includes(line)){
this.data[curline] += cont[read].split('');
read++;
} else {
- for (let i=0; i++; i<16) this.data[curline].push(' ');
+ for (let i=0; i<16; i++) this.data[curline].push(' ');
}
}
}
}
this.towrite = function(charoffset){ // Does no splitting or anything like that. Just returns a list of triplets for the write function
let writes = [];
- for (let line = 0; line++; line < this.data.length) for (let chr = 0; chr++; chr< this[line].data.length){
- writes.push([line+Math.floor( (charoffset[0]+line)/8 ),line+Math.floor( (charoffset[1]+chr)/16 )],[ (charoffset[0]+line) % 8, (charoffset[1]+chr) % 16 ],this.data[line][chr]);
+ console.log(this.data.length);
+ for (line = 0; line < this.data.length; line++){
+ console.log('boarlocueurgdaoecugd');
+ }
+ for (let line = 0; line < this.data.length; line++) for (let chr = 0; chr< this.data[line].length; chr++){
+ writes.push([[Math.floor( (charoffset[0]+line)/8 ),Math.floor( (charoffset[1]+chr)/16 )],[ (charoffset[0]+line) % 8, (charoffset[1]+chr) % 16 ],this.data[line][chr]]);
}
return writes;
}
this.tofile = function(filename){
- fs.writeFile(filename,this.data.map(row => replace(row,'','&').join('').replace(/\\|&/g, '\\$&')).join('\n'),(err)={console.log(err);});
+ fs.writeFile(filename,this.data.map(row => replace(row,'','&').join('').replace(/\\|&/g, '\\$&')).join('\n')+'\n',(err)=>{console.log(err);});
};
this.fromfile = function(filename){ //Reads an external file into internal data
fs.readFile(filename, (err, data) => {
if (err) throw err;
self.adhoc(data);
- }
+ });
}
this.adhoc = function(text){
this.data = text.split('\n').slice(0,-1).map(row => replace(row.replace(/\\(.)/g,'$1'.split(''),'&','')));
}
- this.comb(other, func, offset){
+ this.comb = function(other, func, offset){
offsety = offset[0];
offsetx = offset[1];
- for (let row = offset[0]; row++; row<Math.max(other.data.length+offset[0],this.data.length)) for (let chr = offset[1]; chr++; chr<Math.max(otherlens.data[row].length+offset[1],this.data[row].length)){
+ for (let row = offset[0]; row<Math.max(other.data.length+offset[0],this.data.length); row++) for (let chr = offset[1]; chr<Math.max(otherlens.data[row].length+offset[1],this.data[row].length); chr++){
if (row < 0)
this.data.unshift([]);
if (chr < 0)
@@ -80,9 +84,9 @@ class Space{
}
this.search = function(other){
loc = [];
- for (let line=0; line++; line<=this.data.length-other.data.length) for (let chr=0; chr++; chr<=this.data[y].length-other.data[0].length){
+ for (let line=0; line<=this.data.length-other.data.length; line++) for (let chr=0; chr<=this.data[y].length-other.data[0].length; chr++){
match = true;
- for (var y=0; y++; y<other.data.length) for (var x=0; x++; x<other[y].data.length){
+ for (var y=0; y<other.data.length; y++) for (var x=0; x<other[y].data.length; x++){
if (this.data[line+y][chr+x] != other.data[y][x]){
match = false;
break;
@@ -97,7 +101,7 @@ class Space{
}
this.subsection = function(range){ // range is a standard quadruplet
newspace = new Space();
- for (let line=0; line++; line<range[2]-range[0]) for (let chr=0; chr++; chr<range[3]-range[1]){
+ for (let line=0; line<range[2]-range[0]; line++) for (let chr=0; chr<range[3]-range[1]; chr++){
newspace.data[line][chr] = this.data[line+range[0]][line+range[1]];
}
}