@@ -111,7 +111,7 @@ function applyLook(refresh = decks || crafting) {
111111
112112 // Re-add shiny filter
113113 if ( ! $ ( '#shinyInput' ) . length ) {
114- $ ( '#utyInput' ) . parent ( ) . after ( ' ' , shinyButton ( ) ) ;
114+ $ ( '#utyInput' ) . parent ( ) . after ( shinyButton ( ) ) ;
115115 }
116116 $ ( '#shinyInput' ) . prop ( 'disabled' , mergeShiny ( ) ) ;
117117
@@ -126,11 +126,16 @@ eventManager.on(':preload:Decks :preload:Crafting', () => {
126126 applyLook ( false ) ;
127127 globalSet ( 'isRemoved' , function newFilter ( card ) {
128128 if ( setting . value ( ) ) return this . super ( card ) ;
129+ const results = new Map ( ) ;
129130 return filters . reduce ( ( removed , func ) => {
130- const val = func . call ( this , card , removed ) ;
131+ if ( ! func ) return removed ;
132+ const val = func . call ( this , card , removed , Object . fromEntries ( results ) ) ;
133+ const key = func . displayName || func . name ;
131134 if ( typeof val === 'boolean' ) {
135+ results . set ( key , val !== removed ) ;
132136 return val ;
133137 }
138+ results . set ( key , null ) ;
134139 return removed ;
135140 } , false ) ;
136141 } ) ;
@@ -178,55 +183,80 @@ function ownSelect() {
178183}
179184
180185filters . push (
181- function basicFilter ( card ) {
182- // Rarity, Type, Extension, Search
183- return this . super ( card ) ;
186+ // function isRemoved(card) {
187+ // // Shiny, Rarity, Type, Extension, Search
188+ // return this.super(card);
189+ // },
190+ // eslint-disable-next-line no-shadow
191+ function shiny ( card , removed ) {
192+ if ( removed ) return null ;
193+ if ( mergeShiny ( ) ) return false ;
194+ return card . shiny !== $ ( '#shinyInput' ) . prop ( 'checked' ) ;
184195 } ,
185- function shinyFilter ( card , removed ) {
186- if ( ! removed ) {
187- return ! mergeShiny ( ) && card . shiny !== $ ( '#shinyInput' ) . prop ( 'checked' ) ;
196+ function rarity ( card , removed ) {
197+ if ( removed ) return null ;
198+ const rarities = $ ( '.rarityInput:checked' ) . map ( function getRarity ( ) {
199+ return this . getAttribute ( 'rarity' ) ;
200+ } ) . get ( ) ;
201+ return rarities . length > 0 && ! rarities . includes ( card . rarity ) ;
202+ } ,
203+ function type ( card , removed ) {
204+ if ( removed ) return null ;
205+ const monster = $ ( '#monsterInput' ) . prop ( 'checked' ) ;
206+ const spell = $ ( '#spellInput' ) . prop ( 'checked' ) ;
207+ const cardType = monster ? 0 : 1 ;
208+ return monster !== spell && card . typeCard !== cardType ;
209+ } ,
210+ function extension ( card , removed ) {
211+ if ( removed ) return null ;
212+ const extensions = [ ] ;
213+ if ( $ ( '#undertaleInput' ) . prop ( 'checked' ) ) {
214+ extensions . push ( 'BASE' ) ;
188215 }
189-
190- if ( mergeShiny ( ) ) {
191- return this . super ( {
192- ...card ,
193- shiny : ! card . shiny ,
194- } ) ;
216+ if ( $ ( '#deltaruneInput' ) . prop ( 'checked' ) ) {
217+ extensions . push ( 'DELTARUNE' ) ;
195218 }
196- return removed ;
197- } ,
198- function baseGenFilter ( card , removed ) {
199- if ( ! removed && crafting && splitBaseGen . value ( ) ) {
200- if ( card . rarity === 'BASE' && ! card . shiny && ! $ ( '#baseRarityInput' ) . prop ( 'checked' ) ) {
201- return true ;
202- }
203- if ( card . rarity === 'TOKEN' && ! $ ( '#tokenRarityInput' ) . prop ( 'checked' ) ) {
204- return true ;
205- }
219+ if ( $ ( '#utyInput' ) . prop ( 'checked' ) ) {
220+ extensions . push ( 'UTY' ) ;
206221 }
207- return removed ;
222+ return extensions . length > 0 && ! extensions . includes ( card . extension ) ;
208223 } ,
209- function tribeFilter ( card , removed ) {
210- if ( ! removed && tribe . value ( ) && $ ( '#allTribeInput' ) . prop ( 'checked' ) ) {
211- return ! card . tribes . length ;
224+ function search ( card , removed ) {
225+ if ( removed ) return null ;
226+ const text = $ ( '#searchInput' ) . val ( ) . toLowerCase ( ) ;
227+ if ( ! text . length ) return false ;
228+ function includes ( dirty ) {
229+ return dirty . replace ( / ( < .* ?> ) / g, '' ) . toLowerCase ( ) . includes ( text ) ;
212230 }
213- return removed ;
231+ return (
232+ ! includes ( $ . i18n ( `card-name-${ card . id } ` , 1 ) ) &&
233+ ! includes ( $ . i18n ( `card-${ card . id } ` ) ) &&
234+ ! ( card . soul ?. name && includes ( $ . i18n ( `soul-${ card . soul . name . toLowerCase ( ) . replace ( / _ / g, '-' ) } ` ) ) ) &&
235+ ! card . tribes . some ( ( t ) => includes ( $ . i18n ( `tribe-${ t . toLowerCase ( ) . replace ( / _ / g, '-' ) } ` ) ) )
236+ ) ;
214237 } ,
215- function searchFilter ( card , removed ) { // Custom keywords
216- return removed ;
238+ crafting && function baseGenFilter ( card , removed ) {
239+ if ( removed || ! splitBaseGen . value ( ) ) return null ;
240+ return (
241+ card . rarity === 'BASE' && ! card . shiny && ! $ ( '#baseRarityInput' ) . prop ( 'checked' )
242+ ) || (
243+ card . rarity === 'TOKEN' && ! $ ( '#tokenRarityInput' ) . prop ( 'checked' )
244+ ) ;
217245 } ,
218- function ownedFilter ( card , removed ) {
219- if ( ! removed && crafting && owned . value ( ) ) {
220- switch ( $ ( '#collectionType' ) . val ( ) ) {
221- case 'owned' : return ! card . quantity ;
222- case 'unowned' : return card . quantity > 0 ;
223- case 'maxed' : return card . quantity < max ( card . rarity ) ;
224- case 'surplus' : return card . quantity <= max ( card . rarity ) ;
225- case 'craftable' : return card . quantity >= max ( card . rarity ) ;
226- case 'all' :
227- default : break ;
228- }
246+ function tribeFilter ( card , removed ) {
247+ if ( removed || ! tribe . value ( ) ) return null ;
248+ return $ ( '#allTribeInput' ) . prop ( 'checked' ) && ! card . tribes . length ;
249+ } ,
250+ crafting && function ownedFilter ( card , removed ) {
251+ if ( removed || ! owned . value ( ) ) return null ;
252+ switch ( $ ( '#collectionType' ) . val ( ) ) {
253+ case 'owned' : return ! card . quantity ;
254+ case 'unowned' : return card . quantity > 0 ;
255+ case 'maxed' : return card . quantity < max ( card . rarity ) ;
256+ case 'surplus' : return card . quantity <= max ( card . rarity ) ;
257+ case 'craftable' : return card . quantity >= max ( card . rarity ) ;
258+ case 'all' :
259+ default : return false ;
229260 }
230- return removed ;
231261 } ,
232262) ;
0 commit comments