mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-08-09 00:49:27 +02:00
[WIP]
This commit is contained in:
parent
5321f00636
commit
2d3002ce2d
@ -126,6 +126,11 @@ export type BattlerTagTypeData = Parameters<
|
|||||||
}]["loadTag"]
|
}]["loadTag"]
|
||||||
>[0];
|
>[0];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subset of {@linkcode BattlerTagType}s whose associated `BattlerTag` adds a serializable `moveId` field
|
||||||
|
*/
|
||||||
|
export type BattlerTagTypeWithMoveId = BattlerTagType.DISABLED | BattlerTagType.GORILLA_TACTICS | BattlerTagType.ENCORE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dummy, typescript-only declaration to ensure that
|
* Dummy, typescript-only declaration to ensure that
|
||||||
* {@linkcode BattlerTagTypeMap} has an entry for all `BattlerTagType`s.
|
* {@linkcode BattlerTagTypeMap} has an entry for all `BattlerTagType`s.
|
||||||
|
48
src/@types/helpers/schema-helpers.ts
Normal file
48
src/@types/helpers/schema-helpers.ts
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import type { ObjectValues } from "#types/type-helpers";
|
||||||
|
import type { z } from "zod";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fake a discriminated union type for Zod Schemas.
|
||||||
|
* In essence, allows a particular field that is really a union
|
||||||
|
* to coerce to a zod type that emits a UNION of schemas.
|
||||||
|
*
|
||||||
|
* @typeParam Choices - The set of enum values that the union can take.
|
||||||
|
* @typeParam BaseZodSchema - The base zod schema to extend.
|
||||||
|
* @typeParam FieldName - The name of the field that acts as the discriminator. **Must be a string literal**
|
||||||
|
*
|
||||||
|
* @remarks
|
||||||
|
* There are times where we want to allow a field in the zod schema to take one of
|
||||||
|
* a set of literal values, but we want to treat it as a discriminated union.
|
||||||
|
*
|
||||||
|
* For instance, if we have a zod schema like this:
|
||||||
|
* z.object({
|
||||||
|
* field: z.literal(["Foo", "Bar"])
|
||||||
|
* })
|
||||||
|
*
|
||||||
|
* then pass it into some function which expects field to be either "Foo" or "Bar",
|
||||||
|
* then it would not work. This is because
|
||||||
|
* { field: "Foo" | "Bar" }
|
||||||
|
* would not be considered compatible with
|
||||||
|
* { field: "Foo" } | { field: "Bar"}
|
||||||
|
*
|
||||||
|
* While it is possible to make use of Zod's discriminated union, this
|
||||||
|
* ends up defining way too many additional types, which is not readable,
|
||||||
|
* and is substantially harder to maintain.
|
||||||
|
*
|
||||||
|
* Instead, this type helper can be used as a type assertion on the actual zod schema.
|
||||||
|
* Note that it *does* require defining a base schema separately, which does not isnclude
|
||||||
|
* the discriminator field.
|
||||||
|
*
|
||||||
|
* This is a hacky way to get around typescript's limitations.
|
||||||
|
*/
|
||||||
|
export type DiscriminatedUnionFake<
|
||||||
|
Choices extends string | number,
|
||||||
|
BaseZodSchema extends Record<string, z.ZodType>,
|
||||||
|
FieldName extends string,
|
||||||
|
> = ObjectValues<{
|
||||||
|
[Choice in Choices]: z.ZodObject<
|
||||||
|
BaseZodSchema & {
|
||||||
|
[F in FieldName]: z.ZodLiteral<Choice>;
|
||||||
|
}
|
||||||
|
>;
|
||||||
|
}>;
|
@ -44,12 +44,20 @@ export type InferKeys<O extends object, V extends ObjectValues<O>> = {
|
|||||||
}[keyof O];
|
}[keyof O];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility type to obtain the values of a given object. \
|
* Type helper to construct a union type of the type of each field in an object.
|
||||||
* Functions similar to `keyof E`, except producing the values instead of the keys.
|
*
|
||||||
|
* @typeParam T - The type of the object to extract values from.
|
||||||
|
*
|
||||||
* @remarks
|
* @remarks
|
||||||
* This can be used to convert an `enum` interface produced by `typeof Enum` into the union type representing its members.
|
* Can be used to convert an `enum` interface produced by `typeof Enum` into the union type representing its members.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```ts
|
||||||
|
* type oneThruThree = ObjectValues<{ a: 1, b: 2, c: 3 }>
|
||||||
|
* // ^? 1 | 2 | 3
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
export type ObjectValues<E extends object> = E[keyof E];
|
export type ObjectValues<T extends object> = T[keyof T];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type helper that matches any `Function` type.
|
* Type helper that matches any `Function` type.
|
||||||
@ -64,6 +72,7 @@ export type AnyFn = (...args: any[]) => any;
|
|||||||
* Useful to produce a type that is roughly the same as the type of `{... obj}`, where `obj` is an instance of `T`.
|
* Useful to produce a type that is roughly the same as the type of `{... obj}`, where `obj` is an instance of `T`.
|
||||||
* A couple of differences:
|
* A couple of differences:
|
||||||
* - Private and protected properties are not included.
|
* - Private and protected properties are not included.
|
||||||
|
* - Accessors with getters *are* included
|
||||||
* - Nested properties are not recursively extracted. For this, use {@linkcode NonFunctionPropertiesRecursive}
|
* - Nested properties are not recursively extracted. For this, use {@linkcode NonFunctionPropertiesRecursive}
|
||||||
*/
|
*/
|
||||||
export type NonFunctionProperties<T> = {
|
export type NonFunctionProperties<T> = {
|
||||||
|
@ -0,0 +1,111 @@
|
|||||||
|
// biome-ignore-start lint/correctness/noUnusedImports: used in tsdoc comment
|
||||||
|
import { type ArenaTrapTag, loadArenaTag, type SerializableArenaTag } from "#data/arena-tag";
|
||||||
|
import type { ArenaTagSide } from "#enums/arena-tag-side";
|
||||||
|
import { ArenaTagType } from "#enums/arena-tag-type";
|
||||||
|
// biome-ignore-end lint/correctness/noUnusedImports: end
|
||||||
|
|
||||||
|
import { Z$NonNegativeInt, Z$PositiveInt } from "#system/schemas/common";
|
||||||
|
import type { ArenaTrapTagType, SerializableArenaTagType } from "#types/arena-tags";
|
||||||
|
import type { DiscriminatedUnionFake } from "#types/schema-helpers";
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zod schema for {@linkcode ArenaTagSide} as of version 1.10
|
||||||
|
*
|
||||||
|
* @remarks
|
||||||
|
* - `0`: BOTH
|
||||||
|
* - `1`: PLAYER
|
||||||
|
* - `2`: ENEMY
|
||||||
|
*/
|
||||||
|
export const Z$ArenaTagSide = z.literal([0, 1, 2]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The base shape of an arena tag, consisting of all of the fields other than
|
||||||
|
* Zod schema for {@linkcode SerializableArenaTag} as of version 1.10
|
||||||
|
*/
|
||||||
|
const Z$BaseArenaTag = z.object({
|
||||||
|
turnCount: z.int(),
|
||||||
|
sourceMove: Z$NonNegativeInt.optional().catch(undefined),
|
||||||
|
sourceId: z.int().or(z.undefined()).catch(undefined),
|
||||||
|
side: Z$ArenaTagSide,
|
||||||
|
});
|
||||||
|
|
||||||
|
// #region typescript-hackery to extract out the proper zod schema type
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Arena tag type that has no extra additional fields.
|
||||||
|
*/
|
||||||
|
type BasicArenaTag =
|
||||||
|
| Exclude<SerializableArenaTagType, ArenaTagType.NEUTRALIZING_GAS | ArenaTrapTagType>
|
||||||
|
| ArenaTagType.NONE;
|
||||||
|
|
||||||
|
//#endregion: typescript-hackery
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zod enum for arena tags with no additional properties.
|
||||||
|
* If a new ArenaTagType that has no additional properties is added,
|
||||||
|
* this MUST be updated to include it.
|
||||||
|
*/
|
||||||
|
const Z$BaseArenaTagEnum = z.literal([
|
||||||
|
ArenaTagType.NONE,
|
||||||
|
ArenaTagType.MUD_SPORT,
|
||||||
|
ArenaTagType.WATER_SPORT,
|
||||||
|
ArenaTagType.MIST,
|
||||||
|
ArenaTagType.TRICK_ROOM,
|
||||||
|
ArenaTagType.GRAVITY,
|
||||||
|
ArenaTagType.REFLECT,
|
||||||
|
ArenaTagType.LIGHT_SCREEN,
|
||||||
|
ArenaTagType.AURORA_VEIL,
|
||||||
|
ArenaTagType.TAILWIND,
|
||||||
|
ArenaTagType.HAPPY_HOUR,
|
||||||
|
ArenaTagType.SAFEGUARD,
|
||||||
|
ArenaTagType.NO_CRIT,
|
||||||
|
ArenaTagType.FIRE_GRASS_PLEDGE,
|
||||||
|
ArenaTagType.WATER_FIRE_PLEDGE,
|
||||||
|
ArenaTagType.GRASS_WATER_PLEDGE,
|
||||||
|
ArenaTagType.FAIRY_LOCK,
|
||||||
|
]) satisfies z.ZodLiteral<BasicArenaTag | ArenaTagType.NONE>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zod schema for the subset of {@linkcode ArenaTagType}s
|
||||||
|
* that add no additional serializable fields.
|
||||||
|
*/
|
||||||
|
const Z$PlainArenaTag = z.object({
|
||||||
|
...Z$BaseArenaTag.shape,
|
||||||
|
tagType: Z$BaseArenaTagEnum,
|
||||||
|
}) as DiscriminatedUnionFake<BasicArenaTag, typeof Z$BaseArenaTag.shape, "tagType">;
|
||||||
|
|
||||||
|
const Z$BaseTrapTag = /** __@PURE__ */ z.object({
|
||||||
|
...Z$BaseArenaTag.shape,
|
||||||
|
layers: z.int().min(1).max(3).catch(1),
|
||||||
|
maxLayers: z.int().min(1).max(3),
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zod schema for {@linkcode ArenaTrapTag} as of version 1.10
|
||||||
|
*/
|
||||||
|
const Z$ArenaTrapTag = /** __@PURE__ */ z.object({
|
||||||
|
...Z$BaseTrapTag.shape,
|
||||||
|
tagType: z.literal([
|
||||||
|
ArenaTagType.STICKY_WEB,
|
||||||
|
ArenaTagType.SPIKES,
|
||||||
|
ArenaTagType.TOXIC_SPIKES,
|
||||||
|
ArenaTagType.STEALTH_ROCK,
|
||||||
|
ArenaTagType.IMPRISON,
|
||||||
|
] satisfies ArenaTrapTagType[]),
|
||||||
|
}) as DiscriminatedUnionFake<ArenaTrapTagType, typeof Z$BaseTrapTag.shape, "tagType">;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zod schema for {@linkcode ArenaTagType.NEUTRALIZING_GAS} as of version 1.10
|
||||||
|
*/
|
||||||
|
const Z$SuppressAbilitiesTag = /** __@PURE__ */ z.object({
|
||||||
|
...Z$BaseArenaTag.shape,
|
||||||
|
tagType: z.literal(ArenaTagType.NEUTRALIZING_GAS),
|
||||||
|
sourceCount: Z$PositiveInt,
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zod schema for {@linkcode SerializableArenaTag}s as of version 1.10,
|
||||||
|
* also permitting "NoneTag".
|
||||||
|
*/
|
||||||
|
export const Z$ArenaTag = z.discriminatedUnion("tagType", [Z$ArenaTrapTag, Z$SuppressAbilitiesTag, Z$PlainArenaTag]);
|
@ -1,5 +1,13 @@
|
|||||||
|
import { BattlerTagType } from "#enums/battler-tag-type";
|
||||||
import { Z$NonNegativeInt, Z$PositiveInt } from "#system/schemas/common";
|
import { Z$NonNegativeInt, Z$PositiveInt } from "#system/schemas/common";
|
||||||
import { Z$BattlerIndex } from "#system/schemas/pokemon/battler-index";
|
import { Z$BattlerIndex } from "#system/schemas/pokemon/battler-index";
|
||||||
|
import { Z$Stat } from "#system/schemas/pokemon/pokemon-stats";
|
||||||
|
import type {
|
||||||
|
BattlerTagTypeWithMoveId,
|
||||||
|
HighestStatBoostTagType,
|
||||||
|
SerializableBattlerTagType,
|
||||||
|
} from "#types/battler-tags";
|
||||||
|
import type { DiscriminatedUnionFake } from "#types/schema-helpers";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -7,107 +15,89 @@ Schemas for battler tags are a bit more cumbersome,
|
|||||||
as we need to have schemas for each subclass that has a different shape.
|
as we need to have schemas for each subclass that has a different shape.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
type BasicBattlerTag = Exclude<SerializableBattlerTagType, BattlerTagTypeWithMoveId | HighestStatBoostTagType>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Zod schema for the {@linkcode BattlerTagType} enum as of version 1.10
|
* Zod enum of {@linkcode BattlerTagType}s whose associated `BattlerTag` adds no
|
||||||
|
* additional fields that are serialized.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
const Z$BattlerTagType = z.literal([
|
const Z$BaseBattlerTags = /** @__PURE__ */ z.literal([
|
||||||
"NONE",
|
BattlerTagType.RECHARGING,
|
||||||
"RECHARGING",
|
BattlerTagType.CONFUSED,
|
||||||
"FLINCHED",
|
BattlerTagType.INFATUATED,
|
||||||
"INTERRUPTED",
|
BattlerTagType.SEEDED,
|
||||||
"CONFUSED",
|
BattlerTagType.NIGHTMARE,
|
||||||
"INFATUATED",
|
BattlerTagType.FRENZY,
|
||||||
"SEEDED",
|
BattlerTagType.CHARGING,
|
||||||
"NIGHTMARE",
|
BattlerTagType.ENCORE,
|
||||||
"FRENZY",
|
BattlerTagType.INGRAIN,
|
||||||
"CHARGING",
|
BattlerTagType.OCTOLOCK,
|
||||||
"ENCORE",
|
BattlerTagType.AQUA_RING,
|
||||||
"HELPING_HAND",
|
BattlerTagType.DROWSY,
|
||||||
"INGRAIN",
|
BattlerTagType.TRAPPED,
|
||||||
"OCTOLOCK",
|
BattlerTagType.BIND,
|
||||||
"AQUA_RING",
|
BattlerTagType.WRAP,
|
||||||
"DROWSY",
|
BattlerTagType.FIRE_SPIN,
|
||||||
"TRAPPED",
|
BattlerTagType.WHIRLPOOL,
|
||||||
"BIND",
|
BattlerTagType.CLAMP,
|
||||||
"WRAP",
|
BattlerTagType.SAND_TOMB,
|
||||||
"FIRE_SPIN",
|
BattlerTagType.MAGMA_STORM,
|
||||||
"WHIRLPOOL",
|
BattlerTagType.SNAP_TRAP,
|
||||||
"CLAMP",
|
BattlerTagType.THUNDER_CAGE,
|
||||||
"SAND_TOMB",
|
BattlerTagType.INFESTATION,
|
||||||
"MAGMA_STORM",
|
BattlerTagType.STURDY,
|
||||||
"SNAP_TRAP",
|
BattlerTagType.PERISH_SONG,
|
||||||
"THUNDER_CAGE",
|
BattlerTagType.TRUANT,
|
||||||
"INFESTATION",
|
BattlerTagType.SLOW_START,
|
||||||
"PROTECTED",
|
BattlerTagType.PROTOSYNTHESIS,
|
||||||
"SPIKY_SHIELD",
|
BattlerTagType.QUARK_DRIVE,
|
||||||
"KINGS_SHIELD",
|
BattlerTagType.FLYING,
|
||||||
"OBSTRUCT",
|
BattlerTagType.UNDERGROUND,
|
||||||
"SILK_TRAP",
|
BattlerTagType.UNDERWATER,
|
||||||
"BANEFUL_BUNKER",
|
BattlerTagType.HIDDEN,
|
||||||
"BURNING_BULWARK",
|
BattlerTagType.FIRE_BOOST,
|
||||||
"ENDURING",
|
BattlerTagType.CRIT_BOOST,
|
||||||
"STURDY",
|
BattlerTagType.ALWAYS_CRIT,
|
||||||
"PERISH_SONG",
|
BattlerTagType.IGNORE_ACCURACY,
|
||||||
"TRUANT",
|
BattlerTagType.BYPASS_SLEEP,
|
||||||
"SLOW_START",
|
BattlerTagType.IGNORE_FLYING,
|
||||||
"PROTOSYNTHESIS",
|
BattlerTagType.SALT_CURED,
|
||||||
"QUARK_DRIVE",
|
BattlerTagType.CURSED,
|
||||||
"FLYING",
|
BattlerTagType.CHARGED,
|
||||||
"UNDERGROUND",
|
BattlerTagType.FLOATING,
|
||||||
"UNDERWATER",
|
BattlerTagType.MINIMIZED,
|
||||||
"HIDDEN",
|
BattlerTagType.DESTINY_BOND,
|
||||||
"FIRE_BOOST",
|
BattlerTagType.ICE_FACE,
|
||||||
"CRIT_BOOST",
|
BattlerTagType.DISGUISE,
|
||||||
"ALWAYS_CRIT",
|
BattlerTagType.STOCKPILING,
|
||||||
"IGNORE_ACCURACY",
|
BattlerTagType.RECEIVE_DOUBLE_DAMAGE,
|
||||||
"BYPASS_SLEEP",
|
BattlerTagType.ALWAYS_GET_HIT,
|
||||||
"IGNORE_FLYING",
|
BattlerTagType.DISABLED,
|
||||||
"SALT_CURED",
|
BattlerTagType.SUBSTITUTE,
|
||||||
"CURSED",
|
BattlerTagType.IGNORE_GHOST,
|
||||||
"CHARGED",
|
BattlerTagType.IGNORE_DARK,
|
||||||
"ROOSTED",
|
BattlerTagType.GULP_MISSILE_ARROKUDA,
|
||||||
"FLOATING",
|
BattlerTagType.GULP_MISSILE_PIKACHU,
|
||||||
"MINIMIZED",
|
BattlerTagType.DRAGON_CHEER,
|
||||||
"DESTINY_BOND",
|
BattlerTagType.NO_RETREAT,
|
||||||
"CENTER_OF_ATTENTION",
|
BattlerTagType.GORILLA_TACTICS,
|
||||||
"ICE_FACE",
|
BattlerTagType.UNBURDEN,
|
||||||
"DISGUISE",
|
BattlerTagType.THROAT_CHOPPED,
|
||||||
"STOCKPILING",
|
BattlerTagType.TAR_SHOT,
|
||||||
"RECEIVE_DOUBLE_DAMAGE",
|
BattlerTagType.BURNED_UP,
|
||||||
"ALWAYS_GET_HIT",
|
BattlerTagType.DOUBLE_SHOCKED,
|
||||||
"DISABLED",
|
BattlerTagType.AUTOTOMIZED,
|
||||||
"SUBSTITUTE",
|
BattlerTagType.POWER_TRICK,
|
||||||
"IGNORE_GHOST",
|
BattlerTagType.HEAL_BLOCK,
|
||||||
"IGNORE_DARK",
|
BattlerTagType.TORMENT,
|
||||||
"GULP_MISSILE_ARROKUDA",
|
BattlerTagType.TAUNT,
|
||||||
"GULP_MISSILE_PIKACHU",
|
BattlerTagType.IMPRISON,
|
||||||
"BEAK_BLAST_CHARGING",
|
BattlerTagType.SYRUP_BOMB,
|
||||||
"SHELL_TRAP",
|
BattlerTagType.TELEKINESIS,
|
||||||
"DRAGON_CHEER",
|
BattlerTagType.COMMANDED,
|
||||||
"NO_RETREAT",
|
BattlerTagType.GRUDGE,
|
||||||
"GORILLA_TACTICS",
|
] satisfies SerializableBattlerTagType[]);
|
||||||
"UNBURDEN",
|
|
||||||
"THROAT_CHOPPED",
|
|
||||||
"TAR_SHOT",
|
|
||||||
"BURNED_UP",
|
|
||||||
"DOUBLE_SHOCKED",
|
|
||||||
"AUTOTOMIZED",
|
|
||||||
"MYSTERY_ENCOUNTER_POST_SUMMON",
|
|
||||||
"POWER_TRICK",
|
|
||||||
"HEAL_BLOCK",
|
|
||||||
"TORMENT",
|
|
||||||
"TAUNT",
|
|
||||||
"IMPRISON",
|
|
||||||
"SYRUP_BOMB",
|
|
||||||
"ELECTRIFIED",
|
|
||||||
"TELEKINESIS",
|
|
||||||
"COMMANDED",
|
|
||||||
"GRUDGE",
|
|
||||||
"PSYCHO_SHIFT",
|
|
||||||
"ENDURE_TOKEN",
|
|
||||||
"POWDER",
|
|
||||||
"MAGIC_COAT",
|
|
||||||
]);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Zod schema for {@linkcode BattlerTagLapseType} as of version 1.10
|
* Zod schema for {@linkcode BattlerTagLapseType} as of version 1.10
|
||||||
@ -122,21 +112,72 @@ const Z$BattlerTagType = z.literal([
|
|||||||
* - `7`: After Hit
|
* - `7`: After Hit
|
||||||
* - `8`: Custom
|
* - `8`: Custom
|
||||||
*/
|
*/
|
||||||
const Z$BattlerTagLapseType = z.literal([0, 1, 2, 3, 4, 5, 6, 7, 8]);
|
const Z$BattlerTagLapseType = /** @__PURE__ */ z.literal([0, 1, 2, 3, 4, 5, 6, 7, 8]);
|
||||||
|
|
||||||
// DamagingTrapTag may have a `commonAnim` field, though it's always instantiated.
|
const Z$BaseBattlerTag = /** @__PURE__ */ z.object({
|
||||||
const Z$BattlerTag = z.object({
|
|
||||||
tagType: Z$BattlerTagType,
|
|
||||||
lapseTypes: z.array(Z$BattlerTagLapseType),
|
|
||||||
turnCount: Z$PositiveInt,
|
turnCount: Z$PositiveInt,
|
||||||
// Source move can be `none` for tags not applied by move, so allow `0` here.
|
// Source move can be `none` for tags not applied by move, so allow `0` here.
|
||||||
sourceMove: Z$NonNegativeInt,
|
sourceMove: Z$NonNegativeInt.optional().catch(undefined),
|
||||||
sourceId: z.int().optional().catch(undefined),
|
sourceId: z.int().optional().catch(undefined),
|
||||||
isBatonPassable: z.boolean(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export const Z$SeedTag = z.object({
|
const Z$BaseTagWithMoveId = z.object({
|
||||||
...Z$BattlerTag.shape,
|
...Z$BaseBattlerTag.shape,
|
||||||
seedType: z.literal("SEEDED"),
|
moveId: Z$PositiveInt,
|
||||||
|
});
|
||||||
|
|
||||||
|
/** Subset of battler tags that have a moveID field */
|
||||||
|
const Z$TagWithMoveId = /** @__PURE__ */ z.object({
|
||||||
|
...Z$BaseTagWithMoveId.shape,
|
||||||
|
tagType: z.literal([BattlerTagType.DISABLED, BattlerTagType.GORILLA_TACTICS, BattlerTagType.ENCORE]),
|
||||||
|
moveId: Z$PositiveInt,
|
||||||
|
}) as DiscriminatedUnionFake<
|
||||||
|
BattlerTagType.DISABLED | BattlerTagType.GORILLA_TACTICS | BattlerTagType.ENCORE,
|
||||||
|
typeof Z$TagWithMoveId.shape,
|
||||||
|
"tagType"
|
||||||
|
>;
|
||||||
|
|
||||||
|
const Z$SeedTag = /** @__PURE__ */ z.object({
|
||||||
|
...Z$BaseBattlerTag.shape,
|
||||||
|
tagType: z.literal(BattlerTagType.SEEDED),
|
||||||
sourceIndex: Z$BattlerIndex,
|
sourceIndex: Z$BattlerIndex,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const Z$BaseHighestStatBoostTag = /** @__PURE__ */ z.object({
|
||||||
|
...Z$BaseBattlerTag.shape,
|
||||||
|
stat: Z$Stat,
|
||||||
|
multiplier: z.number(),
|
||||||
|
});
|
||||||
|
|
||||||
|
const Z$HighestStatBoostTag = /** @__PURE__ */ z.object({
|
||||||
|
...Z$BaseHighestStatBoostTag.shape,
|
||||||
|
tagType: z.literal([BattlerTagType.QUARK_DRIVE, BattlerTagType.PROTOSYNTHESIS] satisfies HighestStatBoostTagType[]),
|
||||||
|
}) as DiscriminatedUnionFake<HighestStatBoostTagType, typeof Z$HighestStatBoostTag.shape, "tagType">;
|
||||||
|
|
||||||
|
const Z$CommandedTag = /** @__PURE__ */ z.object({
|
||||||
|
...Z$BaseBattlerTag.shape,
|
||||||
|
tagType: z.literal(BattlerTagType.COMMANDED),
|
||||||
|
tatsugiriFormKey: z.string().catch("curly"),
|
||||||
|
});
|
||||||
|
|
||||||
|
const Z$StockpilingTag = /** @__PURE__ */ z.object({
|
||||||
|
...Z$BaseBattlerTag.shape,
|
||||||
|
tagType: z.literal(BattlerTagType.STOCKPILING),
|
||||||
|
stockpiledCount: Z$PositiveInt.catch(1),
|
||||||
|
statChangeCounts: z.object({
|
||||||
|
[2]: z.int().min(-6).max(6).catch(0), // Defense
|
||||||
|
[4]: z.int().min(-6).max(6).catch(0), // Special Defense
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const Z$AutotomizedTag = /** @__PURE__ */ z.object({
|
||||||
|
...Z$BaseBattlerTag.shape,
|
||||||
|
tagType: z.literal(BattlerTagType.AUTOTOMIZED),
|
||||||
|
autotomizeCount: Z$PositiveInt.catch(1),
|
||||||
|
});
|
||||||
|
|
||||||
|
const Z$SubstituteTag = /** @__PURE__ */ z.object({
|
||||||
|
...Z$BaseBattlerTag.shape,
|
||||||
|
tagType: z.literal(BattlerTagType.SUBSTITUTE),
|
||||||
|
hp: Z$PositiveInt,
|
||||||
|
});
|
||||||
|
@ -1,6 +1,23 @@
|
|||||||
|
// biome-ignore lint/correctness/noUnusedImports: Used in a tsdoc comment
|
||||||
|
import type { Stat } from "#enums/stat";
|
||||||
import { Z$PositiveInt } from "#schemas/common";
|
import { Z$PositiveInt } from "#schemas/common";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schema for {@linkcode Stat}, as of version 1.10
|
||||||
|
*
|
||||||
|
* @remarks
|
||||||
|
* - `0`: Hp
|
||||||
|
* - `1`: Attack
|
||||||
|
* - `2`: Defense
|
||||||
|
* - `3`: Special Attack
|
||||||
|
* - `4`: Special Defense
|
||||||
|
* - `5`: Speed
|
||||||
|
* - `6`: Accuracy
|
||||||
|
* - `7`: Evasion
|
||||||
|
*/
|
||||||
|
export const Z$Stat = /** @__PURE__ */ z.literal([0, 1, 2, 3, 4, 5, 6, 7]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schema for a Pokémon's Individual Values (IVs), as of version 1.10
|
* Schema for a Pokémon's Individual Values (IVs), as of version 1.10
|
||||||
*
|
*
|
||||||
@ -8,7 +25,11 @@ 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 Z$IV = z.int().min(0).max(31).catch(15);
|
export const Z$IV = /** @__PURE__ */ 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,7 +37,9 @@ export const Z$IV = 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 Z$IVSet = z.tuple([Z$IV, Z$IV, Z$IV, Z$IV, Z$IV, Z$IV]).catch([15, 15, 15, 15, 15, 15]);
|
export const Z$IVSet = /** @__PURE__ */ z
|
||||||
|
.tuple([Z$IV, Z$IV, Z$IV, Z$IV, Z$IV, Z$IV])
|
||||||
|
.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
|
||||||
@ -27,7 +50,7 @@ export const Z$IVSet = z.tuple([Z$IV, Z$IV, Z$IV, Z$IV, Z$IV, Z$IV]).catch([15,
|
|||||||
* - [4]: Special Defense,
|
* - [4]: Special Defense,
|
||||||
* - [5]: Speed
|
* - [5]: Speed
|
||||||
*/
|
*/
|
||||||
export const Z$StatSet = z.tuple([
|
export const Z$StatSet = /** @__PURE__ */ z.tuple([
|
||||||
Z$PositiveInt, // HP
|
Z$PositiveInt, // HP
|
||||||
Z$PositiveInt, // Attack
|
Z$PositiveInt, // Attack
|
||||||
Z$PositiveInt, // Defense
|
Z$PositiveInt, // Defense
|
||||||
|
Loading…
Reference in New Issue
Block a user