From 515877b84f345fd7d1d5431aa6650b17db8fa639 Mon Sep 17 00:00:00 2001
From: Mia <49593536+mia-pi-git@users.noreply.github.com>
Date: Sun, 24 Mar 2024 22:14:48 -0500
Subject: [PATCH 1/7] Add support for adding badges in battle
---
play.pokemonshowdown.com/js/client-battle.js | 19 ++++++++++++++++
play.pokemonshowdown.com/js/client-ladder.js | 1 +
.../src/battle-animations.ts | 22 ++++++++++++++++++-
play.pokemonshowdown.com/src/battle.ts | 1 +
4 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/play.pokemonshowdown.com/js/client-battle.js b/play.pokemonshowdown.com/js/client-battle.js
index 5a03645c41..1d1afb23cb 100644
--- a/play.pokemonshowdown.com/js/client-battle.js
+++ b/play.pokemonshowdown.com/js/client-battle.js
@@ -132,6 +132,17 @@
if (this.battle.ended) this.battleEnded = true;
this.updateLayout();
this.updateControls();
+ for (var i = 0; i < log.length; i++) {
+ var logLine = log[i];
+ // i don't like this hardcode, and my preferred solution would be not this
+ // but i don't know how many bugs would be caused by having BattleRoom#add
+ // not `return` the running of this function - i suspect a lot
+ // and i also don't want to move the |badge| message into battle.ts, since it's not simulator-related
+ // so we're doing this, for now. open to suggestions
+ if (logLine.substr(0, 7) === '|badge|') {
+ this.add(logLine);
+ }
+ }
},
add: function (data) {
if (!data) return;
@@ -216,6 +227,14 @@
break;
}
} else if (logLine.substr(0, 7) === '|title|') { // eslint-disable-line no-empty
+ } else if (logLine.substr(0, 7) === '|badge|') {
+ var parts = logLine.split('|').slice(2);
+ var slot = parts.shift();
+ var side = this.battle[slot];
+ if (!side) return; // weird
+ // handle all the rendering further down
+ side.badges.push(parts.join('|'));
+ this.battle.scene.updateSidebar(side);
} else if (logLine.substr(0, 5) === '|win|' || logLine === '|tie') {
this.battleEnded = true;
this.battle.stepQueue.push(logLine);
diff --git a/play.pokemonshowdown.com/js/client-ladder.js b/play.pokemonshowdown.com/js/client-ladder.js
index 89547a6b7d..fb60661322 100644
--- a/play.pokemonshowdown.com/js/client-ladder.js
+++ b/play.pokemonshowdown.com/js/client-ladder.js
@@ -161,6 +161,7 @@
}, function (data) {
if (self.curFormat !== format) return;
var buf = '
`;
+ let badgehtml = '';
+ if (side.badges.length) {
+ // hard limiting it to only ever 3 allowed at a time
+ // that's what the server limit is anyway but there should be a client limit too
+ // just in case
+ for (const badgeData of side.badges.slice(0, 3)) {
+ // ${badge.type}|${badge.format}|${BADGE_THRESHOLDS[badge.type]}-${badge.season}
+ const [type, format, details] = badgeData.split('|');
+ // todo, maybe make this more easily configured if we ever add badges for other stuff?
+ // but idk that we're planning that for now so
+ const [threshold, season] = details.split('-');
+ const hover = `Top ${threshold} in ${format} during ladder season ${season}`;
+ badgehtml += ``;
+ }
+ badgehtml += ' ';
+ }
+ return (
+ `
`
+ );
}
updateSidebar(side: Side) {
if (this.battle.gameType === 'freeforall') {
diff --git a/play.pokemonshowdown.com/src/battle.ts b/play.pokemonshowdown.com/src/battle.ts
index 04ca1b915a..7677e786d7 100644
--- a/play.pokemonshowdown.com/src/battle.ts
+++ b/play.pokemonshowdown.com/src/battle.ts
@@ -607,6 +607,7 @@ export class Side {
foe: Side = null!;
ally: Side | null = null;
avatar: string = 'unknown';
+ badges: string[] = [];
rating: string = '';
totalPokemon = 6;
x = 0;
From 6ce7014e62a9385a9062f582f13b1e9cc3107510 Mon Sep 17 00:00:00 2001
From: Mia <49593536+mia-pi-git@users.noreply.github.com>
Date: Sun, 24 Mar 2024 22:33:24 -0500
Subject: [PATCH 2/7] oops
Forgot these needed to be below the avatar per latest spec, not above
---
play.pokemonshowdown.com/src/battle-animations.ts | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/play.pokemonshowdown.com/src/battle-animations.ts b/play.pokemonshowdown.com/src/battle-animations.ts
index 6300482846..79aa969a16 100644
--- a/play.pokemonshowdown.com/src/battle-animations.ts
+++ b/play.pokemonshowdown.com/src/battle-animations.ts
@@ -692,6 +692,7 @@ export class BattleScene implements BattleSceneStub {
const faded = side.name ? `` : ` style="opacity: 0.4"`;
let badgehtml = '';
if (side.badges.length) {
+ badgehtml = '';
// hard limiting it to only ever 3 allowed at a time
// that's what the server limit is anyway but there should be a client limit too
// just in case
@@ -704,11 +705,11 @@ export class BattleScene implements BattleSceneStub {
const hover = `Top ${threshold} in ${format} during ladder season ${season}`;
badgehtml += ``;
}
- badgehtml += ' ';
+ badgehtml += '';
}
return (
- `
`
);
}
From 07e928782e6e96ec911d1361d016a30ba3082585 Mon Sep 17 00:00:00 2001
From: Mia <49593536+mia-pi-git@users.noreply.github.com>
Date: Sun, 24 Mar 2024 23:06:26 -0500
Subject: [PATCH 3/7] Move |badge| message handling to battle.ts
---
play.pokemonshowdown.com/js/client-battle.js | 19 -------------------
.../src/battle-animations.ts | 4 ++--
play.pokemonshowdown.com/src/battle.ts | 9 +++++++++
3 files changed, 11 insertions(+), 21 deletions(-)
diff --git a/play.pokemonshowdown.com/js/client-battle.js b/play.pokemonshowdown.com/js/client-battle.js
index 1d1afb23cb..5a03645c41 100644
--- a/play.pokemonshowdown.com/js/client-battle.js
+++ b/play.pokemonshowdown.com/js/client-battle.js
@@ -132,17 +132,6 @@
if (this.battle.ended) this.battleEnded = true;
this.updateLayout();
this.updateControls();
- for (var i = 0; i < log.length; i++) {
- var logLine = log[i];
- // i don't like this hardcode, and my preferred solution would be not this
- // but i don't know how many bugs would be caused by having BattleRoom#add
- // not `return` the running of this function - i suspect a lot
- // and i also don't want to move the |badge| message into battle.ts, since it's not simulator-related
- // so we're doing this, for now. open to suggestions
- if (logLine.substr(0, 7) === '|badge|') {
- this.add(logLine);
- }
- }
},
add: function (data) {
if (!data) return;
@@ -227,14 +216,6 @@
break;
}
} else if (logLine.substr(0, 7) === '|title|') { // eslint-disable-line no-empty
- } else if (logLine.substr(0, 7) === '|badge|') {
- var parts = logLine.split('|').slice(2);
- var slot = parts.shift();
- var side = this.battle[slot];
- if (!side) return; // weird
- // handle all the rendering further down
- side.badges.push(parts.join('|'));
- this.battle.scene.updateSidebar(side);
} else if (logLine.substr(0, 5) === '|win|' || logLine === '|tie') {
this.battleEnded = true;
this.battle.stepQueue.push(logLine);
diff --git a/play.pokemonshowdown.com/src/battle-animations.ts b/play.pokemonshowdown.com/src/battle-animations.ts
index 79aa969a16..e47cc78d9c 100644
--- a/play.pokemonshowdown.com/src/battle-animations.ts
+++ b/play.pokemonshowdown.com/src/battle-animations.ts
@@ -709,8 +709,8 @@ export class BattleScene implements BattleSceneStub {
}
return (
`
${BattleLog.escapeHTML(side.name)}` +
- `
${badgehtml}` +
- `
${pokemonhtml}
`
+ `
` +
+ `
${badgehtml}${pokemonhtml}
`
);
}
updateSidebar(side: Side) {
diff --git a/play.pokemonshowdown.com/src/battle.ts b/play.pokemonshowdown.com/src/battle.ts
index 7677e786d7..54080d7479 100644
--- a/play.pokemonshowdown.com/src/battle.ts
+++ b/play.pokemonshowdown.com/src/battle.ts
@@ -3536,6 +3536,15 @@ export class Battle {
this.scene.updateSidebar(side);
break;
}
+ case 'badge': {
+ const slot = args[1] as SideID;
+ var side = this[slot];
+ if (!side) return; // weird
+ // handle all the rendering further down
+ side.badges.push(args.slice(2).join('|'));
+ this.scene.updateSidebar(side);
+ break;
+ }
case 'teamsize': {
let side = this.getSide(args[1]);
side.totalPokemon = parseInt(args[2], 10);
From d105e20dacd7d6a2e2d3289fc05a72490bf427d7 Mon Sep 17 00:00:00 2001
From: Mia <49593536+mia-pi-git@users.noreply.github.com>
Date: Sun, 24 Mar 2024 23:16:01 -0500
Subject: [PATCH 4/7] Update play.pokemonshowdown.com/src/battle.ts
Co-authored-by: Karthik <32044378+Karthik99999@users.noreply.github.com>
---
play.pokemonshowdown.com/src/battle.ts | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/play.pokemonshowdown.com/src/battle.ts b/play.pokemonshowdown.com/src/battle.ts
index 54080d7479..1ab6fb7fa5 100644
--- a/play.pokemonshowdown.com/src/battle.ts
+++ b/play.pokemonshowdown.com/src/battle.ts
@@ -3537,9 +3537,7 @@ export class Battle {
break;
}
case 'badge': {
- const slot = args[1] as SideID;
- var side = this[slot];
- if (!side) return; // weird
+ let side = this.getSide(args[1]);
// handle all the rendering further down
side.badges.push(args.slice(2).join('|'));
this.scene.updateSidebar(side);
From ec71935d33fb294ca2fafe65a6caf89e53230a98 Mon Sep 17 00:00:00 2001
From: Mia <49593536+mia-pi-git@users.noreply.github.com>
Date: Thu, 28 Mar 2024 16:55:40 -0500
Subject: [PATCH 5/7] Style button on ladder page, also add custom badges for
ou/rands
---
play.pokemonshowdown.com/js/client-ladder.js | 2 +-
play.pokemonshowdown.com/src/battle-animations.ts | 8 +++++++-
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/play.pokemonshowdown.com/js/client-ladder.js b/play.pokemonshowdown.com/js/client-ladder.js
index fb60661322..c08ef1294b 100644
--- a/play.pokemonshowdown.com/js/client-ladder.js
+++ b/play.pokemonshowdown.com/js/client-ladder.js
@@ -161,7 +161,7 @@
}, function (data) {
if (self.curFormat !== format) return;
var buf = '