mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
Refactor how cards are recieved
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
"aquaticFriends": "Aquatic Friends",
|
"aquaticFriends": "Aquatic Friends",
|
||||||
"aquaticFriendsText": "Got splashed <%= seafoam %> times by party members.",
|
"aquaticFriendsText": "Got splashed <%= seafoam %> times by party members.",
|
||||||
"valentineCard": "Valentine's Day Card",
|
"valentineCard": "Valentine's Day Card",
|
||||||
|
"valentineCardExplanation": "For enduring such a saccharine poem, you both receive the \"Adoring Friends\" badge!",
|
||||||
"valentineCardNotes": "Send a Valentine's Day card to a party member.",
|
"valentineCardNotes": "Send a Valentine's Day card to a party member.",
|
||||||
"valentine0": "\"Roses are red\n\nMy Dailies are blue\n\nI'm happy that I'm\n\nIn a Party with you!\"",
|
"valentine0": "\"Roses are red\n\nMy Dailies are blue\n\nI'm happy that I'm\n\nIn a Party with you!\"",
|
||||||
"valentine1": "\"Roses are red\n\nViolets are nice\n\nLet's get together\n\nAnd fight against Vice!\"",
|
"valentine1": "\"Roses are red\n\nViolets are nice\n\nLet's get together\n\nAnd fight against Vice!\"",
|
||||||
@@ -33,16 +34,18 @@
|
|||||||
"skiSet": "Ski-sassin (Rogue)",
|
"skiSet": "Ski-sassin (Rogue)",
|
||||||
"snowflakeSet": "Snowflake (Healer)",
|
"snowflakeSet": "Snowflake (Healer)",
|
||||||
"yetiSet": "Yeti Tamer (Warrior)",
|
"yetiSet": "Yeti Tamer (Warrior)",
|
||||||
|
"toAndFromCard": "To: <%= toName %>, From: <%= fromName %>",
|
||||||
"nyeCard": "New Year's Card",
|
"nyeCard": "New Year's Card",
|
||||||
|
"nyeCardExplanation": "For celebrating the new year together, you both receive the \"Auld Acquaintance\" badge!",
|
||||||
"nyeCardNotes": "Send a New Year's card to a party member.",
|
"nyeCardNotes": "Send a New Year's card to a party member.",
|
||||||
"seasonalItems": "Seasonal Items",
|
"seasonalItems": "Seasonal Items",
|
||||||
"auldAcquaintance": "Auld Acquaintance",
|
"auldAcquaintance": "Auld Acquaintance",
|
||||||
"auldAcquaintanceText": "Happy New Year! Sent or received <%= cards %> New Year's cards.",
|
"auldAcquaintanceText": "Happy New Year! Sent or received <%= cards %> New Year's cards.",
|
||||||
"newYear0": "Happy New Year! May you slay many a bad Habit.",
|
"nye0": "Happy New Year! May you slay many a bad Habit.",
|
||||||
"newYear1": "Happy New Year! May you reap many Rewards.",
|
"nye1": "Happy New Year! May you reap many Rewards.",
|
||||||
"newYear2": "Happy New Year! May you earn many a Perfect Day.",
|
"nye2": "Happy New Year! May you earn many a Perfect Day.",
|
||||||
"newYear3": "Happy New Year! May your To-Do list stay short and sweet.",
|
"nye3": "Happy New Year! May your To-Do list stay short and sweet.",
|
||||||
"newYear4": "Happy New Year! May you not get attacked by a raging Hippogriff.",
|
"nye4": "Happy New Year! May you not get attacked by a raging Hippogriff.",
|
||||||
"holidayCard": "Received a holiday card!",
|
"holidayCard": "Received a holiday card!",
|
||||||
"mightyBunnySet": "Mighty Bunny (Warrior)",
|
"mightyBunnySet": "Mighty Bunny (Warrior)",
|
||||||
"magicMouseSet": "Magic Mouse (Mage)",
|
"magicMouseSet": "Magic Mouse (Mage)",
|
||||||
|
|||||||
@@ -1168,9 +1168,9 @@ api.wrap = (user, main=true) ->
|
|||||||
user.stats.mp++ if stat is 'int' #increase their MP along with their max MP
|
user.stats.mp++ if stat is 'int' #increase their MP along with their max MP
|
||||||
cb? null, _.pick(user,$w 'stats')
|
cb? null, _.pick(user,$w 'stats')
|
||||||
|
|
||||||
readValentine: (req,cb) ->
|
readCard: (cardType, cb) ->
|
||||||
user.items.special.valentineReceived.shift()
|
user.items.special["#{cardType}Received"].shift()
|
||||||
user.markModified? 'items.special.valentineReceived'
|
user.markModified? "items.special.#{cardType}Received"
|
||||||
cb? null, 'items.special'
|
cb? null, 'items.special'
|
||||||
|
|
||||||
openMysteryItem: (req,cb,analytics) ->
|
openMysteryItem: (req,cb,analytics) ->
|
||||||
@@ -1191,11 +1191,6 @@ api.wrap = (user, main=true) ->
|
|||||||
(user._tmp?={}).drop = item if typeof window != 'undefined'
|
(user._tmp?={}).drop = item if typeof window != 'undefined'
|
||||||
cb? null, user.items.gear.owned
|
cb? null, user.items.gear.owned
|
||||||
|
|
||||||
readNYE: (req,cb) ->
|
|
||||||
user.items.special.nyeReceived.shift()
|
|
||||||
user.markModified? 'items.special.nyeReceived'
|
|
||||||
cb? null, 'items.special'
|
|
||||||
|
|
||||||
# ------
|
# ------
|
||||||
# Score
|
# Score
|
||||||
# ------
|
# ------
|
||||||
|
|||||||
41
test/common/user.ops.test.js
Normal file
41
test/common/user.ops.test.js
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
var sinon = require('sinon');
|
||||||
|
var chai = require("chai")
|
||||||
|
chai.use(require("sinon-chai"))
|
||||||
|
var expect = chai.expect
|
||||||
|
var _ = require('lodash');
|
||||||
|
|
||||||
|
require('coffee-script');
|
||||||
|
var shared = require('../../common/script/index.coffee');
|
||||||
|
|
||||||
|
describe('user.ops', function() {
|
||||||
|
var user;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
user = {
|
||||||
|
items: {
|
||||||
|
gear: { },
|
||||||
|
special: { }
|
||||||
|
},
|
||||||
|
achievements: { },
|
||||||
|
flags: { }
|
||||||
|
};
|
||||||
|
|
||||||
|
shared.wrap(user);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('readCard', function() {
|
||||||
|
it('removes card from invitation array', function() {
|
||||||
|
user.items.special.valentineReceived = ['Leslie'];
|
||||||
|
user.ops.readCard('valentine');
|
||||||
|
|
||||||
|
expect(user.items.special.valentineReceived).to.be.empty;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('removes the first card from invitation array', function() {
|
||||||
|
user.items.special.valentineReceived = ['Leslie', 'Vicky'];
|
||||||
|
user.ops.readCard('valentine');
|
||||||
|
|
||||||
|
expect(user.items.special.valentineReceived).to.eql(['Vicky']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
describe('Inventory Controller', function() {
|
describe('Inventory Controller', function() {
|
||||||
var scope, ctrl, user, $rootScope;
|
var scope, ctrl, user, rootScope;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
module(function($provide) {
|
module(function($provide) {
|
||||||
@@ -23,6 +23,7 @@ describe('Inventory Controller', function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
scope = $rootScope.$new();
|
scope = $rootScope.$new();
|
||||||
|
rootScope = $rootScope;
|
||||||
|
|
||||||
// Load RootCtrl to ensure shared behaviors are loaded
|
// Load RootCtrl to ensure shared behaviors are loaded
|
||||||
$controller('RootCtrl', {$scope: scope, User: {user: user}, $window: mockWindow});
|
$controller('RootCtrl', {$scope: scope, User: {user: user}, $window: mockWindow});
|
||||||
@@ -109,4 +110,45 @@ describe('Inventory Controller', function() {
|
|||||||
expect(scope.selectedEgg).to.eql(null);
|
expect(scope.selectedEgg).to.eql(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('openCardsModal', function(type, numberOfVariations) {
|
||||||
|
var cardsModalScope;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
cardsModalScope = {};
|
||||||
|
sandbox.stub(rootScope, 'openModal');
|
||||||
|
sandbox.stub(rootScope, '$new').returns(cardsModalScope);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('opens cards modal', function() {
|
||||||
|
scope.openCardsModal('valentine', 4);
|
||||||
|
|
||||||
|
expect(rootScope.openModal).to.be.calledOnce;
|
||||||
|
expect(rootScope.openModal).to.be.calledWith(
|
||||||
|
'cards'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('instantiates a new scope for the modal', function() {
|
||||||
|
scope.openCardsModal('valentine', 4);
|
||||||
|
|
||||||
|
expect(rootScope.$new).to.be.calledOnce;
|
||||||
|
expect(cardsModalScope.cardType).to.eql('valentine');
|
||||||
|
expect(cardsModalScope.cardMessage).to.exist;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('provides a card message', function() {
|
||||||
|
scope.openCardsModal('valentine', 1);
|
||||||
|
|
||||||
|
expect(cardsModalScope.cardMessage).to.eql(env.t('valentine0'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('randomly generates message from x number of messages', function() {
|
||||||
|
var possibleValues = [env.t('valentine0'), env.t('valentine1')];
|
||||||
|
|
||||||
|
scope.openCardsModal('valentine', 2);
|
||||||
|
|
||||||
|
expect(possibleValues).to.contain(cardsModalScope.cardMessage);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -216,7 +216,17 @@ habitrpg.controller("InventoryCtrl",
|
|||||||
$scope.selectedFood = null;
|
$scope.selectedFood = null;
|
||||||
$scope.selectedPotion = null;
|
$scope.selectedPotion = null;
|
||||||
$scope.selectedEgg = null;
|
$scope.selectedEgg = null;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
$scope.openCardsModal = function(type, numberOfVariations) {
|
||||||
|
var cardsModalScope = $rootScope.$new();
|
||||||
|
cardsModalScope.cardType = type;
|
||||||
|
cardsModalScope.cardMessage = _generateCard(type, numberOfVariations);
|
||||||
|
|
||||||
|
$rootScope.openModal('cards', {
|
||||||
|
scope: cardsModalScope
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
function _updateDropAnimalCount(items) {
|
function _updateDropAnimalCount(items) {
|
||||||
$scope.petCount = Shared.count.beastMasterProgress(items.pets);
|
$scope.petCount = Shared.count.beastMasterProgress(items.pets);
|
||||||
@@ -224,5 +234,11 @@ habitrpg.controller("InventoryCtrl",
|
|||||||
$scope.beastMasterProgress = Stats.beastMasterProgress(items.pets);
|
$scope.beastMasterProgress = Stats.beastMasterProgress(items.pets);
|
||||||
$scope.mountMasterProgress = Stats.mountMasterProgress(items.mounts);
|
$scope.mountMasterProgress = Stats.mountMasterProgress(items.mounts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _generateCard(kind, numberOfVariations) {
|
||||||
|
var random = Math.random() * numberOfVariations;
|
||||||
|
var selection = Math.floor(random);
|
||||||
|
return env.t(kind + selection);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -67,7 +67,7 @@
|
|||||||
popover="Valentine's Day Card from {{User.user.items.special.valentineReceived[0]}}",
|
popover="Valentine's Day Card from {{User.user.items.special.valentineReceived[0]}}",
|
||||||
popover-trigger='mouseenter', popover-placement='right',
|
popover-trigger='mouseenter', popover-placement='right',
|
||||||
popover-append-to-body='true',
|
popover-append-to-body='true',
|
||||||
ng-click='openModal("valentine")')
|
ng-click='openCardsModal("valentine", 4)')
|
||||||
.badge.badge-info.stack-count {{user.items.special.valentineReceived.length}}
|
.badge.badge-info.stack-count {{user.items.special.valentineReceived.length}}
|
||||||
|
|
||||||
div(ng-if='user.purchased.plan.customerId || user.purchased.plan.mysteryItems.length')
|
div(ng-if='user.purchased.plan.customerId || user.purchased.plan.mysteryItems.length')
|
||||||
@@ -89,7 +89,7 @@
|
|||||||
popover="New Year's Card from {{User.user.items.special.nyeReceived[0]}}",
|
popover="New Year's Card from {{User.user.items.special.nyeReceived[0]}}",
|
||||||
popover-trigger='mouseenter', popover-placement='right',
|
popover-trigger='mouseenter', popover-placement='right',
|
||||||
popover-append-to-body='true',
|
popover-append-to-body='true',
|
||||||
ng-click='openModal("nye")')
|
ng-click='openCardsModal("nye", 5)')
|
||||||
.badge.badge-info.stack-count {{user.items.special.nyeReceived.length}}
|
.badge.badge-info.stack-count {{user.items.special.nyeReceived.length}}
|
||||||
|
|
||||||
.col-md-6.border-left
|
.col-md-6.border-left
|
||||||
|
|||||||
@@ -1,49 +1,12 @@
|
|||||||
//Valentine
|
script(id='modals/cards.html', type='text/ng-template')
|
||||||
script(id='modals/valentine.html', type='text/ng-template')
|
|
||||||
.modal-header
|
.modal-header
|
||||||
h4
|
.pull-right(class='inventory_special_{{::cardType}}')
|
||||||
.inventory_special_valentine.pull-right
|
h4 {{::env.t(cardType + 'Card')}}
|
||||||
=env.t('valentineCard')
|
|
||||||
.modal-body
|
.modal-body
|
||||||
.bg-info(style='padding:10px')
|
.bg-info(style='padding:10px')
|
||||||
p To: {{user.profile.name}}, From: {{user.items.special.valentineReceived[0]}}
|
p {{::env.t('toAndFromCard', { toName: user.profile.name, fromName: user.items.special[cardType + 'Received'][0]})}}
|
||||||
hr
|
hr
|
||||||
ul.list-unstyled(ng-switch='::Math.floor(Math.random()*4)')
|
markdown(text='{{::cardMessage}}')
|
||||||
li(ng-switch-when='0')
|
|
||||||
markdown(text=env.t('valentine0'))
|
|
||||||
li(ng-switch-when='1')
|
|
||||||
markdown(text=env.t('valentine1'))
|
|
||||||
li(ng-switch-when='2')
|
|
||||||
markdown(text=env.t('valentine2'))
|
|
||||||
li(ng-switch-default)
|
|
||||||
markdown(text=env.t('valentine3'))
|
|
||||||
p
|
|
||||||
small For enduring such a saccharine poem, you both receive the "Adoring Friends" badge!
|
|
||||||
.modal-footer
|
.modal-footer
|
||||||
button.btn.btn-default(ng-click='user.ops.readValentine({});$close()')=env.t('ok')
|
small.pull-left {{::env.t(cardType + 'CardExplanation')}}
|
||||||
|
button.btn.btn-default(ng-click='user.ops.readCard(cardType, {}); $close()')=env.t('ok')
|
||||||
// New Year's
|
|
||||||
script(id='modals/nye.html', type='text/ng-template')
|
|
||||||
.modal-header
|
|
||||||
h4
|
|
||||||
.inventory_special_nye.pull-right
|
|
||||||
=env.t('nyeCard')
|
|
||||||
.modal-body
|
|
||||||
.bg-info(style='padding:10px')
|
|
||||||
p To: {{user.profile.name}}, From: {{user.items.special.nyeReceived[0]}}
|
|
||||||
hr
|
|
||||||
ul.list-unstyled(ng-switch='::Math.floor(Math.random()*5)')
|
|
||||||
li(ng-switch-when='0')
|
|
||||||
=env.t('newYear0')
|
|
||||||
li(ng-switch-when='1')
|
|
||||||
=env.t('newYear1')
|
|
||||||
li(ng-switch-when='2')
|
|
||||||
=env.t('newYear2')
|
|
||||||
li(ng-switch-when='3')
|
|
||||||
=env.t('newYear3')
|
|
||||||
li(ng-switch-default)
|
|
||||||
=env.t('newYear4')
|
|
||||||
p
|
|
||||||
small For celebrating the new year together, you both receive the "Auld Acquaintance" badge!
|
|
||||||
.modal-footer
|
|
||||||
button.btn.btn-default(ng-click='user.ops.readNYE({});$close()')=env.t('ok')
|
|
||||||
|
|||||||
Reference in New Issue
Block a user