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

Client-Side Tera Type Preview Checkbox #2275

Merged
merged 6 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
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
22 changes: 22 additions & 0 deletions play.pokemonshowdown.com/js/client-mainmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,9 @@
var bestOfDefault = format && BattleFormats[format] ? BattleFormats[format].bestOfDefault : false;
buf += '<p' + (!bestOfDefault ? ' class="hidden">' : '>');
buf += '<label class="checkbox"><input type="checkbox" name="bestof" /> <abbr title="Start a team-locked best-of-n series">Best-of-<input name="bestofvalue" type="number" min="3" max="9" step="2" value="3" style="width: 28px; vertical-align: initial;"></abbr></label></p>';
var teraPreviewDefault = format && BattleFormats[format] ? BattleFormats[format].teraPreviewDefault : false;
buf += '<p' + (!teraPreviewDefault ? ' class="hidden">' : '>');
buf += '<label class="checkbox"><input type="checkbox" name="terapreview" /> <abbr title="Start a battle with Tera Type Preview">Tera Type Preview</abbr></label></p>';
buf += '<p class="buttonbar"><button name="makeChallenge" class="button"><strong>Challenge</strong></button> <button type="button" name="dismissChallenge" class="button">Cancel</button></p></form>';
$challenge.html(buf);
},
Expand Down Expand Up @@ -955,6 +958,13 @@
format += 'Best of = ' + bestOfValue;
}

var teraPreview = $pmWindow.find('input[name=terapreview]').is(':checked');
if (teraPreview) {
var hasCustomRulesT = format.includes('@@@');
format += hasCustomRulesT ? ', ' : '@@@';
format += 'Tera Type Preview';
}

var team = null;
if (Storage.teams[teamIndex]) team = Storage.teams[teamIndex];

Expand Down Expand Up @@ -1404,6 +1414,18 @@
}
}

var $teraPreviewCheckbox = this.sourceEl.closest('form').find('input[name=terapreview]');
if ($teraPreviewCheckbox) {
var $parentTag = $teraPreviewCheckbox.parent().parent();
var teraPreviewDefault = BattleFormats[format] && BattleFormats[format].teraPreviewDefault;
if (teraPreviewDefault) {
$parentTag.removeClass('hidden');
} else {
$parentTag.addClass('hidden');
$teraPreviewCheckbox.prop('checked', false);
}
}

var $partnerLabels = $('label[name=partner]');
$partnerLabels.each(function (i, label) {
label.style.display = BattleFormats[format].partner ? '' : 'none';
Expand Down
3 changes: 3 additions & 0 deletions play.pokemonshowdown.com/js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,7 @@ function toId() {
var tournamentShow = true;
var partner = false;
var bestOfDefault = false;
var teraPreviewDefault = false;
var team = null;
var teambuilderLevel = null;
var lastCommaIndex = name.lastIndexOf(',');
Expand All @@ -1354,6 +1355,7 @@ function toId() {
if (code & 16) teambuilderLevel = 50;
if (code & 32) partner = true;
if (code & 64) bestOfDefault = true;
if (code & 128) teraPreviewDefault = true;
} else {
// Backwards compatibility: late 0.9.0 -> 0.10.0
if (name.substr(name.length - 2) === ',#') { // preset teams
Expand Down Expand Up @@ -1418,6 +1420,7 @@ function toId() {
challengeShow: challengeShow,
tournamentShow: tournamentShow,
bestOfDefault: bestOfDefault,
teraPreviewDefault: teraPreviewDefault,
rated: searchShow && id.substr(4, 7) !== 'unrated',
teambuilderLevel: teambuilderLevel,
partner: partner,
Expand Down