Files
habitica/website/client-old/js/controllers/userCtrl.js
Kaitlin Hipkin 0817cf96e1 Achievement list renovation & Achievements API (#7904)
* 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
2016-12-13 12:48:18 -06:00

113 lines
4.3 KiB
JavaScript

"use strict";
habitrpg.controller("UserCtrl", ['$rootScope', '$scope', '$location', 'User', '$http', '$state', 'Guide', 'Shared', 'Content', 'Stats', 'Social', 'Costume',
function($rootScope, $scope, $location, User, $http, $state, Guide, Shared, Content, Stats, Social, Costume) {
$scope.profile = User.user;
$scope.statCalc = Stats;
$scope.loadWidgets = Social.loadWidgets;
$scope.hideUserAvatar = function() {
$(".userAvatar").hide();
};
$scope.$watch('_editing.profile', function(value){
if(value === true) $scope.editingProfile = angular.copy(User.user.profile);
});
$scope.costume = Costume;
$scope.allocate = function(stat){
User.allocate({query:{stat:stat}});
}
$scope.changeClass = function(klass){
if (!klass) {
if (!confirm(window.env.t('sureReset')))
return;
return User.changeClass({});
}
User.changeClass({query:{class:klass}});
$scope.selectedClass = undefined;
Shared.updateStore(User.user);
Guide.goto('classes', 0,true);
}
$scope.save = function(){
var values = {};
_.each($scope.editingProfile, function(value, key){
// Using toString because we need to compare two arrays (websites)
var curVal = $scope.profile.profile[key];
if(!curVal || $scope.editingProfile[key].toString() !== curVal.toString())
values['profile.' + key] = value;
});
User.set(values);
$scope._editing.profile = false;
}
$scope.acknowledgeHealthWarning = function(){
User.set({'flags.warnedLowHealth':true});
}
$scope.backgroundShopSets = Shared.shops.getBackgroundShopSets();
/**
* For gem-unlockable preferences, (a) if owned, select preference (b) else, purchase
* @param path: User.preferences <-> User.purchased maps like User.preferences.skin=abc <-> User.purchased.skin.abc.
* Pass in this paramater as "skin.abc". Alternatively, pass as an array ["skin.abc", "skin.xyz"] to unlock sets
*/
$scope.unlock = function(path){
var fullSet = ~path.indexOf(',');
var cost =
~path.indexOf('background.') ?
(fullSet ? 3.75 : 1.75) : // (Backgrounds) 15G per set, 7G per individual
(fullSet ? 1.25 : 0.5); // (Hair, skin, etc) 5G per set, 2G per individual
if (path.indexOf('background.blue') === -1 && path.indexOf('background.green') === -1 && path.indexOf('background.red') === -1 && path.indexOf('background.purple') === -1 && path.indexOf('background.yellow') === -1) {
if (fullSet) {
if (confirm(window.env.t('purchaseFor',{cost:cost*4})) !== true) return;
if (User.user.balance < cost) return $rootScope.openModal('buyGems');
} else if (!_.get(User.user, 'purchased.' + path)) {
if (confirm(window.env.t('purchaseFor',{cost:cost*4})) !== true) return;
if (User.user.balance < cost) return $rootScope.openModal('buyGems');
}
}
User.unlock({query:{path:path}})
}
$scope.ownsSet = function(type, _set) {
return !_.find(_set,function(v,k) {
if (type === 'background') k = v.key;
return !User.user.purchased[type][k];
});
};
$scope.setKeys = function(type, _set) {
return _.map(_set, function(v,k) {
if (type === 'background') k = v.key;
return type+'.'+k;
}).join(',');
};
$scope.getProgressDisplay = function () {
var currentLoginDay = Content.loginIncentives[$scope.profile.loginIncentives];
var nextRewardAt = currentLoginDay.nextRewardAt;
if (!currentLoginDay.prevRewardKey) currentLoginDay.prevRewardKey = 0;
return ' ' + ($scope.profile.loginIncentives - currentLoginDay.prevRewardKey) + '/' + (nextRewardAt - currentLoginDay.prevRewardKey);
};
$scope.incentivesProgress = function () {
var currentLoginDay = Content.loginIncentives[$scope.profile.loginIncentives];
var previousRewardDay = currentLoginDay.prevRewardKey;
var nextRewardAt = currentLoginDay.nextRewardAt;
return ($scope.profile.loginIncentives - previousRewardDay)/(nextRewardAt - previousRewardDay) * 100;
};
$scope.achievements = Shared.achievements.getAchievementsForProfile($scope.profile);
$scope.achievPopoverPlacement = 'right';
$scope.achievAppendToBody = 'true'; // append-to-body breaks popovers in modal windows
}
]);