From ed98fe2857f97ee6903680aba11e7e77fbab23f9 Mon Sep 17 00:00:00 2001 From: Holden Rohrer Date: Fri, 27 Dec 2019 02:20:34 -0500 Subject: integrated notif for jarvis --- examples/jarvis.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 4 deletions(-) (limited to 'examples') 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 { + 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); } -- cgit