Consolidate helpers

This commit is contained in:
Blade Barringer
2015-09-22 08:16:38 -05:00
parent ad7e01d87e
commit 8eeffeb2a9
7 changed files with 71 additions and 21 deletions

View File

@@ -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);
});
};

View File

@@ -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 = {

View File

@@ -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,

View File

@@ -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 = {

View File

@@ -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 = {

View File

@@ -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= {

View File

@@ -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 = {