@@ -3,15 +3,24 @@ import * as settings from '../../utils/settings/index.js';
3
3
import { global , globalSet } from '../../utils/global.js' ;
4
4
import style from '../../utils/style.js' ;
5
5
import onPage from '../../utils/onPage.js' ;
6
+ import { translateText } from '../../utils/translate.js' ;
7
+ import { max } from '../../utils/cardHelper.js' ;
6
8
7
9
export const crafting = onPage ( 'Crafting' ) ;
8
10
export const decks = onPage ( 'Decks' ) ;
9
11
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 ) {
11
18
return removed ;
12
19
} ,
13
20
] ;
14
21
22
+ filters . shift ( ) ; // Remove template
23
+
15
24
const base = {
16
25
onChange : ( ) => applyLook ( ) ,
17
26
category : 'Filter' ,
@@ -38,6 +47,12 @@ const tribe = settings.register({
38
47
key : 'underscript.deck.filter.tribe' ,
39
48
} ) ;
40
49
50
+ const owned = settings . register ( {
51
+ ...base ,
52
+ name : 'Collection dropdown' ,
53
+ key : 'underscript.deck.filter.collection' ,
54
+ } ) ;
55
+
41
56
const shiny = settings . register ( {
42
57
...base ,
43
58
name : 'Merge Shiny Cards' ,
@@ -47,6 +62,7 @@ const shiny = settings.register({
47
62
} ) ;
48
63
49
64
style . add (
65
+ '#ownedType { margin-bottom: 10px; }' ,
50
66
'.filter input+* { opacity: 0.4; }' ,
51
67
'.filter input:checked+* { opacity: 1; }' ,
52
68
'.filter input:disabled, .filter input:disabled+* { display: none; }' ,
@@ -74,6 +90,15 @@ function applyLook(refresh = decks || crafting) {
74
90
}
75
91
$ ( '#allTribeInput' ) . prop ( 'disabled' , ! tribe . value ( ) ) ;
76
92
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
+
77
102
$ ( '#shinyInput' ) . prop ( 'disabled' , mergeShiny ( ) ) ;
78
103
if ( refresh ) {
79
104
global ( 'applyFilters' ) ( ) ;
@@ -116,6 +141,19 @@ function allTribeButton() {
116
141
</label>` ) ;
117
142
}
118
143
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
+
119
157
filters . push (
120
158
function basicFilter ( card ) {
121
159
// Rarity, Type, Extension, Search
@@ -150,7 +188,18 @@ filters.push(
150
188
function searchFilter ( card , removed ) { // Custom keywords
151
189
return removed ;
152
190
} ,
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
+ }
154
203
return removed ;
155
204
} ,
156
205
) ;
0 commit comments