Implement new release schedule for backgrounds

This commit is contained in:
Phillip Thelen
2024-01-31 17:33:10 +01:00
committed by Sabe Jones
parent 278d9b74f9
commit 17db6a1772
4 changed files with 44 additions and 28 deletions

View File

@@ -5,32 +5,31 @@ import {
import { assembleScheduledMatchers } from '../../website/common/script/content/constants/schedule'; import { assembleScheduledMatchers } from '../../website/common/script/content/constants/schedule';
describe('Content Schedule', () => { describe('Content Schedule', () => {
it('assembles scheduled items on january 15th', () => { it('assembles scheduled items on january 15th', () => {
const items = assembleScheduledMatchers(new Date('2024-01-15')); const items = assembleScheduledMatchers(new Date('2024-01-15'));
}); });
it('assembles scheduled items on january 31th', () => { it('assembles scheduled items on january 31th', () => {
const items = assembleScheduledMatchers(new Date('2024-01-31')); const items = assembleScheduledMatchers(new Date('2024-01-31'));
}); });
it('assembles scheduled items on march 2nd', () => { it('assembles scheduled items on march 2nd', () => {
const items = assembleScheduledMatchers(new Date('2024-03-02')); const items = assembleScheduledMatchers(new Date('2024-03-02'));
}); });
it('assembles scheduled items on march 21st', () => { it('assembles scheduled items on march 21st', () => {
const items = assembleScheduledMatchers(new Date('2024-03-21')); const items = assembleScheduledMatchers(new Date('2024-03-21'));
}); });
it('assembles scheduled items on october 7th', () => { it('assembles scheduled items on october 7th', () => {
const items = assembleScheduledMatchers(new Date('2024-10-07')); const items = assembleScheduledMatchers(new Date('2024-10-07'));
}); });
it('assembles scheduled items on november 1th', () => { it('assembles scheduled items on november 1th', () => {
const items = assembleScheduledMatchers(new Date('2024-11-01')); const items = assembleScheduledMatchers(new Date('2024-11-01'));
}); });
it('assembles scheduled items on december 20th', () => { it('assembles scheduled items on december 20th', () => {
const items = assembleScheduledMatchers(new Date('2024-12-20')); const items = assembleScheduledMatchers(new Date('2024-12-20'));
}); });
}); });

View File

@@ -77,6 +77,7 @@
"userItemsNotEnough": "You do not have enough <%= type %>", "userItemsNotEnough": "You do not have enough <%= type %>",
"pathRequired": "Path string is required", "pathRequired": "Path string is required",
"unlocked": "Items have been unlocked", "unlocked": "Items have been unlocked",
"notAvailable": "This item is not available.",
"alreadyUnlocked": "Full set already unlocked.", "alreadyUnlocked": "Full set already unlocked.",
"alreadyUnlockedPart": "Full set already partially unlocked. It is cheaper to buy the remaining items individually.", "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.", "invalidUnlockSet": "This set of items is invalid and cannot be unlocked.",

View File

@@ -17,6 +17,7 @@ import featuredItems from '../content/shop-featuredItems';
import getOfficialPinnedItems from './getOfficialPinnedItems'; import getOfficialPinnedItems from './getOfficialPinnedItems';
import { getClassName } from './getClassName'; import { getClassName } from './getClassName';
import { assembleScheduledMatchers } from '../content/constants/schedule';
const shops = {}; const shops = {};
@@ -529,15 +530,18 @@ shops.getBackgroundShopSets = function getBackgroundShopSets (language) {
const sets = []; const sets = [];
const officialPinnedItems = getOfficialPinnedItems(); const officialPinnedItems = getOfficialPinnedItems();
const matchers = assembleScheduledMatchers(new Date()).filter(matcher => matcher.type === 'backgrounds').map(matcher => matcher.matcher);
eachRight(content.backgrounds, (group, key) => { eachRight(content.backgrounds, (group, key) => {
const set = { if (matchers.map(matcher => matcher(key)).every(matcher => matcher === true)) {
identifier: key, const set = {
text: i18n.t(key, language), 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; return sets;

View File

@@ -7,6 +7,7 @@ import { removeItemByPath } from './pinnedGearUtils';
import getItemInfo from '../libs/getItemInfo'; import getItemInfo from '../libs/getItemInfo';
import content from '../content/index'; import content from '../content/index';
import updateUserBalance from './updateUserBalance'; import updateUserBalance from './updateUserBalance';
import { assembleScheduledMatchers } from '../content/constants/schedule';
const incentiveBackgrounds = ['blue', 'green', 'red', 'purple', 'yellow']; 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 // The passed paths are not used anymore after this point for full sets
const { set, items, paths } = getSet(setType, firstPath, req); 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 cost;
let unlockedAlready = false; let unlockedAlready = false;