#include "Features/Inspector/InspectorSubject.h" #include "Scene/EditorSceneRuntime.h" namespace XCEngine::UI::Editor::App { InspectorSelectionSource ResolveInspectorSelectionSource( const EditorSession& session, const EditorSceneRuntime& sceneRuntime) { const bool hasProjectSelection = session.selection.kind == EditorSelectionKind::ProjectItem; const bool hasSceneSelection = sceneRuntime.HasSceneSelection(); const std::uint64_t projectStamp = session.selection.stamp; const std::uint64_t sceneStamp = sceneRuntime.GetSelectionStamp(); if (projectStamp > sceneStamp) { return hasProjectSelection ? InspectorSelectionSource::Project : InspectorSelectionSource::None; } if (sceneStamp > projectStamp) { return hasSceneSelection ? InspectorSelectionSource::Scene : InspectorSelectionSource::None; } if (hasSceneSelection) { return InspectorSelectionSource::Scene; } if (hasProjectSelection) { return InspectorSelectionSource::Project; } return InspectorSelectionSource::None; } InspectorSubject BuildInspectorSubject( const EditorSession& session, const EditorSceneRuntime& sceneRuntime) { InspectorSubject subject = {}; subject.source = ResolveInspectorSelectionSource(session, sceneRuntime); switch (subject.source) { case InspectorSelectionSource::Project: subject.kind = InspectorSubjectKind::ProjectAsset; subject.projectAsset.selection = session.selection; break; case InspectorSelectionSource::Scene: if (const auto* gameObject = sceneRuntime.GetSelectedGameObject(); gameObject != nullptr) { subject.kind = InspectorSubjectKind::SceneObject; subject.sceneObject.gameObject = gameObject; subject.sceneObject.itemId = sceneRuntime.GetSelectedItemId(); subject.sceneObject.displayName = sceneRuntime.GetSelectedDisplayName(); } break; case InspectorSelectionSource::None: default: break; } if (!subject.HasSelection()) { subject.source = InspectorSelectionSource::None; } return subject; } } // namespace XCEngine::UI::Editor::App