diff --git a/common/script/src/content/helpers.js b/common/script/src/content/helpers.js index 945d5abc5b..d476e9910f 100644 --- a/common/script/src/content/helpers.js +++ b/common/script/src/content/helpers.js @@ -1,13 +1,15 @@ +import {each, defaults} from 'lodash'; +import capitalize from 'lodash.capitalize'; +import camelCase from 'lodash.camelcase'; + require('coffee-script'); import i18n from '../../../script/i18n.coffee'; -export function translator(string, vars) { - var func = function(lang) { - if (vars == null) { - vars = { - a: 'a' - }; - } +//---------------------------------------- +// Translator Helper +//---------------------------------------- +export function translator(string, vars={a: 'a'}) { + let func = (lang) => { return i18n.t(string, vars, lang); }; @@ -16,3 +18,39 @@ export function translator(string, vars) { return func; }; +//---------------------------------------- +// Formatting Helper +//---------------------------------------- + +export function formatForTranslator(name) { + let camelCasedName = camelCase(name); + let capitalCamelCasedName = capitalize(camelCasedName); + + return capitalCamelCasedName; +} + +//---------------------------------------- +// Spell Helpers +//---------------------------------------- + +export function diminishingReturns(bonus, max, halfway=max/2) { + return max * (bonus / (bonus + halfway)); +}; + +export function calculateBonus(value, stat, crit=1, stat_scale=0.5) { + return (value < 0 ? 1 : value + 1) + (stat * stat_scale * crit); +}; + +export function setSpellDefaults (className, spells) { + let capitalClassName = formatForTranslator(className); + + each(spells, (spell, key) => { + let capitalSpellKey = formatForTranslator(key); + let spellDefaults = { + text: translator(`spell${capitalClassName}${capitalSpellKey}Text`), + notes: translator(`spell${capitalClassName}${capitalSpellKey}Notes`), + }; + + defaults(spell, spellDefaults); + }); +}; diff --git a/common/script/src/content/spells/healer.js b/common/script/src/content/spells/healer.js index 7f6449dc11..f946c19904 100644 --- a/common/script/src/content/spells/healer.js +++ b/common/script/src/content/spells/healer.js @@ -1,5 +1,10 @@ -import {translator as t} from '../helpers'; -import {diminishingReturns, calculateBonus, setSpellDefaults} from './spell-helper'; +import { + translator as t, + diminishingReturns, + calculateBonus, + setSpellDefaults +} from '../helpers'; + import {each} from 'lodash'; let heal = { diff --git a/common/script/src/content/spells/index.js b/common/script/src/content/spells/index.js index 163cd59f2d..742eb5e10f 100644 --- a/common/script/src/content/spells/index.js +++ b/common/script/src/content/spells/index.js @@ -1,6 +1,3 @@ -import {translator as t} from '../helpers'; -import {diminishingReturns, calculateBonus} from './spell-helper'; - import wizard from './wizard'; import warrior from './warrior'; import healer from './healer'; @@ -28,7 +25,6 @@ import special from './special'; Note, user.stats.mp is docked after automatically (it's appended to functions automatically down below in an _.each) */ - var spells = { wizard: wizard, warrior: warrior, diff --git a/common/script/src/content/spells/rogue.js b/common/script/src/content/spells/rogue.js index cd7b966258..a4157c43a7 100644 --- a/common/script/src/content/spells/rogue.js +++ b/common/script/src/content/spells/rogue.js @@ -1,5 +1,9 @@ -import {translator as t} from '../helpers'; -import {diminishingReturns, calculateBonus, setSpellDefaults} from './spell-helper'; +import { + translator as t, + diminishingReturns, + calculateBonus, + setSpellDefaults +} from '../helpers'; import {each} from 'lodash'; let pickPocket = { diff --git a/common/script/src/content/spells/special.js b/common/script/src/content/spells/special.js index c1e21af12f..023480cd61 100644 --- a/common/script/src/content/spells/special.js +++ b/common/script/src/content/spells/special.js @@ -1,5 +1,4 @@ -import {translator as t} from '../helpers'; -import {diminishingReturns, calculateBonus, setSpellDefaults} from './spell-helper'; +import { translator as t } from '../helpers'; import {each} from 'lodash'; let snowball = { diff --git a/common/script/src/content/spells/warrior.js b/common/script/src/content/spells/warrior.js index 9a83f5e042..6271493089 100644 --- a/common/script/src/content/spells/warrior.js +++ b/common/script/src/content/spells/warrior.js @@ -1,5 +1,9 @@ -import {translator as t} from '../helpers'; -import {diminishingReturns, calculateBonus, setSpellDefaults} from './spell-helper'; +import { + translator as t, + diminishingReturns, + calculateBonus, + setSpellDefaults +} from '../helpers'; import {each} from 'lodash'; let smash= { diff --git a/common/script/src/content/spells/wizard.js b/common/script/src/content/spells/wizard.js index 10e13828ab..7056633c22 100644 --- a/common/script/src/content/spells/wizard.js +++ b/common/script/src/content/spells/wizard.js @@ -1,5 +1,9 @@ -import {translator as t} from '../helpers'; -import {diminishingReturns, calculateBonus, setSpellDefaults} from './spell-helper'; +import { + translator as t, + diminishingReturns, + calculateBonus, + setSpellDefaults +} from '../helpers'; import {each} from 'lodash'; let fireball = {