Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Perf-Info button to Dump a system to systemeditor compatible JSON #5888

Merged
merged 3 commits into from
Aug 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/pigui/PerfInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "lua/Lua.h"
#include "lua/LuaManager.h"
#include "scenegraph/Model.h"
#include "JsonUtils.h"
#include "FileSystem.h"

#include <fmt/core.h>
#include <imgui/imgui.h>
Expand Down Expand Up @@ -405,6 +407,32 @@ void PerfInfo::DrawWorldViewStats()
if (system)
system->Dump(Log::GetLog()->GetLogFileHandle());
}

if (ImGui::Button("Dump System-Editor JSON")) {
SystemPath path = Pi::game->GetSectorView()->GetSelected();
RefCountedPtr<StarSystem> system = Pi::game->GetGalaxy()->GetStarSystem(path);

if (system) {
char fileName[1024];
sprintf(fileName, "%s.json", system->GetName().c_str());
Web-eWorks marked this conversation as resolved.
Show resolved Hide resolved
const std::string fname = FileSystem::JoinPathBelow(FileSystem::userFiles.GetRoot(), fileName);
FILE *f = fopen(fname.c_str(), "w");

if (f) {
Json systemdef = Json::object();

system->DumpToJson(systemdef);

// required otherwise the system editor crashes when trying to load it
systemdef["comment"] = system->GetName();

std::string jsonData = systemdef.dump(1, '\t');

fwrite(jsonData.data(), 1, jsonData.size(), f);
fclose(f);
}
}
}
}

}
Expand Down