mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2025-12-23 00:12:18 +00:00
config: make definitions global
This commit is contained in:
parent
784d3973f4
commit
b354c6123d
3 changed files with 8 additions and 8 deletions
|
|
@ -14,7 +14,7 @@ void Config::Load()
|
|||
{
|
||||
auto toml = toml::parse_file(configPath.string());
|
||||
|
||||
for (auto def : Definitions)
|
||||
for (auto def : g_configDefs)
|
||||
{
|
||||
def->ReadValue(toml);
|
||||
#if _DEBUG
|
||||
|
|
@ -38,7 +38,7 @@ void Config::Save()
|
|||
std::string result;
|
||||
std::string section;
|
||||
|
||||
for (auto def : Definitions)
|
||||
for (auto def : g_configDefs)
|
||||
{
|
||||
auto isFirstSection = section.empty();
|
||||
auto isDefWithSection = section != def->GetSection();
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@
|
|||
class Config
|
||||
{
|
||||
public:
|
||||
inline static std::vector<ConfigDefBase*> Definitions{};
|
||||
|
||||
CONFIG_DEFINE_ENUM("System", ELanguage, Language, ELanguage::English);
|
||||
CONFIG_DEFINE("System", bool, Hints, true);
|
||||
CONFIG_DEFINE("System", bool, ControlTutorial, true);
|
||||
|
|
|
|||
|
|
@ -42,6 +42,8 @@ public:
|
|||
virtual std::string ToString() const = 0;
|
||||
};
|
||||
|
||||
inline static std::vector<ConfigDefBase*> g_configDefs{};
|
||||
|
||||
template<typename T, bool isMenuOption = true>
|
||||
class ConfigDef : public ConfigDefBase
|
||||
{
|
||||
|
|
@ -61,7 +63,7 @@ public:
|
|||
ConfigDef(std::string section, std::string name, T defaultValue)
|
||||
: Section(section), Name(name), DefaultValue(defaultValue)
|
||||
{
|
||||
Config::Definitions.emplace_back(this);
|
||||
g_configDefs.emplace_back(this);
|
||||
}
|
||||
|
||||
ConfigDef(std::string section, std::string name, T defaultValue, std::unordered_map<std::string, T> enumTemplate)
|
||||
|
|
@ -70,19 +72,19 @@ public:
|
|||
for (const auto& pair : EnumTemplate)
|
||||
EnumTemplateReverse[pair.second] = pair.first;
|
||||
|
||||
Config::Definitions.emplace_back(this);
|
||||
g_configDefs.emplace_back(this);
|
||||
}
|
||||
|
||||
ConfigDef(std::string section, std::string name, T defaultValue, std::function<void(ConfigDef<T, isMenuOption>*)> readCallback)
|
||||
: Section(section), Name(name), DefaultValue(defaultValue), ReadCallback(readCallback)
|
||||
{
|
||||
Config::Definitions.emplace_back(this);
|
||||
g_configDefs.emplace_back(this);
|
||||
}
|
||||
|
||||
ConfigDef(std::string section, std::string name, T defaultValue, std::function<void(ConfigDef<T, isMenuOption>*, const toml::v3::table&)> readImpl)
|
||||
: Section(section), Name(name), DefaultValue(defaultValue), ReadImpl(readImpl)
|
||||
{
|
||||
Config::Definitions.emplace_back(this);
|
||||
g_configDefs.emplace_back(this);
|
||||
}
|
||||
|
||||
void ReadValue(toml::v3::ex::parse_result& toml) override
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue