Files
XCEngine/editor/app/Features/Inspector/InspectorSubject.cpp

56 lines
1.6 KiB
C++

#include "Inspector/InspectorSubject.h"
#include "Project/EditorProjectRuntime.h"
#include "Scene/EditorSceneRuntime.h"
namespace XCEngine::UI::Editor::App {
InspectorSelectionSource ResolveInspectorSelectionSource(
const EditorProjectRuntime& projectRuntime,
const EditorSceneRuntime& sceneRuntime) {
if (projectRuntime.HasSelection()) {
return InspectorSelectionSource::Project;
}
if (sceneRuntime.HasSceneSelection()) {
return InspectorSelectionSource::Scene;
}
return InspectorSelectionSource::None;
}
InspectorSubject BuildInspectorSubject(
const EditorProjectRuntime& projectRuntime,
const EditorSceneRuntime& sceneRuntime) {
InspectorSubject subject = {};
subject.source = ResolveInspectorSelectionSource(projectRuntime, sceneRuntime);
switch (subject.source) {
case InspectorSelectionSource::Project:
subject.kind = InspectorSubjectKind::ProjectAsset;
subject.projectAsset.selection = projectRuntime.GetSelection();
break;
case InspectorSelectionSource::Scene:
if (const std::optional<EditorSceneObjectSnapshot> objectSnapshot =
sceneRuntime.GetSelectedObjectSnapshot();
objectSnapshot.has_value()) {
subject.kind = InspectorSubjectKind::SceneObject;
subject.sceneObject.object = objectSnapshot.value();
}
break;
case InspectorSelectionSource::None:
default:
break;
}
if (!subject.HasSelection()) {
subject.source = InspectorSelectionSource::None;
}
return subject;
}
} // namespace XCEngine::UI::Editor::App