Skip to content

Commit 1d84f93

Browse files
committed
Teambuilder: Provide Smogon Dex resources when building teams
1 parent 0662f38 commit 1d84f93

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

play.pokemonshowdown.com/js/client-teambuilder.js

+32
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,13 @@
139139
curSearchVal: '',
140140

141141
exportMode: false,
142+
formatResources: {},
142143
update: function () {
143144
teams = Storage.teams;
144145
if (this.curTeam) {
146+
if (this.curTeam.format && !this.formatResources[this.curTeam.format]) {
147+
this.tryLoadFormatResource(this.curTeam.format);
148+
}
145149
if (this.curTeam.loaded === false || (this.curTeam.teamid && !this.curTeam.loaded)) {
146150
this.loadTeam();
147151
return this.updateTeamView();
@@ -175,6 +179,18 @@
175179
});
176180
},
177181

182+
tryLoadFormatResource: function (format) {
183+
var teambuilder = this;
184+
if (teambuilder.formatResources[format] === true) { // already loading, bypass
185+
return;
186+
}
187+
teambuilder.formatResources[format] = true; // true - loading, array - loaded
188+
$.get('https://www.smogon.com/dex/api/formats/by-ps-name/' + format, {}, function (data) {
189+
teambuilder.formatResources[format] = data;
190+
teambuilder.update();
191+
});
192+
},
193+
178194
/*********************************************************
179195
* Team list view
180196
*********************************************************/
@@ -1223,6 +1239,22 @@
12231239
if (i < this.curTeam.capacity) {
12241240
buf += '<li><button name="addPokemon" class="button big"><i class="fa fa-plus"></i> Add Pok&eacute;mon</button></li>';
12251241
}
1242+
buf += '<br />';
1243+
var formatInfo = this.formatResources[this.curTeam.format];
1244+
// data's there and loaded
1245+
if (formatInfo && formatInfo !== true) {
1246+
if (formatInfo.resources.length || formatInfo.url) {
1247+
buf += '<strong>Teambuilding resources for this tier:</strong><br />';
1248+
for (var i = 0; i < formatInfo.resources.length; i++) {
1249+
var resource = formatInfo.resources[i];
1250+
// these are not <li> because that adds too much padding around each entry, making the whole thing
1251+
// take up too much space
1252+
buf += '<small style="padding: 1">- <a href="' + resource.url + '">' + resource.resource_name + '</a></small><br />';
1253+
}
1254+
}
1255+
buf += '<small>Find more helpful resources for this tier on <a href="' + formatInfo.url + '">the Smogon Dex</a>.';
1256+
buf += '<br />';
1257+
}
12261258
buf += '</ol>';
12271259
buf += '<form id="pokepasteForm" style="display:inline" method="post" action="https://pokepast.es/create" target="_blank">';
12281260
buf += '<input type="hidden" name="title" id="pasteTitle">';

0 commit comments

Comments
 (0)