Files
MaaAssistantArknights/src/MeoAssistant/Resource/RoguelikeCopilotConfiger.cpp
zzyyyl c9b5aa638a refactor: 给头文件加上路径
直接在上一个 commit 里改的话可能会导致 history 消失
2022-09-29 23:30:32 +08:00

67 lines
3.0 KiB
C++

#include "RoguelikeCopilotConfiger.h"
#include <meojson/json.hpp>
#include "Utils/Logger.hpp"
std::optional<asst::RoguelikeBattleData> asst::RoguelikeCopilotConfiger::get_stage_data(
const std::string& stage_name) const
{
auto it = m_stage_data.find(stage_name);
if (it == m_stage_data.end()) {
return std::nullopt;
}
return it->second;
}
bool asst::RoguelikeCopilotConfiger::parse(const json::value& json)
{
for (const auto& stage_info : json.as_array()) {
std::string stage_name = stage_info.at("stage_name").as_string();
RoguelikeBattleData data;
data.stage_name = stage_name;
if (auto opt = stage_info.find<json::array>("replacement_home")) {
for (auto& point : opt.value()) {
ReplacementHome home;
home.location = Point(point["location"][0].as_integer(), point["location"][1].as_integer());
static const std::unordered_map<std::string, BattleDeployDirection> DeployDirectionMapping = {
{ "Right", BattleDeployDirection::Right }, { "RIGHT", BattleDeployDirection::Right },
{ "right", BattleDeployDirection::Right }, { "", BattleDeployDirection::Right },
{ "Left", BattleDeployDirection::Left }, { "LEFT", BattleDeployDirection::Left },
{ "left", BattleDeployDirection::Left }, { "", BattleDeployDirection::Left },
{ "Up", BattleDeployDirection::Up }, { "UP", BattleDeployDirection::Up },
{ "up", BattleDeployDirection::Up }, { "", BattleDeployDirection::Up },
{ "Down", BattleDeployDirection::Down }, { "DOWN", BattleDeployDirection::Down },
{ "down", BattleDeployDirection::Down }, { "", BattleDeployDirection::Down },
{ "None", BattleDeployDirection::None }, { "NONE", BattleDeployDirection::None },
{ "none", BattleDeployDirection::None }, { "", BattleDeployDirection::None },
};
const std::string& direction_str = point.get("direction", "none");
if (auto iter = DeployDirectionMapping.find(direction_str); iter != DeployDirectionMapping.end()) {
home.direction = iter->second;
}
else {
home.direction = BattleDeployDirection::None;
}
data.replacement_home.emplace_back(std::move(home));
}
}
if (auto opt = stage_info.find<json::array>("blacklist_location")) {
for (auto& point : opt.value()) {
data.blacklist_location.emplace(point[0].as_integer(), point[1].as_integer());
}
}
if (auto opt = stage_info.find<json::array>("key_kills")) {
for (const auto& key_kill : opt.value()) {
data.key_kills.emplace_back(static_cast<int>(key_kill));
}
}
m_stage_data.emplace(std::move(stage_name), std::move(data));
}
return true;
}