mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
simplify schedule matching usage
This commit is contained in:
committed by
Sabe Jones
parent
129cb7627c
commit
736ef16430
@@ -1,4 +1,5 @@
|
||||
import moment from 'moment';
|
||||
import SEASONAL_SETS from './seasonalSets';
|
||||
|
||||
function backgroundMatcher (month1, month2, oddYear) {
|
||||
return function call (key) {
|
||||
@@ -601,13 +602,34 @@ export const MONTHLY_SCHEDULE = {
|
||||
|
||||
export const GALA_SWITCHOVER_DAY = 21;
|
||||
export const GALA_SCHEDULE = {
|
||||
0: [],
|
||||
1: [],
|
||||
2: [],
|
||||
3: [],
|
||||
0: [
|
||||
{
|
||||
type: 'seasonalGear',
|
||||
matcher: inListMatcher(SEASONAL_SETS.winter),
|
||||
},
|
||||
],
|
||||
1: [
|
||||
{
|
||||
type: 'seasonalGear',
|
||||
matcher: inListMatcher(SEASONAL_SETS.spring),
|
||||
},
|
||||
],
|
||||
2: [
|
||||
{
|
||||
type: 'seasonalGear',
|
||||
matcher: inListMatcher(SEASONAL_SETS.fall),
|
||||
},
|
||||
],
|
||||
3: [
|
||||
{
|
||||
type: 'seasonalGear',
|
||||
matcher: inListMatcher(SEASONAL_SETS.summer),
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export function assembleScheduledMatchers (date) {
|
||||
console.log('Assembling new Schedule!');
|
||||
const items = [];
|
||||
const month = date instanceof moment ? date.month() : date.getMonth();
|
||||
const todayDay = date instanceof moment ? date.date() : date.getDate();
|
||||
@@ -630,3 +652,24 @@ export function assembleScheduledMatchers (date) {
|
||||
items.push(...GALA_SCHEDULE[parseInt((galaCount / 12) * galaMonth, 10)]);
|
||||
return items;
|
||||
}
|
||||
|
||||
let cachedScheduleMatchers = null;
|
||||
|
||||
export function getScheduleMatchingGroup (type, date) {
|
||||
if (!cachedScheduleMatchers) {
|
||||
cachedScheduleMatchers = {};
|
||||
assembleScheduledMatchers(date !== undefined ? date : new Date()).forEach(matcher => {
|
||||
if (cachedScheduleMatchers[matcher.type]) {
|
||||
cachedScheduleMatchers[matcher.type].matchers.push(matcher.matcher);
|
||||
} else {
|
||||
cachedScheduleMatchers[matcher.type] = {
|
||||
matchers: [matcher.matcher],
|
||||
match (key) {
|
||||
return this.matchers.every(m => m(key));
|
||||
},
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
return cachedScheduleMatchers[type];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user