mirror of
https://gitlab.com/Mr_Goldberg/goldberg_emulator
synced 2025-07-07 15:04:28 +08:00
Achievements support & inventory customization.
Added achievements support. Achievements are saved like real steam, see your inventory directory.(like items, uses a .json, tool can be used to dump achievements from steam public api). You will need a public apikey. (See https://steamcommunity.com/dev) Reworked item support to split inventory items to defined items.
This commit is contained in:
@ -20,6 +20,7 @@
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <iomanip>
|
||||
|
||||
struct File_Data {
|
||||
std::string name;
|
||||
@ -52,6 +53,11 @@ std::string Local_Storage::get_global_settings_path()
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string Local_Storage::get_global_inventory_path()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
Local_Storage::Local_Storage(std::string save_directory)
|
||||
{
|
||||
|
||||
@ -127,6 +133,16 @@ bool Local_Storage::update_save_filenames(std::string folder)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Local_Storage::load_inventory_file(nlohmann::json& json, std::string const&file)
|
||||
{
|
||||
return true
|
||||
}
|
||||
|
||||
bool Local_Storage::write_inventory_file(nlohmann::json const& json, std::string const&file)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<std::string> Local_Storage::get_filenames_path(std::string path)
|
||||
{
|
||||
return std::vector<std::string>();
|
||||
@ -378,7 +394,7 @@ std::string Local_Storage::get_program_path()
|
||||
|
||||
std::string Local_Storage::get_game_settings_path()
|
||||
{
|
||||
return get_program_path().append(GAME_SETTINGS_FOLDER).append(PATH_SEPARATOR);
|
||||
return get_program_path().append(game_settings_folder).append(PATH_SEPARATOR);
|
||||
}
|
||||
|
||||
#if defined(STEAM_WIN32)
|
||||
@ -508,7 +524,12 @@ std::string Local_Storage::get_path(std::string folder)
|
||||
|
||||
std::string Local_Storage::get_global_settings_path()
|
||||
{
|
||||
return save_directory + SETTINGS_STORAGE_FOLDER + PATH_SEPARATOR;
|
||||
return save_directory + settings_storage_folder + PATH_SEPARATOR;
|
||||
}
|
||||
|
||||
std::string Local_Storage::get_global_inventory_path()
|
||||
{
|
||||
return save_directory + inventory_storage_folder + PATH_SEPARATOR;
|
||||
}
|
||||
|
||||
std::vector<std::string> Local_Storage::get_filenames_path(std::string path)
|
||||
@ -680,4 +701,54 @@ bool Local_Storage::update_save_filenames(std::string folder)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Local_Storage::load_inventory_file(nlohmann::json& json, std::string const&file)
|
||||
{
|
||||
std::string inv_path = std::move(get_global_inventory_path() + appid + file);
|
||||
std::ifstream inventory_file(inv_path);
|
||||
// If there is a file and we opened it
|
||||
if (inventory_file)
|
||||
{
|
||||
inventory_file.seekg(0, std::ios::end);
|
||||
size_t size = inventory_file.tellg();
|
||||
std::string buffer(size, '\0');
|
||||
inventory_file.seekg(0);
|
||||
// Read it entirely, if the .json file gets too big,
|
||||
// I should look into this and split reads into smaller parts.
|
||||
inventory_file.read(&buffer[0], size);
|
||||
inventory_file.close();
|
||||
|
||||
try {
|
||||
json = std::move(nlohmann::json::parse(buffer));
|
||||
PRINT_DEBUG("Loaded inventory \"%s\". Loaded %u items.\n", inv_path.c_str(), json.size());
|
||||
return true;
|
||||
} catch (std::exception& e) {
|
||||
PRINT_DEBUG("Error while parsing \"%s\" inventory json: %s\n", inv_path.c_str(), e.what());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PRINT_DEBUG("Couldn't open file \"%s\" to read inventory\n", inv_path.c_str());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Local_Storage::write_inventory_file(nlohmann::json const& json, std::string const&file)
|
||||
{
|
||||
std::string inv_path = std::move(get_global_inventory_path() + appid);
|
||||
|
||||
create_directory(inv_path);
|
||||
|
||||
std::ofstream inventory_file(inv_path + file, std::ios::trunc | std::ios::out);
|
||||
if (inventory_file)
|
||||
{
|
||||
inventory_file << std::setw(2) << json;
|
||||
return true;
|
||||
}
|
||||
|
||||
PRINT_DEBUG("Couldn't open file \"%s\" to write inventory\n", inv_path.c_str());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user