Skip to content

Commit

Permalink
Follow js style guide convention of 2 spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
vinnyoodles committed Jan 10, 2018
1 parent 31b4b82 commit 7d9e437
Showing 1 changed file with 48 additions and 48 deletions.
96 changes: 48 additions & 48 deletions src/static/index.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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) {
Expand All @@ -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;
}

1 comment on commit 7d9e437

@Puyush6889
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.