From bf3387703d6fba4c09474d0475457b6c2d11a351 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Sat, 10 Sep 2016 13:37:10 -0500 Subject: [PATCH] Pull out animal content into separate files (#7989) * Pull out animal content into separate files * Correct variable names * Add tests for stable, eggs, and hatching potions content * Add content test back into npm test --- common/script/content/eggs.js | 262 +++++++++++ common/script/content/hatching-potions.js | 115 +++++ common/script/content/index.js | 507 +--------------------- common/script/content/stable.js | 113 +++++ tasks/gulp-tests.js | 1 + test/content/eggs.test.js | 33 ++ test/content/hatching-potions.test.js | 31 ++ test/content/stable.test.js | 145 +++++++ 8 files changed, 719 insertions(+), 488 deletions(-) create mode 100644 common/script/content/eggs.js create mode 100644 common/script/content/hatching-potions.js create mode 100644 common/script/content/stable.js create mode 100644 test/content/eggs.test.js create mode 100644 test/content/hatching-potions.test.js create mode 100644 test/content/stable.test.js diff --git a/common/script/content/eggs.js b/common/script/content/eggs.js new file mode 100644 index 0000000000..a30a86522b --- /dev/null +++ b/common/script/content/eggs.js @@ -0,0 +1,262 @@ +import { + assign, + defaults, + each, +} from 'lodash'; +import t from './translation'; + +function applyEggDefaults (set, config) { + each(set, (egg, key) => { + defaults(egg, { + canBuy: config.canBuy, + value: 3, + key, + notes: t('eggNotes', { + eggText: egg.text, + eggAdjective: egg.adjective, + }), + mountText: egg.text, + }); + }); +} + +function hasQuestAchievementFunction (key) { + return (user) => { + return user.achievements.quests && + user.achievements.quests[key] > 0; + }; +} + +let drops = { + Wolf: { + text: t('dropEggWolfText'), + adjective: t('dropEggWolfAdjective'), + }, + TigerCub: { + text: t('dropEggTigerCubText'), + mountText: t('dropEggTigerCubMountText'), + adjective: t('dropEggTigerCubAdjective'), + }, + PandaCub: { + text: t('dropEggPandaCubText'), + mountText: t('dropEggPandaCubMountText'), + adjective: t('dropEggPandaCubAdjective'), + }, + LionCub: { + text: t('dropEggLionCubText'), + mountText: t('dropEggLionCubMountText'), + adjective: t('dropEggLionCubAdjective'), + }, + Fox: { + text: t('dropEggFoxText'), + adjective: t('dropEggFoxAdjective'), + }, + FlyingPig: { + text: t('dropEggFlyingPigText'), + adjective: t('dropEggFlyingPigAdjective'), + }, + Dragon: { + text: t('dropEggDragonText'), + adjective: t('dropEggDragonAdjective'), + }, + Cactus: { + text: t('dropEggCactusText'), + adjective: t('dropEggCactusAdjective'), + }, + BearCub: { + text: t('dropEggBearCubText'), + mountText: t('dropEggBearCubMountText'), + adjective: t('dropEggBearCubAdjective'), + }, +}; + +let quests = { + Gryphon: { + text: t('questEggGryphonText'), + adjective: t('questEggGryphonAdjective'), + canBuy: hasQuestAchievementFunction('gryphon'), + }, + Hedgehog: { + text: t('questEggHedgehogText'), + adjective: t('questEggHedgehogAdjective'), + canBuy: hasQuestAchievementFunction('hedgehog'), + }, + Deer: { + text: t('questEggDeerText'), + adjective: t('questEggDeerAdjective'), + canBuy: hasQuestAchievementFunction('ghost_stag'), + }, + Egg: { + text: t('questEggEggText'), + adjective: t('questEggEggAdjective'), + mountText: t('questEggEggMountText'), + }, + Rat: { + text: t('questEggRatText'), + adjective: t('questEggRatAdjective'), + canBuy: hasQuestAchievementFunction('rat'), + }, + Octopus: { + text: t('questEggOctopusText'), + adjective: t('questEggOctopusAdjective'), + canBuy: hasQuestAchievementFunction('octopus'), + }, + Seahorse: { + text: t('questEggSeahorseText'), + adjective: t('questEggSeahorseAdjective'), + canBuy: hasQuestAchievementFunction('dilatory_derby'), + }, + Parrot: { + text: t('questEggParrotText'), + adjective: t('questEggParrotAdjective'), + canBuy: hasQuestAchievementFunction('harpy'), + }, + Rooster: { + text: t('questEggRoosterText'), + adjective: t('questEggRoosterAdjective'), + canBuy: hasQuestAchievementFunction('rooster'), + }, + Spider: { + text: t('questEggSpiderText'), + adjective: t('questEggSpiderAdjective'), + canBuy: hasQuestAchievementFunction('spider'), + }, + Owl: { + text: t('questEggOwlText'), + adjective: t('questEggOwlAdjective'), + canBuy: hasQuestAchievementFunction('owl'), + }, + Penguin: { + text: t('questEggPenguinText'), + adjective: t('questEggPenguinAdjective'), + canBuy: hasQuestAchievementFunction('penguin'), + }, + TRex: { + text: t('questEggTRexText'), + adjective: t('questEggTRexAdjective'), + canBuy (user) { + let questAchievements = user.achievements.quests; + + return questAchievements && ( + questAchievements.trex > 0 || + questAchievements.trex_undead > 0 + ); + }, + }, + Rock: { + text: t('questEggRockText'), + adjective: t('questEggRockAdjective'), + canBuy: hasQuestAchievementFunction('rock'), + }, + Bunny: { + text: t('questEggBunnyText'), + adjective: t('questEggBunnyAdjective'), + canBuy: hasQuestAchievementFunction('bunny'), + }, + Slime: { + text: t('questEggSlimeText'), + adjective: t('questEggSlimeAdjective'), + canBuy: hasQuestAchievementFunction('slime'), + }, + Sheep: { + text: t('questEggSheepText'), + adjective: t('questEggSheepAdjective'), + canBuy: hasQuestAchievementFunction('sheep'), + }, + Cuttlefish: { + text: t('questEggCuttlefishText'), + adjective: t('questEggCuttlefishAdjective'), + canBuy: hasQuestAchievementFunction('kraken'), + }, + Whale: { + text: t('questEggWhaleText'), + adjective: t('questEggWhaleAdjective'), + canBuy: hasQuestAchievementFunction('whale'), + }, + Cheetah: { + text: t('questEggCheetahText'), + adjective: t('questEggCheetahAdjective'), + canBuy: hasQuestAchievementFunction('cheetah'), + }, + Horse: { + text: t('questEggHorseText'), + adjective: t('questEggHorseAdjective'), + canBuy: hasQuestAchievementFunction('horse'), + }, + Frog: { + text: t('questEggFrogText'), + adjective: t('questEggFrogAdjective'), + canBuy: hasQuestAchievementFunction('frog'), + }, + Snake: { + text: t('questEggSnakeText'), + adjective: t('questEggSnakeAdjective'), + canBuy: hasQuestAchievementFunction('snake'), + }, + Unicorn: { + text: t('questEggUnicornText'), + mountText: t('questEggUnicornMountText'), + adjective: t('questEggUnicornAdjective'), + canBuy: hasQuestAchievementFunction('unicorn'), + }, + Sabretooth: { + text: t('questEggSabretoothText'), + adjective: t('questEggSabretoothAdjective'), + canBuy: hasQuestAchievementFunction('sabretooth'), + }, + Monkey: { + text: t('questEggMonkeyText'), + adjective: t('questEggMonkeyAdjective'), + canBuy: hasQuestAchievementFunction('monkey'), + }, + Snail: { + text: t('questEggSnailText'), + adjective: t('questEggSnailAdjective'), + canBuy: hasQuestAchievementFunction('snail'), + }, + Falcon: { + text: t('questEggFalconText'), + adjective: t('questEggFalconAdjective'), + canBuy: hasQuestAchievementFunction('falcon'), + }, + Treeling: { + text: t('questEggTreelingText'), + adjective: t('questEggTreelingAdjective'), + canBuy: hasQuestAchievementFunction('treeling'), + }, + Axolotl: { + text: t('questEggAxolotlText'), + adjective: t('questEggAxolotlAdjective'), + canBuy: hasQuestAchievementFunction('axolotl'), + }, + Turtle: { + text: t('questEggTurtleText'), + adjective: t('questEggTurtleAdjective'), + canBuy: hasQuestAchievementFunction('turtle'), + }, + Armadillo: { + text: t('questEggArmadilloText'), + adjective: t('questEggArmadilloAdjective'), + canBuy: hasQuestAchievementFunction('armadillo'), + }, +}; + +applyEggDefaults(drops, { + canBuy () { + return true; + }, +}); + +applyEggDefaults(quests, { + canBuy () { + return false; + }, +}); + +let all = assign({}, drops, quests); + +module.exports = { + drops, + quests, + all, +}; diff --git a/common/script/content/hatching-potions.js b/common/script/content/hatching-potions.js new file mode 100644 index 0000000000..bcef1b727c --- /dev/null +++ b/common/script/content/hatching-potions.js @@ -0,0 +1,115 @@ +import { + assign, + defaults, + each, +} from 'lodash'; +import t from './translation'; + +let drops = { + Base: { + value: 2, + text: t('hatchingPotionBase'), + }, + White: { + value: 2, + text: t('hatchingPotionWhite'), + }, + Desert: { + value: 2, + text: t('hatchingPotionDesert'), + }, + Red: { + value: 3, + text: t('hatchingPotionRed'), + }, + Shade: { + value: 3, + text: t('hatchingPotionShade'), + }, + Skeleton: { + value: 3, + text: t('hatchingPotionSkeleton'), + }, + Zombie: { + value: 4, + text: t('hatchingPotionZombie'), + }, + CottonCandyPink: { + value: 4, + text: t('hatchingPotionCottonCandyPink'), + }, + CottonCandyBlue: { + value: 4, + text: t('hatchingPotionCottonCandyBlue'), + }, + Golden: { + value: 5, + text: t('hatchingPotionGolden'), + }, +}; + +let premium = { + Spooky: { + value: 2, + text: t('hatchingPotionSpooky'), + limited: true, + _season: 'fall', + }, + Peppermint: { + value: 2, + text: t('hatchingPotionPeppermint'), + limited: true, + _season: 'winter', + }, + Floral: { + value: 2, + text: t('hatchingPotionFloral'), + limited: true, + _season: 'spring', + }, + Thunderstorm: { + value: 2, + text: t('hatchingPotionThunderstorm'), + limited: true, + _season: 'summer', + }, +}; + +each(drops, (pot, key) => { + defaults(pot, { + key, + value: 2, + notes: t('hatchingPotionNotes', { + potText: pot.text, + }), + premium: false, + limited: false, + canBuy () { + return true; + }, + }); +}); + +each(premium, (pot, key) => { + defaults(pot, { + key, + value: 2, + notes: t('hatchingPotionNotes', { + potText: pot.text, + }), + _addlNotes: t(`${pot._season}EventAvailability`), + premium: true, + limited: false, + canBuy () { + return false; + }, + }); +}); + +let all = assign({}, drops, premium); + +module.exports = { + drops, + premium, + all, +}; diff --git a/common/script/content/index.js b/common/script/content/index.js index 7a50da147b..f35fb81edb 100644 --- a/common/script/content/index.js +++ b/common/script/content/index.js @@ -14,6 +14,9 @@ let api = module.exports; import mysterySets from './mystery-sets'; +import eggs from './eggs'; +import hatchingPotions from './hatching-potions'; +import stable from './stable'; import gear from './gear'; import appearances from './appearance'; @@ -127,342 +130,9 @@ api.cardTypes = { api.special = api.spells.special; -/* - --------------------------------------------------------------- - Drops - --------------------------------------------------------------- - */ - -api.dropEggs = { - Wolf: { - text: t('dropEggWolfText'), - adjective: t('dropEggWolfAdjective') - }, - TigerCub: { - text: t('dropEggTigerCubText'), - mountText: t('dropEggTigerCubMountText'), - adjective: t('dropEggTigerCubAdjective') - }, - PandaCub: { - text: t('dropEggPandaCubText'), - mountText: t('dropEggPandaCubMountText'), - adjective: t('dropEggPandaCubAdjective') - }, - LionCub: { - text: t('dropEggLionCubText'), - mountText: t('dropEggLionCubMountText'), - adjective: t('dropEggLionCubAdjective') - }, - Fox: { - text: t('dropEggFoxText'), - adjective: t('dropEggFoxAdjective') - }, - FlyingPig: { - text: t('dropEggFlyingPigText'), - adjective: t('dropEggFlyingPigAdjective') - }, - Dragon: { - text: t('dropEggDragonText'), - adjective: t('dropEggDragonAdjective') - }, - Cactus: { - text: t('dropEggCactusText'), - adjective: t('dropEggCactusAdjective') - }, - BearCub: { - text: t('dropEggBearCubText'), - mountText: t('dropEggBearCubMountText'), - adjective: t('dropEggBearCubAdjective') - } -}; - -_.each(api.dropEggs, function(egg, key) { - return _.defaults(egg, { - canBuy: (function() { - return true; - }), - value: 3, - key: key, - notes: t('eggNotes', { - eggText: egg.text, - eggAdjective: egg.adjective - }), - mountText: egg.text - }); -}); - -api.questEggs = { - Gryphon: { - text: t('questEggGryphonText'), - adjective: t('questEggGryphonAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.gryphon != null) > 0; - }) - }, - Hedgehog: { - text: t('questEggHedgehogText'), - adjective: t('questEggHedgehogAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.hedgehog != null) > 0; - }) - }, - Deer: { - text: t('questEggDeerText'), - adjective: t('questEggDeerAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.ghost_stag != null) > 0; - }) - }, - Egg: { - text: t('questEggEggText'), - adjective: t('questEggEggAdjective'), - mountText: t('questEggEggMountText') - }, - Rat: { - text: t('questEggRatText'), - adjective: t('questEggRatAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.rat != null) > 0; - }) - }, - Octopus: { - text: t('questEggOctopusText'), - adjective: t('questEggOctopusAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.octopus != null) > 0; - }) - }, - Seahorse: { - text: t('questEggSeahorseText'), - adjective: t('questEggSeahorseAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.dilatory_derby != null) > 0; - }) - }, - Parrot: { - text: t('questEggParrotText'), - adjective: t('questEggParrotAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.harpy != null) > 0; - }) - }, - Rooster: { - text: t('questEggRoosterText'), - adjective: t('questEggRoosterAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.rooster != null) > 0; - }) - }, - Spider: { - text: t('questEggSpiderText'), - adjective: t('questEggSpiderAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.spider != null) > 0; - }) - }, - Owl: { - text: t('questEggOwlText'), - adjective: t('questEggOwlAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.owl != null) > 0; - }) - }, - Penguin: { - text: t('questEggPenguinText'), - adjective: t('questEggPenguinAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.penguin != null) > 0; - }) - }, - TRex: { - text: t('questEggTRexText'), - adjective: t('questEggTRexAdjective'), - canBuy: (function(u) { - return u.achievements.quests && ((u.achievements.quests.trex != null) > 0 || (u.achievements.quests.trex_undead != null) > 0); - }) - }, - Rock: { - text: t('questEggRockText'), - adjective: t('questEggRockAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.rock != null) > 0; - }) - }, - Bunny: { - text: t('questEggBunnyText'), - adjective: t('questEggBunnyAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.bunny != null) > 0; - }) - }, - Slime: { - text: t('questEggSlimeText'), - adjective: t('questEggSlimeAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.slime != null) > 0; - }) - }, - Sheep: { - text: t('questEggSheepText'), - adjective: t('questEggSheepAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.sheep != null) > 0; - }) - }, - Cuttlefish: { - text: t('questEggCuttlefishText'), - adjective: t('questEggCuttlefishAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.kraken != null) > 0; - }) - }, - Whale: { - text: t('questEggWhaleText'), - adjective: t('questEggWhaleAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.whale != null) > 0; - }) - }, - Cheetah: { - text: t('questEggCheetahText'), - adjective: t('questEggCheetahAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.cheetah != null) > 0; - }) - }, - Horse: { - text: t('questEggHorseText'), - adjective: t('questEggHorseAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.horse != null) > 0; - }) - }, - Frog: { - text: t('questEggFrogText'), - adjective: t('questEggFrogAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.frog != null) > 0; - }) - }, - Snake: { - text: t('questEggSnakeText'), - adjective: t('questEggSnakeAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.snake != null) > 0; - }) - }, - Unicorn: { - text: t('questEggUnicornText'), - mountText: t('questEggUnicornMountText'), - adjective: t('questEggUnicornAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.unicorn != null) > 0; - }) - }, - Sabretooth: { - text: t('questEggSabretoothText'), - adjective: t('questEggSabretoothAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.sabretooth != null) > 0; - }) - }, - Monkey: { - text: t('questEggMonkeyText'), - adjective: t('questEggMonkeyAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.monkey != null) > 0; - }) - }, - Snail: { - text: t('questEggSnailText'), - adjective: t('questEggSnailAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.snail != null) > 0; - }), - }, - Falcon: { - text: t('questEggFalconText'), - adjective: t('questEggFalconAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.falcon != null) > 0; - }), - }, - Treeling: { - text: t('questEggTreelingText'), - adjective: t('questEggTreelingAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.treeling != null) > 0; - }), - }, - Axolotl: { - text: t('questEggAxolotlText'), - adjective: t('questEggAxolotlAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.axolotl != null) > 0; - }), - }, - Turtle: { - text: t('questEggTurtleText'), - adjective: t('questEggTurtleAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.turtle != null) > 0; - }), - }, - Armadillo: { - text: t('questEggArmadilloText'), - adjective: t('questEggArmadilloAdjective'), - canBuy: (function(u) { - return u.achievements.quests && (u.achievements.quests.armadillo != null) > 0; - }), - }, -}; - -_.each(api.questEggs, function(egg, key) { - return _.defaults(egg, { - canBuy: (function() { - return false; - }), - value: 3, - key: key, - notes: t('eggNotes', { - eggText: egg.text, - eggAdjective: egg.adjective - }), - mountText: egg.text - }); -}); - -api.eggs = _.assign(_.cloneDeep(api.dropEggs), api.questEggs); - -api.specialPets = { - 'Wolf-Veteran': 'veteranWolf', - 'Wolf-Cerberus': 'cerberusPup', - 'Dragon-Hydra': 'hydra', - 'Turkey-Base': 'turkey', - 'BearCub-Polar': 'polarBearPup', - 'MantisShrimp-Base': 'mantisShrimp', - 'JackOLantern-Base': 'jackolantern', - 'Mammoth-Base': 'mammoth', - 'Tiger-Veteran': 'veteranTiger', - 'Phoenix-Base': 'phoenix', - 'Turkey-Gilded': 'gildedTurkey', - 'MagicalBee-Base': 'magicalBee', - 'Lion-Veteran': 'veteranLion', - 'Gryphon-RoyalPurple': 'royalPurpleGryphon', -}; - -api.specialMounts = { - 'BearCub-Polar': 'polarBear', - 'LionCub-Ethereal': 'etherealLion', - 'MantisShrimp-Base': 'mantisShrimp', - 'Turkey-Base': 'turkey', - 'Mammoth-Base': 'mammoth', - 'Orca-Base': 'orca', - 'Gryphon-RoyalPurple': 'royalPurpleGryphon', - 'Phoenix-Base': 'phoenix', - 'JackOLantern-Base': 'jackolantern', - 'MagicalBee-Base': 'magicalBee', -}; +api.dropEggs = eggs.drops; +api.questEggs = eggs.quests; +api.eggs = eggs.all; api.timeTravelStable = { pets: { @@ -477,160 +147,21 @@ api.timeTravelStable = { } }; -api.dropHatchingPotions = { - Base: { - value: 2, - text: t('hatchingPotionBase') - }, - White: { - value: 2, - text: t('hatchingPotionWhite') - }, - Desert: { - value: 2, - text: t('hatchingPotionDesert') - }, - Red: { - value: 3, - text: t('hatchingPotionRed') - }, - Shade: { - value: 3, - text: t('hatchingPotionShade') - }, - Skeleton: { - value: 3, - text: t('hatchingPotionSkeleton') - }, - Zombie: { - value: 4, - text: t('hatchingPotionZombie') - }, - CottonCandyPink: { - value: 4, - text: t('hatchingPotionCottonCandyPink') - }, - CottonCandyBlue: { - value: 4, - text: t('hatchingPotionCottonCandyBlue') - }, - Golden: { - value: 5, - text: t('hatchingPotionGolden') - } -}; +api.dropHatchingPotions = hatchingPotions.drops; +api.premiumHatchingPotions = hatchingPotions.premium; +api.hatchingPotions = hatchingPotions.all; -api.premiumHatchingPotions = { - Spooky: { - value: 2, - text: t('hatchingPotionSpooky'), - limited: true, - _season: 'fall', - }, - Peppermint: { - value: 2, - text: t('hatchingPotionPeppermint'), - limited: true, - _season: 'winter', - }, - Floral: { - value: 2, - text: t('hatchingPotionFloral'), - limited: true, - _season: 'spring', - }, - Thunderstorm: { - value: 2, - text: t('hatchingPotionThunderstorm'), - limited: true, - _season: 'summer', - }, -}; +api.pets = stable.dropPets; +api.premiumPets = stable.premiumPets; +api.questPets = stable.questPets; +api.specialPets = stable.specialPets; +api.petInfo = stable.petInfo; -_.each(api.dropHatchingPotions, function(pot, key) { - return _.defaults(pot, { - key: key, - value: 2, - notes: t('hatchingPotionNotes', { - potText: pot.text - }), - premium: false, - limited: false, - canBuy: (function() { - return true; - }) - }); -}); - -_.each(api.premiumHatchingPotions, function(pot, key) { - return _.defaults(pot, { - key: key, - value: 2, - notes: t('hatchingPotionNotes', { - potText: pot.text - }), - _addlNotes: t(`${pot._season}EventAvailability`), - premium: true, - limited: false, - canBuy: (function() { - return false; - }) - }); -}); - -api.hatchingPotions = {}; - -_.merge(api.hatchingPotions, api.dropHatchingPotions); - -_.merge(api.hatchingPotions, api.premiumHatchingPotions); - -api.pets = _.transform(api.dropEggs, function(m, egg) { - return _.defaults(m, _.transform(api.hatchingPotions, function(m2, pot) { - if (!pot.premium) { - return m2[egg.key + "-" + pot.key] = true; - } - })); -}); - -api.premiumPets = _.transform(api.dropEggs, function(m, egg) { - return _.defaults(m, _.transform(api.hatchingPotions, function(m2, pot) { - if (pot.premium) { - return m2[egg.key + "-" + pot.key] = true; - } - })); -}); - -api.questPets = _.transform(api.questEggs, function(m, egg) { - return _.defaults(m, _.transform(api.hatchingPotions, function(m2, pot) { - if (!pot.premium) { - return m2[egg.key + "-" + pot.key] = true; - } - })); -}); - -api.mounts = _.transform(api.dropEggs, function(m, egg) { - return _.defaults(m, _.transform(api.hatchingPotions, function(m2, pot) { - if (!pot.premium) { - return m2[egg.key + "-" + pot.key] = true; - } - })); -}); - -api.questMounts = _.transform(api.questEggs, function(m, egg) { - return _.defaults(m, _.transform(api.hatchingPotions, function(m2, pot) { - if (!pot.premium) { - return m2[egg.key + "-" + pot.key] = true; - } - })); -}); - -api.premiumMounts = _.transform(api.dropEggs, function(m, egg) { - return _.defaults(m, _.transform(api.hatchingPotions, function(m2, pot) { - if (pot.premium) { - return m2[egg.key + "-" + pot.key] = true; - } - })); -}); +api.mounts = stable.dropMounts; +api.questMounts = stable.questMounts; +api.premiumMounts = stable.premiumMounts; +api.specialMounts = stable.specialMounts; +api.mountInfo = stable.mountInfo; api.food = { Meat: { diff --git a/common/script/content/stable.js b/common/script/content/stable.js new file mode 100644 index 0000000000..d6d47c8e3c --- /dev/null +++ b/common/script/content/stable.js @@ -0,0 +1,113 @@ +import { + each, +} from 'lodash'; +import { + drops as dropEggs, + quests as questEggs, +} from './eggs'; +import { + drops as dropPotions, + premium as premiumPotions, +} from './hatching-potions'; +import t from './translation'; + +let petInfo = {}; +let mountInfo = {}; + +function constructSet (type, eggs, potions) { + let pets = {}; + let mounts = {}; + + each(eggs, (egg) => { + each(potions, (potion) => { + let key = `${egg.key}-${potion.key}`; + + function getAnimalData (text) { + return { + key, + type, + potion, + egg, + text, + }; + } + + petInfo[key] = getAnimalData(t('petName', { + potion: potion.text(), + egg: egg.text(), + })); + mountInfo[key] = getAnimalData(t('mountName', { + potion: potion.text(), + mount: egg.mountText(), + })); + + pets[key] = true; + mounts[key] = true; + }); + }); + + return [pets, mounts]; +} + +let [dropPets, dropMounts] = constructSet('drop', dropEggs, dropPotions); +let [premiumPets, premiumMounts] = constructSet('premium', dropEggs, premiumPotions); +let [questPets, questMounts] = constructSet('quest', questEggs, dropPotions); + +let specialPets = { + 'Wolf-Veteran': 'veteranWolf', + 'Wolf-Cerberus': 'cerberusPup', + 'Dragon-Hydra': 'hydra', + 'Turkey-Base': 'turkey', + 'BearCub-Polar': 'polarBearPup', + 'MantisShrimp-Base': 'mantisShrimp', + 'JackOLantern-Base': 'jackolantern', + 'Mammoth-Base': 'mammoth', + 'Tiger-Veteran': 'veteranTiger', + 'Phoenix-Base': 'phoenix', + 'Turkey-Gilded': 'gildedTurkey', + 'MagicalBee-Base': 'magicalBee', + 'Lion-Veteran': 'veteranLion', + 'Gryphon-RoyalPurple': 'royalPurpleGryphon', +}; + +let specialMounts = { + 'BearCub-Polar': 'polarBear', + 'LionCub-Ethereal': 'etherealLion', + 'MantisShrimp-Base': 'mantisShrimp', + 'Turkey-Base': 'turkey', + 'Mammoth-Base': 'mammoth', + 'Orca-Base': 'orca', + 'Gryphon-RoyalPurple': 'royalPurpleGryphon', + 'Phoenix-Base': 'phoenix', + 'JackOLantern-Base': 'jackolantern', + 'MagicalBee-Base': 'magicalBee', +}; + +each(specialPets, (translationString, key) => { + petInfo[key] = { + key, + type: 'special', + text: t(translationString), + }; +}); + +each(specialMounts, (translationString, key) => { + mountInfo[key] = { + key, + type: 'special', + text: t(translationString), + }; +}); + +module.exports = { + dropPets, + premiumPets, + questPets, + dropMounts, + questMounts, + premiumMounts, + specialPets, + specialMounts, + petInfo, + mountInfo, +}; diff --git a/tasks/gulp-tests.js b/tasks/gulp-tests.js index 37b6a5423c..47b97c57d7 100644 --- a/tasks/gulp-tests.js +++ b/tasks/gulp-tests.js @@ -345,6 +345,7 @@ gulp.task('test:api-v3:integration:separate-server', (done) => { gulp.task('test', (done) => { runSequence( 'test:sanity', + 'test:content', 'test:common', 'test:karma', 'test:api-v3:unit', diff --git a/test/content/eggs.test.js b/test/content/eggs.test.js new file mode 100644 index 0000000000..c0f1dc0803 --- /dev/null +++ b/test/content/eggs.test.js @@ -0,0 +1,33 @@ +import { + each, +} from 'lodash'; +import { + expectValidTranslationString, +} from '../helpers/content.helper'; + +import eggs from '../../common/script/content/eggs'; + +describe('eggs', () => { + describe('all', () => { + it('is a combination of drop and quest eggs', () => { + let dropNumber = Object.keys(eggs.drops).length; + let questNumber = Object.keys(eggs.quests).length; + let allNumber = Object.keys(eggs.all).length; + + expect(allNumber).to.be.greaterThan(0); + expect(allNumber).to.equal(dropNumber + questNumber); + }); + + it('contains basic information about each egg', () => { + each(eggs.all, (egg, key) => { + expectValidTranslationString(egg.text); + expectValidTranslationString(egg.adjective); + expectValidTranslationString(egg.mountText); + expectValidTranslationString(egg.notes); + expect(egg.canBuy).to.be.a('function'); + expect(egg.value).to.be.a('number'); + expect(egg.key).to.equal(key); + }); + }); + }); +}); diff --git a/test/content/hatching-potions.test.js b/test/content/hatching-potions.test.js new file mode 100644 index 0000000000..b1e0b03bb0 --- /dev/null +++ b/test/content/hatching-potions.test.js @@ -0,0 +1,31 @@ +import { + each, +} from 'lodash'; +import { + expectValidTranslationString, +} from '../helpers/content.helper'; + +import hatchingPotions from '../../common/script/content/hatching-potions'; + +describe('hatchingPotions', () => { + describe('all', () => { + it('is a combination of drop and premium potions', () => { + let dropNumber = Object.keys(hatchingPotions.drops).length; + let premiumNumber = Object.keys(hatchingPotions.premium).length; + let allNumber = Object.keys(hatchingPotions.all).length; + + expect(allNumber).to.be.greaterThan(0); + expect(allNumber).to.equal(dropNumber + premiumNumber); + }); + + it('contains basic information about each potion', () => { + each(hatchingPotions.all, (potion, key) => { + expectValidTranslationString(potion.text); + expectValidTranslationString(potion.notes); + expect(potion.canBuy).to.be.a('function'); + expect(potion.value).to.be.a('number'); + expect(potion.key).to.equal(key); + }); + }); + }); +}); diff --git a/test/content/stable.test.js b/test/content/stable.test.js new file mode 100644 index 0000000000..2a6609ee27 --- /dev/null +++ b/test/content/stable.test.js @@ -0,0 +1,145 @@ +import { + each, +} from 'lodash'; +import { + expectValidTranslationString, +} from '../helpers/content.helper'; +import t from '../../common/script/content/translation'; + +import stable from '../../common/script/content/stable'; +import eggs from '../../common/script/content/eggs'; +import potions from '../../common/script/content/hatching-potions'; + +describe('stable', () => { + describe('dropPets', () => { + it('contains a pet for each drop potion * each drop egg', () => { + let numberOfDropPotions = Object.keys(potions.drops).length; + let numberOfDropEggs = Object.keys(eggs.drops).length; + let numberOfDropPets = Object.keys(stable.dropPets).length; + let expectedTotal = numberOfDropPotions * numberOfDropEggs; + + expect(numberOfDropPets).to.be.greaterThan(0); + expect(numberOfDropPets).to.equal(expectedTotal); + }); + }); + + describe('questPets', () => { + it('contains a pet for each drop potion * each quest egg', () => { + let numberOfDropPotions = Object.keys(potions.drops).length; + let numberOfQuestEggs = Object.keys(eggs.quests).length; + let numberOfQuestPets = Object.keys(stable.questPets).length; + let expectedTotal = numberOfDropPotions * numberOfQuestEggs; + + expect(numberOfQuestPets).to.be.greaterThan(0); + expect(numberOfQuestPets).to.equal(expectedTotal); + }); + }); + + describe('premiumPets', () => { + it('contains a pet for each premium potion * each drop egg', () => { + let numberOfPremiumPotions = Object.keys(potions.premium).length; + let numberOfDropEggs = Object.keys(eggs.drops).length; + let numberOfPremiumPets = Object.keys(stable.premiumPets).length; + let expectedTotal = numberOfPremiumPotions * numberOfDropEggs; + + expect(numberOfPremiumPets).to.be.greaterThan(0); + expect(numberOfPremiumPets).to.equal(expectedTotal); + }); + }); + + describe('specialPets', () => { + it('each value is a valid translation string', () => { + each(stable.specialPets, (pet) => { + let string = t(pet); + expectValidTranslationString(string); + }); + }); + }); + + describe('dropMounts', () => { + it('contains a mount for each drop potion * each drop egg', () => { + let numberOfDropPotions = Object.keys(potions.drops).length; + let numberOfDropEggs = Object.keys(eggs.drops).length; + let numberOfDropMounts = Object.keys(stable.dropMounts).length; + let expectedTotal = numberOfDropPotions * numberOfDropEggs; + + expect(numberOfDropMounts).to.be.greaterThan(0); + expect(numberOfDropMounts).to.equal(expectedTotal); + }); + }); + + describe('questMounts', () => { + it('contains a mount for each drop potion * each quest egg', () => { + let numberOfDropPotions = Object.keys(potions.drops).length; + let numberOfQuestEggs = Object.keys(eggs.quests).length; + let numberOfQuestMounts = Object.keys(stable.questMounts).length; + let expectedTotal = numberOfDropPotions * numberOfQuestEggs; + + expect(numberOfQuestMounts).to.be.greaterThan(0); + expect(numberOfQuestMounts).to.equal(expectedTotal); + }); + }); + + describe('premiumMounts', () => { + it('contains a mount for each premium potion * each drop egg', () => { + let numberOfPremiumPotions = Object.keys(potions.premium).length; + let numberOfDropEggs = Object.keys(eggs.drops).length; + let numberOfPremiumMounts = Object.keys(stable.premiumMounts).length; + let expectedTotal = numberOfPremiumPotions * numberOfDropEggs; + + expect(numberOfPremiumMounts).to.be.greaterThan(0); + expect(numberOfPremiumMounts).to.equal(expectedTotal); + }); + }); + + describe('specialMounts', () => { + it('each value is a valid translation string', () => { + each(stable.specialMounts, (mount) => { + let string = t(mount); + expectValidTranslationString(string); + }); + }); + }); + + describe('petInfo', () => { + it('contains an entry for all pets', () => { + let dropNumber = Object.keys(stable.dropPets).length; + let questNumber = Object.keys(stable.questPets).length; + let specialNumber = Object.keys(stable.specialPets).length; + let premiumNumber = Object.keys(stable.premiumPets).length; + let allNumber = Object.keys(stable.petInfo).length; + + expect(allNumber).to.be.greaterThan(0); + expect(allNumber).to.equal(dropNumber + questNumber + specialNumber + premiumNumber); + }); + + it('contains basic information about each pet', () => { + each(stable.petInfo, (pet, key) => { + expectValidTranslationString(pet.text); + expect(pet.type).to.be.a('string'); + expect(pet.key).to.equal(key); + }); + }); + }); + + describe('mountInfo', () => { + it('contains an entry for all mounts', () => { + let dropNumber = Object.keys(stable.dropMounts).length; + let questNumber = Object.keys(stable.questMounts).length; + let specialNumber = Object.keys(stable.specialMounts).length; + let premiumNumber = Object.keys(stable.premiumMounts).length; + let allNumber = Object.keys(stable.mountInfo).length; + + expect(allNumber).to.be.greaterThan(0); + expect(allNumber).to.equal(dropNumber + questNumber + specialNumber + premiumNumber); + }); + + it('contains basic information about each mount', () => { + each(stable.mountInfo, (mount, key) => { + expectValidTranslationString(mount.text); + expect(mount.type).to.be.a('string'); + expect(mount.key).to.equal(key); + }); + }); + }); +});