Added replay (first step)

This commit is contained in:
Thomas FORGIONE
2015-05-19 15:43:09 +02:00
parent 98ca4676d8
commit 0d73873135
5 changed files with 472 additions and 12 deletions

View File

@@ -1,7 +1,8 @@
var tools = require('../../my_modules/filterInt.js');
var pg = require('pg');
var pgc = require('../../private.js');
var createNewId = function(req, callback) {
var createNewId = function(req, res, callback) {
pg.connect(pgc.url, function(err, client, release) {
client.query(
"INSERT INTO users(name) VALUES('anonymous'); SELECT currval('users_id_seq');",
@@ -16,6 +17,42 @@ var createNewId = function(req, callback) {
});
}
var getPathFromId = function(req, res, callback, id) {
pg.connect(pgc.url, function(err, client, release) {
client.query(
"SELECT ((camera).position).x AS px, " +
"((camera).position).y AS py, " +
"((camera).position).z AS pz, " +
"((camera).target).x AS tx, " +
"((camera).target).y AS ty, " +
"((camera).target).z AS tz " +
"FROM keyboardevent WHERE user_id = $1;",
[id],
function(err, result) {
res.locals.path = [];
for (var i in result.rows) {
res.locals.path.push(
{
position : {
x: result.rows[i].px,
y: result.rows[i].py,
z: result.rows[i].pz
},
target : {
x: result.rows[i].tx,
y: result.rows[i].ty,
z: result.rows[i].tz
}
}
);
}
callback();
release();
}
);
});
}
module.exports.index = function(req, res) {
res.setHeader('Content-Type', 'text/html');
@@ -25,7 +62,7 @@ module.exports.index = function(req, res) {
}
module.exports.arrows = function(req, res) {
createNewId(req, function() {
createNewId(req, res, function() {
res.setHeader('Content-Type', 'text/html');
res.locals.cameraStyle = 'arrows';
@@ -37,7 +74,7 @@ module.exports.arrows = function(req, res) {
}
module.exports.viewports = function(req, res) {
createNewId(req, function() {
createNewId(req, res, function() {
res.setHeader('Content-Type', 'text/html');
res.locals.cameraStyle = 'viewports';
@@ -49,7 +86,7 @@ module.exports.viewports = function(req, res) {
}
module.exports.reverse = function(req, res) {
createNewId(req, function() {
createNewId(req, res, function() {
res.setHeader('Content-Type', 'text/html');
res.locals.cameraStyle = 'reverse';
@@ -59,3 +96,24 @@ module.exports.reverse = function(req, res) {
});
});
}
module.exports.replay_info = function(req, res) {
res.setHeader('Content-Type', 'text/plain');
// Parse id
var id = tools.filterInt(req.params.id);
getPathFromId(req, res, function() {
res.send(JSON.stringify(res.locals.path));
}, id);
}
module.exports.replay = function(req, res) {
res.setHeader('Content-Type', 'text/html');
res.locals.cameraStyle = "replay";
res.locals.id = tools.filterInt(req.params.id);
res.render('prototype.jade', res.locals, function(err, result) {
res.send(result);
});
}

View File

@@ -2,5 +2,7 @@ module.exports = {
'/prototype': 'index',
'/prototype/arrows': 'arrows',
'/prototype/viewports': 'viewports',
'/prototype/reverse': 'reverse'
'/prototype/reverse': 'reverse',
'/prototype/replay/:id': 'replay',
'/prototype/replay_info/:id': 'replay_info'
}

View File

@@ -14,13 +14,21 @@ block extrajs
script(src="/static/js/prototype/ButtonManager.js")
script(src="/static/js/prototype/Coin.js")
script(src="/static/js/Logger.js")
if cameraStyle == 'arrows'
script RecommendedCamera = FixedCamera;
else if cameraStyle == 'viewports'
script RecommendedCamera = OldFixedCamera;
else if cameraStyle == 'reverse'
script RecommendedCamera = ReverseCamera
script(src="/static/js/prototype/main.js")
if cameraStyle == 'replay'
script var params = params || {}; params.get = params.get || {}; params.get.id = #{id};
script(src="/static/js/ReplayCamera.js")
script(src="/static/js/prototype/replay.js")
else
if cameraStyle == 'arrows'
script RecommendedCamera = FixedCamera;
else if cameraStyle == 'viewports'
script RecommendedCamera = OldFixedCamera;
else if cameraStyle == 'reverse'
script RecommendedCamera = ReverseCamera
script(src="/static/js/prototype/main.js")
script document.getElementById('music').volume = 0.5;
block extrahead