@pkmn/stats 0.0.2 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.md +90 -0
- package/README.md +11 -7
- package/build/aliases.json +1 -0
- package/build/binary.d.ts +138 -0
- package/build/binary.js +386 -0
- package/build/binary.js.map +1 -0
- package/build/classifier.d.ts +2 -2
- package/build/classifier.js +45 -39
- package/build/classifier.js.map +1 -1
- package/build/data.d.ts +39 -0
- package/build/data.js +126 -0
- package/build/data.js.map +1 -0
- package/build/display.d.ts +1 -1
- package/build/display.js +16 -6
- package/build/display.js.map +1 -1
- package/build/index.d.ts +1 -0
- package/build/index.js +3 -1
- package/build/index.js.map +1 -1
- package/build/parser.d.ts +2 -2
- package/build/parser.js +55 -37
- package/build/parser.js.map +1 -1
- package/build/pkmn/data.d.ts +39 -0
- package/build/pkmn/data.js +126 -0
- package/build/pkmn/data.js.map +1 -0
- package/build/pkmn/index.d.ts +1 -0
- package/build/pkmn/index.js +18 -0
- package/build/pkmn/index.js.map +1 -0
- package/build/reports.d.ts +2 -2
- package/build/reports.js +27 -20
- package/build/reports.js.map +1 -1
- package/build/smogon/aliases.json +227 -0
- package/build/smogon/classifier.d.ts +12 -0
- package/build/smogon/classifier.js +556 -0
- package/build/smogon/classifier.js.map +1 -0
- package/build/smogon/display.d.ts +96 -0
- package/build/smogon/display.js +412 -0
- package/build/smogon/display.js.map +1 -0
- package/build/smogon/index.d.ts +6 -0
- package/build/smogon/index.js +19 -0
- package/build/smogon/index.js.map +1 -0
- package/build/smogon/parser.d.ts +57 -0
- package/build/smogon/parser.js +358 -0
- package/build/smogon/parser.js.map +1 -0
- package/build/smogon/reports.d.ts +51 -0
- package/build/smogon/reports.js +652 -0
- package/build/smogon/reports.js.map +1 -0
- package/build/smogon/stats.d.ts +119 -0
- package/build/smogon/stats.js +521 -0
- package/build/smogon/stats.js.map +1 -0
- package/build/smogon/test/integration.d.ts +30 -0
- package/build/smogon/test/integration.js +179 -0
- package/build/smogon/test/integration.js.map +1 -0
- package/build/smogon/test/integration.test.d.ts +1 -0
- package/build/smogon/test/integration.test.js +38 -0
- package/build/smogon/test/integration.test.js.map +1 -0
- package/build/smogon/test/parser.test.d.ts +1 -0
- package/build/smogon/test/parser.test.js +91 -0
- package/build/smogon/test/parser.test.js.map +1 -0
- package/build/smogon/util.d.ts +63 -0
- package/build/smogon/util.js +400 -0
- package/build/smogon/util.js.map +1 -0
- package/build/stats.d.ts +3 -3
- package/build/stats.js +34 -34
- package/build/stats.js.map +1 -1
- package/build/util.d.ts +7 -7
- package/build/util.js +42 -32
- package/build/util.js.map +1 -1
- package/package.json +11 -14
- package/src/aliases.json +1 -0
- package/src/binary.ts +514 -0
- package/src/classifier.ts +38 -37
- package/src/display.ts +12 -14
- package/src/index.ts +6 -17
- package/src/parser.ts +39 -22
- package/src/reports.ts +22 -21
- package/src/stats.ts +27 -24
- package/src/util.ts +39 -39
package/src/util.ts
CHANGED
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-loss-of-precision */
|
|
2
|
-
import {
|
|
3
|
-
Generations,
|
|
4
|
-
Generation,
|
|
5
|
-
GenerationNum,
|
|
6
|
-
Dex,
|
|
7
|
-
ID,
|
|
8
|
-
toID,
|
|
9
|
-
PokemonSet,
|
|
10
|
-
Specie,
|
|
11
|
-
} from '@pkmn/data';
|
|
2
|
+
import {Generations, Generation, Dex, ID, toID, PokemonSet, Specie} from '@pkmn/data';
|
|
12
3
|
import * as aliases from './aliases.json';
|
|
13
4
|
|
|
14
5
|
export const PRECISION = 1e10;
|
|
@@ -31,7 +22,6 @@ export const enum Outcome {
|
|
|
31
22
|
|
|
32
23
|
const ALIASES: Readonly<{ [id: string]: string }> = aliases;
|
|
33
24
|
|
|
34
|
-
// FIXME: Remove newGenerations and ignoreGen in favor of using the normal APIs!
|
|
35
25
|
let DEFAULT!: Generation;
|
|
36
26
|
export function newGenerations(dex: Dex) {
|
|
37
27
|
const gens = new Generations(dex, e => !!e.exists);
|
|
@@ -39,8 +29,9 @@ export function newGenerations(dex: Dex) {
|
|
|
39
29
|
return gens;
|
|
40
30
|
}
|
|
41
31
|
|
|
42
|
-
export function ignoreGen(gen: Generation) {
|
|
32
|
+
export function ignoreGen(gen: Generation, legacy: boolean) {
|
|
43
33
|
if (!gen) throw new Error('ignoreGen called without a gen to ignore!');
|
|
34
|
+
if (!legacy) return gen;
|
|
44
35
|
if (!DEFAULT) throw new Error('Default generation not set - call newGenerations');
|
|
45
36
|
return DEFAULT;
|
|
46
37
|
}
|
|
@@ -49,22 +40,22 @@ export function fromAlias(name: string) {
|
|
|
49
40
|
return ALIASES[toID(name)] || name;
|
|
50
41
|
}
|
|
51
42
|
|
|
52
|
-
export function getSpecies(gen: Generation, name: string) {
|
|
53
|
-
const species = ignoreGen(gen).species.get(name);
|
|
43
|
+
export function getSpecies(gen: Generation, name: string, legacy: boolean) {
|
|
44
|
+
const species = ignoreGen(gen, legacy).species.get(name);
|
|
54
45
|
if (!species) throw new Error(`Unknown species '${name}'`);
|
|
55
46
|
return species;
|
|
56
47
|
}
|
|
57
48
|
|
|
58
|
-
export function getBaseSpecies(gen: Generation, name: string): Specie {
|
|
59
|
-
const species = getSpecies(gen, name);
|
|
49
|
+
export function getBaseSpecies(gen: Generation, name: string, legacy: boolean): Specie {
|
|
50
|
+
const species = getSpecies(gen, name, legacy);
|
|
60
51
|
return species.baseSpecies && species.baseSpecies !== species.name
|
|
61
|
-
? getBaseSpecies(gen, species.baseSpecies)
|
|
52
|
+
? getBaseSpecies(gen, species.baseSpecies, legacy)
|
|
62
53
|
: species;
|
|
63
54
|
}
|
|
64
55
|
|
|
65
56
|
export function genForFormat(gens: Generations, format: ID) {
|
|
66
57
|
const m = /gen(\d)/.exec(format);
|
|
67
|
-
return gens.get(m ?
|
|
58
|
+
return gens.get(m ? m[1] : 6);
|
|
68
59
|
}
|
|
69
60
|
|
|
70
61
|
const MEGA_RAYQUAZA_BANNED = new Set([
|
|
@@ -75,15 +66,19 @@ export function isMegaRayquazaAllowed(format: ID) {
|
|
|
75
66
|
return !MEGA_RAYQUAZA_BANNED.has(format);
|
|
76
67
|
}
|
|
77
68
|
|
|
78
|
-
export function isMega(species: Specie) {
|
|
79
|
-
|
|
80
|
-
|
|
69
|
+
export function isMega(species: Specie, legacy: boolean) {
|
|
70
|
+
return species.forme && (species.forme.startsWith('Mega') || species.forme.startsWith('Primal') ||
|
|
71
|
+
(!legacy && species.forme.startsWith('Ultra')));
|
|
81
72
|
}
|
|
82
73
|
|
|
83
|
-
export function getMegaEvolution(
|
|
84
|
-
|
|
74
|
+
export function getMegaEvolution(
|
|
75
|
+
gen: Generation,
|
|
76
|
+
pokemon: PokemonSet<string | ID>,
|
|
77
|
+
legacy: boolean,
|
|
78
|
+
) {
|
|
79
|
+
const item = ignoreGen(gen, legacy).items.get(pokemon.item);
|
|
85
80
|
if (!item) return undefined;
|
|
86
|
-
const species = getSpecies(gen, pokemon.species);
|
|
81
|
+
const species = getSpecies(gen, pokemon.species, legacy);
|
|
87
82
|
if (item.name === 'Blue Orb' &&
|
|
88
83
|
(species.name === 'Kyogre' || species.baseSpecies === 'Kyogre')) {
|
|
89
84
|
return {species: 'kyogreprimal' as ID, ability: 'primordialsea' as ID};
|
|
@@ -92,19 +87,22 @@ export function getMegaEvolution(gen: Generation, pokemon: PokemonSet<string | I
|
|
|
92
87
|
(species.name === 'Groudon' || species.baseSpecies === 'Groudon')) {
|
|
93
88
|
return {species: 'groudonprimal' as ID, ability: 'desolateland' as ID};
|
|
94
89
|
}
|
|
95
|
-
|
|
90
|
+
if (!legacy && item.name === 'Ultranecrozium Z' &&
|
|
91
|
+
(species.name === 'Necrozma' || species.baseSpecies === 'Necrozma')) {
|
|
92
|
+
return {species: 'necrozmaultra' as ID, ability: 'neuroforce' as ID};
|
|
93
|
+
}
|
|
96
94
|
if (!item.megaEvolves || item.megaEvolves !== species.name || !item.megaStone) {
|
|
97
95
|
return undefined;
|
|
98
96
|
}
|
|
99
|
-
const mega = getSpecies(gen, item.megaStone);
|
|
97
|
+
const mega = getSpecies(gen, item.megaStone, legacy);
|
|
100
98
|
if (!mega) return undefined;
|
|
101
99
|
return {species: toID(mega.name), ability: toID(mega.abilities['0'])};
|
|
102
100
|
}
|
|
103
101
|
|
|
104
|
-
export function revertFormes(gen: Generation, id: ID) {
|
|
105
|
-
const species = getSpecies(gen, id);
|
|
106
|
-
if (!species.forme || isMega(species)) return id;
|
|
107
|
-
return getBaseSpecies(gen, species.id).id;
|
|
102
|
+
export function revertFormes(gen: Generation, id: ID, legacy: boolean) {
|
|
103
|
+
const species = getSpecies(gen, id, legacy);
|
|
104
|
+
if (!species.forme || isMega(species, legacy)) return id;
|
|
105
|
+
return getBaseSpecies(gen, species.id, legacy).id;
|
|
108
106
|
}
|
|
109
107
|
|
|
110
108
|
// FIXME: Generate this based on gameType from config/formats.js
|
|
@@ -117,9 +115,9 @@ const NON_SINGLES_FORMATS = new Set([
|
|
|
117
115
|
'gen7vgc2017', 'gen7vgc2017beta', 'orassmogondoubles', 'randomdoublesbattle', 'smogondoublesuu',
|
|
118
116
|
'randomtriplesbattle', 'smogondoubles', 'smogondoublesubers', 'smogontriples', 'smogontriples',
|
|
119
117
|
'gen8doublesou', 'gen8doublesubers', 'gen8doublesuu', 'vgc2014', 'vgc2015', 'vgc2016',
|
|
120
|
-
'gen6vgc2016', 'gen7vgc2017', 'gen7vgc2018', '
|
|
118
|
+
'gen6vgc2016', 'gen7vgc2017', 'gen7vgc2018', 'gen7vgc2019', 'gen7vgc2019sunseries',
|
|
121
119
|
'gen7vgc2019moonseries', 'gen7vgc2019ultraseries', 'gen8vgc2020', 'gen8vgc2021',
|
|
122
|
-
'gen8vgc2021series9', 'gen8vgc2021series9limitonerestrictedrestrictedlegendary',
|
|
120
|
+
'gen8vgc2021series9', 'gen8vgc2021series9limitonerestrictedrestrictedlegendary', 'gen8vgc2022',
|
|
123
121
|
]);
|
|
124
122
|
|
|
125
123
|
export function isNonSinglesFormat(format: ID) {
|
|
@@ -131,9 +129,10 @@ const NON_6V6_FORMATS = new Set([
|
|
|
131
129
|
'1v1', 'battlespotdoubles', 'battlespotsingles', 'battlespotspecial7', 'challengecup1v1',
|
|
132
130
|
'gen5gbusingles', 'gen71v1', 'gen7alolafriendly', 'gen7battlespotdoubles', 'gen81v1',
|
|
133
131
|
'gen7battlespotsingles', 'gen7challengecup1v1', 'gen7vgc2017', 'gen7vgc2017beta', 'pgllittlecup',
|
|
134
|
-
'vgc2014', 'vgc2015', 'vgc2016', 'gen6vgc2016', 'gen7vgc2017', 'gen7vgc2018', '
|
|
132
|
+
'vgc2014', 'vgc2015', 'vgc2016', 'gen6vgc2016', 'gen7vgc2017', 'gen7vgc2018', 'gen7vgc2019',
|
|
135
133
|
'gen7vgc2019sunseries', 'gen7vgc2019moonseries', 'fen7vgc2019ultraseries', 'gen8vgc2020',
|
|
136
134
|
'gen8vgc2021', 'gen8vgc2021series9', 'gen8vgc2021series9limitonerestrictedrestrictedlegendary',
|
|
135
|
+
'gen8vgc2022', 'gen8firstblood', 'gen8tagteamsingles',
|
|
137
136
|
]);
|
|
138
137
|
|
|
139
138
|
export function isNon6v6Format(format: ID) {
|
|
@@ -165,13 +164,14 @@ export function roundStr(v: number, p = PRECISION) {
|
|
|
165
164
|
return num === Math.floor(num) ? `${num.toFixed(1)}` : `${num}`;
|
|
166
165
|
}
|
|
167
166
|
|
|
168
|
-
export function displaySpecies(gen: Generation, name: string) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
167
|
+
export function displaySpecies(gen: Generation, name: string, legacy: boolean) {
|
|
168
|
+
if (name === 'empty') {
|
|
169
|
+
if (!legacy) throw new Error('empty passed to displaySpecies');
|
|
170
|
+
return name;
|
|
171
|
+
}
|
|
172
|
+
const species = getSpecies(gen, name, legacy).name;
|
|
172
173
|
if (name === 'Flabébé') return 'Flabebe';
|
|
173
|
-
|
|
174
|
-
return species.startsWith('Nidoran') ? species.replace('-', '') : species;
|
|
174
|
+
return legacy && species.startsWith('Nidoran') ? species.replace('-', '') : species;
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
export function toDisplayObject(
|