mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-11 19:02:16 +02:00
Rework and test getPokemonPrefix
This commit is contained in:
parent
29914de5f6
commit
1bf9755691
81
src/messages.test.ts
Normal file
81
src/messages.test.ts
Normal file
@ -0,0 +1,81 @@
|
||||
import { expect, describe, it } from "vitest";
|
||||
import Pokemon from "./field/pokemon";
|
||||
import { getPokemonMessage, getPokemonPrefix } from "./messages";
|
||||
import { BattleSpec } from "./enums/battle-spec";
|
||||
|
||||
describe("messages", () => {
|
||||
describe("getPokemonPrefix", () => {
|
||||
it("returns an empty prefix if the pokemon is a pokemon of the player", () => {
|
||||
const pokemon = {
|
||||
isPlayer: () => true,
|
||||
hasTrainer: () => false,
|
||||
scene: {
|
||||
currentBattle: {
|
||||
battleSpec: BattleSpec.DEFAULT
|
||||
}
|
||||
}
|
||||
} as Pokemon;
|
||||
|
||||
expect(getPokemonPrefix(pokemon)).toBe('');
|
||||
});
|
||||
|
||||
it("returns the wild prefix if the pokemon does not have a trainer", () => {
|
||||
const pokemon = {
|
||||
isPlayer: () => false,
|
||||
hasTrainer: () => false,
|
||||
scene: {
|
||||
currentBattle: {
|
||||
battleSpec: BattleSpec.DEFAULT
|
||||
}
|
||||
}
|
||||
} as Pokemon;
|
||||
|
||||
expect(getPokemonPrefix(pokemon)).toBe('Wild ');
|
||||
});
|
||||
|
||||
it("returns the foe prefix if the pokemon has a trainer which is not the player", () => {
|
||||
const pokemon = {
|
||||
isPlayer: () => false,
|
||||
hasTrainer: () => true,
|
||||
scene: {
|
||||
currentBattle: {
|
||||
battleSpec: BattleSpec.DEFAULT
|
||||
}
|
||||
}
|
||||
} as Pokemon;
|
||||
|
||||
expect(getPokemonPrefix(pokemon)).toBe('Foe ');
|
||||
});
|
||||
|
||||
it("returns the foe prefix if the pokemon is the final boss", () => {
|
||||
const pokemon = {
|
||||
isPlayer: () => false,
|
||||
hasTrainer: () => false,
|
||||
scene: {
|
||||
currentBattle: {
|
||||
battleSpec: BattleSpec.FINAL_BOSS
|
||||
}
|
||||
}
|
||||
} as Pokemon;
|
||||
|
||||
expect(getPokemonPrefix(pokemon)).toBe('Foe ');
|
||||
});
|
||||
});
|
||||
|
||||
describe("getPokemonMessage", () => {
|
||||
it("returns a message with pokemon prefix, pokemon name and content given", () => {
|
||||
const pokemon = {
|
||||
name: "Gengar",
|
||||
isPlayer: () => false,
|
||||
hasTrainer: () => true,
|
||||
scene: {
|
||||
currentBattle: {
|
||||
battleSpec: BattleSpec.DEFAULT
|
||||
}
|
||||
}
|
||||
} as Pokemon;
|
||||
|
||||
expect(getPokemonMessage(pokemon, " is hurt\nby poison!")).toBe('Foe Gengar is hurt\nby poison!');
|
||||
});
|
||||
});
|
||||
});
|
@ -6,14 +6,12 @@ export function getPokemonMessage(pokemon: Pokemon, content: string): string {
|
||||
}
|
||||
|
||||
export function getPokemonPrefix(pokemon: Pokemon): string {
|
||||
let prefix: string;
|
||||
if (pokemon.isPlayer()) return '';
|
||||
|
||||
switch (pokemon.scene.currentBattle.battleSpec) {
|
||||
case BattleSpec.DEFAULT:
|
||||
prefix = !pokemon.isPlayer() ? pokemon.hasTrainer() ? 'Foe ' : 'Wild ' : '';
|
||||
break;
|
||||
return pokemon.hasTrainer() ? 'Foe ' : 'Wild ';
|
||||
case BattleSpec.FINAL_BOSS:
|
||||
prefix = !pokemon.isPlayer() ? 'Foe ' : '';
|
||||
break;
|
||||
return 'Foe ';
|
||||
}
|
||||
return prefix;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user