aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHolden Rohrer <holden.rohrer@gmail.com>2019-12-27 02:20:34 -0500
committerHolden Rohrer <holden.rohrer@gmail.com>2019-12-27 15:00:15 -0500
commited98fe2857f97ee6903680aba11e7e77fbab23f9 (patch)
treea7115b44318135c8238bc583d1ce40944798cd2d
parentd6d52bafb1f7798a937aa57aacc5874f29b0ea8b (diff)
integrated notif for jarvis
-rw-r--r--examples/jarvis.js54
1 files changed, 50 insertions, 4 deletions
diff --git a/examples/jarvis.js b/examples/jarvis.js
index 7ea49b9..7b07c52 100644
--- a/examples/jarvis.js
+++ b/examples/jarvis.js
@@ -3,8 +3,12 @@
const Space = require('../space');
const Socket = require('../socket');
const tilekeys = require('../utils/tilekeys');
+const ms = require('../utils/measurespace');
+const vec = require('../utils/vec');
+const comb = require('../utils/comb');
const Search = require('../tools/search');
const Queue = require('../tools/queue');
+const ri = require('../utils/rectintersect');
var main = new Socket();
@@ -30,13 +34,57 @@ var sender; // Global variable that holds identity()'s `send` for tileHandler
function identity(send){
sender = send;
console.log('identity activated');
+ init();
main.on('tileUpdate', tileHandler);
}
+function init(){
+ writes.enqueue(...notif.towrite()); // A non-conservative write because I don't want to write the fetch request (also, faster in many cases because the notif is <200 chars)
+}
+
function tileHandler(send, source, tiles){
if (send == sender) return;
let locs = tilekeys(tiles);
- detectPrompt(send, tiles, locs);
+ let tilespaces = {};
+ for (let i=0; i<locs.length; i++){
+ let loc = locs[i];
+ tilespaces[loc] = new Space();
+ tilespaces[loc].fromfetch(tiles, [loc, loc], conform=false);
+ }
+ [protectArea, detectPrompt].forEach(func => {
+ func(send, tilespaces, locs);
+ });
+}
+
+var notif = new Space();
+notif.adhoc('\
+ \n\
+ For a node.js YWOT api: \n\
+& http://github.com/feynmansfedora/ywot-clean \n\
+& Try `jarvis` today \n\
+ ');
+notif.loc = [-6, 20];
+var ctrl = ms(notif);
+
+function protectArea(send, tiles, locs){
+ let tilesize = [8, 16]; // This may be exportable to an external util/tool
+ for (loc of locs){
+ let tile = tiles[loc];
+ let origloc = loc;
+ loc = vec.tileToChar(loc);
+ if (ri(ctrl, [loc, vec.add(loc, tilesize)])){
+ // Write diffs from the tile
+ let inter = notif.copy(); // Acts as a window for tile (only see relevant data)
+ inter.comb(tile, comb.unmask);
+ let diff = notif.copy(); // Actually diffs notify with the errant text
+ diff.comb(inter, comb.sub);
+ writes.enqueue(...diff.towrite())
+ // Mask the tile
+ let newtile = notif.copy();
+ newtile.comb(tile, comb.mask);
+ tiles[origloc] = newtile;
+ }
+ }
}
var search = new Space();
@@ -52,9 +100,7 @@ function detectPrompt(send, tiles, locs){ // tries to detect the prompt ('jarvis
delete expire[loc];
read.del(loc);
}
- let locspace = new Space();
- locspace.fromfetch(tiles, [loc, loc], conform=false);
- let results = read.add(loc, locspace);
+ let results = read.add(loc, tiles[loc]);
if (results.length > 0) respond(results);
expire[loc] = setTimeout(() => {read.del(loc)}, 30000);
}