Skip to content

Commit

Permalink
Consistently use this.dex in TeamValidator
Browse files Browse the repository at this point in the history
Additionally allows Dex to optionally be provided as a constructor
arg for clients which do not rely on a global Dex object
  • Loading branch information
scheibo committed Aug 30, 2020
1 parent c9fa3fc commit 8744ada
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions sim/team-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ export class TeamValidator {
readonly minSourceGen: number;

readonly toID: (str: any) => ID;
constructor(format: string | Format) {
this.format = Dex.getFormat(format);
this.dex = Dex.forFormat(this.format);
constructor(format: string | Format, dex = Dex) {
this.format = dex.getFormat(format);
this.dex = dex.forFormat(this.format);
this.gen = this.dex.gen;
this.ruleTable = this.dex.getRuleTable(this.format);

Expand Down Expand Up @@ -959,7 +959,7 @@ export class TeamValidator {
let eventSpecies = species;
if (source.charAt(1) === 'S') {
const splitSource = source.substr(source.charAt(2) === 'T' ? 3 : 2).split(' ');
const dex = (this.dex.gen === 1 ? Dex.mod('gen2') : this.dex);
const dex = (this.dex.gen === 1 ? this.dex.mod('gen2') : this.dex);
eventSpecies = dex.getSpecies(splitSource[1]);
const eventLsetData = this.dex.getLearnsetData(eventSpecies.id);
eventData = eventLsetData.eventData?.[parseInt(splitSource[0])];
Expand Down Expand Up @@ -1027,7 +1027,7 @@ export class TeamValidator {
if (!getAll && eggMoves.length <= 1) return true;

// gen 1 eggs come from gen 2 breeding
const dex = this.dex.gen === 1 ? Dex.mod('gen2') : this.dex;
const dex = this.dex.gen === 1 ? this.dex.mod('gen2') : this.dex;
// In Gen 5 and earlier, egg moves can only be inherited from the father
// we'll test each possible father separately
let eggGroups = species.eggGroups;
Expand Down Expand Up @@ -1188,15 +1188,15 @@ export class TeamValidator {
}
} else {
// Memory/Drive/Griseous Orb/Plate/Z-Crystal - Forme mismatch
const baseSpecies = Dex.getSpecies(species.changesFrom);
const baseSpecies = this.dex.getSpecies(species.changesFrom);
problems.push(
`${name} needs to hold ${species.requiredItems.join(' or ')} to be in its ${species.forme} forme.`,
`(It will revert to its ${baseSpecies.baseForme} forme if you remove the item or give it a different item.)`
);
}
}
if (species.requiredMove && !set.moves.includes(toID(species.requiredMove))) {
const baseSpecies = Dex.getSpecies(species.changesFrom);
const baseSpecies = this.dex.getSpecies(species.changesFrom);
problems.push(
`${name} needs to know the move ${species.requiredMove} to be in its ${species.forme} forme.`,
`(It will revert to its ${baseSpecies.baseForme} forme if it forgets the move.)`
Expand Down

5 comments on commit 8744ada

@Zarel
Copy link
Member

@Zarel Zarel commented on 8744ada Sep 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the correct solution here is to import Dex. Do you have a use case for the optional pass-in or can I switch this to importing?

@scheibo
Copy link
Contributor Author

@scheibo scheibo commented on 8744ada Sep 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can certainly import the Dex type as well instead of leaving it global, but I do have a use case for being able to inject the dependency for the implementation: pkmn/ps#3 (comment)

@Zarel
Copy link
Member

@Zarel Zarel commented on 8744ada Sep 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what that achieves that passing the format doesn't achieve.

@Zarel
Copy link
Member

@Zarel Zarel commented on 8744ada Sep 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we do in fact correctly import Dex. I don't understand your problem at all.

@scheibo
Copy link
Contributor Author

@scheibo scheibo commented on 8744ada Sep 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what that achieves that passing the format doesn't achieve.

To be able to use the TeamValidator with a Dex implementation that is not the Dex implementation in this repository.

Please sign in to comment.