diff --git a/public/js/controllers/inventoryCtrl.js b/public/js/controllers/inventoryCtrl.js index c45e86da0f..0634ad526c 100644 --- a/public/js/controllers/inventoryCtrl.js +++ b/public/js/controllers/inventoryCtrl.js @@ -5,25 +5,32 @@ habitrpg.controller("InventoryCtrl", ['$scope', 'User', $scope.userEggs = User.user.items.eggs; $scope.userHatchingPotions = User.user.items.hatchingPotions; - $scope.chooseEgg = function(egg){ + $scope.selectedEgg = null; // {index: 1, name: "Tiger", value: 5} + $scope.selectedPotion = null; // {index: 5, name: "Red", value: 3} + + $scope.chooseEgg = function(egg, $index){ + var eggData = _.defaults({index:$index}, egg); if (!$scope.selectedPotion) { - $scope.selectedEgg = egg.name; + $scope.selectedEgg = eggData; } else { - $scope.hatch(egg, $scope.selectedPotion); + $scope.hatch(eggData, $scope.selectedPotion); } } - $scope.choosePotion = function(potion){ + $scope.choosePotion = function(potion, $index){ + // we really didn't think through the way these things are stored and getting passed around... + var potionData = _.findWhere(window.habitrpgShared.items.items.hatchingPotions, {name:potion}); + potionData = _.defaults({index:$index}, potionData); if (!$scope.selectedEgg) { - $scope.selectedPotion = potion; + $scope.selectedPotion = potionData; } else { - $scope.hatch($scope.selectedEgg, potion); + $scope.hatch($scope.selectedEgg, potionData); } } $scope.ownsPet = function(egg, potion){ if (!egg || !potion) return; - var pet = egg + '-' + potion; + var pet = egg.name + '-' + potion; return User.user.items.pets && ~User.user.items.pets.indexOf(pet) } @@ -33,15 +40,12 @@ habitrpg.controller("InventoryCtrl", ['$scope', 'User', } $scope.hatch = function(egg, potion){ - var pet = $scope.selectedEgg + '-' + $scope.selectedPotion; - if ($scope.ownsPet(egg, potion)){ + if ($scope.ownsPet(egg.name, potion.name)){ return alert("You already have that pet, hatch a different combo.") } - var i = _.indexOf($scope.userEggs, $scope.selectedEgg); - $scope.userEggs.splice(i, 1); - - i = _.indexOf($scope.userHatchingPotions, $scope.selectedPotion); - $scope.userHatchingPotions.splice(i, 1); + var pet = egg.name + '-' + potion.name; + $scope.userEggs.splice(egg.index, 1); + $scope.userHatchingPotions.splice(potion.index, 1); if(!User.user.items.pets) User.user.items.pets = []; User.user.items.pets.push(pet); diff --git a/views/options/inventory.jade b/views/options/inventory.jade index 82d2e763cd..dea95f0be6 100644 --- a/views/options/inventory.jade +++ b/views/options/inventory.jade @@ -6,13 +6,13 @@ menu.pets-menu(label='Eggs ({{userEggs.length}})') p(ng-show='userEggs.length < 1') You don't have any eggs yet. div(ng-repeat='egg in userEggs track by $index') - button.customize-option(tooltip='{{egg.text}}', ng-click='chooseEgg(egg)', class='Pet_Egg_{{egg.name}}', ng-class='selectableInventory(egg.name, selectedPotion)') + button.customize-option(tooltip='{{egg.text}}', ng-click='chooseEgg(egg, $index)', class='Pet_Egg_{{egg.name}}', ng-class='selectableInventory(egg, selectedPotion.name)') p {{egg.text}} li.customize-menu menu.hatchingPotion-menu(label='Hatching Potions ({{userHatchingPotions.length}})') p(ng-show='userHatchingPotions.length < 1') You don't have any hatching potions yet. div(ng-repeat='hatchingPotion in userHatchingPotions track by $index') - button.customize-option(tooltip='{{hatchingPotion}}', ng-click='choosePotion(hatchingPotion)', class='Pet_HatchingPotion_{{hatchingPotion}}', ng-class='selectableInventory(selectedEgg, hatchingPotion)') + button.customize-option(tooltip='{{hatchingPotion}}', ng-click='choosePotion(hatchingPotion, $index)', class='Pet_HatchingPotion_{{hatchingPotion}}', ng-class='selectableInventory(selectedEgg, hatchingPotion)') p {{hatchingPotion}} .span6 @@ -20,11 +20,11 @@ .row-fluid(ng-controller='MarketCtrl') table.NPC-Alex-container tr - td(ng-controller='InventoryCtrl') + td button.customize-option.sell-inventory(ng-show='selectedEgg') - | Sell {{selectedEgg}} for 5gp + | Sell {{selectedEgg.name}} for {{selectedEgg.value}} GP button.customize-option.sell-inventory(ng-show='selectedPotion') - | Sell {{selectedPotion}} for 5gp + | Sell {{selectedPotion.name}} for {{selectedPotion.value}} GP .NPC-Alex.pull-left(ng-show='!selectedEgg && !selectedPotion') td .popover.static-popover.fade.right.in