diff --git a/src/app/character.coffee b/src/app/character.coffee index d87632f9c5..a345fec55c 100644 --- a/src/app/character.coffee +++ b/src/app/character.coffee @@ -82,68 +82,6 @@ module.exports.app = (appExports, model) -> model.del "users.#{user.get('id')}", -> window.location.href = "/logout" -userSchema = -# _id - stats: { gp: 0, exp: 0, lvl: 1, hp: 50 } - party: { current: null, invitation: null } - items: { weapon: 0, armor: 0, head: 0, shield: 0 } - preferences: { gender: 'm', skin: 'white', hair: 'blond', armorSet: 'v1', dayStart:0, showHelm: true } - habitIds: [] - dailyIds: [] - todoIds: [] - rewardIds: [] - apiToken: null # set in newUserObject below - lastCron: 'new' #this will be replaced with `+new Date` on first run - balance: 0 - tasks: {} - flags: - partyEnabled: false - itemsEnabled: false - tags: [] -# ads: 'show' # added on registration - -module.exports.newUserObject = -> - # deep clone, else further new users get duplicate objects - newUser = _.cloneDeep userSchema - newUser.apiToken = derby.uuid() - - repeat = {m:true,t:true,w:true,th:true,f:true,s:true,su:true} - defaultTasks = [ - {type: 'habit', text: '1h Productive Work', notes: '-- Habits: Constantly Track --\nFor some habits, it only makes sense to *gain* points (like this one).', value: 0, up: true, down: false } - {type: 'habit', text: 'Eat Junk Food', notes: 'For others, it only makes sense to *lose* 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: '-- Dailies: Complete Once a Day --\nAt the end of each day, non-completed Dailies dock you points.', value: 0, completed: false, repeat: repeat } - {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, repeat: repeat } - {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, repeat: repeat } - - {type: 'todo', text: 'Call Mom', notes: "-- Todos: Complete Eventually --\nNon-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: '-- Rewards: Treat Yourself! --\nAs 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 } - ] - - defaultTags = [ - {name: 'morning'} - {name: 'afternoon'} - {name: 'evening'} - ] - - for task in defaultTasks - guid = task.id = derby.uuid() - 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 - - for tag in defaultTags - tag.id = derby.uuid() - newUser.tags.push tag - - return newUser - module.exports.BatchUpdate = BatchUpdate = (model) -> user = model.at("_user") transactionInProgress = false diff --git a/src/app/index.coffee b/src/app/index.coffee index be3bf7094c..372830afc2 100644 --- a/src/app/index.coffee +++ b/src/app/index.coffee @@ -121,7 +121,6 @@ get '/', (page, model, params, next) -> ready (model) -> user = model.at('_user') - model.setNull '_user.apiToken', derby.uuid() browser = require './browser' require('./character').app(exports, model) diff --git a/src/server/index.coffee b/src/server/index.coffee index 7e057b7f06..152b9a79c9 100644 --- a/src/server/index.coffee +++ b/src/server/index.coffee @@ -12,6 +12,8 @@ priv = require './private' habitrpgStore = require './store' middleware = require './middleware' +helpers = require("habitrpg-shared/script/helpers") + ## RACER CONFIGURATION ## #racer.io.set('transports', ['xhr-polling']) @@ -50,7 +52,7 @@ strategies = options = domain: process.env.BASE_URL || 'http://localhost:3000' allowPurl: true - schema: require('../app/character').newUserObject() + schema: helpers.newUser(true) # This has to happen before our middleware stuff auth.store(store, habitrpgStore.customAccessControl) diff --git a/test/api.mocha.coffee b/test/api.mocha.coffee index c2c74319a7..3542a3e0fb 100644 --- a/test/api.mocha.coffee +++ b/test/api.mocha.coffee @@ -22,7 +22,7 @@ expect.Assertion::be = expect.Assertion::equal = (obj) -> origBe.call this, obj # Custom modules -character = require '../src/app/character' +helpers = require 'habitrpg-shared/script/helpers' ###### Helpers & Variables ###### @@ -48,7 +48,7 @@ describe 'API', -> #store.flush() model = store.createModel() model.set '_userId', uid = model.id() - user = character.newUserObject() + user = helpers.newUser(true) user.apiToken = model.id() model.session = {userId:uid} model.set "users.#{uid}", user diff --git a/test/user.mocha.coffee b/test/user.mocha.coffee index 0a7e1fcb76..6f4c2046c2 100644 --- a/test/user.mocha.coffee +++ b/test/user.mocha.coffee @@ -7,7 +7,7 @@ moment = require 'moment' # Custom modules scoring = require '../src/app/scoring' schema = require '../src/app/character' -helpers = require '../src/app/helpers' +helpers = require 'habitrpg-shared/script/helpers' ###### Helpers & Variables ###### @@ -24,7 +24,7 @@ pathSnapshots = (paths) -> statsTask = -> pathSnapshots(['_user.stats', taskPath]) # quick snapshot of user.stats & task cleanUserObj = -> - userObj = schema.newUserObject() + userObj = helpers.newUser() userObj.tasks = {} userObj.habitIds = [] userObj.dailyIds = [] @@ -84,7 +84,7 @@ describe 'User', -> before -> model = new Model - model.set '_user', schema.newUserObject() + model.set '_user', helpers.newUser() scoring.setModel model it 'sets correct user defaults', ->