Skip to content

Commit aba0999

Browse files
committed
feat: priority filters
1 parent 060150b commit aba0999

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/base/library/filter.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import style from 'src/utils/style.js';
55
import onPage from 'src/utils/onPage.js';
66
import { max } from 'src/utils/cardHelper.js';
77
import Translation from 'src/structures/constants/translation.ts';
8+
import Priority from 'src/structures/constants/priority.js';
89
import { getTranslationArray } from '../underscript/translation.js';
910

1011
export const crafting = onPage('Crafting');
@@ -114,7 +115,7 @@ eventManager.on(':preload:Decks :preload:Crafting', () => {
114115
if (setting.value()) return this.super(card);
115116
const results = new Map();
116117
return filters.reduce((removed, func) => {
117-
if (!func) return removed;
118+
if (typeof func !== 'function') return removed;
118119
const val = func.call(this, card, removed, Object.fromEntries(results));
119120
const key = func.displayName || func.name;
120121
if (typeof val === 'boolean') {
@@ -161,6 +162,7 @@ function ownSelect() {
161162
}
162163

163164
filters.push(
165+
Priority.FIRST,
164166
// function isRemoved(card) {
165167
// // Shiny, Rarity, Type, Extension, Search
166168
// return this.super(card);
@@ -213,6 +215,8 @@ filters.push(
213215
!card.tribes.some((t) => includes($.i18n(`tribe-${t.toLowerCase().replace(/_/g, '-')}`)))
214216
);
215217
},
218+
Priority.HIGHEST,
219+
Priority.HIGH,
216220
crafting && function baseGenFilter(card, removed) {
217221
if (removed || $('.rarityInput:checked').length) return null;
218222
return ['BASE', 'TOKEN'].includes(card.rarity);
@@ -233,4 +237,8 @@ filters.push(
233237
default: return false;
234238
}
235239
},
240+
Priority.NORMAL,
241+
Priority.LOW,
242+
Priority.LOWEST,
243+
Priority.LAST,
236244
);

src/base/plugin/addFilter.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import wrap from 'src/utils/2.pokemon.js';
22
import { registerModule } from 'src/utils/plugin.js';
3+
import Priority from 'src/structures/constants/priority.js';
34
import { crafting, decks, filters } from '../library/filter.js';
45

56
wrap(() => {
67
if (!(crafting || decks)) return;
78
const name = 'addFilter';
89
let counter = 0;
910
function mod(plugin) {
10-
return (filter) => {
11+
return (filter, priority = Priority.NORMAL) => {
12+
const fixedPriority = Priority.get(priority);
13+
if (!fixedPriority) throw new Error('Must pass a valid priority');
1114
if (typeof filter !== 'function') throw new Error('Must pass a function');
1215
counter += 1;
1316
const functionName = filter.displayName || filter.name || `filter${counter}`;
@@ -20,7 +23,8 @@ wrap(() => {
2023
return undefined;
2124
}
2225
customFilter.displayName = `${plugin.name}:${functionName}`;
23-
filters.push(customFilter);
26+
const index = filters.indexOf(fixedPriority);
27+
filters.splice(index, 0, customFilter);
2428
};
2529
}
2630

0 commit comments

Comments
 (0)