Refactor random verbs, phrases, and compliments so that only the resources controller is concerned with how to fetch them and how to make them randomly. Remove debug statement from bonfire/show.jade

This commit is contained in:
Nathan Leniz
2015-01-25 10:02:41 -05:00
parent 0e63521ee0
commit d886a77858
4 changed files with 28 additions and 46 deletions

View File

@ -2,16 +2,13 @@ var _ = require('lodash'),
debug = require('debug')('freecc:cntr:bonfires'), debug = require('debug')('freecc:cntr:bonfires'),
Bonfire = require('./../models/Bonfire'), Bonfire = require('./../models/Bonfire'),
User = require('./../models/User'), User = require('./../models/User'),
resources = require('./resources.json'), resources = require('./resources');
phrases = resources.phrases,
verbs = resources.verbs,
compliments = resources.compliments;
/** /**
* Bonfire controller * Bonfire controller
*/ */
var highestBonfireNumber = 1; var highestBonfireNumber = 2;
exports.index = function(req, res) { exports.index = function(req, res) {
res.render('bonfire/bonfire.jade', { res.render('bonfire/bonfire.jade', {
@ -61,9 +58,9 @@ exports.returnBonfire = function(req, res, next) {
challengeEntryPoint: bonfire[bonfireNumber].challengeEntryPoint, challengeEntryPoint: bonfire[bonfireNumber].challengeEntryPoint,
cc: req.user ? req.user.bonfiresHash : undefined, cc: req.user ? req.user.bonfiresHash : undefined,
points: req.user ? req.user.points : undefined, points: req.user ? req.user.points : undefined,
verb: verbs[Math.floor(Math.random() * verbs.length)], verb: resources.randomVerb(),
phrase: phrases[Math.floor(Math.random() * phrases.length)], phrase: resources.randomPhrase(),
compliments: compliments[Math.floor(Math.random() * phrases.length)], compliments: resources.randomCompliment(),
bonfires: bonfire, bonfires: bonfire,
bonfireHash: bonfire[bonfireNumber]._id bonfireHash: bonfire[bonfireNumber]._id
}); });
@ -72,32 +69,6 @@ exports.returnBonfire = function(req, res, next) {
exports.returnIndividualBonfire = function(req, res, next) { exports.returnIndividualBonfire = function(req, res, next) {
var bonfireNumber = parseInt(req.params.bonfireNumber) || 0; 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"
];
if (bonfireNumber > highestBonfireNumber) { bonfireNumber = 0; } if (bonfireNumber > highestBonfireNumber) { bonfireNumber = 0; }
Bonfire.find({}, null, { sort: { bonfireNumber: 1 } }, function(err, bonfire) { Bonfire.find({}, null, { sort: { bonfireNumber: 1 } }, function(err, bonfire) {
@ -117,9 +88,9 @@ exports.returnIndividualBonfire = function(req, res, next) {
challengeEntryPoint: bonfire[bonfireNumber].challengeEntryPoint, challengeEntryPoint: bonfire[bonfireNumber].challengeEntryPoint,
cc: req.user ? req.user.bonfiresHash : undefined, cc: req.user ? req.user.bonfiresHash : undefined,
points: req.user ? req.user.points : undefined, points: req.user ? req.user.points : undefined,
verb: verbs[Math.floor(Math.random() * verbs.length)], verb: resources.randomVerb(),
phrase: phrases[Math.floor(Math.random() * phrases.length)], phrase: resources.randomPhrase(),
compliment: compliments[Math.floor(Math.random() * phrases.length)], compliment: resources.randomCompliment(),
bonfires: bonfire, bonfires: bonfire,
bonfireHash: bonfire[bonfireNumber]._id bonfireHash: bonfire[bonfireNumber]._id
}); });

View File

@ -5,10 +5,7 @@
var _ = require('lodash'), var _ = require('lodash'),
debug = require('debug')('freecc:cntr:challenges'), debug = require('debug')('freecc:cntr:challenges'),
Challenge = require('./../models/Challenge'), Challenge = require('./../models/Challenge'),
resources = require('./resources.json'), resources = require('./resources');
phrases = resources.phrases,
verbs = resources.verbs,
compliments = resources.compliments;
var highestChallengeNumber = 53; var highestChallengeNumber = 53;
@ -29,9 +26,9 @@ exports.returnChallenge = function(req, res, next) {
number: challengeNumber, number: challengeNumber,
cc: req.user ? req.user.challengesHash : undefined, cc: req.user ? req.user.challengesHash : undefined,
points: req.user ? req.user.points : undefined, points: req.user ? req.user.points : undefined,
verb: verbs[Math.floor(Math.random() * verbs.length)], verb: resources.randomVerb(),
compliment: compliments[Math.floor(Math.random() * compliments.length)], phrase: resources.randomPhrase(),
phrase: phrases[Math.floor(Math.random() * phrases.length)], compliment: resources.randomCompliment(),
challenges: c challenges: c
}); });
}); });

View File

@ -167,6 +167,21 @@ module.exports = {
}); });
}); });
}); });
},
randomPhrase: function() {
var phrases = resources.phrases;
return phrases[Math.floor(Math.random() * phrases.length)];
},
randomVerb: function() {
var verbs = resources.verbs;
return verbs[Math.floor(Math.random() * verbs.length)];
},
randomCompliment: function() {
var compliments = resources.compliments;
return compliments[Math.floor(Math.random() * compliments.length)];
} }
}; };

View File

@ -60,7 +60,6 @@ block content
var challengeSeed = !{JSON.stringify(challengeSeed)}; var challengeSeed = !{JSON.stringify(challengeSeed)};
var challengeEntryPoint = !{JSON.stringify(challengeEntryPoint)}; var challengeEntryPoint = !{JSON.stringify(challengeEntryPoint)};
var passedBonfireHash = !{JSON.stringify(bonfireHash)}; var passedBonfireHash = !{JSON.stringify(bonfireHash)};
console.log(passedBonfireHash);
script(src='/js/lib/bonfire/bonfireFramework.js') script(src='/js/lib/bonfire/bonfireFramework.js')