2023-07-11 03:23:32 +00:00
|
|
|
// Copyright 2023 Dolphin Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
#include "VideoCommon/GraphicsModSystem/Config/GraphicsModAsset.h"
|
|
|
|
|
|
|
|
#include "Common/Logging/Log.h"
|
2023-11-11 22:48:18 +00:00
|
|
|
#include "Common/StringUtil.h"
|
|
|
|
|
|
|
|
void GraphicsModAssetConfig::SerializeToConfig(picojson::object& json_obj) const
|
|
|
|
{
|
2024-01-25 03:47:22 +00:00
|
|
|
json_obj.emplace("name", m_asset_id);
|
2023-11-11 22:48:18 +00:00
|
|
|
|
|
|
|
picojson::object serialized_data;
|
|
|
|
for (const auto& [name, path] : m_map)
|
|
|
|
{
|
2024-01-25 03:47:22 +00:00
|
|
|
serialized_data.emplace(name, PathToString(path));
|
2023-11-11 22:48:18 +00:00
|
|
|
}
|
2024-01-25 03:47:22 +00:00
|
|
|
json_obj.emplace("data", std::move(serialized_data));
|
2023-11-11 22:48:18 +00:00
|
|
|
}
|
2023-07-11 03:23:32 +00:00
|
|
|
|
|
|
|
bool GraphicsModAssetConfig::DeserializeFromConfig(const picojson::object& obj)
|
|
|
|
{
|
|
|
|
auto name_iter = obj.find("name");
|
|
|
|
if (name_iter == obj.end())
|
|
|
|
{
|
|
|
|
ERROR_LOG_FMT(VIDEO, "Failed to load mod configuration file, specified asset has no name");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!name_iter->second.is<std::string>())
|
|
|
|
{
|
|
|
|
ERROR_LOG_FMT(VIDEO, "Failed to load mod configuration file, specified asset has a name "
|
|
|
|
"that is not a string");
|
|
|
|
return false;
|
|
|
|
}
|
2023-11-11 22:48:18 +00:00
|
|
|
m_asset_id = name_iter->second.to_str();
|
2023-07-11 03:23:32 +00:00
|
|
|
|
|
|
|
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",
|
2023-11-11 22:48:18 +00:00
|
|
|
m_asset_id);
|
2023-07-11 03:23:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!data_iter->second.is<picojson::object>())
|
|
|
|
{
|
|
|
|
ERROR_LOG_FMT(VIDEO,
|
|
|
|
"Failed to load mod configuration file, specified asset '{}' has data "
|
|
|
|
"that is not an object",
|
2023-11-11 22:48:18 +00:00
|
|
|
m_asset_id);
|
2023-07-11 03:23:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (const auto& [key, value] : data_iter->second.get<picojson::object>())
|
|
|
|
{
|
|
|
|
if (!value.is<std::string>())
|
|
|
|
{
|
|
|
|
ERROR_LOG_FMT(VIDEO,
|
|
|
|
"Failed to load mod configuration file, specified asset '{}' has data "
|
|
|
|
"with a value for key '{}' that is not a string",
|
2023-11-11 22:48:18 +00:00
|
|
|
m_asset_id, key);
|
2023-07-11 03:28:15 +00:00
|
|
|
return false;
|
2023-07-11 03:23:32 +00:00
|
|
|
}
|
|
|
|
m_map[key] = value.to_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|