Add avatar image loading from global ...

... settings directory.

Also adds some additional related debug logging, and a utility function
for converting between std::vector<image_pixel_t> used by Local_Storage::load_image(),
and std::string used by Settings::add_image().
This commit is contained in:
redpolline 2024-11-25 00:50:40 -05:00
parent 0eaba52f76
commit d493e30b98
4 changed files with 58 additions and 1 deletions

View File

@ -34,6 +34,19 @@ struct File_Data {
std::string name;
};
std::string convert_vector_image_pixel_t_to_std_string(std::vector<image_pixel_t> & in) {
std::string out;
for (auto i : in) {
out += i.channels.r;
out += i.channels.g;
out += i.channels.b;
out += i.channels.a;
}
return out;
}
#ifdef NO_DISK_WRITES
std::string Local_Storage::get_program_path()
{
@ -807,6 +820,10 @@ std::vector<image_pixel_t> Local_Storage::load_image(std::string const& image_pa
std::copy(img, img + width * height, res.begin());
stbi_image_free(img);
} else {
width = 0;
height = 0;
PRINT_DEBUG("%s %s. reason: %s\n", "Failed to load image at", image_path.c_str(), stbi_failure_reason());
}
if (out_width != nullptr) {
if (width > 0) {

View File

@ -41,6 +41,8 @@ struct image_t
std::vector<image_pixel_t> pix_map;
};
std::string convert_vector_image_pixel_t_to_std_string(std::vector<image_pixel_t> & in);
class Local_Storage {
public:
static constexpr auto inventory_storage_folder = "inventory";

View File

@ -340,15 +340,32 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s
bool warn_forced = false;
Image_Data profile_small;
Image_Data profile_medium;
Image_Data profile_large;
{
std::string steam_settings_path = local_storage->get_global_settings_path();
std::vector<std::string> paths = local_storage->get_filenames_path(steam_settings_path);
for (auto & p: paths) {
PRINT_DEBUG("global settings path %s\n", p.c_str());
if (p == "enable_achievement_desc_on_unlock.txt") {
enable_achievement_desc_on_unlock = true;
} else if (p == "enable_displaying_hidden_achievements.txt") {
enable_displaying_hidden_achievements = true;
} else if (p == "profile_small.jpg") {
profile_small.data = convert_vector_image_pixel_t_to_std_string(local_storage->load_image(steam_settings_path + p, &profile_small.width, &profile_small.height));
} else if (p == "profile_medium.jpg") {
profile_medium.data = convert_vector_image_pixel_t_to_std_string(local_storage->load_image(steam_settings_path + p, &profile_medium.width, &profile_medium.height));
} else if (p == "profile_large.jpg") {
profile_large.data = convert_vector_image_pixel_t_to_std_string(local_storage->load_image(steam_settings_path + p, &profile_large.width, &profile_large.height));
} else if (p == "profile_small.png") {
profile_small.data = convert_vector_image_pixel_t_to_std_string(local_storage->load_image(steam_settings_path + p, &profile_small.width, &profile_small.height));
} else if (p == "profile_medium.png") {
profile_medium.data = convert_vector_image_pixel_t_to_std_string(local_storage->load_image(steam_settings_path + p, &profile_medium.width, &profile_medium.height));
} else if (p == "profile_large.png") {
profile_large.data = convert_vector_image_pixel_t_to_std_string(local_storage->load_image(steam_settings_path + p, &profile_large.width, &profile_large.height));
}
}
}
@ -433,6 +450,24 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s
settings_server->set_show_achievement_desc_on_unlock(enable_achievement_desc_on_unlock);
settings_client->set_show_achievement_hidden_unearned(enable_displaying_hidden_achievements);
settings_server->set_show_achievement_hidden_unearned(enable_displaying_hidden_achievements);
if (profile_small.data.length() > 0 && profile_small.width > 0 && profile_small.height > 0) {
settings_client->set_profile_image(k_EAvatarSize32x32, &profile_small);
settings_server->set_profile_image(k_EAvatarSize32x32, &profile_small);
} else {
PRINT_DEBUG("%s %"PRI_ZU" %d %d\n", "Small user profile image not defined.", profile_small.data.length(), profile_small.width, profile_small.height);
}
if (profile_medium.data.length() > 0 && profile_medium.width > 0 && profile_medium.height > 0) {
settings_client->set_profile_image(k_EAvatarSize64x64, &profile_medium);
settings_server->set_profile_image(k_EAvatarSize64x64, &profile_medium);
} else {
PRINT_DEBUG("%s %"PRI_ZU" %d %d\n", "Medium user profile image not defined.", profile_medium.data.length(), profile_medium.width, profile_medium.height);
}
if (profile_large.data.length() > 0 && profile_large.width > 0 && profile_large.height > 0) {
settings_client->set_profile_image(k_EAvatarSize184x184, &profile_large);
settings_server->set_profile_image(k_EAvatarSize184x184, &profile_large);
} else {
PRINT_DEBUG("%s %"PRI_ZU" %d %d\n", "Large user profile image not defined.", profile_large.data.length(), profile_large.width, profile_large.height);
}
{
std::string dlc_config_path = Local_Storage::get_game_settings_path() + "DLC.txt";

View File

@ -116,7 +116,10 @@ bool GetImageRGBA( int iImage, uint8 *pubDest, int nDestBufferSize )
if (image == settings->images.end()) return false;
unsigned size = image->second.data.size();
if (nDestBufferSize < size) size = nDestBufferSize;
if (nDestBufferSize < size) {
size = nDestBufferSize;
PRINT_DEBUG("GetImageRGBA %i Given buffer too small. Got 0x%x bytes. Need 0x%x bytes.", iImage, nDestBufferSize, size);
}
image->second.data.copy((char *)pubDest, nDestBufferSize);
return true;
}