refactor(editor): isolate scene backend boundary
This commit is contained in:
@@ -182,10 +182,18 @@ void EditorSceneRuntime::Reset() {
|
||||
m_inspectorRevision = 0u;
|
||||
}
|
||||
|
||||
void EditorSceneRuntime::SetBackend(std::unique_ptr<EditorSceneBackend> backend) {
|
||||
m_backend = std::move(backend);
|
||||
Reset();
|
||||
}
|
||||
|
||||
bool EditorSceneRuntime::Initialize(const std::filesystem::path& projectRoot) {
|
||||
Reset();
|
||||
if (m_backend == nullptr) {
|
||||
return false;
|
||||
}
|
||||
m_projectRoot = projectRoot;
|
||||
m_startupSceneResult = EnsureEditorStartupScene(projectRoot);
|
||||
m_startupSceneResult = m_backend->EnsureStartupScene(projectRoot);
|
||||
EnsureSceneViewCamera();
|
||||
RefreshScene();
|
||||
return m_startupSceneResult.ready;
|
||||
@@ -225,7 +233,7 @@ const EditorStartupSceneResult& EditorSceneRuntime::GetStartupResult() const {
|
||||
}
|
||||
|
||||
Scene* EditorSceneRuntime::GetActiveScene() const {
|
||||
return GetActiveEditorScene();
|
||||
return m_backend != nullptr ? m_backend->GetActiveScene() : nullptr;
|
||||
}
|
||||
|
||||
::XCEngine::Components::CameraComponent* EditorSceneRuntime::GetSceneViewCamera() {
|
||||
@@ -389,7 +397,7 @@ void EditorSceneRuntime::ClearSelection() {
|
||||
}
|
||||
|
||||
bool EditorSceneRuntime::OpenSceneAsset(const std::filesystem::path& scenePath) {
|
||||
if (!OpenEditorSceneAsset(scenePath)) {
|
||||
if (m_backend == nullptr || !m_backend->OpenSceneAsset(scenePath)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -413,13 +421,15 @@ bool EditorSceneRuntime::OpenSceneAsset(const std::filesystem::path& scenePath)
|
||||
}
|
||||
|
||||
GameObject* EditorSceneRuntime::FindGameObject(std::string_view itemId) const {
|
||||
return FindEditorGameObject(itemId);
|
||||
return m_backend != nullptr ? m_backend->FindGameObject(itemId) : nullptr;
|
||||
}
|
||||
|
||||
bool EditorSceneRuntime::RenameGameObject(
|
||||
std::string_view itemId,
|
||||
std::string_view newName) {
|
||||
const bool renamed = RenameEditorGameObject(itemId, newName);
|
||||
const bool renamed =
|
||||
m_backend != nullptr &&
|
||||
m_backend->RenameGameObject(itemId, newName);
|
||||
if (renamed) {
|
||||
IncrementInspectorRevision();
|
||||
}
|
||||
@@ -429,7 +439,9 @@ bool EditorSceneRuntime::RenameGameObject(
|
||||
|
||||
bool EditorSceneRuntime::DeleteGameObject(std::string_view itemId) {
|
||||
ResetTransformEditHistory();
|
||||
const bool deleted = DeleteEditorGameObject(itemId);
|
||||
const bool deleted =
|
||||
m_backend != nullptr &&
|
||||
m_backend->DeleteGameObject(itemId);
|
||||
if (deleted) {
|
||||
IncrementInspectorRevision();
|
||||
}
|
||||
@@ -440,7 +452,10 @@ bool EditorSceneRuntime::DeleteGameObject(std::string_view itemId) {
|
||||
|
||||
std::string EditorSceneRuntime::DuplicateGameObject(std::string_view itemId) {
|
||||
ResetTransformEditHistory();
|
||||
const std::string duplicatedItemId = DuplicateEditorGameObject(itemId);
|
||||
const std::string duplicatedItemId =
|
||||
m_backend != nullptr
|
||||
? m_backend->DuplicateGameObject(itemId)
|
||||
: std::string();
|
||||
if (!duplicatedItemId.empty()) {
|
||||
IncrementInspectorRevision();
|
||||
SetSelection(duplicatedItemId);
|
||||
@@ -455,7 +470,8 @@ bool EditorSceneRuntime::ReparentGameObject(
|
||||
std::string_view parentItemId) {
|
||||
ResetTransformEditHistory();
|
||||
const bool reparented =
|
||||
ReparentEditorGameObject(itemId, parentItemId);
|
||||
m_backend != nullptr &&
|
||||
m_backend->ReparentGameObject(itemId, parentItemId);
|
||||
if (reparented) {
|
||||
IncrementInspectorRevision();
|
||||
}
|
||||
@@ -468,7 +484,8 @@ bool EditorSceneRuntime::MoveGameObjectBefore(
|
||||
std::string_view targetItemId) {
|
||||
ResetTransformEditHistory();
|
||||
const bool moved =
|
||||
MoveEditorGameObjectBefore(itemId, targetItemId);
|
||||
m_backend != nullptr &&
|
||||
m_backend->MoveGameObjectBefore(itemId, targetItemId);
|
||||
if (moved) {
|
||||
IncrementInspectorRevision();
|
||||
}
|
||||
@@ -481,7 +498,8 @@ bool EditorSceneRuntime::MoveGameObjectAfter(
|
||||
std::string_view targetItemId) {
|
||||
ResetTransformEditHistory();
|
||||
const bool moved =
|
||||
MoveEditorGameObjectAfter(itemId, targetItemId);
|
||||
m_backend != nullptr &&
|
||||
m_backend->MoveGameObjectAfter(itemId, targetItemId);
|
||||
if (moved) {
|
||||
IncrementInspectorRevision();
|
||||
}
|
||||
@@ -491,7 +509,9 @@ bool EditorSceneRuntime::MoveGameObjectAfter(
|
||||
|
||||
bool EditorSceneRuntime::MoveGameObjectToRoot(std::string_view itemId) {
|
||||
ResetTransformEditHistory();
|
||||
const bool moved = MoveEditorGameObjectToRoot(itemId);
|
||||
const bool moved =
|
||||
m_backend != nullptr &&
|
||||
m_backend->MoveGameObjectToRoot(itemId);
|
||||
if (moved) {
|
||||
IncrementInspectorRevision();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user