From 283aa65dd4ecb702703632bcbb3a3f77bb1cd1f9 Mon Sep 17 00:00:00 2001
From: tofa <79044321+im-tofa@users.noreply.github.com>
Date: Fri, 1 Mar 2024 22:32:53 +0100
Subject: [PATCH 01/10] WIP user samples
---
.../js/client-teambuilder.js | 31 +++++++++++++++++--
1 file changed, 28 insertions(+), 3 deletions(-)
diff --git a/play.pokemonshowdown.com/js/client-teambuilder.js b/play.pokemonshowdown.com/js/client-teambuilder.js
index 170cf69752..d5b8b27350 100644
--- a/play.pokemonshowdown.com/js/client-teambuilder.js
+++ b/play.pokemonshowdown.com/js/client-teambuilder.js
@@ -1767,6 +1767,7 @@
},
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.
@@ -1775,15 +1776,19 @@
var self = this;
this.smogonSets = this.smogonSets || {};
if (this.smogonSets[format] !== undefined) {
+ this.getUserSets(format);
this.importSetButtons();
return;
}
+
+ this.getUserSets(format);
+
// 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.
$.get('https://' + Config.routes.client + '/data/sets/' + format + '.json', {}, function (data) {
try {
- self.smogonSets[format] = JSON.parse(data);
+ self.smogonSets[format] = $.extend(self.smogonSets[format], JSON.parse(data));
} catch (e) {
// An error occured. Mark this as false, so that we don't try to reimport sets for this format
// in the future.
@@ -1792,6 +1797,17 @@
self.importSetButtons();
}, 'text');
},
+ getUserSets: function (format) {
+ this.smogonSets[format] = $.extend(this.smogonSets[format], {"user": {}});
+ for(const team of teams) {
+ if(team.format === format && team.capacity === 24) {
+ const setList = Storage.unpackTeam(team.team);
+ for(const pokemon of setList) {
+ this.smogonSets[format]["user"][pokemon.species] = {[pokemon.name] : pokemon};
+ }
+ }
+ }
+ },
importSetButtons: function () {
var formatSets = this.smogonSets[this.curTeam.format];
var species = this.curSet.species;
@@ -1799,22 +1815,30 @@
var $setDiv = this.$('.teambuilder-pokemon-import .teambuilder-import-smogon-sets');
$setDiv.empty();
+ var $userSetDiv = this.$('.teambuilder-pokemon-import .teambuilder-import-user-sets');
+ $userSetDiv.empty();
+
if (!formatSets) return;
var sets = $.extend({}, formatSets['dex'][species], (formatSets['stats'] || {})[species]);
-
$setDiv.text('Sample sets: ');
for (var set in sets) {
$setDiv.append('' + BattleLog.escapeHTML(set) + ' ');
}
$setDiv.append(' (Smogon analysis ) ');
+
+ var userSets = $.extend({}, (formatSets['user'] || {})[species]);
+ $userSetDiv.text('User sets: ');
+ for (var set in userSets) {
+ $userSetDiv.append('' + BattleLog.escapeHTML(set) + ' ');
+ }
},
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][setName] || formatSets['stats'][species][setName];
+ var smogonSet = formatSets['dex'][species][setName] || formatSets['stats'][species][setName] || formatSets['user'][species][setName];
var curSet = $.extend({}, this.curSet, smogonSet);
var text = Storage.exportTeam([curSet], this.curTeam.gen);
@@ -1906,6 +1930,7 @@
buf += '
Back Save
';
buf += '';
buf += '
';
+ buf += '
';
buf += '';
this.$el.html('' + buf + '
');
From 2f27c0181883b9cea9cf9662641077b55b8cf1bf Mon Sep 17 00:00:00 2001
From: tofa <79044321+im-tofa@users.noreply.github.com>
Date: Fri, 1 Mar 2024 23:26:53 +0100
Subject: [PATCH 02/10] propagate default tera type from samples
---
play.pokemonshowdown.com/js/client-teambuilder.js | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/play.pokemonshowdown.com/js/client-teambuilder.js b/play.pokemonshowdown.com/js/client-teambuilder.js
index d5b8b27350..483c9193ea 100644
--- a/play.pokemonshowdown.com/js/client-teambuilder.js
+++ b/play.pokemonshowdown.com/js/client-teambuilder.js
@@ -1781,8 +1781,6 @@
return;
}
- this.getUserSets(format);
-
// 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.
@@ -1794,6 +1792,7 @@
// in the future.
self.smogonSets[format] = false;
}
+ self.getUserSets(format);
self.importSetButtons();
}, 'text');
},
@@ -1803,7 +1802,8 @@
if(team.format === format && team.capacity === 24) {
const setList = Storage.unpackTeam(team.team);
for(const pokemon of setList) {
- this.smogonSets[format]["user"][pokemon.species] = {[pokemon.name] : pokemon};
+ console.log(pokemon);
+ this.smogonSets[format]['user'][pokemon.species] = $.extend(this.smogonSets[format]['user'][pokemon.species], {[pokemon.name] : pokemon});
}
}
}
@@ -1839,7 +1839,7 @@
var setName = this.$(button).text();
var smogonSet = formatSets['dex'][species][setName] || formatSets['stats'][species][setName] || formatSets['user'][species][setName];
- var curSet = $.extend({}, this.curSet, smogonSet);
+ var curSet = $.extend({}, smogonSet);
var text = Storage.exportTeam([curSet], this.curTeam.gen);
this.$('.teambuilder-pokemon-import .pokemonedit').val(text);
From a89d9b6dc680971426bbcc14304fe7797b2577f4 Mon Sep 17 00:00:00 2001
From: tofa <79044321+im-tofa@users.noreply.github.com>
Date: Sat, 2 Mar 2024 00:06:36 +0100
Subject: [PATCH 03/10] allow duplicate names as unique sets
---
play.pokemonshowdown.com/js/client-teambuilder.js | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/play.pokemonshowdown.com/js/client-teambuilder.js b/play.pokemonshowdown.com/js/client-teambuilder.js
index 483c9193ea..ffc1bf1240 100644
--- a/play.pokemonshowdown.com/js/client-teambuilder.js
+++ b/play.pokemonshowdown.com/js/client-teambuilder.js
@@ -1786,7 +1786,7 @@
// this into an object based on the content-type header.
$.get('https://' + Config.routes.client + '/data/sets/' + format + '.json', {}, function (data) {
try {
- self.smogonSets[format] = $.extend(self.smogonSets[format], JSON.parse(data));
+ self.smogonSets[format] = JSON.parse(data);
} catch (e) {
// An error occured. Mark this as false, so that we don't try to reimport sets for this format
// in the future.
@@ -1798,12 +1798,16 @@
},
getUserSets: function (format) {
this.smogonSets[format] = $.extend(this.smogonSets[format], {"user": {}});
+
+ var duplicateNameIndices = {};
for(const team of teams) {
if(team.format === format && team.capacity === 24) {
const setList = Storage.unpackTeam(team.team);
for(const pokemon of setList) {
- console.log(pokemon);
- this.smogonSets[format]['user'][pokemon.species] = $.extend(this.smogonSets[format]['user'][pokemon.species], {[pokemon.name] : pokemon});
+ var name = pokemon.name + " " + (duplicateNameIndices[pokemon.name] || "");
+ var sets = this.smogonSets[format]['user'][pokemon.species];
+ this.smogonSets[format]['user'][pokemon.species] = $.extend({}, sets, {[name] : pokemon});
+ duplicateNameIndices[pokemon.name] = 1 + (duplicateNameIndices[pokemon.name] || 0);
}
}
}
From 8b49d3d46ef38cec0b0aed2b587b7291de651ad4 Mon Sep 17 00:00:00 2001
From: tofa <79044321+im-tofa@users.noreply.github.com>
Date: Sat, 2 Mar 2024 00:58:36 +0100
Subject: [PATCH 04/10] fix tera merging and allow either type of set to be
missing
---
.../js/client-teambuilder.js | 34 +++++++++++++------
1 file changed, 23 insertions(+), 11 deletions(-)
diff --git a/play.pokemonshowdown.com/js/client-teambuilder.js b/play.pokemonshowdown.com/js/client-teambuilder.js
index ffc1bf1240..fa3d16f636 100644
--- a/play.pokemonshowdown.com/js/client-teambuilder.js
+++ b/play.pokemonshowdown.com/js/client-teambuilder.js
@@ -1824,17 +1824,21 @@
if (!formatSets) return;
- var sets = $.extend({}, formatSets['dex'][species], (formatSets['stats'] || {})[species]);
- $setDiv.text('Sample sets: ');
- for (var set in sets) {
- $setDiv.append('' + BattleLog.escapeHTML(set) + ' ');
+ var sets = $.extend({}, formatSets['dex']?.[species], formatSets['stats']?.[species]);
+ if(Object.keys(sets).length !== 0) {
+ $setDiv.text('Sample sets: ');
+ for (var set in sets) {
+ $setDiv.append('' + BattleLog.escapeHTML(set) + ' ');
+ }
+ $setDiv.append(' (Smogon analysis ) ');
}
- $setDiv.append(' (Smogon analysis ) ');
- var userSets = $.extend({}, (formatSets['user'] || {})[species]);
- $userSetDiv.text('User sets: ');
- for (var set in userSets) {
- $userSetDiv.append('' + BattleLog.escapeHTML(set) + ' ');
+ var userSets = formatSets['user']?.[species];
+ if(userSets) {
+ $userSetDiv.text('User sets: ');
+ for (var set in userSets) {
+ $userSetDiv.append('' + BattleLog.escapeHTML(set) + ' ');
+ }
}
},
importSmogonSet: function (i, button) {
@@ -1842,8 +1846,16 @@
var species = this.curSet.species;
var setName = this.$(button).text();
- var smogonSet = formatSets['dex'][species][setName] || formatSets['stats'][species][setName] || formatSets['user'][species][setName];
- var curSet = $.extend({}, smogonSet);
+ var smogonSet = formatSets['dex']?.[species]?.[setName]
+ || formatSets['stats']?.[species]?.[setName]
+ || formatSets['user']?.[species]?.[setName];
+
+ var curSet = $.extend({}, this.curSet, smogonSet);
+
+ // never preserve current set tera, even if smogon set used default
+ if(this.curSet.gen === 9) {
+ curSet.teraType = species.forceTeraType || smogonSet?.teraType || species.types[0]
+ }
var text = Storage.exportTeam([curSet], this.curTeam.gen);
this.$('.teambuilder-pokemon-import .pokemonedit').val(text);
From 6b5e8de239239b0ddab454c7601260b625259b83 Mon Sep 17 00:00:00 2001
From: tofa <79044321+im-tofa@users.noreply.github.com>
Date: Sat, 2 Mar 2024 10:05:28 +0100
Subject: [PATCH 05/10] single quotes
---
play.pokemonshowdown.com/js/client-teambuilder.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/play.pokemonshowdown.com/js/client-teambuilder.js b/play.pokemonshowdown.com/js/client-teambuilder.js
index fa3d16f636..e00fe395bc 100644
--- a/play.pokemonshowdown.com/js/client-teambuilder.js
+++ b/play.pokemonshowdown.com/js/client-teambuilder.js
@@ -1797,7 +1797,7 @@
}, 'text');
},
getUserSets: function (format) {
- this.smogonSets[format] = $.extend(this.smogonSets[format], {"user": {}});
+ this.smogonSets[format] = $.extend(this.smogonSets[format], {'user': {}});
var duplicateNameIndices = {};
for(const team of teams) {
From d269e21a20c2c693adce3f320d54429f9582dab7 Mon Sep 17 00:00:00 2001
From: tofa <79044321+im-tofa@users.noreply.github.com>
Date: Sun, 10 Mar 2024 07:38:57 +0100
Subject: [PATCH 06/10] generate user samples at most once per team view
---
.../js/client-teambuilder.js | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/play.pokemonshowdown.com/js/client-teambuilder.js b/play.pokemonshowdown.com/js/client-teambuilder.js
index e00fe395bc..2cb8eda622 100644
--- a/play.pokemonshowdown.com/js/client-teambuilder.js
+++ b/play.pokemonshowdown.com/js/client-teambuilder.js
@@ -104,6 +104,10 @@
this.curSet = null;
Storage.saveTeam(this.curTeam);
} else if (this.curTeam) {
+ var format = this.curTeam.format;
+ if(this.smogonSets?.[format]) {
+ this.smogonSets[format]['user'] = undefined;
+ }
this.curTeam.team = Storage.packTeam(this.curSetList);
this.curTeam.iconCache = '';
var team = this.curTeam;
@@ -1776,7 +1780,6 @@
var self = this;
this.smogonSets = this.smogonSets || {};
if (this.smogonSets[format] !== undefined) {
- this.getUserSets(format);
this.importSetButtons();
return;
}
@@ -1792,13 +1795,12 @@
// in the future.
self.smogonSets[format] = false;
}
- self.getUserSets(format);
self.importSetButtons();
}, 'text');
},
getUserSets: function (format) {
- this.smogonSets[format] = $.extend(this.smogonSets[format], {'user': {}});
-
+ console.log("lazily fetching user sets");
+ $.extend(this.smogonSets[format], {'user': {}});
var duplicateNameIndices = {};
for(const team of teams) {
if(team.format === format && team.capacity === 24) {
@@ -1813,7 +1815,8 @@
}
},
importSetButtons: function () {
- var formatSets = this.smogonSets[this.curTeam.format];
+ const format = this.curTeam.format;
+ var formatSets = this.smogonSets[format];
var species = this.curSet.species;
var $setDiv = this.$('.teambuilder-pokemon-import .teambuilder-import-smogon-sets');
@@ -1833,6 +1836,10 @@
$setDiv.append(' (Smogon analysis ) ');
}
+ if(!this.smogonSets[format]?.['user']) {
+ this.getUserSets(format);
+ }
+
var userSets = formatSets['user']?.[species];
if(userSets) {
$userSetDiv.text('User sets: ');
From 13c36aa899774ca4117e07570a27d5a9b91e6d07 Mon Sep 17 00:00:00 2001
From: tofa <79044321+im-tofa@users.noreply.github.com>
Date: Sun, 10 Mar 2024 08:49:07 +0100
Subject: [PATCH 07/10] don't clear user set cache unless box in format has
been modified
---
.../js/client-teambuilder.js | 21 ++++++++++---------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/play.pokemonshowdown.com/js/client-teambuilder.js b/play.pokemonshowdown.com/js/client-teambuilder.js
index 2cb8eda622..df02489193 100644
--- a/play.pokemonshowdown.com/js/client-teambuilder.js
+++ b/play.pokemonshowdown.com/js/client-teambuilder.js
@@ -104,10 +104,7 @@
this.curSet = null;
Storage.saveTeam(this.curTeam);
} else if (this.curTeam) {
- var format = this.curTeam.format;
- if(this.smogonSets?.[format]) {
- this.smogonSets[format]['user'] = undefined;
- }
+ this.clearCachedUserSetsIfNecessary(this.curTeam.format);
this.curTeam.team = Storage.packTeam(this.curSetList);
this.curTeam.iconCache = '';
var team = this.curTeam;
@@ -1798,8 +1795,9 @@
self.importSetButtons();
}, 'text');
},
- getUserSets: function (format) {
- console.log("lazily fetching user sets");
+ updateCachedUserSets: function (format) {
+ if(this.smogonSets[format]?.['user']) return;
+
$.extend(this.smogonSets[format], {'user': {}});
var duplicateNameIndices = {};
for(const team of teams) {
@@ -1814,6 +1812,12 @@
}
}
},
+ clearCachedUserSetsIfNecessary: function (format) {
+ // clear cached user sets if we have just been in a box for given format
+ if(this.curTeam?.capacity === 24 && this.smogonSets?.[format]) {
+ this.smogonSets[format]['user'] = undefined;
+ }
+ },
importSetButtons: function () {
const format = this.curTeam.format;
var formatSets = this.smogonSets[format];
@@ -1836,10 +1840,7 @@
$setDiv.append(' (Smogon analysis ) ');
}
- if(!this.smogonSets[format]?.['user']) {
- this.getUserSets(format);
- }
-
+ this.updateCachedUserSets(format);
var userSets = formatSets['user']?.[species];
if(userSets) {
$userSetDiv.text('User sets: ');
From 6f55a597d9bc1fff900261bcd6cc6ee809446ff3 Mon Sep 17 00:00:00 2001
From: tofa <79044321+im-tofa@users.noreply.github.com>
Date: Sun, 10 Mar 2024 09:43:42 +0100
Subject: [PATCH 08/10] in case smogonSets[format] === false
---
play.pokemonshowdown.com/js/client-teambuilder.js | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/play.pokemonshowdown.com/js/client-teambuilder.js b/play.pokemonshowdown.com/js/client-teambuilder.js
index df02489193..800a76c4e7 100644
--- a/play.pokemonshowdown.com/js/client-teambuilder.js
+++ b/play.pokemonshowdown.com/js/client-teambuilder.js
@@ -1798,7 +1798,8 @@
updateCachedUserSets: function (format) {
if(this.smogonSets[format]?.['user']) return;
- $.extend(this.smogonSets[format], {'user': {}});
+ this.smogonSets[format] = $.extend(this.smogonSets[format] || {}, {'user': {}});
+
var duplicateNameIndices = {};
for(const team of teams) {
if(team.format === format && team.capacity === 24) {
From 0f473a44897babbd5b36afbfba54f7a1dc860f15 Mon Sep 17 00:00:00 2001
From: tofa <79044321+im-tofa@users.noreply.github.com>
Date: Sun, 17 Mar 2024 07:55:09 +0100
Subject: [PATCH 09/10] place user sets in separate cache
I didn't like certain niche behaviors when the
two were part of the same cache, e.g user sets
weren't loaded when in a tier that had no
samples such as VGC. So I separated them and
allowed them to work independent of each other.
---
.../js/client-teambuilder.js | 55 ++++++++++---------
1 file changed, 28 insertions(+), 27 deletions(-)
diff --git a/play.pokemonshowdown.com/js/client-teambuilder.js b/play.pokemonshowdown.com/js/client-teambuilder.js
index 800a76c4e7..cb4c24f89a 100644
--- a/play.pokemonshowdown.com/js/client-teambuilder.js
+++ b/play.pokemonshowdown.com/js/client-teambuilder.js
@@ -1776,8 +1776,10 @@
var self = this;
this.smogonSets = this.smogonSets || {};
+ this.updateCachedUserSets(format);
+ this.importSetButtons();
+
if (this.smogonSets[format] !== undefined) {
- this.importSetButtons();
return;
}
@@ -1796,9 +1798,10 @@
}, 'text');
},
updateCachedUserSets: function (format) {
- if(this.smogonSets[format]?.['user']) return;
+ if(this.userSets?.[format]) return;
- this.smogonSets[format] = $.extend(this.smogonSets[format] || {}, {'user': {}});
+ this.userSets = this.userSets || {};
+ this.userSets[format] = this.userSets[format] || {};
var duplicateNameIndices = {};
for(const team of teams) {
@@ -1806,8 +1809,8 @@
const setList = Storage.unpackTeam(team.team);
for(const pokemon of setList) {
var name = pokemon.name + " " + (duplicateNameIndices[pokemon.name] || "");
- var sets = this.smogonSets[format]['user'][pokemon.species];
- this.smogonSets[format]['user'][pokemon.species] = $.extend({}, sets, {[name] : pokemon});
+ var sets = this.userSets[format][pokemon.species];
+ this.userSets[format][pokemon.species] = $.extend(sets || {}, {[name] : pokemon});
duplicateNameIndices[pokemon.name] = 1 + (duplicateNameIndices[pokemon.name] || 0);
}
}
@@ -1815,49 +1818,47 @@
},
clearCachedUserSetsIfNecessary: function (format) {
// clear cached user sets if we have just been in a box for given format
- if(this.curTeam?.capacity === 24 && this.smogonSets?.[format]) {
- this.smogonSets[format]['user'] = undefined;
+ if(this.curTeam?.capacity === 24 && this.userSets?.[format]) {
+ this.userSets[format] = undefined;
}
},
importSetButtons: function () {
- const format = this.curTeam.format;
- var formatSets = this.smogonSets[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();
var $userSetDiv = this.$('.teambuilder-pokemon-import .teambuilder-import-user-sets');
$userSetDiv.empty();
- if (!formatSets) return;
-
- var sets = $.extend({}, formatSets['dex']?.[species], formatSets['stats']?.[species]);
- if(Object.keys(sets).length !== 0) {
- $setDiv.text('Sample sets: ');
- for (var set in sets) {
- $setDiv.append('' + BattleLog.escapeHTML(set) + ' ');
+ if(smogonFormatSets) {
+ var smogonSets = $.extend({}, smogonFormatSets['dex'][species], (smogonFormatSets['stats'] || {})[species]);
+ $smogonSetDiv.text('Sample sets: ');
+ for (var set in smogonSets) {
+ $smogonSetDiv.append('' + BattleLog.escapeHTML(set) + ' ');
}
- $setDiv.append(' (Smogon analysis ) ');
+ $smogonSetDiv.append(' (Smogon analysis ) ');
}
- this.updateCachedUserSets(format);
- var userSets = formatSets['user']?.[species];
- if(userSets) {
+ if(userFormatSets?.[species]) {
$userSetDiv.text('User sets: ');
- for (var set in userSets) {
+ for (var set in userFormatSets[species]) {
$userSetDiv.append('' + BattleLog.escapeHTML(set) + ' ');
}
}
},
importSmogonSet: function (i, button) {
- var formatSets = this.smogonSets[this.curTeam.format];
+ var smogonFormatSets = this.smogonSets?.[this.curTeam.format];
+ var userFormatSets = this.userSets?.[this.curTeam.format];
var species = this.curSet.species;
var setName = this.$(button).text();
- var smogonSet = formatSets['dex']?.[species]?.[setName]
- || formatSets['stats']?.[species]?.[setName]
- || formatSets['user']?.[species]?.[setName];
+ var smogonSet = smogonFormatSets?.['dex']?.[species]?.[setName]
+ || smogonFormatSets?.['stats']?.[species]?.[setName]
+ || userFormatSets?.[species]?.[setName];
var curSet = $.extend({}, this.curSet, smogonSet);
From 005479499eba70cac20236ae5ecd1a7ffdb174b4 Mon Sep 17 00:00:00 2001
From: tofa <79044321+im-tofa@users.noreply.github.com>
Date: Sun, 7 Apr 2024 17:43:51 +0200
Subject: [PATCH 10/10] improve based on feedback, add info on empty box sets
---
.../js/client-teambuilder.js | 70 ++++++++++++-------
1 file changed, 43 insertions(+), 27 deletions(-)
diff --git a/play.pokemonshowdown.com/js/client-teambuilder.js b/play.pokemonshowdown.com/js/client-teambuilder.js
index cb4c24f89a..072872443a 100644
--- a/play.pokemonshowdown.com/js/client-teambuilder.js
+++ b/play.pokemonshowdown.com/js/client-teambuilder.js
@@ -1798,27 +1798,32 @@
}, 'text');
},
updateCachedUserSets: function (format) {
- if(this.userSets?.[format]) return;
+ if (this.userSets && this.userSets[format]) return;
this.userSets = this.userSets || {};
- this.userSets[format] = this.userSets[format] || {};
+ this.userSets[format] = {};
var duplicateNameIndices = {};
- for(const team of teams) {
- if(team.format === format && team.capacity === 24) {
- const setList = Storage.unpackTeam(team.team);
- for(const pokemon of setList) {
- var name = pokemon.name + " " + (duplicateNameIndices[pokemon.name] || "");
- var sets = this.userSets[format][pokemon.species];
- this.userSets[format][pokemon.species] = $.extend(sets || {}, {[name] : pokemon});
- duplicateNameIndices[pokemon.name] = 1 + (duplicateNameIndices[pokemon.name] || 0);
- }
+ 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]) {
+ if (this.curTeam.capacity === 24 && this.userSets[format]) {
this.userSets[format] = undefined;
}
},
@@ -1834,37 +1839,48 @@
var $userSetDiv = this.$('.teambuilder-pokemon-import .teambuilder-import-user-sets');
$userSetDiv.empty();
- if(smogonFormatSets) {
+ if (smogonFormatSets) {
var smogonSets = $.extend({}, smogonFormatSets['dex'][species], (smogonFormatSets['stats'] || {})[species]);
$smogonSetDiv.text('Sample sets: ');
for (var set in smogonSets) {
- $smogonSetDiv.append('' + BattleLog.escapeHTML(set) + ' ');
+ $smogonSetDiv.append('' + BattleLog.escapeHTML(set) + ' ');
}
$smogonSetDiv.append(' (Smogon analysis ) ');
}
- if(userFormatSets?.[species]) {
- $userSetDiv.text('User sets: ');
+ $userSetDiv.text('Box sets: ');
+ if (userFormatSets && userFormatSets[species]) {
for (var set in userFormatSets[species]) {
- $userSetDiv.append('' + BattleLog.escapeHTML(set) + ' ');
+ $userSetDiv.append('' + BattleLog.escapeHTML(set) + ' ');
}
+ } else {
+ $userSetDiv.append('(Sets from your boxes in this format will be available here) ');
}
},
importSmogonSet: function (i, button) {
- var smogonFormatSets = this.smogonSets?.[this.curTeam.format];
- var userFormatSets = this.userSets?.[this.curTeam.format];
var species = this.curSet.species;
-
var setName = this.$(button).text();
- var smogonSet = smogonFormatSets?.['dex']?.[species]?.[setName]
- || smogonFormatSets?.['stats']?.[species]?.[setName]
- || userFormatSets?.[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 || smogonSet?.teraType || species.types[0]
+ if (this.curSet.gen === 9) {
+ curSet.teraType = species.forceTeraType || sampleSet.teraType || species.types[0];
}
var text = Storage.exportTeam([curSet], this.curTeam.gen);