mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Fix character values (#8541)
* Display an error when invalid values are given * Add character values tests for settingsCtrl * Only check for invalid level values * Remove unnecessary validation function * Min level of 1 on user model * (tests) Removed stubbing on restore
This commit is contained in:
@@ -334,4 +334,34 @@ describe('Settings Controller', function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('Fixing character values', function () {
|
||||
describe('#restore', function () {
|
||||
var blankRestoreValues = {
|
||||
stats: {
|
||||
hp: 0,
|
||||
exp: 0,
|
||||
gp: 0,
|
||||
lvl: 0,
|
||||
mp: 0,
|
||||
},
|
||||
achievements: {
|
||||
streak: 0,
|
||||
},
|
||||
};
|
||||
|
||||
it('doesn\'t update character values when level is less than 1', function () {
|
||||
scope.restoreValues = blankRestoreValues;
|
||||
scope.restore();
|
||||
expect(User.set).to.not.be.called;
|
||||
});
|
||||
|
||||
it('updates character values when level is at least 1', function () {
|
||||
scope.restoreValues = blankRestoreValues;
|
||||
scope.restoreValues.stats.lvl = 1;
|
||||
scope.restore();
|
||||
expect(User.set).to.be.called;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
// Make user and settings available for everyone through root scope.
|
||||
habitrpg.controller('SettingsCtrl',
|
||||
['$scope', 'User', '$rootScope', '$http', 'ApiUrl', 'Guide', '$location', '$timeout', 'Content', 'Notification', 'Shared', 'Social', '$compile',
|
||||
function($scope, User, $rootScope, $http, ApiUrl, Guide, $location, $timeout, Content, Notification, Shared, Social, $compile) {
|
||||
['$scope', 'User', '$rootScope', '$http', 'ApiUrl', 'Guide', '$location', '$modalStack', '$timeout', 'Content', 'Notification', 'Shared', 'Social', '$compile',
|
||||
function($scope, User, $rootScope, $http, ApiUrl, Guide, $location, $modalStack, $timeout, Content, Notification, Shared, Social, $compile) {
|
||||
var RELEASE_ANIMAL_TYPES = {
|
||||
pets: 'releasePets',
|
||||
mounts: 'releaseMounts',
|
||||
@@ -164,14 +164,21 @@ habitrpg.controller('SettingsCtrl',
|
||||
$scope.restore = function(){
|
||||
var stats = $scope.restoreValues.stats,
|
||||
achievements = $scope.restoreValues.achievements;
|
||||
|
||||
if (stats.lvl < 1) {
|
||||
Notification.error(env.t('invalidLevel'), true);
|
||||
return;
|
||||
}
|
||||
|
||||
User.set({
|
||||
"stats.hp": stats.hp,
|
||||
"stats.exp": stats.exp,
|
||||
"stats.gp": stats.gp,
|
||||
"stats.lvl": stats.lvl,
|
||||
"stats.mp": stats.mp,
|
||||
"achievements.streak": achievements.streak
|
||||
'stats.hp': stats.hp,
|
||||
'stats.exp': stats.exp,
|
||||
'stats.gp': stats.gp,
|
||||
'stats.lvl': stats.lvl,
|
||||
'stats.mp': stats.mp,
|
||||
'achievements.streak': achievements.streak
|
||||
});
|
||||
$modalStack.dismissAll();
|
||||
}
|
||||
|
||||
$scope.reset = function(){
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
"showBaileyPop": "Bring Bailey the Town Crier out of hiding so you can review past news.",
|
||||
"fixVal": "Fix Character Values",
|
||||
"fixValPop": "Manually change values like Health, Level, and Gold.",
|
||||
"invalidLevel": "Invalid value: Level must be 1 or greater.",
|
||||
"enableClass": "Enable Class System",
|
||||
"enableClassPop": "You opted out of the class system initially. Would you like now to opt-in?",
|
||||
"classTourPop": "Show the tour for using the class system.",
|
||||
|
||||
@@ -495,7 +495,7 @@ let schema = new Schema({
|
||||
mp: {type: Number, default: 10},
|
||||
exp: {type: Number, default: 0},
|
||||
gp: {type: Number, default: 0},
|
||||
lvl: {type: Number, default: 1},
|
||||
lvl: {type: Number, default: 1, min: 1},
|
||||
|
||||
// Class System
|
||||
class: {type: String, enum: ['warrior', 'rogue', 'wizard', 'healer'], default: 'warrior', required: true},
|
||||
|
||||
@@ -55,7 +55,7 @@ script(type='text/ng-template', id='modals/restore.html')
|
||||
a.btn.btn-sm.btn-warning(ng-controller='FooterCtrl', ng-click='addMissedDay(1)')=env.t('triggerDay')
|
||||
.modal-footer
|
||||
button.btn.btn-default(ng-click='$close()')=env.t('discardChanges')
|
||||
button.btn.btn-primary(ng-click='restore(); $close();')=env.t('saveAndClose')
|
||||
button.btn.btn-primary(ng-click='restore()')=env.t('saveAndClose')
|
||||
|
||||
script(type='text/ng-template', id='modals/delete.html')
|
||||
.modal-header
|
||||
|
||||
Reference in New Issue
Block a user