Made console command registry a better usage pattern

This commit is contained in:
2026-09-16 01:59:18 -07:00
parent a6b98e0613
commit e93b046489
8 changed files with 131 additions and 33 deletions
+3
View File
@@ -6,6 +6,7 @@
#include <sophia/asset_registry.hpp>
#include <sophia/camera_2d.hpp>
#include <sophia/canvas.hpp>
#include <sophia/console/console_command_registry.hpp>
#include <sophia/frame_info.hpp>
#include <sophia/types.hpp>
#include <sophia/ui/debug_ui.hpp>
@@ -52,6 +53,8 @@ class Application {
Camera2D camera;
std::vector<std::string> args;
ConsoleCommandRegistry consoleCommandRegistry;
void drawMesh(MeshHandle handle, const glm::mat4& transform);
private:
@@ -0,0 +1,35 @@
#pragma once
#include <functional>
#include <map>
#include <string>
#include <vector>
namespace sophia {
class ConsoleCommandRegistry {
public:
using Handler = std::function<std::string(const std::vector<std::string>&)>;
struct CommandInfo {
std::string name;
std::string help;
};
void registerCommand(std::string name, std::string help, Handler handler);
bool dispatch(const std::string& name, const std::vector<std::string>& args,
std::string& outResult) const;
std::vector<CommandInfo> list() const;
private:
struct Command {
std::string help;
Handler handler;
};
std::map<std::string, Command> commands;
};
} // namespace sophia
+2 -1
View File
@@ -1,5 +1,6 @@
#pragma once
#include <sophia/console/console_command_registry.hpp>
#include <sophia/handles.hpp>
#include <sophia/ui/panel_registry.hpp>
@@ -10,7 +11,7 @@ class DebugUI {
DebugUI(const DebugUI&) = delete;
DebugUI& operator=(const DebugUI&) = delete;
explicit DebugUI(PanelRegistry& registry);
DebugUI(PanelRegistry& registry, ConsoleCommandRegistry& commands);
~DebugUI() = default;
void show();