Skip to content

Commit

Permalink
easyrpg_raw: rebase and adapt old code + preparations for future feat…
Browse files Browse the repository at this point in the history
…ures
  • Loading branch information
jetrotal committed Nov 21, 2023
1 parent 91288ad commit fcd862e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -1345,12 +1345,17 @@ class Constants {
};

// Function to retrieve a value from mapCollection ignoring case
std::string get(const std::string& mapName, const std::string& key) {
std::string get(const std::string& mapName, const std::string& key, bool convertMode = 0 ) {
std::unordered_map<std::string, int>& selectedMap = MapCollection(mapName);

for (auto it = selectedMap.begin(); it != selectedMap.end(); ++it)
if ( Utils::StrICmp(it->first, key) == 0 ) return std::to_string(it->second);
if (convertMode == 0) // Name 2 ID
for (auto it = selectedMap.begin(); it != selectedMap.end(); ++it)
if ( Utils::StrICmp(it->first, key) == 0 ) return std::to_string(it->second);

return key; // Key not found
if (convertMode == 1) // ID 2 Name
for (auto it = selectedMap.begin(); it != selectedMap.end(); ++it)
if (Utils::StrICmp(std::to_string(it->second), key) == 0) return it->first;

return key; // Match not found
}
};
3 changes: 2 additions & 1 deletion src/game_dynrpg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ static std::string ParseToken(std::string token, StringView function_name) {
return ToString(Main_Data::game_actors->GetActor(number)->GetName());
} else if (*it == 'T' && Player::IsPatchManiac()) {
// T (String Var) is last
return Main_Data::game_strings->Get(number);
std::string output(Main_Data::game_strings->Get(number));
return output;
} else {
// Variable
number = Main_Data::game_variables->Get(number);
Expand Down

0 comments on commit fcd862e

Please sign in to comment.