Browse Source

Some changes

master
Joshua Moerman 12 years ago
parent
commit
e2b78d1e22
  1. 2
      beats.sublime-project
  2. 28
      index.js

2
beats.sublime-project

@ -2,7 +2,7 @@
"folders": "folders":
[ [
{ {
"path": "/Users/joshua/Documents/www/vadovas/beats" "path": "./"
} }
] ]
} }

28
index.js

@ -1,10 +1,14 @@
var myName; var myName;
var websocket; var websocket;
var statusbar
var ballscreen; var ballscreen;
var svgscreen; var svgscreen;
var current_svgline; var current_svgline;
var balls_online = new Array(); var balls_online = new Array();
var svglines_online = new Array(); var svglines_online = new Array();
var speed = 100; var speed = 100;
var line_kind = 1; var line_kind = 1;
@ -14,7 +18,7 @@ function init() {
var login = document.getElementById('login'); var login = document.getElementById('login');
login.parentNode.removeChild(login); login.parentNode.removeChild(login);
var statusbar = document.getElementById('status'); statusbar = document.getElementById('status');
ballscreen = document.getElementById("ballscreen"); ballscreen = document.getElementById("ballscreen");
svgscreen = document.getElementById("svgscreen"); svgscreen = document.getElementById("svgscreen");
@ -31,40 +35,45 @@ function init() {
function onOpen(evt) { function onOpen(evt) {
updateUser(); updateUser();
setInterval(poll, speed);
} }
function onMessage(evt) { function onMessage(evt) {
console.log(evt.data);
var ret = JSON.parse(evt.data); var ret = JSON.parse(evt.data);
var balls = ret.balls; var balls = ret.balls;
var lines = ret.lines; var lines = ret.lines;
statusbar.innerHTML = balls.length;
if(balls){ if(balls){
console.log('updating balls');
updateBalls(balls); updateBalls(balls);
} }
if(lines){ if(lines){
console.log('updating lines'); //updateLines(lines);
updateLines(lines);
} }
setTimeout(function(){
poll();
}, speed);
} }
function updateBalls(balls){ function updateBalls(balls){
// Because we use transitions for the balls // Because we use transitions for the balls
// we really update them, and only delete the ones which are absent // we really update them, and only delete the ones which are absent
var updates = 0;
var news = 0;
var removed = 0;
for(i in balls_online){ for(i in balls_online){
balls_online[i].should_remove = true; balls_online[i].should_remove = true;
} }
for (var i = balls.length - 1; i >= 0; i--) { for (var i = balls.length - 1; i >= 0; i--) {
var ball = document.getElementById(balls[i].information); var ball = document.getElementById(balls[i].information);
if(ball){ if(ball){
++updates;
ball.style.left = balls[i].position.x + "px"; ball.style.left = balls[i].position.x + "px";
ball.style.top = balls[i].position.y + "px"; ball.style.top = balls[i].position.y + "px";
ball.should_remove = false; ball.should_remove = false;
} else { } else {
++news;
var ball = document.createElement('div'); var ball = document.createElement('div');
ball.should_remove = false; ball.should_remove = false;
ball.id = balls[i].information; ball.id = balls[i].information;
@ -79,10 +88,13 @@ function updateBalls(balls){
} }
for (var i = balls_online.length - 1; i >= 0; i--) { for (var i = balls_online.length - 1; i >= 0; i--) {
if(balls_online[i].should_remove){ if(balls_online[i].should_remove){
++removed
ballscreen.removeChild(balls_online[i]); ballscreen.removeChild(balls_online[i]);
balls_online.splice(i, 1); balls_online.splice(i, 1);
} }
}; };
statusbar.innerHTML = updates + ', ' + news + ', ' + removed;
} }
function updateLines(lines){ function updateLines(lines){