\n';
buf += '\n';
buf += '\n';
From 0647322d4b2e072ed358c2648069bce2e6cc938d Mon Sep 17 00:00:00 2001
From: Mia <49593536+mia-pi-git@users.noreply.github.com>
Date: Sun, 22 Oct 2023 17:43:20 -0500
Subject: [PATCH 4/7] Storage: Improve handling of local teams versus remote
teams
This should help differentiate local teams and remote-loaded teams. When they're initially requested, the client now compares each new team against all the existing teams - if they appear to be similar, it doesn't add it to the builder (so that dupe teams don't show up). It considers them similar if they have the same mons, title, and format. Otherwise, if it finds one that's close, it'll add it but marked as (server version) so people can tell which is which.
---
js/storage.js | 33 ++++++++++++++++++++++++++++++++-
1 file changed, 32 insertions(+), 1 deletion(-)
diff --git a/js/storage.js b/js/storage.js
index f9794cf3c9d..359299f2632 100644
--- a/js/storage.js
+++ b/js/storage.js
@@ -585,6 +585,32 @@ Storage.loadTeams = function () {
} catch (e) {}
};
+/** returns false to add the team, true to not add it, 'rename' to add it under a diff name */
+Storage.compareTeams = function (serverTeam, localTeam) {
+ // if titles match exactly and mons are the same, assume they're the same team
+ // if they don't match, it might be edited, but we'll go ahead and add it to the user's
+ // teambuilder since they may want that old version around. just go ahead and edit the name
+ var mons = serverTeam.team.split(',');
+ var matches = 0;
+ var otherMons = Storage.unpackTeam(localTeam.team);
+ for (var i = 0; i < mons.length; i++) {
+ for (var j = 0; j < otherMons.length; j++) {
+ if (toID(otherMons[j].species) === toID(mons[i])) {
+ matches++;
+ }
+ }
+ }
+ var localTeamName = localTeam.name.replace(' (server version)', '');
+ if (!(serverTeam.name === localTeamName && serverTeam.format === localTeam.format)) {
+ return false;
+ }
+ // if it's been edited since, invalidate the team id on this one (count it as new)
+ // and load from server
+ if (mons.length !== otherMons.length || matches !== otherMons.length) return 'rename';
+ if (serverTeam.teamid === localTeam.teamid && localTeam.teamid) return true;
+ return true;
+};
+
Storage.loadRemoteTeams = function (after) {
$.get(app.user.getActionPHP(), {act: 'getteams'}, Storage.safeJSON(function (data) {
if (data.actionerror) {
@@ -595,12 +621,17 @@ Storage.loadRemoteTeams = function (after) {
var matched = false;
for (var j = 0; j < Storage.teams.length; j++) {
var curTeam = Storage.teams[j];
- if (curTeam.teamid === team.teamid) {
+ var match = Storage.compareTeams(team, curTeam);
+ if (match === true) {
// prioritize locally saved teams over remote
// as so to not overwrite changes
matched = true;
break;
}
+ if (match === 'rename') {
+ delete curTeam.teamid;
+ team.name += ' (server version)';
+ }
}
team.loaded = false;
if (!matched) {
From 68a9694b3ac41c2f83bf431dbd48704ce4a66293 Mon Sep 17 00:00:00 2001
From: Mia <49593536+mia-pi-git@users.noreply.github.com>
Date: Sun, 22 Oct 2023 18:43:41 -0500
Subject: [PATCH 5/7] Storage: Properly compare team names
---
js/storage.js | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/js/storage.js b/js/storage.js
index 359299f2632..20d8ca5783b 100644
--- a/js/storage.js
+++ b/js/storage.js
@@ -600,8 +600,11 @@ Storage.compareTeams = function (serverTeam, localTeam) {
}
}
}
- var localTeamName = localTeam.name.replace(' (server version)', '');
- if (!(serverTeam.name === localTeamName && serverTeam.format === localTeam.format)) {
+ var sanitize = function (name) {
+ return (name || "").replace(' (server version)', '').trim();
+ };
+ var nameMatches = sanitize(serverTeam.name) === sanitize(localTeam.name);
+ if (!(nameMatches && serverTeam.format === localTeam.format)) {
return false;
}
// if it's been edited since, invalidate the team id on this one (count it as new)
From afbb31da920711e7011a80571504fee049edb4b5 Mon Sep 17 00:00:00 2001
From: Leonard Craft III
Date: Mon, 23 Oct 2023 00:00:42 -0500
Subject: [PATCH 6/7] Teambuilder: Fix empty learnsets in oldgen VGC formats
again
---
src/battle-dex-search.ts | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/battle-dex-search.ts b/src/battle-dex-search.ts
index 81807f51ba8..52e5eb1305c 100644
--- a/src/battle-dex-search.ts
+++ b/src/battle-dex-search.ts
@@ -1501,8 +1501,8 @@ class BattleMoveSearch extends BattleTypedSearch<'move'> {
const isSTABmons = (format.includes('stabmons') || format === 'staaabmons');
const isTradebacks = format.includes('tradebacks');
const regionBornLegality = dex.gen >= 6 &&
- /^battle(spot|stadium|festival)/.test(format) || format.startsWith('vgc') ||
- (dex.gen === 9 && this.formatType !== 'natdex');
+ (/^battle(spot|stadium|festival)/.test(format) || format.startsWith('vgc') ||
+ (dex.gen === 9 && this.formatType !== 'natdex'));
let learnsetid = this.firstLearnsetid(species.id);
let moves: string[] = [];
From 65d387a82346b73d14bfa16d236dc7a4260efd0a Mon Sep 17 00:00:00 2001
From: Mia <49593536+mia-pi-git@users.noreply.github.com>
Date: Mon, 23 Oct 2023 14:06:49 -0500
Subject: [PATCH 7/7] Storage: Account for malformed team names in loading
comparisons
---
js/storage.js | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/js/storage.js b/js/storage.js
index 20d8ca5783b..7c8457b2180 100644
--- a/js/storage.js
+++ b/js/storage.js
@@ -601,7 +601,7 @@ Storage.compareTeams = function (serverTeam, localTeam) {
}
}
var sanitize = function (name) {
- return (name || "").replace(' (server version)', '').trim();
+ return (name || "").replace(/\s+\(server version\)/g, '').trim();
};
var nameMatches = sanitize(serverTeam.name) === sanitize(localTeam.name);
if (!(nameMatches && serverTeam.format === localTeam.format)) {
@@ -633,7 +633,9 @@ Storage.loadRemoteTeams = function (after) {
}
if (match === 'rename') {
delete curTeam.teamid;
- team.name += ' (server version)';
+ if (!team.name.endsWith(' (server version)')) {
+ team.name += ' (server version)';
+ }
}
}
team.loaded = false;