diff --git a/external/gamekit b/external/gamekit index feb628bd9..a69852df7 160000 --- a/external/gamekit +++ b/external/gamekit @@ -1 +1 @@ -Subproject commit feb628bd90c8e29d4cad8a1dfd086f163ffd4434 +Subproject commit a69852df75dd070e59cae8908f0d38f325a7b34e diff --git a/source/client/core/ClientApplication.cpp b/source/client/core/ClientApplication.cpp index 3845a72e5..5c2c977e8 100644 --- a/source/client/core/ClientApplication.cpp +++ b/source/client/core/ClientApplication.cpp @@ -130,6 +130,10 @@ void ClientApplication::onEvent(const sf::Event &event) { Config::isFullscreenModeEnabled ^= 1; } +void ClientApplication::onExit() { + Config::saveConfigToFile("config/client.lua"); +} + void ClientApplication::initOpenGL() { // Enable textures glCheck(glEnable(GL_TEXTURE_2D)); diff --git a/source/client/core/ClientApplication.hpp b/source/client/core/ClientApplication.hpp index 28a29f1f2..426ef479b 100644 --- a/source/client/core/ClientApplication.hpp +++ b/source/client/core/ClientApplication.hpp @@ -42,6 +42,7 @@ class ClientApplication : public gk::CoreApplication { void handleEvents() override; void onEvent(const sf::Event &event) override; + void onExit() override; static void initOpenGL(); diff --git a/source/client/core/Config.cpp b/source/client/core/Config.cpp index 51d0d2d53..780ccd7c4 100644 --- a/source/client/core/Config.cpp +++ b/source/client/core/Config.cpp @@ -59,12 +59,12 @@ u8 Config::mouseSensitivity = 8; #include -void Config::loadConfigFromFile(const char *file) { - if (gk::Filesystem::fileExists(file)) { +void Config::loadConfigFromFile(const char *filename) { + if (gk::Filesystem::fileExists(filename)) { sol::state lua; try { - lua.safe_script_file(file); + lua.safe_script_file(filename); isFlyModeEnabled = lua["isFlyModeEnabled"].get_or(isFlyModeEnabled); isNoClipEnabled = lua["isNoClipEnabled"].get_or(isNoClipEnabled); @@ -98,3 +98,32 @@ void Config::loadConfigFromFile(const char *file) { } } +#include + +void Config::saveConfigToFile(const char *filename) { + std::ofstream file{filename, std::ofstream::out | std::ofstream::trunc}; + file << "isFlyModeEnabled = " << (isFlyModeEnabled ? "true" : "false") << std::endl; + file << "isNoClipEnabled = " << (isNoClipEnabled ? "true" : "false") << std::endl; + file << std::endl; + file << "isBlockInfoWidgetEnabled = " << (isBlockInfoWidgetEnabled ? "true" : "false") << std::endl; + file << "isFpsCounterEnabled = " << (isFpsCounterEnabled ? "true" : "false") << std::endl; + file << "isHotbarVisible = " << (isHotbarVisible ? "true" : "false") << std::endl; + file << "isCrosshairVisible = " << (isCrosshairVisible ? "true" : "false") << std::endl; + file << std::endl; + file << "renderDistance = " << renderDistance << std::endl; + file << "isTorchSmoothLightingEnabled = " << (isTorchSmoothLightingEnabled ? "true" : "false") << std::endl; + file << "isSunSmoothLightingEnabled = " << (isSunSmoothLightingEnabled ? "true" : "false") << std::endl; + file << "isAmbientOcclusionEnabled = " << (isAmbientOcclusionEnabled ? "true" : "false") << std::endl; + file << "isWireframeModeEnabled = " << (isWireframeModeEnabled ? "true" : "false") << std::endl; + file << "isFullscreenModeEnabled = " << (isFullscreenModeEnabled ? "true" : "false") << std::endl; + file << "isVerticalSyncEnabled = " << (isVerticalSyncEnabled ? "true" : "false") << std::endl; + file << "cameraFOV = " << cameraFOV << std::endl; + file << "screenWidth = " << screenWidth << std::endl; + file << "screenHeight = " << screenHeight << std::endl; + file << "guiScale = " << (u16)guiScale << std::endl; + file << "mipmapLevels = " << (u16)mipmapLevels << std::endl; + file << "aoStrength = " << aoStrength << std::endl; + file << std::endl; + file << "mouseSensitivity = " << (u16)mouseSensitivity << std::endl; +} + diff --git a/source/client/core/Config.hpp b/source/client/core/Config.hpp index 4ee709493..51a90ad1c 100644 --- a/source/client/core/Config.hpp +++ b/source/client/core/Config.hpp @@ -58,7 +58,8 @@ namespace Config { // Input extern u8 mouseSensitivity; - void loadConfigFromFile(const char *file); + void loadConfigFromFile(const char *filename); + void saveConfigToFile(const char *filename); } #endif // CONFIG_HPP_