2013-09-08 16:28:06 +00:00
"use strict" ;
2013-10-22 19:19:43 +00:00
habitrpg . controller ( "UserCtrl" , [ '$rootScope' , '$scope' , '$location' , 'User' , '$http' ,
function ( $rootScope , $scope , $location , User , $http ) {
$scope . profile = User . user ;
$scope . hideUserAvatar = function ( ) {
$ ( ".userAvatar" ) . hide ( ) ;
} ;
2013-10-13 18:47:59 +00:00
2013-10-22 19:19:43 +00:00
$scope . $watch ( '_editing.profile' , function ( value ) {
if ( value === true ) $scope . editingProfile = angular . copy ( User . user . profile ) ;
2013-10-13 18:47:59 +00:00
} ) ;
2013-11-16 10:22:12 +00:00
$scope . allocate = function ( stat ) {
2013-12-11 16:30:39 +00:00
User . user . ops . allocate ( { query : { stat : stat } } ) ;
2013-11-16 10:22:12 +00:00
}
2013-12-11 16:30:39 +00:00
$scope . changeClass = function ( klass ) {
if ( ! klass ) {
if ( ! confirm ( "Are you sure you want to re-roll? This will reset your character's class and allocated points (you'll get them all back to re-allocate)" ) )
return ;
return User . user . ops . changeClass ( { } ) ;
}
2013-12-06 22:41:58 +00:00
2013-12-11 16:30:39 +00:00
User . user . ops . changeClass ( { query : { class : klass } } ) ;
2013-12-06 17:51:15 +00:00
$scope . selectedClass = undefined ;
2013-12-06 22:41:58 +00:00
2013-12-11 16:30:39 +00:00
User . user . fns . updateStore ( ) ;
2013-12-06 17:51:15 +00:00
}
2013-11-16 10:22:12 +00:00
2013-10-22 19:19:43 +00:00
$scope . save = function ( ) {
var values = { } ;
_ . each ( $scope . editingProfile , function ( value , key ) {
// Using toString because we need to compare two arrays (websites)
2013-10-23 17:24:24 +00:00
var curVal = $scope . profile . profile [ key ] ;
if ( ! curVal || $scope . editingProfile [ key ] . toString ( ) !== curVal . toString ( ) )
values [ 'profile.' + key ] = value ;
2013-10-22 19:19:43 +00:00
} ) ;
2013-12-11 16:30:39 +00:00
User . set ( values ) ;
2013-10-22 19:19:43 +00:00
$scope . _editing . profile = false ;
}
2013-12-11 16:30:39 +00:00
/ * *
* 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 = fullSet ? 1.25 : 0.5 ; // 5G per set, 2G per individual
if ( fullSet ) {
if ( confirm ( "Purchase for 5 Gems?" ) !== true ) return ;
if ( User . user . balance < cost ) return $rootScope . modals . buyGems = true ;
} else if ( ! User . user . fns . dotGet ( 'purchased.' + path ) ) {
if ( confirm ( "Purchase for 2 Gems?" ) !== true ) return ;
if ( User . user . balance < cost ) return $rootScope . modals . buyGems = true ;
}
User . user . ops . unlock ( { query : { path : path } } )
}
2013-10-22 20:59:30 +00:00
2013-09-08 16:28:06 +00:00
}
2013-10-22 19:19:43 +00:00
] ) ;