|
|
|
@ -1,40 +1,30 @@
|
|
|
|
|
#include <fstream> // std::ifstream, std::ofstream |
|
|
|
|
#include <iomanip> // std::setfill, std::setw |
|
|
|
|
#include <string> // std::string |
|
|
|
|
|
|
|
|
|
#include "inferno/core.h" |
|
|
|
|
#include "inferno/file.h" |
|
|
|
|
#include "inferno/log.h" |
|
|
|
|
#include "inferno/settings.h" |
|
|
|
|
|
|
|
|
|
namespace Inferno { |
|
|
|
|
|
|
|
|
|
Settings* Settings::s_instance = nullptr; |
|
|
|
|
bool Settings::m_initialized = false; |
|
|
|
|
|
|
|
|
|
Settings::Settings(const char* path) : |
|
|
|
|
m_path(path) |
|
|
|
|
{ |
|
|
|
|
NF_CORE_ASSERT(!s_instance, "Settings already exists!"); |
|
|
|
|
s_instance = this; |
|
|
|
|
|
|
|
|
|
this->initialize(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Settings::~Settings() |
|
|
|
|
{ |
|
|
|
|
this->destroy(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// -----------------------------------------
|
|
|
|
|
const char* Settings::m_path = "assets/settings.json"; |
|
|
|
|
SettingsProperties Settings::m_properties = {}; |
|
|
|
|
|
|
|
|
|
void Settings::initialize() |
|
|
|
|
{ |
|
|
|
|
this->update(); |
|
|
|
|
Settings::update(); |
|
|
|
|
|
|
|
|
|
m_initialized = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Settings::update() |
|
|
|
|
{ |
|
|
|
|
nlohmann::json json = this->load(); |
|
|
|
|
if (m_initialized) { |
|
|
|
|
Settings::destroy(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
nlohmann::json json = Settings::load(); |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
m_properties.window.title = strdup(json["window"]["title"].get<std::string>().c_str()); |
|
|
|
@ -55,7 +45,7 @@ namespace Inferno {
|
|
|
|
|
delete m_properties.window.fullscreen; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
nlohmann::json Settings::load() const |
|
|
|
|
nlohmann::json Settings::load() |
|
|
|
|
{ |
|
|
|
|
nlohmann::json json; |
|
|
|
|
|
|
|
|
@ -80,6 +70,4 @@ namespace Inferno {
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// -----------------------------------------
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|