From 126c62dc3a362a8287a9beac311956485b84dd24 Mon Sep 17 00:00:00 2001 From: Ylva Selling Date: Fri, 23 Feb 2024 16:44:22 +0100 Subject: [PATCH] Move json documentation generation from keybindings to documentation engine --- .../documentation/documentationengine.h | 1 + .../openspace/interaction/keybindingmanager.h | 2 -- .../server/src/topics/documentationtopic.cpp | 4 ++-- src/documentation/documentationengine.cpp | 21 +++++++++++++++++++ src/interaction/keybindingmanager.cpp | 19 ----------------- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/include/openspace/documentation/documentationengine.h b/include/openspace/documentation/documentationengine.h index 4e3be2269f..37af2cfa39 100644 --- a/include/openspace/documentation/documentationengine.h +++ b/include/openspace/documentation/documentationengine.h @@ -90,6 +90,7 @@ public: nlohmann::json generateScriptEngineJson() const; nlohmann::json generateFactoryManagerJson() const; + nlohmann::json generateKeybindingsJson() const; private: /// The list of all Documentation%s that are stored by the DocumentationEngine std::vector _documentations; diff --git a/include/openspace/interaction/keybindingmanager.h b/include/openspace/interaction/keybindingmanager.h index c638c5015d..9e1865b769 100644 --- a/include/openspace/interaction/keybindingmanager.h +++ b/include/openspace/interaction/keybindingmanager.h @@ -53,8 +53,6 @@ public: void keyboardCallback(Key key, KeyModifier modifier, KeyAction action); - nlohmann::json generateJson() const; - const std::multimap& keyBindings() const; private: diff --git a/modules/server/src/topics/documentationtopic.cpp b/modules/server/src/topics/documentationtopic.cpp index ebfaad75ef..0890319f50 100644 --- a/modules/server/src/topics/documentationtopic.cpp +++ b/modules/server/src/topics/documentationtopic.cpp @@ -53,10 +53,10 @@ void DocumentationTopic::handleJson(const nlohmann::json& json) { response = DocEng.generateFactoryManagerJson(); } else if (requestedType == "keyboard") { - response = global::keybindingManager->generateJson(); + response = DocEng.generateKeybindingsJson(); } else if (requestedType == "asset") { - response = global::keybindingManager->generateJson(); + // TODO: Add asset documentation here } else if (requestedType == "meta") { response = SceneLicenseWriter().generateJsonList(); diff --git a/src/documentation/documentationengine.cpp b/src/documentation/documentationengine.cpp index 97a0067d40..43cedcdcb0 100644 --- a/src/documentation/documentationengine.cpp +++ b/src/documentation/documentationengine.cpp @@ -281,6 +281,27 @@ nlohmann::json DocumentationEngine::generateFactoryManagerJson() const { return result; } +nlohmann::json DocumentationEngine::generateKeybindingsJson() const { + ZoneScoped; + + nlohmann::json json; + const std::multimap& luaKeys = + global::keybindingManager->keyBindings(); + + for (const std::pair& p : luaKeys) { + nlohmann::json keybind; + keybind["name"] = ghoul::to_string(p.first); + keybind["action"] = p.second; + json.push_back(std::move(keybind)); + } + sortJson(json, "name"); + + nlohmann::json result; + result["name"] = "Keybindings"; + result["keybindings"] = json; + return result; +} + void DocumentationEngine::writeDocumentation() const { ZoneScoped; diff --git a/src/interaction/keybindingmanager.cpp b/src/interaction/keybindingmanager.cpp index bc438be44b..b13301898d 100644 --- a/src/interaction/keybindingmanager.cpp +++ b/src/interaction/keybindingmanager.cpp @@ -115,25 +115,6 @@ const std::multimap& KeybindingManager::keyBinding return _keyLua; } -nlohmann::json KeybindingManager::generateJson() const { - ZoneScoped; - - nlohmann::json json; - - for (const std::pair& p : _keyLua) { - nlohmann::json keybind; - keybind["name"] = ghoul::to_string(p.first); - keybind["action"] = p.second; - json.push_back(std::move(keybind)); - } - sortJson(json, "name"); - - nlohmann::json result; - result["name"] = "Keybindings"; - result["keybindings"] = json; - return result; -} - scripting::LuaLibrary KeybindingManager::luaLibrary() { return { "",