move scoring functions around
Conflicts: lib/app/index.js src/app/index.coffee
This commit is contained in:
+5
-23
@@ -52,7 +52,7 @@ get('/:uidParam?', function(page, model, _arg, next) {
|
||||
});
|
||||
|
||||
ready(function(model) {
|
||||
var poormanscron, setupSortable, step, tour, type, _i, _j, _len, _len1, _ref1, _ref2;
|
||||
var setupSortable, step, tour, type, _i, _j, _len, _len1, _ref1, _ref2;
|
||||
scoring.setUser(model.at('_user'));
|
||||
$('[rel=tooltip]').tooltip();
|
||||
$('[rel=popover]').popover();
|
||||
@@ -280,8 +280,8 @@ ready(function(model) {
|
||||
return user.set('stats.hp', hp);
|
||||
}
|
||||
};
|
||||
exports.vote = function(e, el, next) {
|
||||
var direction, task, user;
|
||||
exports.score = function(e, el, next) {
|
||||
var direction, task;
|
||||
direction = $(el).attr('data-direction');
|
||||
if (direction === 'true/') {
|
||||
direction = 'up';
|
||||
@@ -289,7 +289,6 @@ ready(function(model) {
|
||||
if (direction === 'false/') {
|
||||
direction = 'down';
|
||||
}
|
||||
user = model.at('_user');
|
||||
task = model.at($(el).parents('li')[0]);
|
||||
return scoring.score({
|
||||
task: task,
|
||||
@@ -309,24 +308,7 @@ ready(function(model) {
|
||||
model.set('_items.weapon', content.items.weapon[1]);
|
||||
return model.set('_user.balance', model.get('_user.balance') - 0.50);
|
||||
};
|
||||
exports.poormanscron = poormanscron = function() {
|
||||
var daysPassed, lastCron, today;
|
||||
today = new Date();
|
||||
model.setNull('_user.lastCron', today);
|
||||
lastCron = model.get('_user.lastCron');
|
||||
daysPassed = helpers.daysBetween(lastCron, today);
|
||||
if (daysPassed > 0) {
|
||||
model.set('_user.lastCron', today);
|
||||
return _(daysPassed).times(function(n) {
|
||||
var tallyFor;
|
||||
tallyFor = moment(lastCron).add('d', n);
|
||||
return scoring.tally(tallyFor);
|
||||
});
|
||||
}
|
||||
};
|
||||
setTimeout(poormanscron, 2000);
|
||||
setInterval(poormanscron, 3600000);
|
||||
return exports.endOfDayTally = function(e, el) {
|
||||
return scoring.tally();
|
||||
setTimeout(scoring.cron, 2000);
|
||||
setInterval(scoring.cron, 3600000);
|
||||
};
|
||||
});
|
||||
|
||||
+31
-6
@@ -1,16 +1,18 @@
|
||||
// Generated by CoffeeScript 1.3.3
|
||||
var MODIFIER, content, expModifier, hpModifier, score, statsNotification, updateStats, user;
|
||||
var MODIFIER, content, cron, expModifier, helpers, hpModifier, score, setUser, statsNotification, tally, updateStats, user;
|
||||
|
||||
content = require('./content');
|
||||
|
||||
helpers = require('./helpers');
|
||||
|
||||
MODIFIER = .03;
|
||||
|
||||
user = void 0;
|
||||
|
||||
module.exports.setUser = function(u) {
|
||||
setUser = function(u) {
|
||||
return user = u;
|
||||
};
|
||||
|
||||
module.exports.MODIFIER = MODIFIER = .03;
|
||||
|
||||
statsNotification = function(html, type) {
|
||||
if (user.get('stats.lvl') === 0) {
|
||||
return;
|
||||
@@ -85,7 +87,7 @@ updateStats = function(stats) {
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.score = score = function(spec) {
|
||||
score = function(spec) {
|
||||
var adjustvalue, cron, delta, direction, exp, hp, lvl, modified, money, num, sign, task, type, value, _ref, _ref1, _ref2;
|
||||
if (spec == null) {
|
||||
spec = {
|
||||
@@ -165,7 +167,23 @@ module.exports.score = score = function(spec) {
|
||||
return delta;
|
||||
};
|
||||
|
||||
module.exports.tally = function(momentDate) {
|
||||
cron = function() {
|
||||
var daysPassed, lastCron, today;
|
||||
today = new Date();
|
||||
user.setNull('lastCron', today);
|
||||
lastCron = user.get('lastCron');
|
||||
daysPassed = helpers.daysBetween(lastCron, today);
|
||||
if (daysPassed > 0) {
|
||||
user.set('lastCron', today);
|
||||
return _(daysPassed).times(function(n) {
|
||||
var tallyFor;
|
||||
tallyFor = moment(lastCron).add('d', n);
|
||||
return tally(tallyFor);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
tally = function(momentDate) {
|
||||
var expTally, lvl, todoTally;
|
||||
todoTally = 0;
|
||||
_.each(user.get('tasks'), function(taskObj, taskId, list) {
|
||||
@@ -227,3 +245,10 @@ module.exports.tally = function(momentDate) {
|
||||
value: expTally
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
MODIFIER: MODIFIER,
|
||||
setUser: setUser,
|
||||
score: score,
|
||||
cron: cron
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user