From cfd5027009010beda447bd7aa2e5893f4c4e3b22 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 8 Apr 2016 20:14:08 +0200 Subject: [PATCH] math operator --- .../precompiled/components/sheetWorkers.js | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/D&D_5e_Reshaped/precompiled/components/sheetWorkers.js b/D&D_5e_Reshaped/precompiled/components/sheetWorkers.js index 4479607178..a0c20e9eab 100644 --- a/D&D_5e_Reshaped/precompiled/components/sheetWorkers.js +++ b/D&D_5e_Reshaped/precompiled/components/sheetWorkers.js @@ -287,12 +287,12 @@ const getAbilityMod = (score) => { return Math.floor((getIntValue(score) - 10) / 2); }; const addArithmeticOperator = (string, number) => { - let value = number; - if (string && value) { - if (value >= 0) { - value = ` + ${value}`; + let value = ''; + if (string && number) { + if (number >= 0) { + value = ` + ${number}`; } else { - value = ` - ${Math.abs(value)}`; + value = ` - ${Math.abs(number)}`; } } return value; @@ -465,10 +465,12 @@ const updateAbilityModifier = (ability) => { abilityCheck += abilityCheckBonus; abilityCheckFormula += `${addArithmeticOperator(abilityCheckFormula, abilityCheckBonus)}[${ability} check bonus]`; } - if (!isNaN(v.global_check_bonus)) { - abilityCheck += getIntValue(v.global_check_bonus); + if (v.global_check_bonus) { + if (!isNaN(v.global_check_bonus)) { + abilityCheck += getIntValue(v.global_check_bonus); + } + abilityCheckFormula += ' + (@{global_check_bonus})[global check bonus]'; } - abilityCheckFormula += ' + (@{global_check_bonus})[global check bonus]'; finalSetAttrs[`${ability}_calculated`] = abilityScoreCalc; finalSetAttrs[`${ability}_mod`] = abilityMod; @@ -2524,10 +2526,7 @@ const updateDamageToggle = (v, finalSetAttrs, repeatingString, options) => { const damageBonus = getIntValue(v[`${repeatingString}damage_bonus`]); if (exists(damageBonus)) { damageAddition += damageBonus; - if (damageFormula !== '') { - damageFormula += ' + '; - } - damageFormula += `${damageBonus}[bonus]`; + damageFormula += `${addArithmeticOperator(damageFormula, damageBonus)}[bonus]`; } if (exists(options.globalDamageBonus)) {