diff --git a/.gitignore b/.gitignore index 29d61f2358..b6ff87250c 100644 --- a/.gitignore +++ b/.gitignore @@ -117,3 +117,6 @@ data/scene/rosetta/rosetta/obj/Rosetta.obj data/scene/rosetta/rosetta/rosetta/ data/scene/rosetta/rosetta/textures/ data/spice/Rosetta/ +KeyboardMapping.html +LuaScripting.html +Properties.html diff --git a/src/interaction/interactionhandler.cpp b/src/interaction/interactionhandler.cpp index a496a6b636..219461ed84 100644 --- a/src/interaction/interactionhandler.cpp +++ b/src/interaction/interactionhandler.cpp @@ -951,13 +951,33 @@ void InteractionHandler::bindKey(Key key, KeyModifier modifier, std::string lua) void InteractionHandler::writeKeyboardDocumentation(const std::string& type, const std::string& file) { if (type == "text") { - std::ofstream f(absPath(file)); + std::ofstream f; + f.exceptions(~std::ofstream::goodbit); + f.open(file); for (const auto& p : _keyLua) { f << std::to_string(p.first) << ": " << p.second << std::endl; } } + else if (type == "html") { + std::ofstream f; + f.exceptions(~std::ofstream::goodbit); + f.open(absPath(file)); + + std::stringstream json; + json << "["; + for (const auto& p : _keyLua) { + json << "{"; + json << "\"key\": \"" << std::to_string(p.first) << "\","; + json << "\"script\": \"" << p.second << "\","; + json << "},"; + } + json << "]"; + + std::string jsonText = json.str(); + + } else { throw ghoul::RuntimeError( "Unsupported keyboard documentation type '" + type + "'", diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index 5413b08adc..300f2d856b 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -414,13 +414,11 @@ SceneGraph& Scene::sceneGraph() { } void Scene::writePropertyDocumentation(const std::string& filename, const std::string& type) { + LDEBUG("Writing documentation for properties"); if (type == "text") { - LDEBUG("Writing documentation for properties"); - std::ofstream file(filename); - if (!file.good()) { - LERROR("Could not open file '" << filename << "' for writing property documentation"); - return; - } + std::ofstream file; + file.exceptions(~std::ofstream::goodbit); + file.open(filename); using properties::Property; for (SceneGraphNode* node : _graph.nodes()) { @@ -429,13 +427,59 @@ void Scene::writePropertyDocumentation(const std::string& filename, const std::s file << node->name() << std::endl; for (Property* p : properties) { - file << p->fullyQualifiedIdentifier() << ": " << p->guiName() << std::endl; + file << p->fullyQualifiedIdentifier() << ": " << + p->guiName() << std::endl; } file << std::endl; } } } + else if (type == "html") { + std::ofstream file; + file.exceptions(~std::ofstream::goodbit); + file.open(filename); + + // Create JSON + std::function createJson = + [&createJson](properties::PropertyOwner* owner) -> std::string + { + std::stringstream json; + json << "{"; + json << "\"name\": \"" << owner->name() << "\","; + + json << "\"properties\": ["; + for (properties::Property* p : owner->properties()) { + json << "{"; + json << "\"id\": \"" << p->identifier() << "\","; + json << "\"fullyQualifiedId\": \"" << p->fullyQualifiedIdentifier() << "\","; + json << "\"guiName\": \"" << p->guiName() << "\","; + json << "},"; + } + json << "],"; + + json << "\"propertyOwner\": ["; + for (properties::PropertyOwner* o : owner->propertySubOwners()) { + json << createJson(o); + } + json << "],"; + json << "},"; + + return json.str(); + }; + + + std::stringstream json; + json << "["; + for (SceneGraphNode* node : _graph.nodes()) { + json << createJson(node); + } + + json << "]"; + + std::string jsonText = json.str(); + + } else LERROR("Undefined type '" << type << "' for Property documentation"); }