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
go
: a boolean if the rendering should be donex
: the x coordinate of the mousey
: the y coordinate of the mousecamera
: the camera to use for the previewwhatType
: a string being THREE.Vector3
or number
whatType
: a string being THREE.Vector3
or Number
tools
: an object containg sum and mul, functions of the correct typewhatType
: a string being THREE.Vector3
or number
whatType
: a string being THREE.Vector3
or Number
tools
: an object containg sum and mul, functions of the correct type