Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #247 from HabitRPG/improve_stable
Browse files Browse the repository at this point in the history
Add Collection Repeat to Stable to improve performance
  • Loading branch information
CrokinoleMaster committed Aug 3, 2014
2 parents b0bb69b + f8dbc7f commit 11fc00d
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 46 deletions.
3 changes: 2 additions & 1 deletion gulpfile.js
Expand Up @@ -51,7 +51,8 @@ var paths = {
'scripts/controllers/chatCtrl.js',
'scripts/controllers/inventoryCtrl.js',
'scripts/controllers/petDetailsCtrl.js',
'scripts/controllers/mountDetailsCtrl.js'
'scripts/controllers/mountDetailsCtrl.js',
'scripts/controllers/stableCtrl.js'
],
copy: [
'config.xml',
Expand Down
5 changes: 3 additions & 2 deletions scripts/app.js
Expand Up @@ -144,6 +144,7 @@ var habitrpg = angular.module('habitrpg', ['ionic', 'userServices', 'authService
abstract: true,
views: {
menuContent: {
controller: 'StableCtrl',
templateUrl: 'views/app.stable.html'
}
}
Expand All @@ -158,7 +159,7 @@ var habitrpg = angular.module('habitrpg', ['ionic', 'userServices', 'authService
url: '/mounts',
templateUrl: 'views/app.stable.mounts.html'
})

.state('app.pet-details', {
url: '/pet-details/:pet',
views: {
Expand Down Expand Up @@ -247,4 +248,4 @@ var habitrpg = angular.module('habitrpg', ['ionic', 'userServices', 'authService
}]
})

}])
}])
56 changes: 56 additions & 0 deletions scripts/controllers/stableCtrl.js
@@ -0,0 +1,56 @@
'use strict';

