Skip to content

Commit 8411650

Browse files
Add support for adding badges in battle (#2235)
* Add support for adding badges in battle * oops Forgot these needed to be below the avatar per latest spec, not above * Move |badge| message handling to battle.ts * Update play.pokemonshowdown.com/src/battle.ts Co-authored-by: Karthik <[email protected]> * Style button on ladder page, also add custom badges for ou/rands * change some badge filename stuff * more css stuff, final version --------- Co-authored-by: Karthik <[email protected]>
1 parent 6361e25 commit 8411650

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

play.pokemonshowdown.com/js/client-ladder.js

+1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161
}, function (data) {
162162
if (self.curFormat !== format) return;
163163
var buf = '<div class="ladder pad"><p><button name="selectFormat"><i class="fa fa-chevron-left"></i> Format List</button></p><p><button class="button" name="refresh"><i class="fa fa-refresh"></i> Refresh</button>';
164+
buf += '&nbsp;<button class="button" name="send" value="/join view-seasonladder-' + format + '"><i class="fa fa-trophy"></i> Season rankings</button>';
164165
buf += '<form class="search"><input type="text" name="searchval" class="textbox searchinput" value="' + BattleLog.escapeHTML(self.curSearchVal || '') + '" placeholder="username prefix" /><button type="submit"> Search</button></form></p>';
165166
buf += '<h3>' + BattleLog.escapeFormat(format) + ' Top ' + BattleLog.escapeHTML(self.curSearchVal ? "- '" + self.curSearchVal + "'" : '500') + '</h3>';
166167
buf += data + '</div>';

play.pokemonshowdown.com/src/battle-animations.ts

+28-1
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,34 @@ export class BattleScene implements BattleSceneStub {
690690
pokemonhtml = '<div class="teamicons">' + pokemonhtml + '</div>';
691691
const ratinghtml = side.rating ? ` title="Rating: ${BattleLog.escapeHTML(side.rating)}"` : ``;
692692
const faded = side.name ? `` : ` style="opacity: 0.4"`;
693-
return `<div class="trainer trainer-${posStr}"${faded}><strong>${BattleLog.escapeHTML(side.name)}</strong><div class="trainersprite"${ratinghtml} style="background-image:url(${Dex.resolveAvatar(side.avatar)})"></div>${pokemonhtml}</div>`;
693+
let badgehtml = '';
694+
if (side.badges.length) {
695+
badgehtml = '<span class="badges">';
696+
// hard limiting it to only ever 3 allowed at a time
697+
// that's what the server limit is anyway but there should be a client limit too
698+
// just in case
699+
for (const badgeData of side.badges.slice(0, 3)) {
700+
// ${badge.type}|${badge.format}|${BADGE_THRESHOLDS[badge.type]}-${badge.season}
701+
const [type, format, details] = badgeData.split('|');
702+
// todo, maybe make this more easily configured if we ever add badges for other stuff?
703+
// but idk that we're planning that for now so
704+
const [threshold] = details.split('-');
705+
const hover = `User is Top ${threshold} on the ${format} Ladder`;
706+
// ou and randbats get diff badges from everyone else, find it
707+
// (regex futureproofs for double digit gens)
708+
let formatType = format.split(/gen\d+/)[1] || 'none';
709+
if (!['ou', 'randombattle'].includes(formatType)) {
710+
formatType = 'rotating';
711+
}
712+
badgehtml += `<img src="${Dex.resourcePrefix}/sprites/misc/${formatType}_${type}.png" style="padding: 0px 1px 0px 1px" width="16px" height="16px" title="${hover}" />`;
713+
}
714+
badgehtml += '</span>';
715+
}
716+
return (
717+
`<div class="trainer trainer-${posStr}"${faded}><strong>${BattleLog.escapeHTML(side.name)}</strong>` +
718+
`<div class="trainersprite"${ratinghtml} style="background-image:url(${Dex.resolveAvatar(side.avatar)})">` +
719+
`</div>${badgehtml}${pokemonhtml}</div>`
720+
);
694721
}
695722
updateSidebar(side: Side) {
696723
if (this.battle.gameType === 'freeforall') {

play.pokemonshowdown.com/src/battle.ts

+10
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ export class Side {
607607
foe: Side = null!;
608608
ally: Side | null = null;
609609
avatar: string = 'unknown';
610+
badges: string[] = [];
610611
rating: string = '';
611612
totalPokemon = 6;
612613
x = 0;
@@ -3535,6 +3536,15 @@ export class Battle {
35353536
this.scene.updateSidebar(side);
35363537
break;
35373538
}
3539+
case 'badge': {
3540+
let side = this.getSide(args[1]);
3541+
// handle all the rendering further down
3542+
const badge = args.slice(2).join('|');
3543+
// (don't allow duping)
3544+
if (!side.badges.includes(badge)) side.badges.push(badge);
3545+
this.scene.updateSidebar(side);
3546+
break;
3547+
}
35383548
case 'teamsize': {
35393549
let side = this.getSide(args[1]);
35403550
side.totalPokemon = parseInt(args[2], 10);

0 commit comments

Comments
 (0)