From 255d5d716c1f9cd0e61e0b8032aa7ca9a9bf0ae5 Mon Sep 17 00:00:00 2001 From: Andrew Copland Date: Mon, 12 Aug 2024 20:44:02 +0100 Subject: [PATCH] Added Perf-Info button to Dump a system to systemeditor compatible JSON (#5888) --- src/editor/system/SystemEditor.cpp | 2 +- src/pigui/PerfInfo.cpp | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/editor/system/SystemEditor.cpp b/src/editor/system/SystemEditor.cpp index e1239b88cb9..7145f92b653 100644 --- a/src/editor/system/SystemEditor.cpp +++ b/src/editor/system/SystemEditor.cpp @@ -222,7 +222,7 @@ bool SystemEditor::LoadSystemFromFile(const FileSystem::FileInfo &file) ok = LoadCustomSystem(csys); if (ok) - m_systemInfo.comment = data["comment"]; + m_systemInfo.comment = data.value("comment", ""); } else if (ends_with_ci(file.GetPath(), ".lua")) { const CustomSystem *csys = m_systemLoader->LoadSystem(file.GetPath()); if (csys) diff --git a/src/pigui/PerfInfo.cpp b/src/pigui/PerfInfo.cpp index 629c06242d6..6b01267c1d3 100644 --- a/src/pigui/PerfInfo.cpp +++ b/src/pigui/PerfInfo.cpp @@ -17,6 +17,8 @@ #include "lua/Lua.h" #include "lua/LuaManager.h" #include "scenegraph/Model.h" +#include "JsonUtils.h" +#include "FileSystem.h" #include #include @@ -405,6 +407,27 @@ void PerfInfo::DrawWorldViewStats() if (system) system->Dump(Log::GetLog()->GetLogFileHandle()); } + + if (ImGui::Button("Dump System-Editor JSON")) { + SystemPath path = Pi::game->GetSectorView()->GetSelected(); + RefCountedPtr system = Pi::game->GetGalaxy()->GetStarSystem(path); + + if (system) { + const std::string fname = FileSystem::JoinPathBelow(FileSystem::userFiles.GetRoot(), fmt::format("{}.json", system->GetName())); + FILE *f = fopen(fname.c_str(), "w"); + + if (f) { + Json systemdef = Json::object(); + + system->DumpToJson(systemdef); + + std::string jsonData = systemdef.dump(1, '\t'); + + fwrite(jsonData.data(), 1, jsonData.size(), f); + fclose(f); + } + } + } } }