From 7d9e437f61787c4e82d1e18b643eb0617c5a4306 Mon Sep 17 00:00:00 2001 From: Vincent Le Date: Tue, 9 Jan 2018 20:20:37 -0800 Subject: [PATCH] Follow js style guide convention of 2 spaces --- src/static/index.js | 96 ++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/src/static/index.js b/src/static/index.js index 887dd45..1677fb6 100644 --- a/src/static/index.js +++ b/src/static/index.js @@ -1,15 +1,15 @@ var SIZE_MODIFIER = 2; var KEY_MAP = { - 88: 0, // a - 90: 1, // b - 8: 2, // select - 13: 3, // start - 39: 4, // right - 37: 5, // left - 38: 6, // up - 40: 7, // down - 83: 8, // r - 65: 9, // l + 88: 0, // a + 90: 1, // b + 8: 2, // select + 13: 3, // start + 39: 4, // right + 37: 5, // left + 38: 6, // up + 40: 7, // down + 83: 8, // r + 65: 9, // l }; var ws = new WebSocket('ws://' + window.location.host + '/ws'); @@ -19,36 +19,36 @@ document.addEventListener('DOMContentLoaded', onLoad); document.addEventListener('keydown', onKey); function onLoad(event) { - // Handle incoming websocket message callback - ws.onmessage = function(event) { - if (event.data instanceof Blob) { - updateFrame(event.data) - } else { - try { - var json = JSON.parse(event.data); - switch (json.event) { - case 'metadata': return setCanvas(json.width, json.height); - case 'last log': return displayMessage(json.data); - case 'all logs': return addGameEvent(json); - } - } catch (err) { - Raven.captureException(err) - } + // Handle incoming websocket message callback + ws.onmessage = function(event) { + if (event.data instanceof Blob) { + updateFrame(event.data) + } else { + try { + var json = JSON.parse(event.data); + switch (json.event) { + case 'metadata': return setCanvas(json.width, json.height); + case 'last log': return displayMessage(json.data); + case 'all logs': return addGameEvent(json); } - }; - - ws.onopen = function() { - connected = true; + } catch (err) { + Raven.captureException(err) + } } + }; - ws.onclose = function() { - connected = false; - } + ws.onopen = function() { + connected = true; + } + + ws.onclose = function() { + connected = false; + } } function addGameEvent(json) { - for (var message of json.data) - displayMessage(message); + for (var message of json.data) + displayMessage(message); } function displayMessage(message) { @@ -60,24 +60,24 @@ function displayMessage(message) { } function onKey(event) { - if (!connected) - Raven.captureMessage('Client is not connected to websocket'); - else if (KEY_MAP[event.keyCode]) - ws.send(KEY_MAP[event.keyCode]); + if (!connected) + Raven.captureMessage('Client is not connected to websocket'); + else if (KEY_MAP[event.keyCode]) + ws.send(KEY_MAP[event.keyCode]); } function updateFrame(frame) { - var canvas = document.getElementById('canvas'); - var context = canvas.getContext('2d'); - var img = new Image(); - img.onload = function() { - context.drawImage(img, 0, 0, img.width * SIZE_MODIFIER, img.height * SIZE_MODIFIER); - } - img.src = URL.createObjectURL(frame); + var canvas = document.getElementById('canvas'); + var context = canvas.getContext('2d'); + var img = new Image(); + img.onload = function() { + context.drawImage(img, 0, 0, img.width * SIZE_MODIFIER, img.height * SIZE_MODIFIER); + } + img.src = URL.createObjectURL(frame); } function setCanvas(width, height) { - var canvas = document.getElementById('canvas'); - canvas.width = width * SIZE_MODIFIER; - canvas.height = height * SIZE_MODIFIER; + var canvas = document.getElementById('canvas'); + canvas.width = width * SIZE_MODIFIER; + canvas.height = height * SIZE_MODIFIER; }