From f4d8246bc805a4d27374fb3dfded3afa7c66d598 Mon Sep 17 00:00:00 2001 From: Sander Speetjens Date: Thu, 22 Aug 2024 12:54:01 +0200 Subject: [PATCH] simulators change from returning diff to returning a list of ui_elements by extracting the index out of the diff and pushing the item in the list --- tools/simulators.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tools/simulators.cpp b/tools/simulators.cpp index dc850f5..2632366 100644 --- a/tools/simulators.cpp +++ b/tools/simulators.cpp @@ -91,13 +91,23 @@ json Simulators::changed_UI_items() json changed; changed["event"] = "UI_changed"; - changed["diff"] = json::diff(m_before, after); + json diff = json::diff(m_before, after); - if (changed["diff"].empty()) + if (diff.empty()) { return "{}"_json; } + // diff to ui items list + // get index out of each item in diff /UI_items/0/** + // Then push the ui_item at that index to the changed json + for (auto& item : diff) + { + std::string path = item["path"]; + std::string index_s = path.substr(10, path.find("/", 10) - 10); + changed["UI_items"].push_back(after["UI_items"][std::stoul(index_s)]); + } + m_before = after; return changed; } \ No newline at end of file