From fae8f6b3bbb1fd18cd07c26673d454a8136c093f Mon Sep 17 00:00:00 2001 From: Holden Rohrer Date: Wed, 18 Dec 2019 16:35:13 -0500 Subject: tested and fixed socket.fetch/cursor --- socket.js | 9 +++++---- tests/socket_cursor.js | 8 ++++++++ tests/socket_fetch.js | 8 ++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 tests/socket_cursor.js create mode 100644 tests/socket_fetch.js diff --git a/socket.js b/socket.js index 114949b..b690151 100644 --- a/socket.js +++ b/socket.js @@ -52,21 +52,22 @@ class Socket extends retryws { this.send(`{"fetchRectangles":${JSON.stringify(coords)},"kind":"fetch","v":"3"}`); } - this.write = function(chars){ //chars is an list of triplets [ tile coordinate (y/x), pixel coordinate (y/x < 16), char ] + this.write = function(chars){ //chars is an list of pairs [ pixel coordinate (y/x < 16), char ] if (chars.length > 200){ throw "Too many characters to write"; } for (var i=0; i{world.cursor([22,23])}); +world.on('cursor', (locs, send)=>{console.log(locs,send)}); diff --git a/tests/socket_fetch.js b/tests/socket_fetch.js new file mode 100644 index 0000000..a613dc6 --- /dev/null +++ b/tests/socket_fetch.js @@ -0,0 +1,8 @@ +// Tests Socket.fetch and Socket.on('fetch') +const socket = require('../socket'); + +let world = new socket.Socket(); + +world.on('open', () => {world.fetch([[10,10,10,10]])}); + +world.on('fetch', (tiles) => {console.log(tiles);}) -- cgit