From bcf7c9712e7083aaccde2abb603a63ce48fd5f79 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Wed, 12 Aug 2015 18:53:49 -0500 Subject: [PATCH] Split out potion and armoire out of the itemStore object Fixes #5743 --- common/script/index.coffee | 2 -- test/spec/controllers/tasksCtrlSpec.js | 16 +++++++++++--- website/public/js/controllers/tasksCtrl.js | 9 +++++--- .../tasks/task_view/static_rewards.jade | 22 +++++++++++-------- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/common/script/index.coffee b/common/script/index.coffee index 27b44392f1..eded441aef 100644 --- a/common/script/index.coffee +++ b/common/script/index.coffee @@ -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] diff --git a/test/spec/controllers/tasksCtrlSpec.js b/test/spec/controllers/tasksCtrlSpec.js index 0b5ebd2cc2..28ffa79f0b 100644 --- a/test/spec/controllers/tasksCtrlSpec.js +++ b/test/spec/controllers/tasksCtrlSpec.js @@ -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}); + }); + }); }); diff --git a/website/public/js/controllers/tasksCtrl.js b/website/public/js/controllers/tasksCtrl.js index 6fecc56f57..7eee145e37 100644 --- a/website/public/js/controllers/tasksCtrl.js +++ b/website/public/js/controllers/tasksCtrl.js @@ -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'); diff --git a/website/views/shared/tasks/task_view/static_rewards.jade b/website/views/shared/tasks/task_view/static_rewards.jade index eb737be5dd..7fad52176c 100644 --- a/website/views/shared/tasks/task_view/static_rewards.jade +++ b/website/views/shared/tasks/task_view/static_rewards.jade @@ -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')