habitica/public/js/controllers/petsCtrl.js

32 lines
1.2 KiB
JavaScript
Raw Normal View History

2013-09-03 10:05:54 +00:00
habitrpg.controller("PetsCtrl", ['$scope', 'User',
function($scope, User) {
2013-09-03 08:32:06 +00:00
2013-09-03 10:05:54 +00:00
$scope.userPets = User.user.items.pets;
$scope.userCurrentPet = User.user.items.currentPet;
2013-09-03 08:32:06 +00:00
$scope.pets = window.habitrpgShared.items.items.pets;
$scope.hatchingPotions = window.habitrpgShared.items.items.hatchingPotions;
2013-09-18 14:07:23 +00:00
$scope.totalPets = $scope.pets.length * $scope.hatchingPotions.length;
2013-09-03 08:32:06 +00:00
$scope.hasPet = function(name, potion){
if (!$scope.userPets) return false;
return _.contains($scope.userPets, name + '-' + potion) ? true : false;
}
$scope.isCurrentPet = function(name, potion){
if (!$scope.userCurrentPet || !$scope.userPets) return false;
return $scope.userCurrentPet.str === (name + '-' + potion);
}
$scope.choosePet = function(name, potion){
if($scope.userCurrentPet && $scope.userCurrentPet.str === (name + '-' + potion)){
$scope.userCurrentPet = null;
}else{
var pet = _.find($scope.pets, {name: name});
pet.modifier = potion;
pet.str = name + '-' + potion;
$scope.userCurrentPet = pet;
}
2013-09-03 10:05:54 +00:00
User.set('items.currentPet', $scope.userCurrentPet);
2013-09-03 08:32:06 +00:00
}
}]);