Added better settings API that handles errors better

This fixes #161
This commit is contained in:
WerWolv
2021-02-16 23:42:35 +01:00
parent 096bdef25a
commit df06dd49c5
5 changed files with 60 additions and 41 deletions

View File

@@ -109,6 +109,15 @@ namespace hex {
return SharedData::settingsEntries;
}
std::optional<nlohmann::json> ContentRegistry::Settings::getSetting(std::string_view unlocalizedCategory, std::string_view unlocalizedName) {
auto &settings = getSettingsData();
if (!settings.contains(unlocalizedCategory)) return { };
if (!settings[unlocalizedCategory.data()].contains(unlocalizedName)) return { };
return settings[unlocalizedCategory.data()][unlocalizedName.data()];
}
nlohmann::json& ContentRegistry::Settings::getSettingsData() {
return SharedData::settingsJson;
}