From 6c7d61f916bfaeb5e356dc8e4e50be21c6746b35 Mon Sep 17 00:00:00 2001 From: xeals Date: Thu, 27 Apr 2023 12:11:39 +1000 Subject: [PATCH] fix support for mega/formes --- calc.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/calc.js b/calc.js index 6c4fcba..b14f076 100644 --- a/calc.js +++ b/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 };