The next little game in the series where I make a fancy rogue game.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
roguish/config.cpp

28 lines
882 B

#include "config.hpp"
#include "dbc.hpp"
#include <fmt/core.h>
using nlohmann::json;
using fmt::format;
Config::Config(const std::string src_path) : $src_path(src_path) {
std::ifstream infile($src_path);
$config = json::parse(infile);
}
json &Config::operator[](const std::string &key) {
dbc::check($config.contains(key), format("ERROR in config, key {} doesn't exist.", key));
return $config[key];
}
std::wstring Config::wstring(const std::string key) {
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> $converter;
const std::string& str_val = $config[key];
return $converter.from_bytes(str_val);
}
std::wstring Config::wstring(const std::string main_key, const std::string sub_key) {
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> $converter;
const std::string& str_val = $config[main_key][sub_key];
return $converter.from_bytes(str_val);
}