aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorHolden Rohrer <holden.rohrer@gmail.com>2019-12-20 17:59:33 -0500
committerHolden Rohrer <holden.rohrer@gmail.com>2019-12-20 17:59:33 -0500
commitb33eac1d74585b1df6f529736a22c1bdacdf694a (patch)
treed8777eb72c24d125fb94bba26c546826ece462b2 /examples
parent3348e132714efc2b896eccc4749695ac069f0f0c (diff)
used Search in jarvis and added dummy responder
Diffstat (limited to 'examples')
-rw-r--r--examples/jarvis.js29
1 files changed, 20 insertions, 9 deletions
diff --git a/examples/jarvis.js b/examples/jarvis.js
index ccf1f80..a94121c 100644
--- a/examples/jarvis.js
+++ b/examples/jarvis.js
@@ -4,9 +4,9 @@ const Space = require('../space');
const Socket = require('../socket');
const getdims = require('../utils/getdims');
const tilekeys = require('../utils/tilekeys');
+const Search = require('./search');
var main = new Socket();
-var read = {};
function equals(arg1,arg2){ // Just takes the specific case argument of each being an int pair
return arg1[0] == arg2[0] && arg1[1] == arg2[1]
@@ -24,20 +24,31 @@ main.on('open', ()=>{ // Tries to identify itself with a cursor movement
}
})
-main.on('identity', (sender) => {
+main.on('identity', (sender) => { // Does this need to be an event (or would a callback like identity(sender) work just as well?)
console.log('identity activated');
+
+ 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();
+ var expire = {};
+
main.on('tileUpdate', (send, source, tiles) => {
if (send == sender) return;
let locs = tilekeys(tiles);
+
for (let i=0; i<locs.length; i++){
let loc = locs[i];
- if (read[loc]) clearTimeout(read[loc].timer);
- read[loc] = ({
- "timer":setTimeout(()=>{delete read[dim]},30000),
- "block":new Space(),
- });
- read[loc].block.fromfetch(tiles, [loc[0][0], loc[0][1], loc[1][0], loc[1][1]], conform=false);
- // TODO : if any pair or quadruplet of blocks are adjacent, SEARCH THEM!
+ if read.has(loc) clearTimeout(expire[loc]);
+ let locspace = new Space();
+ locspace.fromfetch(tiles, [loc[0][0], loc[0][1], loc[1][0], loc[1][1]], conform=false);
+ let results = read.add(locspace);
+ if (! results) respond(results);
+ expire[loc] = setTimeout(()=>{read.del(loc)}, 30000);
}
+
});
});
+
+function respond(coord){
+ console.log('called at', coord);
+}