![]() |
Jopnal Engine
alpha 0.4
Simple Component Based 2D/3D Game Engine
|
#include <SettingManager.hpp>
Public Types | |
typedef std::unordered_multimap< std::string, detail::SettingCallbackBase * > | UpdaterMap |
typedef std::unordered_map< std::string, std::pair< json::Document, bool > > | SettingMap |
Public Member Functions | |
SettingManager () | |
Default constructor. More... | |
~SettingManager () override | |
Destructor. More... | |
void | preUpdate (const float deltaTime) override |
Update function. More... | |
![]() | |
Subsystem (const uint32 ID) | |
Constructor. More... | |
virtual | ~Subsystem ()=0 |
Virtual destructor. More... | |
virtual void | postUpdate (const float deltaTime) |
Post-update. More... | |
virtual void | draw () |
Draw. More... | |
Message::Result | sendMessage (const Message &message) |
Function to handle messages. More... | |
Subsystem & | setActive (const bool active) |
Set this sub system active. More... | |
bool | isActive () const |
Check if this sub system is active. More... | |
uint32 | getID () const |
Get the ID. More... | |
Static Public Member Functions | |
static bool | settingExists (const std::string &path) |
Check if a certain setting exists. More... | |
template<typename T > | |
static T | get (const std::string &path, const T &defaultValue) |
Get a setting value. More... | |
template<typename T > | |
static T | set (const std::string &path, const T &value) |
Set a setting value. More... | |
static unsigned int | registerCallback (const std::string &path, detail::SettingCallbackBase &callback) |
Register a setting change callback. More... | |
static void | reload () |
Reload the settings from file. More... | |
static void | save () |
Save the settings to file. More... | |
static void | setDefaultDirectory (const std::string &directory) |
Set a directory with any default setting files. More... | |
static void | setOverrideWithDefaults () |
Override existing settings with the defaults. More... | |
Additional Inherited Members | |
![]() | |
virtual Message::Result | receiveMessage (const Message &message) |
Receive a message. More... | |
Definition at line 42 of file SettingManager.hpp.
typedef std::unordered_map<std::string, std::pair<json::Document, bool> > jop::SettingManager::SettingMap |
Definition at line 47 of file SettingManager.hpp.
typedef std::unordered_multimap<std::string, detail::SettingCallbackBase*> jop::SettingManager::UpdaterMap |
Definition at line 46 of file SettingManager.hpp.
jop::SettingManager::SettingManager | ( | ) |
Default constructor.
Loads all the existing settings from file.
|
override |
Destructor.
Saves the settings to file.
|
static |
Get a setting value.
The entry will be created if it doesn't exist.
Example of a correctly formatted setting path: "engine@Path|To|Setting|actualSetting"
The first section "engine", specifies the setting file. The .json extension will be added automatically. The file may be in a nested folder, but it must be specified using a forward slash (/). You may also leave the file part out, in which case the default file will be used ("root.json" by default).
After the file specification, comes the actual setting path. Nodes are separated with "|" after which comes the actual setting name. This example would produce the following setting file:
path | The setting path |
defaultValue | The default value, this will be used if the entry doesn't exist |
|
overridevirtual |
Update function.
Whenever any setting changes occur via file modification, the change callbacks will be called by this function in a synchronized manner.
This never does anything if automatic setting updates have been turned off.
deltaTime | The delta time, not used |
Reimplemented from jop::Subsystem.
|
static |
Register a setting change callback.
The callback will be invoked when you change a corresponding setting using set() or modify the setting file. The new value has to differ from the old one, or the invocation won't happen.
You are responsible for ensuring that the callback stays alive as long as it's meant to be used. You won't need to explicitly unbind it. The callback will be unbound during its destruction.
path | The setting path to associate the callback with |
callback | Reference to a callback object |
|
static |
Reload the settings from file.
Avoid calling this function. It will replace all current settings with those found in the files, discarding all unsaved changes. It will also invoke all registered change callbacks, even when the value hadn't changed.
|
static |
Save the settings to file.
|
static |
Set a setting value.
The entry will be created if it doesn't exist.
The value will be updated only if it differs from the existing one, as is the requirement for invoking any corresponding callbacks.
path | The setting path |
value | The value to set |
|
static |
Set a directory with any default setting files.
If set before engine initialization, the directory will be used to look for existing setting files, meant to contain custom default values. Call this if you need an initial configuration different from the engine's default.
directory | The setting file directory, relative to the Resources folder |
|
static |
Override existing settings with the defaults.
If setDefaultDirectory() hasn't been called, this function is no-op.
Calling this function after setting the default setting directory will cause any pre-existing settings found in the user folder to be replaced with the defaults. This function is meant for debugging purposes mainly.
|
static |
Check if a certain setting exists.
path | The setting path |