Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ShivaD173 committed May 8, 2024
2 parents b065d17 + 3e518b3 commit 1da3e78
Show file tree
Hide file tree
Showing 7 changed files with 387 additions and 43 deletions.
11 changes: 9 additions & 2 deletions build-tools/build-indexes
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ process.stdout.write("Building `data/teambuilder-tables.js`... ");
const STADIUM = [2.04, 1.04];
const NATDEX = [9.1, 8.1];
const ADDED = [-4.81, -9.81, 9.21];
const OTHER = [9.9, 9.411, 9.41, 9.401, 9.4, 9.2, -9.4, -9.401, 8.6, 8.4, 8.2, 8.1, -8.4, -8.6, 7.1];
const OTHER = [9.9, 9.6, 9.411, 9.41, 9.401, 9.4, 9.2, -9.4, -9.401, 8.6, 8.4, 8.2, 8.1, -8.4, -8.6, 7.1];

// process.stdout.write("\n ");
for (const genIdent of [...GENS, ...DOUBLES, ...VGC, ...NFE, ...STADIUM, ...OTHER, ...ADDED, ...NATDEX, ...LC]) {
Expand All @@ -343,6 +343,7 @@ process.stdout.write("Building `data/teambuilder-tables.js`... ");
const isGay = (genIdent === -9.81);
const isMet = (genIdent === 9.21);
const isGen9BH = genIdent === 9.9;
const isSSB = genIdent === 9.6;
const genNum = Math.floor(isDoubles ? -genIdent : genIdent);
const gen = (() => {
let genStr = 'gen' + genNum;
Expand All @@ -355,6 +356,7 @@ process.stdout.write("Building `data/teambuilder-tables.js`... ");
if (isVGCPlat) genStr = 'gen4vgcplat';
if (isGay) genStr = 'gen9vgcgay';
if (isMet) genStr = 'gen9metronome';
if (isSSB) genStr += 'ssb';
return genStr;
})();
// process.stdout.write("" + gen + (isDoubles ? " doubles" : "") + "... ");
Expand Down Expand Up @@ -564,6 +566,11 @@ process.stdout.write("Building `data/teambuilder-tables.js`... ");
BattleTeambuilderTable['bh'].tiers = tiers;
BattleTeambuilderTable['bh'].overrideTier = overrideTier;
BattleTeambuilderTable['bh'].formatSlices = formatSlices;
} else if (isSSB) {
BattleTeambuilderTable['gen9ssb'] = {};
BattleTeambuilderTable['gen9ssb'].tiers = tiers;
BattleTeambuilderTable['gen9ssb'].overrideTier = overrideTier;
BattleTeambuilderTable['gen9ssb'].formatSlices = formatSlices;
} else if (gen === 'gen9') {
BattleTeambuilderTable.tiers = tiers;
BattleTeambuilderTable.items = items;
Expand Down Expand Up @@ -1196,7 +1203,7 @@ process.stdout.write("Building `data/teambuilder-tables.js`... ");
// Mods
//

for (const mod of ['gen7letsgo', 'gen8bdsp', 'gen4vgcplat', 'gen9vgcgay']) {
for (const mod of ['gen7letsgo', 'gen8bdsp', 'gen9ssb', 'gen4vgcplat', 'gen9vgcgay']) {
const modDex = Dex.mod(mod);
const modData = modDex.data;
const parentDex = Dex.forGen(modDex.gen);
Expand Down
13 changes: 8 additions & 5 deletions play.pokemonshowdown.com/js/client-mainmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
'click .spoiler': 'clickSpoiler',
'click button.formatselect': 'selectFormat',
'click button.teamselect': 'selectTeam',
'keyup input': 'selectTeammate'
'click button[name=partnersubmit]': 'selectTeammate'
},
initialize: function () {
this.$el.addClass('scrollable');
Expand All @@ -45,7 +45,8 @@
buf += '<p><label class="label">Format:</label>' + this.renderFormats() + '</p>';
buf += '<p><label class="label">Team:</label>' + this.renderTeams() + '</p>';
buf += '<p><label class="label" name="partner" style="display:none">';
buf += 'Partner: <input name="teammate" /></label></p>';
buf += 'Partner:<br />';
buf += '<input class="partnerselect" /><button name="partnersubmit">Invite</button></label></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><button class="button mainmenu1 big" name="search"><strong>Battle!</strong><br /><small>Find a random opponent</small></button></p></form></div>';
}
Expand Down Expand Up @@ -283,11 +284,13 @@
},

selectTeammate: function (e) {
if (e.currentTarget.name !== 'teammate' || e.keyCode !== 13) return;
var partner = toID(e.currentTarget.value);
e.stopPropagation();
e.preventDefault();
var input = $('input.partnerselect').get(0);
var partner = toID(input.value);
if (!partner.length) return;
app.send('/requestpartner ' + partner + ',' + this.curFormat);
e.currentTarget.value = '';
input.value = "";
},

openPM: function (name, dontFocus) {
Expand Down
95 changes: 81 additions & 14 deletions play.pokemonshowdown.com/js/client-teambuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
this.curSet = null;
Storage.saveTeam(this.curTeam);
} else if (this.curTeam) {
this.clearCachedUserSetsIfNecessary(this.curTeam.format);
this.curTeam.team = Storage.packTeam(this.curSetList);
this.curTeam.iconCache = '';
var team = this.curTeam;
Expand Down Expand Up @@ -1751,17 +1752,21 @@
},
getSmogonSets: function () {
this.$('.teambuilder-pokemon-import .teambuilder-import-smogon-sets').empty();
this.$('.teambuilder-pokemon-import .teambuilder-import-user-sets').empty();

var format = this.curTeam.format;
// If we don't have a specific format, don't try and guess which sets to use.
if (format.match(/gen\d$/)) return;

var self = this;
this.smogonSets = this.smogonSets || {};
this.updateCachedUserSets(format);
this.importSetButtons();

if (this.smogonSets[format] !== undefined) {
this.importSetButtons();
return;
}

// We fetch this as 'text' and JSON.parse it ourserves in order to have consistent behavior
// between the localdev CORS helper and the real jQuery.get function, which would already parse
// this into an object based on the content-type header.
Expand All @@ -1777,30 +1782,91 @@
self.importSetButtons();
}, 'text');
},
updateCachedUserSets: function (format) {
if (this.userSets && this.userSets[format]) return;

this.userSets = this.userSets || {};
this.userSets[format] = {};

var duplicateNameIndices = {};
for (var i = 0; i < teams.length; i++) {
var team = teams[i];
if (team.format !== format || team.capacity !== 24) continue;

var setList = Storage.unpackTeam(team.team);
for (var j = 0; j < setList.length; j++) {
var set = setList[j];
var name = set.name + " " + (duplicateNameIndices[set.name] || "");
var sets = this.userSets[format][set.species] || {};
sets[name] = set;
this.userSets[format][set.species] = sets;
duplicateNameIndices[set.name] = 1 + (duplicateNameIndices[set.name] || 0);
}
}
},
clearCachedUserSetsIfNecessary: function (format) {
if (!this.curTeam || !this.userSets) return;

// clear cached user sets if we have just been in a box for given format
if (this.curTeam.capacity === 24 && this.userSets[format]) {
this.userSets[format] = undefined;
}
},
importSetButtons: function () {
var formatSets = this.smogonSets[this.curTeam.format];
var format = this.curTeam.format;
var smogonFormatSets = this.smogonSets[format];
var userFormatSets = this.userSets[format];
var species = this.curSet.species;

var $setDiv = this.$('.teambuilder-pokemon-import .teambuilder-import-smogon-sets');
$setDiv.empty();
var $smogonSetDiv = this.$('.teambuilder-pokemon-import .teambuilder-import-smogon-sets');
$smogonSetDiv.empty();

if (!formatSets) return;
var $userSetDiv = this.$('.teambuilder-pokemon-import .teambuilder-import-user-sets');
$userSetDiv.empty();

var sets = $.extend({}, formatSets['dex'][species], (formatSets['stats'] || {})[species]);
if (smogonFormatSets) {
var smogonSets = $.extend({}, smogonFormatSets['dex'][species], (smogonFormatSets['stats'] || {})[species]);
$smogonSetDiv.text('Sample sets: ');
for (var set in smogonSets) {
$smogonSetDiv.append('<button name="importSmogonSet" class="button smogon">' + BattleLog.escapeHTML(set) + '</button>');
}
$smogonSetDiv.append(' <small>(<a target="_blank" href="' + this.smogdexLink(species) + '">Smogon&nbsp;analysis</a>)</small>');
}

$setDiv.text('Sample sets: ');
for (var set in sets) {
$setDiv.append('<button name="importSmogonSet" class="button">' + BattleLog.escapeHTML(set) + '</button>');
$userSetDiv.text('Box sets: ');
if (userFormatSets && userFormatSets[species]) {
for (var set in userFormatSets[species]) {
$userSetDiv.append('<button name="importSmogonSet" class="button box">' + BattleLog.escapeHTML(set) + '</button>');
}
} else {
$userSetDiv.append('<small>(Sets from your boxes in this format will be available here)</small>');
}
$setDiv.append(' <small>(<a target="_blank" href="' + this.smogdexLink(species) + '">Smogon&nbsp;analysis</a>)</small>');
},
importSmogonSet: function (i, button) {
var formatSets = this.smogonSets[this.curTeam.format];
var species = this.curSet.species;

var setName = this.$(button).text();
var smogonSet = (formatSets['dex'][species] && formatSets['dex'][species][setName]) || (formatSets['stats'][species] && formatSets['stats'][species][setName]);
var curSet = $.extend({}, this.curSet, smogonSet);
var sampleSet;
if (this.$(button).hasClass('smogon')) {
var smogonFormatSets = this.smogonSets[this.curTeam.format];
sampleSet = smogonFormatSets['dex'][species][setName] || smogonFormatSets['stats'][species][setName];
}

if (this.$(button).hasClass('box')) {
var userFormatSets = this.userSets[this.curTeam.format];
sampleSet = userFormatSets[species][setName];
}

if (!sampleSet) return;

var curSet = $.extend({}, this.curSet, sampleSet);

// smogon samples don't usually have sample names, box samples usually do; either way, don't use them
curSet.name = this.curSet.name || undefined;

// never preserve current set tera, even if smogon set used default
if (this.curSet.gen === 9) {
curSet.teraType = species.forceTeraType || sampleSet.teraType || species.types[0];
}

var text = Storage.exportTeam([curSet], this.curTeam.gen);
this.$('.teambuilder-pokemon-import .pokemonedit').val(text);
Expand Down Expand Up @@ -1891,6 +1957,7 @@
buf += '<div class="pokemonedit-buttons"><button name="closePokemonImport" class="button"><i class="fa fa-chevron-left"></i> Back</button> <button name="savePokemonImport" class="button"><i class="fa fa-floppy-o"></i> Save</button></div>';
buf += '<textarea class="pokemonedit textbox" rows="14"></textarea>';
buf += '<div class="teambuilder-import-smogon-sets"></div>';
buf += '<div class="teambuilder-import-user-sets"></div>';
buf += '</div>';

this.$el.html('<div class="teamwrapper">' + buf + '</div>');
Expand Down
2 changes: 1 addition & 1 deletion play.pokemonshowdown.com/js/client-topbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@
if (navigator.userAgent.includes(' Chrome/64.')) {
buf += '<p><label class="checkbox"><input type="checkbox" name="nogif"' + (Dex.prefs('nogif') ? ' checked' : '') + ' /> Disable GIFs for Chrome 64 bug</label></p>';
}
buf += '<p><label class="checkbox"><input type="checkbox" name="bwgfx"' + (Dex.prefs('bwgfx') ? ' checked' : '') + ' /> Use BW sprites instead of XY models</label></p>';
buf += '<p><label class="checkbox"><input type="checkbox" name="bwgfx"' + (Dex.prefs('bwgfx') ? ' checked' : '') + ' /> Use 2D sprites instead of 3D models</label></p>';
buf += '<p><label class="checkbox"><input type="checkbox" name="nopastgens"' + (Dex.prefs('nopastgens') ? ' checked' : '') + ' /> Use modern sprites for past generations</label></p>';

buf += '<hr />';
Expand Down
2 changes: 1 addition & 1 deletion play.pokemonshowdown.com/js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ function toId() {

var self = this;
var constructSocket = function () {
if (location.host === 'localhost.psim.us' || /[0-9]+.[0-9]+.[0-9]+.[0-9]+\.psim\.us/.test(location.host)) {
if (location.host === 'localhost.psim.us' || /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\.psim\.us/.test(location.host)) {
// normally we assume HTTPS means HTTPS, but make an exception for
// localhost and IPs which generally can't have a signed cert anyway.
Config.server.port = 8000;
Expand Down
Loading

0 comments on commit 1da3e78

Please sign in to comment.