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