Use JSON
Hardcoding all Pokémon names in a C++ source file is not fun. A better software development practice is to store those lengthy data as external files. At runtime, the executable loads the file to use the data.
We use JSON as the file format to store our text-based data like Pokémon lists and Pokédex contents.
An example is Pokedex-National.json, in our Resources
folder. See its topic for more details about the folder.
JSON for Sprites
For better user experience we also have Pokémon sprite images in Resources
folder. Those sprites are used as part of Pokémon selection UI in for example Outbreak Finder.
To save file transfer and loading time, we usually put all sprites of the entire Pokédex into a single image, like MMOSprites.png.
To know which part of the image belongs to which slug (see the slug topic page for what a slug is), we need to have an accompanied JSON file to specify this, like what's in MMOSprites.json.
Code to Load JSON
See code in Pokemon_PokemonSlugs.cpp on how to load a simple JSON of a list Pokémon slugs to get the national Pokédex.
JSON files for image sprites are more complex. You can learn more on our JSON loading and parsing functions by studying the code that loads image sprites in SpriteDatabase
class. This SpriteDatabase
class is used to load an image and its corresponding JSON file to get all the sprites from the image. For example, in PokemonLA_PokemonMapSpriteReader.cpp, SpriteDatabase
is created to load MMOSprites.png and MMOSprites.json mentioned above.