Skip to content

Commit

Permalink
Merge pull request scoopapa#10 from Rezzo64/main
Browse files Browse the repository at this point in the history
October 14 2023: Merge with PS
  • Loading branch information
scoopapa authored Oct 14, 2023
2 parents cbf03f1 + d95892e commit 7e9e71f
Show file tree
Hide file tree
Showing 11 changed files with 290 additions and 32 deletions.
10 changes: 9 additions & 1 deletion js/client-battle.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
if (this.battle) this.battle.destroy();
},
requestLeave: function (e) {
if (this.side && this.battle && !this.battleEnded && !this.expired && !this.battle.forfeitPending) {
if ((this.side || this.requireForfeit) && this.battle && !this.battleEnded && !this.expired && !this.battle.forfeitPending) {
app.addPopup(ForfeitPopup, {room: this, sourceEl: e && e.currentTarget, gameType: 'battle'});
return false;
}
Expand Down Expand Up @@ -138,6 +138,14 @@
if (data.substr(0, 6) === '|init|') {
return this.init(data);
}
if (data.substr(0, 11) === '|cantleave|') {
this.requireForfeit = true;
return;
}
if (data.substr(0, 12) === '|allowleave|') {
this.requireForfeit = false;
return;
}
if (data.substr(0, 9) === '|request|') {
data = data.slice(9);

Expand Down
17 changes: 10 additions & 7 deletions js/client-chat-tournament.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,22 @@
self.room.send('/tournament leave');
});
this.$challengeChallenge.on('click', function () {
app.sendTeam(Storage.teams[self.$teamSelect.children().val()]);
self.room.send('/tournament challenge ' + self.$challengeUserMenu.children().val());
app.sendTeam(Storage.teams[self.$teamSelect.children().val()], function () {
self.room.send('/tournament challenge ' + self.$challengeUserMenu.children().val());
});
});
this.$challengeAccept.on('click', function () {
app.sendTeam(Storage.teams[self.$teamSelect.children().val()]);
self.room.send('/tournament acceptchallenge');
app.sendTeam(Storage.teams[self.$teamSelect.children().val()], function () {
self.room.send('/tournament acceptchallenge');
});
});
this.$challengeCancel.on('click', function () {
self.room.send('/tournament cancelchallenge');
});
this.$validate.on('click', function () {
app.sendTeam(Storage.teams[self.$teamSelect.children().val()]);
self.room.send('/tournament vtm');
app.sendTeam(Storage.teams[self.$teamSelect.children().val()], function () {
self.room.send('/tournament vtm');
});
});

app.user.on('saveteams', this.updateTeams, this);
Expand Down Expand Up @@ -477,7 +480,7 @@
break;

case 'end':
var endData = JSON.parse(data[0]);
var endData = JSON.parse(data.join('|'));

var $bracket = this.generateBracket(endData.bracketData);
if ($bracket) {
Expand Down
47 changes: 38 additions & 9 deletions js/client-mainmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,8 @@
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>';
buf += '<p class="buttonbar"><button name="makeChallenge"><strong>Challenge</strong></button> <button type="button" name="dismissChallenge">Cancel</button></p></form>';
$challenge.html(buf);
},
Expand All @@ -916,10 +918,14 @@
app.addPopupMessage("You need to go into the Teambuilder and build a team for this format.");
return;
}
app.sendTeam(team);
app.sendTeam(team, function () {
target.disabled = true;
app.send(privacy + '/accept ' + userid);
});
} else {
target.disabled = true;
app.send(privacy + '/accept ' + userid);
}
target.disabled = true;
app.send(privacy + '/accept ' + userid);
},
rejectChallenge: function (i, target) {
var userid = $(target).closest('.pm-window').data('userid');
Expand All @@ -935,6 +941,14 @@
var format = $pmWindow.find('button[name=format]').val();
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) {
format += hasCustomRules ? ', ' : '@@@';
format += 'Best of = 3';
}

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

