doshidak / showdex

Pokémon Showdown extension that harnesses the power of parabolic calculus to strategically extract your opponents' Elo.
GNU Affero General Public License v3.0
104 stars 18 forks source link

gen8nationaldex formats crashes Calcdex #8

Closed doshidak closed 2 years ago

doshidak commented 2 years ago

this is caused by mega evo items like Mawilite not existing in the Gen 8 Generation object from @pkmn/dex.

import { Dex } from '@pkmn/dex';
import { Generations } from '@pkmn/data';

const gens = new Generations(Dex);
const dexGen8 = gens.get(8);

dexGen8.items.get('Mawilite');

returns:

undefined

we can either load from a previous gen (e.g., gens.get(6)) if dex.items.get() returns undefined, or use the global Dex object from the Showdown client:

Dex.items.get('Mawilite');

returns:

Item {
  id: 'Mawilite',
  num: 681,
  spritenum: 598,
  name: 'Mawilite',
  desc: 'If held by a Mawile, this item allows it to Mega Evolve in battle.',
  shortDesc: 'If held by a Mawile, this item allows it to Mega Evolve in battle.',
  gen: 6,
  exists: true,
  effectType: 'Item',
  itemUser: [
    'Mawile',
  ],
  fling: null,
  isPokeball: false,
  megaEvolves: 'Mawile',
  megaStone: 'Mawile-Mega',
  naturalGift: null,
  onDrive: '',
  onMemory: '',
  onPlate: '',
  zMove: null,
  zMoveFrom: '',
  zMoveType: '',
  zMoveUser: null,
}

note that the following is the return object of dex.items.get() (from @pkmn/dex):

const dexGen6 = gens.get(6);

dexGen6.items.get('Mawilite');

returns:

Item {
  id: 'mawilite',
  num: 681,
  name: 'Mawilite',
  fullName: 'item: Mawilite',
  desc: 'If held by a Mawile, this item allows it to Mega Evolve in battle.',
  shortDesc: '',
  gen: 6,
  exists: true,
  isNonstandard: null,
  kind: 'Item',
  effectType: 'Item',
  itemUser: [
    'Mawile',
  ],
  duration: undefined,
  fling: {
    basePower: 80,
  },
  megaEvolves: 'Mawile',
  megaStone: 'Mawile-Mega',
}

the objects from Dex.items.get() and dex.items.get() share similar properties, but differ slightly, such as the return object from Dex.items.get() not including the isNonstandard property that the return object from dex.items.get() has.

doshidak commented 2 years ago

Down the rabbit hole we go...

Apparently it wasn't enough fixing the item lookup via dex since there are other things like the species and moves that also aren't available in the gen 8 dex.

Anyways, got gen8nationaldex* formats working for the most part:

nationaldex-screenshot

Had to add a couple checks to conditionally change the gen to 7 we're in since solely relying on the gen 8 dex crashes the extension. Additionally, slowly working on phasing out using the dex from @pkmn/dex and using the global Dex object that's available in the Showdown client instead.

missing-greninja-spread

Will close this via reference on the next PR.