diff --git a/src/Settings.hpp b/src/Settings.hpp new file mode 100644 index 0000000..5505859 --- /dev/null +++ b/src/Settings.hpp @@ -0,0 +1,40 @@ +#pragma once + +#include + +#include + +namespace Settings +{ + using namespace geode::prelude; + + namespace impl + { + template + constexpr T get_default() + { + #define DEFINE_DEFAULT(type, def) if constexpr (std::is_same_v) default_value = def + + T default_value; + + DEFINE_DEFAULT(bool, false); + DEFINE_DEFAULT(float, .0f); + DEFINE_DEFAULT(int, 0); + DEFINE_DEFAULT(std::string, ""); + + return default_value; + } + } + + template + T get(const std::string_view name, const T& default_value = impl::get_default()) + { + if (Mod::get()->getSaveContainer().contains(name)) + return Mod::get()->getSavedValue(name); + else + { + Mod::get()->setSavedValue(name, default_value); + return default_value; + } + } +}