mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-10 17:46:53 -10:00
This is a system for storing arbitrary data in the config file and then easily retrieving it later on. This has full Lua support for exposing the available options in a custom UI and changing the values of the options. This ported some of the existing command line options over to the new system which is opt-in for the moment by using a mod_table flag.
58 lines
1.5 KiB
C++
58 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include "globalincs/pstypes.h"
|
|
#include "libs/jansson.h"
|
|
#include <memory>
|
|
|
|
namespace options {
|
|
|
|
// Forward declaration
|
|
class OptionBase;
|
|
|
|
class OptionsManager {
|
|
OptionsManager();
|
|
|
|
SCP_unordered_map<SCP_string, std::unique_ptr<json_t>> _config_overrides;
|
|
|
|
SCP_unordered_map<SCP_string, std::unique_ptr<json_t>> _changed_values;
|
|
|
|
SCP_unordered_map<SCP_string, const OptionBase*> _optionsMapping;
|
|
|
|
SCP_vector<std::unique_ptr<const OptionBase>> _options;
|
|
bool _optionsSorted = false;
|
|
|
|
public:
|
|
static OptionsManager* instance();
|
|
|
|
~OptionsManager();
|
|
|
|
std::unique_ptr<json_t> getValueFromConfig(const SCP_string& key) const;
|
|
|
|
void setConfigValue(const SCP_string& key, std::unique_ptr<json_t>&& value);
|
|
|
|
void setOverride(const SCP_string& key, const SCP_string& json);
|
|
|
|
const OptionBase* addOption(std::unique_ptr<const OptionBase>&& option);
|
|
|
|
void removeOption(const OptionBase* option);
|
|
|
|
const SCP_vector<std::unique_ptr<const options::OptionBase>>& getOptions();
|
|
|
|
/**
|
|
* @brief Persists changes to the disk
|
|
*
|
|
* This writes all the outstanding changes to the config file and returns a vector of all the options that indicated
|
|
* that they could not change the value. If the return value is empty then all changes were applied but if it is not
|
|
* empty then a restart is required for all the options to take effect.
|
|
*
|
|
* @return A vector of options that did not support changing the value
|
|
*/
|
|
SCP_vector<const options::OptionBase*> persistChanges();
|
|
|
|
void discardChanges();
|
|
|
|
void loadInitialValues();
|
|
};
|
|
|
|
}
|