1+ // globals updateQuantity, currentPage, applyFilters, showPage, collection
12onPage ( 'Crafting' , function disenchant ( ) {
23 eventManager . on ( 'jQuery' , ( ) => {
34 const button = $ ( '<button class="btn btn-info">Smart Disenchant</button>' ) ;
@@ -71,7 +72,7 @@ onPage('Crafting', function disenchant() {
7172 . then ( ( response ) => {
7273 if ( ! response ) throw new Error ( 'All errored out' ) ;
7374 const data = response . data ;
74- const gained = data . dust - parseInt ( $ ( '#dust' ) . text ( ) ) ;
75+ const gained = data . dust - parseInt ( $ ( '#dust' ) . text ( ) , 10 ) ;
7576 $ ( '#dust' ) . text ( data . dust ) ;
7677 $ ( '#totalDisenchant' ) . text ( data . totalDisenchant ) ;
7778 $ ( '#nbDTFragments' ) . text ( data . DTFragments ) ;
@@ -80,6 +81,8 @@ onPage('Crafting', function disenchant() {
8081 if ( data . DTFragments ) {
8182 $ ( '#DTFragmentsDiv' ) . show ( ) ;
8283 }
84+ applyFilters ( ) ;
85+ showPage ( currentPage ) ;
8386 updateOrToast ( toast , `Finished disenchanting.\n+${ gained } dust` ) ;
8487 } ) . catch ( ( ) => {
8588 updateOrToast ( toast , 'Could not complete disenchanting.' ) ;
@@ -129,8 +132,7 @@ onPage('Crafting', function disenchant() {
129132 debug ( 'set' ) ;
130133 last = response ;
131134 }
132- const quantity = cardHelper . find ( response . data . cardId , response . data . shiny ) . querySelector ( `#quantity .nb` ) ;
133- quantity . textContent = parseInt ( quantity . textContent ) - 1 ;
135+ updateQuanity ( JSON . parse ( response . data . card ) , - 1 ) ; // External
134136 } ) ;
135137 if ( redo . length ) {
136138 debug ( `Redoing ${ redo . length } ` ) ;
@@ -140,40 +142,31 @@ onPage('Crafting', function disenchant() {
140142 return last ;
141143 }
142144
145+ function cardFilter ( card , shiny , priority , family ) {
146+ // TODO: Family filters
147+ return card . quantity > 0 && include ( card . rarity ) && ( priority || card . shiny === shiny ) ;
148+ }
149+
143150 function calcCards ( { shiny, priority, deltarune} ) {
144151 const cards = { } ;
145152 const extras = [ ] ;
146- $ ( 'table.cardBoard' ) . filter ( function ( ) {
147- // Don't include DT/unknown cards
148- return include ( cardHelper . rarity ( this ) ) ;
149- } ) . filter ( function ( ) {
150- // We want to calculate all cards for "priority", otherwise we only want shiny/normals
151- return priority || cardHelper . shiny ( this ) === shiny ;
152- } ) . filter ( function ( ) {
153- // We only care if we actually have cards to remove
154- return cardHelper . craft . quantity ( this ) > 0 ;
155- } ) . each ( function ( ) {
156- const id = this . id ;
157- const quantity = cardHelper . craft . quantity ( this ) ;
158- const rarity = cardHelper . rarity ( this ) ;
159- if ( priority ) {
160- if ( ! cards . hasOwnProperty ( id ) ) {
161- const max = cardHelper . craft . max ( rarity ) ;
162- if ( ! max ) return ;
163- cards [ id ] = {
164- max, rarity,
165- name : cardHelper . name ( this ) ,
166- } ;
153+ collection . filter ( ( card ) => cardFilter ( card , shiny , priority , deltarune ) )
154+ . forEach ( ( { id, name, shiny : isShiny , rarity, quantity} ) => {
155+ if ( priority ) {
156+ if ( ! cards . hasOwnProperty ( id ) ) {
157+ const max = cardHelper . craft . max ( rarity ) ;
158+ if ( ! max ) return ;
159+ cards [ id ] = {
160+ max, rarity, name,
161+ } ;
162+ }
163+ cards [ id ] [ isShiny ?'shiny' :'normal' ] = quantity ;
164+ } else {
165+ extras . push ( {
166+ id, name, rarity, quantity, shiny,
167+ } ) ;
167168 }
168- const isShiny = cardHelper . shiny ( this ) ;
169- cards [ id ] [ isShiny ?'shiny' :'normal' ] = quantity ;
170- } else {
171- extras . push ( {
172- id, rarity, quantity, shiny,
173- name : cardHelper . name ( this ) ,
174- } ) ;
175- }
176- } ) ;
169+ } ) ;
177170 if ( priority ) {
178171 // Calculate extras
179172 fn . each ( cards , function ( data , id ) {
0 commit comments