Просмотр исходного кода

pokemon: Clean up pokemon data tables

Refactors the three separate name, icon, and hex tables in to a
single array of structs to keep data more easily consistent.
Kris Bahnsen 2 лет назад
Родитель
Сommit
0e956db65d
4 измененных файлов с 167 добавлено и 74 удалено
  1. 154 65
      pokemon_app.cpp
  2. 8 4
      pokemon_app.h
  3. 4 4
      views/select_pokemon.cpp
  4. 1 1
      views/trade.cpp

+ 154 - 65
pokemon_app.cpp

@@ -1,70 +1,159 @@
 #include "pokemon_app.h"
 
-const char* pokemon_names[] = {
-    "bulbasaur",  "ivysaur",   "venusaur",   "charmander", "charmeleon", "charizard",
-    "squirtle",   "wartortle", "blastoise",  "caterpie",   "metapod",    "butterfree",
-    "weedle",     "kakuna",    "beedrill",   "pidgey",     "pidgeotto",  "pidgeot",
-    "rattata",    "raticate",  "spearow",    "fearow",     "ekans",      "arbok",
-    "pikachu",    "raichu",    "sandshrew",  "sandslash",  "nidoran ♀",  "nidorina",
-    "nidoqueen",  "nidoran ♂", "nidorino",   "nidoking",   "clefairy",   "clefable",
-    "vulpix",     "ninetales", "jigglypuff", "wigglytuff", "zubat",      "golbat",
-    "oddish",     "gloom",     "vileplume",  "paras",      "parasect",   "venonat",
-    "venomoth",   "diglett",   "dugtrio",    "meowth",     "persian",    "psyduck",
-    "golduck",    "mankey",    "primeape",   "growlithe",  "arcanine",   "poliwag",
-    "poliwhirl",  "poliwrath", "abra",       "kadabra",    "alakazam",   "machop",
-    "machoke",    "machamp",   "bellsprout", "weepinbell", "victreebel", "tentacool",
-    "tentacruel", "geodude",   "graveler",   "golem",      "ponyta",     "rapidash",
-    "slowpoke",   "slowbro",   "magnemite",  "magneton",   "farfetchd",  "doduo",
-    "dodrio",     "seel",      "dewgong",    "grimer",     "muk",        "shellder",
-    "cloyster",   "gastly",    "haunter",    "gengar",     "onix",       "drowzee",
-    "hypno",      "krabby",    "kingler",    "voltorb",    "electrode",  "exeggcute",
-    "exeggutor",  "cubone",    "marowak",    "hitmonlee",  "hitmonchan", "lickitung",
-    "koffing",    "weezing",   "rhyhorn",    "rhydon",     "chansey",    "tangela",
-    "kangaskhan", "horsea",    "seadra",     "goldeen",    "seaking",    "staryu",
-    "starmie",    "mr. mime",  "scyther",    "jynx",       "electabuzz", "magmar",
-    "pinsir",     "tauros",    "magikarp",   "gyarados",   "lapras",     "ditto",
-    "eevee",      "vaporeon",  "jolteon",    "flareon",    "porygon",    "omanyte",
-    "omastar",    "kabuto",    "kabutops",   "aerodactyl", "snorlax",    "articuno",
-    "zapdos",     "moltres",   "dratini",    "dragonair",  "dragonite",  "mewtwo",
-    "mew"};
-const Icon* pokemon_icons[] = {
-    &I_bulbasaur,  &I_ivysaur,   &I_venusaur,   &I_charmander, &I_charmeleon, &I_charizard,
-    &I_squirtle,   &I_wartortle, &I_blastoise,  &I_caterpie,   &I_metapod,    &I_butterfree,
-    &I_weedle,     &I_kakuna,    &I_beedrill,   &I_pidgey,     &I_pidgeotto,  &I_pidgeot,
-    &I_rattata,    &I_raticate,  &I_spearow,    &I_fearow,     &I_ekans,      &I_arbok,
-    &I_pikachu,    &I_raichu,    &I_sandshrew,  &I_sandslash,  &I_nidoranf,   &I_nidorina,
-    &I_nidoqueen,  &I_nidoranm,  &I_nidorino,   &I_nidoking,   &I_clefairy,   &I_clefable,
-    &I_vulpix,     &I_ninetales, &I_jigglypuff, &I_wigglytuff, &I_zubat,      &I_golbat,
-    &I_oddish,     &I_gloom,     &I_vileplume,  &I_paras,      &I_parasect,   &I_venonat,
-    &I_venomoth,   &I_diglett,   &I_dugtrio,    &I_meowth,     &I_persian,    &I_psyduck,
-    &I_golduck,    &I_mankey,    &I_primeape,   &I_growlithe,  &I_arcanine,   &I_poliwag,
-    &I_poliwhirl,  &I_poliwrath, &I_abra,       &I_kadabra,    &I_alakazam,   &I_machop,
-    &I_machoke,    &I_machamp,   &I_bellsprout, &I_weepinbell, &I_victreebel, &I_tentacool,
-    &I_tentacruel, &I_geodude,   &I_graveler,   &I_golem,      &I_ponyta,     &I_rapidash,
-    &I_slowpoke,   &I_slowbro,   &I_magnemite,  &I_magneton,   &I_farfetchd,  &I_doduo,
-    &I_dodrio,     &I_seel,      &I_dewgong,    &I_grimer,     &I_muk,        &I_shellder,
-    &I_cloyster,   &I_gastly,    &I_haunter,    &I_gengar,     &I_onix,       &I_drowzee,
-    &I_hypno,      &I_krabby,    &I_kingler,    &I_voltorb,    &I_electrode,  &I_exeggcute,
-    &I_exeggutor,  &I_cubone,    &I_marowak,    &I_hitmonlee,  &I_hitmonchan, &I_lickitung,
-    &I_koffing,    &I_weezing,   &I_rhyhorn,    &I_rhydon,     &I_chansey,    &I_tangela,
-    &I_kangaskhan, &I_horsea,    &I_seadra,     &I_goldeen,    &I_seaking,    &I_staryu,
-    &I_starmie,    &I_mr_mime,   &I_scyther,    &I_jynx,       &I_electabuzz, &I_magmar,
-    &I_pinsir,     &I_tauros,    &I_magikarp,   &I_gyarados,   &I_lapras,     &I_ditto,
-    &I_eevee,      &I_vaporeon,  &I_jolteon,    &I_flareon,    &I_porygon,    &I_omanyte,
-    &I_omastar,    &I_kabuto,    &I_kabutops,   &I_aerodactyl, &I_snorlax,    &I_articuno,
-    &I_zapdos,     &I_moltres,   &I_dratini,    &I_dragonair,  &I_dragonite,  &I_mewtwo,
-    &I_mew};
-const unsigned char pokemon_hex_codes[] = {
-    0x99, 0x09, 0x9A, 0xB0, 0xB2, 0xB4, 0xB1, 0xB3, 0x1C, 0x7B, 0x7C, 0x7D, 0x70, 0x71, 0x72, 0x24,
-    0x96, 0x97, 0xA5, 0xA6, 0x05, 0x23, 0x6C, 0x2D, 0x54, 0x55, 0x60, 0x61, 0x0F, 0xA8, 0x10, 0x03,
-    0xA7, 0x07, 0x04, 0x8E, 0x52, 0x53, 0x64, 0x65, 0x6B, 0x82, 0xB9, 0xBA, 0xBB, 0x6D, 0x2E, 0x41,
-    0x77, 0x3B, 0x76, 0x4D, 0x90, 0x2F, 0x80, 0x39, 0x75, 0x21, 0x14, 0x47, 0x6E, 0x6F, 0x94, 0x26,
-    0x95, 0x6A, 0x29, 0x7E, 0xBC, 0xBD, 0xBE, 0x18, 0x9B, 0xA9, 0x27, 0x31, 0xA3, 0xA4, 0x25, 0x08,
-    0xAD, 0x36, 0x40, 0x46, 0x74, 0x3A, 0x78, 0x0D, 0x88, 0x17, 0x8B, 0x19, 0x93, 0x0E, 0x22, 0x30,
-    0x81, 0x4E, 0x8A, 0x06, 0x8D, 0x0C, 0x0A, 0x11, 0x91, 0x2B, 0x2C, 0x0B, 0x37, 0x8F, 0x12, 0x01,
-    0x28, 0x1E, 0x02, 0x5C, 0x5D, 0x9D, 0x9E, 0x1B, 0x98, 0x2A, 0x1A, 0x48, 0x35, 0x33, 0x1D, 0x3C,
-    0x85, 0x16, 0x13, 0x4C, 0x66, 0x69, 0x68, 0x67, 0xAA, 0x62, 0x63, 0x5A, 0x5B, 0xAB, 0x84, 0x4A,
-    0x4B, 0x49, 0x58, 0x59, 0x42, 0x83, 0x15};
+struct pokemon_lut pokemon_table[] = {
+	{ "Bulbasaur",	&I_bulbasaur,	0x99 },
+	{ "Ivysaur",	&I_ivysaur,	0x09 },
+	{ "Venusaur",	&I_venusaur,	0x9A },
+	{ "Charmander",	&I_charmander,	0xB0 },
+	{ "Charmeleon",	&I_charmeleon,	0xB2 },
+	{ "Charizard",	&I_charizard,	0xB4 },
+	{ "Squirtle",	&I_squirtle,	0xB1 },
+	{ "Wartortle",	&I_wartortle,	0xB3 },
+	{ "Blastoise",	&I_blastoise,	0x1C },
+	{ "Caterpie",	&I_caterpie,	0x7B },
+	{ "Metapod",	&I_metapod,	0x7C },
+	{ "Butterfree",	&I_butterfree,	0x7D },
+	{ "Weedle",	&I_weedle,	0x70 },
+	{ "Kakuna",	&I_kakuna,	0x71 },
+	{ "Beedrill",	&I_beedrill,	0x72 },
+	{ "Pidgey",	&I_pidgey,	0x24 },
+	{ "Pidgeotto",	&I_pidgeotto,	0x96 },
+	{ "Pidgeot",	&I_pidgeot,	0x97 },
+	{ "Rattata",	&I_rattata,	0xA5 },
+	{ "Raticate",	&I_raticate,	0xA6 },
+	{ "Spearow",	&I_spearow,	0x05 },
+	{ "Fearow",	&I_fearow,	0x23 },
+	{ "Ekans",	&I_ekans,	0x6C },
+	{ "Arbok",	&I_arbok,	0x2D },
+	{ "Pikachu",	&I_pikachu,	0x54 },
+	{ "Raichu",	&I_raichu,	0x55 },
+	{ "Sandshrew",	&I_sandshrew,	0x60 },
+	{ "Sandslash",	&I_sandslash,	0x61 },
+	{ "Nidoran ♀",	&I_nidoranf,	0x0F },
+	{ "Nidorina",	&I_nidorina,	0xA8 },
+	{ "Nidoqueen",	&I_nidoqueen,	0x10 },
+	{ "Nidoran ♂",	&I_nidoranm,	0x03 },
+	{ "Nidorino",	&I_nidorino,	0xA7 },
+	{ "Nidoking",	&I_nidoking,	0x07 },
+	{ "Clefairy",	&I_clefairy,	0x04 },
+	{ "Clefable",	&I_clefable,	0x8E },
+	{ "Vulpix",	&I_vulpix,	0x52 },
+	{ "Ninetales",	&I_ninetales,	0x53 },
+	{ "Jigglypuff",	&I_jigglypuff,	0x64 },
+	{ "Wigglytuff",	&I_wigglytuff,	0x65 },
+	{ "Zubat",	&I_zubat,	0x6B },
+	{ "Golbat",	&I_golbat,	0x82 },
+	{ "Oddish",	&I_oddish,	0xB9 },
+	{ "Gloom",	&I_gloom,	0xBA },
+	{ "Vileplume",	&I_vileplume,	0xBB },
+	{ "Paras",	&I_paras,	0x6D },
+	{ "Parasect",	&I_parasect,	0x2E },
+	{ "Venonat",	&I_venonat,	0x41 },
+	{ "Venomoth",	&I_venomoth,	0x77 },
+	{ "Diglett",	&I_diglett,	0x3B },
+	{ "Dugtrio",	&I_dugtrio,	0x76 },
+	{ "Meowth",	&I_meowth,	0x4D },
+	{ "Persian",	&I_persian,	0x90 },
+	{ "Psyduck",	&I_psyduck,	0x2F },
+	{ "Golduck",	&I_golduck,	0x80 },
+	{ "Mankey",	&I_mankey,	0x39 },
+	{ "Primeape",	&I_primeape,	0x75 },
+	{ "Growlithe",	&I_growlithe,	0x21 },
+	{ "Arcanine",	&I_arcanine,	0x14 },
+	{ "Poliwag",	&I_poliwag,	0x47 },
+	{ "Poliwhirl",	&I_poliwhirl,	0x6E },
+	{ "Poliwrath",	&I_poliwrath,	0x6F },
+	{ "Abra",	&I_abra,	0x94 },
+	{ "Kadabra",	&I_kadabra,	0x26 },
+	{ "Alakazam",	&I_alakazam,	0x95 },
+	{ "Machop",	&I_machop,	0x6A },
+	{ "Machoke",	&I_machoke,	0x29 },
+	{ "Machamp",	&I_machamp,	0x7E },
+	{ "Bellsprout",	&I_bellsprout,	0xBC },
+	{ "Weepinbell",	&I_weepinbell,	0xBD },
+	{ "Victreebel",	&I_victreebel,	0xBE },
+	{ "Tentacool",	&I_tentacool,	0x18 },
+	{ "Tentacruel",	&I_tentacruel,	0x9B },
+	{ "Geodude",	&I_geodude,	0xA9 },
+	{ "Graveler",	&I_graveler,	0x27 },
+	{ "Golem",	&I_golem,	0x31 },
+	{ "Ponyta",	&I_ponyta,	0xA3 },
+	{ "Rapidash",	&I_rapidash,	0xA4 },
+	{ "Slowpoke",	&I_slowpoke,	0x25 },
+	{ "Slowbro",	&I_slowbro,	0x08 },
+	{ "Magnemite",	&I_magnemite,	0xAD },
+	{ "Magneton",	&I_magneton,	0x36 },
+	{ "Farfetch'd",	&I_farfetchd,	0x40 },
+	{ "Doduo",	&I_doduo,	0x46 },
+	{ "Dodrio",	&I_dodrio,	0x74 },
+	{ "Seel",	&I_seel,	0x3A },
+	{ "Dewgong",	&I_dewgong,	0x78 },
+	{ "Grimer",	&I_grimer,	0x0D },
+	{ "Muk",	&I_muk,	        0x88 },
+	{ "Shellder",	&I_shellder,	0x17 },
+	{ "Cloyster",	&I_cloyster,	0x8B },
+	{ "Gastly",	&I_gastly,	0x19 },
+	{ "Haunter",	&I_haunter,	0x93 },
+	{ "Gengar",	&I_gengar,	0x0E },
+	{ "Onix",	&I_onix,	0x22 },
+	{ "Drowzee",	&I_drowzee,	0x30 },
+	{ "Hypno",	&I_hypno,	0x81 },
+	{ "Krabby",	&I_krabby,	0x4E },
+	{ "Kingler",	&I_kingler,	0x8A },
+	{ "Voltorb",	&I_voltorb,	0x06 },
+	{ "Electrode",	&I_electrode,	0x8D },
+	{ "Exeggcute",	&I_exeggcute,	0x0C },
+	{ "Exeggutor",	&I_exeggutor,	0x0A },
+	{ "Cubone",	&I_cubone,	0x11 },
+	{ "Marowak",	&I_marowak,	0x91 },
+	{ "Hitmonlee",	&I_hitmonlee,	0x2B },
+	{ "Hitmonchan",	&I_hitmonchan,	0x2C },
+	{ "Lickitung",	&I_lickitung,	0x0B },
+	{ "Koffing",	&I_koffing,	0x37 },
+	{ "Weezing",	&I_weezing,	0x8F },
+	{ "Rhyhorn",	&I_rhyhorn,	0x12 },
+	{ "Rhydon",	&I_rhydon,	0x01 },
+	{ "Chansey",	&I_chansey,	0x28 },
+	{ "Tangela",	&I_tangela,	0x1E },
+	{ "Kangaskhan",	&I_kangaskhan,	0x02 },
+	{ "Horsea",	&I_horsea,	0x5C },
+	{ "Seadra",	&I_seadra,	0x5D },
+	{ "Goldeen",	&I_goldeen,	0x9D },
+	{ "Seaking",	&I_seaking,	0x9E },
+	{ "Staryu",	&I_staryu,	0x1B },
+	{ "Starmie",	&I_starmie,	0x98 },
+	{ "Mr. Mime",	&I_mr_mime,	0x2A },
+	{ "Scyther",	&I_scyther,	0x1A },
+	{ "Jynx",	&I_jynx,	0x48 },
+	{ "Electabuzz",	&I_electabuzz,	0x35 },
+	{ "Magmar",	&I_magmar,	0x33 },
+	{ "Pinsir",	&I_pinsir,	0x1D },
+	{ "Tauros",	&I_tauros,	0x3C },
+	{ "Magikarp",	&I_magikarp,	0x85 },
+	{ "Gyarados",	&I_gyarados,	0x16 },
+	{ "Lapras",	&I_lapras,	0x13 },
+	{ "Ditto",	&I_ditto,	0x4C },
+	{ "Eevee",	&I_eevee,	0x66 },
+	{ "Vaporeon",	&I_vaporeon,	0x69 },
+	{ "Jolteon",	&I_jolteon,	0x68 },
+	{ "Flareon",	&I_flareon,	0x67 },
+	{ "Porygon",	&I_porygon,	0xAA },
+	{ "Omanyte",	&I_omanyte,	0x62 },
+	{ "Omastar",	&I_omastar,	0x63 },
+	{ "Kabuto",	&I_kabuto,	0x5A },
+	{ "Kabutops",	&I_kabutops,	0x5B },
+	{ "Aerodactyl",	&I_aerodactyl,	0xAB },
+	{ "Snorlax",	&I_snorlax,	0x84 },
+	{ "Articuno",	&I_articuno,	0x4A },
+	{ "Zapdos",	&I_zapdos,	0x4B },
+	{ "Moltres",	&I_moltres,	0x49 },
+	{ "Dratini",	&I_dratini,	0x58 },
+	{ "Dragonair",	&I_dragonair,	0x59 },
+	{ "Dragonite",	&I_dragonite,	0x42 },
+	{ "Mewtwo",	&I_mewtwo,	0x83 },
+	{ "Mew",	&I_mew,	        0x15 },
+	{ },
+};
 
 uint32_t pokemon_exit_confirm_view(void* context) {
     UNUSED(context);

+ 8 - 4
pokemon_app.h

@@ -15,6 +15,12 @@
 
 #define TAG "Pokemon"
 
+struct pokemon_lut {
+	const char *name;
+	const Icon *icon;
+	const uint8_t hex;
+};
+
 typedef struct App App;
 typedef enum {
     GAMEBOY_INITIAL,
@@ -54,8 +60,6 @@ typedef struct SelectPokemonModel {
     void* callback_context;
 } SelectPokemonModel;
 
-extern const char* pokemon_names[];
-extern const Icon* pokemon_icons[];
-extern const unsigned char pokemon_hex_codes[];
+extern struct pokemon_lut pokemon_table[];
 
-#endif /* POKEMON_APP_H */
+#endif /* POKEMON_APP_H */

+ 4 - 4
views/select_pokemon.cpp

@@ -8,7 +8,7 @@ static void select_pokemon_render_callback(Canvas* canvas, void* context) {
     const uint8_t current_index = model->current_pokemon;
     char pokedex_num[5];
 
-    snprintf(hex_str, sizeof(hex_str), "#%03d", current_index+1);
+    snprintf(pokedex_num, sizeof(pokedex_num), "#%03d", current_index+1);
     canvas_set_font(canvas, FontPrimary);
     canvas_draw_str_aligned(
         canvas,
@@ -16,11 +16,11 @@ static void select_pokemon_render_callback(Canvas* canvas, void* context) {
         54 / 2,
         AlignLeft,
         AlignTop,
-	pokemon_names[current_index]);
+	pokemon_table[current_index].name);
 
     canvas_set_font(canvas, FontSecondary);
     canvas_draw_str_aligned(canvas, 55, 38, AlignLeft, AlignTop, pokedex_num);
-    canvas_draw_icon(canvas, 0, 0, pokemon_icons[current_index]);
+    canvas_draw_icon(canvas, 0, 0, pokemon_table[current_index].icon);
     canvas_draw_icon(canvas, 128 - 80, 0, &I_Space_80x18);
     canvas_draw_str_aligned(canvas, (128 - 40), 5, AlignCenter, AlignTop, "Select Pokemon");
 
@@ -40,7 +40,7 @@ static bool select_pokemon_input_callback(InputEvent* event, void* context) {
             model,
             {
                 select_pokemon->app->current_pokemon = model->current_pokemon;
-                select_pokemon->app->pokemon_hex_code = pokemon_hex_codes[model->current_pokemon];
+                select_pokemon->app->pokemon_hex_code = pokemon_table[model->current_pokemon].hex;
             },
             false);
         view_dispatcher_switch_to_view(select_pokemon->app->view_dispatcher, AppViewTrade);

+ 1 - 1
views/trade.cpp

@@ -60,7 +60,7 @@ static void trade_draw_callback(Canvas* canvas, void* context) {
         } else if(
             model->gameboy_status == GAMEBOY_READY || model->gameboy_status == GAMEBOY_WAITING ||
             model->gameboy_status == GAMEBOY_SEND) {
-            canvas_draw_icon(canvas, 38, 11, pokemon_icons[model->current_pokemon]);
+            canvas_draw_icon(canvas, 38, 11, pokemon_table[model->current_pokemon].icon);
         }
         canvas_draw_icon(canvas, 0, 53, &I_Background_128x11);