/** * Dex * Pokemon Showdown - http://pokemonshowdown.com/ * * Handles getting data about pokemon, items, etc. Also contains some useful * helper functions for using dex data. * * By default, nothing is loaded until you call Dex.mod(mod) or * Dex.forFormat(format). * * You may choose to preload some things: * - Dex.includeMods() ~10ms * This will populate Dex.dexes, giving you a list of possible mods. * Note that you don't need this for Dex.mod, Dex.mod will * automatically populate this. * - Dex.includeFormats() ~30ms * As above, but will also populate Dex.formats, giving an object * containing formats. * - Dex.includeData() ~500ms * As above, but will also preload all of Dex.data, giving access to * the data access functions like Dex.getTemplate, Dex.getMove, etc. * - Dex.includeModData() ~1500ms * As above, but will also preload Dex.dexes[...].data for all mods. * * Note that preloading is only necessary for iterating Dex.dexes. Getters * like Dex.getTemplate will automatically load this data as needed. * * @license MIT license */ Object.defineProperty(Array.prototype, 'flatMap', { value(this: T[], callback: (this: W, item: T, index: number, array: T[]) => U[], thisArg: W): U[] { const newArray = []; for (let i = 0; i < this.length; i++) { newArray.push(...callback.call(thisArg, this[i], i, this)); } return newArray; }, configurable: true, writable: true, }); import * as fs from 'fs'; import * as path from 'path'; import * as Data from './dex-data'; import {PRNG, PRNGSeed} from './prng'; const DATA_DIR = path.resolve(__dirname, '../data'); const MODS_DIR = path.resolve(__dirname, '../data/mods'); const FORMATS = path.resolve(__dirname, '../config/formats'); const dexes: {[mod: string]: ModdedDex} = Object.create(null); type DataType = 'Abilities' | 'Formats' | 'FormatsData' | 'Items' | 'Learnsets' | 'Movedex' | 'Natures' | 'Pokedex' | 'Scripts' | 'Statuses' | 'TypeChart'; const DATA_TYPES: (DataType | 'Aliases')[] = [ 'Abilities', 'Formats', 'FormatsData', 'Items', 'Learnsets', 'Movedex', 'Natures', 'Pokedex', 'Scripts', 'Statuses', 'TypeChart', ]; const DATA_FILES = { Abilities: 'abilities', Aliases: 'aliases', Formats: 'rulesets', FormatsData: 'formats-data', Items: 'items', Learnsets: 'learnsets', Movedex: 'moves', Natures: 'natures', Pokedex: 'pokedex', Scripts: 'scripts', Statuses: 'statuses', TypeChart: 'typechart', }; const nullEffect: PureEffect = new Data.PureEffect({name: '', exists: false}); interface Nature { name: string; plus?: keyof StatsTable; minus?: keyof StatsTable; [k: string]: any; } interface DexTableData { Abilities: DexTable; Aliases: {[id: string]: string}; Formats: DexTable; FormatsData: DexTable; Items: DexTable; Learnsets: DexTable<{learnset: {[k: string]: MoveSource[]}}>; Movedex: DexTable; Natures: DexTable; Pokedex: DexTable