Windows settings write fix

This commit is contained in:
MihailRis 2023-12-14 14:55:25 +03:00
parent 396ee31bcc
commit cd4d07c6d8
3 changed files with 19 additions and 14 deletions

View File

@ -1,48 +1,50 @@
#include "settings_io.h"
#include <memory>
#include <iostream>
#include "../window/Events.h"
#include "../window/input.h"
#include "../coders/toml.h"
#include "../coders/json.h"
using std::string;
toml::Wrapper create_wrapper(EngineSettings& settings) {
toml::Wrapper wrapper;
toml::Section& display = wrapper.add("display");
toml::Wrapper* create_wrapper(EngineSettings& settings) {
std::unique_ptr<toml::Wrapper> wrapper (new toml::Wrapper());
toml::Section& display = wrapper->add("display");
display.add("fullscreen", &settings.display.fullscreen);
display.add("width", &settings.display.width);
display.add("height", &settings.display.height);
display.add("samples", &settings.display.samples);
display.add("swap-interval", &settings.display.swapInterval);
toml::Section& chunks = wrapper.add("chunks");
toml::Section& chunks = wrapper->add("chunks");
chunks.add("load-distance", &settings.chunks.loadDistance);
chunks.add("load-speed", &settings.chunks.loadSpeed);
chunks.add("padding", &settings.chunks.padding);
toml::Section& camera = wrapper.add("camera");
toml::Section& camera = wrapper->add("camera");
camera.add("fov-effects", &settings.camera.fovEvents);
camera.add("fov", &settings.camera.fov);
camera.add("shaking", &settings.camera.shaking);
camera.add("sensitivity", &settings.camera.sensitivity);
toml::Section& graphics = wrapper.add("graphics");
toml::Section& graphics = wrapper->add("graphics");
graphics.add("fog-curve", &settings.graphics.fogCurve);
graphics.add("backlight", &settings.graphics.backlight);
graphics.add("frustum-culling", &settings.graphics.frustumCulling);
graphics.add("skybox-resolution", &settings.graphics.skyboxResolution);
toml::Section& debug = wrapper.add("debug");
toml::Section& debug = wrapper->add("debug");
debug.add("generator-test-mode", &settings.debug.generatorTestMode);
debug.add("show-chunk-borders", &settings.debug.showChunkBorders);
debug.add("do-write-lights", &settings.debug.doWriteLights);
toml::Section& ui = wrapper.add("ui");
toml::Section& ui = wrapper->add("ui");
ui.add("language", &settings.ui.language);
return wrapper;
return wrapper.release();
}
string write_controls() {

View File

@ -2,11 +2,14 @@
#define FILES_SETTINGS_IO_H_
#include <string>
#include "../coders/toml.h"
#include "../settings.h"
namespace toml {
class Wrapper;
}
extern std::string write_controls();
extern toml::Wrapper create_wrapper(EngineSettings& settings);
extern toml::Wrapper* create_wrapper(EngineSettings& settings);
extern void load_controls(std::string filename, std::string source);
#endif // FILES_SETTINGS_IO_H_

View File

@ -24,14 +24,14 @@ int main(int argc, char** argv) {
platform::configure_encoding();
try {
EngineSettings settings;
toml::Wrapper wrapper = create_wrapper(settings);
std::unique_ptr<toml::Wrapper> wrapper (create_wrapper(settings));
path settings_file = platform::get_settings_file();
path controls_file = platform::get_controls_file();
if (std::filesystem::is_regular_file(settings_file)) {
std::cout << "-- loading settings" << std::endl;
std::string text = files::read_string(settings_file);
toml::Reader reader(&wrapper, settings_file.string(), text);
toml::Reader reader(wrapper.get(), settings_file.string(), text);
reader.read();
}
Engine engine(settings, &paths);
@ -44,7 +44,7 @@ int main(int argc, char** argv) {
engine.mainloop();
std::cout << "-- saving settings" << std::endl;
files::write_string(settings_file, wrapper.write());
files::write_string(settings_file, wrapper->write());
files::write_string(controls_file, write_controls());
}
catch (const initialize_error& err) {