From 17ef7e28850e1e6a933e5d20fec686b86a221db6 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Sat, 18 Jul 2015 13:12:11 -0500 Subject: [PATCH] Add hpDisplay function --- test/spec/services/statServicesSpec.js | 17 +++++++++++++++++ website/public/js/services/statServices.js | 9 +++++++++ 2 files changed, 26 insertions(+) diff --git a/test/spec/services/statServicesSpec.js b/test/spec/services/statServicesSpec.js index 4593038171..a8fbe5f6f8 100644 --- a/test/spec/services/statServicesSpec.js +++ b/test/spec/services/statServicesSpec.js @@ -15,6 +15,23 @@ describe('Stats Service', function() { }); }); + describe('hpDisplay', function() { + it('displays hp as "hp / totalHP"', function() { + var hp = 34; + var hpDisplay = statCalc.hpDisplay(hp); + + expect(hpDisplay).to.eql('34/50'); + }); + + it('Rounds hp up when given a decimal', function() { + + var hp = 34.4; + var hpDisplay = statCalc.hpDisplay(hp); + + expect(hpDisplay).to.eql('35/50'); + }); + }); + 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 593031526f..6fbe6d4f73 100644 --- a/website/public/js/services/statServices.js +++ b/website/public/js/services/statServices.js @@ -12,6 +12,14 @@ function statsFactory(Content, Shared) { + function hpDisplay(hp) { + var remainingHP = Math.ceil(hp); + var totalHP = Shared.maxHealth; + var display = remainingHP + '/' + totalHP; + + return display; + } + function levelBonus(level) { // Level bonus is derived by taking the level, subtracting one, // taking the smaller of it or maxLevel (100), @@ -59,6 +67,7 @@ return { classBonus: classBonus, equipmentStatBonus: equipmentStatBonus, + hpDisplay: hpDisplay, levelBonus: levelBonus } }