Skip to content

Commit

Permalink
Update pokemon-popup.component.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
mariokreitz committed Sep 10, 2024
1 parent 10a53bd commit 5779e1b
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import { DecimalPipe, TitleCasePipe } from '@angular/common';
styleUrl: './pokemon-popup.component.scss',
})
export class PokemonPopupComponent implements OnInit {
playCry() {
if (this.cries) {
const audio = new Audio(this.cries.legacy);
audio.play();
}
}
closePopup() {
document.getElementById('overview')?.classList.add('d_none');
}
Expand All @@ -20,6 +26,10 @@ export class PokemonPopupComponent implements OnInit {
imgSrc!: string | null;
types!: string[];
description!: string;
cries?: {
latest: string;
legacy: string;
};

constructor() {}

Expand All @@ -44,14 +54,23 @@ export class PokemonPopupComponent implements OnInit {
stats,
types,
weight,
cries,
} = this.selectedPokemon;
this.id = id;
this.name = name;
this.imgSrc =
sprites.other.dream_world.front_default ??
sprites.other['official-artwork'].front_default;
this.types = types.map(({ type }) => type.name);
this.description = flavor_text_entries[0].flavor_text;
const filteredDescription = flavor_text_entries.filter(
({ language }) => language.name === 'en'
);
const randomDescription =
filteredDescription[
Math.floor(Math.random() * filteredDescription.length)
];
this.description = randomDescription.flavor_text;
this.cries = cries;
}
}
}
Expand Down

0 comments on commit 5779e1b

Please sign in to comment.