simulators

add changed_ui_items
This commit is contained in:
2024-08-22 10:11:09 +02:00
parent aaff6802c3
commit 1d89d5b1e1
2 changed files with 44 additions and 3 deletions
+41 -2
View File
@@ -3,7 +3,7 @@
Simulators::Simulators() Simulators::Simulators()
{ {
INSERT_SIMULATOR(Test_Sim);
} }
void Simulators::run() void Simulators::run()
@@ -17,6 +17,7 @@ void Simulators::run()
return; return;
} }
m_before = this->m_simulators.at(m_current_simulator)->get_UI_items();
this->m_simulators.at(m_current_simulator)->run(); this->m_simulators.at(m_current_simulator)->run();
} }
@@ -59,7 +60,7 @@ std::vector<std::string> Simulators::list_simulators() const
return names; return names;
} }
Simulator_base* Simulators::invoke_active_simulator() const Simulator_base* Simulators::invoke_active_simulator()
{ {
if (this->m_simulators.empty()) if (this->m_simulators.empty())
{ {
@@ -70,5 +71,43 @@ Simulator_base* Simulators::invoke_active_simulator() const
return nullptr; return nullptr;
} }
m_before = this->m_simulators.at(m_current_simulator)->get_UI_items();
return this->m_simulators.at(m_current_simulator).get(); return this->m_simulators.at(m_current_simulator).get();
} }
json Simulators::changed_UI_items()
{
if (this->m_simulators.empty())
{
return json();
}
if (this->m_current_simulator.empty())
{
return json();
}
json after = this->m_simulators.at(m_current_simulator)->get_UI_items();
json changed;
changed["event"] = "UI_changed";
if (m_before["UI_items"].empty())
{
changed = after;
return changed;
}
for (const json& item : after["UI_items"])
{
for (const json& before_item : m_before["UI_items"])
{
if (before_item["id"] == item["id"])
{
if (before_item != item)
{
changed["UI_items"].push_back(item);
}
}
}
}
return changed;
}
+3 -1
View File
@@ -13,8 +13,10 @@ class Simulators {
void stop(); void stop();
void switch_simulator(std::string name); void switch_simulator(std::string name);
std::vector<std::string> list_simulators() const; std::vector<std::string> list_simulators() const;
Simulator_base* invoke_active_simulator() const; Simulator_base* invoke_active_simulator();
json changed_UI_items();
private: private:
std::map<std::string, std::unique_ptr<Simulator_base>> m_simulators; std::map<std::string, std::unique_ptr<Simulator_base>> m_simulators;
std::string m_current_simulator; std::string m_current_simulator;
json m_before;
}; };