Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
426 changes: 426 additions & 0 deletions SerialPrograms/Source/Pokemon/Inference/Pokemon_TypeReader.cpp

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions SerialPrograms/Source/Pokemon/Inference/Pokemon_TypeReader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* Type Reader
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_Pokemon_TypeReader_H
#define PokemonAutomation_Pokemon_TypeReader_H

#include <map>
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
#include "CommonFramework/ImageTools/ImageBoxes.h"
#include "Pokemon/Pokemon_Types.h"

namespace PokemonAutomation {
namespace Pokemon {

// The style of type symbols.
// GEN8: SWSH, Needs testing: LGPE
// GEN9: SV, LZA, HOME(Currently), Needs testing: Champions, LA, BDSP
enum class PokemonTypeGeneration{
GEN8,
GEN9,
};

// Find all type symbols inside the image.
std::multimap<double, std::pair<PokemonType, ImagePixelBox>> find_type_symbols(
const ImageViewPlanar32& original_screen,
const ImageViewRGB32& image,
double max_area_ratio,
PokemonTypeGeneration generation
);

// Reads the types of a Pokemon. Second type will be PokemonType::NONE if the Pokemon is single-type
std::pair<PokemonType, PokemonType> read_pokemon_types(
const ImageViewRGB32& original_screen,
const ImageFloatBox& box,
PokemonTypeGeneration generation
);

}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const EnumDropdownDatabase<SortingRuleType>& SortingRuleType_Database(){
{SortingRuleType::Alpha, "alpha", "Alpha"},
{SortingRuleType::Ball_Slug, "ball_slug", "Ball Type"},
{SortingRuleType::Gender, "gender", "Gender (Male, Female, Genderless)"},
//{SortingRuleType::Type, "type", "Types"}, Mainly used for testing. The order of the PokemonType Enum is not the most intuitive for sorting.
});
return database;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum class SortingRuleType
Alpha,
Ball_Slug,
Gender,
Type
};

struct SortingRule
Expand Down
17 changes: 15 additions & 2 deletions SerialPrograms/Source/Pokemon/Pokemon_CollectedPokemonInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "Pokemon/Pokemon_Strings.h"
#include "Pokemon/Pokemon_BoxCursor.h"
#include "Pokemon/Resources/Pokemon_PokemonNames.h"
#include "Pokemon/Resources/Pokemon_PokemonSlugs.h"
#include "Pokemon_CollectedPokemonInfo.h"

namespace PokemonAutomation{
Expand All @@ -27,7 +26,9 @@ bool operator==(const CollectedPokemonInfo& lhs, const CollectedPokemonInfo& rhs
lhs.alpha == rhs.alpha &&
lhs.ball_slug == rhs.ball_slug &&
lhs.gender == rhs.gender &&
lhs.ot_id == rhs.ot_id;
lhs.ot_id == rhs.ot_id &&
lhs.primaryType == rhs.primaryType &&
lhs.secondaryType == rhs.secondaryType;
}


Expand Down Expand Up @@ -73,6 +74,14 @@ bool operator<(const std::optional<CollectedPokemonInfo>& lhs, const std::option
return (lhs->gender < rhs->gender) != preference.reverse;
}
break;
case SortingRuleType::Type:
if (lhs->primaryType != rhs->primaryType){
return (lhs->primaryType < rhs->primaryType) != preference.reverse;
}
if (lhs->secondaryType != rhs->secondaryType){
return (lhs->secondaryType < rhs->secondaryType) != preference.reverse;
}
break;
default:
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "unknown SortingRuleType");
} // end switch
Expand All @@ -94,6 +103,8 @@ std::ostream& operator<<(std::ostream& os, const std::optional<CollectedPokemonI
os << "ball:" << pokemon->ball_slug << " ";
os << "gender:" << gender_to_string(pokemon->gender) << " ";
os << "ot_id:" << pokemon->ot_id << " ";
os << "primaryType:" << POKEMON_TYPE_SLUGS().get_string(pokemon->primaryType) << " ";
os << "secondaryType:" << POKEMON_TYPE_SLUGS().get_string(pokemon->secondaryType) << " ";
os << ")";
}else{
os << "(empty)";
Expand Down Expand Up @@ -144,6 +155,8 @@ void save_boxes_data_to_json(const std::vector<std::optional<CollectedPokemonInf
pokemon["ball"] = current_pokemon->ball_slug;
pokemon["gender"] = gender_to_string(current_pokemon->gender);
pokemon["ot_id"] = current_pokemon->ot_id;
pokemon["primaryType"] = POKEMON_TYPE_SLUGS().get_string(current_pokemon->primaryType);
pokemon["secondaryType"] = POKEMON_TYPE_SLUGS().get_string(current_pokemon->secondaryType);
}
pokemon_data.push_back(std::move(pokemon));
}
Expand Down
3 changes: 3 additions & 0 deletions SerialPrograms/Source/Pokemon/Pokemon_CollectedPokemonInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <ostream>
#include "Pokemon/Options/Pokemon_StatsHuntFilter.h"
#include "Pokemon/Options/Pokemon_BoxSortingTable.h"
#include "Pokemon_Types.h"

