diff --git a/public/js/controllers/inventoryCtrl.js b/public/js/controllers/inventoryCtrl.js index ce090d18ec..2d60a5d9dd 100644 --- a/public/js/controllers/inventoryCtrl.js +++ b/public/js/controllers/inventoryCtrl.js @@ -12,14 +12,12 @@ habitrpg.controller("InventoryCtrl", ['$rootScope', '$scope', 'User', 'API_URL', // count egg, food, hatchingPotion stack totals var countStacks = function(items) { return _.reduce(items,function(m,v){return m+v;},0);} - // count pets, mounts collected totals - var countExists = function(items) { return _.reduce(items,function(m,v){return m+(v ? 1 : 0);},0);} - $scope.$watch('user.items.pets', function(pets){ $scope.petCount = countExists(pets); }); - $scope.$watch('user.items.mounts', function(mounts){ $scope.mountCount = countExists(mounts); }); - $scope.$watch('user.items.eggs', function(eggs){ $scope.eggCount = countStacks(eggs); }); - $scope.$watch('user.items.hatchingPotions', function(pots){ $scope.potCount = countStacks(pots); }); - $scope.$watch('user.items.food', function(food){ $scope.foodCount = countStacks(food); }); + $scope.$watch('user.items.pets', function(pets){ $scope.petCount = $rootScope.countExists(pets); }, true); + $scope.$watch('user.items.mounts', function(mounts){ $scope.mountCount = $rootScope.countExists(mounts); }, true); + $scope.$watch('user.items.eggs', function(eggs){ $scope.eggCount = countStacks(eggs); }, true); + $scope.$watch('user.items.hatchingPotions', function(pots){ $scope.potCount = countStacks(pots); }, true); + $scope.$watch('user.items.food', function(food){ $scope.foodCount = countStacks(food); }, true); $scope.chooseEgg = function(egg){ if ($scope.selectedEgg && $scope.selectedEgg.name == egg) { diff --git a/public/js/controllers/rootCtrl.js b/public/js/controllers/rootCtrl.js index 98b09b2401..607bd333e7 100644 --- a/public/js/controllers/rootCtrl.js +++ b/public/js/controllers/rootCtrl.js @@ -21,6 +21,9 @@ habitrpg.controller("RootCtrl", ['$scope', '$rootScope', '$location', 'User', '$ return haystack && ~haystack.indexOf(needle); } + // count pets, mounts collected totals, etc + $rootScope.countExists = function(items) {return _.reduce(items,function(m,v){return m+(v?1:0)},0)} + $scope.safeApply = function(fn) { var phase = this.$root.$$phase; if(phase == '$apply' || phase == '$digest') { diff --git a/views/options/inventory/inventory.jade b/views/options/inventory/inventory.jade index febf372a48..f74df36c94 100644 --- a/views/options/inventory/inventory.jade +++ b/views/options/inventory/inventory.jade @@ -7,7 +7,7 @@ script(type='text/ng-template', id='partials/options.inventory.inventory.html') li.customize-menu menu.pets-menu(label='Eggs ({{eggCount}})') - p(ng-show='user.items.eggs.length < 1') You don't have any eggs yet. + p(ng-show='eggCount < 1') You don't have any eggs yet. div(ng-repeat='(egg,points) in ownedItems(user.items.eggs)') //TODO move positioning this styling to css button.customize-option(popover='{{Items.eggs[egg].notes}}', popover-title='{{Items.eggs[egg].text}} Egg', popover-trigger='mouseenter', popover-placement='right', ng-click='chooseEgg(egg)', class='Pet_Egg_{{egg}}', ng-class='{selectableInventory: selectedPotion && !user.items.pets[egg+"-"+selectedPotion.name]}') diff --git a/views/shared/profiles/stats.jade b/views/shared/profiles/stats.jade index 07e8bf7735..0c87b8136b 100644 --- a/views/shared/profiles/stats.jade +++ b/views/shared/profiles/stats.jade @@ -32,7 +32,7 @@ p | : {{userDef(profile.stats.lvl)}} p strong Pets Found - | : {{profile.items.pets.length || 0}} + | : {{countExists(profile.items.pets)}} hr p strong Total Strength