mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
nodejitsu: adding lib/ (removing from .gitignore so nodejitsu doesn't
have to run make, since I can't figure out how to do that anyway)
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,5 +1,5 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
public/gen
|
public/gen
|
||||||
node_modules
|
node_modules
|
||||||
lib/
|
#lib/
|
||||||
*.swp
|
*.swp
|
||||||
|
|||||||
497
lib/app/content.js
Normal file
497
lib/app/content.js
Normal file
@@ -0,0 +1,497 @@
|
|||||||
|
// Generated by CoffeeScript 1.3.3
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
tylerDefaultTasks: {
|
||||||
|
habits: [
|
||||||
|
{
|
||||||
|
type: 'habit',
|
||||||
|
text: 'Stairs',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
up: true,
|
||||||
|
down: true
|
||||||
|
}, {
|
||||||
|
type: 'habit',
|
||||||
|
text: 'Diet',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
up: true,
|
||||||
|
down: true
|
||||||
|
}, {
|
||||||
|
type: 'habit',
|
||||||
|
text: 'Ticket (Workflowy, Pivotal)',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
up: true,
|
||||||
|
down: false
|
||||||
|
}, {
|
||||||
|
type: 'habit',
|
||||||
|
text: 'Temptation Control',
|
||||||
|
notes: '* meditate for 1 minute, visualize<br/>* positive, specific, present self-talk<br/>* do first task',
|
||||||
|
value: 0,
|
||||||
|
up: true,
|
||||||
|
down: false
|
||||||
|
}, {
|
||||||
|
type: 'habit',
|
||||||
|
text: 'Propose, not ask',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
up: true,
|
||||||
|
down: false
|
||||||
|
}, {
|
||||||
|
type: 'habit',
|
||||||
|
text: 'Focus',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
up: false,
|
||||||
|
down: true
|
||||||
|
}, {
|
||||||
|
type: 'habit',
|
||||||
|
text: 'Facebook/RSS out of turn',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
up: false,
|
||||||
|
down: true
|
||||||
|
}, {
|
||||||
|
type: 'habit',
|
||||||
|
text: 'Negative Talk',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
up: false,
|
||||||
|
down: true
|
||||||
|
}, {
|
||||||
|
type: 'habit',
|
||||||
|
text: 'Exaggeration',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
up: false,
|
||||||
|
down: true
|
||||||
|
}, {
|
||||||
|
type: 'habit',
|
||||||
|
text: 'Insult Self',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
up: false,
|
||||||
|
down: true
|
||||||
|
}, {
|
||||||
|
type: 'habit',
|
||||||
|
text: 'Other',
|
||||||
|
notes: '* Nail-biting<br/>* Posture<br/>* Visualize / Meditate to sleep<br/>* Smile/eye-gaze',
|
||||||
|
value: 0,
|
||||||
|
up: false,
|
||||||
|
down: false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
dailys: [
|
||||||
|
{
|
||||||
|
type: 'daily',
|
||||||
|
text: 'Review Pivotal, Asana, Workflowy',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
completed: false
|
||||||
|
}, {
|
||||||
|
type: 'daily',
|
||||||
|
text: 'TMJ Exercise',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
completed: false
|
||||||
|
}, {
|
||||||
|
type: 'daily',
|
||||||
|
text: 'Anki (20m)',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
completed: false
|
||||||
|
}, {
|
||||||
|
type: 'daily',
|
||||||
|
text: '30m Code Reading',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
completed: false
|
||||||
|
}, {
|
||||||
|
type: 'daily',
|
||||||
|
text: 'Google News',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
completed: false
|
||||||
|
}, {
|
||||||
|
type: 'daily',
|
||||||
|
text: 'Mint',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
completed: false
|
||||||
|
}, {
|
||||||
|
type: 'daily',
|
||||||
|
text: 'Anki (new / review)',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
completed: false
|
||||||
|
}, {
|
||||||
|
type: 'daily',
|
||||||
|
text: 'Check Meetup',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
completed: false
|
||||||
|
}, {
|
||||||
|
type: 'daily',
|
||||||
|
text: 'Read it later',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
completed: false
|
||||||
|
}, {
|
||||||
|
type: 'daily',
|
||||||
|
text: 'RSS (Drupal)',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
completed: false
|
||||||
|
}, {
|
||||||
|
type: 'daily',
|
||||||
|
text: 'RSS (Other)',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
completed: false
|
||||||
|
}, {
|
||||||
|
type: 'daily',
|
||||||
|
text: 'Lunch TODO',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
completed: false
|
||||||
|
}, {
|
||||||
|
type: 'daily',
|
||||||
|
text: 'Exercise',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
completed: false
|
||||||
|
}, {
|
||||||
|
type: 'daily',
|
||||||
|
text: 'Read (45m)',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
completed: false
|
||||||
|
}, {
|
||||||
|
type: 'daily',
|
||||||
|
text: 'Night TODO',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
completed: false
|
||||||
|
}, {
|
||||||
|
type: 'daily',
|
||||||
|
text: 'Brain Game',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
completed: false
|
||||||
|
}, {
|
||||||
|
type: 'daily',
|
||||||
|
text: '1h Personal Project',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
completed: false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
todos: [
|
||||||
|
{
|
||||||
|
type: 'todo',
|
||||||
|
text: 'VPM',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
completed: false
|
||||||
|
}, {
|
||||||
|
type: 'todo',
|
||||||
|
text: 'mail',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
completed: false
|
||||||
|
}, {
|
||||||
|
type: 'todo',
|
||||||
|
text: 'krav',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
completed: false
|
||||||
|
}, {
|
||||||
|
type: 'todo',
|
||||||
|
text: 'rubber cement',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
completed: false
|
||||||
|
}, {
|
||||||
|
type: 'todo',
|
||||||
|
text: 'bike',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
completed: false
|
||||||
|
}, {
|
||||||
|
type: 'todo',
|
||||||
|
text: 'clean ~/.ievms',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
completed: false
|
||||||
|
}, {
|
||||||
|
type: 'todo',
|
||||||
|
text: 'http://www.php-debug.com/www/',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
completed: false
|
||||||
|
}, {
|
||||||
|
type: 'todo',
|
||||||
|
text: 'make sure IRA is setup for auto distribution',
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
completed: false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
rewards: [
|
||||||
|
{
|
||||||
|
type: 'reward',
|
||||||
|
text: 'TV Show',
|
||||||
|
notes: '',
|
||||||
|
value: 20
|
||||||
|
}, {
|
||||||
|
type: 'reward',
|
||||||
|
text: '1h Novel',
|
||||||
|
notes: '',
|
||||||
|
value: 10
|
||||||
|
}, {
|
||||||
|
type: 'reward',
|
||||||
|
text: 'Shop',
|
||||||
|
notes: '',
|
||||||
|
value: 10
|
||||||
|
}, {
|
||||||
|
type: 'reward',
|
||||||
|
text: 'Junk Food',
|
||||||
|
notes: '',
|
||||||
|
value: 10
|
||||||
|
}, {
|
||||||
|
type: 'reward',
|
||||||
|
text: '9gag',
|
||||||
|
notes: '',
|
||||||
|
value: 5
|
||||||
|
}, {
|
||||||
|
type: 'reward',
|
||||||
|
text: 'Coffee',
|
||||||
|
notes: '',
|
||||||
|
value: 5
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
tourSteps: [
|
||||||
|
{
|
||||||
|
element: "#avatar",
|
||||||
|
title: "Welcome to HabitRPG",
|
||||||
|
content: "Welcome to HabitRPG, a habit-tracker which treats your goals like a Role Playing Game."
|
||||||
|
}, {
|
||||||
|
element: "#bars",
|
||||||
|
title: "Acheive goals and level up",
|
||||||
|
content: "As you accomplish goals, you level up. If you fail your goals, you lose hit points. Lose all your HP and you die."
|
||||||
|
}, {
|
||||||
|
element: "ul.habits",
|
||||||
|
title: "Habits",
|
||||||
|
content: "Habits are goals that you constantly track.",
|
||||||
|
placement: "bottom"
|
||||||
|
}, {
|
||||||
|
element: "ul.dailys",
|
||||||
|
title: "Dailies",
|
||||||
|
content: "Dailies are goals that you want to complete once a day.",
|
||||||
|
placement: "bottom"
|
||||||
|
}, {
|
||||||
|
element: "ul.todos",
|
||||||
|
title: "Todos",
|
||||||
|
content: "Todos are one-off goals which need to be completed eventually.",
|
||||||
|
placement: "bottom"
|
||||||
|
}, {
|
||||||
|
element: "ul.rewards",
|
||||||
|
title: "Rewards",
|
||||||
|
content: "As you complete goals, you earn gold to buy rewards. Buy them liberally - rewards are integral in forming good habits.",
|
||||||
|
placement: "bottom"
|
||||||
|
}, {
|
||||||
|
element: "ul.habits li:first-child",
|
||||||
|
title: "Hover over comments",
|
||||||
|
content: "Different task-types have special properties. Hover over each task's comment for more information. When you're ready to get started, delete the existing tasks and add your own.",
|
||||||
|
placement: "right"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
items: {
|
||||||
|
unlockedMessage: {
|
||||||
|
title: "Item Store Unlocked",
|
||||||
|
content: "Congradulations, you have unlocked the Item Store! You can now buy weapons, armor, potions, etc. Read each item's comment for more information."
|
||||||
|
},
|
||||||
|
weapon: [
|
||||||
|
{
|
||||||
|
type: 'weapon',
|
||||||
|
index: 0,
|
||||||
|
text: "Sword 1",
|
||||||
|
icon: "item-sword1",
|
||||||
|
notes: 'Training weapon.',
|
||||||
|
value: 0
|
||||||
|
}, {
|
||||||
|
type: 'weapon',
|
||||||
|
index: 1,
|
||||||
|
text: "Sword 2",
|
||||||
|
icon: 'item-sword2',
|
||||||
|
notes: 'Increases experience gain by 3%.',
|
||||||
|
value: 50
|
||||||
|
}, {
|
||||||
|
type: 'weapon',
|
||||||
|
index: 2,
|
||||||
|
text: "Axe",
|
||||||
|
icon: 'item-axe',
|
||||||
|
notes: 'Increases experience gain by 6%.',
|
||||||
|
value: 100
|
||||||
|
}, {
|
||||||
|
type: 'weapon',
|
||||||
|
index: 3,
|
||||||
|
text: "Morningstar",
|
||||||
|
icon: 'item-morningstar',
|
||||||
|
notes: 'Increases experience gain by 9%.',
|
||||||
|
value: 150
|
||||||
|
}, {
|
||||||
|
type: 'weapon',
|
||||||
|
index: 4,
|
||||||
|
text: "Blue Sword",
|
||||||
|
icon: 'item-bluesword',
|
||||||
|
notes: 'Increases experience gain by 12%.',
|
||||||
|
value: 200
|
||||||
|
}, {
|
||||||
|
type: 'weapon',
|
||||||
|
index: 5,
|
||||||
|
text: "Red Sword",
|
||||||
|
icon: 'item-redsword',
|
||||||
|
notes: 'Increases experience gain by 15%.',
|
||||||
|
value: 250
|
||||||
|
}, {
|
||||||
|
type: 'weapon',
|
||||||
|
index: 6,
|
||||||
|
text: "Golden Sword",
|
||||||
|
icon: 'item-goldensword',
|
||||||
|
notes: 'Increases experience gain by 18%.',
|
||||||
|
value: 300
|
||||||
|
}
|
||||||
|
],
|
||||||
|
armor: [
|
||||||
|
{
|
||||||
|
type: 'armor',
|
||||||
|
index: 0,
|
||||||
|
text: "Cloth Armor",
|
||||||
|
icon: 'item-clotharmor',
|
||||||
|
notes: 'Training armor.',
|
||||||
|
value: 0
|
||||||
|
}, {
|
||||||
|
type: 'armor',
|
||||||
|
index: 1,
|
||||||
|
text: "Leather Armor",
|
||||||
|
icon: 'item-leatherarmor',
|
||||||
|
notes: 'Decreases HP loss by 3%.',
|
||||||
|
value: 50
|
||||||
|
}, {
|
||||||
|
type: 'armor',
|
||||||
|
index: 2,
|
||||||
|
text: "Chain Mail",
|
||||||
|
icon: 'item-mailarmor',
|
||||||
|
notes: 'Decreases HP loss by 6%.',
|
||||||
|
value: 100
|
||||||
|
}, {
|
||||||
|
type: 'armor',
|
||||||
|
index: 3,
|
||||||
|
text: "Plate Mail",
|
||||||
|
icon: 'item-platearmor',
|
||||||
|
notes: 'Decreases HP loss by 9%.',
|
||||||
|
value: 150
|
||||||
|
}, {
|
||||||
|
type: 'armor',
|
||||||
|
index: 4,
|
||||||
|
text: "Red Armor",
|
||||||
|
icon: 'item-redarmor',
|
||||||
|
notes: 'Decreases HP loss by 12%.',
|
||||||
|
value: 200
|
||||||
|
}, {
|
||||||
|
type: 'armor',
|
||||||
|
index: 5,
|
||||||
|
text: "Golden Armor",
|
||||||
|
icon: 'item-goldenarmor',
|
||||||
|
notes: 'Decreases HP loss by 15%.',
|
||||||
|
value: 250
|
||||||
|
}
|
||||||
|
],
|
||||||
|
potion: {
|
||||||
|
type: 'potion',
|
||||||
|
text: "Potion",
|
||||||
|
notes: "Recover 15 HP",
|
||||||
|
value: 30,
|
||||||
|
icon: 'item-flask'
|
||||||
|
},
|
||||||
|
reroll: {
|
||||||
|
type: 'reroll',
|
||||||
|
text: "Re-Roll",
|
||||||
|
icon: 'favicon',
|
||||||
|
notes: "Reset your task values to 0. Do this only if you're <b>really</b> struggling.",
|
||||||
|
value: 100
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
564
lib/app/index.js
Normal file
564
lib/app/index.js
Normal file
@@ -0,0 +1,564 @@
|
|||||||
|
// Generated by CoffeeScript 1.3.3
|
||||||
|
var content, derby, get, getRoom, ready, view, _ref;
|
||||||
|
|
||||||
|
derby = require('derby');
|
||||||
|
|
||||||
|
_ref = derby.createApp(module), get = _ref.get, view = _ref.view, ready = _ref.ready;
|
||||||
|
|
||||||
|
derby.use(require('derby-ui-boot'));
|
||||||
|
|
||||||
|
derby.use(require('../../ui'));
|
||||||
|
|
||||||
|
content = require('./content');
|
||||||
|
|
||||||
|
view.fn('taskClasses', function(type, completed, value, hideCompleted) {
|
||||||
|
var classes;
|
||||||
|
classes = type;
|
||||||
|
if (completed) {
|
||||||
|
classes += " completed";
|
||||||
|
}
|
||||||
|
if (type === 'todo') {
|
||||||
|
if ((hideCompleted && completed) || (!hideCompleted && !completed)) {
|
||||||
|
classes += " hide";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch (false) {
|
||||||
|
case !(value < -8):
|
||||||
|
classes += ' color-worst';
|
||||||
|
break;
|
||||||
|
case !(value >= -8 && value < -5):
|
||||||
|
classes += ' color-worse';
|
||||||
|
break;
|
||||||
|
case !(value >= -5 && value < -1):
|
||||||
|
classes += ' color-bad';
|
||||||
|
break;
|
||||||
|
case !(value >= -1 && value < 1):
|
||||||
|
classes += ' color-neutral';
|
||||||
|
break;
|
||||||
|
case !(value >= 1 && value < 5):
|
||||||
|
classes += ' color-good';
|
||||||
|
break;
|
||||||
|
case !(value >= 5 && value < 10):
|
||||||
|
classes += ' color-better';
|
||||||
|
break;
|
||||||
|
case !(value >= 10):
|
||||||
|
classes += ' color-best';
|
||||||
|
}
|
||||||
|
return classes;
|
||||||
|
});
|
||||||
|
|
||||||
|
view.fn("percent", function(x, y) {
|
||||||
|
if (x === 0) {
|
||||||
|
x = 1;
|
||||||
|
}
|
||||||
|
return Math.round(x / y * 100);
|
||||||
|
});
|
||||||
|
|
||||||
|
view.fn("round", function(num) {
|
||||||
|
return Math.round(num);
|
||||||
|
});
|
||||||
|
|
||||||
|
view.fn("gold", function(num) {
|
||||||
|
if (num) {
|
||||||
|
return num.toFixed(1).split('.')[0];
|
||||||
|
} else {
|
||||||
|
return "0";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
view.fn("silver", function(num) {
|
||||||
|
if (num) {
|
||||||
|
return num.toFixed(1).split('.')[1];
|
||||||
|
} else {
|
||||||
|
return "0";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
get('/', function(page, model) {
|
||||||
|
var userId;
|
||||||
|
if (userId = model.get('_session.userId')) {
|
||||||
|
return getRoom(page, model, userId);
|
||||||
|
}
|
||||||
|
return model.async.incr('configs.1.nextUserId', function(err, userId) {
|
||||||
|
model.set('_session.userId', userId);
|
||||||
|
model.set("users." + userId, {
|
||||||
|
name: 'User ' + userId
|
||||||
|
});
|
||||||
|
return getRoom(page, model, userId);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
getRoom = function(page, model, userId) {
|
||||||
|
return model.subscribe("users." + userId, function(err, user) {
|
||||||
|
var task, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref1, _ref2, _ref3, _ref4;
|
||||||
|
model.ref('_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')) {
|
||||||
|
_ref1 = content.defaultTasks.habits;
|
||||||
|
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
||||||
|
task = _ref1[_i];
|
||||||
|
model.push('_habitList', task);
|
||||||
|
}
|
||||||
|
_ref2 = content.defaultTasks.dailys;
|
||||||
|
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
|
||||||
|
task = _ref2[_j];
|
||||||
|
model.push('_dailyList', task);
|
||||||
|
}
|
||||||
|
_ref3 = content.defaultTasks.todos;
|
||||||
|
for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) {
|
||||||
|
task = _ref3[_k];
|
||||||
|
model.push('_todoList', task);
|
||||||
|
}
|
||||||
|
_ref4 = content.defaultTasks.rewards;
|
||||||
|
for (_l = 0, _len3 = _ref4.length; _l < _len3; _l++) {
|
||||||
|
task = _ref4[_l];
|
||||||
|
model.push('_rewardList', task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return page.render();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
ready(function(model) {
|
||||||
|
var endOfDayTally, expModifier, hpModifier, poormanscron, setupSortable, step, tour, type, updateStats, _i, _j, _len, _len1, _ref1, _ref2;
|
||||||
|
$('[rel=popover]').popover();
|
||||||
|
model.on('set', '*', function() {
|
||||||
|
return $('[rel=popover]').popover();
|
||||||
|
});
|
||||||
|
model.set('_hideCompleted', true);
|
||||||
|
$('a[data-toggle="tab"]').on('shown', function(e) {
|
||||||
|
var hideCompleted;
|
||||||
|
hideCompleted = $(e.target).attr('href') === '#tab1' ? true : false;
|
||||||
|
return model.set('_hideCompleted', hideCompleted);
|
||||||
|
});
|
||||||
|
setupSortable = function(type) {
|
||||||
|
return $("ul." + type + "s").sortable({
|
||||||
|
dropOnEmpty: false,
|
||||||
|
cursor: "move",
|
||||||
|
items: "li",
|
||||||
|
opacity: 0.4,
|
||||||
|
scroll: true,
|
||||||
|
axis: 'y',
|
||||||
|
update: function(e, ui) {
|
||||||
|
var domId, id, item, to;
|
||||||
|
item = ui.item[0];
|
||||||
|
domId = item.id;
|
||||||
|
id = item.getAttribute('data-id');
|
||||||
|
to = $("ul." + type + "s").children().index(item);
|
||||||
|
return model.at("_" + type + "List").pass({
|
||||||
|
ignore: domId
|
||||||
|
}).move({
|
||||||
|
id: id
|
||||||
|
}, to);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
_ref1 = ['habit', 'daily', 'todo', 'reward'];
|
||||||
|
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
||||||
|
type = _ref1[_i];
|
||||||
|
setupSortable(type);
|
||||||
|
}
|
||||||
|
tour = new Tour();
|
||||||
|
_ref2 = content.tourSteps;
|
||||||
|
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
|
||||||
|
step = _ref2[_j];
|
||||||
|
tour.addStep({
|
||||||
|
element: step.element,
|
||||||
|
title: step.title,
|
||||||
|
content: step.content,
|
||||||
|
placement: step.placement
|
||||||
|
});
|
||||||
|
}
|
||||||
|
tour.start();
|
||||||
|
exports.loadDebugDefaults = function(e, el) {
|
||||||
|
var task, _k, _l, _len2, _len3, _len4, _len5, _len6, _m, _n, _o, _ref3, _ref4, _ref5, _ref6, _ref7, _results;
|
||||||
|
_ref3 = model.get('_user.tasks');
|
||||||
|
for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) {
|
||||||
|
task = _ref3[_k];
|
||||||
|
console.log(task);
|
||||||
|
task = model.at(task);
|
||||||
|
model.del('_user.tasks.' + task.get('id'));
|
||||||
|
task.remove();
|
||||||
|
}
|
||||||
|
_ref4 = content.tylerDefaultTasks.habits;
|
||||||
|
for (_l = 0, _len3 = _ref4.length; _l < _len3; _l++) {
|
||||||
|
task = _ref4[_l];
|
||||||
|
model.push('_habitList', task);
|
||||||
|
}
|
||||||
|
_ref5 = content.tylerDefaultTasks.dailys;
|
||||||
|
for (_m = 0, _len4 = _ref5.length; _m < _len4; _m++) {
|
||||||
|
task = _ref5[_m];
|
||||||
|
model.push('_dailyList', task);
|
||||||
|
}
|
||||||
|
_ref6 = content.tylerDefaultTasks.todos;
|
||||||
|
for (_n = 0, _len5 = _ref6.length; _n < _len5; _n++) {
|
||||||
|
task = _ref6[_n];
|
||||||
|
model.push('_todoList', task);
|
||||||
|
}
|
||||||
|
_ref7 = content.tylerDefaultTasks.rewards;
|
||||||
|
_results = [];
|
||||||
|
for (_o = 0, _len6 = _ref7.length; _o < _len6; _o++) {
|
||||||
|
task = _ref7[_o];
|
||||||
|
_results.push(model.push('_rewardList', task));
|
||||||
|
}
|
||||||
|
return _results;
|
||||||
|
};
|
||||||
|
exports.addTask = function(e, el, next) {
|
||||||
|
var list, newModel, text;
|
||||||
|
type = $(el).attr('data-task-type');
|
||||||
|
list = model.at("_" + type + "List");
|
||||||
|
newModel = model.at('_new' + type.charAt(0).toUpperCase() + type.slice(1));
|
||||||
|
if (!(text = view.escapeHtml(newModel.get()))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
newModel.set('');
|
||||||
|
switch (type) {
|
||||||
|
case 'habit':
|
||||||
|
return list.push({
|
||||||
|
type: type,
|
||||||
|
text: text,
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
up: true,
|
||||||
|
down: true
|
||||||
|
});
|
||||||
|
case 'reward':
|
||||||
|
return list.push({
|
||||||
|
type: type,
|
||||||
|
text: text,
|
||||||
|
notes: '',
|
||||||
|
value: 20
|
||||||
|
});
|
||||||
|
case 'daily':
|
||||||
|
case 'todo':
|
||||||
|
return list.push({
|
||||||
|
type: type,
|
||||||
|
text: text,
|
||||||
|
notes: '',
|
||||||
|
value: 0,
|
||||||
|
completed: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
exports.del = function(e, el) {
|
||||||
|
var task;
|
||||||
|
task = model.at(e.target);
|
||||||
|
model.del('_user.tasks.' + task.get('id'));
|
||||||
|
return task.remove();
|
||||||
|
};
|
||||||
|
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();
|
||||||
|
};
|
||||||
|
exports.toggleChart = function(e, el) {
|
||||||
|
var chart, chartSelector, data, date, hideSelector, historyPath, matrix, obj, options, readableDate, _k, _len2, _ref3;
|
||||||
|
hideSelector = $(el).attr('data-hide-selector');
|
||||||
|
chartSelector = $(el).attr('data-chart-selector');
|
||||||
|
historyPath = $(el).attr('data-history-path');
|
||||||
|
$(document.getElementById(hideSelector)).hide();
|
||||||
|
$(document.getElementById(chartSelector)).toggle();
|
||||||
|
matrix = [['Date', 'Score']];
|
||||||
|
_ref3 = model.get(historyPath);
|
||||||
|
for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) {
|
||||||
|
obj = _ref3[_k];
|
||||||
|
date = new Date(obj.date);
|
||||||
|
readableDate = "" + (date.getMonth()) + "/" + (date.getDate()) + "/" + (date.getFullYear());
|
||||||
|
matrix.push([readableDate, obj.value]);
|
||||||
|
}
|
||||||
|
data = google.visualization.arrayToDataTable(matrix);
|
||||||
|
options = {
|
||||||
|
title: 'History',
|
||||||
|
backgroundColor: 'whiteSmoke'
|
||||||
|
};
|
||||||
|
chart = new google.visualization.LineChart(document.getElementById(chartSelector));
|
||||||
|
return chart.draw(data, options);
|
||||||
|
};
|
||||||
|
exports.buyItem = function(e, el, next) {
|
||||||
|
var hp, index, money, task, taskId, user, value, _ref3, _results;
|
||||||
|
user = model.at('_user');
|
||||||
|
money = user.get('stats.money');
|
||||||
|
_ref3 = [$(el).attr('data-type'), $(el).attr('data-value'), $(el).attr('data-index')], type = _ref3[0], value = _ref3[1], index = _ref3[2];
|
||||||
|
if (money < value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
user.set('stats.money', money - value);
|
||||||
|
if (type === 'armor') {
|
||||||
|
user.set('items.armor', index);
|
||||||
|
return model.set('_items.armor', content.items.armor[parseInt(index) + 1]);
|
||||||
|
} else if (type === 'weapon') {
|
||||||
|
user.set('items.weapon', index);
|
||||||
|
return model.set('_items.weapon', content.items.weapon[parseInt(index) + 1]);
|
||||||
|
} else if (type === 'potion') {
|
||||||
|
hp = user.get('stats.hp');
|
||||||
|
hp += 15;
|
||||||
|
if (hp > 50) {
|
||||||
|
hp = 50;
|
||||||
|
}
|
||||||
|
return user.set('stats.hp', hp);
|
||||||
|
} else if (type === 'reroll') {
|
||||||
|
_results = [];
|
||||||
|
for (taskId in user.get('tasks')) {
|
||||||
|
task = model.at('_user.tasks.' + taskId);
|
||||||
|
if (task.get('type') !== 'reward') {
|
||||||
|
_results.push(task.set('value', 0));
|
||||||
|
} else {
|
||||||
|
_results.push(void 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _results;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
exports.updateStats = updateStats = function(user, stats) {
|
||||||
|
var money, tnl;
|
||||||
|
if (stats.hp != null) {
|
||||||
|
if (stats.hp < 0) {
|
||||||
|
user.set('stats.lvl', 0);
|
||||||
|
} else {
|
||||||
|
user.set('stats.hp', stats.hp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (stats.exp != null) {
|
||||||
|
tnl = model.get('_tnl');
|
||||||
|
if (stats.exp >= tnl) {
|
||||||
|
stats.exp -= tnl;
|
||||||
|
user.set('stats.lvl', user.get('stats.lvl') + 1);
|
||||||
|
}
|
||||||
|
if (!user.get('items.itemsEnabled') && stats.exp >= 50) {
|
||||||
|
user.set('items.itemsEnabled', true);
|
||||||
|
$('ul.items').popover({
|
||||||
|
title: content.items.unlockedMessage.title,
|
||||||
|
placement: 'left',
|
||||||
|
trigger: 'manual',
|
||||||
|
html: true,
|
||||||
|
content: "<div class='item-store-popover'> <img src='/img/BrowserQuest/chest.png' /> " + content.items.unlockedMessage.content + " <a href='#' onClick=\"$('ul.items').popover('hide');return false;\">[Close]</a> </div>"
|
||||||
|
});
|
||||||
|
$('ul.items').popover('show');
|
||||||
|
}
|
||||||
|
user.set('stats.exp', stats.exp);
|
||||||
|
}
|
||||||
|
if (stats.money != null) {
|
||||||
|
if (!(typeof money !== "undefined" && money !== null) || money < 0) {
|
||||||
|
money = 0.0;
|
||||||
|
}
|
||||||
|
return user.set('stats.money', stats.money);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
expModifier = function(value) {
|
||||||
|
var dmg, modified, user;
|
||||||
|
user = model.at('_user');
|
||||||
|
dmg = user.get('items.weapon') * .03;
|
||||||
|
dmg += user.get('stats.lvl') * .03;
|
||||||
|
modified = value + (value * dmg);
|
||||||
|
console.log(modified, 'exp modified');
|
||||||
|
return modified;
|
||||||
|
};
|
||||||
|
hpModifier = function(value) {
|
||||||
|
var ac, modified, user;
|
||||||
|
user = model.at('_user');
|
||||||
|
ac = user.get('items.armor') * .03;
|
||||||
|
ac += user.get('stats.lvl') * .03;
|
||||||
|
modified = value - (value * ac);
|
||||||
|
console.log(modified, 'hp modified');
|
||||||
|
return modified;
|
||||||
|
};
|
||||||
|
exports.vote = function(e, el, next) {
|
||||||
|
var adjustvalue, completed, delta, direction, exp, hp, lvl, money, sign, task, user, value, _ref3;
|
||||||
|
direction = $(el).attr('data-direction');
|
||||||
|
if (direction === 'true/') {
|
||||||
|
direction = 'up';
|
||||||
|
}
|
||||||
|
if (direction === 'false/') {
|
||||||
|
direction = 'down';
|
||||||
|
}
|
||||||
|
task = model.at($(el).parents('li')[0]);
|
||||||
|
user = model.at('_user');
|
||||||
|
sign = direction === "up" ? 1 : -1;
|
||||||
|
value = task.get('value');
|
||||||
|
delta = 0;
|
||||||
|
if (value < 0) {
|
||||||
|
delta = (-0.1 * value + 1) * sign;
|
||||||
|
} else {
|
||||||
|
delta = (Math.pow(0.9, value)) * sign;
|
||||||
|
}
|
||||||
|
adjustvalue = task.get('type') !== 'reward';
|
||||||
|
if ((task.get('type') === 'habit') && (task.get("up") === false || task.get("down") === false)) {
|
||||||
|
adjustvalue = false;
|
||||||
|
}
|
||||||
|
if (adjustvalue) {
|
||||||
|
value += delta;
|
||||||
|
}
|
||||||
|
completed = task.get("completed");
|
||||||
|
if (task.get('type') !== 'habit') {
|
||||||
|
if (direction === "up") {
|
||||||
|
completed = true;
|
||||||
|
}
|
||||||
|
if (direction === "down") {
|
||||||
|
completed = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (task.get('value') !== value) {
|
||||||
|
task.push('history', {
|
||||||
|
date: new Date(),
|
||||||
|
value: value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
task.set('value', value);
|
||||||
|
task.set('completed', completed);
|
||||||
|
_ref3 = [user.get('stats.money'), user.get('stats.hp'), user.get('stats.exp'), user.get('stats.lvl')], money = _ref3[0], hp = _ref3[1], exp = _ref3[2], lvl = _ref3[3];
|
||||||
|
if (task.get('type') === 'reward') {
|
||||||
|
money -= task.get('value');
|
||||||
|
if (money < 0) {
|
||||||
|
hp += money;
|
||||||
|
money = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (delta > 0 || (task.get('type') === 'daily' || task.get('type') === 'todo')) {
|
||||||
|
exp += expModifier(delta);
|
||||||
|
money += delta;
|
||||||
|
} else if (task.get('type') !== 'reward') {
|
||||||
|
hp += hpModifier(delta);
|
||||||
|
}
|
||||||
|
return updateStats(user, {
|
||||||
|
hp: hp,
|
||||||
|
exp: exp,
|
||||||
|
money: money
|
||||||
|
});
|
||||||
|
};
|
||||||
|
exports.endOfDayTally = endOfDayTally = function(e, el) {
|
||||||
|
var absVal, completed, expTally, hp, key, lvl, task, todoTally, user, value, _ref3;
|
||||||
|
user = model.at('_user');
|
||||||
|
todoTally = 0;
|
||||||
|
for (key in model.get('_user.tasks')) {
|
||||||
|
task = model.at("_user.tasks." + key);
|
||||||
|
_ref3 = [task.get('type'), task.get('value'), task.get('completed')], type = _ref3[0], value = _ref3[1], completed = _ref3[2];
|
||||||
|
if (type === 'todo' || type === 'daily') {
|
||||||
|
if (!completed) {
|
||||||
|
value += value < 0 ? (-0.1 * value + 1) * -1 : (Math.pow(0.9, value)) * -1;
|
||||||
|
task.set('value', value);
|
||||||
|
if (type === 'daily') {
|
||||||
|
hp = user.get('stats.hp') + hpModifier(value);
|
||||||
|
updateStats(user, {
|
||||||
|
hp: hp
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (type === 'daily') {
|
||||||
|
task.push("history", {
|
||||||
|
date: new Date(),
|
||||||
|
value: value
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
absVal = completed ? Math.abs(value) : value;
|
||||||
|
todoTally += absVal;
|
||||||
|
}
|
||||||
|
if (type === 'daily') {
|
||||||
|
task.set('completed', false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
model.push('_user.history.todos', {
|
||||||
|
date: new Date(),
|
||||||
|
value: todoTally
|
||||||
|
});
|
||||||
|
expTally = user.get('stats.exp');
|
||||||
|
lvl = 0;
|
||||||
|
_(user.get('stats.lvl') - 1).times(function() {
|
||||||
|
lvl++;
|
||||||
|
return expTally += 50 * Math.pow(lvl, 2) - 150 * lvl + 200;
|
||||||
|
});
|
||||||
|
return model.push('_user.history.exp', {
|
||||||
|
date: new Date(),
|
||||||
|
value: expTally
|
||||||
|
});
|
||||||
|
};
|
||||||
|
poormanscron = function() {
|
||||||
|
var DAY, daysPassed, lastCron, today;
|
||||||
|
lastCron = model.get('_user.lastCron');
|
||||||
|
lastCron = lastCron ? new Date(lastCron) : new Date();
|
||||||
|
DAY = 1000 * 60 * 60 * 24;
|
||||||
|
today = new Date();
|
||||||
|
daysPassed = Math.round((today.getTime() - lastCron.getTime()) / DAY);
|
||||||
|
if (daysPassed > 0) {
|
||||||
|
_(daysPassed).times(function() {
|
||||||
|
return endOfDayTally();
|
||||||
|
});
|
||||||
|
lastCron = new Date();
|
||||||
|
}
|
||||||
|
return model.set('_user.lastCron', lastCron);
|
||||||
|
};
|
||||||
|
poormanscron();
|
||||||
|
exports.toggleDebug = function() {
|
||||||
|
return model.set('_debug', !model.get('_debug'));
|
||||||
|
};
|
||||||
|
exports.revive = function(e, el) {
|
||||||
|
var stats;
|
||||||
|
stats = model.at('_user.stats');
|
||||||
|
stats.set('hp', 50);
|
||||||
|
stats.set('lvl', 1);
|
||||||
|
stats.set('exp', 0);
|
||||||
|
stats.set('money', 0);
|
||||||
|
model.set('_user.items.armor', 0);
|
||||||
|
model.set('_user.items.weapon', 0);
|
||||||
|
model.set('_items.armor', content.items.armor[1]);
|
||||||
|
return model.set('_items.weapon', content.items.weapon[1]);
|
||||||
|
};
|
||||||
|
exports.shortcuts = function(e) {
|
||||||
|
var code, command;
|
||||||
|
if (!(e.metaKey || e.ctrlKey)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
code = e.which;
|
||||||
|
if (!(command = ((function() {
|
||||||
|
switch (code) {
|
||||||
|
case 66:
|
||||||
|
return 'bold';
|
||||||
|
case 73:
|
||||||
|
return 'italic';
|
||||||
|
case 32:
|
||||||
|
return 'removeFormat';
|
||||||
|
case 220:
|
||||||
|
return 'removeFormat';
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})()))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
document.execCommand(command, false, null);
|
||||||
|
if (e.preventDefault) {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
document.execCommand('useCSS', false, true);
|
||||||
|
return document.execCommand('styleWithCSS', false, false);
|
||||||
|
});
|
||||||
52
lib/server/index.js
Normal file
52
lib/server/index.js
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
// Generated by CoffeeScript 1.3.3
|
||||||
|
var MongoStore, ONE_YEAR, app, derby, exports, express, expressApp, gzippo, http, path, publicPath, root, server, serverError;
|
||||||
|
|
||||||
|
http = require('http');
|
||||||
|
|
||||||
|
path = require('path');
|
||||||
|
|
||||||
|
express = require('express');
|
||||||
|
|
||||||
|
gzippo = require('gzippo');
|
||||||
|
|
||||||
|
MongoStore = require('connect-mongo')(express);
|
||||||
|
|
||||||
|
derby = require('derby');
|
||||||
|
|
||||||
|
app = require('../app');
|
||||||
|
|
||||||
|
serverError = require('./serverError');
|
||||||
|
|
||||||
|
ONE_YEAR = 1000 * 60 * 60 * 24 * 365;
|
||||||
|
|
||||||
|
root = path.dirname(path.dirname(__dirname));
|
||||||
|
|
||||||
|
publicPath = path.join(root, 'public');
|
||||||
|
|
||||||
|
(expressApp = express()).use(express.favicon()).use(gzippo.staticGzip(publicPath, {
|
||||||
|
maxAge: ONE_YEAR
|
||||||
|
})).use(express.compress()).use(express.cookieParser('secret_sauce')).use(express.session({
|
||||||
|
cookie: {
|
||||||
|
maxAge: ONE_YEAR
|
||||||
|
},
|
||||||
|
store: new MongoStore({
|
||||||
|
db: 'habitrpg',
|
||||||
|
collection: 'express-sessions'
|
||||||
|
})
|
||||||
|
})).use(app.session()).use(app.router()).use(expressApp.router).use(serverError(root));
|
||||||
|
|
||||||
|
exports = module.exports = server = http.createServer(expressApp);
|
||||||
|
|
||||||
|
expressApp.all('*', function(req) {
|
||||||
|
throw "404: " + req.url;
|
||||||
|
});
|
||||||
|
|
||||||
|
derby.use(require('racer-db-mongo'));
|
||||||
|
|
||||||
|
exports.store = app.createStore({
|
||||||
|
listen: server,
|
||||||
|
db: {
|
||||||
|
type: 'Mongo',
|
||||||
|
uri: 'mongodb://localhost/habitrpg'
|
||||||
|
}
|
||||||
|
});
|
||||||
27
lib/server/serverError.js
Normal file
27
lib/server/serverError.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
// Generated by CoffeeScript 1.3.3
|
||||||
|
var derby, isProduction;
|
||||||
|
|
||||||
|
derby = require('derby');
|
||||||
|
|
||||||
|
isProduction = derby.util.isProduction;
|
||||||
|
|
||||||
|
module.exports = function(root) {
|
||||||
|
var staticPages;
|
||||||
|
staticPages = derby.createStatic(root);
|
||||||
|
return function(err, req, res, next) {
|
||||||
|
var message, status;
|
||||||
|
if (err == null) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
console.log(err.stack ? err.stack : err);
|
||||||
|
message = err.message || err.toString();
|
||||||
|
status = parseInt(message);
|
||||||
|
if (status === 404) {
|
||||||
|
return staticPages.render('404', res, {
|
||||||
|
url: req.url
|
||||||
|
}, 404);
|
||||||
|
} else {
|
||||||
|
return res.send((400 <= status && status < 600) ? status : 500);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user