refactor: 重构 Resource 类

fix https://github.com/MaaAssistantArknights/MaaAssistantArknights/issues/1541
This commit is contained in:
MistEO
2022-09-04 00:27:54 +08:00
parent f85e0db429
commit 7c8bf92eb4
72 changed files with 376 additions and 548 deletions

View File

@@ -0,0 +1,71 @@
#include "ResourceLoader.h"
#include <filesystem>
#include "Logger.hpp"
#include "BattleDataConfiger.h"
#include "CopilotConfiger.h"
#include "GeneralConfiger.h"
#include "InfrastConfiger.h"
#include "ItemConfiger.h"
#include "OcrPack.h"
#include "RecruitConfiger.h"
#include "RoguelikeCopilotConfiger.h"
#include "RoguelikeRecruitConfiger.h"
#include "RoguelikeShoppingConfiger.h"
#include "StageDropsConfiger.h"
#include "TaskData.h"
#include "TemplResource.h"
#include "TilePack.h"
bool asst::ResourceLoader::load(const std::filesystem::path& path)
{
#define LoadResouceAndCheckRet(Configer, Filename) \
{ \
auto full_path = path / Filename; \
bool ret = load_resource<Configer>(full_path); \
if (!ret) { \
Log.error("Load", full_path, "failed"); \
return false; \
} \
}
#define LoadResouceWithTemplAndCheckRet(Configer, Filename, TemplDir) \
{ \
auto full_path = path / Filename; \
auto full_templ_dir = path / TemplDir; \
bool ret = load_resource_with_templ<Configer>(full_path, full_templ_dir); \
if (!ret) { \
Log.error("Load", full_path, "with", full_templ_dir, "failed"); \
return false; \
} \
}
LogTraceFunction;
/* load resource with json files*/
LoadResouceAndCheckRet(GeneralConfiger, "config.json");
LoadResouceAndCheckRet(RecruitConfiger, "recruit.json");
LoadResouceAndCheckRet(StageDropsConfiger, "stages.json");
LoadResouceAndCheckRet(RoguelikeCopilotConfiger, "roguelike_copilot.json");
LoadResouceAndCheckRet(RoguelikeRecruitConfiger, "roguelike_recruit.json");
LoadResouceAndCheckRet(RoguelikeShoppingConfiger, "roguelike_shopping.json");
LoadResouceAndCheckRet(BattleDataConfiger, "battle_data.json");
/* load resource with json and template files*/
LoadResouceWithTemplAndCheckRet(TaskData, "tasks.json", "template");
LoadResouceWithTemplAndCheckRet(InfrastConfiger, "infrast.json", "template" / "infrast");
LoadResouceWithTemplAndCheckRet(ItemConfiger, "item_index.json", "template" / "items");
/* load 3rd parties resource */
LoadResouceAndCheckRet(TilePack, "Arknights-Tile-Pos" / "levels.json");
LoadResouceAndCheckRet(OcrPack, "PaddleOCR");
m_loaded = true;
#undef LoadTemplByConfigerAndCheckRet
#undef LoadResouceAndCheckRet
return true;
}