Skip to content

Instantly share code, notes, and snippets.

@vittorioromeo
Created May 12, 2020 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vittorioromeo/bbc72668ef2f096211cc9326735291dc to your computer and use it in GitHub Desktop.
Save vittorioromeo/bbc72668ef2f096211cc9326735291dc to your computer and use it in GitHub Desktop.
[[nodiscard]] static quake::menu makeMenuFromJSON(const json& src)
{
quake::menu m{"Custom Test Menu", &M_Menu_QuakeVRSettings_f};
for(const auto& [key, value] : src.items())
{
const char* title = key.data();
const auto& bounds = value["bounds"];
const auto generateOption = [&]<typename T>(
const quake::menu_bounds<T> bounds) {
cvar_t* const cvar = Cvar_FindVar(title);
m.add_cvar_entry<T>(title, *cvar, bounds);
};
const auto extractBounds = [&]<typename T>() -> quake::menu_bounds<T> {
return {bounds[0], bounds[1], bounds[2]};
};
if(value["type"] == "float")
{
generateOption(extractBounds.operator()<float>());
}
else if(value["type"] == "int")
{
generateOption(extractBounds.operator()<int>());
}
else if(value["type"] == "bool")
{
generateOption(quake::menu_bounds<bool>{});
}
}
return m;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment