#include "Configuration.hpp" Configuration::Configuration(Node *parent) : Configuration(parent, "config.json") {} Configuration::Configuration(Node *parent, fs::path path) : Node(parent) { config_path = path; set_defaults(); load(); merge(); } void Configuration::set_defaults() { sys_config["keys"] = { {"record", {"CTRL", "SHIFT", "f10"}}, {"save-current-stash", {"CTRL", "SHIFT", "v"}}, {"screenshot", "f9"}, {"action", "space"}, {"up", "up"}, {"right", "right"}, {"down", "down"}, {"left", "left"}, {"pause", "enter"}, {"fullscreen", {"ALT", "enter"}}, {"toggle-framerate", {"CTRL", "f"}} }; sys_config["path"] = { {"screenshots", "."}, {"video", "."} }; sys_config["display"] = { {"dimensions", {640, 480}}, {"framerate", 60}, {"title", "sfw"} }; sys_config["recording"] = { {"enabled", false}, {"screenshot-prefix", "screenshot-"}, {"screenshot-extension", ".png"}, {"screenshot-zfill", 5}, {"gif-frame-length", 100}, {"write-mp4", false}, {"max-stash-length", 5000}, {"max-in-game-stashes", 3}, {"max-video-stashes", 40}, {"max-video-memory", 1000}, {"mp4-pixel-format", "yuv444p"} }; sys_config["fps-indicator"] = { {"width", .05}, {"height", .04}, {"background", {255, 255, 255}}, {"foreground", {0, 0, 0}} }; sys_config["animation"] = { {"all-frames-frameset-name", "all"} }; } void Configuration::load() { load(config_path); } void Configuration::load(fs::path path) { if (fs::exists(path)) { std::ifstream contents(path); contents >> game_config; } } void Configuration::merge() { config = sys_config; if (not game_config.empty()) { for (auto& section: config.items()) { if (game_config.contains(section.key())) { config[section.key()].update(game_config[section.key()]); } } } std::cout << std::setw(4) << config << std::endl; } void Configuration::write() { write(config_path); } void Configuration::write(fs::path path) { std::ofstream output(path); output << std::setw(tab_width) << game_config << std::endl; }