@@ -17,10 +17,6 @@ settings.register({
17
17
18
18
onPage ( 'Decks' , function deckStorage ( ) {
19
19
if ( settings . value ( 'underscript.storage.disable' ) ) return ;
20
- const mockLastOpenedDialog = {
21
- close ( ) { } ,
22
- } ;
23
- let templastOpenedDialog ;
24
20
style . add ( '.btn-storage { margin-top: 5px; margin-right: 6px; width: 30px; padding: 5px 0; }' ) ;
25
21
26
22
function getFromLibrary ( id , library , shiny ) {
@@ -43,50 +39,6 @@ onPage('Decks', function deckStorage() {
43
39
eventManager . on ( 'jQuery' , ( ) => {
44
40
const container = $ ( '<p>' ) ;
45
41
const buttons = [ ] ;
46
- let loading ;
47
- let pending = [ ] ;
48
-
49
- function processNext ( ) {
50
- if ( global ( 'lastOpenedDialog' ) === mockLastOpenedDialog ) {
51
- globalSet ( 'lastOpenedDialog' , templastOpenedDialog ) ;
52
- }
53
- const job = pending . shift ( ) ;
54
- if ( job ) {
55
- if ( job . action === 'validate' ) {
56
- loadDeck ( loading ) ;
57
- if ( ! pending . length ) {
58
- loading = null ;
59
- }
60
- return ;
61
- }
62
- if ( job . action === 'clear' ) {
63
- global ( 'removeAllCards' ) ( ) ;
64
- } else if ( job . action === 'remove' ) {
65
- global ( 'removeCard' ) ( parseInt ( job . id , 10 ) , job . shiny === true ) ;
66
- } else if ( job . action === 'clearArtifacts' ) {
67
- global ( 'clearArtifacts' ) ( ) ;
68
- } else if ( job . action === 'addArtifact' ) {
69
- debug ( `Adding artifact: ${ job . id } ` ) ;
70
- templastOpenedDialog = global ( 'lastOpenedDialog' ) ;
71
- globalSet ( 'lastOpenedDialog' , mockLastOpenedDialog ) ;
72
- global ( 'addArtifact' ) ( job . id ) ;
73
- } else {
74
- global ( 'addCard' ) ( parseInt ( job . id , 10 ) , job . shiny === true ) ;
75
- }
76
- if ( ! pending . length ) {
77
- pending . push ( { action : 'validate' } ) ;
78
- }
79
- }
80
- }
81
-
82
- eventManager . on ( 'Deck:postChange' , ( { action, data } ) => {
83
- if ( ! [ 'addCard' , 'removeCard' , 'removeAllCards' , 'clearArtifacts' , 'addArtifact' ] . includes ( action ) ) return ;
84
- if ( data . status === 'error' ) {
85
- pending = [ ] ;
86
- return ;
87
- }
88
- processNext ( ) ;
89
- } ) ;
90
42
91
43
for ( let i = 1 , x = Math . max ( parseInt ( settings . value ( 'underscript.storage.rows' ) , 10 ) , 1 ) * 5 ; i <= x ; i ++ ) {
92
44
buttons . push ( $ ( '<button>' )
@@ -98,8 +50,7 @@ onPage('Decks', function deckStorage() {
98
50
container . append ( button ) ;
99
51
} ) ;
100
52
101
- const clearDeck = $ ( '#yourCardList > button:last' ) ;
102
- clearDeck . after ( container ) ;
53
+ $ ( '#deckCardsCanvas' ) . before ( container ) ;
103
54
$ ( '#yourCardList > br' ) . remove ( ) ;
104
55
$ ( '#yourCardList' ) . css ( 'margin-bottom' , '35px' ) ;
105
56
@@ -137,67 +88,10 @@ onPage('Decks', function deckStorage() {
137
88
138
89
function loadDeck ( i ) {
139
90
if ( i === null ) return ;
140
- debug ( 'loading' ) ;
141
- pending = [ ] ; // Clear pending
142
- loading = i ;
143
- let deck = getDeck ( i , true ) ;
144
- const cDeck = global ( 'decks' ) [ global ( 'soul' ) ] ;
145
-
146
- if ( cDeck . length ) {
147
- const builtDeck = [ ] ;
148
- // Build deck options
149
- cDeck . forEach ( ( { id, shiny } ) => {
150
- builtDeck . push ( {
151
- id,
152
- shiny,
153
- action : 'remove' ,
154
- } ) ;
155
- } ) ;
156
-
157
- // Compare the decks
158
- const temp = deck . slice ( 0 ) ;
159
- const removals = builtDeck . filter ( ( card ) => ! temp . some ( ( card2 , ind ) => {
160
- const found = card2 . id === card . id && ( card . shiny && card2 . shiny || true ) ;
161
- if ( found ) { // Remove the item
162
- temp . splice ( ind , 1 ) ;
163
- }
164
- return found ;
165
- } ) ) ;
166
-
167
- // Check what we need to do
168
- if ( ! removals . length && ! temp . length ) { // There's nothing
169
- debug ( 'Finished' ) ;
170
- deck = [ ] ;
171
- } else if ( removals . length > 13 ) { // Too much to do (Cards in deck + 1)
172
- pending . push ( {
173
- action : 'clear' ,
174
- } ) ;
175
- } else {
176
- pending . push ( ...removals ) ;
177
- deck = temp ;
178
- }
179
- }
180
- pending . push ( ...deck ) ;
181
- if ( ! matchingArtifacts ( i ) ) {
182
- debug ( 'Loading Artifacts' ) ;
183
- pending . push ( {
184
- action : 'clearArtifacts' ,
185
- } ) ;
186
- getArtifacts ( i ) . forEach ( ( id ) => {
187
- pending . push ( {
188
- id,
189
- action : 'addArtifact' ,
190
- } ) ;
191
- } ) ;
192
- }
193
- processNext ( ) ;
194
- }
195
-
196
-
197
- function matchingArtifacts ( id ) {
198
- const dArts = getArtifacts ( id ) ;
199
- const cArts = global ( 'decksArtifacts' ) [ global ( 'soul' ) ] ;
200
- return ! dArts . length || dArts . length === cArts . length && cArts . every ( ( { id : id1 } ) => ! ! ~ dArts . indexOf ( id1 ) ) ;
91
+ fn . deckLoader . load ( {
92
+ cards : getDeck ( i , true ) ,
93
+ artifacts : getArtifacts ( i ) ,
94
+ } ) ;
201
95
}
202
96
203
97
function getKey ( id ) {
@@ -210,7 +104,10 @@ onPage('Decks', function deckStorage() {
210
104
const deck = JSON . parse ( localStorage . getItem ( key ) ) ;
211
105
if ( ! deck ) return null ;
212
106
if ( trim ) {
213
- return deck . cards . filter ( ( { id, shiny } ) => getCardData ( id , shiny ) !== null ) ;
107
+ return deck . cards . filter ( ( { id, shiny } ) => {
108
+ const data = getCardData ( id , shiny ) ;
109
+ return data && data . name ;
110
+ } ) ;
214
111
}
215
112
return deck . cards ;
216
113
}
@@ -360,8 +257,8 @@ onPage('Decks', function deckStorage() {
360
257
eventManager . on ( 'Deck:Loaded' , ( ) => {
361
258
loadStorage ( ) ;
362
259
} ) ;
363
- clearDeck . on ( 'click' , ( ) => {
364
- pending = [ ] ;
260
+ $ ( '#yourCardList > button[onclick="removeAllCards();"]' ) . on ( 'click' , ( ) => {
261
+ fn . deckLoader . clear ( ) ;
365
262
} ) ;
366
263
} ) ;
367
264
} ) ;
0 commit comments