@@ -70,27 +70,28 @@ async function buildBanlistsView() {
70
70
71
71
// Load data from API
72
72
const desiredFormats = [' startup' , ' standard' , ' eternal' ];
73
- const formats = await Promise .all (desiredFormats . map ( f => fetch ( ` {{ v3_api_url }}/api/v3/public/formats/ ${ f } ` ). then ( data => data . json ()). then ( json => json . data )));
74
- const cards = await fetchCards ( ` ?include=card_subtypes&filter[search]=in_restriction:true ` , 250 ).then (cards => splitBySide (cards));
75
- const restrictions = await Promise . all ( formats . map ( f =>
76
- fetchData (` {{ v3_api_url }}/api/v3/public/formats/ ${ f . id } / restrictions?sort=-date_start` )
77
- ) );
73
+ const [ formats , cards , restrictions ] = await Promise .all ([
74
+ fetchData ( ` {{ v3_api_url }}/api/v3/public/formats ` ).then (fs => fs . filter ( f => desiredFormats . includes ( f . id ))),
75
+ fetchCards ( ` ?include=card_subtypes&filter[search]=in_restriction:true ` , 250 ). then (splitBySide),
76
+ fetchData (` {{ v3_api_url }}/api/v3/public/restrictions?sort=-date_start` )
77
+ ] );
78
78
79
79
// Remove the loading indicator
80
80
$ (' .temp-loading' ).remove ();
81
81
82
82
// Add each format to the page
83
83
// Start by adding an empty text box for each restriction
84
- for ( const [ i , f ] of formats .entries ()) {
84
+ formats .forEach ( f => {
85
85
$ (` #tab-pane-${ f .id } ` ).append (` <div class="list"><div class="row"><div id="${ f .id } " class="col-sm-12"></div></div></div>` );
86
86
const jqCol = $ (` #${ f .id } ` );
87
- if (restrictions[i].length == 0 ) {
87
+ const formatRestrictions = restrictions .filter (r => f .attributes .restriction_ids .includes (r .id ));
88
+ if (formatRestrictions .length == 0 ) {
88
89
jqCol .append (` <p>No cards are currently banned in ${ f .attributes .name } . Have a blast!</p>` );
89
90
} else {
90
91
jqCol .append (' <p><button class="show-all btn btn-secondary">Show all</button><button class="hide-all pull-right btn btn-secondary">Hide all</button></p>' );
91
- for ( const r of restrictions[i]) {
92
+ formatRestrictions . forEach ( r => {
92
93
const active = r .id == f .attributes .active_restriction_id ;
93
- const visible = active || r .id == restrictions[i] [0 ].id ;
94
+ const visible = active || r .id == formatRestrictions [0 ].id ;
94
95
// Create panel
95
96
jqCol .append (` <div id="restriction-${ r .id } " class="panel panel-default"></div>` );
96
97
const jqPanel = $ (` #restriction-${ r .id } ` );
@@ -100,9 +101,9 @@ async function buildBanlistsView() {
100
101
.append (` <button class="list-toggle btn btn-secondary" style="margin-left:auto; margin-top: auto; margin-bottom: auto;">${ visible ? ' Hide' : ' Show' } </button>` );
101
102
// Add subheader (search link hyphenated for legacy IDs)
102
103
jqPanel .append (` <div class="panel-heading" ${ visible ? ' ' : ' style="display: none;"' } ><a href=${ Routing .generate (' cards_find' , {type: ' find' , ' view' : ' list' , ' q' : ` b!${ r .id .replaceAll (' _' , ' -' )} ` })} >${ r .attributes .size } cards</a>. Start Date: ${ r .attributes .date_start } .</div>` );
103
- }
104
+ });
104
105
}
105
- }
106
+ });
106
107
107
108
// Set up event handling
108
109
$ (' .list-toggle' ).on (' click' , function (event ) {
@@ -126,62 +127,60 @@ async function buildBanlistsView() {
126
127
});
127
128
128
129
// Add the restriction data to each text box
129
- for (const format of restrictions) {
130
- for (const r of format) {
131
- const v = r .attributes .verdicts ;
132
-
133
- // Lists (bans, restricted cards, global penalty cards)
134
- const [corpBan , runnerBan ] = cards .map (cs => cs .filter (card => v .banned ? .includes (card .id )));
135
- const [corpRes , runnerRes ] = cards .map (cs => cs .filter (card => v .restricted ? .includes (card .id )));
136
- const [corpPen , runnerPen ] = cards .map (cs => cs .filter (card => v .global_penalty ? .includes (card .id )));
137
-
138
- // Mappings (points, universal faction costs)
139
- const [corpUFC , runnerUFC ] = cards .map (cs => makeCardMap (cs, v .universal_faction_cost ));
140
- const [corpPts , runnerPts ] = cards .map (cs => makeCardMap (cs, v .points ));
141
-
142
- // Get the panel DOM object
143
- const jqPanel = $ (` #restriction-${ r .id } ` );
144
-
145
- // Add body
146
- jqPanel .append (` <div class="panel-body" ${ jqPanel .find (` button` ).html () == ' Show' ? ' style="display: none;"' : ' ' } ><div class="container-fluid"><div class="row flex-fill">` );
147
-
148
- // Generate corp restrictions
149
- jqPanel .find (` .row` ).append (` <div class="col-md-6"><h3>Corp Cards</h3><ul id="${ r .id } -corp"></ul></div>` );
150
- const jqCorp = $ (` #${ r .id } -corp` );
151
- // Bans (banned subtypes (i.e. currents) are removed beforehand to reduce length)
152
- if (corpBan .length > 0 ) {
153
- if (r .attributes .banned_subtypes .length > 0 ) { // NOTE: currently hardcoded to only be currents
154
- const pre = ` All cards with the <strong><a href="${ Routing .generate (' cards_find' , {type: ' find' , ' view' : ' list' , ' q' : ' s:current d:corp' })} ">Current</a></strong> subtype.` ;
155
- jqCorp .append (generateList (' Banned' , removeCurrents (corpBan), pre));
156
- } else {
157
- jqCorp .append (generateList (' Banned' , corpBan));
158
- }
130
+ restrictions .forEach (r => {
131
+ const v = r .attributes .verdicts ;
132
+
133
+ // Lists (bans, restricted cards, global penalty cards)
134
+ const [corpBan , runnerBan ] = cards .map (cs => cs .filter (card => v .banned ? .includes (card .id )));
135
+ const [corpRes , runnerRes ] = cards .map (cs => cs .filter (card => v .restricted ? .includes (card .id )));
136
+ const [corpPen , runnerPen ] = cards .map (cs => cs .filter (card => v .global_penalty ? .includes (card .id )));
137
+
138
+ // Mappings (points, universal faction costs)
139
+ const [corpUFC , runnerUFC ] = cards .map (cs => makeCardMap (cs, v .universal_faction_cost ));
140
+ const [corpPts , runnerPts ] = cards .map (cs => makeCardMap (cs, v .points ));
141
+
142
+ // Get the panel DOM object
143
+ const jqPanel = $ (` #restriction-${ r .id } ` );
144
+
145
+ // Add body
146
+ jqPanel .append (` <div class="panel-body" ${ jqPanel .find (` button` ).html () == ' Show' ? ' style="display: none;"' : ' ' } ><div class="container-fluid"><div class="row flex-fill">` );
147
+
148
+ // Generate corp restrictions
149
+ jqPanel .find (` .row` ).append (` <div class="col-md-6"><h3>Corp Cards</h3><ul id="${ r .id } -corp"></ul></div>` );
150
+ const jqCorp = $ (` #${ r .id } -corp` );
151
+ // Bans (banned subtypes (i.e. currents) are removed beforehand to reduce length)
152
+ if (corpBan .length > 0 ) {
153
+ if (r .attributes .banned_subtypes .length > 0 ) { // NOTE: currently hardcoded to only be currents
154
+ const pre = ` All cards with the <strong><a href="${ Routing .generate (' cards_find' , {type: ' find' , ' view' : ' list' , ' q' : ' s:current d:corp' })} ">Current</a></strong> subtype.` ;
155
+ jqCorp .append (generateList (' Banned' , removeCurrents (corpBan), pre));
156
+ } else {
157
+ jqCorp .append (generateList (' Banned' , corpBan));
159
158
}
160
- // The others
161
- if ( corpRes . length > 0 ) { jqCorp . append ( generateList ( ' Restricted ' , corpRes)); }
162
- Object . keys (corpUFC). sort (). reverse (). forEach ( p => { jqCorp .append (generateList (` + ${ p } Universal Influence ` , corpUFC[p] )); });
163
- if ( corpPen . length > 0 ) { jqCorp .append (generateList (' Identity Influence Reduction ' , corpPen )); }
164
- Object . keys (corpPts). sort (). reverse (). forEach ( p => { jqCorp .append (generateList (` ${ p } ${ p == 1 ? ' Point ' : ' Points ' } ` , corpPts[p] )); });
165
-
166
- // Generate runner restrictions
167
- jqPanel . find ( ' .row ' ). append ( ` <div class="col-md-6"><h3>Runner Cards</h3><ul id=" ${ r . id } - runner"></ul></div> ` );
168
- const jqRunner = $ ( ` # $ {r .id } -runner` );
169
- // Bans (banned subtypes (i.e. currents) are removed beforehand to reduce length)
170
- if ( runnerBan . length > 0 ) {
171
- if (r . attributes . banned_subtypes . length > 0 ) { // NOTE: currently hardcoded to only be currents
172
- const pre = ` All cards with the <strong><a href=" ${ Routing . generate ( ' cards_find ' , {type : ' find ' , ' view ' : ' list ' , ' q ' : ' s:current d:runner ' }) } ">Current</a></strong> subtype. ` ;
173
- jqRunner . append ( generateList ( ' Banned ' , removeCurrents (runnerBan), pre)) ;
174
- } else {
175
- jqRunner . append ( generateList ( ' Banned ' , runnerBan));
176
- }
159
+ }
160
+ // The others
161
+ if ( corpRes . length > 0 ) { jqCorp .append (generateList (' Restricted ' , corpRes )); }
162
+ Object . keys (corpUFC). sort (). reverse (). forEach ( p => { jqCorp .append (generateList (` + ${ p } Universal Influence ` , corpUFC[p] )); });
163
+ if ( corpPen . length > 0 ) { jqCorp .append (generateList (' Identity Influence Reduction ' , corpPen )); }
164
+ Object . keys (corpPts). sort (). reverse (). forEach ( p => { jqCorp . append ( generateList ( ` ${ p } ${ p == 1 ? ' Point ' : ' Points ' } ` , corpPts[p])); });
165
+
166
+ // Generate runner restrictions
167
+ jqPanel . find ( ' .row ' ). append ( ` <div class="col-md-6"><h3>Runner Cards</h3><ul id=" $ {r .id } -runner"></ul></div> ` );
168
+ const jqRunner = $ ( ` # ${ r . id } -runner ` );
169
+ // Bans (banned subtypes (i.e. currents) are removed beforehand to reduce length)
170
+ if (runnerBan . length > 0 ) {
171
+ if ( r . attributes . banned_subtypes . length > 0 ) { // NOTE: currently hardcoded to only be currents
172
+ const pre = ` All cards with the <strong><a href=" ${ Routing . generate ( ' cards_find ' , {type : ' find ' , ' view ' : ' list ' , ' q ' : ' s:current d:runner ' }) } ">Current</a></strong> subtype. ` ;
173
+ jqRunner . append ( generateList ( ' Banned ' , removeCurrents (runnerBan), pre));
174
+ } else {
175
+ jqRunner . append ( generateList ( ' Banned ' , runnerBan));
177
176
}
178
- // The others
179
- if (runnerRes .length > 0 ) { jqRunner .append (generateList (' Restricted' , runnerRes)); }
180
- Object .keys (runnerUFC).sort ().reverse ().forEach (p => { jqRunner .append (generateList (` +${ p} Universal Influence` , runnerUFC[p])); });
181
- if (runnerPen .length > 0 ) { jqRunner .append (generateList (' Identity Influence Reduction' , runnerPen)); }
182
- Object .keys (runnerPts).sort ().reverse ().forEach (p => { jqRunner .append (generateList (` ${ p} ${ p == 1 ? ' Point' : ' Points' } ` , runnerPts[p])); });
183
177
}
184
- }
178
+ // The others
179
+ if (runnerRes .length > 0 ) { jqRunner .append (generateList (' Restricted' , runnerRes)); }
180
+ Object .keys (runnerUFC).sort ().reverse ().forEach (p => { jqRunner .append (generateList (` +${ p} Universal Influence` , runnerUFC[p])); });
181
+ if (runnerPen .length > 0 ) { jqRunner .append (generateList (' Identity Influence Reduction' , runnerPen)); }
182
+ Object .keys (runnerPts).sort ().reverse ().forEach (p => { jqRunner .append (generateList (` ${ p} ${ p == 1 ? ' Point' : ' Points' } ` , runnerPts[p])); });
183
+ });
185
184
}
186
185
187
186
// Create the banlists view on load
0 commit comments