mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2025-12-22 16:02:19 +00:00
config: load config dynamically
This commit is contained in:
parent
231a78a118
commit
4cb22bfd5f
2 changed files with 20 additions and 61 deletions
|
|
@ -4,57 +4,8 @@ void Config::Load()
|
||||||
{
|
{
|
||||||
auto toml = toml::parse_file(GetConfigPath().string());
|
auto toml = toml::parse_file(GetConfigPath().string());
|
||||||
|
|
||||||
TOML_BEGIN_SECTION("System")
|
for (auto def : Definitions)
|
||||||
{
|
def->ReadValue(toml);
|
||||||
TOML_READ_ENUM(ELanguage, Language);
|
|
||||||
TOML_READ_BOOLEAN(Hints);
|
|
||||||
TOML_READ_ENUM(EScoreBehaviour, ScoreBehaviour);
|
|
||||||
TOML_READ_BOOLEAN(UnleashOutOfControlDrain);
|
|
||||||
TOML_READ_BOOLEAN(WerehogHubTransformVideo);
|
|
||||||
TOML_READ_BOOLEAN(LogoSkip);
|
|
||||||
}
|
|
||||||
TOML_END_SECTION();
|
|
||||||
|
|
||||||
TOML_BEGIN_SECTION("Controls")
|
|
||||||
{
|
|
||||||
TOML_READ_BOOLEAN(CameraXInvert);
|
|
||||||
TOML_READ_BOOLEAN(CameraYInvert);
|
|
||||||
TOML_READ_BOOLEAN(XButtonHoming);
|
|
||||||
TOML_READ_BOOLEAN(UnleashCancel);
|
|
||||||
}
|
|
||||||
TOML_END_SECTION();
|
|
||||||
|
|
||||||
TOML_BEGIN_SECTION("Audio")
|
|
||||||
{
|
|
||||||
TOML_READ_FLOAT(MusicVolume);
|
|
||||||
TOML_READ_FLOAT(SEVolume);
|
|
||||||
TOML_READ_ENUM(EVoiceLanguage, VoiceLanguage);
|
|
||||||
TOML_READ_FLOAT(Subtitles);
|
|
||||||
TOML_READ_BOOLEAN(WerehogBattleMusic);
|
|
||||||
}
|
|
||||||
TOML_END_SECTION();
|
|
||||||
|
|
||||||
TOML_BEGIN_SECTION("Video")
|
|
||||||
{
|
|
||||||
TOML_READ_ENUM(EGraphicsAPI, GraphicsAPI);
|
|
||||||
TOML_READ_INTEGER(WindowWidth);
|
|
||||||
TOML_READ_INTEGER(WindowHeight);
|
|
||||||
TOML_READ_FLOAT(ResolutionScale);
|
|
||||||
TOML_READ_BOOLEAN(Fullscreen);
|
|
||||||
TOML_READ_BOOLEAN(VSync);
|
|
||||||
TOML_READ_INTEGER(BufferCount);
|
|
||||||
TOML_READ_INTEGER(FPS);
|
|
||||||
TOML_READ_FLOAT(Brightness);
|
|
||||||
TOML_READ_INTEGER(MSAA);
|
|
||||||
TOML_READ_INTEGER(AnisotropicFiltering);
|
|
||||||
TOML_READ_INTEGER(ShadowResolution);
|
|
||||||
TOML_READ_ENUM(EGITextureFiltering, GITextureFiltering);
|
|
||||||
TOML_READ_BOOLEAN(AlphaToCoverage);
|
|
||||||
TOML_READ_BOOLEAN(Xbox360ColorCorrection);
|
|
||||||
TOML_READ_ENUM(EMovieScaleMode, MovieScaleMode);
|
|
||||||
TOML_READ_ENUM(EUIScaleMode, UIScaleMode);
|
|
||||||
}
|
|
||||||
TOML_END_SECTION();
|
|
||||||
}
|
}
|
||||||
catch (toml::parse_error& err)
|
catch (toml::parse_error& err)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -4,16 +4,6 @@
|
||||||
|
|
||||||
#define TOML_FILE "config.toml"
|
#define TOML_FILE "config.toml"
|
||||||
|
|
||||||
#define TOML_BEGIN_SECTION(name) if (auto pSection = toml[name].as_table()) { const auto& section = *pSection;
|
|
||||||
#define TOML_END_SECTION() }
|
|
||||||
|
|
||||||
#define TOML_READ_STRING(var) var.Value = section[#var].value_or<std::string>(var.DefaultValue);
|
|
||||||
#define TOML_READ_BOOLEAN(var) var.Value = section[#var].value_or(var.DefaultValue);
|
|
||||||
#define TOML_READ_FLOAT(var) var.Value = section[#var].value_or(var.DefaultValue);
|
|
||||||
#define TOML_READ_INTEGER(var) var.Value = section[#var].value_or(var.DefaultValue);
|
|
||||||
#define TOML_READ_DOUBLE(var) var.Value = section[#var].value_or(var.DefaultValue);
|
|
||||||
#define TOML_READ_ENUM(type, var) var.Value = (type)section[#var].value_or(var.DefaultValue);
|
|
||||||
|
|
||||||
#define CONFIG_DEFINE(section, type, name, defaultValue) inline static ConfigDef<type> name{section, #name, defaultValue};
|
#define CONFIG_DEFINE(section, type, name, defaultValue) inline static ConfigDef<type> name{section, #name, defaultValue};
|
||||||
#define CONFIG_VALUE(name) Config::name.Value
|
#define CONFIG_VALUE(name) Config::name.Value
|
||||||
|
|
||||||
|
|
@ -24,6 +14,7 @@ class ConfigDefBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~ConfigDefBase() = default;
|
virtual ~ConfigDefBase() = default;
|
||||||
|
virtual void ReadValue(toml::v3::ex::parse_result toml) = 0;
|
||||||
virtual void MakeDefault() = 0;
|
virtual void MakeDefault() = 0;
|
||||||
virtual std::string GetSection() const = 0;
|
virtual std::string GetSection() const = 0;
|
||||||
virtual std::string GetName() const = 0;
|
virtual std::string GetName() const = 0;
|
||||||
|
|
@ -45,6 +36,23 @@ public:
|
||||||
Config::Definitions.emplace_back(this);
|
Config::Definitions.emplace_back(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ReadValue(toml::v3::ex::parse_result toml) override
|
||||||
|
{
|
||||||
|
if (auto pSection = toml[Section].as_table())
|
||||||
|
{
|
||||||
|
const auto& section = *pSection;
|
||||||
|
|
||||||
|
if constexpr (std::is_same<T, std::string>::value)
|
||||||
|
{
|
||||||
|
Value = section[Name].value_or<std::string>(DefaultValue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Value = section[Name].value_or(DefaultValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MakeDefault() override
|
void MakeDefault() override
|
||||||
{
|
{
|
||||||
Value = DefaultValue;
|
Value = DefaultValue;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue