Documentation, BD -> DB

This commit is contained in:
Thomas FORGIONE
2015-07-17 16:28:55 +02:00
parent df87f629f6
commit 6a4cd21081
8 changed files with 252 additions and 61 deletions
+231 -40
View File
@@ -1,9 +1,24 @@
L3D.BD = {};
/**
* @namespace
* @memberof L3D
*/
L3D.DB = {};
L3D.BD.Private = {};
/**
* @namespace
* @memberof L3D.DB
*/
L3D.DB.Private = {};
L3D.BD.Private.sendData = function(url, data, force) {
if (L3D.BD.Private.enabled || force) {
/**
* Sends an object to an url (use JSON)
* @memberof L3D.DB.Private
* @param url {String} the url to send the request
* @param data {Object} the data to send to the url
* @param force {Boolean} if the DB is disabled, the message will only be sent if force is true
*/
L3D.DB.Private.sendData = function(url, data, force) {
if (L3D.DB.Private.enabled || force) {
// Append time to data
data.time = Date.now() / 1000;
@@ -21,17 +36,36 @@ L3D.BD.Private.sendData = function(url, data, force) {
}
};
L3D.BD.Private.enabled = true;
/**
* If false, only forced requests will be sent
* @memberof L3D.DB.Private
* @type {Boolean}
*/
L3D.DB.Private.enabled = true;
L3D.BD.enable = function() {
L3D.BD.Private.enabled = true;
/**
* Enables the requests
* @memberof L3D.DB
*/
L3D.DB.enable = function() {
L3D.DB.Private.enabled = true;
};
L3D.BD.disable = function() {
L3D.BD.Private.enabled = false;
/**
* Disables the requests
* @memberof L3D.DB
*/
L3D.DB.disable = function() {
L3D.DB.Private.enabled = false;
};
L3D.BD.Private.compactCamera = function(camera) {
/**
* Compacts a camera
* @memberof L3D.DB.Private
* @param camera {L3D.PointerCamera} a camera with a position and a target
* @return {Object} an object containing a position and a target
*/
L3D.DB.Private.compactCamera = function(camera) {
return {
position: {
x: camera.position.x,
@@ -46,92 +80,249 @@ L3D.BD.Private.compactCamera = function(camera) {
};
};
L3D.BD.Event = {};
/**
* Contains all the classes to log events into the DB. You must set the
* attribute of the instance, and then call the <code>send</code> method
* on them to send them.
* @namespace
* @memberof L3D.DB
*/
L3D.DB.Event = {};
L3D.BD.Event.ArrowClicked = function() {};
L3D.BD.Event.ArrowClicked.prototype.send = function() {
/**
* An event when an arrow is clicked
* @constructor
* @memberof L3D.DB.Event
*/
L3D.DB.Event.ArrowClicked = function() {
/**
* Id of the arrow
* @type {Number}
*/
this.arrow_id = null;
};
/**
* Sends the event to the correct url
*/
L3D.DB.Event.ArrowClicked.prototype.send = function() {
var url = "/posts/arrow-clicked";
var data = {arrow_id: this.arrow_id};
L3D.BD.Private.sendData(url, data);
L3D.DB.Private.sendData(url, data);
};
L3D.BD.Event.CoinClicked = function() {};
L3D.BD.Event.CoinClicked.prototype.send = function() {
/**
* An event when a coin is taken
* @constructor
* @memberof L3D.DB.Event
*/
L3D.DB.Event.CoinClicked = function() {
/**
* Id of the coin taken
* @type {Number}
*/
this.coin_id = null;
};
/**
* Sends the event to the correct url
*/
L3D.DB.Event.CoinClicked.prototype.send = function() {
var url = "/posts/coin-clicked";
var data = {coin_id: this.coin_id};
L3D.BD.Private.sendData(url, data);
L3D.DB.Private.sendData(url, data);
};
L3D.BD.Event.KeyboardEvent = function() {};
L3D.BD.Event.KeyboardEvent.prototype.send = function() {
/**
* An event when the keyboard is touched
* @constructor
* @memberof L3D.DB.Event
*/
L3D.DB.Event.KeyboardEvent = function() {
/**
* A reference to the camera
* @type {L3D.PointerCamera}
*/
this.camera = null;
};
/**
* Sends the event to the correct url
*/
L3D.DB.Event.KeyboardEvent.prototype.send = function() {
var url = "/posts/keyboard-event";
var data = {
camera: L3D.BD.Private.compactCamera(this.camera)
camera: L3D.DB.Private.compactCamera(this.camera)
};
L3D.BD.Private.sendData(url, data);
L3D.DB.Private.sendData(url, data);
};
L3D.BD.Event.ResetClicked = function() {};
L3D.BD.Event.ResetClicked.prototype.send = function() {
/**
* An event when the reset button is clicked
* @constructor
* @memberof L3D.DB.Event
*/
L3D.DB.Event.ResetClicked = function() {};
/**
* Sends the event to the correct url
*/
L3D.DB.Event.ResetClicked.prototype.send = function() {
var url = "/posts/reset-clicked";
var data = {};
L3D.BD.Private.sendData(url, data);
L3D.DB.Private.sendData(url, data);
};
L3D.BD.Event.PreviousNextClicked = function() {};
L3D.BD.Event.PreviousNextClicked.prototype.send = function() {
/**
* An event when previous or next buttons are clicked
* @constructor
* @memberof L3D.DB.Event
*/
L3D.DB.Event.PreviousNextClicked = function() {
/**
* A reference to the camera
* @type {L3D.PointerCamera}
*/
this.camera = null;
};
/**
* Sends the event to the correct url
*/
L3D.DB.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)
camera: L3D.DB.Private.compactCamera(this.camera)
};
L3D.BD.Private.sendData(url, data);
L3D.DB.Private.sendData(url, data);
};
L3D.BD.Event.Hovered = function() {};
L3D.BD.Event.Hovered.prototype.send = function() {
/**
* An event when a recommendation is hovered
* @constructor
* @memberof L3D.DB.Event
*/
L3D.DB.Event.Hovered = function() {
/**
* The id of the arrow hovered
* @type {Number}
*/
this.arrow_id = null;
/**
* true if the hover starts, false if finishes
* @type {Boolean}
*/
this.start = null;
};
/**
* Sends the event to the correct url
*/
L3D.DB.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.DB.Private.sendData(url, data);
};
L3D.BD.Event.Fps = function() {};
L3D.BD.Event.Fps.prototype.send = function() {
/**
* An event with the framerate of the client
* @constructor
* @memberof L3D.DB.Event
*/
L3D.DB.Event.Fps = function() {
/**
* the frame rate
* @type {Number}
*/
this.fps = null;
};
/**
* Sends the event to the correct url
*/
L3D.DB.Event.Fps.prototype.send = function() {
var url = "/posts/fps";
var data = {
fps: this.fps
};
L3D.BD.Private.sendData(url, data);
L3D.DB.Private.sendData(url, data);
};
L3D.BD.Event.PointerLocked = function() {};
L3D.BD.Event.PointerLocked.prototype.send = function() {
/**
* An event when the pointer is locked
* @constructor
* @memberof L3D.DB.Event
*/
L3D.DB.Event.PointerLocked = function() {
/**
* True if the pointer is locked, false otherwise
* @type {Boolean}
*/
this.locked = null;
};
/**
* Sends the event to the correct url
*/
L3D.DB.Event.PointerLocked.prototype.send = function() {
var url = "/posts/pointer-locked";
var data = {
locked: this.locked
};
L3D.BD.Private.sendData(url, data);
L3D.DB.Private.sendData(url, data);
};
L3D.BD.Event.SwitchedLockOption = function() {};
L3D.BD.Event.SwitchedLockOption.prototype.send = function() {
/**
* An event when the pointer lock option is changed
* @constructor
* @memberof L3D.DB.Event
*/
L3D.DB.Event.SwitchedLockOption = function() {
/**
* True if the lock option is enabled, false otherwise
* @type {Boolean}
*/
this.locked = null;
};
/**
* Sends the event to the correct url
*/
L3D.DB.Event.SwitchedLockOption.prototype.send = function() {
var url = "/posts/switched-lock-option";
var data = {
locked: this.locked
};
L3D.BD.Private.sendData(url, data);
L3D.DB.Private.sendData(url, data);
};