mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-12-15 14:25:32 +01:00
* make IVs use Uint8Array * Add many typed array helpers * Move array utils to its own file * Add suppression comment * Adjust type of `getStats` * Adjust test mocks to use typed arrays * Adjust signatures of some phases to use ArrayLike<T> * Adjust signature of src/ui/containers/stats-container#updateIvs * Remove comment gap to try to satisfy typedoc * Ensure ivs are always set * fix: fun-and-games me to use typed array * Add new tests for array utilities * Update type of ivs in save-data.ts * Update part-timer-encounter.test.ts * Convert uses of StatusEffect[] to Uint8Array * Update ssui to use uint8array for ivs * Revert use of typed arrays * Move `nil` to @types/common * Make more arrays readonly * fix: remnant change to immune effects * Even more array improvements * Apply kev's suggestions from code review Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> * address Bertie's comments from code review * tests: remove undefined check for bigint array types * fixup abilities.ts --------- Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
78 lines
2.7 KiB
TypeScript
78 lines
2.7 KiB
TypeScript
// biome-ignore-start lint/correctness/noUnusedImports: TSDoc imports
|
|
import type { Pokemon } from "#field/pokemon";
|
|
// biome-ignore-end lint/correctness/noUnusedImports: TSDoc imports
|
|
|
|
import { getPokemonNameWithAffix } from "#app/messages";
|
|
import Overrides from "#app/overrides";
|
|
import { MoveId } from "#enums/move-id";
|
|
import { getEnumStr } from "#test/test-utils/string-utils";
|
|
import { isPokemonInstance, receivedStr } from "#test/test-utils/test-utils";
|
|
import { coerceArray } from "#utils/array";
|
|
import type { MatcherState, SyncExpectationResult } from "@vitest/expect";
|
|
|
|
/**
|
|
* Matcher to check the amount of PP consumed by a {@linkcode Pokemon}.
|
|
* @param received - The actual value received. Should be a {@linkcode Pokemon}
|
|
* @param moveId - The {@linkcode MoveId} that should have consumed PP
|
|
* @param ppUsed - The numerical amount of PP that should have been consumed,
|
|
* or `all` to indicate the move should be _out_ of PP
|
|
* @returns Whether the matcher passed
|
|
* @remarks
|
|
* If the same move appears in the Pokemon's moveset multiple times, this will fail the test!
|
|
*/
|
|
export function toHaveUsedPP(
|
|
this: MatcherState,
|
|
received: unknown,
|
|
moveId: MoveId,
|
|
ppUsed: number | "all",
|
|
): SyncExpectationResult {
|
|
if (!isPokemonInstance(received)) {
|
|
return {
|
|
pass: this.isNot,
|
|
message: () => `Expected to receive a Pokémon, but got ${receivedStr(received)}!`,
|
|
};
|
|
}
|
|
|
|
const override = received.isPlayer() ? Overrides.MOVESET_OVERRIDE : Overrides.ENEMY_MOVESET_OVERRIDE;
|
|
if (coerceArray(override).length > 0) {
|
|
return {
|
|
pass: this.isNot,
|
|
message: () =>
|
|
`Cannot test for PP consumption with ${received.isPlayer() ? "player" : "enemy"} moveset overrides active!`,
|
|
};
|
|
}
|
|
|
|
const pkmName = getPokemonNameWithAffix(received);
|
|
const moveStr = getEnumStr(MoveId, moveId);
|
|
|
|
const movesetMoves = received.getMoveset().filter(pm => pm.moveId === moveId);
|
|
if (movesetMoves.length !== 1) {
|
|
return {
|
|
pass: this.isNot,
|
|
message: () =>
|
|
`Expected MoveId.${moveStr} to appear in ${pkmName}'s moveset exactly once, but got ${movesetMoves.length} times!`,
|
|
expected: moveId,
|
|
actual: received.getMoveset(),
|
|
};
|
|
}
|
|
|
|
const move = movesetMoves[0]; // will be the only move in the array
|
|
|
|
let ppStr: string = ppUsed.toString();
|
|
if (typeof ppUsed === "string") {
|
|
ppStr = "all its";
|
|
ppUsed = move.getMovePp();
|
|
}
|
|
const pass = move.ppUsed === ppUsed;
|
|
|
|
return {
|
|
pass,
|
|
message: () =>
|
|
pass
|
|
? `Expected ${pkmName}'s ${moveStr} to NOT have used ${ppStr} PP, but it did!`
|
|
: `Expected ${pkmName}'s ${moveStr} to have used ${ppStr} PP, but got ${move.ppUsed} instead!`,
|
|
expected: ppUsed,
|
|
actual: move.ppUsed,
|
|
};
|
|
}
|