aboutsummaryrefslogtreecommitdiff
path: root/socket.js
diff options
context:
space:
mode:
authorHolden Rohrer <holden.rohrer@gmail.com>2019-12-18 16:54:11 -0500
committerHolden Rohrer <holden.rohrer@gmail.com>2019-12-18 16:54:11 -0500
commit02b5b4840862aa92e7c50faf332571b1db1f70f0 (patch)
treedbd2936e021b982c92bd8814b6e583169170c1cc /socket.js
parentccde5508af1f68499ccf09f76edcef2f13e3adbd (diff)
replaced formatting with JSON.stringify
Diffstat (limited to 'socket.js')
-rw-r--r--socket.js24
1 files 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
+ }
+ ]
+ }));
}
}