Skip to content

Commit

Permalink
Populate Tooltips with information from OTS (#2161)
Browse files Browse the repository at this point in the history
  • Loading branch information
Karthik99999 authored Oct 18, 2023
1 parent dd4108c commit ec1ca0e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/battle-text-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class BattleTextParser {
case 'fieldhtml': case 'controlshtml': case 'bigerror':
case 'debug': case 'tier': case 'challstr': case 'popup': case '':
return [cmd, line.slice(index + 1)];
case 'c': case 'chat': case 'uhtml': case 'uhtmlchange': case 'queryresponse':
case 'c': case 'chat': case 'uhtml': case 'uhtmlchange': case 'queryresponse': case 'showteam':
// three parts
const index2a = line.indexOf('|', index + 1);
return [cmd, line.slice(index + 1, index2a), line.slice(index2a + 1)];
Expand Down
45 changes: 43 additions & 2 deletions src/battle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,14 +736,19 @@ export class Side {
this.battle.scene.removeSideCondition(this.n, id);
}
addPokemon(name: string, ident: string, details: string, replaceSlot = -1) {
const oldItem = replaceSlot >= 0 ? this.pokemon[replaceSlot].item : undefined;
const oldPokemon = replaceSlot >= 0 ? this.pokemon[replaceSlot] : undefined;

const data = this.battle.parseDetails(name, ident, details);
const poke = new Pokemon(data, this);
if (oldItem) poke.item = oldItem;
if (oldPokemon) {
poke.item = oldPokemon.item;
poke.baseAbility = oldPokemon.baseAbility;
poke.teraType = oldPokemon.teraType;
}

if (!poke.ability && poke.baseAbility) poke.ability = poke.baseAbility;
poke.reset();
if (oldPokemon?.moveTrack.length) poke.moveTrack = oldPokemon.moveTrack;

if (replaceSlot >= 0) {
this.pokemon[replaceSlot] = poke;
Expand Down Expand Up @@ -3571,6 +3576,42 @@ export class Battle {
this.scene.teamPreview();
break;
}
case 'showteam': {
if (this.turn !== 0) return;
// @ts-ignore
if (!window.Storage?.unpackTeam || !window.Storage?.exportTeam) return;
// @ts-ignore
const team: PokemonSet[] = Storage.unpackTeam(args[2]);
if (!team) return;
const side = this.getSide(args[1]);
side.clearPokemon();
for (const set of team) {
const details = set.species + (!set.level || set.level === 100 ? '' : ', L' + set.level) +
(!set.gender || set.gender === 'N' ? '' : ', ' + set.gender) + (set.shiny ? ', shiny' : '');
const pokemon = side.addPokemon('', '', details);
if (set.item) pokemon.item = set.item;
if (set.ability) pokemon.rememberAbility(set.ability);
for (const move of set.moves) {
pokemon.rememberMove(move, 0);
}
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>`);
break;
}
case 'switch': case 'drag': case 'replace': {
this.endLastTurn();
let poke = this.getSwitchedPokemon(args[1], args[2])!;
Expand Down

0 comments on commit ec1ca0e

Please sign in to comment.