This commit is contained in:
Sirz Benjie 2025-07-24 19:14:29 -06:00
parent 0c42f16fdd
commit 4df9a60743
No known key found for this signature in database
GPG Key ID: 4A524B4D196C759E
5 changed files with 71 additions and 19 deletions

View File

@ -19,6 +19,12 @@ export const Z$BoolCatchToFalse = /*@__PURE__*/ z
.boolean() .boolean()
.catch(false); .catch(false);
/** Reusable schema for a positive number, equivalent to `z.number().positive()`. */
export const Z$PositiveNumber = /*@__PURE__*/ z
.number()
.positive()
.catch(0);
/** Reusable schema for an optional non-negative integer that coerces invalid inputs to `undefined` */ /** Reusable schema for an optional non-negative integer that coerces invalid inputs to `undefined` */
export const Z$OptionalNonNegativeIntCatchToUndef = /*@__PURE__*/ z export const Z$OptionalNonNegativeIntCatchToUndef = /*@__PURE__*/ z
.int() .int()

View File

@ -4,7 +4,7 @@ import { Z$PokemonMove } from "#schemas/pokemon-move";
import { Z$Gender } from "#system/schemas/v1.10/pokemon-gender"; import { Z$Gender } from "#system/schemas/v1.10/pokemon-gender";
import z from "zod"; import z from "zod";
import { NatureSchema } from "./pokemon-nature"; import { NatureSchema } from "./pokemon-nature";
import { IVSetSchema, statSetSchema } from "./pokemon-stats"; import { Z$IVSet, Z$StatSet } from "./pokemon-stats";
import { Z$PokemonType } from "./pokemon-type"; import { Z$PokemonType } from "./pokemon-type";
import { StatusSchema } from "./status-effect"; import { StatusSchema } from "./status-effect";
@ -37,8 +37,8 @@ const Z$PokemonData = z.looseObject({
gender: Z$Gender.catch(-1), gender: Z$Gender.catch(-1),
// hp can be 0 if fainted // hp can be 0 if fainted
hp: Z$NonNegativeInt, hp: Z$NonNegativeInt,
stats: statSetSchema, stats: Z$StatSet,
ivs: IVSetSchema, ivs: Z$IVSet,
nature: NatureSchema, nature: NatureSchema,
moveset: z.array(Z$PokemonMove).catch([]), moveset: z.array(Z$PokemonMove).catch([]),
status: z.union([z.null(), StatusSchema]).catch(null), status: z.union([z.null(), StatusSchema]).catch(null),
@ -88,8 +88,6 @@ export const Z$EnemyPokemonData = z.object({
bossSegments: z.int().nonnegative().default(0), bossSegments: z.int().nonnegative().default(0),
}); });
// TODO: Replace output assertion type with the type of pokemon data that has CustomPokemonData. // TODO: Replace output assertion type with the type of pokemon data that has CustomPokemonData.
export function PreCustomPokemonDataMigrator( export function PreCustomPokemonDataMigrator(
data: z.output<typeof Z$PokemonData>, data: z.output<typeof Z$PokemonData>,

View File

@ -0,0 +1,30 @@
import { Z$NonNegativeInt, Z$PositiveInt, Z$PositiveNumber } from "#system/schemas/common";
import { Z$PokemonType } from "#system/schemas/v1.10/pokemon-type";
import { z } from "zod";
export const Z$PokemonSpeciesForm = z.object({
speciesId: Z$PositiveInt,
_formIndex: Z$NonNegativeInt.catch(0),
_generation: Z$PositiveInt.catch(1),
type1: Z$PokemonType,
type2: Z$PokemonType.nullable().catch(null),
height: Z$PositiveNumber,
weight: Z$PositiveNumber,
ability: Z$NonNegativeInt,
ability2: Z$NonNegativeInt,
abilityHidden: Z$NonNegativeInt,
baseTotal: Z$PositiveInt,
baseStats: z.tuple([
Z$PositiveInt, // hp
Z$PositiveInt, // atk
Z$PositiveInt, // def
Z$PositiveInt, // spa
Z$PositiveInt, // spd
Z$PositiveInt, // spe
]),
catchRate: z.int().min(0).max(255),
baseFriendship: Z$NonNegativeInt,
baseExp: Z$PositiveInt,
genderDiffs: z.boolean(),
isStarterSelectable: z.boolean(),
});

View File

@ -8,7 +8,7 @@ import { z } from "zod";
* - Each IV is an integer between 0 and 31, inclusive. * - Each IV is an integer between 0 and 31, inclusive.
* - Malformed values parse to 15 by default. * - Malformed values parse to 15 by default.
*/ */
export const IVSchema = z.int().min(0).max(31).catch(15); export const Z$IV = z.int().min(0).max(31).catch(15);
/** /**
* Schema for a set of 6 Pokémon IVs, as of version 1.10 * Schema for a set of 6 Pokémon IVs, as of version 1.10
@ -16,9 +16,7 @@ export const IVSchema = z.int().min(0).max(31).catch(15);
* @remarks * @remarks
* Malformed IV sets default to [15, 15, 15, 15, 15, 15]. * Malformed IV sets default to [15, 15, 15, 15, 15, 15].
*/ */
export const IVSetSchema = z export const Z$IVSet = z.tuple([Z$IV, Z$IV, Z$IV, Z$IV, Z$IV, Z$IV]).catch([15, 15, 15, 15, 15, 15]);
.tuple([IVSchema, IVSchema, IVSchema, IVSchema, IVSchema, IVSchema])
.catch([15, 15, 15, 15, 15, 15]);
/** /**
* Schema for a Pokémon's stats, as of version 1.10 * Schema for a Pokémon's stats, as of version 1.10
@ -29,7 +27,7 @@ export const IVSetSchema = z
* - [4]: Special Defense, * - [4]: Special Defense,
* - [5]: Speed * - [5]: Speed
*/ */
export const statSetSchema = z.tuple([ export const Z$StatSet = z.tuple([
Z$PositiveInt, // HP Z$PositiveInt, // HP
Z$PositiveInt, // Attack Z$PositiveInt, // Attack
Z$PositiveInt, // Defense Z$PositiveInt, // Defense

View File

@ -1,7 +1,11 @@
import { Z$NonNegativeInt } from "#system/schemas/common";
import { Z$Gender } from "#system/schemas/v1.10/pokemon-gender";
import { Z$PokemonSpeciesForm } from "#system/schemas/v1.10/pokemon-species-form";
import { Z$StatSet } from "#system/schemas/v1.10/pokemon-stats";
import { Z$PokemonType } from "#system/schemas/v1.10/pokemon-type";
import { Z$TurnMove } from "#system/schemas/v1.10/turn-move"; import { Z$TurnMove } from "#system/schemas/v1.10/turn-move";
import { z } from "zod"; import { z } from "zod";
const Z$StatStage = z.int().min(-6).max(6).catch(0); const Z$StatStage = z.int().min(-6).max(6).catch(0);
const Z$StatStageSet = z.tuple([ const Z$StatStageSet = z.tuple([
@ -11,7 +15,12 @@ const Z$StatStageSet = z.tuple([
Z$StatStage, Z$StatStage,
Z$StatStage, Z$StatStage,
Z$StatStage, Z$StatStage,
Z$StatStage]) Z$StatStage,
]);
// Pre version 1.10 pokemon summon data migration needs to rename
// input fields
/** /**
* Zod schema for Pokémon summon data as of version 1.10. * Zod schema for Pokémon summon data as of version 1.10.
* *
@ -19,9 +28,20 @@ const Z$StatStageSet = z.tuple([
export const Z$PokemonSummonData = z.object({ export const Z$PokemonSummonData = z.object({
statStages: Z$StatStageSet.optional().catch(undefined), statStages: Z$StatStageSet.optional().catch(undefined),
moveQueue: z.array(Z$TurnMove).optional().catch(undefined), moveQueue: z.array(Z$TurnMove).optional().catch(undefined),
// todo: tags
abilitySuppressed: z.boolean().optional().catch(undefined),
//#region Overrides for transform //#region Overrides for transform
speciesForm: Z$PokemonSpeciesForm.nullable().catch(null),
fusionSpeciesForm: Z$PokemonSpeciesForm.nullable().catch(null),
ability: Z$NonNegativeInt.optional().catch(undefined),
passiveAbility: Z$NonNegativeInt.optional().catch(undefined),
gender: Z$Gender.optional().catch(undefined),
fusionGender: Z$Gender.optional().catch(undefined),
stats: Z$StatSet.optional().catch(undefined),
moveset: z.array(Z$TurnMove).nullable().catch(null),
//#endregion Overrides for transform //#endregion Overrides for transform
types: z.array(Z$PokemonType).optional().catch(undefined),
addedType: Z$PokemonType.nullable().catch(null),
}); });