fix support for mega/formes
This commit is contained in:
		
							
								
								
									
										16
									
								
								calc.js
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								calc.js
									
									
									
									
									
								
							| @@ -49,7 +49,15 @@ function buildLexer() { | |||||||
|   const Pokemon = createToken({ |   const Pokemon = createToken({ | ||||||
|     name: "Pokemon", |     name: "Pokemon", | ||||||
|     pattern: new RegExp( |     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({ |   const Move = createToken({ | ||||||
| @@ -336,6 +344,12 @@ function test() { | |||||||
|  |  | ||||||
|   res = parseAndCalculate("Tera Electric Iron Hands Wild Charge vs Basculin"); |   res = parseAndCalculate("Tera Electric Iron Hands Wild Charge vs Basculin"); | ||||||
|   assert(res.attacker.teraType === "Electric", "should parse tera type"); |   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 }; | export { parseAndCalculate, test }; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user