diff options
author | Holden Rohrer <holden.rohrer@gmail.com> | 2019-12-18 16:54:11 -0500 |
---|---|---|
committer | Holden Rohrer <holden.rohrer@gmail.com> | 2019-12-18 16:54:11 -0500 |
commit | 02b5b4840862aa92e7c50faf332571b1db1f70f0 (patch) | |
tree | dbd2936e021b982c92bd8814b6e583169170c1cc | |
parent | ccde5508af1f68499ccf09f76edcef2f13e3adbd (diff) |
replaced formatting with JSON.stringify
-rw-r--r-- | socket.js | 24 |
1 files changed, 21 insertions, 3 deletions
@@ -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 + } + ] + })); } } |