Skip to content

Commit

Permalink
Import SV AAA sets
Browse files Browse the repository at this point in the history
  • Loading branch information
thejetou committed Nov 8, 2023
1 parent 64cefd4 commit 3dee008
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions import/src/set-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ interface CalcSet {

const VALIDATORS: {[format: string]: TeamValidator} = {};

// NOTE: https://github.com/pkmn/ps/issues/25
const BROKEN_FORMATS: {[format: string]: { id: ID, name: string, exists: boolean }} = {
'gen9almostanyability': {id: 'gen9almostanyability' as ID, name: '[Gen 9] Almost Any Ability', exists: true},
'gen9lc': {name: '[Gen 9] LC', id: 'gen9lc' as ID, exists: true},
}

function first<T>(v: T[] | T): T {
return Array.isArray(v) ? v[0] : v;
}
Expand Down Expand Up @@ -323,19 +329,16 @@ async function importGen(
const statsIgnore: {[specie: string]: Set<ID>} = {};
for (const [specieName, formats] of Object.entries(dexSets)) {
for (const [formatID, sets] of Object.entries(formats)) {
// NOTE: `Dex.formats.get('gen9lc') crashes so we avoid running it
// Awaiting fix http://github.com/pkmn/ps/issues/25
const format = gen.num === 9 && formatID === 'lc'
? {name: '[Gen 9] LC', id: 'gen9lc', exists: true}
: Dex.formats.get(`gen${gen.num}${formatID}`);
const brokenFormat = BROKEN_FORMATS[`gen${gen.num}${formatID}`];
const format = brokenFormat ?? Dex.formats.get(`gen${gen.num}${formatID}`);
if (!format.exists) {
continue;
}
formatIDs.add(formatID as ID);
for (const [name, set] of Object.entries(sets)) {
const specie = getSpecie(gen, specieName as SpeciesName);
const pset = dexToPset(gen, specie, set);
if (format.id !== 'gen9lc' && !validatePSet(format as Format, pset, 'dex')) continue;
if (!brokenFormat && !validatePSet(format as Format, pset, 'dex')) continue;
const calcSet = psetToCalcSet(gen.num, pset);
if (!calcSets[specieName]) calcSets[specieName] = {};
const setName = `${format.name.slice(format.name.indexOf(']') + 2)} ${name}`;
Expand All @@ -362,9 +365,8 @@ async function importGen(
}
}
for (const formatID of formatIDs) {
const format = gen.num === 9 && formatID === 'lc'
? {name: '[Gen 9] LC', id: 'gen9lc', exists: true}
: Dex.formats.get(`gen${gen.num}${formatID}`);
const brokenFormat = BROKEN_FORMATS[`gen${gen.num}${formatID}`];
const format = brokenFormat ?? Dex.formats.get(`gen${gen.num}${formatID}`);
let stats: DisplayStatistics | false = false;
try {
stats = await fetchStats(format.id as ID);
Expand All @@ -383,7 +385,7 @@ async function importGen(
if (uset.usage.weighted < threshold) continue;
const specie = getSpecie(gen, specieName);
const pset = usageToPset(gen, format.id as ID, specie.name, uset);
if (format.id !== 'gen9lc' && !validatePSet(format as Format, pset, 'stats')) continue;
if (!brokenFormat && !validatePSet(format as Format, pset, 'stats')) continue;
const calcSet = psetToCalcSet(gen.num, pset);
if (!calcSets[specieName]) calcSets[specieName] = {};
const setName = `${format.name.slice(format.name.indexOf(']') + 2)} Showdown Usage`;
Expand Down

0 comments on commit 3dee008

Please sign in to comment.