mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-26 21:51:13 +01:00
Add initial simulator base
This commit is contained in:
@@ -1 +1,34 @@
|
||||
#include "simulator_base.hpp"
|
||||
|
||||
SimulatorBase::SimulatorBase(std::string name)
|
||||
: p_name(name), p_timer([this]{ timer(); })
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SimulatorBase::add_UI_item(UI_item* item) {
|
||||
// Add a UI item to the simulator
|
||||
p_UI_items_map[item->id()] = item;
|
||||
p_UI_items.push_back(item);
|
||||
}
|
||||
|
||||
json SimulatorBase::get_UI_items() const {
|
||||
// Get the UI items
|
||||
json items;
|
||||
items["name"] = p_name;
|
||||
for (UI_item* item : p_UI_items) {
|
||||
items["UI_items"].push_back(item->to_json());
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
UI_item* SimulatorBase::get_UI_item(std::string id) const {
|
||||
// Get a UI item by id
|
||||
return p_UI_items_map.at(id);
|
||||
}
|
||||
|
||||
void SimulatorBase::run() {
|
||||
// Run the simulator
|
||||
p_timer.setInterval(std::chrono::milliseconds(100));
|
||||
}
|
||||
@@ -1 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "UI.hpp"
|
||||
#include "timer.hpp"
|
||||
|
||||
class SimulatorBase {
|
||||
|
||||
public:
|
||||
SimulatorBase(std::string name);
|
||||
|
||||
void add_UI_item(UI_item* item);
|
||||
json get_UI_items() const;
|
||||
|
||||
UI_item* get_UI_item(std::string id) const;
|
||||
|
||||
void run();
|
||||
|
||||
virtual void timer() {};
|
||||
protected:
|
||||
std::string p_name;
|
||||
std::vector<UI_item*> p_UI_items;
|
||||
std::map<std::string, UI_item*> p_UI_items_map;
|
||||
Timer p_timer;
|
||||
};
|
||||
Reference in New Issue
Block a user