mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +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.
|
// Make user and settings available for everyone through root scope.
|
||||||
habitrpg.controller('SettingsCtrl',
|
habitrpg.controller('SettingsCtrl',
|
||||||
['$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, $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 = {
|
var RELEASE_ANIMAL_TYPES = {
|
||||||
pets: 'releasePets',
|
pets: 'releasePets',
|
||||||
mounts: 'releaseMounts',
|
mounts: 'releaseMounts',
|
||||||
@@ -164,14 +164,21 @@ habitrpg.controller('SettingsCtrl',
|
|||||||
$scope.restore = function(){
|
$scope.restore = function(){
|
||||||
var stats = $scope.restoreValues.stats,
|
var stats = $scope.restoreValues.stats,
|
||||||
achievements = $scope.restoreValues.achievements;
|
achievements = $scope.restoreValues.achievements;
|
||||||
|
|
||||||
|
if (stats.lvl < 1) {
|
||||||
|
Notification.error(env.t('invalidLevel'), true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
User.set({
|
User.set({
|
||||||
"stats.hp": stats.hp,
|
'stats.hp': stats.hp,
|
||||||
"stats.exp": stats.exp,
|
'stats.exp': stats.exp,
|
||||||
"stats.gp": stats.gp,
|
'stats.gp': stats.gp,
|
||||||
"stats.lvl": stats.lvl,
|
'stats.lvl': stats.lvl,
|
||||||
"stats.mp": stats.mp,
|
'stats.mp': stats.mp,
|
||||||
"achievements.streak": achievements.streak
|
'achievements.streak': achievements.streak
|
||||||
});
|
});
|
||||||
|
$modalStack.dismissAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.reset = function(){
|
$scope.reset = function(){
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
"showBaileyPop": "Bring Bailey the Town Crier out of hiding so you can review past news.",
|
"showBaileyPop": "Bring Bailey the Town Crier out of hiding so you can review past news.",
|
||||||
"fixVal": "Fix Character Values",
|
"fixVal": "Fix Character Values",
|
||||||
"fixValPop": "Manually change values like Health, Level, and Gold.",
|
"fixValPop": "Manually change values like Health, Level, and Gold.",
|
||||||
|
"invalidLevel": "Invalid value: Level must be 1 or greater.",
|
||||||
"enableClass": "Enable Class System",
|
"enableClass": "Enable Class System",
|
||||||
"enableClassPop": "You opted out of the class system initially. Would you like now to opt-in?",
|
"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.",
|
"classTourPop": "Show the tour for using the class system.",
|
||||||
|
|||||||
@@ -495,7 +495,7 @@ let schema = new Schema({
|
|||||||
mp: {type: Number, default: 10},
|
mp: {type: Number, default: 10},
|
||||||
exp: {type: Number, default: 0},
|
exp: {type: Number, default: 0},
|
||||||
gp: {type: Number, default: 0},
|
gp: {type: Number, default: 0},
|
||||||
lvl: {type: Number, default: 1},
|
lvl: {type: Number, default: 1, min: 1},
|
||||||
|
|
||||||
// Class System
|
// Class System
|
||||||
class: {type: String, enum: ['warrior', 'rogue', 'wizard', 'healer'], default: 'warrior', required: true},
|
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')
|
a.btn.btn-sm.btn-warning(ng-controller='FooterCtrl', ng-click='addMissedDay(1)')=env.t('triggerDay')
|
||||||
.modal-footer
|
.modal-footer
|
||||||
button.btn.btn-default(ng-click='$close()')=env.t('discardChanges')
|
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')
|
script(type='text/ng-template', id='modals/delete.html')
|
||||||
.modal-header
|
.modal-header
|
||||||
|
|||||||
Reference in New Issue
Block a user