smogon / damage-calc

Pokemon games damage calculator
https://calc.pokemonshowdown.com
MIT License
381 stars 357 forks source link

Incorrect handling of Pokemon names containing é #515

Open RainingChain opened 1 year ago

RainingChain commented 1 year ago

The official english name for Pokemon #669 is Flabébé. However, when trying to create a new Smogon.Pokemon instance with that name, it fails.

Current behaviour:

new Smogon.Pokemon(6, 'Flabébé',{}); 
// Uncaught TypeError: Cannot read properties of undefined (reading 'hp')

Expected behaviour:

new Smogon.Pokemon(6, 'Flabébé',{}); 
// Pokemon {species: {…}, gen: Generation, name: 'Flabebe', types: Array(1), isDynamaxed: false, …}

The issue is with the function utils.toID

function toID(text) {
    return ('' + text).toLowerCase().replace(/[^a-z0-9]+/g, '');
}

Internally, the id for Flabébé is flabebe. However, toID('Flabébé') returns flabb.

Ideally, we would modify the function toID for:

function toID(text) {
    return ('' + text).toLowerCase().replace(/é/g, 'e').replace(/[^a-z0-9]+/g, '');
}
monsanto commented 1 year ago

Yes although Smogon's data is now derived from PS' data in the past there were some differences, and not all of the kinks have been smoothed. The conversion has the following exceptions (from the PS data import code)

name = name.replace(/\u2019/g, "'"); // Farfetch'd ...
if (name === 'Necrozma-Dawn-Wings') {
    name = 'Necrozma-Dawn Wings';
  } else if (name === 'Necrozma-Dusk-Mane') {
    name = 'Necrozma-Dusk Mane';
  } else if (name === 'Flabébé') {
    name = 'Flabebe';
  } else if (name === 'Meowstic') {
    name = 'Meowstic-M';
  } else if (name === 'Vise Grip') {
    // Can't handle this rename yet, will break old links
    name = 'Vice Grip';
  }