2015-05-18 15:36:24 +02:00
|
|
|
var BD = {};
|
|
|
|
|
2015-05-19 11:03:53 +02:00
|
|
|
BD.Private = {};
|
2015-05-26 11:49:24 +02:00
|
|
|
|
2015-05-19 11:03:53 +02:00
|
|
|
BD.Private.sendData = function(url, data) {
|
2015-05-26 11:49:24 +02:00
|
|
|
if (BD.Private.enabled) {
|
|
|
|
// Append time to data
|
|
|
|
data.time = Date.now() / 1000;
|
|
|
|
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
xhr.open("POST", url, true);
|
|
|
|
xhr.setRequestHeader("Content-type", "application/json;charset=UTF-8");
|
|
|
|
|
|
|
|
// xhr.onreadystatechange = function() {
|
|
|
|
// if(xhr.readyState == 4 && xhr.status == 200) {
|
|
|
|
// console.log(xhr.responseText);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
xhr.send(JSON.stringify(data));
|
|
|
|
}
|
|
|
|
}
|
2015-05-20 10:23:19 +02:00
|
|
|
|
2015-05-26 11:49:24 +02:00
|
|
|
BD.Private.enabled = true;
|
2015-05-20 16:28:53 +02:00
|
|
|
|
2015-05-26 11:49:24 +02:00
|
|
|
BD.enable = function() {
|
|
|
|
BD.Private.enabled = true;
|
|
|
|
}
|
2015-05-21 16:59:17 +02:00
|
|
|
|
2015-05-26 11:49:24 +02:00
|
|
|
BD.disable = function() {
|
|
|
|
BD.Private.enabled = false;
|
2015-05-19 11:03:53 +02:00
|
|
|
}
|
|
|
|
|
2015-05-20 16:28:53 +02:00
|
|
|
BD.Private.compactCamera = function(camera) {
|
|
|
|
return {
|
|
|
|
position: {
|
|
|
|
x: camera.position.x,
|
|
|
|
y: camera.position.y,
|
|
|
|
z: camera.position.z
|
|
|
|
},
|
|
|
|
target: {
|
|
|
|
x: camera.target.x,
|
|
|
|
y: camera.target.y,
|
|
|
|
z: camera.target.z
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-05-19 11:03:53 +02:00
|
|
|
BD.Event = {};
|
|
|
|
|
|
|
|
BD.Event.ArrowClicked = function() {};
|
|
|
|
BD.Event.ArrowClicked.prototype.send = function() {
|
|
|
|
var url = "/arrow-clicked";
|
|
|
|
var data = {arrow_id: this.arrow_id};
|
|
|
|
BD.Private.sendData(url, data);
|
|
|
|
}
|
2015-05-18 15:36:24 +02:00
|
|
|
|
2015-05-19 11:03:53 +02:00
|
|
|
BD.Event.CoinClicked = function() {};
|
|
|
|
BD.Event.CoinClicked.prototype.send = function() {
|
|
|
|
var url = "/coin-clicked";
|
|
|
|
var data = {coin_id: this.coin_id};
|
|
|
|
BD.Private.sendData(url, data);
|
|
|
|
}
|
2015-05-18 15:36:24 +02:00
|
|
|
|
2015-05-19 11:50:12 +02:00
|
|
|
BD.Event.KeyboardEvent = function() {};
|
|
|
|
BD.Event.KeyboardEvent.prototype.send = function() {
|
|
|
|
var url = "/keyboard-event";
|
2015-05-20 16:28:53 +02:00
|
|
|
|
2015-05-19 11:50:12 +02:00
|
|
|
var data = {
|
2015-05-20 16:28:53 +02:00
|
|
|
camera: BD.Private.compactCamera(this.camera)
|
|
|
|
}
|
|
|
|
|
2015-05-19 11:50:12 +02:00
|
|
|
BD.Private.sendData(url, data);
|
|
|
|
}
|
2015-05-20 15:20:59 +02:00
|
|
|
|
|
|
|
BD.Event.ResetClicked = function() {};
|
|
|
|
BD.Event.ResetClicked.prototype.send = function() {
|
|
|
|
var url = "/reset-clicked";
|
|
|
|
var data = {};
|
|
|
|
BD.Private.sendData(url, data);
|
|
|
|
}
|
2015-05-20 16:28:53 +02:00
|
|
|
|
|
|
|
BD.Event.PreviousNextClicked = function() {};
|
|
|
|
BD.Event.PreviousNextClicked.prototype.send = function() {
|
|
|
|
var url = "/previous-next-clicked";
|
|
|
|
var data = {
|
|
|
|
// casts previous to boolean
|
|
|
|
previous: this.previous,
|
|
|
|
camera: BD.Private.compactCamera(this.camera)
|
|
|
|
};
|
|
|
|
|
|
|
|
BD.Private.sendData(url, data);
|
|
|
|
}
|
2015-05-21 15:35:40 +02:00
|
|
|
|
|
|
|
BD.Event.Hovered = function() {};
|
|
|
|
BD.Event.Hovered.prototype.send = function() {
|
|
|
|
var url = "/hovered";
|
|
|
|
var data = {
|
|
|
|
start: this.start,
|
|
|
|
arrow_id: this.arrow_id
|
|
|
|
};
|
|
|
|
|
|
|
|
BD.Private.sendData(url, data);
|
|
|
|
}
|