Skip to content

Commit

Permalink
dynRPG raw - fix for unsuported get<int>() function
Browse files Browse the repository at this point in the history
dynRPG raw - fix for unsuported get<int>() function
(Mac, Android, etc)...
  • Loading branch information
jetrotal committed Nov 1, 2023
1 parent 5259545 commit 6be0795
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ class Constants {
public:
std::map<std::string, std::map<std::string, std::variant<int, std::string>>> mapCollection;

Constants() {
mapCollection["DestinyScript"] = {
Constants() : mapCollection{
//DestinyScript
{"DestinyScript",{

// Activation/Deactivation
{"DISABLE", 0},
Expand Down Expand Up @@ -777,10 +778,10 @@ class Constants {
{"TERRAIN_EVENT_TRANSPARENT", 3},

// Special Text Parts
{"CR", "Chr(0x0D)"},
{"LF", "Chr(0x0A)"},
{"CRLF", "CR..LF"},
{"QUOTE", "\"\""},
{"CR", std::string("Chr(0x0D)")},
{"LF", std::string("Chr(0x0A)")},
{"CRLF", std::string("CR..LF")},
{"QUOTE", std::string("\"\"")},

// Text Colors
{"TEXTCOLOR_DEFAULT", 0},
Expand Down Expand Up @@ -1173,8 +1174,9 @@ class Constants {
{"CONDITIONLIMITATION_ATTACKENEMY", 2}, // LEGACY
{"STATELIMITATION_ATTACKALLY", 3},
{"CONDITIONLIMITATION_ATTACKALLY", 3} // LEGACY
};
mapCollection["EventCode"] = {
}},
//EventCode
{ "EventCode", {
{"END", 10},
{"CallCommonEvent", 1005},
{"ForceFlee", 1006},
Expand Down Expand Up @@ -1329,30 +1331,37 @@ class Constants {
{ "Maniac_AddMoveRoute", 3027 },
{ "Maniac_EditTile", 3028 },
{ "Maniac_ControlTextProcessing", 3029 }
};
};
}}
} {};

std::string get(const std::string& mapName, const std::string& key) {
// Use the find function to search for the map by name
auto mapIt = mapCollection.find(mapName);
if (mapIt != mapCollection.end()) {
// Use the map associated with the mapName to look up the key in a case-insensitive manner
auto& map = mapIt->second;
// Convert the search key and map keys to lowercase (or uppercase) for a case-insensitive search
// Convert the search key to lowercase for a case-insensitive search
std::string lowercaseKey = toLower(key);
for (auto it = map.begin(); it != map.end(); ++it) {
std::string lowercaseMapKey = toLower(it->first);
if (lowercaseMapKey == lowercaseKey) {
if (std::holds_alternative<std::string>(it->second)) {
return std::get<std::string>(it->second);
}
else {
return std::to_string(std::get<int>(it->second));
}
// Use std::visit to access the value stored in the variant
std::variant<int, std::string>& value = it->second;
std::string result;
std::visit([&result](auto&& arg) {
using T = std::decay_t<decltype(arg)>;
if constexpr (std::is_same_v<T, std::string>) {
result = arg;
}
else if constexpr (std::is_same_v<T, int>) {
result = std::to_string(arg);
}
}, value);
return result;
}
}
}
return "0"; // Key not found
return "0"; // 0 when Key not found
}

// Helper function to convert a string to lowercase
Expand Down

0 comments on commit 6be0795

Please sign in to comment.