Skip to content

Commit

Permalink
Tera Preview Checkbox Client-Side
Browse files Browse the repository at this point in the history
Adds a checkbox to toggle tera preview in select formats
  • Loading branch information
Nonexistent-0 committed Aug 8, 2024
1 parent 3410986 commit afac21d
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 Down Expand Up @@ -1418,13 +1419,15 @@ function toId() {
challengeShow: challengeShow,
tournamentShow: tournamentShow,
bestOfDefault: bestOfDefault,
teraPreviewDefault: teraPreviewDefault,
rated: searchShow && id.substr(4, 7) !== 'unrated',
teambuilderLevel: teambuilderLevel,
partner: partner,
teambuilderFormat: teambuilderFormat,
isTeambuilderFormat: isTeambuilderFormat,
effectType: 'Format'
};
console.log(teraPreviewDefault ? true : false);
}
}

Expand Down

0 comments on commit afac21d

Please sign in to comment.