From b04db8e3e4e215347db16d59179955ed195d021f Mon Sep 17 00:00:00 2001
From: Holden Rohrer <hr@hrhr.dev>
Date: Mon, 20 Jan 2020 22:46:19 -0500
Subject: bug statement

---
 examples/jarvis.js | 4 ++++
 1 file changed, 4 insertions(+)

(limited to 'examples')

diff --git a/examples/jarvis.js b/examples/jarvis.js
index 04c12db..a95131a 100644
--- a/examples/jarvis.js
+++ b/examples/jarvis.js
@@ -1,5 +1,9 @@
 // A bot which responds to `jarvis` with a box
 
+// BUG: The Scheduler, Search, Claims, ident, AND Write Listener can ALL be 
+// used as extensions for Socket. This would make the code so much easier to 
+// understand
+
 const Space = require('../space');
 const Socket = require('../socket');
 const ms = require('../utils/measurespace');
-- 
cgit 


From 496ee8200fa540663fafd7092f8ca5cce65a0bef Mon Sep 17 00:00:00 2001
From: Holden Rohrer <hr@hrhr.dev>
Date: Fri, 24 Jan 2020 15:34:32 -0500
Subject: jarvis integrated new changes

---
 examples/jarvis.js | 57 +++++++++++++++++++++++++++++-------------------------
 1 file changed, 31 insertions(+), 26 deletions(-)

(limited to 'examples')

diff --git a/examples/jarvis.js b/examples/jarvis.js
index 0dad87e..31a3443 100644
--- a/examples/jarvis.js
+++ b/examples/jarvis.js
@@ -18,38 +18,43 @@ const wwrap = require('../utils/writewrap');
 const Claims = require('../tools/claim');
 
 //// The queue of all writes to be sent to the server @ 200chars/1000ms
-var writes = new sched.Queue(1000, 200, (elems) => main.write(elems));
-var main = new Socket();
-var claims = new Claims(detectPrompt);
+class MetaSocket extends Socket{
+  constructor(world='', delayms=1000){
+    super(world);
+    let self = this;
+    sched.Queue.call(self, 1000, 200, (elems) => self.write(elems));
+    Claims.call(self);
+    id.call(self);
+    wwrap.call(self);
+    self.sender;
+    self.on('init',(send)=>{
+      self.sender = send;
+    });
+  }
+}
+var main = new MetaSocket('testworld');
 
 // See ident.js for further documentation, but this basically sets up init functions
-id(main, initOnce, init, deinit);
-writeListen = new wwrap(main);
-
-var sender;
-function init(send){
-  sender = send; // tileUpdates require knowledge of the sender
-  setTimeout(()=>{writes.enable()},1000); // Would fail if a write were added because it would be within a second of cursor send
-  writes.enqueue(genNotif().towrite());
-}
 
-function deinit(){
-  writes.disable();
-}
+main.on('init', (send)=>{
+  setTimeout(()=>{main.enable()},1000);
+  main.enqueue(genNotif().towrite());
+});
+main.on('close', ()=>main.disable());
 
-function initOnce(){
+main.on('initOnce', ()=>{
   timect();
   main.on('tileUpdate', tileHandler); // Should only be active after the "control space" of the notification has been established
-}
+});
 
 //// Management utilities
 
 // When a tile changes, processes data into usable form and runs every function in `funcs` w/ that data.
 // Note that functions can edit inputs
 function tileHandler(send, source, tiles){
-  if (send == sender) return;
+  if (send == main.sender) return;
   let tiledata = maketiles(tiles);
-  claims.handle(send, tiledata.tilespaces, tiledata.locs);
+  main.handle(send, tiledata.tilespaces, tiledata.locs);
 }
 
 //// "userspace" functions for responses, like to tileUpdates
@@ -81,14 +86,14 @@ function notifRefresh(){
   let diff = newnotif.copy();
   if (typeof notif !== 'undefined') diff.comb(notif, comb.sub);
   notif = newnotif;
-  if (notifClaim) claims.unclaim(notifClaim);
-  notifClaim = claims.claim(newnotif, protectArea);
+  if (notifClaim) main.unclaim(notifClaim);
+  notifClaim = main.claim(newnotif, protectArea);
   return (diff.towrite());
 }
 
 function timect(){
   minsUp++;
-  writes.enqueue(notifRefresh());
+  main.enqueue(notifRefresh());
   setTimeout(timect, 60*1000);
 }
 
