Skip to content

Commit 9c3b10d

Browse files
kichithewolfGin890
authored andcommitted
hyperspace reward names
1 parent 52c110f commit 9c3b10d

File tree

3 files changed

+150
-0
lines changed

3 files changed

+150
-0
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/* Hyperspace Reward Names
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#include <map>
8+
#include "Common/Cpp/Json/JsonValue.h"
9+
#include "Common/Cpp/Json/JsonArray.h"
10+
#include "Common/Cpp/Json/JsonObject.h"
11+
#include "CommonFramework/Globals.h"
12+
#include "PokemonLZA_HyperspaceRewardNames.h"
13+
14+
namespace PokemonAutomation{
15+
namespace NintendoSwitch{
16+
namespace PokemonLZA{
17+
18+
19+
struct HyperspaceRewardNamesDatabase{
20+
HyperspaceRewardNamesDatabase();
21+
22+
static const HyperspaceRewardNamesDatabase& instance(){
23+
static HyperspaceRewardNamesDatabase database;
24+
return database;
25+
}
26+
27+
static const std::string NULL_SLUG;
28+
std::vector<std::string> ordered_list;
29+
std::map<std::string, HyperspaceRewardNames> database;
30+
std::map<std::string, std::string> reverse_lookup;
31+
};
32+
const std::string HyperspaceRewardNamesDatabase::NULL_SLUG;
33+
34+
HyperspaceRewardNamesDatabase::HyperspaceRewardNamesDatabase()
35+
{
36+
// Load a list of tournament prize slugs in the desired order:
37+
// ["potion", "fresh-water", ... ]
38+
std::string path_slugs = RESOURCE_PATH() + "PokemonSV/AAT/TournamentPrizeList.json"; //TODO: Get reward list
39+
JsonValue json_slugs = load_json_file(path_slugs);
40+
JsonArray& slugs = json_slugs.to_array_throw(path_slugs);
41+
42+
// Load a map of tournament prize slugs to item names in all languages, e.g.:
43+
// {
44+
// "potion": {
45+
// "eng": "Potion",
46+
// "deu": "Trank",
47+
// ...
48+
// },
49+
// ....
50+
// }
51+
std::string path_disp = RESOURCE_PATH() + "PokemonSV/AAT/TournamentPrizeNameDisplay.json"; //TODO: Get reward list
52+
JsonValue json_disp = load_json_file(path_disp);
53+
JsonObject& item_disp = json_disp.to_object_throw(path_disp);
54+
55+
for (auto& item : slugs){
56+
std::string& slug = item.to_string_throw(path_slugs);
57+
58+
JsonObject& auction_item_name_dict = item_disp.get_object_throw(slug, path_disp);
59+
std::string& display_name = auction_item_name_dict.get_string_throw("eng", path_disp);
60+
61+
ordered_list.push_back(slug);
62+
database[std::move(slug)].m_display_name = std::move(display_name);
63+
}
64+
65+
for (const auto& item : database){
66+
reverse_lookup[item.second.m_display_name] = item.first;
67+
}
68+
}
69+
70+
const HyperspaceRewardNames& get_hyperspace_reward_name(const std::string& slug){
71+
const std::map<std::string, HyperspaceRewardNames>& database = HyperspaceRewardNamesDatabase::instance().database;
72+
auto iter = database.find(slug);
73+
if (iter == database.end()){
74+
throw InternalProgramError(
75+
nullptr, PA_CURRENT_FUNCTION,
76+
"Hyperspace reward slug not found in database: " + slug
77+
);
78+
}
79+
return iter->second;
80+
}
81+
const std::string& parse_hyperspace_reward_name(const std::string& display_name){
82+
const std::map<std::string, std::string>& database = HyperspaceRewardNamesDatabase::instance().reverse_lookup;
83+
auto iter = database.find(display_name);
84+
if (iter == database.end()){
85+
throw InternalProgramError(
86+
nullptr, PA_CURRENT_FUNCTION,
87+
"Hyperspace reward name not found in database: " + display_name
88+
);
89+
}
90+
return iter->second;
91+
}
92+
const std::string& parse_hyperspace_reward_name_nothrow(const std::string& display_name){
93+
const std::map<std::string, std::string>& database = HyperspaceRewardNamesDatabase::instance().reverse_lookup;
94+
auto iter = database.find(display_name);
95+
if (iter == database.end()){
96+
return HyperspaceRewardNamesDatabase::NULL_SLUG;
97+
}
98+
return iter->second;
99+
}
100+
101+
102+
const std::vector<std::string>& HYPERSPACE_REWARD_SLUGS(){
103+
return HyperspaceRewardNamesDatabase::instance().ordered_list;
104+
}
105+
106+
107+
}
108+
}
109+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* Hyperspace Reward Names
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_PokemonLZA_HyperspaceRewardNames_H
8+
#define PokemonAutomation_PokemonLZA_HyperspaceRewardNames_H
9+
10+
#include <string>
11+
#include <vector>
12+
13+
namespace PokemonAutomation{
14+
namespace NintendoSwitch{
15+
namespace PokemonLZA{
16+
17+
18+
class HyperspaceRewardNames{
19+
public:
20+
const std::string& display_name() const { return m_display_name; }
21+
22+
private:
23+
friend struct HyperspaceRewardNamesDatabase;
24+
25+
std::string m_display_name;
26+
};
27+
28+
29+
const HyperspaceRewardNames& get_hyperspace_reward_name(const std::string& slug);
30+
const std::string& parse_hyperspace_reward_name(const std::string& display_name);
31+
const std::string& parse_hyperspace_reward_name_nothrow(const std::string& display_name);
32+
33+
const std::vector<std::string>& HYPERSPACE_REWARD_SLUGS();
34+
35+
36+
}
37+
}
38+
}
39+
#endif

SerialPrograms/SourceFiles.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,6 +1686,8 @@ file(GLOB LIBRARY_SOURCES
16861686
Source/PokemonLZA/Programs/Trading/PokemonLZA_SelfBoxTrade.h
16871687
Source/PokemonLZA/Programs/Trading/PokemonLZA_TradeRoutines.cpp
16881688
Source/PokemonLZA/Programs/Trading/PokemonLZA_TradeRoutines.h
1689+
Source/PokemonLZA/Resources/PokemonLZA_HyperspaceRewardNames.cpp
1690+
Source/PokemonLZA/Resources/PokemonLZA_HyperspaceRewardNames.h
16891691
Source/PokemonRSE/Inference/Dialogs/PokemonRSE_DialogDetector.cpp
16901692
Source/PokemonRSE/Inference/Dialogs/PokemonRSE_DialogDetector.h
16911693
Source/PokemonRSE/Inference/PokemonRSE_ShinyNumberDetector.cpp

0 commit comments

Comments
 (0)