diff --git a/controllers/prototype/dbrequests.js b/controllers/prototype/dbrequests.js index 649f0b9..c1e9b20 100644 --- a/controllers/prototype/dbrequests.js +++ b/controllers/prototype/dbrequests.js @@ -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 diff --git a/controllers/prototype/index.js b/controllers/prototype/index.js index 07a26b6..74898c5 100644 --- a/controllers/prototype/index.js +++ b/controllers/prototype/index.js @@ -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,83 +123,39 @@ module.exports.tutorial = function(req, res) { }; -module.exports.clicker = function(req, res, next) { +function editorHelper(templateName) { - var scene = req.params.scene; + return function(req, res, next) { - switch (scene) { + var scene = req.params.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; + 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_clicker.jade', res.locals, function(err, result) { - res.send(result); - }); + } + + res.setHeader('Content-Type', 'text/html'); + 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'); diff --git a/js/l3d/src/cameras/PointerCamera.js b/js/l3d/src/cameras/PointerCamera.js index 2d4a8e8..aef18ae 100644 --- a/js/l3d/src/cameras/PointerCamera.js +++ b/js/l3d/src/cameras/PointerCamera.js @@ -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
    + *
  1. the position of the camera
  2. + *
  3. the target of the camera
  4. + *
  5. and planes defining the frustum of the camera (a,b,c, and d from ax+by+cz+d=0)
  6. + *
+ */ L3D.PointerCamera.prototype.toList = function() { this.updateMatrix(); this.updateMatrixWorld(); diff --git a/js/l3d/src/canvases/Previewer.js b/js/l3d/src/canvases/Previewer.js index 1f2f3bd..9ac92c5 100644 --- a/js/l3d/src/canvases/Previewer.js +++ b/js/l3d/src/canvases/Previewer.js @@ -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 : - * * @param {Number} container_width width of the container * @param {Number} container_height height of the container */ diff --git a/js/l3d/src/loaders/ProgressiveLoader.js b/js/l3d/src/loaders/ProgressiveLoader.js index d7c6b5b..df2bfe8 100644 --- a/js/l3d/src/loaders/ProgressiveLoader.js +++ b/js/l3d/src/loaders/ProgressiveLoader.js @@ -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} diff --git a/js/l3d/src/math/Hermite.js b/js/l3d/src/math/Hermite.js index 93d79c5..b7a3079 100644 --- a/js/l3d/src/math/Hermite.js +++ b/js/l3d/src/math/Hermite.js @@ -48,7 +48,7 @@ L3D.Hermite.Polynom = function(t, f, fp) { * @type {Object} * @description an object containing * */ @@ -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 * */ diff --git a/js/l3d/src/recommendations/EmptyRecommendation.js b/js/l3d/src/recommendations/EmptyRecommendation.js index fedfa3b..0111325 100644 --- a/js/l3d/src/recommendations/EmptyRecommendation.js +++ b/js/l3d/src/recommendations/EmptyRecommendation.js @@ -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(); diff --git a/js/l3d/src/scenes/initScene.js b/js/l3d/src/scenes/initScene.js index b63faa6..ad2e02c 100644 --- a/js/l3d/src/scenes/initScene.js +++ b/js/l3d/src/scenes/initScene.js @@ -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; diff --git a/posts/feedback-target/index.js b/posts/feedback-target/index.js index d846b0b..dd346fb 100644 --- a/posts/feedback-target/index.js +++ b/posts/feedback-target/index.js @@ -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({