Apply kev's suggestions from code review

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
This commit is contained in:
Sirz Benjie 2025-06-09 12:19:20 -05:00
parent 5b13d7d9ba
commit 50a5611837
No known key found for this signature in database
GPG Key ID: 4A524B4D196C759E
12 changed files with 39 additions and 31 deletions

View File

@ -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; export type MoveAttrFilter = (attr: MoveAttr) => boolean;
@ -11,6 +19,9 @@ export type MoveClassMap = {
AttackMove: typeof AttackMove; AttackMove: typeof AttackMove;
StatusMove: typeof StatusMove; StatusMove: typeof StatusMove;
SelfStatusMove: typeof SelfStatusMove; 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. * Union type of all move attribute names as strings.
*/ */
export type MoveAttrString = keyof MoveAttrMap; export type MoveAttrString = keyof MoveAttrMap;
export type ChargingMove = ChargingAttackMove | ChargingSelfStatusMove;

View File

@ -2,10 +2,10 @@
* Module holding functions to apply move attributes. * Module holding functions to apply move attributes.
* Must not import anything that is not a type. * 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 Pokemon from "#app/field/pokemon";
import type { default as Move, ChargingMove, MoveAttr } from "./move"; import type { default as Move, MoveAttr } from "./move";
import type { MoveAttrFilter } from "#app/@types/move-types"; import type { ChargingMove } from "#app/@types/move-types";
import type { MoveAttrFilter, MoveAttrString } from "#app/@types/move-types";
function applyMoveAttrsInternal( function applyMoveAttrsInternal(
attrFilter: MoveAttrFilter, attrFilter: MoveAttrFilter,

View File

@ -123,14 +123,14 @@ import { MoveEffectTrigger } from "#enums/MoveEffectTrigger";
import { MultiHitType } from "#enums/MultiHitType"; import { MultiHitType } from "#enums/MultiHitType";
import { invalidAssistMoves, invalidCopycatMoves, invalidMetronomeMoves, invalidMirrorMoveMoves, invalidSleepTalkMoves } from "./invalid-moves"; import { invalidAssistMoves, invalidCopycatMoves, invalidMetronomeMoves, invalidMirrorMoveMoves, invalidSleepTalkMoves } from "./invalid-moves";
import { SelectBiomePhase } from "#app/phases/select-biome-phase"; 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 { applyMoveAttrs } from "./apply-attrs";
import { frenzyMissFunc, getMoveTargets } from "./move-utils"; import { frenzyMissFunc, getMoveTargets } from "./move-utils";
type MoveConditionFunc = (user: Pokemon, target: Pokemon, move: Move) => boolean; type MoveConditionFunc = (user: Pokemon, target: Pokemon, move: Move) => boolean;
export type UserMoveConditionFunc = (user: 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 id: MoveId;
public name: string; public name: string;
private _type: PokemonType; 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`. * 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. * @returns Whether this move is of the provided type.
*/ */
public is<K extends keyof MoveClassMap>(moveSort: K): this is MoveClassMap[K] { public abstract is<K extends keyof MoveClassMap>(moveKind: K): this is MoveClassMap[K];
return false;
}
constructor(id: MoveId, type: PokemonType, category: MoveCategory, defaultMoveTarget: MoveTarget, power: number, accuracy: number, pp: number, chance: number, priority: number, generation: number) { constructor(id: MoveId, type: PokemonType, category: MoveCategory, defaultMoveTarget: MoveTarget, power: number, accuracy: number, pp: number, chance: number, priority: number, generation: number) {
this.id = id; this.id = id;
@ -978,8 +976,8 @@ export default class Move implements Localizable {
} }
export class AttackMove extends Move { export class AttackMove extends Move {
override is<K extends keyof MoveClassMap>(moveSort: K): this is MoveClassMap[K] { override is<K extends keyof MoveClassMap>(moveKind: K): this is MoveClassMap[K] {
return moveSort === "AttackMove" || super.is(moveSort); return moveKind === "AttackMove";
} }
constructor(id: MoveId, type: PokemonType, category: MoveCategory, power: number, accuracy: number, pp: number, chance: number, priority: number, generation: number) { 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); 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) { 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); super(id, type, MoveCategory.STATUS, MoveTarget.NEAR_OTHER, -1, accuracy, pp, chance, priority, generation);
} }
override is<K extends keyof MoveClassMap>(moveSort: K): this is MoveClassMap[K] {
return moveSort === "StatusMove" || super.is(moveSort); override is<K extends keyof MoveClassMap>(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) { 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); super(id, type, MoveCategory.STATUS, MoveTarget.USER, -1, accuracy, pp, chance, priority, generation);
} }
override is<K extends keyof MoveClassMap>(moveSort: K): this is MoveClassMap[K] {
return moveSort === "SelfStatusMove" || super.is(moveSort); override is<K extends keyof MoveClassMap>(moveKind: K): this is MoveClassMap[K] {
return moveKind === "SelfStatusMove";
} }
} }
type SubMove = new (...args: any[]) => Move; type SubMove = new (...args: any[]) => Move;
function ChargeMove<TBase extends SubMove>(Base: TBase) { function ChargeMove<TBase extends SubMove>(Base: TBase, nameAppend: string) {
return class extends Base { return class extends Base {
/** The animation to play during the move's charging phase */ /** The animation to play during the move's charging phase */
public readonly chargeAnim: ChargeAnim = ChargeAnim[`${MoveId[this.id]}_CHARGING`]; public readonly chargeAnim: ChargeAnim = ChargeAnim[`${MoveId[this.id]}_CHARGING`];
@ -1061,6 +1061,11 @@ function ChargeMove<TBase extends SubMove>(Base: TBase) {
return true; return true;
} }
override is<K extends keyof MoveClassMap>(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. * Sets the text to be displayed during this move's charging phase.
* References to the user Pokemon should be written as "{USER}", and * References to the user Pokemon should be written as "{USER}", and
@ -1127,11 +1132,8 @@ function ChargeMove<TBase extends SubMove>(Base: TBase) {
}; };
} }
export class ChargingAttackMove extends ChargeMove(AttackMove) {} export class ChargingAttackMove extends ChargeMove(AttackMove, "ChargingAttackMove") {}
export class ChargingSelfStatusMove extends ChargeMove(SelfStatusMove) {} export class ChargingSelfStatusMove extends ChargeMove(SelfStatusMove, "ChargingSelfStatusMove") {}
export type ChargingMove = ChargingAttackMove | ChargingSelfStatusMove;
/** /**
* Base class defining all {@linkcode Move} Attributes * Base class defining all {@linkcode Move} Attributes

View File

@ -17,7 +17,6 @@ import type Move from "./move";
* @see {@linkcode getPpRatio} - returns the current PP amount / max PP amount. * @see {@linkcode getPpRatio} - returns the current PP amount / max PP amount.
* @see {@linkcode getName} - returns name of {@linkcode Move}. * @see {@linkcode getName} - returns name of {@linkcode Move}.
**/ **/
export class PokemonMove { export class PokemonMove {
public moveId: MoveId; public moveId: MoveId;
public ppUsed: number; public ppUsed: number;

View File

@ -1,4 +1,3 @@
export enum FieldPosition { export enum FieldPosition {
CENTER, CENTER,
LEFT, LEFT,

View File

@ -1,4 +1,3 @@
export enum FormChangeItem { export enum FormChangeItem {
NONE, NONE,

View File

@ -1,4 +1,3 @@
export enum GameModes { export enum GameModes {
CLASSIC, CLASSIC,
ENDLESS, ENDLESS,

View File

@ -1,4 +1,3 @@
export enum HitResult { export enum HitResult {
EFFECTIVE = 1, EFFECTIVE = 1,
SUPER_EFFECTIVE, SUPER_EFFECTIVE,

View File

@ -1,4 +1,3 @@
export enum LearnMoveType { export enum LearnMoveType {
/** For learning a move via level-up, evolution, or other non-item-based event */ /** For learning a move via level-up, evolution, or other non-item-based event */
LEARN_MOVE, LEARN_MOVE,

View File

@ -1,15 +1,16 @@
export enum AnimFrameTarget { export enum AnimFrameTarget {
USER, USER,
TARGET, TARGET,
GRAPHIC GRAPHIC
} }
export enum AnimFocus { export enum AnimFocus {
TARGET = 1, TARGET = 1,
USER, USER,
USER_TARGET, USER_TARGET,
SCREEN SCREEN
} }
export enum AnimBlendType { export enum AnimBlendType {
NORMAL, NORMAL,
ADD, ADD,

View File

@ -1,4 +1,3 @@
export enum MoveResult { export enum MoveResult {
PENDING, PENDING,
SUCCESS, SUCCESS,

View File

@ -1,4 +1,3 @@
export enum TrainerVariant { export enum TrainerVariant {
DEFAULT, DEFAULT,
FEMALE, FEMALE,