36 lines
997 B
C++
36 lines
997 B
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <unordered_map>
|
|
|
|
/**
|
|
* AppConfig
|
|
* ---------
|
|
* Minimal INI-style config file reader.
|
|
* Supports [sections], key = value pairs, and # comments.
|
|
*
|
|
* Keys are accessed as "section.key", e.g. "ui.font_path".
|
|
* Missing keys return a provided default value.
|
|
*
|
|
* The config file is searched in this order:
|
|
* 1. Next to the executable: <exeDir>/assets/config.ini
|
|
* 2. Current working dir: assets/config.ini
|
|
*/
|
|
class AppConfig {
|
|
public:
|
|
/// Load config. Returns true if a file was found and parsed.
|
|
bool load();
|
|
|
|
std::string getString(const std::string& key,
|
|
const std::string& defaultVal = "") const;
|
|
|
|
float getFloat(const std::string& key,
|
|
float defaultVal = 0.f) const;
|
|
|
|
int getInt(const std::string& key,
|
|
int defaultVal = 0) const;
|
|
|
|
private:
|
|
std::unordered_map<std::string, std::string> m_values;
|
|
};
|