use 'passed' parameter to ignore *.completed on cron

This commit is contained in:
Tyler Renelle
2012-07-27 21:56:21 -04:00
parent b9a9239bbd
commit 33c5acf5ec
4 changed files with 168 additions and 13 deletions
+3 -2
View File
@@ -164,11 +164,12 @@ ready (model) ->
# @render()
# return false
model.on 'set', '_user.tasks.*.completed', (i, completed, previous, isLocal) ->
model.on 'set', '_user.tasks.*.completed', (i, completed, previous, isLocal, passed) ->
return if passed.cron? # Don't do this stuff on cron
direction = () ->
return 'up' if completed==true and previous == false
return 'down' if completed==false and previous == true
console.error 'Error: direction neither "up" nor "down" on checkbox set.'
throw new Error("Direction neither 'up' nor 'down' on checkbox set.")
# Score the user based on todo task
task = model.at("_user.tasks.#{i}")
+3 -9
View File
@@ -49,6 +49,7 @@ updateStats = (user, stats) ->
user.set 'stats.money', stats.money
exports.score = score = (spec = {user:null, task:null, direction:null, cron:null}) ->
# console.log spec, "scoring.coffee: score( ->spec<- )"
[user, task, direction, cron] = [spec.user, spec.task, spec.direction, spec.cron]
# For negative values, use a line: something like y=-.1x+1
@@ -66,17 +67,10 @@ exports.score = score = (spec = {user:null, task:null, direction:null, cron:null
adjustvalue = false
value += delta if adjustvalue
# # up/down -voting as checkbox & assigning as completed, 2 birds one stone
# completed = task.get("completed")
# if type != 'habit'
# completed = true if direction=="up"
# completed = false if direction=="down"
# else
if type == 'habit'
# Add habit value to habit-history (if different)
task.push 'history', { date: new Date(), value: value } if task.get('value') != value
task.set('value', value)
# task.set('completed', completed)
# Update the user's status
[money, hp, exp, lvl] = [user.get('stats.money'), user.get('stats.hp'), user.get('stats.exp'), user.get('stats.lvl')]
@@ -91,7 +85,7 @@ exports.score = score = (spec = {user:null, task:null, direction:null, cron:null
# Add points to exp & money if positive delta
# Only take away mony if it was a mistake (aka, a checkbox)
if delta > 0 or ( type in ['daily', 'todo'] and !cron )
if (delta > 0 or ( type in ['daily', 'todo'])) and !cron
exp += expModifier(user, delta)
money += delta
# Deduct from health (rewards case handled above)
@@ -121,7 +115,7 @@ exports.tally = tally = (model) ->
else
absVal = if (completed) then Math.abs(value) else value
todoTally += absVal
task.set('completed', false) if type == 'daily'
task.pass({cron:true}).set('completed', false) if type == 'daily'
model.push '_user.history.todos', { date: new Date(), value: todoTally }
# tally experience