remove poormanscron() from refresh for now, only in setInterval

This commit is contained in:
Tyler Renelle
2012-08-06 12:34:54 -04:00
parent a341ff9763
commit 6d204fb08c
4 changed files with 16 additions and 17 deletions

View File

@@ -290,21 +290,18 @@ ready(function(model) {
return model.set('_items.weapon', content.items.weapon[1]); return model.set('_items.weapon', content.items.weapon[1]);
}; };
exports.poormanscron = poormanscron = function() { exports.poormanscron = poormanscron = function() {
var daysPassed, lastCron, n, today, _k, _results; var daysPassed, lastCron, n, today, _k;
today = new Date(); today = new Date();
model.setNull('_user.lastCron', today); model.setNull('_user.lastCron', today);
lastCron = model.get('_user.lastCron'); lastCron = model.get('_user.lastCron');
daysPassed = helpers.daysBetween(lastCron, today); daysPassed = helpers.daysBetween(lastCron, today);
if (daysPassed > 0) { if (daysPassed > 0) {
model.set('_user.lastCron', today);
_results = [];
for (n = _k = 1; 1 <= daysPassed ? _k <= daysPassed : _k >= daysPassed; n = 1 <= daysPassed ? ++_k : --_k) { for (n = _k = 1; 1 <= daysPassed ? _k <= daysPassed : _k >= daysPassed; n = 1 <= daysPassed ? ++_k : --_k) {
_results.push(scoring.tally(model)); scoring.tally(model);
} }
return _results; return model.set('_user.lastCron', today);
} }
}; };
poormanscron();
setInterval((function() { setInterval((function() {
return poormanscron(); return poormanscron();
}), 3600000); }), 3600000);

View File

@@ -1,5 +1,5 @@
// Generated by CoffeeScript 1.3.3 // Generated by CoffeeScript 1.3.3
var content, expModifier, hpModifier, score, tally, updateStats; var content, expModifier, hpModifier, updateStats;
content = require('./content'); content = require('./content');
@@ -55,7 +55,7 @@ updateStats = function(user, stats) {
} }
}; };
module.exports.score = score = function(spec) { module.exports.score = function(spec) {
var adjustvalue, cron, delta, direction, exp, hp, lvl, money, sign, task, type, user, value, _ref, _ref1; var adjustvalue, cron, delta, direction, exp, hp, lvl, money, sign, task, type, user, value, _ref, _ref1;
if (spec == null) { if (spec == null) {
spec = { spec = {
@@ -108,7 +108,7 @@ module.exports.score = score = function(spec) {
return delta; return delta;
}; };
module.exports.tally = tally = function(model) { module.exports.tally = function(model) {
var absVal, completed, expTally, key, lvl, task, todoTally, type, user, value, _ref; var absVal, completed, expTally, key, lvl, task, todoTally, type, user, value, _ref;
user = model.at('_user'); user = model.at('_user');
todoTally = 0; todoTally = 0;
@@ -117,7 +117,7 @@ module.exports.tally = tally = function(model) {
_ref = [task.get('type'), task.get('value'), task.get('completed')], type = _ref[0], value = _ref[1], completed = _ref[2]; _ref = [task.get('type'), task.get('value'), task.get('completed')], type = _ref[0], value = _ref[1], completed = _ref[2];
if (type === 'todo' || type === 'daily') { if (type === 'todo' || type === 'daily') {
if (!completed) { if (!completed) {
score({ module.exports.score({
user: user, user: user,
task: task, task: task,
direction: 'down', direction: 'down',

View File

@@ -236,16 +236,18 @@ ready (model) ->
# ========== CRON ========== # ========== CRON ==========
#TODO: remove when cron implemented #TODO: remove when cron implemented
exports.poormanscron = poormanscron = -> exports.poormanscron = poormanscron = () ->
today = new Date() today = new Date()
model.setNull('_user.lastCron', today) model.setNull('_user.lastCron', today)
lastCron = model.get('_user.lastCron') lastCron = model.get('_user.lastCron')
daysPassed = helpers.daysBetween(lastCron, today) daysPassed = helpers.daysBetween(lastCron, today)
if daysPassed > 0 if daysPassed > 0
model.set('_user.lastCron', today) # reset cron
for n in [1..daysPassed] for n in [1..daysPassed]
scoring.tally(model) scoring.tally(model)
poormanscron() # Run once on refresh model.set('_user.lastCron', today) # reset cron
## FIXME scoring.tally isn't working for calling poormanscron() on refresh, but does
## for setInterval & button-click -- what's going on?
# poormanscron() # Run once on refresh
setInterval (-> # Then run once every hour setInterval (-> # Then run once every hour
poormanscron() poormanscron()
), 3600000 ), 3600000

View File

@@ -48,7 +48,7 @@ updateStats = (user, stats) ->
money = 0.0 if (!money? or money<0) money = 0.0 if (!money? or money<0)
user.set 'stats.money', stats.money user.set 'stats.money', stats.money
module.exports.score = score = (spec = {user:null, task:null, direction:null, cron:null}) -> module.exports.score = (spec = {user:null, task:null, direction:null, cron:null}) ->
# console.log spec, "scoring.coffee: score( ->spec<- )" # console.log spec, "scoring.coffee: score( ->spec<- )"
[user, task, direction, cron] = [spec.user, spec.task, spec.direction, spec.cron] [user, task, direction, cron] = [spec.user, spec.task, spec.direction, spec.cron]
@@ -98,7 +98,7 @@ module.exports.score = score = (spec = {user:null, task:null, direction:null, cr
# At end of day, add value to all incomplete Daily & Todo tasks (further incentive) # At end of day, add value to all incomplete Daily & Todo tasks (further incentive)
# For incomplete Dailys, deduct experience # For incomplete Dailys, deduct experience
module.exports.tally = tally = (model) -> module.exports.tally = (model) ->
# users = model.at('users') #TODO this isn't working, iterate over all users # users = model.at('users') #TODO this isn't working, iterate over all users
# for user in users # for user in users
user = model.at '_user' user = model.at '_user'
@@ -109,7 +109,7 @@ module.exports.tally = tally = (model) ->
if type in ['todo', 'daily'] if type in ['todo', 'daily']
# Deduct experience for missed Daily tasks, # Deduct experience for missed Daily tasks,
# but not for Todos (just increase todo's value) # but not for Todos (just increase todo's value)
score({user:user, task:task, direction:'down', cron:true}) unless completed module.exports.score({user:user, task:task, direction:'down', cron:true}) unless completed
if type == 'daily' if type == 'daily'
task.push "history", { date: new Date(), value: value } task.push "history", { date: new Date(), value: value }
else else