4#include <aegis2d/core/export.hpp>
30using VarValue = std::variant<bool, std::int64_t, double, std::string>;
89 void add(std::string_view name,
VarValue default_value, std::string_view description,
101 template <std::same_as<
bool> Bool>
102 void add(std::string_view name, Bool default_value, std::string_view description,
104 add(name,
VarValue{default_value}, description, flags);
113 template <std::
integral Integer>
114 requires(!std::same_as<Integer, bool>)
115 void add(std::string_view name, Integer default_value, std::string_view description,
117 add(name,
VarValue{
static_cast<std::int64_t
>(default_value)}, description, flags);
126 void add(std::string_view name,
const char* default_value, std::string_view description,
132 [[nodiscard]]
bool contains(std::string_view name)
const;
146 template <
typename Value>
147 [[nodiscard]]
const Value&
get(std::string_view name)
const {
148 return std::get<Value>(info(name).value);
155 [[nodiscard]] std::string
text(std::string_view name)
const;
183 [[nodiscard]]
bool cheats() const noexcept;
187 [[nodiscard]]
std::vector<
std::string_view> names() const;
191 [[nodiscard]]
std::
size_t size() const noexcept;
195 bool cheats_ = false;
202[[nodiscard]] AEGIS2D_CORE_EXPORT
std::
string to_text(const
VarValue& value);
210[[nodiscard]] AEGIS2D_CORE_EXPORT
std::optional<
VarValue> read_value(
std::string_view text,
217[[nodiscard]] AEGIS2D_CORE_EXPORT
bool is_console_name(
std::string_view name) noexcept;
The settings a console reads and changes by name while the game runs.
Definition console_variables.hpp:80
void reset_all()
Puts every variable back at its default.
std::string text(std::string_view name) const
Value of a variable as text, as set_text() reads it back.
void add(std::string_view name, Bool default_value, std::string_view description, VarFlags flags={})
Declares a boolean variable.
Definition console_variables.hpp:102
void add(std::string_view name, Integer default_value, std::string_view description, VarFlags flags={})
Declares a variable from an integer, kept as a 64-bit integer.
Definition console_variables.hpp:115
const Value & get(std::string_view name) const
Value of a variable, in its type.
Definition console_variables.hpp:147
VarResult set(std::string_view name, VarValue value)
Changes a variable, in its type; an integer sets a number too.
bool cheats() const noexcept
Tells whether cheats are on.
void add(std::string_view name, const char *default_value, std::string_view description, VarFlags flags={})
Declares a text variable from a C string.
const VarInfo & info(std::string_view name) const
A variable, as declared, with its value now.
void set_cheats(bool enabled) noexcept
Turns cheats on or off; cheat variables keep their values.
VarResult set_text(std::string_view name, std::string_view text)
Changes a variable from text, as a console or a command line gives it.
bool contains(std::string_view name) const
Tells whether a variable is declared.
void reset(std::string_view name)
Puts a variable back at its default, whatever its flags.
void add(std::string_view name, VarValue default_value, std::string_view description, VarFlags flags={})
Declares a variable, at its default.
Logging, time, main loop, events and configuration shared by client and server.
Definition clock.hpp:11
std::variant< bool, std::int64_t, double, std::string > VarValue
Value of a console variable: a boolean, an integer, a number or a text.
Definition console_variables.hpp:30
std::string_view to_string(VarResult result) noexcept
Sentence for a VarResult, as a console shows it.
VarResult
What became of a change of a console variable.
Definition console_variables.hpp:33
@ ReadOnly
The variable is read-only.
@ Cheat
The variable is a cheat, and cheats are off.
@ BadText
The text does not read as a value of the variable's type.
@ Changed
The variable has its new value.
@ WrongType
The value is of another type than the variable's.
@ Unknown
No command and no variable has this name.
Definition endpoint.hpp:85
What a console variable allows: {.saved = true, .cheat = true}.
Definition console_variables.hpp:20
bool read_only
Keeps its default: only the code that declares it sets it.
Definition console_variables.hpp:26
bool saved
Kept in the player's settings between runs.
Definition console_variables.hpp:22
bool cheat
Changes only while cheats are on (ConsoleVariables::set_cheats()).
Definition console_variables.hpp:24
A console variable as declared, with its value now.
Definition console_variables.hpp:54
VarValue value
Value now.
Definition console_variables.hpp:56
VarValue default_value
Value it was declared with, which reset() restores.
Definition console_variables.hpp:58
std::string description
What it is for, as a console's help shows it.
Definition console_variables.hpp:60
VarFlags flags
Saved, cheat, read-only.
Definition console_variables.hpp:62