From 02b5b4840862aa92e7c50faf332571b1db1f70f0 Mon Sep 17 00:00:00 2001 From: Holden Rohrer <holden.rohrer@gmail.com> Date: Wed, 18 Dec 2019 16:54:11 -0500 Subject: replaced formatting with JSON.stringify --- socket.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/socket.js b/socket.js index b690151..d5ce72d 100644 --- a/socket.js +++ b/socket.js @@ -49,7 +49,11 @@ class Socket extends retryws { for (var i=0; i<coords.length; i++){ coords[i] = {"minY":coords[i][0], "minX":coords[i][1], "maxY":coords[i][2], "maxX":coords[i][3]}; } - this.send(`{"fetchRectangles":${JSON.stringify(coords)},"kind":"fetch","v":"3"}`); + this.send( JSON.stringify({ + "fetchRectangles": coords, + "kind": "fetch", + "v": "3" + })); } this.write = function(chars){ //chars is an list of pairs [ pixel coordinate (y/x < 16), char ] @@ -63,11 +67,25 @@ class Socket extends retryws { chars[i].splice(4,0,0); chars[i].push(i); } - this.send(`{"edits":${JSON.stringify(chars)},"kind":"write"}`); + this.send( JSON.stringify({ + "edits": chars, + "kind": "write" + })); } this.cursor = function(coords){ //coords is just one pair of char coords; I think the api could handle more, but it's unnecessary for now. - this.send(`{"kind":"cursor","positions":[{"tileY":${Math.floor(coords[0]/8)},"tileX":${Math.floor(coords[1]/16)},"charY":${coords[0] % 8},"charX":${coords[1] % 16}}]}`); + this.send( JSON.stringify({ + "kind": "cursor", + "positions": + [ + { + "tileY": Math.floor(coords[0]/8), + "tileX": Math.floor(coords[1]/16), + "charY": coords[0] % 8, + "charX": coords[0] % 16 + } + ] + })); } } -- cgit