0817cf96e1
* pull apart achievements into different subcategories
* achievs previously hidden to others if unachieved are now always shown
* achievs previously always hidden if unachieved are now always shown
* pull apart ultimate gear achievs
* add achiev wrapper mixin
* add achiev mixin for simple counts
* add achiev mixin for singular/plural achievs
* add simpleAchiev mixin and support attributes
* always hide potentially unearnable achievs if unearned
* contributor achiev now uses string interpolation for readMore link
* transition to basic achiev grid layout
* fix npc achievement img bug introduced in c90f7e2
* move surveys and contributor achievs into special section so it is never empty
* double size of achievs in achievs grid
* achievs in grid are muted if unachieved (includes recompiled sprites)
* fix streak notification strings
* add counts to achievement badges for applicable achieved achievs
* list achievements by api
* fix achievement strings in new api
* unearned achievs now use dedicated (WIP) 'unearned' badge instead of muted versions of the normal badges
* fix & cleanup achievements api
* extract generation of the achievements result to a class
* clean up achievement counter css using existing classes
* simplify exports of new achievementBuilder lib
* remove class logic from achievementBuilder lib
* move achievs to common, add rebirth achiev logic, misc fixes
* replace achievs jade logic with results of api call
* fix linting errors
* achievs lib now returns achievs object subdivided by type (basic/seasonal/special
* add tests for new achievs lib
* fix linting errors
* update controllers and views for updated achievs lib
* add indices to achievements to preserve intended order
* move achiev popovers to left
* rename achievs lib to achievements
* adjust positioning of achieve popovers now that stats and achievs pages
are separate
* fix: achievements api correctly decides whether to append extra string for master and triadBingo achievs
* revert compiled sprites so they don't bog down the PR
* pull out achievs api integration tests
* parameterize ultimate gear achievements' text string
* break out static achievement data from user-specific data
* reorg content.achievements to add achiev data in related chunks
* cleanup, respond to feedback
* improve api documentation
* fix merge issues
* Helped Habit Grow --> Helped Habitica Grow
* achievement popovers are muted if the achiev is unearned
* fix singular achievement labels / achievement popover on click
* update apidoc for achievements (description, param-type, successExample, error-types)
* fix whitespace issues in members.js
* move html to a variable
* updated json example
* fix syntax after merge
181 lines
5.0 KiB
JavaScript
181 lines
5.0 KiB
JavaScript
'use strict'
|
|
/**
|
|
Set up "+1 Exp", "Level Up", etc notifications
|
|
*/
|
|
angular.module("habitrpg").factory("Notification",
|
|
['$filter', 'Shared', '$rootScope', function($filter, Shared, $rootScope) {
|
|
|
|
/**
|
|
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) {
|
|
return "" + gold + " <span class='notification-icon shop_gold'></span> " + silver + " <span class='notification-icon shop_silver'></span>";
|
|
} else if (gold > 0) {
|
|
return "" + gold + " <span class='notification-icon shop_gold'></span>";
|
|
} else if (silver > 0) {
|
|
return "" + silver + " <span class='notification-icon shop_silver'></span>";
|
|
}
|
|
}
|
|
|
|
function crit(val) {
|
|
_notify(window.env.t('critBonus') + Math.round(val) + "%", 'crit', 'glyphicon glyphicon-certificate');
|
|
}
|
|
|
|
function drop(val, item) {
|
|
var dropClass = "";
|
|
if ( item !== undefined ) {
|
|
switch ( item.type ) {
|
|
case "Egg":
|
|
dropClass = 'Pet_Egg_' + item.key;
|
|
break;
|
|
case "HatchingPotion":
|
|
dropClass = 'Pet_HatchingPotion_' + item.key;
|
|
break;
|
|
case "Food":
|
|
dropClass = 'Pet_Food_' + item.key;
|
|
break;
|
|
case "armor":
|
|
case "back":
|
|
case "body":
|
|
case "eyewear":
|
|
case "head":
|
|
case "headAccessory":
|
|
case "shield":
|
|
case "weapon":
|
|
dropClass = 'shop_' + item.key;
|
|
break;
|
|
default:
|
|
dropClass = 'glyphicon glyphicon-gift';
|
|
}
|
|
}
|
|
_notify(val, 'drop', dropClass);
|
|
}
|
|
|
|
function quest(type, val) {
|
|
_notify(window.env.t(type, { val: val }), 'success');
|
|
}
|
|
|
|
function exp(val) {
|
|
if (val < -50) return; // don't show when they level up (resetting their exp)
|
|
_notify(_sign(val) + " " + _round(val) + " " + window.env.t('experience'), 'xp', 'glyphicon glyphicon-star');
|
|
}
|
|
|
|
function error(error, canHide){
|
|
_notify(error, "danger", 'glyphicon glyphicon-exclamation-sign', canHide);
|
|
}
|
|
|
|
function gp(val, bonus) {
|
|
_notify(_sign(val) + " " + coins(val - bonus), 'gp');
|
|
}
|
|
|
|
function hp(val) {
|
|
// don't show notifications if user dead
|
|
_notify(_sign(val) + " " + _round(val) + " " + window.env.t('health'), 'hp', 'glyphicon glyphicon-heart');
|
|
}
|
|
|
|
function lvl(){
|
|
_notify(window.env.t('levelUp'), 'lvl', 'glyphicon glyphicon-chevron-up');
|
|
}
|
|
|
|
function markdown(val){
|
|
if (val) {
|
|
var parsed_markdown = $filter("markdown")(val);
|
|
_notify(parsed_markdown, 'info');
|
|
}
|
|
}
|
|
|
|
function mp(val) {
|
|
_notify(_sign(val) + " " + _round(val) + " " + window.env.t('mana'), 'mp', 'glyphicon glyphicon-fire');
|
|
}
|
|
|
|
function streak(val) {
|
|
_notify(window.env.t('streaks') + ': ' + val, 'streak', 'glyphicon glyphicon-repeat');
|
|
}
|
|
|
|
function text(val, onClick){
|
|
if (val) {
|
|
_notify(val, 'info', null, null, onClick);
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------
|
|
// Private Methods
|
|
//--------------------------------------------------
|
|
|
|
function _sign(number){
|
|
return number?number<0?'-':'+':'+';
|
|
}
|
|
|
|
function _round(number){
|
|
return Math.abs(number.toFixed(1));
|
|
}
|
|
|
|
// Used to stack notifications, must be outside of _notify
|
|
var stack_topright = {"dir1": "down", "dir2": "left", "spacing1": 15, "spacing2": 15, "firstpos1": 60};
|
|
|
|
function _notify(html, type, icon, canHide, onClick) {
|
|
var notice = $.pnotify({
|
|
type: type || 'warning', //('info', 'text', 'warning', 'success', 'gp', 'xp', 'hp', 'lvl', 'death', 'mp', 'crit')
|
|
text: html,
|
|
opacity: 1,
|
|
addclass: 'alert-' + type,
|
|
delay: 7000,
|
|
hide: ((type == 'error' || type == 'danger') && !canHide) ? false : true,
|
|
mouse_reset: false,
|
|
width: "250px",
|
|
stack: stack_topright,
|
|
icon: icon || false
|
|
}).click(function() {
|
|
notice.pnotify_remove();
|
|
|
|
if (onClick) {
|
|
onClick();
|
|
}
|
|
});
|
|
}
|
|
|
|
// Login incentive
|
|
// @TODO: Document reward data param
|
|
// @TODO: loadWidgets is a circular dependency but we should not inject it this way
|
|
function showLoginIncentive (user, rewardData, loadWidgets) {
|
|
var modalScope = $rootScope.$new();
|
|
modalScope.data = rewardData;
|
|
var nextRewardKey = Shared.content.loginIncentives[user.loginIncentives].nextRewardAt;
|
|
modalScope.nextReward = Shared.content.loginIncentives[nextRewardKey];
|
|
modalScope.user = user;
|
|
// modalScope.loadWidgets = Social.loadWidgets;
|
|
modalScope.loadWidgets = loadWidgets;
|
|
|
|
var modalKey = 'login-incentives';
|
|
if (rewardData.rewardKey) {
|
|
modalKey = 'login-incentives-reward-unlocked';
|
|
}
|
|
|
|
$rootScope.openModal(modalKey, {
|
|
scope: modalScope
|
|
});
|
|
}
|
|
|
|
return {
|
|
coins: coins,
|
|
crit: crit,
|
|
drop: drop,
|
|
exp: exp,
|
|
error: error,
|
|
gp: gp,
|
|
hp: hp,
|
|
lvl: lvl,
|
|
markdown: markdown,
|
|
mp: mp,
|
|
streak: streak,
|
|
text: text,
|
|
quest: quest,
|
|
showLoginIncentive: showLoginIncentive,
|
|
};
|
|
}]);
|