From 548806927b820639e7294fff5ccb025d25ee9db8 Mon Sep 17 00:00:00 2001 From: Pete Shadbolt Date: Wed, 18 May 2016 14:48:01 +0100 Subject: [PATCH] Better --- static/index.html | 2 ++ static/scripts/graph.js | 2 +- static/scripts/gui.js | 4 +--- static/scripts/main.js | 5 +++-- static/scripts/message.js | 7 ++++++- static/scripts/websocket.js | 12 ++++-------- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/static/index.html b/static/index.html index 1e44493..e8efb15 100644 --- a/static/index.html +++ b/static/index.html @@ -6,6 +6,8 @@ + + diff --git a/static/scripts/graph.js b/static/scripts/graph.js index d0ab0f7..1ab3b15 100644 --- a/static/scripts/graph.js +++ b/static/scripts/graph.js @@ -1,4 +1,4 @@ -define(["three", "anders_briegel", "websocket"], function(three, websocket) { +define(["anders_briegel", "websocket"], function(anders_briegel, websocket) { return { colors: ["red", "green", "yellow", "blue", "pink", "orange", "purple"], diff --git a/static/scripts/gui.js b/static/scripts/gui.js index bae3bc9..08717d0 100644 --- a/static/scripts/gui.js +++ b/static/scripts/gui.js @@ -1,4 +1,4 @@ -define(["three", "orbitcontrols", "message"], function() { +define(["message"], function() { return { construct: function() { this.renderer = new THREE.WebGLRenderer(); @@ -38,7 +38,5 @@ define(["three", "orbitcontrols", "message"], function() { grid.setColors(0xdddddd, 0xeeeeee); this.scene.add(grid); } - - }; }); diff --git a/static/scripts/main.js b/static/scripts/main.js index 111ed0a..7b7b450 100644 --- a/static/scripts/main.js +++ b/static/scripts/main.js @@ -1,10 +1,11 @@ // Import modules -requirejs(["anders_briegel", "gui"], init); +requirejs(["anders_briegel", "gui", "graph"], init); var ab; // Called on startup -function init(anders_briegel, gui) { +function init(anders_briegel, gui, graph) { ab = anders_briegel; + graph.hookEvents(); gui.construct(); gui.render(); } diff --git a/static/scripts/message.js b/static/scripts/message.js index 20e4f18..d2b5b90 100644 --- a/static/scripts/message.js +++ b/static/scripts/message.js @@ -1 +1,6 @@ -define({}); +define({ + serverMessage: function(msgtext){ + message.innerHTML = msgtext; + message.className = "visible"; + } +}); diff --git a/static/scripts/websocket.js b/static/scripts/websocket.js index 0a9f983..9bc5ef2 100644 --- a/static/scripts/websocket.js +++ b/static/scripts/websocket.js @@ -1,29 +1,25 @@ define(["message"], function(message){ return { - bindEvents: function(update){ + connect: function(update){ var ws = new WebSocket("ws://localhost:5000"); ws.onopen = function(evt) { - message.innerHTML = "Connected to server."; - message.className = "visible"; + message.serverMessage("Connected to server."); }; ws.onerror = function(err) { - message.innerHTML = "Could not connect to server."; - message.className = "visible"; + message.serverMessage("Could not connect to server."); }; ws.onmessage = function (evt) { - console.log("Received update"); update(JSON.parse(evt.data)); }; ws.onclose = function(evt) { - message.innerHTML = "Connection to server lost. Reconnect."; - message.className = "visible"; + message.serverMessage("Connection to server lost. Reconnect."); }; } };