From 17db6a17725ca6ddd6c607d7aa2c735c80daddc6 Mon Sep 17 00:00:00 2001 From: Phillip Thelen Date: Wed, 31 Jan 2024 17:33:10 +0100 Subject: [PATCH] Implement new release schedule for backgrounds --- test/content/schedule.test.js | 43 ++++++++++++++--------------- website/common/locales/en/npc.json | 1 + website/common/script/libs/shops.js | 16 +++++++---- website/common/script/ops/unlock.js | 12 ++++++++ 4 files changed, 44 insertions(+), 28 deletions(-) diff --git a/test/content/schedule.test.js b/test/content/schedule.test.js index 5d7c211dfe..e61e837f9e 100644 --- a/test/content/schedule.test.js +++ b/test/content/schedule.test.js @@ -5,32 +5,31 @@ import { import { assembleScheduledMatchers } from '../../website/common/script/content/constants/schedule'; - describe('Content Schedule', () => { - it('assembles scheduled items on january 15th', () => { - const items = assembleScheduledMatchers(new Date('2024-01-15')); - }); + it('assembles scheduled items on january 15th', () => { + const items = assembleScheduledMatchers(new Date('2024-01-15')); + }); - it('assembles scheduled items on january 31th', () => { - const items = assembleScheduledMatchers(new Date('2024-01-31')); - }); + it('assembles scheduled items on january 31th', () => { + const items = assembleScheduledMatchers(new Date('2024-01-31')); + }); - it('assembles scheduled items on march 2nd', () => { - const items = assembleScheduledMatchers(new Date('2024-03-02')); - }); + it('assembles scheduled items on march 2nd', () => { + const items = assembleScheduledMatchers(new Date('2024-03-02')); + }); - it('assembles scheduled items on march 21st', () => { - const items = assembleScheduledMatchers(new Date('2024-03-21')); - }); + it('assembles scheduled items on march 21st', () => { + const items = assembleScheduledMatchers(new Date('2024-03-21')); + }); - it('assembles scheduled items on october 7th', () => { - const items = assembleScheduledMatchers(new Date('2024-10-07')); - }); - it('assembles scheduled items on november 1th', () => { - const items = assembleScheduledMatchers(new Date('2024-11-01')); - }); + it('assembles scheduled items on october 7th', () => { + const items = assembleScheduledMatchers(new Date('2024-10-07')); + }); + it('assembles scheduled items on november 1th', () => { + const items = assembleScheduledMatchers(new Date('2024-11-01')); + }); - it('assembles scheduled items on december 20th', () => { - const items = assembleScheduledMatchers(new Date('2024-12-20')); - }); + it('assembles scheduled items on december 20th', () => { + const items = assembleScheduledMatchers(new Date('2024-12-20')); + }); }); diff --git a/website/common/locales/en/npc.json b/website/common/locales/en/npc.json index 19fca03acd..b92aabc71c 100644 --- a/website/common/locales/en/npc.json +++ b/website/common/locales/en/npc.json @@ -77,6 +77,7 @@ "userItemsNotEnough": "You do not have enough <%= type %>", "pathRequired": "Path string is required", "unlocked": "Items have been unlocked", + "notAvailable": "This item is not available.", "alreadyUnlocked": "Full set already unlocked.", "alreadyUnlockedPart": "Full set already partially unlocked. It is cheaper to buy the remaining items individually.", "invalidUnlockSet": "This set of items is invalid and cannot be unlocked.", diff --git a/website/common/script/libs/shops.js b/website/common/script/libs/shops.js index 39dc7bd88e..44d0035a6f 100644 --- a/website/common/script/libs/shops.js +++ b/website/common/script/libs/shops.js @@ -17,6 +17,7 @@ import featuredItems from '../content/shop-featuredItems'; import getOfficialPinnedItems from './getOfficialPinnedItems'; import { getClassName } from './getClassName'; +import { assembleScheduledMatchers } from '../content/constants/schedule'; const shops = {}; @@ -529,15 +530,18 @@ shops.getBackgroundShopSets = function getBackgroundShopSets (language) { const sets = []; const officialPinnedItems = getOfficialPinnedItems(); + const matchers = assembleScheduledMatchers(new Date()).filter(matcher => matcher.type === 'backgrounds').map(matcher => matcher.matcher); eachRight(content.backgrounds, (group, key) => { - const set = { - identifier: key, - text: i18n.t(key, language), - }; + if (matchers.map(matcher => matcher(key)).every(matcher => matcher === true)) { + const set = { + identifier: key, + text: i18n.t(key, language), + }; - set.items = map(group, background => getItemInfo(null, 'background', background, officialPinnedItems, language)); + set.items = map(group, background => getItemInfo(null, 'background', background, officialPinnedItems, language)); - sets.push(set); + sets.push(set); + } }); return sets; diff --git a/website/common/script/ops/unlock.js b/website/common/script/ops/unlock.js index 342c9dc7a9..3cc4b4cf01 100644 --- a/website/common/script/ops/unlock.js +++ b/website/common/script/ops/unlock.js @@ -7,6 +7,7 @@ import { removeItemByPath } from './pinnedGearUtils'; import getItemInfo from '../libs/getItemInfo'; import content from '../content/index'; import updateUserBalance from './updateUserBalance'; +import { assembleScheduledMatchers } from '../content/constants/schedule'; const incentiveBackgrounds = ['blue', 'green', 'red', 'purple', 'yellow']; @@ -223,6 +224,17 @@ export default async function unlock (user, req = {}, analytics) { // The passed paths are not used anymore after this point for full sets const { set, items, paths } = getSet(setType, firstPath, req); + if (isBackground) { + const matchers = assembleScheduledMatchers(new Date()) + .filter(matcher => matcher.type === 'backgrounds') + .map(matcher => matcher.matcher); + const isAvailable = matchers.map(matcher => matcher(set.key)) + .every(matcher => matcher === true); + if (!isAvailable) { + throw new NotAuthorized(i18n.t('notAvailable', req.language)); + } + } + let cost; let unlockedAlready = false;