Expand All @@ -949,8 +963,9 @@
buf += '<p class="buttonbar"><button name="cancelChallenge">Cancel</button></p></form>';

$(target).closest('.challenge').html(buf);
app.sendTeam(team);
app.send(privacy + '/challenge ' + userid + ', ' + format);
app.sendTeam(team, function () {
app.send(privacy + '/challenge ' + userid + ', ' + format);
});
},
cancelChallenge: function (i, target) {
var userid = $(target).closest('.pm-window').data('userid');
Expand Down Expand Up @@ -1090,11 +1105,12 @@
$searchForm.find('button.big').html('<strong><i class="fa fa-refresh fa-spin"></i> Connecting...</strong>').addClass('disabled');
$searchForm.append('<p class="cancel buttonbar"><button name="cancelSearch">Cancel</button></p>');

app.sendTeam(team);
var self = this;
this.searchDelay = setTimeout(function () {
app.send(self.adjustPrivacy($privacyCheckbox.is(':checked')) + '/search ' + format);
}, 3000);
app.sendTeam(team, function () {
self.searchDelay = setTimeout(function () {
app.send(self.adjustPrivacy($privacyCheckbox.is(':checked')) + '/search ' + format);
}, 3000);
});
},
cancelSearch: function () {
clearTimeout(this.searchDelay);
Expand Down Expand Up @@ -1272,6 +1288,18 @@
app.rooms[''].curTeamIndex = -1;
var $teamButton = this.sourceEl.closest('form').find('button[name=team]');
if ($teamButton.length) $teamButton.replaceWith(app.rooms[''].renderTeams(format));

var $bestOfCheckbox = this.sourceEl.closest('form').find('input[name=bestof]');
if ($bestOfCheckbox) {
var $parentTag = $bestOfCheckbox.parent().parent();
if (format.includes('vgc')) {
$parentTag.removeClass('hidden');
} else {
$parentTag.addClass('hidden');
$bestOfCheckbox.prop('checked', false);
}
}

var $partnerLabels = $('label[name=partner]');
$partnerLabels.each(function (i, label) {
label.style.display = BattleFormats[format].partner ? '' : 'none';
Expand Down Expand Up @@ -1379,6 +1407,7 @@
count++;
if (count % bufBoundary === 0 && count != 0 && curBuf < 4) curBuf++;
}
console.log(teamFormat);
if (!isNoFolder) {
for (var i = 0; i < teams.length; i++) {
if ((!teams[i].format && !teamFormat) || teams[i].format === teamFormat) {
Expand Down
81 changes: 76 additions & 5 deletions js/client-teambuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
Storage.whenTeamsLoaded(this.update, this);
}
this.update();
if (typeof Storage.prefs('uploadprivacy') !== 'undefined') {
this.$('input[name=teamprivacy]').is('checked', Storage.prefs('uploadprivacy'));
}
},
focus: function () {
if (this.curTeam) {
Expand Down Expand Up @@ -45,6 +48,9 @@
'click button.formatselect': 'selectFormat',
'change input[name=nickname]': 'nicknameChange',

// misc
'click input[name=teamprivacy]': 'privacyChange',

// details
'change .detailsform input': 'detailsChange',
'change .detailsform select': 'detailsChange',
Expand Down Expand Up @@ -141,6 +147,11 @@
teams = Storage.teams;
if (this.curTeam) {
// console.log(JSON.stringify(this.curTeam, null, 4))

if (this.curTeam.loaded === false || (this.curTeam.teamid && !this.curTeam.loaded)) {
this.loadTeam();
return this.updateTeamView();
}
this.ignoreEVLimits = (this.curTeam.gen < 3 ||
((this.curTeam.format.includes('hackmons') || this.curTeam.format.endsWith('bh')) && this.curTeam.gen !== 6) ||
this.curTeam.format.includes('metronomebattle') || (this.curTeam.mod && ModConfig[this.curTeam.mod].ignoreEVLimits));
Expand All @@ -154,6 +165,24 @@
return this.updateTeamInterface();
},

privacyChange: function (ev) {
Storage.prefs('uploadprivacy', ev.currentTarget.checked);
},

loadTeam: function () {
if (this.loadingTeam) return false;
this.loadingTeam = true;
var teambuilder = this;
app.loadTeam(this.curTeam, function (team) {
window.builderTeam = team;
teambuilder.loadingTeam = false;
teambuilder.curSetList = Storage.unpackTeam(team.team);
Storage.activeSetList = teambuilder.curSetList;
teambuilder.curTeam.team = Storage.packTeam(teambuilder.curSetList);
teambuilder.updateTeamView();
});
},

/*********************************************************
* Team list view
*********************************************************/
Expand Down Expand Up @@ -467,17 +496,21 @@
}
}

buf += '</ul>';
buf += '</ul><p>';
if (atLeastOne) {
buf += '<p><button name="new" value="team" class="button"><i class="fa fa-plus-circle"></i> ' + newTeamButtonText + '</button> <button name="new" value="box" class="button"><i class="fa fa-archive"></i> New Box</button></p>';
buf += '<button name="new" value="team" class="button"><i class="fa fa-plus-circle"></i> ' + newTeamButtonText + '</button> <button name="new" value="box" class="button"><i class="fa fa-archive"></i> New Box</button> ';
}
buf += '<button class="button" name="send" value="/teams">View teams uploaded to server</button>';
buf += '</p>';

if (window.nodewebkit) {
buf += '<button name="revealFolder" class="button"><i class="fa fa-folder-open"></i> Reveal teams folder</button> <button name="reloadTeamsFolder" class="button"><i class="fa fa-refresh"></i> Reload teams files</button> <button name="backup" class="button"><i class="fa fa-upload"></i> Backup/Restore all teams</button>';
} else if (this.curFolder) {
buf += '<button name="backup" class="button"><i class="fa fa-upload"></i> Backup all teams from this folder</button>';
} else if (atLeastOne) {
buf += '<p><strong>Clearing your cookies (specifically, <code>localStorage</code>) will delete your teams.</strong> <span class="storage-warning">Browsers sometimes randomly clear cookies - you should back up your teams or use the desktop client if you want to make sure you don\'t lose them.</span></p>';
buf += '<p><strong>Clearing your cookies (specifically, <code>localStorage</code>) will delete your teams.</strong> ';
buf += '<span class="storage-warning">Browsers sometimes randomly clear cookies - you should upload your teams to the Showdown database ';
buf += 'or make a backup yourself if you want to make sure you don\'t lose them.</span></p>';
buf += '<button name="backup" class="button"><i class="fa fa-upload"></i> Backup/Restore all teams</button>';
buf += '<p>If you want to clear your cookies or <code>localStorage</code>, you can use the Backup/Restore feature to save your teams as text first.</p>';
var self = this;
Expand Down Expand Up @@ -848,6 +881,24 @@
this.exportMode = true;
this.update();
},
psExport: function () {
var cmd = '/teams ';
cmd += this.curTeam.teamid ? 'update' : 'save';
// teamName, formatid, rawPrivacy, rawTeam
var buf = [];
if (this.curTeam.teamid) buf.push(this.curTeam.teamid);
buf.push(this.curTeam.name);
buf.push(this.curTeam.format);
buf.push(this.$('input[name=teamprivacy]').get(0).checked ? 1 : 0);
var team = Storage.exportTeam(this.curSetList, this.curTeam.gen, false);
if (!team) return app.addPopupMessage("Add a Pokémon to your team before uploading it!");
buf.push(team);
app.send(cmd + " " + buf.join(', '));
this.exported = true;
$('button[name=psExport]').addClass('disabled');
$('button[name=psExport]')[0].disabled = true;
$('label[name=editMessage]').hide();
},
pokepasteExport: function (type) {
var team = Storage.exportTeam(this.curSetList, this.curTeam.gen, type === 'openteamsheet');
if (!team) return app.addPopupMessage("Add a Pokémon to your team before uploading it!");
Expand Down Expand Up @@ -966,6 +1017,10 @@
if (edited) {
Storage.saveTeam(team);
app.user.trigger('saveteams');
this.exported = false;
$('button[name=psExport]').removeClass('disabled');
$('button[name=psExport]')[0].disabled = false;
$('label[name=editMessage]').show();
}

// We're going to try to animate the team settling into its new position
Expand Down Expand Up @@ -1150,6 +1205,9 @@
if (/^gen\d+$/.test(formatName)) return true;
return false;
};
if (this.loadingTeam) buf += '<div style="message-error">Downloading team from server...</strong><br />';
buf += '<label name="editMessage" style="display: none">';
buf += 'Remember to click the upload button below to sync your changes to the server!</label><br />';
if (exports.BattleFormats) {
buf += '<li class="format-select">';
buf += '<label class="label">Format:</label><button class="select formatselect teambuilderformatselect" name="format" value="' + this.curTeam.format + '">' + (isGenericFormat(this.curTeam.format) ? '<em>Select a format</em>' : BattleLog.escapeFormat(this.curTeam.format)) + '</button>';
Expand Down Expand Up @@ -1180,6 +1238,10 @@
buf += '<input type="hidden" name="paste" id="pasteData">';
buf += '<input type="hidden" name="author" id="pasteAuthor">';
buf += '<input type="hidden" name="notes" id="pasteNotes">';
buf += '<button name="psExport" type="submit" class="button exportbutton"> <i class="fa fa-upload"></i> Upload to Showdown database (saves across devices)</button>';
var privacy = (Storage.prefs('uploadprivacy') || typeof Storage.prefs('uploadprivacy') !== 'boolean') ? 'checked' : '';
buf += ' <small>(Private:</small> <input type="checkbox" name="teamprivacy" ' + privacy + ' /><small>)</small>';
buf += '<br />';
buf += '<button name="pokepasteExport" type="submit" class="button exportbutton"><i class="fa fa-upload"></i> Upload to PokePaste</button></form>';
if (this.curTeam.format.includes('vgc')) {
buf += '<button name="pokepasteExport" value="openteamsheet" type="submit" class="button exportbutton"><i class="fa fa-upload"></i> Upload to PokePaste (Open Team Sheet)</button></form>';
Expand Down Expand Up @@ -1473,6 +1535,9 @@
}
},
validate: function () {
if (this.curTeam.teamid && !this.curTeam.loaded) {
return app.loadTeam(this.curTeam, this.validate.bind(this));
}
var format = this.curTeam.format || 'gen7anythinggoes';

if (!this.curSetList.length) {
Expand All @@ -1483,8 +1548,9 @@
if (window.BattleFormats && BattleFormats[format] && BattleFormats[format].battleFormat) {
format = BattleFormats[format].battleFormat;
}
app.sendTeam(this.curTeam);
app.send('/vtm ' + format);
app.sendTeam(this.curTeam, function () {
app.send('/vtm ' + format);
});
},
teamNameChange: function (e) {
var name = ($.trim(e.currentTarget.value) || 'Untitled ' + (this.curTeamLoc + 1));
Expand All @@ -1496,6 +1562,11 @@
app.addPopupMessage("Names can't contain the character |, since they're used for storing teams.");
name = name.replace(/\|/g, '');
}
if (name.indexOf('[') >= 0 || name.indexOf(']') >= 0) {
app.addPopupMessage("Names can't contain the characters [ or ], since they're used for storing team IDs.");
name = name.replace(/\[/g, '');
name = name.replace(/\]/g, '');
}
this.curTeam.name = name;
e.currentTarget.value = name;
this.save();
Expand Down
Loading

0 comments on commit 7e9e71f

Please sign in to comment.