namespace PokemonAutomation{
namespace Pokemon{
Expand All @@ -31,6 +32,8 @@ struct CollectedPokemonInfo{
std::string ball_slug = "";
StatsHuntGenderFilter gender = StatsHuntGenderFilter::Genderless;
uint32_t ot_id = 0; // original trainer ID
PokemonType primaryType = PokemonType::NONE;
PokemonType secondaryType = PokemonType::NONE;
};

bool operator==(const CollectedPokemonInfo& lhs, const CollectedPokemonInfo& rhs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ language
#include "CommonTools/OCR/OCR_NumberReader.h"
#include "CommonTools/StartupChecks/StartProgramChecks.h"
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
#include "Pokemon/Inference/Pokemon_TypeReader.h"
#include "Pokemon/Pokemon_Strings.h"
#include "Pokemon/Resources/Pokemon_PokemonNames.h"
#include "Pokemon/Resources/Pokemon_PokemonSlugs.h"
Expand Down Expand Up @@ -401,6 +402,8 @@ void read_summary_screen(
ImageFloatBox nature_box(0.157, 0.783, 0.212, 0.042); // Nature
ImageFloatBox ability_box(0.158, 0.838, 0.213, 0.042); // Ability
ImageFloatBox alpha_box(0.787, 0.095, 0.024, 0.046); // Alpha symbol
ImageFloatBox type_box(0.615, 0.240, 0.071, 0.057); // Type symbols


video_overlay_set.add(COLOR_WHITE, national_dex_number_box);
video_overlay_set.add(COLOR_BLUE, shiny_symbol_box);
Expand Down Expand Up @@ -461,7 +464,12 @@ void read_summary_screen(
dump_image(env.console, ProgramInfo(), "ReadSummary_OT", screen);
}
cur_pokemon_info.ot_id = ot_id;


auto [primaryType, secondaryType] = read_pokemon_types(screen, type_box, PokemonTypeGeneration::GEN9);

cur_pokemon_info.primaryType = primaryType;
cur_pokemon_info.secondaryType = secondaryType;

env.add_overlay_log(create_overlay_info(cur_pokemon_info));
video_overlay_set.clear();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "CommonTools/VisualDetectors/FrozenImageDetector.h"
#include "CommonTools/StartupChecks/StartProgramChecks.h"
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
#include "Pokemon/Inference/Pokemon_TypeReader.h"
#include "Pokemon/Pokemon_Strings.h"
#include "Pokemon/Resources/Pokemon_PokemonNames.h"
#include "Pokemon/Pokemon_BoxCursor.h"
Expand Down Expand Up @@ -319,13 +320,16 @@ void BoxSorter::program(SingleSwitchProgramEnvironment& env, ProControllerContex
name_slug = LUMIOSE_DEX_SLUGS()[dex_number-1];
}

auto [primaryType, secondaryType] = read_pokemon_types(screen, ImageFloatBox(0.467, 0.256, 0.110, 0.041), PokemonTypeGeneration::GEN9);
boxes_data.push_back(
CollectedPokemonInfo{
.preferences = &sort_preferences,
.dex_number = static_cast<uint16_t>(dex_number),
.name_slug = name_slug,
.shiny = shiny_detector.detect(screen),
.alpha = alpha_detector.detect(screen),
.primaryType = primaryType,
.secondaryType = secondaryType,
}
);
ss << "\u2705 " ; // checkbox
Expand Down
Loading