From 50a561183724a84faa1e4421918a65266c462774 Mon Sep 17 00:00:00 2001 From: Sirz Benjie <142067137+SirzBenjie@users.noreply.github.com> Date: Mon, 9 Jun 2025 12:19:20 -0500 Subject: [PATCH] Apply kev's suggestions from code review Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> --- src/@types/move-types.ts | 15 +++++++++++++- src/data/moves/apply-attrs.ts | 6 +++--- src/data/moves/move.ts | 38 ++++++++++++++++++---------------- src/data/moves/pokemon-move.ts | 1 - src/enums/field-position.ts | 1 - src/enums/form-change-item.ts | 1 - src/enums/game-modes.ts | 1 - src/enums/hit-result.ts | 1 - src/enums/learn-move-type.ts | 1 - src/enums/move-anims-common.ts | 3 ++- src/enums/move-result.ts | 1 - src/enums/trainer-variant.ts | 1 - 12 files changed, 39 insertions(+), 31 deletions(-) diff --git a/src/@types/move-types.ts b/src/@types/move-types.ts index cb21a469153..7aeb70876d2 100644 --- a/src/@types/move-types.ts +++ b/src/@types/move-types.ts @@ -1,4 +1,12 @@ -import type { AttackMove, StatusMove, SelfStatusMove, MoveAttrConstructorMap, MoveAttr } from "#app/data/moves/move"; +import type { + AttackMove, + StatusMove, + SelfStatusMove, + ChargingAttackMove, + ChargingSelfStatusMove, + MoveAttrConstructorMap, + MoveAttr, +} from "#app/data/moves/move"; export type MoveAttrFilter = (attr: MoveAttr) => boolean; @@ -11,6 +19,9 @@ export type MoveClassMap = { AttackMove: typeof AttackMove; StatusMove: typeof StatusMove; SelfStatusMove: typeof SelfStatusMove; + ChargingAttackMove: typeof ChargingAttackMove; + ChargingSelfStatusMove: typeof ChargingSelfStatusMove; + ChargeMove: typeof ChargingAttackMove | typeof ChargingSelfStatusMove; }; /** @@ -26,3 +37,5 @@ export type MoveAttrMap = { * Union type of all move attribute names as strings. */ export type MoveAttrString = keyof MoveAttrMap; + +export type ChargingMove = ChargingAttackMove | ChargingSelfStatusMove; diff --git a/src/data/moves/apply-attrs.ts b/src/data/moves/apply-attrs.ts index 11e7777355c..98e7b6d791f 100644 --- a/src/data/moves/apply-attrs.ts +++ b/src/data/moves/apply-attrs.ts @@ -2,10 +2,10 @@ * Module holding functions to apply move attributes. * Must not import anything that is not a type. */ -import type { MoveAttrString } from "#app/@types/move-types"; import type Pokemon from "#app/field/pokemon"; -import type { default as Move, ChargingMove, MoveAttr } from "./move"; -import type { MoveAttrFilter } from "#app/@types/move-types"; +import type { default as Move, MoveAttr } from "./move"; +import type { ChargingMove } from "#app/@types/move-types"; +import type { MoveAttrFilter, MoveAttrString } from "#app/@types/move-types"; function applyMoveAttrsInternal( attrFilter: MoveAttrFilter, diff --git a/src/data/moves/move.ts b/src/data/moves/move.ts index 7ad5e25b364..ff963414d4b 100644 --- a/src/data/moves/move.ts +++ b/src/data/moves/move.ts @@ -123,14 +123,14 @@ import { MoveEffectTrigger } from "#enums/MoveEffectTrigger"; import { MultiHitType } from "#enums/MultiHitType"; import { invalidAssistMoves, invalidCopycatMoves, invalidMetronomeMoves, invalidMirrorMoveMoves, invalidSleepTalkMoves } from "./invalid-moves"; import { SelectBiomePhase } from "#app/phases/select-biome-phase"; -import { MoveAttrMap, MoveAttrString, MoveClass, MoveClassMap } from "#app/@types/move-types"; +import { ChargingMove, MoveAttrMap, MoveAttrString, MoveClass, MoveClassMap } from "#app/@types/move-types"; import { applyMoveAttrs } from "./apply-attrs"; import { frenzyMissFunc, getMoveTargets } from "./move-utils"; type MoveConditionFunc = (user: Pokemon, target: Pokemon, move: Move) => boolean; export type UserMoveConditionFunc = (user: Pokemon, move: Move) => boolean; -export default class Move implements Localizable { +export default abstract class Move implements Localizable { public id: MoveId; public name: string; private _type: PokemonType; @@ -153,12 +153,10 @@ export default class Move implements Localizable { /** * Check if the move is of the given subclass without requiring `instanceof`. * - * @param moveSort - The string name of the move to check against + * @param moveKind - The string name of the move to check against * @returns Whether this move is of the provided type. */ - public is(moveSort: K): this is MoveClassMap[K] { - return false; - } + public abstract is(moveKind: K): this is MoveClassMap[K]; constructor(id: MoveId, type: PokemonType, category: MoveCategory, defaultMoveTarget: MoveTarget, power: number, accuracy: number, pp: number, chance: number, priority: number, generation: number) { this.id = id; @@ -978,8 +976,8 @@ export default class Move implements Localizable { } export class AttackMove extends Move { - override is(moveSort: K): this is MoveClassMap[K] { - return moveSort === "AttackMove" || super.is(moveSort); + override is(moveKind: K): this is MoveClassMap[K] { + return moveKind === "AttackMove"; } constructor(id: MoveId, type: PokemonType, category: MoveCategory, power: number, accuracy: number, pp: number, chance: number, priority: number, generation: number) { super(id, type, category, MoveTarget.NEAR_OTHER, power, accuracy, pp, chance, priority, generation); @@ -1031,8 +1029,9 @@ export class StatusMove extends Move { constructor(id: MoveId, type: PokemonType, accuracy: number, pp: number, chance: number, priority: number, generation: number) { super(id, type, MoveCategory.STATUS, MoveTarget.NEAR_OTHER, -1, accuracy, pp, chance, priority, generation); } - override is(moveSort: K): this is MoveClassMap[K] { - return moveSort === "StatusMove" || super.is(moveSort); + + override is(moveKind: K): this is MoveClassMap[K] { + return moveKind === "StatusMove"; } } @@ -1040,14 +1039,15 @@ export class SelfStatusMove extends Move { constructor(id: MoveId, type: PokemonType, accuracy: number, pp: number, chance: number, priority: number, generation: number) { super(id, type, MoveCategory.STATUS, MoveTarget.USER, -1, accuracy, pp, chance, priority, generation); } - override is(moveSort: K): this is MoveClassMap[K] { - return moveSort === "SelfStatusMove" || super.is(moveSort); + + override is(moveKind: K): this is MoveClassMap[K] { + return moveKind === "SelfStatusMove"; } } type SubMove = new (...args: any[]) => Move; -function ChargeMove(Base: TBase) { +function ChargeMove(Base: TBase, nameAppend: string) { return class extends Base { /** The animation to play during the move's charging phase */ public readonly chargeAnim: ChargeAnim = ChargeAnim[`${MoveId[this.id]}_CHARGING`]; @@ -1061,6 +1061,11 @@ function ChargeMove(Base: TBase) { return true; } + override is(moveKind: K): this is MoveClassMap[K] { + // Anything subclassing this is a charge move. + return moveKind === "ChargeMove" || moveKind === nameAppend; + } + /** * Sets the text to be displayed during this move's charging phase. * References to the user Pokemon should be written as "{USER}", and @@ -1127,11 +1132,8 @@ function ChargeMove(Base: TBase) { }; } -export class ChargingAttackMove extends ChargeMove(AttackMove) {} -export class ChargingSelfStatusMove extends ChargeMove(SelfStatusMove) {} - -export type ChargingMove = ChargingAttackMove | ChargingSelfStatusMove; - +export class ChargingAttackMove extends ChargeMove(AttackMove, "ChargingAttackMove") {} +export class ChargingSelfStatusMove extends ChargeMove(SelfStatusMove, "ChargingSelfStatusMove") {} /** * Base class defining all {@linkcode Move} Attributes diff --git a/src/data/moves/pokemon-move.ts b/src/data/moves/pokemon-move.ts index d5256171c4e..da46caa819f 100644 --- a/src/data/moves/pokemon-move.ts +++ b/src/data/moves/pokemon-move.ts @@ -17,7 +17,6 @@ import type Move from "./move"; * @see {@linkcode getPpRatio} - returns the current PP amount / max PP amount. * @see {@linkcode getName} - returns name of {@linkcode Move}. **/ - export class PokemonMove { public moveId: MoveId; public ppUsed: number; diff --git a/src/enums/field-position.ts b/src/enums/field-position.ts index ed9a046f4fd..5b7f9c6c570 100644 --- a/src/enums/field-position.ts +++ b/src/enums/field-position.ts @@ -1,4 +1,3 @@ - export enum FieldPosition { CENTER, LEFT, diff --git a/src/enums/form-change-item.ts b/src/enums/form-change-item.ts index 2d50fab9d00..15620eafd0a 100644 --- a/src/enums/form-change-item.ts +++ b/src/enums/form-change-item.ts @@ -1,4 +1,3 @@ - export enum FormChangeItem { NONE, diff --git a/src/enums/game-modes.ts b/src/enums/game-modes.ts index 57a99799794..837b634621c 100644 --- a/src/enums/game-modes.ts +++ b/src/enums/game-modes.ts @@ -1,4 +1,3 @@ - export enum GameModes { CLASSIC, ENDLESS, diff --git a/src/enums/hit-result.ts b/src/enums/hit-result.ts index 0f930accd17..3e62587dd6c 100644 --- a/src/enums/hit-result.ts +++ b/src/enums/hit-result.ts @@ -1,4 +1,3 @@ - export enum HitResult { EFFECTIVE = 1, SUPER_EFFECTIVE, diff --git a/src/enums/learn-move-type.ts b/src/enums/learn-move-type.ts index 2ce3b1d6675..442639c1bc7 100644 --- a/src/enums/learn-move-type.ts +++ b/src/enums/learn-move-type.ts @@ -1,4 +1,3 @@ - export enum LearnMoveType { /** For learning a move via level-up, evolution, or other non-item-based event */ LEARN_MOVE, diff --git a/src/enums/move-anims-common.ts b/src/enums/move-anims-common.ts index 437b0e62bbe..f21e4c8be4a 100644 --- a/src/enums/move-anims-common.ts +++ b/src/enums/move-anims-common.ts @@ -1,15 +1,16 @@ - export enum AnimFrameTarget { USER, TARGET, GRAPHIC } + export enum AnimFocus { TARGET = 1, USER, USER_TARGET, SCREEN } + export enum AnimBlendType { NORMAL, ADD, diff --git a/src/enums/move-result.ts b/src/enums/move-result.ts index aed92d76ec4..d402f5b1aed 100644 --- a/src/enums/move-result.ts +++ b/src/enums/move-result.ts @@ -1,4 +1,3 @@ - export enum MoveResult { PENDING, SUCCESS, diff --git a/src/enums/trainer-variant.ts b/src/enums/trainer-variant.ts index af8788819f6..cd8d71cc1b9 100644 --- a/src/enums/trainer-variant.ts +++ b/src/enums/trainer-variant.ts @@ -1,4 +1,3 @@ - export enum TrainerVariant { DEFAULT, FEMALE,