Browse Source

Better

master
Pete Shadbolt 8 years ago
parent
commit
548806927b
6 changed files with 17 additions and 15 deletions
  1. +2
    -0
      static/index.html
  2. +1
    -1
      static/scripts/graph.js
  3. +1
    -3
      static/scripts/gui.js
  4. +3
    -2
      static/scripts/main.js
  5. +6
    -1
      static/scripts/message.js
  6. +4
    -8
      static/scripts/websocket.js

+ 2
- 0
static/index.html View File

@@ -6,6 +6,8 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=1" />
<link rel="stylesheet" href="main.css">
<script src="scripts/three.js"></script>
<script src="scripts/orbitcontrols.js"></script>
<script data-main="scripts/main" src="scripts/require.js"></script>
</head>



+ 1
- 1
static/scripts/graph.js View File

@@ -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"],


+ 1
- 3
static/scripts/gui.js View File

@@ -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);
}


};
});

+ 3
- 2
static/scripts/main.js View File

@@ -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();
}

+ 6
- 1
static/scripts/message.js View File

@@ -1 +1,6 @@
define({});
define({
serverMessage: function(msgtext){
message.innerHTML = msgtext;
message.className = "visible";
}
});

+ 4
- 8
static/scripts/websocket.js View File

@@ -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. <a href='#' onclick='javascript:connect_to_server()'>Reconnect</a>.";
message.className = "visible";
message.serverMessage("Connection to server lost. <a href='#' onclick='javascript:connect_to_server()'>Reconnect</a>.");
};
}
};


Loading…
Cancel
Save