aboutsummaryrefslogtreecommitdiff
path: root/examples/jarvis.js
diff options
context:
space:
mode:
Diffstat (limited to 'examples/jarvis.js')
-rw-r--r--examples/jarvis.js40
1 files changed, 15 insertions, 25 deletions
diff --git a/examples/jarvis.js b/examples/jarvis.js
index 3e18e85..9f4e529 100644
--- a/examples/jarvis.js
+++ b/examples/jarvis.js
@@ -11,10 +11,12 @@ const ri = require('../utils/rectintersect');
const id = require('../utils/ident');
const maketiles = require('../utils/maketiles');
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);
// See ident.js for further documentation, but this basically sets up init functions
id(main, initOnce, init, deinit);
@@ -43,14 +45,10 @@ function initOnce(){
function tileHandler(send, source, tiles){
if (send == sender) return;
let tiledata = maketiles(tiles);
- funcs.forEach(func => {
- func(send, tiledata.tilespaces, tiledata.locs);
- });
+ claims.handle(send, tiledata.tilespaces, tiledata.locs);
}
//// "userspace" functions for responses, like to tileUpdates
-var funcs = [protectArea, detectPrompt];
-
var command = 'jarvis'
var sig = 'feynmansfedora'
var notifsrc = '\
@@ -63,7 +61,7 @@ var notifsrc = '\
notifsrc = notifsrc.replace('COMMAND', command).replace('SIGNATURE', sig);
var minsUp = 0;
var callct = 0;
-var ctrl;
+var notifClaim;
function genNotif(){
let newnotif = new Space();
@@ -79,34 +77,26 @@ function notifRefresh(){
let newnotif = genNotif();
let diff = newnotif.copy();
if (typeof notif !== 'undefined') diff.comb(notif, comb.sub);
- notif = diff;
- ctrl = ms(notif);
+ notif = newnotif;
+ claims.unclaim(notifClaim);
+ notifClaim = claims.claim(newnotif, protectArea);
return (diff.towrite());
}
function timect(){
- writes.enqueue(notifRefresh());
minsUp++;
+ writes.enqueue(notifRefresh());
setTimeout(timect, 60*1000);
}
-function protectArea(send, tiles, locs){
- let tilesize = [8, 16]; // This may be exportable to an external util/tool
- for (loc of locs){
+function protectArea(send, tiles, locs, id, space, ctrl){
+ for (let 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 diff = notif.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())
- // Mask the tile
- let newtile = notif.copy();
- newtile.comb(tile, comb.mask);
- tiles[origloc] = newtile;
- }
+ // Write diffs from the tile
+ 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())
}
}