mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-06-11 16:49:28 +02:00
VideoCommon: add ability to serialize graphics mod to json object
This commit is contained in:
@ -4,6 +4,19 @@
|
||||
#include "VideoCommon/GraphicsModSystem/Config/GraphicsModAsset.h"
|
||||
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Common/StringUtil.h"
|
||||
|
||||
void GraphicsModAssetConfig::SerializeToConfig(picojson::object& json_obj) const
|
||||
{
|
||||
json_obj["name"] = picojson::value{m_asset_id};
|
||||
|
||||
picojson::object serialized_data;
|
||||
for (const auto& [name, path] : m_map)
|
||||
{
|
||||
serialized_data[name] = picojson::value{PathToString(path)};
|
||||
}
|
||||
json_obj["data"] = picojson::value{serialized_data};
|
||||
}
|
||||
|
||||
bool GraphicsModAssetConfig::DeserializeFromConfig(const picojson::object& obj)
|
||||
{
|
||||
@ -19,13 +32,13 @@ bool GraphicsModAssetConfig::DeserializeFromConfig(const picojson::object& obj)
|
||||
"that is not a string");
|
||||
return false;
|
||||
}
|
||||
m_name = name_iter->second.to_str();
|
||||
m_asset_id = name_iter->second.to_str();
|
||||
|
||||
auto data_iter = obj.find("data");
|
||||
if (data_iter == obj.end())
|
||||
{
|
||||
ERROR_LOG_FMT(VIDEO, "Failed to load mod configuration file, specified asset '{}' has no data",
|
||||
m_name);
|
||||
m_asset_id);
|
||||
return false;
|
||||
}
|
||||
if (!data_iter->second.is<picojson::object>())
|
||||
@ -33,7 +46,7 @@ bool GraphicsModAssetConfig::DeserializeFromConfig(const picojson::object& obj)
|
||||
ERROR_LOG_FMT(VIDEO,
|
||||
"Failed to load mod configuration file, specified asset '{}' has data "
|
||||
"that is not an object",
|
||||
m_name);
|
||||
m_asset_id);
|
||||
return false;
|
||||
}
|
||||
for (const auto& [key, value] : data_iter->second.get<picojson::object>())
|
||||
@ -43,7 +56,7 @@ bool GraphicsModAssetConfig::DeserializeFromConfig(const picojson::object& obj)
|
||||
ERROR_LOG_FMT(VIDEO,
|
||||
"Failed to load mod configuration file, specified asset '{}' has data "
|
||||
"with a value for key '{}' that is not a string",
|
||||
m_name, key);
|
||||
m_asset_id, key);
|
||||
return false;
|
||||
}
|
||||
m_map[key] = value.to_str();
|
||||
|
Reference in New Issue
Block a user