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
|
|
|
|
2018-07-06 11:58:34 +02:00
|
|
|
#include "Config.hpp"
|
|
|
|
|
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;
|
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;
|
2019-01-27 21:37:53 +01:00
|
|
|
bool Config::isTorchSmoothLightingEnabled = true;
|
2019-12-30 18:09:22 +09:00
|
|
|
bool Config::isSunSmoothLightingEnabled = true;
|
2019-12-30 06:59:10 +09:00
|
|
|
bool Config::isAmbientOcclusionEnabled = false;
|
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-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-03-29 16:36:31 +02:00
|
|
|
u8 Config::mipmapLevels = 0;
|
2020-03-31 14:27:23 +02:00
|
|
|
float Config::aoStrength = 1.0f;
|
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-05-13 21:41:32 +02:00
|
|
|
void Config::loadConfigFromFile(const char *filename) {
|
|
|
|
if (gk::Filesystem::fileExists(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-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);
|
|
|
|
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);
|
2020-02-24 23:16:51 +09:00
|
|
|
isVerticalSyncEnabled = lua["isVerticalSyncEnabled"].get_or(isVerticalSyncEnabled);
|
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);
|
|
|
|
guiScale = lua["guiScale"].get_or(guiScale);
|
2020-03-29 16:36:31 +02:00
|
|
|
mipmapLevels = lua["mipmapLevels"].get_or(mipmapLevels);
|
2020-03-30 04:36:00 +02:00
|
|
|
aoStrength = lua["aoStrength"].get_or(aoStrength);
|
2020-02-15 23:06:01 +09:00
|
|
|
|
|
|
|
mouseSensitivity = lua["mouseSensitivity"].get_or(mouseSensitivity);
|
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|