Files
XCEngine/editor/app/Services/Scene/EditorSceneRuntime.h

169 lines
6.2 KiB
C++

#pragma once
#include "Scene/EditorSceneBackend.h"
#include "Scene/SceneToolState.h"
#include "State/EditorSelectionService.h"
#include <memory>
#include <filesystem>
#include <optional>
#include <cstdint>
#include <string>
#include <string_view>
#include <vector>
namespace XCEngine::Math {
struct Quaternion;
struct Vector3;
} // namespace XCEngine::Math
namespace XCEngine::Components {
class Scene;
} // namespace XCEngine::Components
namespace XCEngine::UI::Editor::App {
class EditorSceneRuntime {
public:
EditorSceneRuntime() = default;
EditorSceneRuntime(const EditorSceneRuntime&) = delete;
EditorSceneRuntime& operator=(const EditorSceneRuntime&) = delete;
EditorSceneRuntime(EditorSceneRuntime&&) = delete;
EditorSceneRuntime& operator=(EditorSceneRuntime&&) = delete;
void Reset();
void SetBackend(std::unique_ptr<EditorSceneBackend> backend);
EditorStartupSceneResult Initialize(const std::filesystem::path& projectRoot);
void BindSelectionService(EditorSelectionService* selectionService);
void RefreshScene();
void EnsureSceneSelection();
EditorSceneHierarchySnapshot BuildHierarchySnapshot() const;
std::vector<EditorSceneViewportIconSnapshot> BuildSceneViewportIconSnapshots() const;
std::optional<EditorSceneViewportSelectionSnapshot> BuildSceneViewportSelectionSnapshot() const;
std::vector<EditorSceneViewportHelperSnapshot> BuildSelectedViewportHelperSnapshots() const;
bool HasSceneSelection() const;
std::optional<EditorSceneObjectId> GetSelectedObjectId() const;
std::string GetSelectedItemId() const;
std::string GetSelectedDisplayName() const;
std::optional<EditorSceneObjectSnapshot> GetSelectedObjectSnapshot() const;
std::vector<EditorSceneComponentDescriptor> GetSelectedComponents() const;
std::uint64_t GetSelectionStamp() const;
std::uint64_t GetInspectorRevision() const;
std::uint64_t GetSceneContentRevision() const;
bool SetSelection(std::string_view itemId);
bool SetSelection(EditorSceneObjectId id);
void ClearSelection();
bool NewScene(std::string_view sceneName);
bool OpenSceneAsset(const std::filesystem::path& scenePath);
bool SaveScene(const std::filesystem::path& scenePath);
::XCEngine::Components::Scene* GetActiveScene() const;
std::string GetActiveSceneName() const;
std::unique_ptr<EditorScenePlaySession> BeginPlaySession();
bool RenameGameObject(
std::string_view itemId,
std::string_view newName);
bool DeleteGameObject(std::string_view itemId);
std::string DuplicateGameObject(std::string_view itemId);
bool ReparentGameObject(
std::string_view itemId,
std::string_view parentItemId);
bool MoveGameObjectBefore(
std::string_view itemId,
std::string_view targetItemId);
bool MoveGameObjectAfter(
std::string_view itemId,
std::string_view targetItemId);
bool MoveGameObjectToRoot(std::string_view itemId);
bool AddComponentToSelectedGameObject(std::string_view componentTypeName);
bool CanRemoveSelectedComponent(std::string_view componentId) const;
bool RemoveSelectedComponent(std::string_view componentId);
bool SetSelectedTransformLocalPosition(
std::string_view componentId,
const ::XCEngine::Math::Vector3& position);
bool SetSelectedTransformLocalEulerAngles(
std::string_view componentId,
const ::XCEngine::Math::Vector3& eulerAngles);
bool SetSelectedTransformLocalScale(
std::string_view componentId,
const ::XCEngine::Math::Vector3& scale);
bool ApplySelectedComponentMutation(
const EditorSceneComponentMutation& mutation);
bool CaptureSelectedTransformSnapshot(SceneTransformSnapshot& outSnapshot) const;
bool ApplyTransformToolWorldPreview(
EditorSceneObjectId targetId,
const ::XCEngine::Math::Vector3& position,
const ::XCEngine::Math::Quaternion& rotation);
bool ApplyTransformToolLocalScalePreview(
EditorSceneObjectId targetId,
const ::XCEngine::Math::Vector3& localScale);
bool BeginSceneEditTransaction(std::string_view label);
bool HasPendingSceneEditTransaction() const;
bool CommitSceneEditTransaction();
bool CancelSceneEditTransaction();
bool CanUndoSceneEdit() const;
bool CanRedoSceneEdit() const;
bool UndoSceneEdit();
bool RedoSceneEdit();
void NotifyExternalInspectorStateChanged();
private:
struct SceneEditStateSnapshot {
std::string sceneSnapshot = {};
EditorSelectionState selection = {};
};
struct SceneEditTransaction {
std::string label = {};
SceneEditStateSnapshot before = {};
SceneEditStateSnapshot after = {};
};
struct PendingSceneEditTransaction {
std::string label = {};
SceneEditStateSnapshot before = {};
};
EditorSelectionService& SelectionService();
const EditorSelectionService& SelectionService() const;
bool HasHierarchySelection() const;
void RevalidateSelection();
bool HasValidSelection() const;
std::optional<EditorSceneObjectSnapshot> GetObjectSnapshot(
std::string_view itemId) const;
EditorSceneComponentDescriptor ResolveSelectedComponentDescriptor(
std::string_view componentId) const;
bool SelectFirstAvailableGameObject();
bool CaptureSceneEditState(SceneEditStateSnapshot& outSnapshot) const;
bool RestoreSceneEditState(const SceneEditStateSnapshot& snapshot);
void ResetSceneEditHistory();
void ClearPendingSceneEditTransaction();
bool FinalizePendingSceneEditTransaction(bool& outChanged);
void IncrementInspectorRevision();
void IncrementSceneContentRevision();
std::filesystem::path m_projectRoot = {};
std::unique_ptr<EditorSceneBackend> m_backend = {};
EditorSelectionService m_ownedSelectionService = {};
EditorSelectionService* m_selectionService = &m_ownedSelectionService;
std::vector<SceneEditTransaction> m_sceneUndoStack = {};
std::vector<SceneEditTransaction> m_sceneRedoStack = {};
std::optional<PendingSceneEditTransaction> m_pendingSceneEditTransaction = {};
std::uint64_t m_inspectorRevision = 0u;
std::uint64_t m_sceneContentRevision = 0u;
};
} // namespace XCEngine::UI::Editor::App