55 */
66
77#include " Common/Cpp/Exceptions.h"
8+ #include " Common/Cpp/Json/JsonValue.h"
9+ #include " Common/Cpp/Json/JsonArray.h"
10+ #include " Common/Cpp/Json/JsonObject.h"
811#include " Pokemon/Pokemon_Strings.h"
12+ #include " Pokemon/Pokemon_BoxCursor.h"
913#include " Pokemon/Resources/Pokemon_PokemonNames.h"
1014#include " Pokemon/Resources/Pokemon_PokemonSlugs.h"
1115#include " Pokemon_CollectedPokemonInfo.h"
@@ -16,7 +20,8 @@ namespace Pokemon{
1620
1721bool operator ==(const CollectedPokemonInfo& lhs, const CollectedPokemonInfo& rhs){
1822 // NOTE edit when adding new struct members
19- return lhs.national_dex_number == rhs.national_dex_number &&
23+ return lhs.dex_number == rhs.dex_number &&
24+ lhs.name_slug == rhs.name_slug &&
2025 lhs.shiny == rhs.shiny &&
2126 lhs.gmax == rhs.gmax &&
2227 lhs.alpha == rhs.alpha &&
@@ -25,19 +30,7 @@ bool operator==(const CollectedPokemonInfo& lhs, const CollectedPokemonInfo& rhs
2530 lhs.ot_id == rhs.ot_id ;
2631}
2732
28- // Sort two pokemon slot. "Smaller" pokemon is placed closer to front.
29- // If a slot is empty, it is always larger than non-empty slot so all the empty slots are at end after sorting.
30- // For two pokemon, check each preference rule. If we cannot determine the order based on the first rule, go
31- // to the second rule, and so on.
32- // Available rules:
33- // - National dex number: smaller ID should be at front.
34- // - Shiny: shiny pokemon should be at front.
35- // - Gigantamax: Gigantamax pokemon should be at front.
36- // - Alpha: Alpha pokemon should be at front.
37- // - Ball slug: pokemon with a ball slug that's smaller in the alphabetical order should be at front.
38- // - Gender: Male should be at front, then comes female, and genderless is last
39- // Each rule type also has a "reverse" which if true, reverses above ordering for that rule type.
40- // If user does not give a preference ruleset, sort by national dex number.
33+
4134bool operator <(const std::optional<CollectedPokemonInfo>& lhs, const std::optional<CollectedPokemonInfo>& rhs){
4235 if (!lhs.has_value ()){ // lhs is empty
4336 return false ;
@@ -49,10 +42,10 @@ bool operator<(const std::optional<CollectedPokemonInfo>& lhs, const std::option
4942 for (const SortingRule& preference : *lhs->preferences ){
5043 switch (preference.sort_type ){
5144 // NOTE edit when adding new struct members
52- case SortingRuleType::NationalDexNo :
53- if (lhs->national_dex_number != rhs->national_dex_number ){
45+ case SortingRuleType::DexNo :
46+ if (lhs->dex_number != rhs->dex_number ){
5447 // we use (boolean != reverse) to apply the reverse effect
55- return (lhs->national_dex_number < rhs->national_dex_number ) != preference.reverse ;
48+ return (lhs->dex_number < rhs->dex_number ) != preference.reverse ;
5649 }
5750 break ;
5851 case SortingRuleType::Shiny:
@@ -85,20 +78,20 @@ bool operator<(const std::optional<CollectedPokemonInfo>& lhs, const std::option
8578 } // end switch
8679 } // end for preference
8780
88- // Default to sort by national dex number
89- return lhs->national_dex_number < rhs->national_dex_number ;
81+ // Default to sort by dex number
82+ return lhs->dex_number < rhs->dex_number ;
9083}
9184
9285std::ostream& operator <<(std::ostream& os, const std::optional<CollectedPokemonInfo>& pokemon)
9386{
9487 if (pokemon.has_value ()){
9588 // NOTE edit when adding new struct members
9689 os << " (" ;
97- os << " national_dex_number: " << pokemon->national_dex_number << " " ;
90+ os << " dex_id: " << pokemon->dex_number << " " << pokemon-> name_slug << " " ;
9891 os << " shiny:" << (pokemon->shiny ? " true" : " false" ) << " " ;
9992 os << " gmax:" << (pokemon->gmax ? " true" : " false" ) << " " ;
10093 os << " alpha:" << (pokemon->alpha ? " true" : " false" ) << " " ;
101- os << " ball_slug :" << pokemon->ball_slug << " " ;
94+ os << " ball :" << pokemon->ball_slug << " " ;
10295 os << " gender:" << gender_to_string (pokemon->gender ) << " " ;
10396 os << " ot_id:" << pokemon->ot_id << " " ;
10497 os << " )" ;
@@ -109,9 +102,10 @@ std::ostream& operator<<(std::ostream& os, const std::optional<CollectedPokemonI
109102}
110103
111104std::string create_overlay_info (const CollectedPokemonInfo& pokemon){
112- const std::string& species_slug = NATIONAL_DEX_SLUGS ()[pokemon.national_dex_number -1 ];
113- const std::string& display_name = get_pokemon_name (species_slug).display_name ();
114- std::string overlay_log = display_name;
105+ const std::string& display_name = get_pokemon_name (pokemon.name_slug ).display_name ();
106+ char dex_str[5 ];
107+ snprintf (dex_str, sizeof (dex_str), " %04d" , pokemon.dex_number );
108+ std::string overlay_log = std::string (dex_str) + " " + display_name;
115109 if (pokemon.gender == StatsHuntGenderFilter::Male){
116110 overlay_log += " " + UNICODE_MALE;
117111 } else if (pokemon.gender == StatsHuntGenderFilter::Female){
@@ -130,5 +124,32 @@ std::string create_overlay_info(const CollectedPokemonInfo& pokemon){
130124}
131125
132126
127+ void save_boxes_data_to_json (const std::vector<std::optional<CollectedPokemonInfo>>& boxes_data, const std::string& json_path){
128+ JsonArray pokemon_data;
129+ for (size_t slot_idx = 0 ; slot_idx < boxes_data.size (); slot_idx++){
130+ BoxCursor cursor (slot_idx);
131+ JsonObject pokemon;
132+ pokemon[" index" ] = slot_idx;
133+ pokemon[" box" ] = cursor.box ;
134+ pokemon[" row" ] = cursor.row ;
135+ pokemon[" column" ] = cursor.column ;
136+ const auto & current_pokemon = boxes_data[slot_idx];
137+ if (current_pokemon != std::nullopt ){
138+ // NOTE edit when adding new struct members
139+ pokemon[" name" ] = current_pokemon->name_slug ;
140+ pokemon[" dex" ] = current_pokemon->dex_number ;
141+ pokemon[" shiny" ] = current_pokemon->shiny ;
142+ pokemon[" gmax" ] = current_pokemon->gmax ;
143+ pokemon[" alpha" ] = current_pokemon->alpha ;
144+ pokemon[" ball" ] = current_pokemon->ball_slug ;
145+ pokemon[" gender" ] = gender_to_string (current_pokemon->gender );
146+ pokemon[" ot_id" ] = current_pokemon->ot_id ;
147+ }
148+ pokemon_data.push_back (std::move (pokemon));
149+ }
150+ pokemon_data.dump (json_path);
151+ }
152+
153+
133154}
134155}
0 commit comments