3d-interface/controllers/prototype/index.js

176 lines
4.7 KiB
JavaScript
Raw Normal View History

2015-06-30 15:13:49 +02:00
var tools = require('../../lib/filterInt');
2015-05-18 17:51:20 +02:00
var pg = require('pg');
var pgc = require('../../private');
var db = require('./dbrequests');
2015-05-20 11:17:14 +02:00
2015-05-05 11:56:35 +02:00
module.exports.index = function(req, res) {
res.setHeader('Content-Type', 'text/html');
2015-05-05 16:30:51 +02:00
res.render('index.jade', res.locals, function(err, result) {
2015-05-05 11:56:35 +02:00
res.send(result);
});
};
2015-05-05 11:56:35 +02:00
var sceneToFunction = function(scene) {
switch (scene) {
case 2:
2015-07-01 16:31:43 +02:00
return 'L3D.initBobomb';
case 3:
2015-07-01 16:31:43 +02:00
return 'L3D.initMountain';
case 4:
2015-07-01 16:31:43 +02:00
return 'L3D.initWhomp';
default:
2015-07-01 16:31:43 +02:00
return 'L3D.initPeach';
}
};
2015-08-04 18:59:24 +02:00
module.exports.game = function(req, res) {
2015-07-29 11:04:38 +02:00
db.tryUser(req.session.userId, function(id) {
2015-07-29 11:04:38 +02:00
req.session.userId = id;
2015-07-29 11:04:38 +02:00
2015-08-04 18:59:24 +02:00
db.createExp(id, function(expId, coinCombinationId, sceneId, recommendationStyle, coins) {
if (expId === undefined) {
res.redirect('/feedback');
return;
2015-07-29 11:04:38 +02:00
2015-08-04 18:59:24 +02:00
}
req.session.expId = expId;
2015-08-04 18:59:24 +02:00
req.session.save();
res.locals.scene = sceneToFunction(sceneId);
res.locals.recommendationStyle = recommendationStyle;
res.locals.coins = coins;
res.setHeader('Content-Type','text/html');
res.render('prototype_recommendation.jade', res.locals, function(err, result) {
res.send(result);
});
});
2015-08-04 18:59:24 +02:00
});
};
2015-05-05 11:56:35 +02:00
2015-06-11 11:47:44 +02:00
module.exports.sponza = function(req, res) {
res.setHeader('Content-Type', 'text/html');
res.render('sponza.jade', res.locals, function(err, result) {
res.send(result);
});
};
2015-06-11 11:47:44 +02:00
module.exports.replayInfo = function(req, res) {
2015-05-19 15:43:09 +02:00
res.setHeader('Content-Type', 'text/plain');
// Parse id
var id = tools.filterInt(req.params.id);
db.getInfo(id, function(results) {
res.send(JSON.stringify(results));
2015-05-20 10:47:27 +02:00
});
};
2015-05-19 15:43:09 +02:00
2015-05-19 15:55:00 +02:00
module.exports.replay = function(req, res, next) {
// Get id parameter
2015-05-19 15:43:09 +02:00
res.locals.id = tools.filterInt(req.params.id);
db.checkExpId(res.locals.id, function(sceneId) {
if (sceneId === null) {
var err = new Error("This replay does not exist");
err.status = 404;
next(err);
} else {
res.locals.initjs = sceneToFunction(sceneId);
res.setHeader('Content-Type', 'text/html');
res.render('prototype_replays.jade', res.locals, function(err, result) {
res.send(result);
});
}
});
};
2015-05-20 11:17:14 +02:00
module.exports.replayIndex = function(req, res, next) {
db.getAllExps(function(result) {
res.locals.users = result;
res.setHeader('Content-Type', 'text/html');
2015-05-20 11:17:14 +02:00
res.render("replay_index.jade", res.locals, function(err, result) {
res.send(result);
});
});
};
2015-05-26 11:49:24 +02:00
module.exports.tutorial = function(req, res) {
db.tryUser(req.session.userId, function(id) {
req.session.userId = id;
2015-05-26 11:49:24 +02:00
// 1 is the ID of peach scene
2015-08-05 14:47:54 +02:00
db.createTutorial(id, function(id, coins) {
req.session.expId = id;
2015-08-05 14:47:54 +02:00
res.locals.coins = coins;
req.session.save();
res.setHeader('Content-Type', 'text/html');
res.render('tutorial.jade', res.locals, function(err, result) {
res.send(result);
});
});
2015-05-26 11:49:24 +02:00
});
};
2015-07-17 11:32:57 +02:00
2015-08-25 14:03:01 +02:00
function editorHelper(templateName) {
2015-07-17 11:32:57 +02:00
2015-08-25 14:03:01 +02:00
return function(req, res, next) {
2015-07-20 15:48:44 +02:00
2015-08-25 14:03:01 +02:00
var scene = req.params.scene;
2015-07-20 15:48:44 +02:00
2015-08-25 14:03:01 +02:00
switch (scene) {
2015-07-20 15:48:44 +02:00
2015-08-25 14:03:01 +02:00
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;
2015-07-20 15:48:44 +02:00
2015-08-25 14:03:01 +02:00
}
2015-07-20 15:48:44 +02:00
2015-08-25 14:03:01 +02:00
res.setHeader('Content-Type', 'text/html');
res.render(templateName, res.locals, function(err, result) {
res.send(result);
});
2015-07-20 15:48:44 +02:00
2015-08-25 14:03:01 +02:00
};
2015-07-20 15:48:44 +02:00
2015-08-26 14:27:22 +02:00
}
2015-07-23 17:19:53 +02:00
2015-08-25 14:03:01 +02:00
module.exports.clicker = editorHelper('prototype_clicker.jade');
module.exports.viewer = editorHelper('prototype_viewer.jade');
module.exports.checker = editorHelper('prototype_checker.jade');
2015-08-24 17:13:14 +02:00
2015-07-23 17:19:53 +02:00
module.exports.userstudy = function(req, res) {
res.setHeader('Content-Type', 'text/html');
res.locals.identificationFailed = req.session.identificationFailed;
req.session.identificationFailed = false;
req.session.save();
res.render('user_study.jade', res.locals, function(err, result) {
2015-07-23 17:19:53 +02:00
res.send(result);
});
};
2015-08-31 13:05:05 +02:00
module.exports.next = function(req, res) {
2015-09-01 09:51:57 +02:00
res.redirect('/prototype/game');
2015-08-31 13:05:05 +02:00
};