This commit is contained in:
Vivek Singh 2025-11-20 11:56:46 +05:30 committed by GitHub
commit 1fd904c9ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 0 deletions

View file

@ -50,6 +50,7 @@ class IConfigVar : virtual public ICommandVar {
virtual std::string config_value() const = 0; virtual std::string config_value() const = 0;
virtual void LoadConfigValue(std::shared_ptr<cpptoml::base> result) = 0; virtual void LoadConfigValue(std::shared_ptr<cpptoml::base> result) = 0;
virtual void LoadGameConfigValue(std::shared_ptr<cpptoml::base> result) = 0; virtual void LoadGameConfigValue(std::shared_ptr<cpptoml::base> result) = 0;
virtual void ResetGameConfigValue() = 0;
virtual void ResetConfigValueToDefault() = 0; virtual void ResetConfigValueToDefault() = 0;
}; };
@ -95,6 +96,7 @@ class ConfigVar : public CommandVar<T>, virtual public IConfigVar {
// one that will be stored when the global config is written next time. After // one that will be stored when the global config is written next time. After
// overriding, however, the next game config loaded may still change it. // overriding, however, the next game config loaded may still change it.
void OverrideConfigValue(T val); void OverrideConfigValue(T val);
void ResetGameConfigValue() override;
private: private:
std::string category_; std::string category_;
@ -278,6 +280,13 @@ void ConfigVar<T>::OverrideConfigValue(T val) {
this->commandline_value_.reset(); this->commandline_value_.reset();
UpdateValue(); UpdateValue();
} }
template <class T>
void ConfigVar<T>::ResetGameConfigValue() {
game_config_value_.reset();
UpdateValue();
}
template <class T> template <class T>
void ConfigVar<T>::ResetConfigValueToDefault() { void ConfigVar<T>::ResetConfigValueToDefault() {
SetConfigValue(this->default_value_); SetConfigValue(this->default_value_);

View file

@ -104,6 +104,16 @@ void ReadGameConfig(const std::filesystem::path& file_path) {
XELOGI("Loaded game config: {}", xe::path_to_utf8(file_path)); XELOGI("Loaded game config: {}", xe::path_to_utf8(file_path));
} }
void ResetGameConfigValues() {
if (!cvar::ConfigVars) {
return;
}
for (auto& it : *cvar::ConfigVars) {
auto config_var = static_cast<cvar::IConfigVar*>(it.second);
config_var->ResetGameConfigValue();
}
}
void SaveConfig() { void SaveConfig() {
if (config_path.empty()) { if (config_path.empty()) {
return; return;
@ -238,6 +248,8 @@ void SetupConfig(const std::filesystem::path& config_folder) {
} }
void LoadGameConfig(const std::string_view title_id) { void LoadGameConfig(const std::string_view title_id) {
ResetGameConfigValues();
const auto game_config_folder = config_folder / "config"; const auto game_config_folder = config_folder / "config";
const auto game_config_path = const auto game_config_path =
game_config_folder / (std::string(title_id) + game_config_suffix); game_config_folder / (std::string(title_id) + game_config_suffix);