From 53fb0ec8b04534afe176ba68f8ed4e0c120d760a Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Sat, 18 Jul 2015 14:50:02 -0500 Subject: [PATCH] Add display experience function --- test/spec/services/statServicesSpec.js | 18 ++++++++++++++++++ website/public/js/services/statServices.js | 9 +++++++++ 2 files changed, 27 insertions(+) diff --git a/test/spec/services/statServicesSpec.js b/test/spec/services/statServicesSpec.js index 6b0b2edec7..35e53109a1 100644 --- a/test/spec/services/statServicesSpec.js +++ b/test/spec/services/statServicesSpec.js @@ -66,6 +66,24 @@ describe('Stats Service', function() { }); }); + describe('expDisplay', function() { + it('displays exp as "exp / toNextLevelExp"', function() { + user.stats.exp = 10; + user.stats.lvl = 29; + var expDisplay = statCalc.expDisplay(user); + + expect(expDisplay).to.eql('10/640'); + }); + + it('Rounds exp down when given a decimal', function() { + user.stats.exp = 10.999; + user.stats.lvl = 29; + var expDisplay = statCalc.expDisplay(user); + + expect(expDisplay).to.eql('10/640'); + }); + }); + describe('levelBonus', function() { it('calculates bonus as half of level for even numbered level under 100', function() { var level = 50; diff --git a/website/public/js/services/statServices.js b/website/public/js/services/statServices.js index b2418c6900..c05afb3390 100644 --- a/website/public/js/services/statServices.js +++ b/website/public/js/services/statServices.js @@ -33,6 +33,14 @@ return display; } + function expDisplay(user) { + var exp = Math.floor(user.stats.exp); + var toNextLevel = Shared.tnl(user.stats.lvl); + var display = exp + '/' + toNextLevel; + + return display; + } + function levelBonus(level) { // Level bonus is derived by taking the level, subtracting one, // taking the smaller of it or maxLevel (100), @@ -80,6 +88,7 @@ return { classBonus: classBonus, equipmentStatBonus: equipmentStatBonus, + expDisplay: expDisplay, goldDisplay: goldDisplay, hpDisplay: hpDisplay, levelBonus: levelBonus,