2015-01-11 06:59:24 +00:00
|
|
|
var _ = require('lodash'),
|
2015-01-22 02:32:13 +00:00
|
|
|
debug = require('debug')('freecc:cntr:bonfires'),
|
2015-01-24 22:29:50 +00:00
|
|
|
Bonfire = require('./../models/Bonfire'),
|
|
|
|
User = require('./../models/User');
|
2015-01-11 06:59:24 +00:00
|
|
|
|
2015-01-11 05:45:37 +00:00
|
|
|
/**
|
|
|
|
* Bonfire controller
|
|
|
|
*/
|
2015-01-22 02:32:13 +00:00
|
|
|
|
2015-01-23 08:30:34 +00:00
|
|
|
var highestBonfireNumber = 1;
|
2015-01-22 02:32:13 +00:00
|
|
|
|
2015-01-11 06:59:24 +00:00
|
|
|
exports.index = function(req, res) {
|
2015-01-22 02:32:13 +00:00
|
|
|
res.render('bonfire/bonfire.jade', {
|
|
|
|
title: 'Learn to code with Bonfire'
|
|
|
|
});
|
|
|
|
|
|
|
|
Bonfire.find({}, null, { sort: { bonfireNumber: 1 } }, function(err, c) {
|
|
|
|
if (err) {
|
|
|
|
debug('bonfire err: ', err);
|
|
|
|
next(err);
|
|
|
|
}
|
|
|
|
});
|
2015-01-16 23:58:27 +00:00
|
|
|
};
|
|
|
|
|
2015-01-22 02:32:13 +00:00
|
|
|
exports.returnBonfire = function(req, res, next) {
|
|
|
|
var bonfireNumber = parseInt(req.params.bonfireNumber) || 0;
|
|
|
|
var verbs = [
|
|
|
|
'ACED',
|
|
|
|
'NAILED',
|
|
|
|
'ROCKED',
|
|
|
|
'SCORCHED',
|
|
|
|
'DEVASTATED',
|
|
|
|
'OWNED',
|
|
|
|
'CRUSHED',
|
|
|
|
'CONQUERED',
|
|
|
|
'KILLED',
|
|
|
|
'SHREDDED',
|
|
|
|
'ANNIHILATED',
|
|
|
|
'NUKED'
|
|
|
|
];
|
|
|
|
var phrases = [
|
|
|
|
"Shout it from on top of a mountain",
|
|
|
|
"Tell everyone and their dogs",
|
|
|
|
"Show them. Show them all!",
|
|
|
|
"Inspire your friends",
|
|
|
|
"Tell the world of your greatness",
|
|
|
|
"Look accomplished on social media",
|
|
|
|
"Share news of your grand endeavor",
|
|
|
|
"Establish your alibi for the past two hours",
|
|
|
|
"Prove to mom that computers aren't just for games"
|
|
|
|
];
|
2015-01-22 18:20:46 +00:00
|
|
|
|
2015-01-24 22:29:50 +00:00
|
|
|
|
|
|
|
// This code is in bad need of refactoring
|
|
|
|
var bonfiresToFind = req.user.bonfiresHash;
|
|
|
|
var bonfiresArray = _.map(bonfiresToFind, function(value, index) {
|
|
|
|
return [index, value];
|
|
|
|
});
|
|
|
|
// Get rid of the first entry, which will be a useless function that causes an error.
|
|
|
|
bonfiresArray.shift();
|
|
|
|
unsolvedBonfires = [];
|
|
|
|
for (i = 0; i < bonfiresArray.length; i++) {
|
|
|
|
if (bonfiresArray[i][1]["completedDate"] === 0) {
|
|
|
|
unsolvedBonfires.push(bonfiresArray[i][0])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//.where('likes').in(['vaporizing', 'talking'])
|
|
|
|
var displayedBonfires = Bonfire.find({}).where('_id').in(unsolvedBonfires).sort({ difficulty: 1 });
|
|
|
|
displayedBonfires.exec(function(err, bonfire) {
|
|
|
|
if (err) {
|
|
|
|
next(err);
|
|
|
|
}
|
|
|
|
res.render('bonfire/show', {
|
|
|
|
completedWith: null,
|
|
|
|
title: bonfire[bonfireNumber].name,
|
|
|
|
name: bonfire[bonfireNumber].name,
|
|
|
|
number: bonfire[bonfireNumber].bonfireNumber,
|
|
|
|
difficulty: bonfire[bonfireNumber].difficulty,
|
2015-01-25 01:49:59 +00:00
|
|
|
brief: bonfire[bonfireNumber].description[0],
|
|
|
|
details: bonfire[bonfireNumber].description.slice(1),
|
2015-01-24 22:29:50 +00:00
|
|
|
tests: bonfire[bonfireNumber].tests,
|
|
|
|
challengeSeed: bonfire[bonfireNumber].challengeSeed,
|
|
|
|
challengeEntryPoint: bonfire[bonfireNumber].challengeEntryPoint,
|
|
|
|
cc: req.user ? req.user.bonfiresHash : undefined,
|
|
|
|
points: req.user ? req.user.points : undefined,
|
|
|
|
verb: verbs[Math.floor(Math.random() * verbs.length)],
|
|
|
|
phrase: phrases[Math.floor(Math.random() * phrases.length)],
|
|
|
|
bonfires: bonfire,
|
|
|
|
bonfireHash: bonfire[bonfireNumber]._id
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.returnIndividualBonfire = function(req, res, next) {
|
|
|
|
var bonfireNumber = parseInt(req.params.bonfireNumber) || 0;
|
|
|
|
var verbs = [
|
|
|
|
'ACED',
|
|
|
|
'NAILED',
|
|
|
|
'ROCKED',
|
|
|
|
'SCORCHED',
|
|
|
|
'DEVASTATED',
|
|
|
|
'OWNED',
|
|
|
|
'CRUSHED',
|
|
|
|
'CONQUERED',
|
|
|
|
'KILLED',
|
|
|
|
'SHREDDED',
|
|
|
|
'ANNIHILATED',
|
|
|
|
'NUKED'
|
|
|
|
];
|
|
|
|
var phrases = [
|
|
|
|
"Shout it from on top of a mountain",
|
|
|
|
"Tell everyone and their dogs",
|
|
|
|
"Show them. Show them all!",
|
|
|
|
"Inspire your friends",
|
|
|
|
"Tell the world of your greatness",
|
|
|
|
"Look accomplished on social media",
|
|
|
|
"Share news of your grand endeavor",
|
|
|
|
"Establish your alibi for the past two hours",
|
|
|
|
"Prove to mom that computers aren't just for games"
|
|
|
|
];
|
|
|
|
|
|
|
|
|
2015-01-22 02:32:13 +00:00
|
|
|
if (bonfireNumber > highestBonfireNumber) { bonfireNumber = 0; }
|
2015-01-24 22:29:50 +00:00
|
|
|
Bonfire.find({}, null, { sort: { bonfireNumber: 1 } }, function(err, bonfire) {
|
2015-01-22 02:32:13 +00:00
|
|
|
if (err) {
|
|
|
|
next(err);
|
|
|
|
}
|
2015-01-22 18:20:46 +00:00
|
|
|
res.render('bonfire/show', {
|
2015-01-24 08:11:01 +00:00
|
|
|
completedWith: null,
|
2015-01-22 18:20:46 +00:00
|
|
|
title: bonfire[bonfireNumber].name,
|
|
|
|
name: bonfire[bonfireNumber].name,
|
|
|
|
number: bonfire[bonfireNumber].bonfireNumber,
|
|
|
|
difficulty: bonfire[bonfireNumber].difficulty,
|
2015-01-25 01:49:59 +00:00
|
|
|
brief: bonfire[bonfireNumber].description[0],
|
|
|
|
details: bonfire[bonfireNumber].description.slice(1),
|
2015-01-24 05:44:08 +00:00
|
|
|
tests: bonfire[bonfireNumber].tests,
|
2015-01-22 18:20:46 +00:00
|
|
|
challengeSeed: bonfire[bonfireNumber].challengeSeed,
|
|
|
|
challengeEntryPoint: bonfire[bonfireNumber].challengeEntryPoint,
|
2015-01-24 05:44:08 +00:00
|
|
|
cc: req.user ? req.user.bonfiresHash : undefined,
|
|
|
|
points: req.user ? req.user.points : undefined,
|
|
|
|
verb: verbs[Math.floor(Math.random() * verbs.length)],
|
|
|
|
phrase: phrases[Math.floor(Math.random() * phrases.length)],
|
2015-01-24 08:11:01 +00:00
|
|
|
bonfires: bonfire,
|
|
|
|
bonfireHash: bonfire[bonfireNumber]._id
|
2015-01-22 02:32:13 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|