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

View File

@ -35,7 +35,7 @@ var ButtonManager = function(camera, cameras, previewer) {
self.camera.onPointerLockChange();
// Log
var event = new L3D.BD.Event.SwitchedLockOption();
var event = new L3D.DB.Event.SwitchedLockOption();
event.locked = self.pointerLockElement.checked;
event.send();
};

View File

@ -21,7 +21,7 @@ var container_size = {
};
function logfps(fps) {
var event = new L3D.BD.Event.Fps();
var event = new L3D.DB.Event.Fps();
event.fps = fps;
event.send();
}
@ -49,7 +49,7 @@ function objectClickerOnHover(camera1, previewer, recommendations, container) {
// Manage the hover camera event
if (hoveredCamera !== obj) {
var event = new L3D.BD.Event.Hovered();
var event = new L3D.DB.Event.Hovered();
if (obj instanceof L3D.BaseRecommendation) {
// The newly hovered object is different and is a recommendation
@ -93,7 +93,7 @@ function objectClickerOnClick(camera1, buttonManager, recommendations, coins) {
obj.get();
// Send event to DB
event = new L3D.BD.Event.CoinClicked();
event = new L3D.DB.Event.CoinClicked();
event.coin_id = coins.indexOf(obj);
event.send();
@ -103,7 +103,7 @@ function objectClickerOnClick(camera1, buttonManager, recommendations, coins) {
camera1.moveHermite(obj);
// Send event to DB
event = new L3D.BD.Event.ArrowClicked();
event = new L3D.DB.Event.ArrowClicked();
event.arrow_id = recommendations.indexOf(obj);
event.send();
}

View File

@ -48,7 +48,7 @@ saveCoins = function() {
result.coins.push(coins[i].mesh.position);
}
L3D.BD.Private.sendData('/posts/coin-info', result, true);
L3D.DB.Private.sendData('/posts/coin-info', result, true);
};
@ -69,7 +69,7 @@ function main() {
onWindowResize();
// Some config
L3D.BD.disable();
L3D.DB.disable();
Coin.update();
startCanvas.render(L3D.StartCanvas.Black);

View File

@ -47,7 +47,7 @@ function main() {
if (initMainScene !== L3D.initPeach && initMainScene !== L3D.initSponza)
setInterval(function() {logfps(stats.getFps());}, 500);
else
L3D.BD.disable();
L3D.DB.disable();
Coin.update();
startCanvas.render(L3D.StartCanvas.Black);

View File

@ -270,7 +270,7 @@ TutoCamera.prototype.reset = function() {
this.resetPosition();
this.moving = false;
this.movingHermite = false;
(new L3D.BD.Event.ResetClicked()).send();
(new L3D.DB.Event.ResetClicked()).send();
this.previousTheta = this.theta;
this.previousPhi = this.phi;
@ -435,7 +435,7 @@ TutoCamera.prototype.onKeyEvent = function(event, toSet) {
if (motionJsonCopy != JSON.stringify(this.motion)) {
// Log any change
var e = new L3D.BD.Event.KeyboardEvent();
var e = new L3D.DB.Event.KeyboardEvent();
e.camera = this;
e.send();
}
@ -503,7 +503,7 @@ TutoCamera.prototype.onMouseUp = function(event) {
// Send log to DB
if (this.dragging && this.mouseMoved && !this.moving && !this.movingHermite) {
var e = new L3D.BD.Event.KeyboardEvent();
var e = new L3D.DB.Event.KeyboardEvent();
e.camera = this;
e.send();
}
@ -526,7 +526,7 @@ TutoCamera.prototype.save = function() {
TutoCamera.prototype.undo = function() {
var move = this.history.undo();
if (move !== undefined) {
var event = new L3D.BD.Event.PreviousNextClicked();
var event = new L3D.DB.Event.PreviousNextClicked();
event.previous = true;
event.camera = move;
event.send();
@ -538,7 +538,7 @@ TutoCamera.prototype.undo = function() {
TutoCamera.prototype.redo = function() {
var move = this.history.redo();
if (move !== undefined) {
var event = new L3D.BD.Event.PreviousNextClicked();
var event = new L3D.DB.Event.PreviousNextClicked();
event.previous = false;
event.camera = move;
event.send();

View File

@ -223,7 +223,7 @@ L3D.PointerCamera.prototype.isLocked = function() {
* Update the camera when the pointer lock changes state
*/
L3D.PointerCamera.prototype.onPointerLockChange = function() {
var event = new L3D.BD.Event.PointerLocked();
var event = new L3D.DB.Event.PointerLocked();
if (this.isLocked()) {
@ -356,7 +356,7 @@ L3D.PointerCamera.prototype.normalMotion = function(time) {
self.shouldLogCameraAngles = true;
}, 500);
var event = new L3D.BD.Event.KeyboardEvent();
var event = new L3D.DB.Event.KeyboardEvent();
event.camera = this;
event.send();
@ -405,7 +405,7 @@ L3D.PointerCamera.prototype.reset = function() {
this.resetPosition();
this.moving = false;
this.movingHermite = false;
(new L3D.BD.Event.ResetClicked()).send();
(new L3D.DB.Event.ResetClicked()).send();
};
/**
@ -577,7 +577,7 @@ L3D.PointerCamera.prototype.onKeyEvent = function(event, toSet) {
}
if (motionJsonCopy != JSON.stringify(this.motion)) {
// Log any change
var e = new L3D.BD.Event.KeyboardEvent();
var e = new L3D.DB.Event.KeyboardEvent();
e.camera = this;
e.send();
}
@ -662,7 +662,7 @@ L3D.PointerCamera.prototype.onMouseUp = function(event) {
// Send log to DB
if (this.dragging && this.mouseMoved && !this.moving && !this.movingHermite) {
var e = new L3D.BD.Event.KeyboardEvent();
var e = new L3D.DB.Event.KeyboardEvent();
e.camera = this;
e.send();
}
@ -694,7 +694,7 @@ L3D.PointerCamera.prototype.save = function() {
L3D.PointerCamera.prototype.undo = function() {
var move = this.history.undo();
if (move !== undefined) {
var event = new L3D.BD.Event.PreviousNextClicked();
var event = new L3D.DB.Event.PreviousNextClicked();
event.previous = true;
event.camera = move;
event.send();
@ -709,7 +709,7 @@ L3D.PointerCamera.prototype.undo = function() {
L3D.PointerCamera.prototype.redo = function() {
var move = this.history.redo();
if (move !== undefined) {
var event = new L3D.BD.Event.PreviousNextClicked();
var event = new L3D.DB.Event.PreviousNextClicked();
event.previous = false;
event.camera = move;
event.send();

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

View File

@ -69,7 +69,7 @@ Log.mailerror = function(error) {
'[MLE] ' + new Date() + ' ' + error,
Colors.RED
);
}
};
if (isDev) {
Log.debug = function(info) {