Skip to content

Commit 58fa9c8

Browse files
committed
feat: card selection filter
1 parent 2fd43f1 commit 58fa9c8

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

changelog.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
# UnderScript Changelog
22

33
## Version 0.57.0 (2024-04-01)
4-
1. Adjust music volume while in settings
4+
### New Features
55
1. Added filter for tribes
6+
1. Added filters for crafting collection
7+
### Misc.
8+
1. Adjust music volume while in settings
9+
### Plugin
10+
1. Added method for plugins to add own collection filters `plugin.addFilter()`
611

712
## Version 0.56.3 (2024-03-31)
813
1. Removed broken googletagmanager

src/base/library/filter.js

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,24 @@ import * as settings from '../../utils/settings/index.js';
33
import { global, globalSet } from '../../utils/global.js';
44
import style from '../../utils/style.js';
55
import onPage from '../../utils/onPage.js';
6+
import { translateText } from '../../utils/translate.js';
7+
import { max } from '../../utils/cardHelper.js';
68

79
export const crafting = onPage('Crafting');
810
export const decks = onPage('Decks');
911
export const filters = [
10-
function templateFilter(card, removed = false) {
12+
/**
13+
* @param {Card} card
14+
* @param {boolean} removed
15+
* @returns {boolean | undefined}
16+
*/
17+
function templateFilter(card, removed) {
1118
return removed;
1219
},
1320
];
1421

22+
filters.shift(); // Remove template
23+
1524
const base = {
1625
onChange: () => applyLook(),
1726
category: 'Filter',
@@ -38,6 +47,12 @@ const tribe = settings.register({
3847
key: 'underscript.deck.filter.tribe',
3948
});
4049

50+
const owned = settings.register({
51+
...base,
52+
name: 'Collection dropdown',
53+
key: 'underscript.deck.filter.collection',
54+
});
55+
4156
const shiny = settings.register({
4257
...base,
4358
name: 'Merge Shiny Cards',
@@ -47,6 +62,7 @@ const shiny = settings.register({
4762
});
4863

4964
style.add(
65+
'#ownedType { margin-bottom: 10px; }',
5066
'.filter input+* { opacity: 0.4; }',
5167
'.filter input:checked+* { opacity: 1; }',
5268
'.filter input:disabled, .filter input:disabled+* { display: none; }',
@@ -74,6 +90,15 @@ function applyLook(refresh = decks || crafting) {
7490
}
7591
$('#allTribeInput').prop('disabled', !tribe.value());
7692

93+
const allCardsElement = $('[data-i18n="[html]crafting-all-cards"]');
94+
if (setting.value() || !owned.value()) {
95+
$('#collectionType').remove();
96+
allCardsElement.toggleClass('invisible', false);
97+
} else if (!$('#collectionType').length) {
98+
allCardsElement.toggleClass('invisible', true)
99+
.after(ownSelect());
100+
}
101+
77102
$('#shinyInput').prop('disabled', mergeShiny());
78103
if (refresh) {
79104
global('applyFilters')();
@@ -116,6 +141,19 @@ function allTribeButton() {
116141
</label>`);
117142
}
118143

144+
function ownSelect() {
145+
return $(`
146+
<select id="collectionType" onchange="applyFilters(); showPage(0);">
147+
<option value="all">${translateText('crafting-all-cards')}</option>
148+
<option value="owned">Owned cards</option>
149+
<option value="unowned">Unowned cards</option>
150+
<option value="maxed">Maxed cards</option>
151+
<option value="surplus">Surplus cards</option>
152+
<option value="craftable">Craftable cards</option>
153+
</select>
154+
`);
155+
}
156+
119157
filters.push(
120158
function basicFilter(card) {
121159
// Rarity, Type, Extension, Search
@@ -150,7 +188,18 @@ filters.push(
150188
function searchFilter(card, removed) { // Custom keywords
151189
return removed;
152190
},
153-
function unownedFilter(card, removed) { // Crafting only
191+
function ownedFilter(card, removed) {
192+
if (!removed && crafting && owned.value()) {
193+
switch ($('#collectionType').val()) {
194+
case 'owned': return !card.quantity;
195+
case 'unowned': return card.quantity > 0;
196+
case 'maxed': return card.quantity < max(card.rarity);
197+
case 'surplus': return card.quantity <= max(card.rarity);
198+
case 'craftable': return card.quantity >= max(card.rarity) || card.rarity === 'DETERMINATION';
199+
case 'all': // fall-through
200+
default: break;
201+
}
202+
}
154203
return removed;
155204
},
156205
);

0 commit comments

Comments
 (0)