3d-interface/js/l3d/src/utils/Logger.js

138 lines
3.3 KiB
JavaScript

L3D.BD = {};
L3D.BD.Private = {};
L3D.BD.Private.sendData = function(url, data, force) {
if (L3D.BD.Private.enabled || force) {
// 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("Done : " + xhr.responseText);
// }
// }
xhr.send(JSON.stringify(data));
}
};
L3D.BD.Private.enabled = true;
L3D.BD.enable = function() {
L3D.BD.Private.enabled = true;
};
L3D.BD.disable = function() {
L3D.BD.Private.enabled = false;
};
L3D.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
}
};
};
L3D.BD.Event = {};
L3D.BD.Event.ArrowClicked = function() {};
L3D.BD.Event.ArrowClicked.prototype.send = function() {
var url = "/posts/arrow-clicked";
var data = {arrow_id: this.arrow_id};
L3D.BD.Private.sendData(url, data);
};
L3D.BD.Event.CoinClicked = function() {};
L3D.BD.Event.CoinClicked.prototype.send = function() {
var url = "/posts/coin-clicked";
var data = {coin_id: this.coin_id};
L3D.BD.Private.sendData(url, data);
};
L3D.BD.Event.KeyboardEvent = function() {};
L3D.BD.Event.KeyboardEvent.prototype.send = function() {
var url = "/posts/keyboard-event";
var data = {
camera: L3D.BD.Private.compactCamera(this.camera)
};
L3D.BD.Private.sendData(url, data);
};
L3D.BD.Event.ResetClicked = function() {};
L3D.BD.Event.ResetClicked.prototype.send = function() {
var url = "/posts/reset-clicked";
var data = {};
L3D.BD.Private.sendData(url, data);
};
L3D.BD.Event.PreviousNextClicked = function() {};
L3D.BD.Event.PreviousNextClicked.prototype.send = function() {
var url = "/posts/previous-next-clicked";
var data = {
// casts previous to boolean
previous: this.previous,
camera: L3D.BD.Private.compactCamera(this.camera)
};
L3D.BD.Private.sendData(url, data);
};
L3D.BD.Event.Hovered = function() {};
L3D.BD.Event.Hovered.prototype.send = function() {
var url = "/posts/hovered";
var data = {
start: this.start,
arrow_id: this.arrow_id
};
L3D.BD.Private.sendData(url, data);
};
L3D.BD.Event.Fps = function() {};
L3D.BD.Event.Fps.prototype.send = function() {
var url = "/posts/fps";
var data = {
fps: this.fps
};
L3D.BD.Private.sendData(url, data);
};
L3D.BD.Event.PointerLocked = function() {};
L3D.BD.Event.PointerLocked.prototype.send = function() {
var url = "/posts/pointer-locked";
var data = {
locked: this.locked
};
L3D.BD.Private.sendData(url, data);
};
L3D.BD.Event.SwitchedLockOption = function() {};
L3D.BD.Event.SwitchedLockOption.prototype.send = function() {
var url = "/posts/switched-lock-option";
var data = {
locked: this.locked
};
L3D.BD.Private.sendData(url, data);
};