mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
fix(quests): Refactoring
Based on feedback from @crookedneighbor and @gisikw. Removes double ternary in the block that normalizes the item type string, and reverts the notification logic to if/else if format instead of switch/case. Also removes a block of commented-out code once used for death notifications.
This commit is contained in:
@@ -59,40 +59,38 @@ habitrpg.controller('NotificationCtrl',
|
|||||||
$rootScope.$watch('user._tmp.drop', function(after, before){
|
$rootScope.$watch('user._tmp.drop', function(after, before){
|
||||||
// won't work when getting the same item twice?
|
// won't work when getting the same item twice?
|
||||||
if (_.isEqual(after, before) || !after) return;
|
if (_.isEqual(after, before) || !after) return;
|
||||||
var text, notes;
|
var text, notes, type;
|
||||||
$rootScope.playSound('Item_Drop');
|
$rootScope.playSound('Item_Drop');
|
||||||
|
|
||||||
if (after.type !== 'gear' && after.type !== 'Quest') {
|
if (after.type !== 'gear' && after.type !== 'Quest') {
|
||||||
var type = (after.type == 'Food') ? 'food' :
|
if (after.type === 'Food') {
|
||||||
(after.type == 'HatchingPotion') ? 'hatchingPotions' : // can we use camelcase and remove this line?
|
type = 'food';
|
||||||
(after.type.toLowerCase() + 's');
|
} else if (after.type === 'HatchingPotion') {
|
||||||
|
type = 'hatchingPotions';
|
||||||
|
} else type = after.type.toLowerCase() + 's';
|
||||||
if(!User.user.items[type][after.key]){
|
if(!User.user.items[type][after.key]){
|
||||||
User.user.items[type][after.key] = 0;
|
User.user.items[type][after.key] = 0;
|
||||||
}
|
}
|
||||||
User.user.items[type][after.key]++;
|
User.user.items[type][after.key]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(after.type) {
|
if (after.type === 'HatchingPotion'){
|
||||||
case 'Quest':
|
|
||||||
$rootScope.selectedQuest = Content.quests[after.key];
|
|
||||||
$rootScope.openModal('questDrop');
|
|
||||||
break;
|
|
||||||
case 'HatchingPotion':
|
|
||||||
text = Content.hatchingPotions[after.key].text();
|
text = Content.hatchingPotions[after.key].text();
|
||||||
notes = Content.hatchingPotions[after.key].notes();
|
notes = Content.hatchingPotions[after.key].notes();
|
||||||
Notification.drop(env.t('messageDropPotion', {dropText: text, dropNotes: notes}), after);
|
Notification.drop(env.t('messageDropPotion', {dropText: text, dropNotes: notes}), after);
|
||||||
break;
|
} else if (after.type === 'Egg'){
|
||||||
case 'Egg':
|
|
||||||
text = Content.eggs[after.key].text();
|
text = Content.eggs[after.key].text();
|
||||||
notes = Content.eggs[after.key].notes();
|
notes = Content.eggs[after.key].notes();
|
||||||
Notification.drop(env.t('messageDropEgg', {dropText: text, dropNotes: notes}), after);
|
Notification.drop(env.t('messageDropEgg', {dropText: text, dropNotes: notes}), after);
|
||||||
break;
|
} else if (after.type === 'Food'){
|
||||||
case 'Food':
|
|
||||||
text = Content.food[after.key].text();
|
text = Content.food[after.key].text();
|
||||||
notes = Content.food[after.key].notes();
|
notes = Content.food[after.key].notes();
|
||||||
Notification.drop(env.t('messageDropFood', {dropArticle: after.article, dropText: text, dropNotes: notes}), after);
|
Notification.drop(env.t('messageDropFood', {dropArticle: after.article, dropText: text, dropNotes: notes}), after);
|
||||||
break;
|
} else if (after.type === 'Quest') {
|
||||||
default:
|
$rootScope.selectedQuest = Content.quests[after.key];
|
||||||
|
$rootScope.openModal('questDrop');
|
||||||
|
} else {
|
||||||
|
// Keep support for another type of drops that might be added
|
||||||
Notification.drop(User.user._tmp.drop.dialog);
|
Notification.drop(User.user._tmp.drop.dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,17 +128,6 @@ habitrpg.controller('NotificationCtrl',
|
|||||||
$rootScope.openModal('achievements/contributor');
|
$rootScope.openModal('achievements/contributor');
|
||||||
});
|
});
|
||||||
|
|
||||||
/*_.each(['weapon', 'head', 'chest', 'shield'], function(watched){
|
|
||||||
$rootScope.$watch('user.items.' + watched, function(before, after){
|
|
||||||
if (after == before) return;
|
|
||||||
if (+after < +before) {
|
|
||||||
//don't want to day "lost a head"
|
|
||||||
if (watched === 'head') watched = 'helm';
|
|
||||||
Notification.text('Lost GP, 1 LVL, ' + watched);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
});*/
|
|
||||||
|
|
||||||
// Classes modal
|
// Classes modal
|
||||||
$rootScope.$watch('!user.flags.classSelected && user.stats.lvl >= 10', function(after, before){
|
$rootScope.$watch('!user.flags.classSelected && user.stats.lvl >= 10', function(after, before){
|
||||||
if(after){
|
if(after){
|
||||||
|
|||||||
Reference in New Issue
Block a user