@@ -90,10 +90,11 @@ onPage('Decks', function deckStorage() {
9090
9191 function loadDeck ( i ) {
9292 if ( i === null ) return ;
93+ debug ( 'loading' ) ;
9394 pending = [ ] ; // Clear pending
9495 loading = i ;
9596 const soul = $ ( '#selectClasses' ) . find ( ':selected' ) . text ( ) ;
96- let deck = JSON . parse ( localStorage . getItem ( `underscript.deck.${ selfId } .${ soul } .${ i } ` ) ) ;
97+ let deck = getDeck ( `underscript.deck.${ selfId } .${ soul } .${ i } ` , true ) ;
9798 const cDeck = $ ( `#deckCards${ soul } li` ) ;
9899
99100 if ( cDeck . length ) {
@@ -122,20 +123,29 @@ onPage('Decks', function deckStorage() {
122123
123124 // Check what we need to do
124125 if ( ! removals . length && ! temp . length ) { // There's nothing
126+ debug ( 'Finished' ) ;
125127 return ;
126128 } else if ( removals . length > 13 ) { // Too much to do (Cards in deck + 1)
127129 pending . push ( {
128130 action : 'clear' ,
129131 } ) ;
130132 } else {
131- pending . push . apply ( pending , removals ) ;
133+ pending . push ( ... removals ) ;
132134 deck = temp ;
133135 }
134136 }
135- pending . push . apply ( pending , deck ) ;
137+ pending . push ( ... deck ) ;
136138 processNext ( ) ;
137139 }
138140
141+ function getDeck ( key , trim ) {
142+ const deck = JSON . parse ( localStorage . getItem ( key ) ) ;
143+ if ( trim ) {
144+ return deck . filter ( ( { id, shiny} ) => $ ( `table#${ id } ${ shiny ?'.shiny' :':not(.shiny)' } :lt(1)` ) . length ) ;
145+ }
146+ return deck ;
147+ }
148+
139149 function cards ( list ) {
140150 const names = [ ] ;
141151 list . forEach ( ( card ) => {
@@ -169,7 +179,7 @@ onPage('Decks', function deckStorage() {
169179 function hoverButton ( e ) {
170180 let text = '' ;
171181 if ( e . type === 'mouseenter' ) {
172- const deck = JSON . parse ( localStorage . getItem ( deckKey ) ) ;
182+ const deck = getDeck ( deckKey ) ;
173183 if ( deck ) {
174184 text = `
175185 <div id="deckName">${ localStorage . getItem ( nameKey ) || ( `${ soul } -${ i + 1 } ` ) } </div>
0 commit comments