eggs: some cleanup and passing around of $index so we can retrieve

egg/pot value
This commit is contained in:
Tyler Renelle
2013-10-19 19:58:11 -07:00
parent 378d158a44
commit 017398eb83
2 changed files with 23 additions and 19 deletions

View File

@@ -5,25 +5,32 @@ habitrpg.controller("InventoryCtrl", ['$scope', 'User',
$scope.userEggs = User.user.items.eggs; $scope.userEggs = User.user.items.eggs;
$scope.userHatchingPotions = User.user.items.hatchingPotions; $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) { if (!$scope.selectedPotion) {
$scope.selectedEgg = egg.name; $scope.selectedEgg = eggData;
} else { } 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) { if (!$scope.selectedEgg) {
$scope.selectedPotion = potion; $scope.selectedPotion = potionData;
} else { } else {
$scope.hatch($scope.selectedEgg, potion); $scope.hatch($scope.selectedEgg, potionData);
} }
} }
$scope.ownsPet = function(egg, potion){ $scope.ownsPet = function(egg, potion){
if (!egg || !potion) return; if (!egg || !potion) return;
var pet = egg + '-' + potion; var pet = egg.name + '-' + potion;
return User.user.items.pets && ~User.user.items.pets.indexOf(pet) 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){ $scope.hatch = function(egg, potion){
var pet = $scope.selectedEgg + '-' + $scope.selectedPotion; if ($scope.ownsPet(egg.name, potion.name)){
if ($scope.ownsPet(egg, potion)){
return alert("You already have that pet, hatch a different combo.") return alert("You already have that pet, hatch a different combo.")
} }
var i = _.indexOf($scope.userEggs, $scope.selectedEgg); var pet = egg.name + '-' + potion.name;
$scope.userEggs.splice(i, 1); $scope.userEggs.splice(egg.index, 1);
$scope.userHatchingPotions.splice(potion.index, 1);
i = _.indexOf($scope.userHatchingPotions, $scope.selectedPotion);
$scope.userHatchingPotions.splice(i, 1);
if(!User.user.items.pets) User.user.items.pets = []; if(!User.user.items.pets) User.user.items.pets = [];
User.user.items.pets.push(pet); User.user.items.pets.push(pet);

View File

@@ -6,13 +6,13 @@
menu.pets-menu(label='Eggs ({{userEggs.length}})') menu.pets-menu(label='Eggs ({{userEggs.length}})')
p(ng-show='userEggs.length < 1') You don't have any eggs yet. p(ng-show='userEggs.length < 1') You don't have any eggs yet.
div(ng-repeat='egg in userEggs track by $index') 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}} p {{egg.text}}
li.customize-menu li.customize-menu
menu.hatchingPotion-menu(label='Hatching Potions ({{userHatchingPotions.length}})') menu.hatchingPotion-menu(label='Hatching Potions ({{userHatchingPotions.length}})')
p(ng-show='userHatchingPotions.length < 1') You don't have any hatching potions yet. p(ng-show='userHatchingPotions.length < 1') You don't have any hatching potions yet.
div(ng-repeat='hatchingPotion in userHatchingPotions track by $index') 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}} p {{hatchingPotion}}
.span6 .span6
@@ -20,11 +20,11 @@
.row-fluid(ng-controller='MarketCtrl') .row-fluid(ng-controller='MarketCtrl')
table.NPC-Alex-container table.NPC-Alex-container
tr tr
td(ng-controller='InventoryCtrl') td
button.customize-option.sell-inventory(ng-show='selectedEgg') 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') 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') .NPC-Alex.pull-left(ng-show='!selectedEgg && !selectedPotion')
td td
.popover.static-popover.fade.right.in .popover.static-popover.fade.right.in