mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
Merge branch 'develop' into sabrecat/more-modals
Conflicts: common/dist/sprites/spritesmith-largeSprites-0.png common/locales/en/front.json
This commit is contained in:
@@ -487,34 +487,7 @@ UserSchema.pre('save', function(next) {
|
||||
|
||||
// Populate new users with default content
|
||||
if (this.isNew){
|
||||
//TODO for some reason this doesn't work here: `_.merge(this, shared.content.userDefaults);`
|
||||
var self = this;
|
||||
_.each(['habits', 'dailys', 'todos', 'rewards', 'tags'], function(taskType){
|
||||
self[taskType] = _.map(shared.content.userDefaults[taskType], function(task){
|
||||
var newTask = _.cloneDeep(task);
|
||||
|
||||
// Render task's text and notes in user's language
|
||||
if(taskType === 'tags'){
|
||||
// tasks automatically get id=helpers.uuid() from TaskSchema id.default, but tags are Schema.Types.Mixed - so we need to manually invoke here
|
||||
newTask.id = shared.uuid();
|
||||
newTask.name = newTask.name(self.preferences.language);
|
||||
}else{
|
||||
newTask.text = newTask.text(self.preferences.language);
|
||||
if(newTask.notes) {
|
||||
newTask.notes = newTask.notes(self.preferences.language);
|
||||
}
|
||||
|
||||
if(newTask.checklist){
|
||||
newTask.checklist = _.map(newTask.checklist, function(checklistItem){
|
||||
checklistItem.text = checklistItem.text(self.preferences.language);
|
||||
return checklistItem;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return newTask;
|
||||
});
|
||||
});
|
||||
_populateDefaultsForNewUser(this);
|
||||
}
|
||||
|
||||
//this.markModified('tasks');
|
||||
@@ -607,6 +580,88 @@ UserSchema.methods.unlink = function(options, cb) {
|
||||
self.save(cb);
|
||||
}
|
||||
|
||||
function _populateDefaultsForNewUser(user) {
|
||||
var taskTypes;
|
||||
|
||||
if (user.registeredThrough === "habitica-web") {
|
||||
taskTypes = ['habits', 'dailys', 'todos', 'rewards', 'tags'];
|
||||
|
||||
var tutorialCommonSections = [
|
||||
'habits',
|
||||
'dailies',
|
||||
'todos',
|
||||
'rewards',
|
||||
'party',
|
||||
'pets',
|
||||
'gems',
|
||||
'skills',
|
||||
'classes',
|
||||
'tavern',
|
||||
'equipment',
|
||||
'items',
|
||||
];
|
||||
|
||||
_.each(tutorialCommonSections, function(section) {
|
||||
user.flags.tutorial.common[section] = true;
|
||||
});
|
||||
} else {
|
||||
taskTypes = ['todos', 'tags']
|
||||
|
||||
user.flags.showTour = false;
|
||||
|
||||
var tourSections = [
|
||||
'showTour',
|
||||
'intro',
|
||||
'classes',
|
||||
'stats',
|
||||
'tavern',
|
||||
'party',
|
||||
'guilds',
|
||||
'challenges',
|
||||
'market',
|
||||
'pets',
|
||||
'mounts',
|
||||
'hall',
|
||||
'equipment',
|
||||
];
|
||||
|
||||
_.each(tourSections, function(section) {
|
||||
user.flags.tour[section] = -2;
|
||||
});
|
||||
}
|
||||
|
||||
_populateDefaultTasks(user, taskTypes);
|
||||
}
|
||||
|
||||
function _populateDefaultTasks (user, taskTypes) {
|
||||
_.each(taskTypes, function(taskType){
|
||||
user[taskType] = _.map(shared.content.userDefaults[taskType], function(task){
|
||||
var newTask = _.cloneDeep(task);
|
||||
|
||||
// Render task's text and notes in user's language
|
||||
if(taskType === 'tags'){
|
||||
// tasks automatically get id=helpers.uuid() from TaskSchema id.default, but tags are Schema.Types.Mixed - so we need to manually invoke here
|
||||
newTask.id = shared.uuid();
|
||||
newTask.name = newTask.name(user.preferences.language);
|
||||
}else{
|
||||
newTask.text = newTask.text(user.preferences.language);
|
||||
if(newTask.notes) {
|
||||
newTask.notes = newTask.notes(user.preferences.language);
|
||||
}
|
||||
|
||||
if(newTask.checklist){
|
||||
newTask.checklist = _.map(newTask.checklist, function(checklistItem){
|
||||
checklistItem.text = checklistItem.text(user.preferences.language);
|
||||
return checklistItem;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return newTask;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.schema = UserSchema;
|
||||
module.exports.model = mongoose.model("User", UserSchema);
|
||||
// Initially export an empty object so external requires will get
|
||||
|
||||
Reference in New Issue
Block a user