From f83abab0a031c765041b168667a3d6b75649ec31 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Mon, 4 Dec 2023 02:16:37 +0100 Subject: [PATCH] draft generated help --- src/main.cpp | 2 ++ src/message_command_dispatcher.cpp | 50 +++++++++++++++++++++++++----- src/message_command_dispatcher.hpp | 8 +++++ 3 files changed, 52 insertions(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 716510e..884a6d4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -379,6 +379,8 @@ int main(int argc, char** argv) { mc.iterate(0.02f); + mcd.iterate(0.02f); + //std::this_thread::sleep_for( // time left to get to 60fps //std::chrono::duration(0.0166f) // 60fps frame duration //- std::chrono::duration(std::chrono::steady_clock::now() - new_time) // time used for rendering diff --git a/src/message_command_dispatcher.cpp b/src/message_command_dispatcher.cpp index 2eef90e..64f11dd 100644 --- a/src/message_command_dispatcher.cpp +++ b/src/message_command_dispatcher.cpp @@ -1,14 +1,13 @@ #include "./message_command_dispatcher.hpp" -#include "nlohmann/detail/input/position_t.hpp" -#include "solanaceae/message3/registry_message_model.hpp" -#include #include #include #include #include #include +#include +#include //MessageCommandDispatcher::Command::Command(Command&& other) : //m(std::move(other.m)), @@ -44,7 +43,14 @@ MessageCommandDispatcher::MessageCommandDispatcher( MessageCommandDispatcher::~MessageCommandDispatcher(void) { } -void MessageCommandDispatcher::iterate(float time_delta) { +void MessageCommandDispatcher::iterate(float) { + if (!_message_queue.empty()) { + _rmm.sendText( + _message_queue.front().to, + _message_queue.front().message + ); + _message_queue.pop_front(); + } } static std::string_view get_first_word(std::string_view text, std::string_view::size_type& out_next) { @@ -101,10 +107,38 @@ void MessageCommandDispatcher::registerCommand( bool MessageCommandDispatcher::helpCommand(std::string_view params, Message3Handle m) { std::cout << "MCD: help got called '" << params << "'\n"; - _rmm.sendText( - m.get().c, - "I am still missing :), ping green for how it actually works." - ); + std::map> module_command_list; + for (auto it = _command_map.cbegin(); it != _command_map.cend(); it++) { + if (true) { // have permission + module_command_list[it->second.m].push_back(it); + } + } + + const auto contact_from = m.get().c; + + for (const auto& [module_name, command_list] : module_command_list) { + _message_queue.push_back({ + contact_from, + "=== " + module_name + " ===" + }); + + for (const auto& it : command_list) { + std::string help_line {" !"}; + if (!it->second.m_prefix.empty()) { + help_line += it->second.m_prefix + " "; + } + + help_line += it->second.command; + + help_line += " - "; + help_line += it->second.help_text; + + _message_queue.push_back({ + contact_from, + help_line + }); + } + } return true; } diff --git a/src/message_command_dispatcher.hpp b/src/message_command_dispatcher.hpp index 502a4d1..0988280 100644 --- a/src/message_command_dispatcher.hpp +++ b/src/message_command_dispatcher.hpp @@ -2,6 +2,8 @@ #include +#include + // fwd struct ConfigModelI; @@ -21,6 +23,12 @@ class MessageCommandDispatcher : public RegistryMessageModelEventI { }; std::unordered_map _command_map; + struct QueuedMessage { + Contact3 to; + std::string message; + }; + std::deque _message_queue; + public: MessageCommandDispatcher(Contact3Registry& cr, RegistryMessageModel& rmm, ConfigModelI& conf); ~MessageCommandDispatcher(void);