124 lines
3.7 KiB
C++
124 lines
3.7 KiB
C++
#include "MetaEditor/NullEditorShell.h"
|
|
|
|
#include "MetaEditor/DearImGuiEditorShell.h"
|
|
#include "MetaCore/foundation/FileSystem.h"
|
|
#include "MetaCore/engine/editor_core/WorkspaceLayout.h"
|
|
|
|
#include <cstdlib>
|
|
#include <sstream>
|
|
|
|
namespace metacore::editor {
|
|
|
|
namespace {
|
|
|
|
const char* region_name(const metacore::engine::editor_core::DockRegion region) {
|
|
using metacore::engine::editor_core::DockRegion;
|
|
switch (region) {
|
|
case DockRegion::TopMenuBar:
|
|
return "TopMenuBar";
|
|
case DockRegion::TopToolbar:
|
|
return "TopToolbar";
|
|
case DockRegion::LeftSidebar:
|
|
return "LeftSidebar";
|
|
case DockRegion::CenterViewport:
|
|
return "CenterViewport";
|
|
case DockRegion::RightSidebar:
|
|
return "RightSidebar";
|
|
case DockRegion::BottomConsole:
|
|
return "BottomConsole";
|
|
case DockRegion::BottomRuntimePreview:
|
|
return "BottomRuntimePreview";
|
|
}
|
|
return "Unknown";
|
|
}
|
|
|
|
} // namespace
|
|
|
|
bool NullEditorShell::initialize() {
|
|
initialized_ = true;
|
|
return true;
|
|
}
|
|
|
|
void NullEditorShell::shutdown() {
|
|
initialized_ = false;
|
|
last_snapshot_ = {};
|
|
}
|
|
|
|
void NullEditorShell::consume_snapshot(const EditorFrameSnapshot& snapshot) {
|
|
last_snapshot_ = snapshot;
|
|
if (!debug_export_path_.empty()) {
|
|
foundation::write_text_file(debug_export_path_, summarize_snapshot() + "\n" + describe_workspace() + "\n");
|
|
}
|
|
}
|
|
|
|
bool NullEditorShell::initialized() const {
|
|
return initialized_;
|
|
}
|
|
|
|
const EditorFrameSnapshot& NullEditorShell::last_snapshot() const {
|
|
return last_snapshot_;
|
|
}
|
|
|
|
std::string NullEditorShell::summarize_snapshot() const {
|
|
std::ostringstream stream;
|
|
stream << "Shell=" << shell_name()
|
|
<< ", Actions=" << last_snapshot_.actions.size()
|
|
<< ", Panels=" << last_snapshot_.workspace.panels.size()
|
|
<< ", Hierarchy=" << last_snapshot_.hierarchy.size()
|
|
<< ", Assets=" << last_snapshot_.assets.size()
|
|
<< ", Inspector=" << last_snapshot_.inspector.object_name
|
|
<< ", Console=" << last_snapshot_.console.size()
|
|
<< ", Status=" << last_snapshot_.status_text
|
|
<< ", Toolbar=" << (last_snapshot_.toolbar_visible ? "on" : "off")
|
|
<< ", RuntimePreview=" << (last_snapshot_.runtime_preview_visible ? "on" : "off");
|
|
return stream.str();
|
|
}
|
|
|
|
std::string NullEditorShell::describe_workspace() const {
|
|
std::ostringstream stream;
|
|
stream << "Workspace[" << last_snapshot_.workspace.name << "]";
|
|
for (const auto& panel : last_snapshot_.workspace.panels) {
|
|
stream << "\n - " << panel.title
|
|
<< " (" << panel.id << ")"
|
|
<< " @ " << region_name(panel.region)
|
|
<< " visible=" << (panel.visible ? "true" : "false");
|
|
}
|
|
return stream.str();
|
|
}
|
|
|
|
std::string NullEditorShell::shell_name() const {
|
|
return "NullEditorShell";
|
|
}
|
|
|
|
PendingShellEdits NullEditorShell::consume_pending_edits() {
|
|
return {};
|
|
}
|
|
|
|
metacore::engine::render::UiDrawFrame NullEditorShell::consume_render_frame() {
|
|
return {};
|
|
}
|
|
|
|
void NullEditorShell::set_debug_export_path(std::filesystem::path path) {
|
|
debug_export_path_ = std::move(path);
|
|
}
|
|
|
|
std::unique_ptr<IEditorShell> create_default_editor_shell() {
|
|
if (const char* shell_env = std::getenv("METACORE_EDITOR_SHELL")) {
|
|
const std::string value(shell_env);
|
|
if (value == "dearimgui") {
|
|
return std::make_unique<DearImGuiEditorShell>();
|
|
}
|
|
if (value == "null") {
|
|
return std::make_unique<NullEditorShell>();
|
|
}
|
|
}
|
|
|
|
#if defined(METACORE_HAS_IMGUI) && METACORE_HAS_IMGUI
|
|
return std::make_unique<DearImGuiEditorShell>();
|
|
#else
|
|
return std::make_unique<NullEditorShell>();
|
|
#endif
|
|
}
|
|
|
|
} // namespace metacore::editor
|