aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/helloworld.js3
-rw-r--r--examples/jarvis.js20
-rw-r--r--space.js13
3 files changed, 30 insertions, 6 deletions
diff --git a/examples/helloworld.js b/examples/helloworld.js
index 4984914..889ce8f 100644
--- a/examples/helloworld.js
+++ b/examples/helloworld.js
@@ -3,8 +3,9 @@ const Space = require('../space');
writes = new Space(); //Generate a place to store potential writes
writes.adhoc('hello\nworld') // A method to fill internal data with inline code.
+writes.loc = [8, 16]; // Declares the location (in terms of characters displaced from the center)
main = new Socket('helloworld'); // Open socket at yourworldoftext.com/helloworld
main.on('open',()=>{ // When socket opens
- main.write(writes.towrite([8,16])); // Tell the server to write the content of `writes` to
+ main.write(writes.towrite()); // Tell the server to write the content of `writes` to
});
diff --git a/examples/jarvis.js b/examples/jarvis.js
index 8b67961..e0cb82f 100644
--- a/examples/jarvis.js
+++ b/examples/jarvis.js
@@ -54,6 +54,26 @@ function identity(sender){
});
}
+let response = new Space();
+response.adhoc('yes, my liege');
+let queue = []; // Must be expanded to handle actual use cases
+let open = true;
+function send(){
+ if (queue.length == 0) open = true;
+ else{
+ main.write(queue.shift());
+ setTimeout(send, 1000);
+ }
+}
function respond(coord){
+ response.loc = coord;
console.log('called at', coord);
+ if (open){
+ main.write(response.towrite());
+ setTimeout(send, 1000);
+ } else {
+ queue.push(response.towrite());
+ }
+ send(response.towrite());
+ main.write(response.towrite());
}
diff --git a/space.js b/space.js
index c0cce60..0dffbca 100644
--- a/space.js
+++ b/space.js
@@ -49,11 +49,12 @@ function Space(){
}
}
}
- this.towrite = function(charoffset){ // Does no splitting or anything like that. Just returns a list of triplets for the write function
+
+ 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;
- writes.push([[charoffset[0]+line,charoffset[1]+chr],this.data[line][chr]]);
+ 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;
}
@@ -99,7 +100,9 @@ function Space(){
}
}
}
- this.search = function(other){ //Returns first instance of a subspace (prioritized vertically then horizontally)
+
+ this.search = function(other){ //Returns first instance of `other` subspace (prioritized vertically then horizontally)
+ // Non-standard exclusion of this.loc
let loc = [];
for (let line=0; line<=this.data.length-other.data.length; line++){ for (let chr=0; chr<=this.data[line].length-other.data[0].length; chr++){
var match = true;