Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use most recent format as default format #2319

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions play.pokemonshowdown.com/js/client-mainmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@
if (!this.searching || $.isArray(this.searching) && !this.searching.length) {
var format = $formatButton.val();
var teamIndex = $teamButton.val();

$formatButton.replaceWith(this.renderFormats(format));
$teamButton.replaceWith(this.renderTeams(format, teamIndex));

Expand Down Expand Up @@ -1026,14 +1027,19 @@
return '<button class="select formatselect" name="format" disabled><em>No formats available</em></button>';
}
if (!noChoice) {
this.curFormat = formatid;
if (!this.curFormat) {
if (BattleFormats['gen9randombattle']) {
this.curFormat = 'gen9randombattle';
} else for (var i in BattleFormats) {
if (!BattleFormats[i].searchShow || !BattleFormats[i].challengeShow) continue;
this.curFormat = i;
break;
var defaultFormat = Storage.prefs('defaultformat');
if (BattleFormats[defaultFormat]) {
this.curFormat = defaultFormat;
} else {
this.curFormat = formatid;
if (!this.curFormat) {
if (BattleFormats['gen9randombattle']) {
this.curFormat = 'gen9randombattle';
} else for (var i in BattleFormats) {
if (!BattleFormats[i].searchShow || !BattleFormats[i].challengeShow) continue;
this.curFormat = i;
break;
}
}
}
formatid = this.curFormat;
Expand Down Expand Up @@ -1066,7 +1072,12 @@
if (!teams.length) {
return '<button class="select teamselect" name="team" disabled>You have no teams</button>';
}
if (teamIndex === undefined) teamIndex = -1;
if (teamIndex === undefined || teamIndex === '' || teamIndex === -1) {
// if format is selected from default on reload, teamIndex gets set to -1 or ''
// handle both cases so we find the first team in that format
teamIndex = -1;
this.curTeamIndex = -1;
}
if (teamIndex < 0) {
if (this.curTeamIndex >= 0) {
teamIndex = this.curTeamIndex;
Expand Down Expand Up @@ -1432,6 +1443,7 @@
});
}
this.sourceEl.val(format).html(BattleLog.escapeFormat(format) || '(Select a format)');
Storage.prefs('defaultformat', format);

this.close();
}
Expand Down
Loading