Skip to content

Commit

Permalink
Sort sets via 'rankings'
Browse files Browse the repository at this point in the history
  • Loading branch information
thejetou committed Nov 20, 2023
1 parent 92bf20a commit 0408aa1
Show file tree
Hide file tree
Showing 10 changed files with 3,933 additions and 3,902 deletions.
44 changes: 37 additions & 7 deletions import/src/set-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ interface CalcSet {
}

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

// These formats don't exist in @pkmn/sim so we make them bypass
// the validator which is the only area that needs the Format object
const UNSUPPORTED: {[format: string]: string} = {
Expand All @@ -62,13 +61,37 @@ const UNSUPPORTED: {[format: string]: string} = {
'gen9lc': '[Gen 9] LC',
'gen9vgc2023regulatione': '[Gen 9] VGC 2023 Regulation E',
};

const SHORT_STAT_FORM: {[stat: string]: keyof CalcStatsTable} =
{'hp': 'hp', 'atk': 'at', 'def': 'df', 'spa': 'sa', 'spd': 'sd', 'spe': 'sp'};

const USELESS_NATURES = ['Bashful', 'Docile', 'Hardy', 'Quirky', 'Serious'];

const CROWNED = {'Zacian-Crowned': 'Behemoth Blade', 'Zamazenta-Crowned': 'Behemoth Bash'};
// These 'rankings' are pulled completely out of my ass
const TIER_RANKINGS: {[tier: string]: number} = {
ou: 0,
ubers: 1,
uu: 2,
ru: 3,
nu: 4,
pu: 5,
lc: 6,
doublesou: 7,
// VGC/BSS
nintendo: 8,
monotype: 9,
nationaldex: 10,
nationaldexubers: 11,
nationaldexuu: 12,
nationaldexru: 13,
nationaldexmonotype: 14,
anythinggoes: 15,
'1v1': 16,
balancedhackmons: 17,
purehackmons: 18,
almostanyability: 19,
zu: 20,
cap: 21,
tradebacksou: 22,
};

function first<T>(v: T[] | T): T {
return Array.isArray(v) ? v[0] : v;
Expand All @@ -93,6 +116,12 @@ function top(weighted: {[key: string]: number}, n = 1): string | string[] | unde
.map(x => x[0]);
}

function getTierRanking(tier: string): number {
const isNintendo =
tier.startsWith('vgc') || tier.startsWith('battlestadium') || tier.startsWith('battlespot');
return TIER_RANKINGS[isNintendo ? 'nintendo' : tier] ?? 100;
}

function toCalcStatsTable(
stats: Partial<StatsTable>, ignoreVal: number
): Partial<CalcStatsTable> | undefined {
Expand Down Expand Up @@ -407,7 +436,6 @@ async function fetchStats(formatID: ID): Promise<DisplayStatistics | false> {
if (resp.status === 404) return false;
return resp.json();
}

async function importGen(
gen: Generation
): Promise<{ [specie: string]: { [name: string]: CalcSet } }> {
Expand All @@ -416,7 +444,8 @@ async function importGen(
const formatIDs = new Set<ID>();
const statsIgnore: {[specie: string]: Set<ID>} = {};
for (const [specieName, formats] of Object.entries(dexSets)) {
for (let [formatID, sets] of Object.entries(formats) as unknown as [ID, DexSet][]) {
for (let [formatID, sets] of Object.entries(formats).sort((a, b) =>
getTierRanking(a[0]) - getTierRanking(b[0])) as unknown as [ID, DexSet][]) {
formatID = `gen${gen.num}${formatID}` as ID;
const psFormat = toPSFormat(formatID);
const format = UNSUPPORTED[psFormat] ? null : Dex.formats.get(psFormat);
Expand Down Expand Up @@ -452,7 +481,8 @@ async function importGen(
}
}
}
for (const formatID of formatIDs) {
for (const formatID of [...formatIDs].sort((a, b) =>
getTierRanking(a[0]) - getTierRanking(b[0]))) {
const psFormat = toPSFormat(formatID);
const format = UNSUPPORTED[psFormat] ? null : Dex.formats.get(psFormat);
if (format && !format.exists) {
Expand Down
280 changes: 140 additions & 140 deletions src/js/data/sets/gen1.js

Large diffs are not rendered by default.

64 changes: 32 additions & 32 deletions src/js/data/sets/gen2.js

Large diffs are not rendered by default.

325 changes: 163 additions & 162 deletions src/js/data/sets/gen3.js

Large diffs are not rendered by default.

258 changes: 129 additions & 129 deletions src/js/data/sets/gen4.js

Large diffs are not rendered by default.

596 changes: 298 additions & 298 deletions src/js/data/sets/gen5.js

Large diffs are not rendered by default.

998 changes: 499 additions & 499 deletions src/js/data/sets/gen6.js

Large diffs are not rendered by default.

1,392 changes: 696 additions & 696 deletions src/js/data/sets/gen7.js

Large diffs are not rendered by default.

1,762 changes: 881 additions & 881 deletions src/js/data/sets/gen8.js

Large diffs are not rendered by default.

2,116 changes: 1,058 additions & 1,058 deletions src/js/data/sets/gen9.js

Large diffs are not rendered by default.

0 comments on commit 0408aa1

Please sign in to comment.