This commit is contained in:
Sirz Benjie 2025-07-30 11:21:39 -06:00
parent 10af69a777
commit 5321f00636
No known key found for this signature in database
GPG Key ID: 4A524B4D196C759E
28 changed files with 136 additions and 54 deletions

View File

@ -1,5 +1,5 @@
import type { Z$PokemonData } from "#system/schemas/v1.10/pokemon-data";
import { NatureSchema } from "#system/schemas/v1.10/pokemon-nature";
import type { Z$PokemonData } from "#system/schemas/pokemon/pokemon-data";
import { NatureSchema } from "#system/schemas/pokemon/pokemon-nature";
import type z from "zod";
/**

View File

@ -1,5 +1,6 @@
import { Z$PositiveInt } from "#system/schemas/common";
import type { Z$IllusionData } from "#system/schemas/v1.10/illusion-data";
import type { Z$IllusionData } from "#system/schemas/pokemon/illusion-data";
import { isNullOrUndefined } from "#utils/common";
import { getPokemonSpecies } from "#utils/pokemon-utils";
import { z } from "zod";
@ -29,6 +30,7 @@ import { z } from "zod";
* ```
*
* As this version of the data is compatible with version 1.10, we only need to specify the new properties.
* In addition, the value type of `fusionSpecies` changed from `PokemonSpecies` to simply the species ID.
*/
export const Z$V1_9_IllusionData = z.looseObject({
species: Z$PositiveInt,
@ -45,25 +47,27 @@ type V1_9_IllusionData = z.input<typeof Z$V1_9_IllusionData>;
* Migrate illusion data from version 1.9 to 1.10
*
* @remarks
* Extract `speciesId` from `fusionSpecies`, and use defaults for all fields from the illusioned pokemon.
* Extracts `speciesId` from `fusionSpecies`, and use defaults for all fields from the illusioned pokemon.
*
* In version 1.9, the illusion's name and shiny state were not serialized.
* The name is recoverable from the species ID, but shiny state is not recoverable.
*/
export function V1_10_IllusionDataMigrator(arg: V1_9_IllusionData): Partial<z.input<typeof Z$IllusionData>> {
return Z$V1_9_IllusionData.transform(data => {
// Needed to fetch a default name.
const pokemon = getPokemonSpecies(data.species);
return {
const result = {
...(data as Omit<V1_9_IllusionData, "fusionSpecies">),
// unwrap fusion species
fusionSpecies: data.fusionSpecies?.speciesId,
// and use defaults for all fields from the illusioned pokemon
name: pokemon.name,
nickname: pokemon.name,
shiny: false,
fusionShiny: false,
variant: 0,
fusionVariant: 0,
fusionFormIndex: 0,
};
} as Partial<z.input<typeof Z$IllusionData>>;
// With no fusion species, these fields should be left undefined.
if (!isNullOrUndefined(data.fusionSpecies)) {
result.fusionSpecies = data.fusionSpecies.speciesId;
result.fusionShiny = false; // default shiny state
result.fusionVariant = 0; // default variant
}
return result;
}).parse(arg);
}

View File

@ -0,0 +1,22 @@
// biome-ignore-start lint/correctness/noUnusedImports: used in a tsdoc comment
import type { SerializedArenaData } from "#system/arena-data";
import { Z$Terrain } from "#system/schemas/arena/terrain";
import { Z$Weather } from "#system/schemas/arena/weather";
// biome-ignore-end lint/correctness/noUnusedImports: end
import { Z$BiomeID } from "#system/schemas/biome-id";
import { Z$NonNegativeInt } from "#system/schemas/common";
import { z } from "zod";
/**
* Zod schema for {@linkcode SerializedArenaData} as of version 1.10
*/
export const Z$ArenaData = z.object({
biome: Z$BiomeID,
weather: Z$Weather.optional().catch(undefined),
terrain: Z$Terrain.optional().catch(undefined),
tags: z
.array(0 as unknown as any)
.optional()
.catch(undefined),
playerTerasUsed: Z$NonNegativeInt.optional().catch(undefined),
});

View File

@ -0,0 +1,24 @@
// biome-ignore-start lint/correctness/noUnusedImports: used in a tsdoc commentD
import type { SerializedTerrain, TerrainType } from "#data/terrain";
// biome-ignore-end lint/correctness/noUnusedImports: end
import { z } from "zod";
/**
* Zod schema for {@linkcode TerrainType} as of version 1.10.
*
* @remarks
* - `0`: NONE,
* - `1`: MISTY,
* - `2`: ELECTRIC,
* - `3`: GRASSY,
* - `4`: PSYCHIC
*/
export const Z$TerrainType = z.literal([0, 1, 2, 3, 4]);
/**
* Zod schema for {@linkcode SerializedTerrain} as of version 1.10.
*/
export const Z$Terrain = z.object({
terrainType: Z$TerrainType,
turnsLeft: z.int(),
});

View File

@ -0,0 +1,30 @@
// biome-ignore-start lint/correctness/noUnusedImports: used in a tsdoc comment
import type { Weather } from "#data/weather";
import type { WeatherType } from "#enums/weather-type";
// biome-ignore-end lint/correctness/noUnusedImports: used in a tsdoc comment
import { z } from "zod";
/**
* Zod schema for {@linkcode WeatherType} as of version 1.10.
*
* @remarks
* - `0`: NONE,
* - `1`: SUNNY,
* - `2`: RAIN,
* - `3`: SANDSTORM,
* - `4`: HAIL,
* - `5`: SNOW,
* - `6`: FOG,
* - `7`: HEAVY_RAIN,
* - `8`: HARSH_SUN,
* - `9`: STRONG_WINDS
*/
export const Z$WeatherType = z.literal([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
/**
* Zod schema for {@linkcode SerializedWeather} as of version 1.10.
*/
export const Z$Weather = z.object({
type: Z$WeatherType,
turnsLeft: z.int(),
});

View File

@ -1,6 +1,5 @@
import { z } from "zod";
/**
* Zod schema for a Pokémon move, as of version 1.10.
*/
@ -14,4 +13,3 @@ export const Z$PokemonMove = z.object({
// If necessary, we can define `transforms` which implicitly create an instance of the class.
export type ParsedPokemonMove = z.output<typeof Z$PokemonMove>;

View File

@ -4,7 +4,7 @@ import type { TurnMove } from "#types/turn-move";
// biome-ignore-end lint/correctness/noUnusedImports: used in tsdoc comment
import { Z$NonNegativeInt, Z$PositiveInt } from "#system/schemas/common";
import { Z$BattlerIndex } from "#system/schemas/v1.10/battler-index";
import { Z$BattlerIndex } from "#system/schemas/pokemon/battler-index";
import { Z$MoveResult } from "#system/schemas/v1.10/move-result";
import { z } from "zod";
@ -17,9 +17,9 @@ export const Z$MoveUseMode = z.literal([1, 2, 3, 4, 5]);
* Zod schema for `{@linkcode TurnMove} as of version 1.10.
*/
export const Z$TurnMove = z.object({
move: Z$PositiveInt,
targets: z.array(Z$BattlerIndex),
useMode: Z$MoveUseMode,
result: Z$MoveResult.optional().catch(undefined),
turn: Z$NonNegativeInt.optional().catch(undefined)
move: Z$PositiveInt,
targets: z.array(Z$BattlerIndex),
useMode: Z$MoveUseMode,
result: Z$MoveResult.optional().catch(undefined),
turn: Z$NonNegativeInt.optional().catch(undefined),
});

View File

@ -1,5 +1,5 @@
import { Z$NonNegativeInt, Z$PositiveInt } from "#system/schemas/common";
import { Z$BattlerIndex } from "#system/schemas/v1.10/battler-index";
import { Z$BattlerIndex } from "#system/schemas/pokemon/battler-index";
import { z } from "zod";
/*
@ -126,17 +126,17 @@ const Z$BattlerTagLapseType = z.literal([0, 1, 2, 3, 4, 5, 6, 7, 8]);
// DamagingTrapTag may have a `commonAnim` field, though it's always instantiated.
const Z$BattlerTag = z.object({
tagType: Z$BattlerTagType,
lapseTypes: z.array(Z$BattlerTagLapseType),
turnCount: Z$PositiveInt,
// Source move can be `none` for tags not applied by move, so allow `0` here.
sourceMove: Z$NonNegativeInt,
sourceId: z.int().optional().catch(undefined),
isBatonPassable: z.boolean(),
tagType: Z$BattlerTagType,
lapseTypes: z.array(Z$BattlerTagLapseType),
turnCount: Z$PositiveInt,
// Source move can be `none` for tags not applied by move, so allow `0` here.
sourceMove: Z$NonNegativeInt,
sourceId: z.int().optional().catch(undefined),
isBatonPassable: z.boolean(),
});
export const Z$SeedTag = z.object({
...Z$BattlerTag.shape,
seedType: z.literal("SEEDED"),
sourceIndex: Z$BattlerIndex,
})
...Z$BattlerTag.shape,
seedType: z.literal("SEEDED"),
sourceIndex: Z$BattlerIndex,
});

View File

@ -1,5 +1,5 @@
import { Z$OptionalNonNegativeIntCatchToUndef, Z$PositiveInt } from "#schemas/common";
import { Z$PokemonType } from "#system/schemas/v1.10/pokemon-type";
import { Z$PokemonType } from "#system/schemas/pokemon/pokemon-type";
import { z } from "zod";
/**

View File

@ -1,15 +1,14 @@
import { Z$NonNegativeInt, Z$PositiveInt } from "#system/schemas/common";
import { Z$Gender } from "#system/schemas/pokemon/pokemon-gender";
import { Z$PokeballType } from "#system/schemas/v1.10/pokeball-type";
import { Z$Gender } from "#system/schemas/v1.10/pokemon-gender";
import { z } from "zod";
// TODO: Write migrator for illusion data's fusionSpecies field
// that transforms incoming fusion species
export const Z$IllusionData = z.object({
name: z.string(),
nickname: z.string(),
nickname: z.string().optional().catch(undefined),
shiny: z.boolean(),
variant: z.literal([0, 1, 2]).catch(0),
species: Z$PositiveInt,

View File

@ -1,13 +1,13 @@
import { Z$BoolCatchToFalse, Z$NonNegativeInt, Z$PositiveInt } from "#schemas/common";
import { Z$PokeballType } from "#schemas/pokeball-type";
import { Z$PokemonMove } from "#schemas/pokemon-move";
import { Z$PokemonBattleData } from "#system/schemas/v1.10/pokemon-battle-data";
import { Z$Gender } from "#system/schemas/v1.10/pokemon-gender";
import { NatureSchema } from "#schemas/pokemon/pokemon-nature";
import { Z$IVSet, Z$StatSet } from "#schemas/pokemon/pokemon-stats";
import { StatusSchema } from "#schemas/status-effect";
import { Z$PokemonMove } from "#system/schemas/moves/pokemon-move";
import { Z$PokemonBattleData } from "#system/schemas/pokemon/pokemon-battle-data";
import { Z$Gender } from "#system/schemas/pokemon/pokemon-gender";
import z from "zod";
import { NatureSchema } from "./pokemon-nature";
import { Z$IVSet, Z$StatSet } from "./pokemon-stats";
import { Z$PokemonType } from "./pokemon-type";
import { StatusSchema } from "./status-effect";
/**
* Not meant to actually be used itself.

View File

@ -1,5 +1,5 @@
import { Z$NonNegativeInt, Z$PositiveInt, Z$PositiveNumber } from "#system/schemas/common";
import { Z$PokemonType } from "#system/schemas/v1.10/pokemon-type";
import { Z$PokemonType } from "#system/schemas/pokemon/pokemon-type";
import { z } from "zod";
export const Z$PokemonSpeciesForm = z.object({

View File

@ -1,9 +1,9 @@
import { Z$NonNegativeInt } from "#system/schemas/common";
import { Z$Gender } from "#system/schemas/v1.10/pokemon-gender";
import { Z$PokemonMove } from "#system/schemas/v1.10/pokemon-move";
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$PokemonMove } from "#system/schemas/moves/pokemon-move";
import { Z$TurnMove } from "#system/schemas/moves/turn-move";
import { Z$Gender } from "#system/schemas/pokemon/pokemon-gender";
import { Z$StatSet } from "#system/schemas/pokemon/pokemon-stats";
import { Z$PokemonType } from "#system/schemas/pokemon/pokemon-type";
import { z } from "zod";
export const Z$SerializedSpeciesForm = z.object({
@ -32,5 +32,5 @@ export const Z$PokemonSummonData = z.object({
moveset: z.array(Z$PokemonMove).optional().catch(undefined),
types: z.array(Z$PokemonType).optional().catch(undefined),
addedType: Z$PokemonType.optional().catch(undefined),
illusion
illusion,
});

View File

View File

@ -48,7 +48,12 @@
"./system/version-migration/*.ts",
"./system/*.ts"
],
"#schemas/*": ["./system/schemas/*.ts", "./system/schemas/v1.10/*.ts"],
"#schemas/*": [
"./system/schemas/*.ts",
"./system/schemas/arena/*.ts",
"./system/schemas/moves/*.ts",
"./system/schemas/pokemon/*.ts"
],
"#trainers/*": ["./data/trainers/*.ts"],
"#types/*": ["./@types/helpers/*.ts", "./@types/*.ts", "./typings/phaser/*.ts"],
"#ui/*": ["./ui/battle-info/*.ts", "./ui/settings/*.ts", "./ui/*.ts"],