Fix incorrect achievements.json parsing.

The correct name for the locked achievement image is "icon_gray".

Also fix the debugging counters and properly check for an existing key
in the parsed json.
This commit is contained in:
redpolline 2025-02-12 07:11:01 -05:00
parent 08ceeb2419
commit 82e2abd117

View File

@ -151,10 +151,21 @@ void load_achievements_db()
for (auto & it : defined_achievements) { for (auto & it : defined_achievements) {
name = ""; name = "";
try { try {
name = static_cast<std::string const&>(it["name"]); auto name_it = it.find("name");
if (name_it != it.end()) {
name = static_cast<std::string const&>(*name_it);
}
if (name.length() > 0) { if (name.length() > 0) {
std::string normal = Local_Storage::get_game_settings_path() + static_cast<std::string const&>(it["icon"]); auto normal_it = it.find("icon");
std::string gray = Local_Storage::get_game_settings_path() + static_cast<std::string const&>(it["icongray"]); auto gray_it = it.find("icon_gray");
std::string normal = "";
std::string gray = "";
if (normal_it != it.end()) {
normal = Local_Storage::get_game_settings_path() + static_cast<std::string const&>(*normal_it);
}
if (gray_it != it.end()) {
gray = Local_Storage::get_game_settings_path() + static_cast<std::string const&>(*gray_it);
}
if (normal.length() > 0 && gray.length() > 0) { if (normal.length() > 0 && gray.length() > 0) {
uint32 normal_height = 0; uint32 normal_height = 0;
uint32 normal_width = 0; uint32 normal_width = 0;
@ -227,10 +238,10 @@ void load_achievements_db()
count, count,
corrupt_count, corrupt_count,
bad_count); bad_count);
PRINT_DEBUG("ignored %" PRIu64 " missing normal achivement images.\nignored %" PRIu64 " missing gray achivement images.\n", PRINT_DEBUG("ignored %" PRIu64 " missing normal achievement images.\nignored %" PRIu64 " missing gray achievement images.\n",
missing_normal_images, missing_normal_images,
missing_gray_images); missing_gray_images);
PRINT_DEBUG("ignored %" PRIu64 " unreadable normal achivement images.\nignored %" PRIu64 " unreadable gray achivement images.\n", PRINT_DEBUG("ignored %" PRIu64 " unreadable normal achievement images.\nignored %" PRIu64 " unreadable gray achievement images.\n",
unreadable_normal_images, unreadable_normal_images,
unreadable_gray_images); unreadable_gray_images);
} }