125 lines
3.2 KiB
C++
125 lines
3.2 KiB
C++
#include <fstream>
|
|
#include <ostream>
|
|
#include <iomanip>
|
|
|
|
#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();
|
|
}
|
|
|
|
/* Fill the system level config JSON with default values set by the framework */
|
|
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"}},
|
|
{"reset", {"CTRL", "r"}}
|
|
};
|
|
sys_config["input"] = {
|
|
{"suppress-any-key-on-mods", true},
|
|
{"system-any-key-ignore-commands",
|
|
{"fullscreen", "screenshot", "toggle-framerate", "record", "quit"}},
|
|
{"any-key-ignore-commands", {}},
|
|
{"default-unsuppress-delay", 700},
|
|
{"ignore-repeat-keypress", true}
|
|
};
|
|
sys_config["display"] = {
|
|
{"dimensions", {640, 480}},
|
|
{"framerate", 60},
|
|
{"title", "sfw"},
|
|
{"debug", false},
|
|
{"show-cursor", false},
|
|
{"render-test-spacing", 2},
|
|
{"render driver", "opengl"}
|
|
};
|
|
sys_config["audio"] = {
|
|
{"default-sfx-root", "resource/sfx"},
|
|
{"default-bgm-root", "resource/bgm"}
|
|
};
|
|
sys_config["recording"] = {
|
|
{"enabled", false},
|
|
{"screenshot-prefix", "screenshot-"},
|
|
{"screenshot-extension", ".png"},
|
|
{"screenshot-zfill", 5},
|
|
{"screenshot-directory", "."},
|
|
{"gif-frame-length", 100},
|
|
{"video-directory", "."},
|
|
{"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"}
|
|
};
|
|
sys_config["log"] = {
|
|
{"enabled", false},
|
|
{"debug-to-stdout", false},
|
|
{"debug-to-file", false},
|
|
{"ouput-directory", "."},
|
|
{"info-file-name", "log.txt"},
|
|
{"debug-file-name", "debug_log.txt"}
|
|
};
|
|
}
|
|
|
|
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: game_config.items())
|
|
{
|
|
config[section.key()].update(game_config[section.key()]);
|
|
}
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|