diff --git a/.gitignore b/.gitignore index 97224e0ea..25a36b239 100644 --- a/.gitignore +++ b/.gitignore @@ -57,4 +57,5 @@ server/openminer_server # Misc *.zip test_atlas.png +config.lua diff --git a/client/include/core/Config.hpp b/client/include/core/Config.hpp index 594a76491..79bc4bcd5 100644 --- a/client/include/core/Config.hpp +++ b/client/include/core/Config.hpp @@ -44,6 +44,8 @@ namespace Config { // Input extern u8 mouseSensitivity; + + void loadConfigFromFile(const char *file); } #endif // CONFIG_HPP_ diff --git a/client/source/core/ClientApplication.cpp b/client/source/core/ClientApplication.cpp index 6520aad57..421716c7b 100644 --- a/client/source/core/ClientApplication.cpp +++ b/client/source/core/ClientApplication.cpp @@ -50,6 +50,8 @@ void ClientApplication::init() { if (m_argumentParser.getArgument("port").isFound) m_port = std::stoi(m_argumentParser.getArgument("port").parameter); + Config::loadConfigFromFile("config.lua"); + m_keyboardHandler.loadKeysFromFile("resources/config/keys.xml"); gk::GamePad::init(m_keyboardHandler); diff --git a/client/source/core/Config.cpp b/client/source/core/Config.cpp index 43241ee33..7c2bf00a7 100644 --- a/client/source/core/Config.cpp +++ b/client/source/core/Config.cpp @@ -41,3 +41,40 @@ u8 Config::guiScale = 3; // Input u8 Config::mouseSensitivity = 8; +#include + +#include + +#include + +void Config::loadConfigFromFile(const char *file) { + if (gk::Filesystem::fileExists(file)) { + sol::state lua; + + try { + lua.safe_script_file(file); + + isFlyModeEnabled = lua["isFlyModeEnabled"].get_or(isFlyModeEnabled); + isNoClipEnabled = lua["isNoClipEnabled"].get_or(isNoClipEnabled); + + renderDistance = lua["renderDistance"].get_or(renderDistance); + isTorchSmoothLightingEnabled = lua["isTorchSmoothLightingEnabled"].get_or(isTorchSmoothLightingEnabled); + isSunSmoothLightingEnabled = lua["isSunSmoothLightingEnabled"].get_or(isSunSmoothLightingEnabled); + isAmbientOcclusionEnabled = lua["isAmbientOcclusionEnabled"].get_or(isAmbientOcclusionEnabled); + isWireframeModeEnabled = lua["isWireframeModeEnabled"].get_or(isWireframeModeEnabled); + isFullscreenModeEnabled = lua["isFullscreenModeEnabled"].get_or(isFullscreenModeEnabled); + cameraFOV = lua["cameraFOV"].get_or(cameraFOV); + screenWidth = lua["screenWidth"].get_or(screenWidth); + screenHeight = lua["screenHeight"].get_or(screenHeight); + guiScale = lua["guiScale"].get_or(guiScale); + + mouseSensitivity = lua["mouseSensitivity"].get_or(mouseSensitivity); + + std::cout << "Config file loaded successfully" << std::endl; + } + catch (sol::error &e) { + std::cerr << e.what() << std::endl; + } + } +} +