Closer to getting initial contentn imported properly

This commit is contained in:
Tyler Renelle 2012-07-17 15:33:08 -04:00
parent 036badb3e4
commit 4261ff82c7
4 changed files with 86 additions and 112 deletions

View file

@ -2,73 +2,76 @@
module.exports = {
defaultTasks: {
habits: [
{
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
}
],
dailys: [
{
},
'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
}
],
todos: [
{
},
'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
}
],
rewards: [
{
},
'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']
},
tourSteps: [
{

View file

@ -1,5 +1,5 @@
// Generated by CoffeeScript 1.3.3
var Guid, content, debug, derby, get, getRoom, ready, view, _ref;
var Guid, content, debug, derby, get, ready, view, _ref;
derby = require('derby');
@ -84,73 +84,57 @@ get('/:userId?', function(page, model, _arg) {
var userId;
userId = _arg.userId;
return model.subscribe("users", function(err, users) {
var newUser;
var newUser, user;
userId = model.get('_userId');
debug(userId, 'model.get _userId');
if (model.get("users." + userId)) {
debug(userId, 'model.get userId');
return getRoom(page, model, userId);
} else {
newUser = {
tasks: {}
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
};
return users.set(userId, newUser, function(err, path, value) {
debug({
users.set(userId, newUser, function(err, path, value) {
return debug({
err: err,
path: path,
value: value
}, 'new user');
return getRoom(page, model, userId);
});
}
user = model.at("users." + userId);
model.ref('_user', user);
model.set('_items', {
armor: content.items.armor[parseInt(user.get('items.armor')) + 1],
weapon: content.items.weapon[parseInt(user.get('items.weapon')) + 1],
potion: content.items.potion,
reroll: content.items.reroll
});
model.fn('_tnl', '_user.stats.lvl', function(lvl) {
return 50 * Math.pow(lvl, 2) - 150 * lvl + 200;
});
model.refList("_habitList", "_user.tasks", "_user.habitIds");
model.refList("_dailyList", "_user.tasks", "_user.dailyIds");
model.refList("_todoList", "_user.tasks", "_user.todoIds");
model.refList("_rewardList", "_user.tasks", "_user.rewardIds");
return page.render();
});
});
getRoom = function(page, model, userId) {
var user;
user = model.at("users." + userId);
model.ref('_user', user);
debug(user, 'user');
/* Set User Defaults
*/
user.setNull('stats', {
money: 0,
exp: 0,
lvl: 1,
hp: 50
});
user.setNull('items', {
itemsEnabled: false,
armor: 0,
weapon: 0
});
model.set('_items', {
armor: content.items.armor[parseInt(user.get('items.armor')) + 1],
weapon: content.items.weapon[parseInt(user.get('items.weapon')) + 1],
potion: content.items.potion,
reroll: content.items.reroll
});
model.fn('_tnl', '_user.stats.lvl', function(lvl) {
return 50 * Math.pow(lvl, 2) - 150 * lvl + 200;
});
model.refList("_habitList", "_user.tasks", "_user.habitIds");
model.refList("_dailyList", "_user.tasks", "_user.dailyIds");
model.refList("_todoList", "_user.tasks", "_user.todoIds");
model.refList("_rewardList", "_user.tasks", "_user.rewardIds");
if (!model.get('_user.tasks')) {
model.push('_habitList', {
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
});
}
return page.render();
};
ready(function(model) {
var endOfDayTally, expModifier, hpModifier, poormanscron, setupSortable, step, tour, type, updateStats, _i, _j, _len, _len1, _ref1, _ref2;
model.set('_purl', window.location.origin + '/' + model.get('_user.id'));
@ -248,9 +232,7 @@ ready(function(model) {
};
exports.toggleTaskEdit = function(e, el) {
var task;
task = model.at($(el).parents('li')[0]);
$('#\\' + task.get('id') + '-chart').hide();
return $('#\\' + task.get('id') + '-edit').toggle();
return task = model.at($(el).parents('li')[0]);
};
exports.toggleChart = function(e, el) {
var chart, chartSelector, data, date, hideSelector, historyPath, matrix, obj, options, readableDate, _k, _len2, _ref3;

View file

@ -1,22 +1,19 @@
module.exports = {
defaultTasks:
habits: [
{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}
]
dailys: [
{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 }
]
todos: [
{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 }
]
rewards: [
{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 }
]
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']
tourSteps: [
{

View file

@ -47,7 +47,6 @@ view.fn "silver", (num) ->
debug = (obj, message) ->
console.log obj, "[debug] #{message}"
get '/:userId?', (page, model, {userId}) ->
# # Saved session
# # TODO: this doesn't check that the user at guid exists, and
@ -58,7 +57,7 @@ get '/:userId?', (page, model, {userId}) ->
# if userId? and (Guid.isGuid(userId) or debuggingUsers)# and model.get(userId)?
# model.set '_userId', userId
# return getRoom page, model, userId
model.subscribe "users", (err, users) ->
# The session middleware will assign a _userId automatically
# Render page if a userId is already stored in session data
@ -66,26 +65,25 @@ get '/:userId?', (page, model, {userId}) ->
debug userId, 'model.get _userId'
if model.get "users.#{userId}"
debug userId, 'model.get userId'
return getRoom page, model, userId
else
# Otherwise, select a new userId and initialize user
newUser = {
tasks: {}
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
}
users.set userId, newUser, (err, path, value) ->
debug {err:err, path:path, value:value}, 'new user'
getRoom page, model, userId
getRoom = (page, model, userId) ->
user = model.at("users.#{userId}")
model.ref '_user', user
debug user, 'user'
### Set User Defaults ###
# Default Items & Stats
user.setNull 'stats', { money: 0, exp: 0, lvl: 1, hp: 50 }
user.setNull 'items', { itemsEnabled: false, armor: 0, weapon: 0 }
# Store
model.set '_items'
armor: content.items.armor[parseInt(user.get('items.armor')) + 1]
weapon: content.items.weapon[parseInt(user.get('items.weapon')) + 1]
@ -100,12 +98,6 @@ getRoom = (page, model, userId) ->
model.refList "_dailyList", "_user.tasks", "_user.dailyIds"
model.refList "_todoList", "_user.tasks", "_user.todoIds"
model.refList "_rewardList", "_user.tasks", "_user.rewardIds"
unless model.get('_user.tasks')
model.push '_habitList', {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 }
# model.push '_habitList', task for task in content.defaultTasks.habits
# model.push '_dailyList', task for task in content.defaultTasks.dailys
# model.push '_todoList', task for task in content.defaultTasks.todos
# model.push '_rewardList', task for task in content.defaultTasks.rewards
page.render()
@ -197,8 +189,8 @@ ready (model) ->
exports.toggleTaskEdit = (e, el) ->
task = model.at $(el).parents('li')[0]
$('#\\' + task.get('id') + '-chart').hide()
$('#\\' + task.get('id') + '-edit').toggle()
# $( document.getElementById(task.get('id')+'-chart') ).hide()
# $( document.getElementById(task.get('id')+'-edit') ).toggle()
exports.toggleChart = (e, el) ->
hideSelector = $(el).attr('data-hide-selector')