Compare commits

..

No commits in common. "dc95076faa2a597c33252fa29a9dc93329d97be6" and "44305a0068df6a97cb3db352652f24430f4f27aa" have entirely different histories.

2 changed files with 38 additions and 43 deletions

View File

@ -66,17 +66,6 @@ unsigned int find_leaderboard(std::string name)
return 0; return 0;
} }
nlohmann::detail::iter_impl<nlohmann::json> defined_achievements_find(std::string key)
{
return std::find_if(defined_achievements.begin(), defined_achievements.end(), [key](nlohmann::json& item) {
std::string name = static_cast<std::string const&>(item["name"]);
return key.size() == name.size() && std::equal(name.begin(), name.end(), key.begin(),
[](char a, char b) {
return tolower(a) == tolower(b);
});
});
}
void load_achievements_db() void load_achievements_db()
{ {
std::string file_path = Local_Storage::get_game_settings_path() + achievements_user_file; std::string file_path = Local_Storage::get_game_settings_path() + achievements_user_file;
@ -238,10 +227,10 @@ bool GetAchievement( const char *pchName, bool *pbAchieved )
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
try { try {
auto it = defined_achievements_find(pchName); auto it = std::find_if(defined_achievements.begin(), defined_achievements.end(), [pchName]( nlohmann::json &item ) {
std::string pch_name = it->value("name", std::string()); return item["name"].get<std::string>() == pchName;
});
auto ach = user_achievements.find(pch_name); auto ach = user_achievements.find(pchName);
if (it != defined_achievements.end() && ach != user_achievements.end()) { if (it != defined_achievements.end() && ach != user_achievements.end()) {
if(pbAchieved != nullptr) *pbAchieved = (*ach)["earned"]; if(pbAchieved != nullptr) *pbAchieved = (*ach)["earned"];
return true; return true;
@ -260,13 +249,13 @@ bool SetAchievement( const char *pchName )
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
try { try {
auto it = defined_achievements_find(pchName); auto it = std::find_if(defined_achievements.begin(), defined_achievements.end(), [pchName](nlohmann::json& item) {
std::string pch_name = it->value("name", std::string()); return item["name"].get<std::string>() == pchName;
});
if (it != defined_achievements.end()) { if (it != defined_achievements.end()) {
if (user_achievements.find(pch_name) == user_achievements.end() || user_achievements[pch_name].value("earned", false) == false) { if (user_achievements.find(pchName) == user_achievements.end() || user_achievements[pchName].value("earned", false) == false) {
user_achievements[pch_name]["earned"] = true; user_achievements[pchName]["earned"] = true;
user_achievements[pch_name]["earned_time"] = std::chrono::duration_cast<std::chrono::duration<uint32>>(std::chrono::system_clock::now().time_since_epoch()).count(); user_achievements[pchName]["earned_time"] = std::chrono::duration_cast<std::chrono::duration<uint32>>(std::chrono::system_clock::now().time_since_epoch()).count();
#ifdef EMU_OVERLAY #ifdef EMU_OVERLAY
overlay->AddAchievementNotification(it.value()); overlay->AddAchievementNotification(it.value());
#endif #endif
@ -287,12 +276,12 @@ bool ClearAchievement( const char *pchName )
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
try { try {
auto it = defined_achievements_find(pchName); auto it = std::find_if(defined_achievements.begin(), defined_achievements.end(), [pchName](nlohmann::json& item) {
std::string pch_name = it->value("name", std::string()); return static_cast<std::string const&>(item["name"]) == pchName;
});
if (it != defined_achievements.end()) { if (it != defined_achievements.end()) {
user_achievements[pch_name]["earned"] = false; user_achievements[pchName]["earned"] = false;
user_achievements[pch_name]["earned_time"] = static_cast<uint32>(0); user_achievements[pchName]["earned_time"] = static_cast<uint32>(0);
save_achievements(); save_achievements();
return true; return true;
} }
@ -312,10 +301,10 @@ bool GetAchievementAndUnlockTime( const char *pchName, bool *pbAchieved, uint32
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
try { try {
auto it = defined_achievements_find(pchName); auto it = std::find_if(defined_achievements.begin(), defined_achievements.end(), [pchName](nlohmann::json& item) {
std::string pch_name = it->value("name", std::string()); return static_cast<std::string const&>(item["name"]) == pchName;
});
auto ach = user_achievements.find(pch_name); auto ach = user_achievements.find(pchName);
if (it != defined_achievements.end() && ach != user_achievements.end()) { if (it != defined_achievements.end() && ach != user_achievements.end()) {
if(pbAchieved != nullptr) *pbAchieved = (*ach)["earned"]; if(pbAchieved != nullptr) *pbAchieved = (*ach)["earned"];
if(punUnlockTime != nullptr) *punUnlockTime = (*ach)["earned_time"]; if(punUnlockTime != nullptr) *punUnlockTime = (*ach)["earned_time"];
@ -378,7 +367,9 @@ const char * GetAchievementDisplayAttribute( const char *pchName, const char *pc
if (strcmp (pchKey, "name") == 0) { if (strcmp (pchKey, "name") == 0) {
try { try {
auto it = defined_achievements_find(pchName); auto it = std::find_if(defined_achievements.begin(), defined_achievements.end(), [pchName](nlohmann::json& item) {
return static_cast<std::string const&>(item["name"]) == pchName;
});
if (it != defined_achievements.end()) { if (it != defined_achievements.end()) {
return it.value()["displayName"].get_ptr<std::string*>()->c_str(); return it.value()["displayName"].get_ptr<std::string*>()->c_str();
} }
@ -387,7 +378,9 @@ const char * GetAchievementDisplayAttribute( const char *pchName, const char *pc
if (strcmp (pchKey, "desc") == 0) { if (strcmp (pchKey, "desc") == 0) {
try { try {
auto it = defined_achievements_find(pchName); auto it = std::find_if(defined_achievements.begin(), defined_achievements.end(), [pchName](nlohmann::json& item) {
return static_cast<std::string const&>(item["name"]) == pchName;
});
if (it != defined_achievements.end()) { if (it != defined_achievements.end()) {
return it.value()["description"].get_ptr<std::string*>()->c_str(); return it.value()["description"].get_ptr<std::string*>()->c_str();
} }
@ -396,7 +389,9 @@ const char * GetAchievementDisplayAttribute( const char *pchName, const char *pc
if (strcmp (pchKey, "hidden") == 0) { if (strcmp (pchKey, "hidden") == 0) {
try { try {
auto it = defined_achievements_find(pchName); auto it = std::find_if(defined_achievements.begin(), defined_achievements.end(), [pchName](nlohmann::json& item) {
return static_cast<std::string const&>(item["name"]) == pchName;
});
if (it != defined_achievements.end()) { if (it != defined_achievements.end()) {
return it.value()["hidden"].get_ptr<std::string*>()->c_str(); return it.value()["hidden"].get_ptr<std::string*>()->c_str();
} }
@ -411,15 +406,15 @@ const char * GetAchievementDisplayAttribute( const char *pchName, const char *pc
// Calling this w/ N out of N progress will NOT set the achievement, the game must still do that. // Calling this w/ N out of N progress will NOT set the achievement, the game must still do that.
bool IndicateAchievementProgress( const char *pchName, uint32 nCurProgress, uint32 nMaxProgress ) bool IndicateAchievementProgress( const char *pchName, uint32 nCurProgress, uint32 nMaxProgress )
{ {
PRINT_DEBUG("IndicateAchievementProgress %s\n", pchName); PRINT_DEBUG("IndicateAchievementProgress\n");
if (pchName == nullptr) return false; if (pchName == nullptr) return false;
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
try { try {
auto it = defined_achievements_find(pchName); auto it = std::find_if(defined_achievements.begin(), defined_achievements.end(), [pchName](nlohmann::json& item) {
std::string pch_name = it->value("name", std::string()); return static_cast<std::string const&>(item["name"]) == pchName;
});
auto ach = user_achievements.find(pch_name); auto ach = user_achievements.find(pchName);
if (it != defined_achievements.end()) { if (it != defined_achievements.end()) {
bool achieved = false; bool achieved = false;
if ( ach != user_achievements.end()) { if ( ach != user_achievements.end()) {
@ -429,14 +424,14 @@ bool IndicateAchievementProgress( const char *pchName, uint32 nCurProgress, uint
UserAchievementStored_t data = {}; UserAchievementStored_t data = {};
data.m_nGameID = settings->get_local_game_id().ToUint64(); data.m_nGameID = settings->get_local_game_id().ToUint64();
data.m_bGroupAchievement = false; data.m_bGroupAchievement = false;
strncpy(data.m_rgchAchievementName, pch_name.c_str(), k_cchStatNameMax); strncpy(data.m_rgchAchievementName, pchName, k_cchStatNameMax);
if (achieved) { if (achieved) {
data.m_nCurProgress = 0; data.m_nCurProgress = 0;
data.m_nMaxProgress = 0; data.m_nMaxProgress = 0;
} else { } else {
user_achievements[pch_name]["progress"] = nCurProgress; user_achievements[pchName]["progress"] = nCurProgress;
user_achievements[pch_name]["max_progress"] = nMaxProgress; user_achievements[pchName]["max_progress"] = nMaxProgress;
data.m_nCurProgress = nCurProgress; data.m_nCurProgress = nCurProgress;
data.m_nMaxProgress = nMaxProgress; data.m_nMaxProgress = nMaxProgress;
} }

View File

@ -698,7 +698,7 @@ void Steam_Overlay::Callback(Common_Message *msg)
{ {
Steam_Messages const& steam_message = msg->steam_messages(); Steam_Messages const& steam_message = msg->steam_messages();
// Change color to cyan for friend // Change color to cyan for friend
friend_info->second.chat_history.append(steam_message.message()).append("\n", 1); friend_info->second.chat_history.append("\x1""00FFFFFF", 9).append(steam_message.message()).append("\n", 1);
if (!(friend_info->second.window_state & window_state_show)) if (!(friend_info->second.window_state & window_state_show))
{ {
friend_info->second.window_state |= window_state_need_attention; friend_info->second.window_state |= window_state_need_attention;
@ -758,7 +758,7 @@ void Steam_Overlay::RunCallbacks()
msg.set_dest_id(friend_id); msg.set_dest_id(friend_id);
network->sendTo(&msg, true); network->sendTo(&msg, true);
friend_info->second.chat_history.append(input).append("\n", 1); friend_info->second.chat_history.append("\x1""00FF00FF", 9).append(input).append("\n", 1);
} }
*input = 0; // Reset the input field *input = 0; // Reset the input field
friend_info->second.window_state &= ~window_state_send_message; friend_info->second.window_state &= ~window_state_send_message;