habitrpg
.controller('StableCtrl', ['$scope', '$rootScope', 'User', '$state', function($scope, $rootScope, User, $state) {

$scope.hatchingPotions = env.Content.hatchingPotions;

function toArray(eggs, type) {
var array = [];
if (type) array.push({type: type});
if (type === 'rarePets'){
Object.keys(eggs).forEach(function(key) {
var egg = key.split('-')[0];
var potion = key.split('-')[1];
array.push({egg: egg, potion: potion});
})
return array;
} else {
Object.keys(eggs).forEach(function(key) {
Object.keys($scope.hatchingPotions).forEach(function(potion) {
array.push({egg: eggs[key].key,
potion: $scope.hatchingPotions[potion].key
});
})
})
return array;
}
}

$scope.eggs = toArray(env.Content.dropEggs)
.concat(toArray(env.Content.questEggs, 'questPets'))
.concat(toArray(env.Content.specialPets, 'rarePets'));
$scope.mounts = toArray(env.Content.dropEggs)
.concat(toArray(env.Content.questEggs, 'questMounts'))
.concat(toArray(env.Content.specialPets, 'rareMounts'));

$scope.getPetsHeight = function(item) {
var value = $rootScope.user.items.pets[item.egg+'-'+item.potion]
if (value > 0) {
return 100;
} else if (value < 0) {
return 50;
}
return 80;
};
$scope.getMountsHeight = function(item) {
var value = $rootScope.user.items.pets[item.egg+'-'+item.potion]
if (value) {
return 100;
} else {
return 80;
}
};

}
]);
7 changes: 6 additions & 1 deletion styles/app.styl
Expand Up @@ -118,6 +118,7 @@ for $stage in (worst $worst) (worse $worse) (bad $bad) (neutral $neutral) (good

.stable-pet-icon
float: left
margin-top -20px

.stable-pet-not-owned-icon
float: left
Expand All @@ -133,6 +134,10 @@ for $stage in (worst $worst) (worse $worse) (bad $bad) (neutral $neutral) (good
.costume-list
margin-bottom: 0px

.pet-item
left 0
right 0

// Contributor colors - use until module is updated
$color-contributor-one = #f57a9d
$color-contributor-two = #b93030
Expand Down Expand Up @@ -172,4 +177,4 @@ hrpg-contributor-label-mixin($hrpg-contributor-color)
hrpg-contributor-label-mixin($color-contributor-staff)
.label-npc
hrpg-contributor-label-mixin($color-contributor-npc)
color: #00FF00 !important
color: #00FF00 !important
72 changes: 30 additions & 42 deletions views/app/stable.jade
@@ -1,60 +1,48 @@
mixin petList(source)
each egg in source
each potion in env.Content.hatchingPotions
- pet = egg.key+"-"+potion.key
a.item.item-icon-right(href='#/app/pet-details/#{pet}')
.stable-pet-icon(class="Pet-#{pet}", ng-if='user.items.pets["#{pet}"]>0')
.PixelPaw.stable-pet-not-owned-icon(ng-if='!user.items.pets["#{pet}"]')
p=env.t('petName', {potion: potion.text(env.language.code), egg: egg.text(env.language.code)})
.list
a.pet-item.item.item-icon-right(collection-repeat='item in #{source}' collection-item-width="'100%'" collection-item-height="getPetsHeight(item)" href='#/app/pet-details/{{item.egg+"-"+item.potion}}' ng-style='{height: getPetsHeight(item)}')
div(ng-if='item.potion')
.stable-pet-icon(class="{{'Pet-'+item.egg+\'-\'+item.potion}}", ng-if="user.items.pets[item.egg+'-'+item.potion]>0")
.PixelPaw.stable-pet-not-owned-icon(ng-if="!user.items.pets[item.egg+'-'+item.potion]")
| {{ env.t('petName', {potion: item.potion, egg: item.egg} )}}
i.icon.ion-chevron-right
div(ng-if='!item.potion')
.item.item-divider {{env.t(item.type)}}
.item(ng-if='!user.items.pets["Dragon-Hydra"]')
a(target='_blank', href='http://habitrpg.wikia.com/wiki/Contributing_to_HabitRPG')
.PixelPaw-Gold.stable-pet-not-owned-icon
| Rare pet contributors

mixin mountList(source)
.list
a.pet-item.item.item-icon-right(collection-repeat='item in #{source}' collection-item-width="'100%'" collection-item-height="getMountsHeight(item)" href='#/app/mount-details/{{item.egg+"-"+item.potion}}' ng-style='{height: getMountsHeight(item)}')
div(ng-if='item.potion')
.stable-pet-icon(class="{{'Mount_Head_'+item.egg+\'-\'+item.potion}}", ng-if="user.items.mounts[item.egg+'-'+item.potion]")
.PixelPaw.stable-pet-not-owned-icon(ng-if="!user.items.mounts[item.egg+'-'+item.potion]")
| {{ env.t('mountName', {potion: item.potion, mount: item.egg} )}}
i.icon.ion-chevron-right
div(ng-if='!item.potion')
.item.item-divider {{env.t(item.type)}}

script(id='views/app.stable.html',type='text/ng-template')
+ionContentView('Stable', true)
div(ui-view='')
div(ui-view='')
.tabs
a.tab-item(ng-class='{"tab-item-active": $state.is("app.stable.pets")}', ui-sref='app.stable.pets')=env.t('pets')
a.tab-item(ng-class='{"tab-item-active": $state.is("app.stable.mounts")}', ui-sref='app.stable.mounts')=env.t('mounts')

script(id='views/app.stable.pets.html',type='text/ng-template')
.list
+petList(env.Content.dropEggs)
.item.item-divider=env.t('questPets')
+petList(env.Content.questEggs)
.item.item-divider=env.t('rarePets')
each t,k in env.Content.specialPets
- var egg = k.split('-')[0], pot = k.split('-')[1]
a.item.item-icon-right(href='#/app/pet-details/#{k}', ng-if='user.items.pets["#{k}"]')
.stable-pet-icon(class="Pet-#{k}")
p=env.t(t)
i.icon.ion-chevron-right
.item(ng-if='!user.items.pets["Dragon-Hydra"]')
a(target='_blank', href='http://habitrpg.wikia.com/wiki/Contributing_to_HabitRPG')
.PixelPaw-Gold.stable-pet-not-owned-icon
| Rare pet contributors
+ionContentView('Stable', true)
+petList('eggs')

script(id='views/app.stable.mounts.html',type='text/ng-template')
.list
each egg in env.Content.eggs
each potion in env.Content.hatchingPotions
- mount = egg.key+"-"+potion.key
a.item.item-icon-right(href='#/app/mount-details/#{mount}')
.stable-pet-icon(class="Mount_Head_#{mount}", ng-if="user.items.mounts[\"#{mount}\"]")
.PixelPaw.stable-pet-not-owned-icon(ng-if='!user.items.mounts["#{mount}"]')
p=env.t('mountName', {potion: potion.text(env.language.code), mount: egg.mountText(env.language.code)})
i.icon.ion-chevron-right
.item.item-divider=env.t('rareMounts')
each t,k in env.Content.specialMounts
a.item.item-icon-right(ng-if='user.items.mounts["#{k}"]', href='#/app/mount-details/#{k}')
- var animal = k.split('-')[0], color = k.split('-')[1]
.stable-pet-icon(class="Mount_Head_#{k}")
p=env.t(t)
i.icon.ion-chevron-right
+ionContentView('Stable', true)
+mountList('mounts')

script(id='views/app.pet-details.html',type='text/ng-template')
+ionView('Pet details')
+content()
.list
.item
.item
|{{petDisplayName}}
div(class="Pet-{{pet}}", ng-if='user.items.pets[pet]>0')
.PixelPaw(ng-if='!user.items.pets[pet]')
Expand All @@ -78,7 +66,7 @@ script(id='views/app.mount-details.html',type='text/ng-template')
+ionView('Mount details')
+content()
.list
.item
.item
|{{mountDisplayName}}
div(class="Mount_Head_{{mount}}", ng-if='user.items.mounts[mount]>0')
.PixelPaw(ng-if='!user.items.mounts[mount]')
Expand Down

0 comments on commit 11fc00d

Please sign in to comment.