From bad2bd5bd1c26e33a902b03ff4670aaa5e9fdc1d Mon Sep 17 00:00:00 2001 From: Holden Rohrer Date: Wed, 18 Dec 2019 23:07:53 -0500 Subject: jarvis work --- examples/jarvis.js | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'examples') diff --git a/examples/jarvis.js b/examples/jarvis.js index 19f9651..f31a9ea 100644 --- a/examples/jarvis.js +++ b/examples/jarvis.js @@ -3,20 +3,10 @@ const Space = require('../space'); const Socket = require('../socket'); const getdims = require('../utils/getdims'); +const tilekeys = require('../utils/tilekeys'); var main = new Socket(); - -function Sparse(){ // A "sparse" data-storage mechanism - this.data = []; - this.avail = []; - this.add = function(data){ - - } - this.del = function(id){ - this.avail.push(id); - this.data[id] = null; - } -} +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] @@ -25,19 +15,23 @@ function equals(arg1,arg2){ // Just takes the specific case argument of each bei main.on('open', ()=>{ // Tries to identify itself with a cursor movement let coords = [Math.floor(Math.random()*100000+16),Math.floor(Math.random()*100000+16)]; main.cursor(coords); - main.on('cursor', detect); + main.on('cursor',detect); function detect(pos, send){ if (equals(pos[0],coords)){ main.off('cursor', detect); - this.emit('identity', sender); + this.emit('identity', send); } } }) main.on('identity', (sender) => { + console.log('identity activated'); main.on('tileUpdate', (send, source, tiles) => { if (send == sender) return; - // Get dimensions somehow - + let dim = tilekeys(tiles); + let data = new Space(); data.fromfetch(tiles, [dim[0][0],dim[0][1],dim[0][0],dim[0][1]],conform=false); + console.log(data.print()); + //let data = new Space(); data.fromfetch(tiles, dim); + //data.search }) }) -- cgit