better defaultTasks implementation

This commit is contained in:
Tyler Renelle 2012-07-17 15:45:05 -04:00
parent 4261ff82c7
commit bc6b30ee5a
4 changed files with 104 additions and 100 deletions

View file

@ -1,78 +1,64 @@
// Generated by CoffeeScript 1.3.3
module.exports = {
defaultTasks: {
tasks: {
'0': {
type: 'habit',
text: '1h Productive Work',
notes: '<u>Habits: Constantly Track</u><br/>For some habits, it only makes sense to <b>gain</b> points (like this one).',
value: 0,
up: true,
down: false
},
'1': {
type: 'habit',
text: 'Eat Junk Food',
notes: 'For others, it only makes sense to <b>lose</b> points',
value: 0,
up: false,
down: true
},
'2': {
type: 'habit',
text: 'Take The Stairs',
notes: 'For the rest, both + and - make sense (stairs = gain, elevator = lose)',
value: 0,
up: true,
down: true
},
'3': {
type: 'daily',
text: '1h Personal Project',
notes: '<u>Dailies: Complete Once a Day</u><br/>At the end of each day, non-completed Dailies dock you points.',
value: 0,
completed: false
},
'4': {
type: 'daily',
text: 'Exercise',
notes: "If you are doing well, they turn green and are less valuable (experience, gold) and less damaging (HP). This means you can ease up on them for a bit.",
value: 3,
completed: false
},
'5': {
type: 'daily',
text: '45m Reading',
notes: 'But if you are doing poorly, they turn red. The worse you do, the more valuable (exp, gold) and more damaging (HP) these goals become. This encourages you to focus on your shortcomings, the reds.',
value: -10,
completed: false
},
'6': {
type: 'todo',
text: 'Call Mom',
notes: "<u>Todos: Complete Eventually</u><br/>Non-completed Todos won't hurt you, but they will become more valuable over time. This will encourage you to wrap up stale Todos.",
value: -3,
completed: false
},
'7': {
type: 'reward',
text: '1 Episode of Game of Thrones',
notes: '<u>Rewards: Treat Yourself!</u><br/>As you complete goals, you earn gold to buy rewards. Buy them liberally - rewards are integral in forming good habits.',
value: 20
},
'8': {
type: 'reward',
text: 'Cake',
notes: 'But only buy if you have enough gold - you lose HP otherwise.',
value: 10
}
},
habitIds: ['0', '1', '2'],
dailyIds: ['3', '4', '5'],
todoIds: ['6'],
rewardIds: ['7', '8']
},
defaultTasks: [
{
type: 'habit',
text: '1h Productive Work',
notes: '<u>Habits: Constantly Track</u><br/>For some habits, it only makes sense to <b>gain</b> points (like this one).',
value: 0,
up: true,
down: false
}, {
type: 'habit',
text: 'Eat Junk Food',
notes: 'For others, it only makes sense to <b>lose</b> points',
value: 0,
up: false,
down: true
}, {
type: 'habit',
text: 'Take The Stairs',
notes: 'For the rest, both + and - make sense (stairs = gain, elevator = lose)',
value: 0,
up: true,
down: true
}, {
type: 'daily',
text: '1h Personal Project',
notes: '<u>Dailies: Complete Once a Day</u><br/>At the end of each day, non-completed Dailies dock you points.',
value: 0,
completed: false
}, {
type: 'daily',
text: 'Exercise',
notes: "If you are doing well, they turn green and are less valuable (experience, gold) and less damaging (HP). This means you can ease up on them for a bit.",
value: 3,
completed: false
}, {
type: 'daily',
text: '45m Reading',
notes: 'But if you are doing poorly, they turn red. The worse you do, the more valuable (exp, gold) and more damaging (HP) these goals become. This encourages you to focus on your shortcomings, the reds.',
value: -10,
completed: false
}, {
type: 'todo',
text: 'Call Mom',
notes: "<u>Todos: Complete Eventually</u><br/>Non-completed Todos won't hurt you, but they will become more valuable over time. This will encourage you to wrap up stale Todos.",
value: -3,
completed: false
}, {
type: 'reward',
text: '1 Episode of Game of Thrones',
notes: '<u>Rewards: Treat Yourself!</u><br/>As you complete goals, you earn gold to buy rewards. Buy them liberally - rewards are integral in forming good habits.',
value: 20
}, {
type: 'reward',
text: 'Cake',
notes: 'But only buy if you have enough gold - you lose HP otherwise.',
value: 10
}
],
tourSteps: [
{
element: "#avatar",

View file

@ -84,7 +84,7 @@ get('/:userId?', function(page, model, _arg) {
var userId;
userId = _arg.userId;
return model.subscribe("users", function(err, users) {
var newUser, user;
var guid, newUser, task, user, _i, _len, _ref1;
userId = model.get('_userId');
debug(userId, 'model.get _userId');
if (model.get("users." + userId)) {
@ -102,12 +102,31 @@ get('/:userId?', function(page, model, _arg) {
armor: 0,
weapon: 0
},
tasks: content.defaultTasks.tasks,
habitIds: content.defaultTasks.habitIds,
dailyIds: content.defaultTasks.dailyIds,
todoIds: content.defaultTasks.todoIds,
rewardIds: content.defaultTasks.rewardIds
tasks: {},
habitIds: [],
dailyIds: [],
todoIds: [],
rewardIds: []
};
_ref1 = content.defaultTasks;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
task = _ref1[_i];
guid = Guid.raw();
newUser.tasks[guid] = task;
switch (task.type) {
case 'habit':
newUser.habitIds.push(guid);
break;
case 'daily':
newUser.dailyIds.push(guid);
break;
case 'todo':
newUser.todoIds.push(guid);
break;
case 'reward':
newUser.rewardIds.push(guid);
}
}
users.set(userId, newUser, function(err, path, value) {
return debug({
err: err,

View file

@ -1,20 +1,16 @@
module.exports = {
defaultTasks:
tasks:
'0': {type: 'habit', text: '1h Productive Work', notes: '<u>Habits: Constantly Track</u><br/>For some habits, it only makes sense to <b>gain</b> points (like this one).', value: 0, up: true, down: false }
'1': {type: 'habit', text: 'Eat Junk Food', notes: 'For others, it only makes sense to <b>lose</b> points', value: 0, up: false, down: true}
'2': {type: 'habit', text: 'Take The Stairs', notes: 'For the rest, both + and - make sense (stairs = gain, elevator = lose)', value: 0, up: true, down: true}
'3': {type: 'daily', text: '1h Personal Project', notes: '<u>Dailies: Complete Once a Day</u><br/>At the end of each day, non-completed Dailies dock you points.', value: 0, completed: false }
'4': {type: 'daily', text: 'Exercise', notes: "If you are doing well, they turn green and are less valuable (experience, gold) and less damaging (HP). This means you can ease up on them for a bit.", value: 3, completed: false }
'5': {type: 'daily', text: '45m Reading', notes: 'But if you are doing poorly, they turn red. The worse you do, the more valuable (exp, gold) and more damaging (HP) these goals become. This encourages you to focus on your shortcomings, the reds.', value: -10, completed: false }
'6': {type: 'todo', text: 'Call Mom', notes: "<u>Todos: Complete Eventually</u><br/>Non-completed Todos won't hurt you, but they will become more valuable over time. This will encourage you to wrap up stale Todos.", value: -3, completed: false }
'7': {type: 'reward', text: '1 Episode of Game of Thrones', notes: '<u>Rewards: Treat Yourself!</u><br/>As you complete goals, you earn gold to buy rewards. Buy them liberally - rewards are integral in forming good habits.', value: 20 }
'8': {type: 'reward', text: 'Cake', notes: 'But only buy if you have enough gold - you lose HP otherwise.', value: 10 }
habitIds: ['0','1','2']
dailyIds: ['3','4','5']
todoIds: ['6']
rewardIds: ['7','8']
defaultTasks: [
{type: 'habit', text: '1h Productive Work', notes: '<u>Habits: Constantly Track</u><br/>For some habits, it only makes sense to <b>gain</b> points (like this one).', value: 0, up: true, down: false }
{type: 'habit', text: 'Eat Junk Food', notes: 'For others, it only makes sense to <b>lose</b> points', value: 0, up: false, down: true}
{type: 'habit', text: 'Take The Stairs', notes: 'For the rest, both + and - make sense (stairs = gain, elevator = lose)', value: 0, up: true, down: true}
{type: 'daily', text: '1h Personal Project', notes: '<u>Dailies: Complete Once a Day</u><br/>At the end of each day, non-completed Dailies dock you points.', value: 0, completed: false }
{type: 'daily', text: 'Exercise', notes: "If you are doing well, they turn green and are less valuable (experience, gold) and less damaging (HP). This means you can ease up on them for a bit.", value: 3, completed: false }
{type: 'daily', text: '45m Reading', notes: 'But if you are doing poorly, they turn red. The worse you do, the more valuable (exp, gold) and more damaging (HP) these goals become. This encourages you to focus on your shortcomings, the reds.', value: -10, completed: false }
{type: 'todo', text: 'Call Mom', notes: "<u>Todos: Complete Eventually</u><br/>Non-completed Todos won't hurt you, but they will become more valuable over time. This will encourage you to wrap up stale Todos.", value: -3, completed: false }
{type: 'reward', text: '1 Episode of Game of Thrones', notes: '<u>Rewards: Treat Yourself!</u><br/>As you complete goals, you earn gold to buy rewards. Buy them liberally - rewards are integral in forming good habits.', value: 20 }
{type: 'reward', text: 'Cake', notes: 'But only buy if you have enough gold - you lose HP otherwise.', value: 10 }
]
tourSteps: [
{
element: "#avatar"

View file

@ -70,13 +70,16 @@ get '/:userId?', (page, model, {userId}) ->
newUser = {
stats: { money: 0, exp: 0, lvl: 1, hp: 50 }
items: { itemsEnabled: false, armor: 0, weapon: 0 }
tasks: content.defaultTasks.tasks
habitIds: content.defaultTasks.habitIds
dailyIds: content.defaultTasks.dailyIds
todoIds: content.defaultTasks.todoIds
rewardIds: content.defaultTasks.rewardIds
tasks: {}, habitIds: [], dailyIds: [], todoIds: [], rewardIds: []
}
for task in content.defaultTasks
guid = Guid.raw()
newUser.tasks[guid] = task
switch task.type
when 'habit' then newUser.habitIds.push guid
when 'daily' then newUser.dailyIds.push guid
when 'todo' then newUser.todoIds.push guid
when 'reward' then newUser.rewardIds.push guid
users.set userId, newUser, (err, path, value) ->
debug {err:err, path:path, value:value}, 'new user'