add newUser to helpers, will be needed when creating new users on mobile
This commit is contained in:
@@ -29,8 +29,83 @@ shouldDo = (day, repeat, dayStart=0) ->
|
||||
yesterday = moment(now).subtract(1,'d').day()
|
||||
return repeat[dayMapping[yesterday]]
|
||||
|
||||
uuid = ->
|
||||
"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace /[xy]/g, (c) ->
|
||||
r = Math.random() * 16 | 0
|
||||
v = (if c is "x" then r else (r & 0x3 | 0x8))
|
||||
v.toString 16
|
||||
|
||||
module.exports =
|
||||
|
||||
uuid: uuid
|
||||
|
||||
newUser: (isDerby=false) ->
|
||||
userSchema =
|
||||
# _id / id handled by Racer
|
||||
stats: { gp: 0, exp: 0, lvl: 1, hp: 50 }
|
||||
party: { invitation: null }
|
||||
items: { weapon: 0, armor: 0, head: 0, shield: 0 }
|
||||
preferences: { gender: 'm', skin: 'white', hair: 'blond', armorSet: 'v1', dayStart:0, showHelm: true }
|
||||
apiToken: uuid() # set in newUserObject below
|
||||
lastCron: 'new' #this will be replaced with `+new Date` on first run
|
||||
balance: 0
|
||||
flags:
|
||||
partyEnabled: false
|
||||
itemsEnabled: false
|
||||
ads: 'show'
|
||||
tags: []
|
||||
|
||||
if isDerby
|
||||
userSchema.habitIds = []
|
||||
userSchema.dailyIds = []
|
||||
userSchema.todoIds = []
|
||||
userSchema.rewardIds = []
|
||||
userSchema.tasks = {}
|
||||
else
|
||||
userSchema.habits = []
|
||||
userSchema.dailys = []
|
||||
userSchema.todos = []
|
||||
userSchema.rewards = []
|
||||
|
||||
# deep clone, else further new users get duplicate objects
|
||||
newUser = _.cloneDeep userSchema
|
||||
|
||||
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 = uuid()
|
||||
if isDerby
|
||||
newUser.tasks[guid] = task
|
||||
newUser["#{task.type}Ids"].push guid
|
||||
else
|
||||
newUser["#{task.type}s"].push task
|
||||
|
||||
for tag in defaultTags
|
||||
tag.id = uuid()
|
||||
newUser.tags.push tag
|
||||
|
||||
newUser
|
||||
|
||||
###
|
||||
This allows you to set object properties by dot-path. Eg, you can run pathSet('stats.hp',50,user) which is the same as
|
||||
user.stats.hp = 50. This is useful because in our habitrpg-shared functions we're returning changesets as {path:value},
|
||||
|
||||
Reference in New Issue
Block a user