refactor: Extract constants into constants file

This commit is contained in:
Blade Barringer
2015-12-26 19:40:36 -06:00
parent ba31cda85d
commit 1b118d86b2
4 changed files with 26 additions and 35 deletions

View File

@@ -0,0 +1,3 @@
export const MAX_HEALTH = 50;
export const MAX_LEVEL = 100;
export const MAX_STAT_POINTS = MAX_LEVEL;

View File

@@ -2,6 +2,11 @@ import {
daysSince,
shouldDo,
} from '../../common/script/cron';
import {
MAX_HEALTH,
MAX_LEVEL,
MAX_STAT_POINTS,
} from './constants';
import * as statHelpers from './statHelpers';
var $w, _, api, content, i18n, moment, preenHistory, sortOrder,
@@ -20,10 +25,9 @@ api = module.exports = {};
api.i18n = i18n;
api.shouldDo = shouldDo;
api.maxLevel = statHelpers.MAX_LEVEL;
api.maxStatPoints = statHelpers.MAX_STAT_POINTS;
api.maxLevel = MAX_LEVEL;
api.capByLevel = statHelpers.capByLevel;
api.maxHealth = statHelpers.MAX_HEALTH;
api.maxHealth = MAX_HEALTH;
api.tnl = statHelpers.toNextLevel;
api.diminishingReturns = statHelpers.diminishingReturns;
@@ -2283,7 +2287,8 @@ api.wrap = function(user, main) {
tnl = api.tnl(user.stats.lvl);
user.stats.hp = 50;
var userTotalStatPoints = user.stats.str + user.stats.int + user.stats.con + user.stats.per;
if (userTotalStatPoints >= api.maxStatPoints) {
if (userTotalStatPoints >= MAX_STAT_POINTS) {
continue;
}
if (user.preferences.automaticAllocation) {

View File

@@ -1,11 +1,13 @@
import {
MAX_LEVEL,
} from './constants';
/*
------------------------------------------------------
Level cap
------------------------------------------------------
*/
export const MAX_LEVEL = 100;
export function capByLevel (lvl) {
if (lvl > MAX_LEVEL) {
return MAX_LEVEL;
@@ -14,22 +16,6 @@ export function capByLevel (lvl) {
}
}
/*
------------------------------------------------------
Stats cap
------------------------------------------------------
*/
export const MAX_STAT_POINTS = MAX_LEVEL;
/*
------------------------------------------------------
Health cap
------------------------------------------------------
*/
export const MAX_HEALTH = 50;
/*
------------------------------------------------------
Scoring

View File

@@ -1,4 +1,3 @@
/* eslint-disable camelcase */
import {
generateUser,
} from '../helpers/common.helper';
@@ -19,31 +18,29 @@ describe('user.fns.updateStats', () => {
});
context('Stat Allocation', () => {
it('Adds an attibute point when user\'s stat points are less than max level', () => {
let stats = {
exp: 3581,
};
it('adds an attibute point when user\'s stat points are less than max level', () => {
user.stats.exp = 3581;
user.stats.lvl = 99;
user.stats.str = 25;
user.stats.int = 25;
user.stats.con = 25;
user.stats.per = 24;
user.fns.updateStats(stats);
user.fns.updateStats(user.stats);
expect(user.stats.points).to.eql(1);
});
it('Does not add an attibute point when user\'s stat points are equal to max level', () => {
let stats = {
exp: 3581,
};
it('does not add an attibute point when user\'s stat points are equal to max level', () => {
user.stats.exp = 3581;
user.stats.lvl = 99;
user.stats.str = 25;
user.stats.int = 25;
user.stats.con = 25;
user.stats.per = 25;
user.fns.updateStats(stats);
user.fns.updateStats(user.stats);
expect(user.stats.points).to.eql(0);
});
});