From 4d172e432707ee4ff495bdf8d0df4a9858a65510 Mon Sep 17 00:00:00 2001 From: Nonexistent-0 <154090245+Nonexistent-0@users.noreply.github.com> Date: Mon, 19 Aug 2024 11:24:55 -0400 Subject: [PATCH] Client-Side Tera Type Preview Checkbox (#2275) Didn't test this change at all, but it's needed and nobody is reviewing it in a timely manner. --- .../js/client-mainmenu.js | 22 +++++++++++++++++++ play.pokemonshowdown.com/js/client.js | 3 +++ 2 files changed, 25 insertions(+) diff --git a/play.pokemonshowdown.com/js/client-mainmenu.js b/play.pokemonshowdown.com/js/client-mainmenu.js index 9655498a9d..08d9d05809 100644 --- a/play.pokemonshowdown.com/js/client-mainmenu.js +++ b/play.pokemonshowdown.com/js/client-mainmenu.js @@ -903,6 +903,9 @@ var bestOfDefault = format && BattleFormats[format] ? BattleFormats[format].bestOfDefault : false; buf += '
' : '>'); buf += '
'; + var teraPreviewDefault = format && BattleFormats[format] ? BattleFormats[format].teraPreviewDefault : false; + buf += '' : '>'); + buf += '
'; buf += ' '; $challenge.html(buf); }, @@ -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]; @@ -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'; diff --git a/play.pokemonshowdown.com/js/client.js b/play.pokemonshowdown.com/js/client.js index 7b1ea5a67b..abd53ebf71 100644 --- a/play.pokemonshowdown.com/js/client.js +++ b/play.pokemonshowdown.com/js/client.js @@ -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(','); @@ -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 @@ -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,