0
0
mirror of https://github.com/Nimac0/SDL_Minigame synced 2026-01-12 07:53:43 +00:00

added documentation

This commit is contained in:
freezarite 2025-01-14 19:27:56 +01:00
parent 91f15671c0
commit 201b5c8b5d
3 changed files with 48 additions and 3 deletions

View File

@ -4,16 +4,52 @@
using json = nlohmann::json; using json = nlohmann::json;
/*!
* \class ConfigLoader
* \brief Enables configuration of specific engine variables via a custom JSON file.
*
* The Config loader is responsible to handling customization for engine parameters like the
* window icon, window title, ... through json files.
*
* It includes a standard config file and the option to add a custom one by overwriting the setConfigFilePath()
* function within the implementation of the \ref Game class. Those files get merged, with a priorization on
* the parameters set within the custom config file.
*
*
* The currently available config parameters with their default values are:
* \include ../config.json
*
*/
class ConfigLoader { class ConfigLoader {
public: public:
ConfigLoader(); ConfigLoader();
~ConfigLoader(); ~ConfigLoader();
/*!
* \brief Creates the final config for the engine
*
* Loads the default config and then creates the final config by either merging
* (if the custom config has been set) or by implementing the standard config (if no custom
* config was set).
*
* \private
*/
void init(); void init();
/*!
* \brief Sets the customConfigPath variable
*
* \param path optional variable that should include the path to the custom config JSON file
*
* \private
*/
void setCustomConfig(const std::optional<std::string>& path); void setCustomConfig(const std::optional<std::string>& path);
/*!
* \brief Gets final configuration
* \return `json` variable containing the final config
* \private
*/
json getFinalConfig(); json getFinalConfig();
private: private:

View File

@ -9,6 +9,15 @@ public:
virtual void init() = 0; virtual void init() = 0;
virtual void update(uint_fast16_t diffTime) = 0; virtual void update(uint_fast16_t diffTime) = 0;
/*!
* \brief Sets the path for a custom config file.
*
* Virtual function to be overwritten in the implementation to return the path of a custom config JSON file.
* \sa Layout of the config file is shown in ConfigLoader
*
* \return std::optional<std::string>
*/
virtual std::optional<std::string> setConfigFilePath() {return std::nullopt;} virtual std::optional<std::string> setConfigFilePath() {return std::nullopt;}
GameInternal* gameInternal; //!< \deprecated GameInternal* gameInternal; //!< \deprecated

View File

@ -8,7 +8,7 @@ ConfigLoader::~ConfigLoader() {}
void ConfigLoader::init() { void ConfigLoader::init() {
//TODO: look into adaptive paths for better handling as this requires the implemented game //TODO: look into adaptive paths for better handling as this requires the implemented game
// to have ./engine in the root folder // to have ./engine in the root folder (very low prio)
const json baseConfig = loadConfigFromJSON("./engine/config.json"); const json baseConfig = loadConfigFromJSON("./engine/config.json");
if (!customConfigPath.has_value()) { if (!customConfigPath.has_value()) {