From 68cd51fbb03bba868e47013489032b77eb534410 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Fri, 25 Sep 2015 17:34:17 -0500 Subject: [PATCH] Move egg function to helpers --- common/script/src/content/eggs/drops.js | 25 ++-------------------- common/script/src/content/eggs/quest.js | 25 ++-------------------- common/script/src/content/helpers.js | 28 +++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 46 deletions(-) diff --git a/common/script/src/content/eggs/drops.js b/common/script/src/content/eggs/drops.js index fa0f5a8f0a..6630998b43 100644 --- a/common/script/src/content/eggs/drops.js +++ b/common/script/src/content/eggs/drops.js @@ -1,5 +1,4 @@ -import {each, defaults} from 'lodash'; -import {translator as t} from '../helpers'; +import {generateEggs} from '../helpers'; const DROP_EGGS = [ 'Wolf', @@ -13,26 +12,6 @@ const DROP_EGGS = [ 'BearCub', ]; -let eggs = { }; - -each(DROP_EGGS, (pet) => { - eggs[pet] = { - text: t(`dropEgg${pet}Text`), - mountText: t(`dropEgg${pet}MountText`), - adjective: t(`dropEgg${pet}Adjective`), - } -}); - -each(eggs, (egg, key) => { - return defaults(egg, { - canBuy: true, - value: 3, - key: key, - notes: t('eggNotes', { - eggText: egg.text, - eggAdjective: egg.adjective - }), - }); -}); +let eggs = generateEggs(DROP_EGGS, {type: 'drop', canBuy: true}); export default eggs; diff --git a/common/script/src/content/eggs/quest.js b/common/script/src/content/eggs/quest.js index 60c01414ec..f2c85d343c 100644 --- a/common/script/src/content/eggs/quest.js +++ b/common/script/src/content/eggs/quest.js @@ -1,5 +1,4 @@ -import {each, defaults} from 'lodash'; -import {translator as t} from '../helpers'; +import {generateEggs} from '../helpers'; const QUEST_EGGS = [ 'Gryphon', @@ -25,26 +24,6 @@ const QUEST_EGGS = [ 'Horse', ]; -let eggs = { }; - -each(QUEST_EGGS, (pet) => { - eggs[pet] = { - text: t(`questEgg${pet}Text`), - mountText: t(`questEgg${pet}MountText`), - adjective: t(`questEgg${pet}Adjective`), - } -}); - -each(eggs, (egg, key) => { - return defaults(egg, { - canBuy: false, - value: 3, - key: key, - notes: t('eggNotes', { - eggText: egg.text, - eggAdjective: egg.adjective - }), - }); -}); +let eggs = generateEggs(QUEST_EGGS, {type: 'quest', canBuy: false}); export default eggs; diff --git a/common/script/src/content/helpers.js b/common/script/src/content/helpers.js index a3571122be..4f56ae8daf 100644 --- a/common/script/src/content/helpers.js +++ b/common/script/src/content/helpers.js @@ -143,3 +143,31 @@ export function generateBackgrounds(sets) { return backgrounds; } + +//---------------------------------------- +// Egg Helpers +//---------------------------------------- + +export function generateEggs(set, options={}) { + let eggs = {}; + let type = options.type; + let canBuy = options.canBuy; + + each(set, (pet) => { + eggs[pet] = { + text: translator(`${type}Egg${pet}Text`), + mountText: translator(`${type}Egg${pet}MountText`), + adjective: translator(`${type}Egg${pet}Adjective`), + canBuy: canBuy, + value: 3, + key: pet, + } + + eggs[pet].notes = translator('eggNotes', { + eggText: eggs[pet].text, + eggAdjective: eggs[pet].adjective + }); + }); + + return eggs; +}