This commit is contained in:
2024-08-29 15:00:27 +02:00
parent 6c6a60e980
commit 21a2c16607
31 changed files with 457 additions and 409 deletions
+62 -60
View File
@@ -1,8 +1,8 @@
#include "message_parser.hpp"
#include <magic_enum.hpp>
#include <iostream>
#include <magic_enum.hpp>
extern Simulators* g_simulators;
extern Simulators *g_simulators;
std::string message_parser(std::string message)
{
@@ -31,36 +31,37 @@ json command_parser(json command)
Command cmd = magic_enum::enum_cast<Command>(type).value_or(Command::end);
switch (cmd)
{
case Command::get_UI_element:
spdlog::info("Command {}: {}", type, std::string(command.at("id")));
j["response"]["type"] = type;
j["response"]["UI_item"] = g_simulators->invoke_active_simulator()->get_UI_item(command.at("id"))->to_json();
break;
case Command::get_UI_elements:
spdlog::info("Command {}", type);
j["response"]["type"] = type;
j["response"]["UI_items"] = g_simulators->invoke_active_simulator()->get_UI_items()["UI_items"];
break;
case Command::switch_simulator:
spdlog::info("Command {} to {}", type, std::string(command.at("name")));
g_simulators->switch_simulator(command.at("name"));
j["response"]["type"] = type;
break;
case Command::get_active_simulator_name:
spdlog::info("Command {}", type);
j["response"]["type"] = type;
j["response"]["name"] = g_simulators->active_simulator_name();
break;
case Command::get_simulators:
spdlog::info("Command {}", type);
j["response"]["type"] = type;
j["response"]["simulators"] = g_simulators->list_simulators();
break;
default:
break;
case Command::get_UI_element:
spdlog::info("Command {}: {}", type, std::string(command.at("id")));
j["response"]["type"] = type;
j["response"]["UI_item"] =
g_simulators->invoke_active_simulator()->get_UI_item(command.at("id"))->to_json();
break;
case Command::get_UI_elements:
spdlog::info("Command {}", type);
j["response"]["type"] = type;
j["response"]["UI_items"] = g_simulators->invoke_active_simulator()->get_UI_items()["UI_items"];
break;
case Command::switch_simulator:
spdlog::info("Command {} to {}", type, std::string(command.at("name")));
g_simulators->switch_simulator(command.at("name"));
j["response"]["type"] = type;
break;
case Command::get_active_simulator_name:
spdlog::info("Command {}", type);
j["response"]["type"] = type;
j["response"]["name"] = g_simulators->active_simulator_name();
break;
case Command::get_simulators:
spdlog::info("Command {}", type);
j["response"]["type"] = type;
j["response"]["simulators"] = g_simulators->list_simulators();
break;
default:
break;
}
}
catch(const json::exception& e)
catch (const json::exception &e)
{
spdlog::error(e.what());
}
@@ -80,39 +81,40 @@ void event_handler(json event)
return;
}
switch(e)
switch (e)
{
case Event::clicked:
{
spdlog::debug("Event {}: {}", type, std::string(event.at("id")));
g_simulators->invoke_active_simulator()->get_UI_item(std::string(event.at("id")))->click();
break;
}
case Event::value_changed:
{
spdlog::debug("Event {}: {} {}", type, std::string(event.at("id")), (double)(event["value"]));
g_simulators->invoke_active_simulator()->get_UI_item(std::string(event.at("id")))->set_value((double)event.at("value"));
break;
}
case Event::text_changed:
{
spdlog::debug("Event {}: {} {}", type, std::string(event.at("id")), std::string(event.at("text")));
g_simulators->invoke_active_simulator()->get_UI_item(std::string(event.at("id")))->set_text(std::string(event.at("text")));
break;
}
case Event::selected:
{
spdlog::debug("Event {}: {} {}", type, std::string(event.at("id")), std::string(event.at("selected")));
g_simulators->invoke_active_simulator()->get_UI_item(std::string(event.at("id")))->set_selected(std::string(event.at("selected")));
break;
}
default:
{
break;
}
case Event::clicked: {
spdlog::debug("Event {}: {}", type, std::string(event.at("id")));
g_simulators->invoke_active_simulator()->get_UI_item(std::string(event.at("id")))->click();
break;
}
case Event::value_changed: {
spdlog::debug("Event {}: {} {}", type, std::string(event.at("id")), (double)(event["value"]));
g_simulators->invoke_active_simulator()
->get_UI_item(std::string(event.at("id")))
->set_value((double)event.at("value"));
break;
}
case Event::text_changed: {
spdlog::debug("Event {}: {} {}", type, std::string(event.at("id")), std::string(event.at("text")));
g_simulators->invoke_active_simulator()
->get_UI_item(std::string(event.at("id")))
->set_text(std::string(event.at("text")));
break;
}
case Event::selected: {
spdlog::debug("Event {}: {} {}", type, std::string(event.at("id")), std::string(event.at("selected")));
g_simulators->invoke_active_simulator()
->get_UI_item(std::string(event.at("id")))
->set_selected(std::string(event.at("selected")));
break;
}
default: {
break;
}
}
}
catch(const json::exception& e)
catch (const json::exception &e)
{
spdlog::error(e.what());
}