Skip to content

Commit

Permalink
[Config] New function 'loadConfigFromFile' automatically loads 'confi…
Browse files Browse the repository at this point in the history
…g.lua' if present.
  • Loading branch information
Unarelith committed Feb 15, 2020
1 parent 93cd68f commit c4ea0d8
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ server/openminer_server
# Misc
*.zip
test_atlas.png
config.lua

2 changes: 2 additions & 0 deletions client/include/core/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ namespace Config {

// Input
extern u8 mouseSensitivity;

void loadConfigFromFile(const char *file);
}

#endif // CONFIG_HPP_
2 changes: 2 additions & 0 deletions client/source/core/ClientApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
37 changes: 37 additions & 0 deletions client/source/core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,40 @@ u8 Config::guiScale = 3;
// Input
u8 Config::mouseSensitivity = 8;

#include <iostream>

#include <gk/core/Filesystem.hpp>

#include <sol.hpp>

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;
}
}
}

0 comments on commit c4ea0d8

Please sign in to comment.