libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
Console.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdint.h>
4#include <string>
5#include <memory>
6#include <vector>
7#include <functional>
8#include <map>
9#include <imgui.h>
10#include "ship/core/Component.h"
11
12namespace Ship {
13
14class Console;
15
24typedef std::function<int32_t(std::shared_ptr<Console> console, std::vector<std::string> args, std::string* output)>
26
28enum class ArgumentType { TEXT, NUMBER };
29
34 std::string Info;
36 bool Optional = false;
37};
38
44 std::string Description;
45 std::vector<CommandArgument> Arguments;
46};
47
63class Console : public Component {
64 public:
67
87 int32_t Run(const std::string& command, std::string* output);
88
93 bool HasCommand(const std::string& command);
94
100 void AddCommand(const std::string& command, CommandEntry entry);
101
107 std::string BuildUsage(const std::string& command);
108
114 std::string BuildUsage(const CommandEntry& entry);
115
120 CommandEntry& GetCommand(const std::string& command);
121
127 std::map<std::string, CommandEntry>& GetCommands();
128
129 protected:
135 void OnInit(const nlohmann::json& initArgs = nlohmann::json::object()) override;
136
137 private:
138 std::map<std::string, CommandEntry> mCommands;
139};
140
141} // namespace Ship
A named Part with a parent/child hierarchy and optional thread safety.
Definition Component.h:34
In-process command interpreter used by ConsoleWindow.
Definition Console.h:63
CommandEntry & GetCommand(const std::string &command)
Returns a reference to the CommandEntry for the given command name.
bool HasCommand(const std::string &command)
Returns true if a command with the given name is registered.
std::string BuildUsage(const std::string &command)
Builds a usage string from the command's argument list.
std::string BuildUsage(const CommandEntry &entry)
Builds a usage string directly from a CommandEntry.
void OnInit(const nlohmann::json &initArgs=nlohmann::json::object()) override
Registers built-in commands. Called automatically by Component::Init().
std::map< std::string, CommandEntry > & GetCommands()
Returns the full command registry (name → entry map).
void AddCommand(const std::string &command, CommandEntry entry)
Registers a new command.
int32_t Run(const std::string &command, std::string *output)
Registers built-in commands. Called by Component::Init().
Core namespace for the libultraship engine framework.
Definition gfx_direct3d_common.h:14
ArgumentType
Describes the expected type of a command argument.
Definition Console.h:28
std::function< int32_t(std::shared_ptr< Console > console, std::vector< std::string > args, std::string *output)> CommandHandler
Signature of a function that handles a console command.
Definition Console.h:25
Metadata for a single positional argument of a console command.
Definition Console.h:33
ArgumentType Type
Expected value type (text or numeric).
Definition Console.h:35
bool Optional
If true, the argument may be omitted.
Definition Console.h:36
std::string Info
Human-readable description of the argument.
Definition Console.h:34
Registration record for a single console command.
Definition Console.h:42
std::vector< CommandArgument > Arguments
Ordered list of expected arguments.
Definition Console.h:45
CommandHandler Handler
Callable invoked when the command is executed.
Definition Console.h:43
std::string Description
Short description shown by the "help" command.
Definition Console.h:44