5#include <aegis2d/core/export.hpp>
50 CommandCall(std::span<const CommandArg> arguments, std::vector<std::optional<VarValue>> values);
56 [[nodiscard]]
bool has(std::string_view argument)
const;
63 [[nodiscard]]
const std::string&
text(std::string_view argument)
const;
69 [[nodiscard]] std::int64_t
integer(std::string_view argument)
const;
75 [[nodiscard]]
double number(std::string_view argument)
const;
81 [[nodiscard]]
bool boolean(std::string_view argument)
const;
84 [[nodiscard]]
const VarValue& value(std::string_view argument)
const;
85 [[nodiscard]] std::size_t index(std::string_view argument)
const;
87 std::span<const CommandArg> arguments_;
88 std::vector<std::optional<VarValue>> values_;
153 void add(std::string_view name, std::vector<CommandArg> arguments, std::string_view description,
164 [[nodiscard]]
bool contains(std::string_view name)
const;
175 [[nodiscard]] std::string
usage(std::string_view name)
const;
179 [[nodiscard]] std::vector<std::string>
names()
const;
183 std::vector<CommandArg> arguments;
184 std::string description;
188 [[nodiscard]] std::string help(std::span<const std::string> words)
const;
189 CommandResult run_variable(std::string_view name, std::span<const std::string> words);
191 std::map<std::string, Command, std::less<>> commands_;
The arguments of a command being run, read in their types.
Definition commands.hpp:45
bool has(std::string_view argument) const
Tells whether an argument was given.
bool boolean(std::string_view argument) const
A boolean argument.
CommandCall(std::span< const CommandArg > arguments, std::vector< std::optional< VarValue > > values)
Arguments as read.
const std::string & text(std::string_view argument) const
A text argument.
double number(std::string_view argument) const
A number argument; an integer argument reads as a number too.
std::int64_t integer(std::string_view argument) const
An integer argument.
The commands a console runs: each has a name, its arguments and a help.
Definition commands.hpp:140
void add_variables(ConsoleVariables &variables) noexcept
Makes the variables of a registry commands too.
std::string usage(std::string_view name) const
How to call a command.
CommandResult run(std::string_view line)
Runs a line.
bool contains(std::string_view name) const
Tells whether a line can start with a name.
std::vector< std::string > names() const
Names of the commands and the variables, in alphabetical order.
void add(std::string_view name, std::vector< CommandArg > arguments, std::string_view description, CommandHandler handler)
Adds a command.
Commands()
Creates the commands, with help only.
The settings a console reads and changes by name while the game runs.
Definition console_variables.hpp:80
Console variables: named, typed settings with a default, a description and flags.
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::function< std::string(const CommandCall &call)> CommandHandler
What a command does with its arguments.
Definition commands.hpp:94
ArgType
Type of an argument of a command, read from its text as a console variable's.
Definition commands.hpp:20
@ Boolean
1, 0, true, false, on or off.
@ Text
A word, or words between double quotes.
CommandStatus
How running a line went.
Definition commands.hpp:97
@ WrongArguments
An argument is missing, too many are given, or one does not read in its type.
@ Unknown
No command and no variable has this name.
@ Empty
The line has no command (blank).
@ Failed
The command failed, or a variable refused its new value.
An argument a command takes: {.name = "count", .type = ArgType::Integer}.
Definition commands.hpp:32
ArgType type
Its type.
Definition commands.hpp:36
bool optional
May be left out; the optional arguments come after the others.
Definition commands.hpp:38
bool rest
Takes the rest of the words, joined by a space: only for the last argument, a text.
Definition commands.hpp:41
std::string name
Its name, as the help shows it and CommandCall reads it.
Definition commands.hpp:34
What running a line gave.
Definition commands.hpp:111
CommandStatus status
How it went.
Definition commands.hpp:113
std::string text
What the command showed, or why the line did not run (with the usage of the command for wrong argumen...
Definition commands.hpp:116