Files
MaaAssistantArknights/MeoAssistance/InfrastConfiger.cpp
2021-08-12 00:46:38 +08:00

66 lines
1.3 KiB
C++
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "InfrastConfiger.h"
#include <fstream>
#include <sstream>
#include <json.h>
#include "Logger.hpp"
using namespace asst;
bool InfrastConfiger::load(const std::string& filename)
{
DebugTraceFunction;
DebugTrace("Configer::load | ", filename);
InfrastConfiger temp;
if (temp._load(filename)) {
*this = std::move(temp);
return true;
}
else {
return false;
}
}
bool InfrastConfiger::_load(const std::string& filename)
{
std::ifstream ifs(filename, std::ios::in);
if (!ifs.is_open()) {
return false;
}
std::stringstream iss;
iss << ifs.rdbuf();
ifs.close();
std::string content(iss.str());
auto&& ret = json::parser::parse(content);
if (!ret) {
DebugTrace("parse error", content);
return false;
}
json::value root = ret.value();
try {
// ÖÆÔìÕ¾
for (json::value& comb_info : root["Manufacturing"]["combs"].as_array())
{
std::vector<std::string> comb_vec;
for (json::value& oper_name : comb_info["comb"].as_array())
{
std::string oper_name_str = oper_name.as_string();
m_mfg_opers.emplace(oper_name_str);
comb_vec.emplace_back(std::move(oper_name_str));
}
m_mfg_combs.emplace_back(std::move(comb_vec));
}
// óÒ×Õ¾ TODO¡­¡­
}
catch (json::exception& e) {
DebugTraceError("Load config json error!", e.what());
return false;
}
DebugTrace("Load config succeed");
return true;
}