@@ -99,7 +104,7 @@ function protectArea(send, tiles, locs, id, space, ctrl){
     let diff = space.copy(); // Acts as a window for tile (only see relevant data)
     diff.comb(tile, comb.flip(comb.unmask));
     diff.comb(tile, comb.sub);
-    writes.enqueue(diff.towrite())
+    main.enqueue(diff.towrite())
   }
 }
 
@@ -108,7 +113,7 @@ search.adhoc('jarvis'); // The search space is the word jarvis, so whenever that
 var read = new Search(search);
 var expire = {};
 
-function detectPrompt(send, tiles, locs){ // tries to detect the prompt ('jarvis') and calls respond if found.
+main.on('fallback', (send, tiles, locs) => { // tries to detect the prompt ('jarvis') and calls respond if found.
   for (let i=0; i<locs.length; i++){
     let loc = locs[i];
     if (read.has(loc)){
@@ -120,7 +125,7 @@ function detectPrompt(send, tiles, locs){ // tries to detect the prompt ('jarvis
     if (results.length > 0) respond(results, send);
     expire[loc] = setTimeout(() => {read.del(loc); delete expire[loc];}, 30000);
   }
-}
+});
 
 let response = new Space();
 response.adhoc('yes, my liege');
@@ -131,7 +136,7 @@ function respond(coord, send){
   console.log('called at', coord);
   callct += 1;
   response.loc = coord;
-  writes.enqueue(response.towrite().concat(notifRefresh()));
+  main.enqueue(response.towrite().concat(notifRefresh()));
   read.update(response);
   setTimeout(() => {limits.splice(limits.indexOf(send))}, 5*1000);
   limits.push(send);
-- 
cgit 


From fdac79c026a2f6a321a1a3846c2f331bede6af02 Mon Sep 17 00:00:00 2001
From: Holden Rohrer <hr@hrhr.dev>
Date: Fri, 24 Jan 2020 18:15:09 -0500
Subject: jarvis changed in preparation for search refactor

---
 examples/jarvis.js | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

(limited to 'examples')

diff --git a/examples/jarvis.js b/examples/jarvis.js
index 31a3443..79f0ca6 100644
--- a/examples/jarvis.js
+++ b/examples/jarvis.js
@@ -30,6 +30,7 @@ class MetaSocket extends Socket{
     self.on('init',(send)=>{
       self.sender = send;
     });
+    Search.call(this);
   }
 }
 var main = new MetaSocket('testworld');
@@ -110,19 +111,17 @@ function protectArea(send, tiles, locs, id, space, ctrl){
 
 var search = new Space();
 search.adhoc('jarvis'); // The search space is the word jarvis, so whenever that's caught, a relevant function can be called.
-var read = new Search(search);
+var read = new Search();
+read.match(search, respond);
 var expire = {};
 
 main.on('fallback', (send, tiles, locs) => { // tries to detect the prompt ('jarvis') and calls respond if found.
-  for (let i=0; i<locs.length; i++){
-    let loc = locs[i];
+  for (let loc of locs){
     if (read.has(loc)){
       clearTimeout(expire[loc]);
-      delete expire[loc];
       read.del(loc);
     }
-    let results = read.add(loc, tiles[loc]);
-    if (results.length > 0) respond(results, send);
+    read.add(loc, tiles[loc]);
     expire[loc] = setTimeout(() => {read.del(loc); delete expire[loc];}, 30000);
   }
 });
-- 
cgit 


From a468d5783fe63f68e679dd7f51d670fc82905131 Mon Sep 17 00:00:00 2001
From: Holden Rohrer <hr@hrhr.dev>
Date: Wed, 29 Jan 2020 23:41:42 -0500
Subject: jarvis uses mainworld now

---
 examples/jarvis.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'examples')

diff --git a/examples/jarvis.js b/examples/jarvis.js
index 79f0ca6..1a8137f 100644
--- a/examples/jarvis.js
+++ b/examples/jarvis.js
@@ -33,7 +33,7 @@ class MetaSocket extends Socket{
     Search.call(this);
   }
 }
-var main = new MetaSocket('testworld');
+var main = new MetaSocket();
 
 // See ident.js for further documentation, but this basically sets up init functions
 
-- 
cgit