diff options
| -rw-r--r-- | examples/jarvis.js | 29 | 
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); +} | 
