2018-07-06 11:58:34 +02:00
|
|
|
/*
|
|
|
|
* =====================================================================================
|
|
|
|
*
|
2020-02-08 18:34:26 +09:00
|
|
|
* OpenMiner
|
2020-02-25 01:42:10 +09:00
|
|
|
*
|
2020-02-08 18:34:26 +09:00
|
|
|
* Copyright (C) 2018-2020 Unarelith, Quentin Bazin <openminer@unarelith.net>
|
2020-02-25 01:42:10 +09:00
|
|
|
* Copyright (C) 2019-2020 the OpenMiner contributors (see CONTRIBUTORS.md)
|
|
|
|
*
|
|
|
|
* This file is part of OpenMiner.
|
2018-07-06 11:58:34 +02:00
|
|
|
*
|
2020-02-25 01:42:10 +09:00
|
|
|
* OpenMiner is free software; you can redistribute it and/or
|
2020-02-08 18:34:26 +09:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2018-07-06 11:58:34 +02:00
|
|
|
*
|
2020-02-25 01:42:10 +09:00
|
|
|
* OpenMiner is distributed in the hope that it will be useful,
|
2020-02-08 18:34:26 +09:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2018-07-06 11:58:34 +02:00
|
|
|
*
|
2020-02-08 18:34:26 +09:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2020-02-25 01:42:10 +09:00
|
|
|
* along with OpenMiner; if not, write to the Free Software Foundation, Inc.,
|
2020-02-08 18:34:26 +09:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2018-07-06 11:58:34 +02:00
|
|
|
*
|
|
|
|
* =====================================================================================
|
|
|
|
*/
|
2020-05-15 00:12:26 +02:00
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
#include <gk/core/Debug.hpp>
|
|
|
|
#include <gk/core/Filesystem.hpp>
|
|
|
|
|
2020-05-22 19:39:40 +02:00
|
|
|
#include <sol/sol.hpp>
|
2020-05-15 00:12:26 +02:00
|
|
|
|
2020-07-07 20:21:47 +02:00
|
|
|
#include <filesystem.hpp>
|
|
|
|
|
2018-07-06 11:58:34 +02:00
|
|
|
#include "Config.hpp"
|
|
|
|
|
2020-07-07 20:21:47 +02:00
|
|
|
namespace fs = ghc::filesystem;
|
|
|
|
|
2019-01-12 19:49:41 +01:00
|
|
|
// Gameplay
|
|
|
|
bool Config::isFlyModeEnabled = false;
|
2019-01-19 15:21:49 +01:00
|
|
|
bool Config::isNoClipEnabled = false;
|
2020-07-11 15:17:56 +02:00
|
|
|
u16 Config::maxBlockReach = 7;
|
2019-01-12 19:49:41 +01:00
|
|
|
|
2020-02-24 22:43:31 +09:00
|
|
|
// Interface
|
|
|
|
bool Config::isBlockInfoWidgetEnabled = true;
|
2020-03-04 12:54:20 +01:00
|
|
|
bool Config::isFpsCounterEnabled = true;
|
|
|
|
bool Config::isHotbarVisible = true;
|
|
|
|
bool Config::isCrosshairVisible = true;
|
2020-02-24 22:43:31 +09:00
|
|
|
|
2019-01-12 19:49:41 +01:00
|
|
|
// Graphics
|
2020-01-27 15:33:06 +09:00
|
|
|
u16 Config::renderDistance = 8;
|
2020-07-17 19:18:09 +02:00
|
|
|
u8 Config::ambientOcclusion = 1;
|
2020-06-29 14:46:40 +02:00
|
|
|
bool Config::isSmoothLightingEnabled = true;
|
2018-12-31 07:45:11 +01:00
|
|
|
bool Config::isWireframeModeEnabled = false;
|
2020-01-27 15:33:06 +09:00
|
|
|
bool Config::isFullscreenModeEnabled = false;
|
2020-02-24 23:16:51 +09:00
|
|
|
bool Config::isVerticalSyncEnabled = true;
|
2020-07-17 03:50:48 +02:00
|
|
|
bool Config::isStarRenderingEnabled = true;
|
2020-01-25 15:29:14 +09:00
|
|
|
float Config::cameraFOV = 70.0f;
|
2020-02-15 22:48:56 +09:00
|
|
|
u16 Config::screenWidth = 1600;
|
|
|
|
u16 Config::screenHeight = 1050;
|
|
|
|
u8 Config::guiScale = 3;
|
2020-07-10 16:56:32 +02:00
|
|
|
u8 Config::mipmapLevels = 0;
|
2020-01-27 15:33:06 +09:00
|
|
|
|
|
|
|
// Input
|
2020-01-26 16:03:43 +09:00
|
|
|
u8 Config::mouseSensitivity = 8;
|
2018-07-06 11:58:34 +02:00
|
|
|
|
2020-06-26 02:16:29 +02:00
|
|
|
// Other
|
|
|
|
std::string Config::defaultUsername = "";
|
|
|
|
std::string Config::defaultServerAddress = "localhost:4242";
|
2020-07-17 20:41:43 +02:00
|
|
|
std::string Config::texturePack = "";
|
2020-06-26 02:16:29 +02:00
|
|
|
|
2020-05-13 21:41:32 +02:00
|
|
|
void Config::loadConfigFromFile(const char *filename) {
|
2020-07-08 00:20:12 +02:00
|
|
|
if (!fs::exists("config") && !fs::create_directory("config")) {
|
|
|
|
gkError() << "Failed to create 'config' folder";
|
|
|
|
return;
|
|
|
|
}
|
2020-07-07 20:21:47 +02:00
|
|
|
|
|
|
|
if (fs::exists(filename)) {
|
2020-02-15 23:06:01 +09:00
|
|
|
sol::state lua;
|
|
|
|
|
|
|
|
try {
|
2020-05-13 21:41:32 +02:00
|
|
|
lua.safe_script_file(filename);
|
2020-02-15 23:06:01 +09:00
|
|
|
|
|
|
|
isFlyModeEnabled = lua["isFlyModeEnabled"].get_or(isFlyModeEnabled);
|
|
|
|
isNoClipEnabled = lua["isNoClipEnabled"].get_or(isNoClipEnabled);
|
2020-07-11 15:17:56 +02:00
|
|
|
maxBlockReach = lua["maxBlockReach"].get_or(maxBlockReach);
|
2020-02-15 23:06:01 +09:00
|
|
|
|
2020-02-24 22:43:31 +09:00
|
|
|
isBlockInfoWidgetEnabled = lua["isBlockInfoWidgetEnabled"].get_or(isBlockInfoWidgetEnabled);
|
2020-03-04 12:54:20 +01:00
|
|
|
isFpsCounterEnabled = lua["isFpsCounterEnabled"].get_or(isFpsCounterEnabled);
|
|
|
|
isHotbarVisible = lua["isHotbarVisible"].get_or(isHotbarVisible);
|
|
|
|
isCrosshairVisible = lua["isCrosshairVisible"].get_or(isCrosshairVisible);
|
2020-02-24 22:43:31 +09:00
|
|
|
|
2020-02-15 23:06:01 +09:00
|
|
|
renderDistance = lua["renderDistance"].get_or(renderDistance);
|
2020-07-16 16:32:56 +02:00
|
|
|
ambientOcclusion = std::clamp<u8>(lua["ambientOcclusion"].get_or(ambientOcclusion), 0, 2);
|
2020-06-29 14:46:40 +02:00
|
|
|
isSmoothLightingEnabled = lua["isSmoothLightingEnabled"].get_or(isSmoothLightingEnabled);
|
2020-02-15 23:06:01 +09:00
|
|
|
isWireframeModeEnabled = lua["isWireframeModeEnabled"].get_or(isWireframeModeEnabled);
|
|
|
|
isFullscreenModeEnabled = lua["isFullscreenModeEnabled"].get_or(isFullscreenModeEnabled);
|
2020-02-24 23:16:51 +09:00
|
|
|
isVerticalSyncEnabled = lua["isVerticalSyncEnabled"].get_or(isVerticalSyncEnabled);
|
2020-07-17 03:50:48 +02:00
|
|
|
isStarRenderingEnabled = lua["isStarRenderingEnabled"].get_or(isStarRenderingEnabled);
|
2020-02-15 23:06:01 +09:00
|
|
|
cameraFOV = lua["cameraFOV"].get_or(cameraFOV);
|
|
|
|
screenWidth = lua["screenWidth"].get_or(screenWidth);
|
|
|
|
screenHeight = lua["screenHeight"].get_or(screenHeight);
|
2020-07-16 16:32:56 +02:00
|
|
|
guiScale = std::clamp<u8>(lua["guiScale"].get_or(guiScale), 1, 3);
|
|
|
|
mipmapLevels = std::clamp<u8>(lua["mipmapLevels"].get_or(mipmapLevels), 0, 4);
|
2020-02-15 23:06:01 +09:00
|
|
|
|
|
|
|
mouseSensitivity = lua["mouseSensitivity"].get_or(mouseSensitivity);
|
|
|
|
|
2020-06-26 02:16:29 +02:00
|
|
|
defaultUsername = lua["defaultUsername"].get_or(defaultUsername);
|
|
|
|
defaultServerAddress = lua["defaultServerAddress"].get_or(defaultServerAddress);
|
2020-07-17 20:41:43 +02:00
|
|
|
texturePack = lua["texturePack"].get_or(texturePack);
|
2020-06-26 02:16:29 +02:00
|
|
|
|
2020-04-03 07:27:57 +02:00
|
|
|
gkInfo() << "Config file loaded successfully";
|
2020-02-15 23:06:01 +09:00
|
|
|
}
|
|
|
|
catch (sol::error &e) {
|
2020-04-03 07:27:57 +02:00
|
|
|
gkError() << e.what();
|
2020-02-15 23:06:01 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-13 21:41:32 +02:00
|
|
|
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;
|
2020-07-11 15:17:56 +02:00
|
|
|
file << "maxBlockReach = " << maxBlockReach << std::endl;
|
2020-05-13 21:41:32 +02:00
|
|
|
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;
|
2020-07-16 16:32:56 +02:00
|
|
|
file << "ambientOcclusion = " << (u16)ambientOcclusion << std::endl;
|
2020-06-29 14:46:40 +02:00
|
|
|
file << "isSmoothLightingEnabled = " << (isSmoothLightingEnabled ? "true" : "false") << std::endl;
|
2020-05-13 21:41:32 +02:00
|
|
|
file << "isWireframeModeEnabled = " << (isWireframeModeEnabled ? "true" : "false") << std::endl;
|
|
|
|
file << "isFullscreenModeEnabled = " << (isFullscreenModeEnabled ? "true" : "false") << std::endl;
|
|
|
|
file << "isVerticalSyncEnabled = " << (isVerticalSyncEnabled ? "true" : "false") << std::endl;
|
2020-07-17 03:50:48 +02:00
|
|
|
file << "isStarRenderingEnabled = " << (isStarRenderingEnabled ? "true" : "false") << std::endl;
|
2020-05-13 21:41:32 +02:00
|
|
|
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 << std::endl;
|
|
|
|
file << "mouseSensitivity = " << (u16)mouseSensitivity << std::endl;
|
2020-06-26 02:16:29 +02:00
|
|
|
file << std::endl;
|
|
|
|
file << "defaultUsername = \"" << defaultUsername << "\"" << std::endl;
|
|
|
|
file << "defaultServerAddress = \"" << defaultServerAddress << "\"" << std::endl;
|
2020-07-17 20:41:43 +02:00
|
|
|
file << "texturePack = \"" << texturePack << "\"" << std::endl;
|
2020-05-13 21:41:32 +02:00
|
|
|
}
|
|
|
|
|