Skip to content

Commit

Permalink
Create HTML for showteam protocol in BattleLog
Browse files Browse the repository at this point in the history
  • Loading branch information
Karthik99999 committed Oct 18, 2023
1 parent ec1ca0e commit e45d7a4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
24 changes: 24 additions & 0 deletions src/battle-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,30 @@ export class BattleLog {
app.rooms[roomid].notifyOnce(title, body, 'highlight');
break;

case 'showteam': {
// @ts-ignore
if (!window.Storage?.unpackTeam || !window.Storage?.exportTeam) return;
// @ts-ignore
const team: PokemonSet[] = Storage.unpackTeam(args[2]);
const side = this.scene?.battle.getSide(args[1]);
if (!team || !side) return;
const exportedTeam = team.map(set => {
// @ts-ignore
let buf = Storage.exportTeam([set], this.gen).replace(/\n/g, '<br />');
if (set.name && set.name !== set.species) {
buf = buf.replace(set.name, BattleLog.sanitizeHTML(`<span class="picon" style="${Dex.getPokemonIcon(set.species)}"></span><br />${set.name}`));
} else {
buf = buf.replace(set.species, `<span class="picon" style="${Dex.getPokemonIcon(set.species)}"></span><br />${set.species}`);
}
if (set.item) {
buf = buf.replace(set.item, `${set.item} <span class="itemicon" style="${Dex.getItemIcon(set.item)}"></span>`);
}
return buf;
}).join('');
divHTML = `<div class="infobox"><details><summary>Open Team Sheet for ${side.name}</summary>${exportedTeam}</details></div>`;
break;
}

case 'seed': case 'choice': case ':': case 'timer': case 't:':
case 'J': case 'L': case 'N': case 'spectator': case 'spectatorleave':
case 'initdone':
Expand Down
17 changes: 2 additions & 15 deletions src/battle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3579,7 +3579,7 @@ export class Battle {
case 'showteam': {
if (this.turn !== 0) return;
// @ts-ignore
if (!window.Storage?.unpackTeam || !window.Storage?.exportTeam) return;
if (!window.Storage?.unpackTeam) return;
// @ts-ignore
const team: PokemonSet[] = Storage.unpackTeam(args[2]);
if (!team) return;
Expand All @@ -3596,20 +3596,7 @@ export class Battle {
}
if (set.teraType) pokemon.teraType = set.teraType;
}
const exportedTeam = team.map(set => {
// @ts-ignore
let buf = Storage.exportTeam([set], this.gen).replace(/\n/g, '<br />');
if (set.name && set.name !== set.species) {
buf = buf.replace(set.name, BattleLog.sanitizeHTML(`<psicon pokemon="${set.species}" /> <br />${set.name}`));
} else {
buf = buf.replace(set.species, `<psicon pokemon="${set.species}" /> <br />${set.species}`);
}
if (set.item) {
buf = buf.replace(set.item, `${set.item} <psicon item="${set.item}" />`);
}
return buf;
}).join('');
this.add(`|raw|<div class="infobox"><details><summary>Open Team Sheet for ${side.name}</summary>${exportedTeam}</details></div>`);
this.log(args);
break;
}
case 'switch': case 'drag': case 'replace': {
Expand Down

0 comments on commit e45d7a4

Please sign in to comment.