Skip to content

Commit

Permalink
Added Perf-Info button to Dump a system to systemeditor compatible JS…
Browse files Browse the repository at this point in the history
  • Loading branch information
fluffyfreak authored Aug 12, 2024
1 parent e123a3f commit 255d5d7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/editor/system/SystemEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 23 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,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<StarSystem> 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);
}
}
}
}

}
Expand Down

0 comments on commit 255d5d7

Please sign in to comment.