Split out potion and armoire out of the itemStore object

Fixes #5743
This commit is contained in:
Blade Barringer
2015-08-12 18:53:49 -05:00
parent 60f92a8997
commit bcf7c9712e
4 changed files with 32 additions and 17 deletions

View File

@@ -202,8 +202,6 @@ api.updateStore = (user) ->
# Add special items (contrib gear, backer gear, etc)
changes = changes.concat _.filter content.gear.flat, (v) ->
v.klass in ['special','mystery','armoire'] and !user.items.gear.owned[v.key] and v.canOwn?(user)
changes.push content.potion
if user.flags.armoireEnabled then changes.push content.armoire
# Return sorted store (array)
_.sortBy changes, (c)->sortOrder[c.type]

View File

@@ -1,7 +1,7 @@
'use strict';
describe('Tasks Controller', function() {
var $rootScope, scope, user, ctrl;
var $rootScope, shared, scope, user, ctrl;
beforeEach(function() {
user = specHelper.newUser();
@@ -10,10 +10,10 @@ describe('Tasks Controller', function() {
$provide.value('Guide', {});
});
inject(function($rootScope, $controller){
inject(function($rootScope, $controller, Shared){
scope = $rootScope.$new();
shared = Shared;
$controller('RootCtrl', {$scope: scope, User: {user: user}});
ctrl = $controller('TasksCtrl', {$scope: scope, User: {user: user}});
@@ -28,4 +28,14 @@ describe('Tasks Controller', function() {
});
});
});
describe('watch to updateStore', function() {
it('updates itemStore when user gear changes', function() {
sinon.stub(shared, 'updateStore').returns({item: true});
user.items.gear.owned.foo = true;
scope.$digest();
expect(scope.itemStore).to.eql({item: true});
});
});
});

View File

@@ -1,7 +1,7 @@
"use strict";
habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','Notification', '$http', 'ApiUrl', '$timeout', 'Shared', 'Guide', 'Tasks', 'Analytics',
function($scope, $rootScope, $location, User, Notification, $http, ApiUrl, $timeout, Shared, Guide, Tasks, Analytics) {
habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','Notification', '$http', 'ApiUrl', '$timeout', 'Content', 'Shared', 'Guide', 'Tasks', 'Analytics',
function($scope, $rootScope, $location, User, Notification, $http, ApiUrl, $timeout, Content, Shared, Guide, Tasks, Analytics) {
$scope.obj = User.user; // used for task-lists
$scope.user = User.user;
@@ -212,10 +212,13 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User','N
------------------------
*/
$scope.$watchGroup(['user.items.gear.owned', 'user.flags.armoireEnabled'], function(){
$scope.$watch('user.items.gear.owned', function(){
$scope.itemStore = Shared.updateStore(User.user);
},true);
$scope.healthPotion = Content.potion;
$scope.armoire = Content.armoire;
$scope.buy = function(item) {
User.user.ops.buy({params:{key:item.key}});
$rootScope.playSound('Reward');

View File

@@ -1,18 +1,22 @@
ul.items.rewards(ng-if='main && list.type=="reward"')
li.task.reward-item(ng-repeat='item in itemStore',popover-trigger='mouseenter', popover-placement='top', popover='{{item.key == "armoire" && !user.flags.armoireEmpty ? env.t("armoireNotesFull") + armoireCount(user.items.gear.owned) : item.notes()}}')
mixin reward(item)
li.task.reward-item(popover-trigger='mouseenter', popover-placement='top', popover='{{::#{item}.notes()}}')&attributes(attributes)
// right-hand side control buttons
.task-meta-controls
span.task-notes
span.glyphicon.glyphicon-comment
//left-hand size commands
.task-controls.task-primary
input.visuallyhidden(
class="reward",
input.reward.visuallyhidden(
type='checkbox',
ui-keypress='{13:"buy(item)"}')
a.money.btn-buy.item-btn(ng-class='{highValue: item.value >= 1000}', ng-click='buy(item)')
ui-keypress='{13:"buy(#{item})"}')
a.money.btn-buy.item-btn(ng-class='::{highValue: #{item}.value >= 1000}', ng-click='::buy(#{item})')
span.shop_gold
span.reward-cost {{item.value}}
span.reward-cost {{::#{item}.value}}
// main content
span(ng-class='::{"shop_{{item.key}} shop-sprite item-img": true}').reward-img
p.task-text {{item.text()}}
span(ng-class='::{"shop_{{#{item}.key}} shop-sprite item-img": true}').reward-img
p.task-text {{::#{item}.text()}}
ul.items.rewards(ng-if='main && list.type=="reward"')
+reward('item')(ng-repeat='item in itemStore')
+reward('healthPotion')
+reward('armoire')(ng-if='user.flags.armoireEnabled')