Files
habitica/public/js/controllers/notificationCtrl.js
2013-09-17 12:16:16 -04:00

62 lines
1.8 KiB
JavaScript

'use strict';
habitrpg.controller('NotificationCtrl',
['$scope', '$rootScope', 'User', 'Guide', 'Notification', function ($scope, $rootScope, User, Guide, Notification) {
Guide.initTour();
$rootScope.$watch('user.stats.hp', function(after, before) {
if (after == before) return;
Notification.hp(after - before, 'hp');
});
$rootScope.$watch('user.stats.exp', function(after, before) {
if (after == before) return;
Notification.exp(after - before);
});
$rootScope.$watch('user.stats.gp', function(after, before) {
if (after == before) return;
var bonus, money;
var money = after - before;
Notification.gp(money);
//Append Bonus
bonus = User.user._tmp.streakBonus;
if ((money > 0) && !!bonus) {
if (bonus < 0.01) {
bonus = 0.01;
}
Notification.text("+ " + Notification.coins(bonus) + " Streak Bonus!");
delete User.user._tmp.streakBonus;
}
});
$rootScope.$watch('user._tmp.drop', function(after, before){
if (after == before || !after) return;
$rootScope.modals.drop = true;
});
// FIXME: this isn't working for some reason
/*_.each(['weapon', 'head', 'chest', 'shield'], function(watched){
$rootScope.$watch('user.items.' + watched, function(before, after){
if (after == before) return;
if (+after < +before) {
Notification.death();
//don't want to day "lost a head"
if (watched === 'head') watched = 'helm';
Notification.text('Lost GP, 1 LVL, ' + watched);
}
})
});*/
$rootScope.$watch('user.stats.lvl', function(after, before) {
if (after == before) return;
if (after > before) {
Notification.lvl();
}
});
}
]);