2019-08-17 14:40:58 -05:00
|
|
|
// Copyright 2019 Dolphin Emulator Project
|
2021-07-05 03:22:19 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2019-08-17 14:40:58 -05:00
|
|
|
|
|
|
|
#include "InputCommon/DynamicInputTextureManager.h"
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
|
|
|
|
#include "Common/CommonPaths.h"
|
|
|
|
#include "Common/FileSearch.h"
|
|
|
|
#include "Common/FileUtil.h"
|
|
|
|
#include "Core/ConfigManager.h"
|
2021-02-02 23:04:33 -06:00
|
|
|
#include "Core/Core.h"
|
2019-08-17 14:40:58 -05:00
|
|
|
|
2021-02-14 20:47:00 -06:00
|
|
|
#include "InputCommon/DynamicInputTextures/DITConfiguration.h"
|
2025-01-25 21:49:32 -06:00
|
|
|
#include "InputCommon/ImageOperations.h"
|
2019-08-17 14:40:58 -05:00
|
|
|
#include "VideoCommon/HiresTextures.h"
|
2023-01-31 00:46:10 +13:00
|
|
|
#include "VideoCommon/TextureCacheBase.h"
|
2019-08-17 14:40:58 -05:00
|
|
|
|
|
|
|
namespace InputCommon
|
|
|
|
{
|
|
|
|
DynamicInputTextureManager::DynamicInputTextureManager() = default;
|
|
|
|
|
|
|
|
DynamicInputTextureManager::~DynamicInputTextureManager() = default;
|
|
|
|
|
|
|
|
void DynamicInputTextureManager::Load()
|
|
|
|
{
|
|
|
|
m_configuration.clear();
|
|
|
|
|
|
|
|
const std::string& game_id = SConfig::GetInstance().GetGameID();
|
|
|
|
const std::set<std::string> dynamic_input_directories =
|
|
|
|
GetTextureDirectoriesWithGameId(File::GetUserPath(D_DYNAMICINPUT_IDX), game_id);
|
|
|
|
|
|
|
|
for (const auto& dynamic_input_directory : dynamic_input_directories)
|
|
|
|
{
|
|
|
|
const auto json_files = Common::DoFileSearch({dynamic_input_directory}, {".json"});
|
|
|
|
for (auto& file : json_files)
|
|
|
|
{
|
|
|
|
m_configuration.emplace_back(file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-13 09:38:09 -04:00
|
|
|
void DynamicInputTextureManager::GenerateTextures(const Common::IniFile& file,
|
2021-02-27 16:41:50 -06:00
|
|
|
const std::vector<std::string>& controller_names)
|
2019-08-17 14:40:58 -05:00
|
|
|
{
|
2025-01-25 21:49:32 -06:00
|
|
|
DynamicInputTextures::OutputDetails output;
|
2019-08-17 14:40:58 -05:00
|
|
|
for (const auto& configuration : m_configuration)
|
|
|
|
{
|
2025-01-25 21:49:32 -06:00
|
|
|
configuration.GenerateTextures(file, controller_names, &output);
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& game_id = SConfig::GetInstance().GetGameID();
|
|
|
|
for (const auto& [generated_folder_name, images] : output)
|
|
|
|
{
|
|
|
|
const auto hi_res_folder = File::GetUserPath(D_HIRESTEXTURES_IDX) + generated_folder_name;
|
|
|
|
|
|
|
|
if (!File::IsDirectory(hi_res_folder))
|
|
|
|
{
|
|
|
|
File::CreateDir(hi_res_folder);
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto game_id_folder = hi_res_folder + DIR_SEP + "gameids";
|
|
|
|
if (!File::IsDirectory(game_id_folder))
|
|
|
|
{
|
|
|
|
File::CreateDir(game_id_folder);
|
|
|
|
}
|
|
|
|
|
|
|
|
File::CreateEmptyFile(game_id_folder + DIR_SEP + game_id + ".txt");
|
|
|
|
|
|
|
|
for (const auto& [image_name, image] : images)
|
|
|
|
{
|
|
|
|
WriteImage(hi_res_folder + DIR_SEP + image_name, image);
|
|
|
|
}
|
2019-08-17 14:40:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace InputCommon
|