Skip to content

Commit

Permalink
Client-Side Tera Type Preview Checkbox (#2275)
Browse files Browse the repository at this point in the history
Didn't test this change at all, but it's needed and nobody is reviewing it in a timely manner.
  • Loading branch information
Nonexistent-0 authored Aug 19, 2024
1 parent a9e4c3b commit 4d172e4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
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

0 comments on commit 4d172e4

Please sign in to comment.