smogon / pokemon-showdown

Pokémon battle simulator.
https://pokemonshowdown.com
MIT License
4.77k stars 2.79k forks source link

Move set import logic from the calc to Pokemon-Showdown #5732

Closed scheibo closed 5 years ago

scheibo commented 5 years ago

In order to support easily accessing sets in the client teambuilder, the newly committed sets package from the damage calc will be moved to this repository.

  1. @pokemon-showdown/sets package will be hosted in the main https://github.com/Pokemon-Showdown/Pokemon-Showdown repo. The code will be modified to drop the @pokemon-showdown/calc dep and will depend directly on Dex without a shim. Because the @pokemon-showdown/sets package will only be exporting the data (see 3 below), isolating the generation code into a subpackage is less important (though can be done at a later date once https://pkmn.cc/ps-core-design is complete).
  2. The data produced will include both sets and weights (adds negligible size overhead but allows for https://calc.pokemonshowdown.com to depend on https://play.pokemonshowdown.com assets for better caching, also facilitates integrating usage statistics into the client). The set data will follow PokemonSet conventions instead of those used by the damage calc (ie. standard as opposed to abbreviated StatName)
  3. sets package will actually publish the data, not the code for fetching the data (ie/ two 'build' folders, compiled TS which can then be run to fetch the script, and the actual data files which is going to be what developers importing @pokemon-showdown/sets will be accessing). The npm package's will also include an index.js and index.d.ts for loading logic and typings, but Pokemon-Showdown-Client will likely just pull the raw JSON files out of the dist folder.
  4. Because the sets package pushes data, sets are updated before npm publish. node build full on the client will simply copy the data out of node_modules/, so updating sets actually involves running the set importer locally, bumping the version, publishing, updating the client's package.json and running node build full
  5. The new UI of the calc will depend on @pokemon-showdown/sets and Parcel will handle bundling and lazy loading for us. The current UI can simply copy the files like the client.

Originally the @pokemon-showdown/sets package will support slicing by generation only (gen1.json etc), but I would like to also support supporting by generation + format (gen1lgpeou.json) as well.

scheibo commented 5 years ago

Some more thoughts:

The type structure I'm going for is as follows:

type DeepPartial<T> = {
    [P in keyof T]?: T[P] extends (infer I)[]
    ? (DeepPartial<I>)[]
    : DeepPartial<T[P]>;
};

// eg. 'gen1.json'
export interface GenerationData {
    [formatid: string]: FormatData;
}

// eg. 'gen7balancedhackmons.json'
export interface FormatData {
    sets: {
        [source: string]: {
            [speciesid: string]: {
                [name: string]: DeepPartial<PokemonSet>;
            };
        };
    };
    weights: {
        species: {[id: string]: number};
        abilities: {[id: string]: number};
        items: {[id: string]: number};
        moves: {[id: string]: number};
    };
}

The logic for generating the sets data package will live in tools/set-import/index.ts (built to tools/set-import/index.ts), and tools/{simulate.js,SIMULATE.md} will be moved do its only subdir within tools (ie. tools/simulate/index.js, so node tools/simulate still works). The directory will be set up as follows (build artifacts indicated with *):

tools/
   set-import/
      index.ts
      index.js*
      sets/
        package.json
        index.js
        index.d.ts
        gen1.json*
        ...
        gen7zu.json*

Thus, one will run npm build at the top level, then node tools/set-import which will write new files to the tools/set-import/sets/ subdir (and bump the version on its package.json?) and then cd tools/set-import/sets && npm publish can be run to release a new package.

scheibo commented 5 years ago

This is now code complete and verified (yay!). Assigning to @Zarel to resolve logistics with Smogon.

Zarel commented 5 years ago

Which logistics do you need me to resolve?