fix support for mega/formes

This commit is contained in:
xeals 2023-04-27 12:11:39 +10:00
parent 2acbf9945c
commit 6c7d61f916
Signed by: xeals
GPG Key ID: A498C7AF27EC6B5C

16
calc.js
View File

@ -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 };