Added initial JSON configuration support

This commit is contained in:
2025-12-04 15:04:39 +02:00
parent 34ce515521
commit 6cad6428a4
6 changed files with 24709 additions and 7 deletions

View File

@@ -1,9 +1,13 @@
#ifndef SDL_HELPERS_H_
#define SDL_HELPERS_H_
#include <string>
#include <SDL2/SDL_ttf.h>
#include <iostream>
#include <string>
#include "json.hpp"
// Call this before everything
// Prints its messages
bool init_sdl();
@@ -15,4 +19,15 @@ void clean_sdl();
// Can return NULL
TTF_Font* get_font(const std::string& filename, int size);
// Reads the file and tries to parse a JSON file with comments
// cfg - output json struct
// filename - filepath to open and read
// log - output errors to this ostream, silent if NULL
bool read_config_json(nlohmann::json& cfg, const std::string& filename, std::ostream* log = &std::cout);
// JSON Extractors - They do not override already set values if key is not present
void json_extract(const nlohmann::json& j, const std::string& key, std::string& out);
void json_extract(const nlohmann::json& j, const std::string& key, int& out);
#endif // SDL_HELPERS_H_