Added namespaces

This commit is contained in:
Thomas FORGIONE
2015-07-01 16:31:43 +02:00
parent 5e0551179e
commit 9c7350d41b
38 changed files with 552 additions and 556 deletions
+12 -12
View File
@@ -1,4 +1,4 @@
var CameraSelecter = function(renderer, scene, cameras, coins, buttonManager) {
L3D.CameraSelecter = function(renderer, scene, cameras, coins, buttonManager) {
this.raycaster = new THREE.Raycaster();
this.renderer = renderer;
this.mouse = {};
@@ -9,7 +9,7 @@ var CameraSelecter = function(renderer, scene, cameras, coins, buttonManager) {
this.coins = coins;
};
CameraSelecter.prototype.pointedCamera = function() {
L3D.CameraSelecter.prototype.pointedCamera = function() {
var returnCamera;
var x = ( this.mouse.x / this.renderer.domElement.width ) * 2 - 1;
@@ -66,7 +66,7 @@ CameraSelecter.prototype.pointedCamera = function() {
this.currentPointedCamera = null;
};
CameraSelecter.prototype.update = function(event, y) {
L3D.CameraSelecter.prototype.update = function(event, y) {
var e;
if (event !== undefined) {
@@ -85,7 +85,7 @@ CameraSelecter.prototype.update = function(event, y) {
if (hovered !== undefined && !(hovered instanceof Coin)) {
if (hovered !== previousCamera) {
// log it
e = new BD.Event.Hovered();
e = new L3D.BD.Event.Hovered();
e.start = true;
e.arrow_id = this.cameras.cameras.indexOf(this.currentPointedCamera);
e.send();
@@ -98,7 +98,7 @@ CameraSelecter.prototype.update = function(event, y) {
} else {
if (this.prev.go) {
// Log if previous was not null
e = new BD.Event.Hovered();
e = new L3D.BD.Event.Hovered();
e.start = false;
e.arrow_id = null;
e.send();
@@ -109,17 +109,17 @@ CameraSelecter.prototype.update = function(event, y) {
document.getElementById('container').style.cursor = hovered ? "pointer" : "auto";
if (this.cameras.mainCamera().pointerLocked)
this.cameras.mainCamera().mousePointer.render(hovered ? MousePointer.RED : MousePointer.BLACK);
this.cameras.mainCamera().mousePointer.render(hovered ? L3D.MousePointer.RED : L3D.MousePointer.BLACK);
};
CameraSelecter.prototype.click = function(event) {
L3D.CameraSelecter.prototype.click = function(event) {
var e;
var newCamera = this.pointedCamera();
if (newCamera !== undefined && !(newCamera instanceof Coin)) {
e = new BD.Event.ArrowClicked();
e = new L3D.BD.Event.ArrowClicked();
e.arrow_id = this.cameras.cameras.indexOf(newCamera);
e.send();
@@ -130,7 +130,7 @@ CameraSelecter.prototype.click = function(event) {
} else if (newCamera instanceof Coin) {
// Coin found, notify server
e = new BD.Event.CoinClicked();
e = new L3D.BD.Event.CoinClicked();
e.coin_id = this.coins.indexOf(newCamera);
e.send();
newCamera.get();
@@ -139,7 +139,7 @@ CameraSelecter.prototype.click = function(event) {
};
CameraSelecter.prototype.clickPointer = function(event) {
L3D.CameraSelecter.prototype.clickPointer = function(event) {
var e;
if (this.cameras.mainCamera().pointerLocked) {
@@ -148,7 +148,7 @@ CameraSelecter.prototype.clickPointer = function(event) {
if (newCamera !== undefined && !(newCamera instanceof Coin)) {
e = new BD.Event.ArrowClicked();
e = new L3D.BD.Event.ArrowClicked();
e.arrow_id = this.cameras.cameras.indexOf(newCamera);
e.send();
@@ -159,7 +159,7 @@ CameraSelecter.prototype.clickPointer = function(event) {
} else if (newCamera instanceof Coin) {
// Coin found, notify server
e = new BD.Event.CoinClicked();
e = new L3D.BD.Event.CoinClicked();
e.coin_id = this.coins.indexOf(newCamera);
e.send();
newCamera.get();
+8 -7
View File
@@ -1,8 +1,9 @@
/**
* Represents the history of an object
* @constructor
* @memberOf L3D
*/
var History = function() {
L3D.History = function() {
/**
* Stores the different states of the object
* @type {Object[]}
@@ -26,7 +27,7 @@ var History = function() {
* Appends a new state at the end of the history
* @param {Object} state the state to append
*/
History.prototype.addState = function(state) {
L3D.History.prototype.addState = function(state) {
++this.index;
this.size = this.index + 1;
this.states[this.size-1] = state;
@@ -35,7 +36,7 @@ History.prototype.addState = function(state) {
/**
* Returns the previous state and change the index to the previous state (so you can redo)
*/
History.prototype.undo = function() {
L3D.History.prototype.undo = function() {
if (this.undoable()) {
this.index--;
return this.currentState();
@@ -45,7 +46,7 @@ History.prototype.undo = function() {
/**
* Returns the next state and change the index to the next state (so you can re-undo)
*/
History.prototype.redo = function() {
L3D.History.prototype.redo = function() {
if (this.redoable()) {
this.index++;
return this.currentState();
@@ -56,7 +57,7 @@ History.prototype.redo = function() {
* Checks if there is a undo possibility
* @returns {Boolean} true if undo is possible, false otherwise
*/
History.prototype.undoable = function() {
L3D.History.prototype.undoable = function() {
return this.index > 0;
};
@@ -64,7 +65,7 @@ History.prototype.undoable = function() {
* Checks if there is a redo possibility
* @returns {Boolean} true if redo is possible, false otherwise
*/
History.prototype.redoable = function() {
L3D.History.prototype.redoable = function() {
return this.index < this.size - 1;
};
@@ -72,6 +73,6 @@ History.prototype.redoable = function() {
* Returns the current state in the history
* @returns {Object} the current state in the history
*/
History.prototype.currentState = function() {
L3D.History.prototype.currentState = function() {
return this.states[this.index];
};
+1 -1
View File
@@ -1,4 +1,4 @@
var utils = (function() {
L3D.utils = (function() {
var utils = {};
+34 -34
View File
@@ -1,9 +1,9 @@
var BD = {};
L3D.BD = {};
BD.Private = {};
L3D.BD.Private = {};
BD.Private.sendData = function(url, data) {
if (BD.Private.enabled) {
L3D.BD.Private.sendData = function(url, data) {
if (L3D.BD.Private.enabled) {
// Append time to data
data.time = Date.now() / 1000;
@@ -21,17 +21,17 @@ BD.Private.sendData = function(url, data) {
}
};
BD.Private.enabled = true;
L3D.BD.Private.enabled = true;
BD.enable = function() {
BD.Private.enabled = true;
L3D.BD.enable = function() {
L3D.BD.Private.enabled = true;
};
BD.disable = function() {
BD.Private.enabled = false;
L3D.BD.disable = function() {
L3D.BD.Private.enabled = false;
};
BD.Private.compactCamera = function(camera) {
L3D.BD.Private.compactCamera = function(camera) {
return {
position: {
x: camera.position.x,
@@ -46,71 +46,71 @@ BD.Private.compactCamera = function(camera) {
};
};
BD.Event = {};
L3D.BD.Event = {};
BD.Event.ArrowClicked = function() {};
BD.Event.ArrowClicked.prototype.send = function() {
L3D.BD.Event.ArrowClicked = function() {};
L3D.BD.Event.ArrowClicked.prototype.send = function() {
var url = "/arrow-clicked";
var data = {arrow_id: this.arrow_id};
BD.Private.sendData(url, data);
L3D.BD.Private.sendData(url, data);
};
BD.Event.CoinClicked = function() {};
BD.Event.CoinClicked.prototype.send = function() {
L3D.BD.Event.CoinClicked = function() {};
L3D.BD.Event.CoinClicked.prototype.send = function() {
var url = "/coin-clicked";
var data = {coin_id: this.coin_id};
BD.Private.sendData(url, data);
L3D.BD.Private.sendData(url, data);
};
BD.Event.KeyboardEvent = function() {};
BD.Event.KeyboardEvent.prototype.send = function() {
L3D.BD.Event.KeyboardEvent = function() {};
L3D.BD.Event.KeyboardEvent.prototype.send = function() {
var url = "/keyboard-event";
var data = {
camera: BD.Private.compactCamera(this.camera)
camera: L3D.BD.Private.compactCamera(this.camera)
};
BD.Private.sendData(url, data);
L3D.BD.Private.sendData(url, data);
};
BD.Event.ResetClicked = function() {};
BD.Event.ResetClicked.prototype.send = function() {
L3D.BD.Event.ResetClicked = function() {};
L3D.BD.Event.ResetClicked.prototype.send = function() {
var url = "/reset-clicked";
var data = {};
BD.Private.sendData(url, data);
L3D.BD.Private.sendData(url, data);
};
BD.Event.PreviousNextClicked = function() {};
BD.Event.PreviousNextClicked.prototype.send = function() {
L3D.BD.Event.PreviousNextClicked = function() {};
L3D.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)
camera: L3D.BD.Private.compactCamera(this.camera)
};
BD.Private.sendData(url, data);
L3D.BD.Private.sendData(url, data);
};
BD.Event.Hovered = function() {};
BD.Event.Hovered.prototype.send = function() {
L3D.BD.Event.Hovered = function() {};
L3D.BD.Event.Hovered.prototype.send = function() {
var url = "/hovered";
var data = {
start: this.start,
arrow_id: this.arrow_id
};
BD.Private.sendData(url, data);
L3D.BD.Private.sendData(url, data);
};
BD.Event.Fps = function() {};
BD.Event.Fps.prototype.send = function() {
L3D.BD.Event.Fps = function() {};
L3D.BD.Event.Fps.prototype.send = function() {
var url = "/fps";
var data = {
fps: this.fps
};
BD.Private.sendData(url, data);
L3D.BD.Private.sendData(url, data);
};
+14 -14
View File
@@ -1,19 +1,19 @@
var Displayable = function() {
L3D.Displayable = function() {
// Nothing to do here
};
Displayable.prototype.addToScene = function(scene) {
L3D.Displayable.prototype.addToScene = function(scene) {
scene.add(this.mesh);
};
Displayable.prototype.translate = function(x,y,z) {
L3D.Displayable.prototype.translate = function(x,y,z) {
this.geometry.applyMatrix(new THREE.Matrix4().makeTranslation(x,y,z));
};
// class Cube extends Displayable
var Cube = function(size, style) {
// class L3D.Cube extends L3D.Displayable
L3D.Cube = function(size, style) {
// Super constructor call
Displayable.call(this);
L3D.Displayable.call(this);
if (size === undefined) size = 100;
if (style === undefined) style = {};
@@ -25,12 +25,12 @@ var Cube = function(size, style) {
this.mesh = new THREE.Mesh(this.geometry, this.material);
this.mesh.castShadow = false;
};
Cube.prototype = Object.create(Displayable.prototype);
Cube.prototype.constructor = Cube;
L3D.Cube.prototype = Object.create(L3D.Displayable.prototype);
L3D.Cube.prototype.constructor = L3D.Cube;
// class Plane extends Displayable
var Plane = function(size1, size2, style) {
Displayable.call(this);
// class L3D.Plane extends L3D.Displayable
L3D.Plane = function(size1, size2, style) {
L3D.Displayable.call(this);
if (style === undefined) style = {};
@@ -41,9 +41,9 @@ var Plane = function(size1, size2, style) {
this.mesh.receiveShadow = true;
};
Plane.prototype = Object.create(Displayable.prototype);
Plane.prototype.constructor = Plane;
L3D.Plane.prototype = Object.create(L3D.Displayable.prototype);
L3D.Plane.prototype.constructor = L3D.Plane;
Plane.prototype.addToScene = function(scene) {
L3D.Plane.prototype.addToScene = function(scene) {
scene.add(this.mesh);
};