Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
Settings.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaghettDev committed Jan 28, 2024
1 parent 04135a0 commit d54025c
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/Settings.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once

#include <string>

#include <Geode/Geode.hpp>

namespace Settings
{
using namespace geode::prelude;

namespace impl
{
template<typename T>
constexpr T get_default()
{
#define DEFINE_DEFAULT(type, def) if constexpr (std::is_same_v<T, type>) 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<typename T>
T get(const std::string_view name, const T& default_value = impl::get_default<T>())
{
if (Mod::get()->getSaveContainer().contains(name))
return Mod::get()->getSavedValue<T>(name);
else
{
Mod::get()->setSavedValue<T>(name, default_value);
return default_value;
}
}
}

0 comments on commit d54025c

Please sign in to comment.