2013-09-17 15:43:05 +00:00
|
|
|
/**
|
|
|
|
|
Set up "+1 Exp", "Level Up", etc notifications
|
|
|
|
|
*/
|
|
|
|
|
angular.module("notificationServices", [])
|
2013-12-15 04:58:53 +00:00
|
|
|
.factory("Notification", [function() {
|
2013-09-17 15:43:05 +00:00
|
|
|
function growl(html, type) {
|
|
|
|
|
$.bootstrapGrowl(html, {
|
|
|
|
|
ele: '#notification-area',
|
2014-02-05 18:05:42 +00:00
|
|
|
type: type || 'warning', //('info', 'text', 'warning', 'success', 'gp', 'xp', 'hp', 'lvl', 'death', 'mp', 'crit')
|
2014-03-22 16:37:21 +00:00
|
|
|
top_offset: 60,
|
2013-09-17 15:43:05 +00:00
|
|
|
align: 'right', //('left', 'right', or 'center')
|
|
|
|
|
width: 250, //(integer, or 'auto')
|
2014-02-12 18:10:45 +00:00
|
|
|
delay: (type=='error') ? 0 : 7000,
|
2013-09-17 15:43:05 +00:00
|
|
|
allow_dismiss: true,
|
2014-03-22 16:37:21 +00:00
|
|
|
stackup_spacing: 10 // spacing between consecutive stacked growls.
|
2013-08-28 00:07:28 +00:00
|
|
|
});
|
2013-09-17 15:43:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Show "+ 5 {gold_coin} 3 {silver_coin}"
|
|
|
|
|
*/
|
|
|
|
|
function coins(money) {
|
|
|
|
|
var absolute, gold, silver;
|
|
|
|
|
absolute = Math.abs(money);
|
|
|
|
|
gold = Math.floor(absolute);
|
|
|
|
|
silver = Math.floor((absolute - gold) * 100);
|
|
|
|
|
if (gold && silver > 0) {
|
2014-02-12 14:10:22 +00:00
|
|
|
return "" + gold + " <span class='notification-icon shop_gold'></span> " + silver + " <span class='notification-icon shop_silver'></span>";
|
2013-09-17 15:43:05 +00:00
|
|
|
} else if (gold > 0) {
|
2014-02-12 14:10:22 +00:00
|
|
|
return "" + gold + " <span class='notification-icon shop_gold'></span>";
|
2013-09-17 15:43:05 +00:00
|
|
|
} else if (silver > 0) {
|
2014-02-12 14:10:22 +00:00
|
|
|
return "" + silver + " <span class='notification-icon shop_silver'></span>";
|
2013-08-28 00:07:28 +00:00
|
|
|
}
|
2013-09-17 15:43:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var sign = function(number){
|
|
|
|
|
return number?number<0?'-':'+':'+';
|
2013-08-28 00:07:28 +00:00
|
|
|
}
|
2013-09-17 15:43:05 +00:00
|
|
|
|
|
|
|
|
var round = function(number){
|
|
|
|
|
return Math.abs(number.toFixed(1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
coins: coins,
|
|
|
|
|
hp: function(val) {
|
|
|
|
|
// don't show notifications if user dead
|
2014-02-06 16:36:33 +00:00
|
|
|
growl("<span class='glyphicon glyphicon-heart'></span> " + sign(val) + " " + round(val) + " " + window.env.t('hp'), 'hp');
|
2013-09-17 15:43:05 +00:00
|
|
|
},
|
|
|
|
|
exp: function(val) {
|
|
|
|
|
if (val < -50) return; // don't show when they level up (resetting their exp)
|
2014-02-06 16:36:33 +00:00
|
|
|
growl("<span class='glyphicon glyphicon-star'></span> " + sign(val) + " " + round(val) + " " + window.env.t('xp'), 'xp');
|
2013-09-17 15:43:05 +00:00
|
|
|
},
|
2014-01-07 17:14:34 +00:00
|
|
|
gp: function(val, bonus) {
|
|
|
|
|
growl(sign(val) + " " + coins(val - bonus), 'gp');
|
2013-09-17 15:43:05 +00:00
|
|
|
},
|
|
|
|
|
text: function(val){
|
|
|
|
|
growl(val);
|
|
|
|
|
},
|
|
|
|
|
lvl: function(){
|
2014-02-06 16:36:33 +00:00
|
|
|
growl('<span class="glyphicon glyphicon-chevron-up"></span> ' + window.env.t('levelUp'), 'lvl');
|
2013-09-17 15:43:05 +00:00
|
|
|
},
|
2013-10-30 18:29:46 +00:00
|
|
|
error: function(error){
|
2014-02-05 18:05:42 +00:00
|
|
|
growl("<span class='glyphicon glyphicon-exclamation-sign'></span> " + error, "danger");
|
2013-12-26 13:31:00 +00:00
|
|
|
},
|
|
|
|
|
mp: function(val) {
|
2014-02-06 16:36:33 +00:00
|
|
|
growl("<span class='glyphicon glyphicon-fire'></span> " + sign(val) + " " + round(val) + " " + window.env.t('mp'), 'mp');
|
2014-01-07 18:03:07 +00:00
|
|
|
},
|
|
|
|
|
crit: function(val) {
|
2014-02-06 16:36:33 +00:00
|
|
|
growl("<span class='glyphicon glyphicon-certificate'></span> " + window.env.t('critBonus') + Math.round(val) + "%", 'crit');
|
2014-01-15 04:02:22 +00:00
|
|
|
},
|
|
|
|
|
drop: function(val) {
|
2014-02-04 19:53:09 +00:00
|
|
|
growl("<span class='glyphicon glyphicon-gift'></span> " + val, 'drop');
|
2013-09-17 15:43:05 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
]);
|