Cleaning
This commit is contained in:
parent
5f3b2e1862
commit
f0e4455bc2
|
@ -2,26 +2,6 @@ var pg = require('pg');
|
|||
var pgc = require('../../private.js');
|
||||
var Log = require('../../lib/NodeLog.js');
|
||||
|
||||
// Shuffle array
|
||||
function shuffle(array) {
|
||||
var currentIndex = array.length, temporaryValue, randomIndex ;
|
||||
|
||||
// While there remain elements to shuffle...
|
||||
while (0 !== currentIndex) {
|
||||
|
||||
// Pick a remaining element...
|
||||
randomIndex = Math.floor(Math.random() * currentIndex);
|
||||
currentIndex -= 1;
|
||||
|
||||
// And swap it with the current element.
|
||||
temporaryValue = array[currentIndex];
|
||||
array[currentIndex] = array[randomIndex];
|
||||
array[randomIndex] = temporaryValue;
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @namespace
|
||||
|
@ -994,7 +974,7 @@ DBReq.TutorialCreator.prototype.finish = function() {
|
|||
this.client = null;
|
||||
|
||||
this.finishAction(this.finalResult.expId, this.finalResult.coins);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Try to get a user by id, and creates it if it doesn't exists
|
||||
|
|
|
@ -3,47 +3,6 @@ var pg = require('pg');
|
|||
var pgc = require('../../private');
|
||||
var db = require('./dbrequests');
|
||||
|
||||
// Shuffle array
|
||||
function shuffle(array) {
|
||||
var currentIndex = array.length, temporaryValue, randomIndex ;
|
||||
|
||||
// While there remain elements to shuffle...
|
||||
while (0 !== currentIndex) {
|
||||
|
||||
// Pick a remaining element...
|
||||
randomIndex = Math.floor(Math.random() * currentIndex);
|
||||
currentIndex -= 1;
|
||||
|
||||
// And swap it with the current element.
|
||||
temporaryValue = array[currentIndex];
|
||||
array[currentIndex] = array[randomIndex];
|
||||
array[randomIndex] = temporaryValue;
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
function randomArray() {
|
||||
var arr = [];
|
||||
for (var i = 2; i < 5; i++) {
|
||||
arr.push(i);
|
||||
}
|
||||
arr = shuffle(arr);
|
||||
return arr;
|
||||
}
|
||||
|
||||
|
||||
function randomReco() {
|
||||
var recoStyles = [
|
||||
'prototype_empty.jade',
|
||||
'prototype_viewports.jade',
|
||||
'prototype_arrows.jade'
|
||||
];
|
||||
|
||||
return shuffle(recoStyles);
|
||||
|
||||
}
|
||||
|
||||
module.exports.index = function(req, res) {
|
||||
res.setHeader('Content-Type', 'text/html');
|
||||
|
||||
|
@ -52,26 +11,6 @@ module.exports.index = function(req, res) {
|
|||
});
|
||||
};
|
||||
|
||||
var generateSceneNumber = function(req, res) {
|
||||
if (req.session.scenes !== undefined) {
|
||||
req.session.currentSceneIndex++;
|
||||
} else {
|
||||
req.session.scenes = randomArray();
|
||||
req.session.currentSceneIndex = 0;
|
||||
}
|
||||
|
||||
return req.session.scenes[req.session.currentSceneIndex];
|
||||
};
|
||||
|
||||
var generateRecommendationStyle = function(req, res) {
|
||||
|
||||
if (req.session.recos === undefined) {
|
||||
req.session.recos = randomReco();
|
||||
}
|
||||
|
||||
return req.session.recos.shift();
|
||||
};
|
||||
|
||||
var sceneToFunction = function(scene) {
|
||||
switch (scene) {
|
||||
case 2:
|
||||
|
@ -89,9 +28,6 @@ module.exports.game = function(req, res) {
|
|||
|
||||
db.tryUser(req.session.user_id, function(id) {
|
||||
|
||||
var scene = generateSceneNumber(req, res);
|
||||
res.locals.scene = sceneToFunction(scene);
|
||||
res.locals.recommendationStyle = 'L3D.ArrowRecommendation';
|
||||
req.session.user_id = id;
|
||||
|
||||
db.createExp(id, function(expId, coinCombinationId, sceneId, recommendationStyle, coins) {
|
||||
|
@ -187,7 +123,9 @@ module.exports.tutorial = function(req, res) {
|
|||
|
||||
};
|
||||
|
||||
module.exports.clicker = function(req, res, next) {
|
||||
function editorHelper(templateName) {
|
||||
|
||||
return function(req, res, next) {
|
||||
|
||||
var scene = req.params.scene;
|
||||
|
||||
|
@ -207,63 +145,17 @@ module.exports.clicker = function(req, res, next) {
|
|||
}
|
||||
|
||||
res.setHeader('Content-Type', 'text/html');
|
||||
res.render('prototype_clicker.jade', res.locals, function(err, result) {
|
||||
res.render(templateName, res.locals, function(err, result) {
|
||||
res.send(result);
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
module.exports.viewer = function(req, res, next) {
|
||||
|
||||
var scene = req.params.scene;
|
||||
|
||||
switch (scene) {
|
||||
|
||||
case 'peach': res.locals.scene = "L3D.initPeach"; break;
|
||||
case 'coolcoolmountain': res.locals.scene = "L3D.initMountain"; break;
|
||||
case 'whomp': res.locals.scene = "L3D.initWhomp"; break;
|
||||
case 'bobomb': res.locals.scene = "L3D.initBobomb"; break;
|
||||
default:
|
||||
// 404
|
||||
var err = new Error('Incorrect scene');
|
||||
err.status = 404;
|
||||
next(err);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
res.setHeader('Content-Type', 'text/html');
|
||||
res.render('prototype_viewer.jade', res.locals, function(err, result) {
|
||||
res.send(result);
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
module.exports.checker = function(req, res, next) {
|
||||
|
||||
var scene = req.params.scene;
|
||||
|
||||
switch (scene) {
|
||||
|
||||
case 'peach': res.locals.scene = "L3D.initPeach"; break;
|
||||
case 'coolcoolmountain': res.locals.scene = "L3D.initMountain"; break;
|
||||
case 'whomp': res.locals.scene = "L3D.initWhomp"; break;
|
||||
case 'bobomb': res.locals.scene = "L3D.initBobomb"; break;
|
||||
default:
|
||||
// 404
|
||||
var err = new Error('Incorrect scene');
|
||||
err.status = 404;
|
||||
next(err);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
res.setHeader('Content-Type', 'text/html');
|
||||
res.render('prototype_checker.jade', res.locals, function(err, result) {
|
||||
res.send(result);
|
||||
});
|
||||
|
||||
};
|
||||
module.exports.clicker = editorHelper('prototype_clicker.jade');
|
||||
module.exports.viewer = editorHelper('prototype_viewer.jade');
|
||||
module.exports.checker = editorHelper('prototype_checker.jade');
|
||||
|
||||
module.exports.userstudy = function(req, res) {
|
||||
res.setHeader('Content-Type', 'text/html');
|
||||
|
|
|
@ -210,13 +210,11 @@ L3D.PointerCamera.prototype.lockPointer = function() {
|
|||
* @returns true if the pointer is locked, false otherwise
|
||||
*/
|
||||
L3D.PointerCamera.prototype.isLocked = function() {
|
||||
var toto =
|
||||
return
|
||||
document.pointerLockElement === this.renderer.domElement ||
|
||||
document.mozPointerLockElement === this.renderer.domElement ||
|
||||
document.webkitPointerLockElement === this.renderer.domElement;
|
||||
|
||||
return toto;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -741,6 +739,14 @@ L3D.PointerCamera.prototype.redoable = function() {
|
|||
return this.history.redoable();
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a list containing all the elements to send to the server to stream visible part
|
||||
* @return {Array} A list containing <ol start="0">
|
||||
* <li>the position of the camera</li>
|
||||
* <li>the target of the camera</li>
|
||||
* <li>and planes defining the frustum of the camera (a,b,c, and d from ax+by+cz+d=0)</li>
|
||||
* </ol>
|
||||
*/
|
||||
L3D.PointerCamera.prototype.toList = function() {
|
||||
this.updateMatrix();
|
||||
this.updateMatrixWorld();
|
||||
|
|
|
@ -10,6 +10,7 @@ Math.clamp = Math.clamp || function(number, min, max) {
|
|||
* @description Displays a small preview of a camera
|
||||
*/
|
||||
L3D.Previewer = function(renderer, scene) {
|
||||
|
||||
/**
|
||||
* @type {element}
|
||||
* @description The document element to add on top of the renderer
|
||||
|
@ -60,13 +61,6 @@ L3D.Previewer = function(renderer, scene) {
|
|||
|
||||
/**
|
||||
* Renders the preview
|
||||
* @param {Object} pref an object containing :
|
||||
* <ul>
|
||||
* <li><code>go</code> : a boolean if the rendering should be done</li>
|
||||
* <li><code>x</code> : the x coordinate of the mouse</li>
|
||||
* <li><code>y</code> : the y coordinate of the mouse</li>
|
||||
* <li><code>camera</code> : the camera to use for the preview</li>
|
||||
* </ul>
|
||||
* @param {Number} container_width width of the container
|
||||
* @param {Number} container_height height of the container
|
||||
*/
|
||||
|
|
|
@ -2,6 +2,7 @@ L3D.ProgressiveLoader = (function() {
|
|||
|
||||
/**
|
||||
* Parse a list as it is sent by the server and gives a slightly more comprehensible result
|
||||
* @param Array array corresponding to the line of the mesh file
|
||||
* @private
|
||||
*/
|
||||
var _parseList = function(arr) {
|
||||
|
@ -117,12 +118,6 @@ var ProgressiveLoader = function(path, scene, camera, callback, log) {
|
|||
*/
|
||||
this.callback = callback;
|
||||
|
||||
/**
|
||||
* Counter (not used)
|
||||
* @private
|
||||
*/
|
||||
this.counter = 0;
|
||||
|
||||
/**
|
||||
* Group where the sub-objects will be added
|
||||
* @type {THREE.Object3D}
|
||||
|
|
|
@ -48,7 +48,7 @@ L3D.Hermite.Polynom = function(t, f, fp) {
|
|||
* @type {Object}
|
||||
* @description an object containing
|
||||
* <ul>
|
||||
* <li><code>whatType</code> : a string being <code>THREE.Vector3</code> or <code>number</code></li>
|
||||
* <li><code>whatType</code> : a string being <code>THREE.Vector3</code> or <code>Number</code></li>
|
||||
* <li><code>tools</code> : an object containg sum and mul, functions of the correct type</li>
|
||||
* </ul>
|
||||
*/
|
||||
|
@ -58,7 +58,7 @@ L3D.Hermite.Polynom = function(t, f, fp) {
|
|||
this.tools.sum = L3D.Tools.sum;
|
||||
this.tools.prod = L3D.Tools.mul;
|
||||
} else {
|
||||
this.tools.whatType = 'number';
|
||||
this.tools.whatType = 'Number';
|
||||
this.tools.sum = function(a, b) { return a + b; };
|
||||
this.tools.prod = function(a, b) { return a * b; };
|
||||
}
|
||||
|
@ -266,7 +266,7 @@ L3D.Hermite.special.Polynom = function(P0, P1, PP1) {
|
|||
* @type {Object}
|
||||
* @description an object containing
|
||||
* <ul>
|
||||
* <li><code>whatType</code> : a string being <code>THREE.Vector3</code> or <code>number</code></li>
|
||||
* <li><code>whatType</code> : a string being <code>THREE.Vector3</code> or <code>Number</code></li>
|
||||
* <li><code>tools</code> : an object containg sum and mul, functions of the correct type</li>
|
||||
* </ul>
|
||||
*/
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
/**
|
||||
* @memberof L3D
|
||||
* @extends BaseRecommendation
|
||||
* @description Represents a recommendation not shown and not clickable (for hiding recommendations)
|
||||
* @constructor
|
||||
*/
|
||||
L3D.EmptyRecommendation = function() {
|
||||
L3D.BaseRecommendation.apply(this, arguments);
|
||||
this.target = new THREE.Vector3();
|
||||
|
|
|
@ -1,23 +1,3 @@
|
|||
// http://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array#answer-2450976
|
||||
L3D.shuffle = function(array) {
|
||||
var currentIndex = array.length, temporaryValue, randomIndex ;
|
||||
|
||||
// While there remain elements to shuffle...
|
||||
while (0 !== currentIndex) {
|
||||
|
||||
// Pick a remaining element...
|
||||
randomIndex = Math.floor(Math.random() * currentIndex);
|
||||
currentIndex -= 1;
|
||||
|
||||
// And swap it with the current element.
|
||||
temporaryValue = array[currentIndex];
|
||||
array[currentIndex] = array[randomIndex];
|
||||
array[randomIndex] = temporaryValue;
|
||||
}
|
||||
|
||||
return array;
|
||||
};
|
||||
|
||||
L3D.LogFunction = function(a,b) {
|
||||
var val = 100*a/b;
|
||||
$('.progress-bar').css('width', val+'%').attr('aria-valuenow', val);
|
||||
|
@ -218,19 +198,27 @@ L3D.resetBobombElements = function() {
|
|||
L3D.generateCoins = function(totalCoins, coin_ids) {
|
||||
|
||||
var i = 0;
|
||||
var tmp = [];
|
||||
|
||||
if (coin_ids === undefined) {
|
||||
var tmp = [];
|
||||
// Use global variable coinsId
|
||||
|
||||
tmp = [];
|
||||
|
||||
// Use global variable coinsId set by server
|
||||
for (i = 0; i < totalCoins.length; i++) {
|
||||
tmp.push(totalCoins[i]);
|
||||
}
|
||||
|
||||
totalCoins.length = 0;
|
||||
for (var i = 0; i < 8; i++) {
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
totalCoins.push(tmp[coinsId[i]]);
|
||||
}
|
||||
|
||||
} else if (coin_ids === null) {
|
||||
|
||||
return [];
|
||||
|
||||
} else {
|
||||
|
||||
for (i = 0; i < coin_ids.length; i++) {
|
||||
|
@ -240,7 +228,7 @@ L3D.generateCoins = function(totalCoins, coin_ids) {
|
|||
if (coin_ids[i] === totalCoins[j].id) {
|
||||
|
||||
// Swap i and j
|
||||
var tmp = totalCoins[i];
|
||||
tmp = totalCoins[i];
|
||||
totalCoins[i] = totalCoins[j];
|
||||
totalCoins[j] = tmp;
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ module.exports.index = function(req, res) {
|
|||
var text = '';
|
||||
|
||||
for (var i in req.body) {
|
||||
text += i + ' : ' + req.body[i] + '\n'
|
||||
text += i + ' : ' + req.body[i] + '\n';
|
||||
}
|
||||
|
||||
mail.send({
|
||||
|
|
Loading…
Reference in New Issue