Skip to content

Commit

Permalink
Support more variable best-of challenges (#2173)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaWoblefet authored Nov 2, 2023
1 parent 5e638d4 commit 463948f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
21 changes: 13 additions & 8 deletions js/client-mainmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -896,8 +896,9 @@
buf += '<p><label class="label">Format:</label>' + this.renderFormats(format) + '</p>';
buf += '<p><label class="label">Team:</label>' + this.renderTeams(format) + '</p>';
buf += '<p><label class="checkbox"><input type="checkbox" name="private" ' + (Storage.prefs('disallowspectators') ? 'checked' : '') + ' /> <abbr title="You can still invite spectators by giving them the URL or using the /invite command">Don\'t allow spectators</abbr></label></p>';
buf += '<p' + (!(format && format.includes('vgc')) ? ' class="hidden">' : '>');
buf += '<label class="checkbox"><input type="checkbox" name="bestof" /> <abbr title="Start a team-locked best-of-3 series">Best-of-3</abbr></label></p>';
var bestOfDefault = 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>';
buf += '<p class="buttonbar"><button name="makeChallenge"><strong>Challenge</strong></button> <button type="button" name="dismissChallenge">Cancel</button></p></form>';
$challenge.html(buf);
},
Expand Down Expand Up @@ -942,11 +943,12 @@
var teamIndex = $pmWindow.find('button[name=team]').val();
var privacy = this.adjustPrivacy($pmWindow.find('input[name=private]').is(':checked'));

var bestof = $pmWindow.find('input[name=bestof]').is(':checked');
var hasCustomRules = format.includes('@@@');
if (bestof) {
var bestOf = $pmWindow.find('input[name=bestof]').is(':checked');
var bestOfValue = $pmWindow.find('input[name=bestofvalue]').val();
if (bestOf && bestOfValue) {
var hasCustomRules = format.includes('@@@');
format += hasCustomRules ? ', ' : '@@@';
format += 'Best of = 3';
format += 'Best of = ' + bestOfValue;
}

var team = null;
Expand Down Expand Up @@ -1381,10 +1383,13 @@
if ($teamButton.length) $teamButton.replaceWith(app.rooms[''].renderTeams(format));

var $bestOfCheckbox = this.sourceEl.closest('form').find('input[name=bestof]');
if ($bestOfCheckbox) {
var $bestOfValueInput = this.sourceEl.closest('form').find('input[name=bestofvalue]');
if ($bestOfCheckbox && $bestOfValueInput) {
var $parentTag = $bestOfCheckbox.parent().parent();
if (format.includes('vgc')) {
var bestOfDefault = BattleFormats[format].bestOfDefault;
if (bestOfDefault) {
$parentTag.removeClass('hidden');
$bestOfValueInput.val(3);
} else {
$parentTag.addClass('hidden');
$bestOfCheckbox.prop('checked', false);
Expand Down
3 changes: 3 additions & 0 deletions js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,7 @@ function toId() {
var challengeShow = true;
var tournamentShow = true;
var partner = false;
var bestOfDefault = false;
var team = null;
var teambuilderLevel = null;
var lastCommaIndex = name.lastIndexOf(',');
Expand All @@ -1340,6 +1341,7 @@ function toId() {
if (!(code & 8)) tournamentShow = false;
if (code & 16) teambuilderLevel = 50;
if (code & 32) partner = true;
if (code & 64) bestOfDefault = true;
} else {
// Backwards compatibility: late 0.9.0 -> 0.10.0
if (name.substr(name.length - 2) === ',#') { // preset teams
Expand Down Expand Up @@ -1403,6 +1405,7 @@ function toId() {
searchShow: searchShow,
challengeShow: challengeShow,
tournamentShow: tournamentShow,
bestOfDefault: bestOfDefault,
rated: searchShow && id.substr(4, 7) !== 'unrated',
teambuilderLevel: teambuilderLevel,
partner: partner,
Expand Down

0 comments on commit 463948f

Please sign in to comment.