From b83f62bd829a4e238da6c8520ec5b3d93d8d8bed Mon Sep 17 00:00:00 2001 From: Phillip Thelen Date: Tue, 11 Jun 2024 18:19:11 +0200 Subject: [PATCH] Revert "allow eggs to have a release date" This reverts commit 6d13a257dd8143625f3a66a8b17d1b15ee3c7782. --- test/content/armoire.test.js | 2 +- test/content/eggs.test.js | 58 +++++----------- test/content/stable.test.js | 13 +--- .../script/content/constants/releaseDates.js | 19 ------ website/common/script/content/eggs.js | 25 ++----- .../script/content/gear/sets/armoire.js | 19 ++++-- website/common/script/content/index.js | 4 +- website/common/script/content/is_released.js | 30 -------- website/common/script/content/stable.js | 68 +++++++++++++------ website/common/script/fns/datedMemoize.js | 4 -- website/common/script/fns/firstDrops.js | 8 +-- 11 files changed, 97 insertions(+), 153 deletions(-) delete mode 100644 website/common/script/content/constants/releaseDates.js delete mode 100644 website/common/script/content/is_released.js diff --git a/test/content/armoire.test.js b/test/content/armoire.test.js index 5ed052d7a9..df49eaa911 100644 --- a/test/content/armoire.test.js +++ b/test/content/armoire.test.js @@ -64,7 +64,7 @@ describe('armoire', () => { delete require.cache[require.resolve('../../website/common/script/content/gear/sets/armoire')]; clock = sinon.useFakeTimers(new Date('2024-02-07T09:00:00.000Z')); const febuaryItems = makeArmoireIitemList(); - expect(febuaryItems.length).to.equal(384); + expect(febuaryItems.length).to.equal(381); }); it('sets have at least 2 items', () => { diff --git a/test/content/eggs.test.js b/test/content/eggs.test.js index 69dcb47798..cb0e173579 100644 --- a/test/content/eggs.test.js +++ b/test/content/eggs.test.js @@ -5,51 +5,29 @@ import { expectValidTranslationString, } from '../helpers/content.helper'; -import eggs from '../../website/common/script/content/eggs'; +import * as eggs from '../../website/common/script/content/eggs'; describe('eggs', () => { - let clock; + describe('all', () => { + it('is a combination of drop and quest eggs', () => { + const dropNumber = Object.keys(eggs.drops).length; + const questNumber = Object.keys(eggs.quests).length; + const allNumber = Object.keys(eggs.all).length; - afterEach(() => { - if (clock) { - clock.restore(); - } - }); + expect(allNumber).to.be.greaterThan(0); + expect(allNumber).to.equal(dropNumber + questNumber); + }); - const eggTypes = [ - 'drops', - 'quests', - ]; - - eggTypes.forEach(eggType => { - describe(eggType, () => { - it('contains basic information about each egg', () => { - each(eggs[eggType], (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); - }); + 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); }); }); }); - - it('does not contain unreleased eggs', () => { - clock = sinon.useFakeTimers(new Date('2024-05-20')); - const questEggs = eggs.quests; - expect(questEggs.Giraffe).to.not.exist; - }); - - it('Releases eggs when appropriate without needing restarting', () => { - clock = sinon.useFakeTimers(new Date('2024-05-20')); - const mayEggs = eggs.quests; - clock.restore(); - clock = sinon.useFakeTimers(new Date('2024-06-20')); - const juneEggs = eggs.quests; - expect(juneEggs.Giraffe).to.exist; - expect(Object.keys(mayEggs).length).to.equal(Object.keys(juneEggs).length - 1); - }); }); diff --git a/test/content/stable.test.js b/test/content/stable.test.js index 218e340e78..3266cb7f47 100644 --- a/test/content/stable.test.js +++ b/test/content/stable.test.js @@ -7,20 +7,11 @@ import { import t from '../../website/common/script/content/translation'; import * as stable from '../../website/common/script/content/stable'; -import eggs from '../../website/common/script/content/eggs'; -import potions from '../../website/common/script/content/hatching-potions'; +import * as eggs from '../../website/common/script/content/eggs'; +import * as potions from '../../website/common/script/content/hatching-potions'; describe('stable', () => { describe('dropPets', () => { - let clock; - beforeEach(() => { - clock = sinon.useFakeTimers(new Date('2020-05-20')); - }); - - afterEach(() => { - clock.restore(); - }); - it('contains a pet for each drop potion * each drop egg', () => { const numberOfDropPotions = Object.keys(potions.drops).length; const numberOfDropEggs = Object.keys(eggs.drops).length; diff --git a/website/common/script/content/constants/releaseDates.js b/website/common/script/content/constants/releaseDates.js deleted file mode 100644 index 46fd821d55..0000000000 --- a/website/common/script/content/constants/releaseDates.js +++ /dev/null @@ -1,19 +0,0 @@ -export const ARMOIRE_RELEASE_DATES = { - somethingSpooky: { year: 2023, month: 10 }, - cookingImplementsTwo: { year: 2023, month: 11 }, - greenTrapper: { year: 2023, month: 12 }, - schoolUniform: { year: 2024, month: 1 }, - whiteLoungeWear: { year: 2024, month: 2 }, - hatterSet: { year: 2024, month: 3 }, - optimistSet: { year: 2024, month: 4 }, - pottersSet: { year: 2024, month: 5 }, - beachsideSet: { year: 2024, month: 6 }, -}; - -export const EGGS_RELEASE_DATES = { - Giraffe: { year: 2024, month: 6, day: 1 }, -}; - -export const HATCHING_POTIONS_RELEASE_DATES = { - Koi: { year: 2024, month: 6, day: 1 }, -}; diff --git a/website/common/script/content/eggs.js b/website/common/script/content/eggs.js index af68a5b6be..0a6e438e5b 100644 --- a/website/common/script/content/eggs.js +++ b/website/common/script/content/eggs.js @@ -1,10 +1,7 @@ +import assign from 'lodash/assign'; import defaults from 'lodash/defaults'; import each from 'lodash/each'; -import assign from 'lodash/assign'; import t from './translation'; -import { filterReleased } from './is_released'; -import { EGGS_RELEASE_DATES } from './constants/releaseDates'; -import datedMemoize from '../fns/datedMemoize'; function applyEggDefaults (set, config) { each(set, (egg, key) => { @@ -413,20 +410,10 @@ applyEggDefaults(quests, { }, }); -function filterEggs (eggs) { - return filterReleased(eggs, 'key', EGGS_RELEASE_DATES); -} +const all = assign({}, drops, quests); -const memoizedFilter = datedMemoize(filterEggs); - -export default { - get drops () { - return memoizedFilter({ memoizeConfig: true, identifier: 'drops' }, drops); - }, - get quests () { - return memoizedFilter({ memoizeConfig: true, identifier: 'quests' }, quests); - }, - get all () { - return assign({}, this.drops, this.quests); - }, +export { + drops, + quests, + all, }; diff --git a/website/common/script/content/gear/sets/armoire.js b/website/common/script/content/gear/sets/armoire.js index eba2f92b95..8c4084ed9d 100644 --- a/website/common/script/content/gear/sets/armoire.js +++ b/website/common/script/content/gear/sets/armoire.js @@ -2,13 +2,12 @@ import defaults from 'lodash/defaults'; import find from 'lodash/find'; import forEach from 'lodash/forEach'; import moment from 'moment'; +import nconf from 'nconf'; import upperFirst from 'lodash/upperFirst'; import { ownsItem } from '../gear-helper'; import { ATTRIBUTES } from '../../../constants'; import t from '../../translation'; import memoize from '../../../fns/datedMemoize'; -import { ARMOIRE_RELEASE_DATES as releaseDates } from '../../constants/releaseDates'; -import { buildReleaseDate } from '../../is_released'; const armor = { lunarArmor: { @@ -1834,7 +1833,19 @@ const weapon = { }, }; +const SWITCHOVER_TIME = nconf.get('CONTENT_SWITCHOVER_TIME_OFFSET') || 0; const releaseDay = 7; +const releaseDates = { + somethingSpooky: { year: 2023, month: 10 }, + cookingImplementsTwo: { year: 2023, month: 11 }, + greenTrapper: { year: 2023, month: 12 }, + schoolUniform: { year: 2024, month: 1 }, + whiteLoungeWear: { year: 2024, month: 2 }, + hatterSet: { year: 2024, month: 3 }, + optimistSet: { year: 2024, month: 4 }, + pottersSet: { year: 2024, month: 5 }, + beachsideSet: { year: 2024, month: 6 }, +}; forEach({ armor, @@ -1879,12 +1890,12 @@ forEach({ function updateReleased (type) { const today = moment(); + const releaseDateEndPart = `${String(releaseDay).padStart(2, '0')}T${String(SWITCHOVER_TIME).padStart(2, '0')}:00-0500`; const returnType = {}; forEach(type, (gearItem, gearKey) => { let released; if (releaseDates[gearItem.set]) { - const components = releaseDates[gearItem.set]; - const releaseDateString = buildReleaseDate(components.year, components.month, releaseDay); + const releaseDateString = `${releaseDates[gearItem.set].year}-${String(releaseDates[gearItem.set].month).padStart(2, '0')}-${releaseDateEndPart}`; released = today.isAfter(releaseDateString); } else { released = true; diff --git a/website/common/script/content/index.js b/website/common/script/content/index.js index af344f4264..0de5f5d5f0 100644 --- a/website/common/script/content/index.js +++ b/website/common/script/content/index.js @@ -18,8 +18,8 @@ import { import achievements from './achievements'; -import eggs from './eggs'; -import hatchingPotions from './hatching-potions'; +import * as eggs from './eggs'; +import * as hatchingPotions from './hatching-potions'; import * as stable from './stable'; import gear from './gear'; import { quests, questsByLevel, userCanOwnQuestCategories } from './quests'; diff --git a/website/common/script/content/is_released.js b/website/common/script/content/is_released.js deleted file mode 100644 index e1b4f69cef..0000000000 --- a/website/common/script/content/is_released.js +++ /dev/null @@ -1,30 +0,0 @@ -import moment from 'moment'; -import filter from 'lodash/filter'; -import { pickBy } from 'lodash'; -import nconf from 'nconf'; - -const SWITCHOVER_TIME = nconf.get('CONTENT_SWITCHOVER_TIME_OFFSET') || 0; - -const releaseDateEndPart = `T${String(SWITCHOVER_TIME).padStart(2, '0')}:00-0000`; - -export function buildReleaseDate (year, month, day = 1) { - return `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}${releaseDateEndPart}`; -} - -function isReleased (item, fieldName, releaseDateMap, releaseByDefault) { - if (releaseDateMap[item[fieldName]]) { - const release = releaseDateMap[item[fieldName]]; - if (release.day) { - return moment().isAfter(moment(buildReleaseDate(release.year, release.month, release.day))); - } - return moment().isAfter(releaseDateMap[item[fieldName]]); - } - return releaseByDefault; -} - -export function filterReleased (items, fieldName, releaseDateMap, releaseByDefault = true) { - if (typeof items === 'object') { - return pickBy(items, item => isReleased(item, fieldName, releaseDateMap, releaseByDefault)); - } - return filter(items, item => isReleased(item, fieldName, releaseDateMap, releaseByDefault)); -} diff --git a/website/common/script/content/stable.js b/website/common/script/content/stable.js index 1f08886df3..e6015f6e77 100644 --- a/website/common/script/content/stable.js +++ b/website/common/script/content/stable.js @@ -1,14 +1,21 @@ import each from 'lodash/each'; import moment from 'moment'; import { EVENTS } from './constants/events'; -import allEggs from './eggs'; -import allPotions from './hatching-potions'; +import { + drops as dropEggs, + quests as questEggs, +} from './eggs'; +import { + drops as dropPotions, + premium as premiumPotions, + wacky as wackyPotions, +} from './hatching-potions'; import t from './translation'; const petInfo = {}; const mountInfo = {}; -function constructSet (type, eggs, potions, hasMounts = true) { +function constructSet (type, eggs, potions) { const pets = {}; const mounts = {}; @@ -30,24 +37,52 @@ function constructSet (type, eggs, potions, hasMounts = true) { potion: potion.text, egg: egg.text, })); - pets[key] = true; + mountInfo[key] = getAnimalData(t('mountName', { + potion: potion.text, + mount: egg.mountText, + })); - if (hasMounts) { - mountInfo[key] = getAnimalData(t('mountName', { - potion: potion.text, - mount: egg.mountText, - })); - mounts[key] = true; - } + pets[key] = true; + mounts[key] = true; + }); + }); + + return [pets, mounts]; +} + +function constructPetOnlySet (type, eggs, potions) { + const pets = {}; + + each(eggs, egg => { + each(potions, potion => { + const key = `${egg.key}-${potion.key}`; + + function getAnimalData (text) { + return { + key, + type, + potion: potion.key, + egg: egg.key, + text, + }; + } + + petInfo[key] = getAnimalData(t('petName', { + potion: potion.text, + egg: egg.text, + })); + pets[key] = true; }); }); - if (hasMounts) { - return [pets, mounts]; - } return pets; } +const [dropPets, dropMounts] = constructSet('drop', dropEggs, dropPotions); +const [premiumPets, premiumMounts] = constructSet('premium', dropEggs, premiumPotions); +const [questPets, questMounts] = constructSet('quest', questEggs, dropPotions); +const wackyPets = constructPetOnlySet('wacky', dropEggs, wackyPotions); + const canFindSpecial = { pets: { // Veteran Pet Ladder - awarded on major updates @@ -123,11 +158,6 @@ const canFindSpecial = { }, }; -const [dropPets, dropMounts] = constructSet('drop', allEggs.drops, allPotions.drops); -const [premiumPets, premiumMounts] = constructSet('premium', allEggs.drops, allPotions.premium); -const [questPets, questMounts] = constructSet('quest', allEggs.quests, allPotions.drops); -const wackyPets = constructSet('wacky', allEggs.drops, allPotions.wacky, false); - const specialPets = { 'Wolf-Veteran': 'veteranWolf', 'Wolf-Cerberus': 'cerberusPup', diff --git a/website/common/script/fns/datedMemoize.js b/website/common/script/fns/datedMemoize.js index c71ab59248..6e91fbc52c 100644 --- a/website/common/script/fns/datedMemoize.js +++ b/website/common/script/fns/datedMemoize.js @@ -33,10 +33,6 @@ const memoize = fn => { identifier = config.identifier; } } - - if (identifier.length === 0) { - identifier = args.filter(arg => typeof arg === 'string').join('-'); - } } if (!checkedDate) { checkedDate = new Date(); diff --git a/website/common/script/fns/firstDrops.js b/website/common/script/fns/firstDrops.js index 5272dcc72e..cfcd5c933a 100644 --- a/website/common/script/fns/firstDrops.js +++ b/website/common/script/fns/firstDrops.js @@ -1,10 +1,10 @@ -import allEggs from '../content/eggs'; -import allPotions from '../content/hatching-potions'; +import { drops as eggs } from '../content/eggs'; +import { drops as hatchingPotions } from '../content/hatching-potions'; import randomVal from '../libs/randomVal'; export default function firstDrops (user) { - const eggDrop = randomVal(allEggs.drops); - const potionDrop = randomVal(allPotions.drops); + const eggDrop = randomVal(eggs); + const potionDrop = randomVal(hatchingPotions); user.items.eggs = { ...user.items.eggs,