fix support for mega/formes
This commit is contained in:
parent
2acbf9945c
commit
6c7d61f916
16
calc.js
16
calc.js
@ -49,7 +49,15 @@ function buildLexer() {
|
||||
const Pokemon = createToken({
|
||||
name: "Pokemon",
|
||||
pattern: new RegExp(
|
||||
[...gen.species].map((s) => escapeRegExp(s.name)).join("|")
|
||||
[...gen.species]
|
||||
.flatMap((s) => [
|
||||
// Important: formes are expanded first because the parser takes the
|
||||
// first match, and the original species is always a subset of a
|
||||
// forme.
|
||||
...(s.otherFormes || []).map(escapeRegExp),
|
||||
escapeRegExp(s.name),
|
||||
])
|
||||
.join("|")
|
||||
),
|
||||
});
|
||||
const Move = createToken({
|
||||
@ -336,6 +344,12 @@ function test() {
|
||||
|
||||
res = parseAndCalculate("Tera Electric Iron Hands Wild Charge vs Basculin");
|
||||
assert(res.attacker.teraType === "Electric", "should parse tera type");
|
||||
|
||||
res = parseAndCalculate("Gallade-Mega Triple Axel vs Gligar");
|
||||
assert(res.attacker.name === "Gallade-Mega", "should parse Mega forme");
|
||||
|
||||
res = parseAndCalculate("Zoroark-Hisui Night Slash vs Golem");
|
||||
assert(res.attacker.name === "Zoroark-Hisui", "should parse regional forme");
|
||||
}
|
||||
|
||||
export { parseAndCalculate, test };
|
||||
|
Loading…
Reference in New Issue
Block a user