From 60bb47f25ee0714d609d2e6be8390aceed5783fe Mon Sep 17 00:00:00 2001 From: Joeyrp Date: Wed, 2 Mar 2022 20:07:46 -0500 Subject: [PATCH] Editor Assets are included when a project is saved and loaded --- docs/Bugs.todo | 3 +++ src/run_modes/editor/editor.cpp | 10 ++++++---- .../editor/project/contents/content_manager.cpp | 16 ++++++++-------- src/run_modes/editor/project/project.cpp | 8 ++++++-- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/docs/Bugs.todo b/docs/Bugs.todo index e69de29..4181ad1 100644 --- a/docs/Bugs.todo +++ b/docs/Bugs.todo @@ -0,0 +1,3 @@ + +High Importance: + ☐ The Map Editor does not get the tile maps when a project is opened @high \ No newline at end of file diff --git a/src/run_modes/editor/editor.cpp b/src/run_modes/editor/editor.cpp index 5cb9474..ae08b42 100644 --- a/src/run_modes/editor/editor.cpp +++ b/src/run_modes/editor/editor.cpp @@ -69,6 +69,8 @@ namespace editor void Editor::Shutdown() { + + DataManager::Shutdown(); mPanelManager.Shutdown(); } @@ -218,10 +220,10 @@ namespace editor Logger::Log(LogCat, LogLevel::INFO, "Opening project: %s", mpPath->string().c_str()); // Open project at mpPath - OpRes result = mProject.LoadProject(*mpPath); - if (Failed(result)) + if (Failed(mProject.LoadProject(*mpPath).LogIfFailed(Editor::LogCat))) { - Logger::Log(LogCat, LogLevel::ERROR, "Could not open project: %s -- reason: %s", mpPath->string().c_str(), result.Description); + mDoOpenProject = false; + return; } ((AssetBrowser*)mPanelManager.GetPanel(PanelType::PT_ASSET_BROWSER))->SetAssetDirectory(mpPath->parent_path() / std::filesystem::path("contents/assets")); mDoOpenProject = false; @@ -243,7 +245,7 @@ namespace editor } else { - //mProject.SaveProject(); + mProject.SaveProject(); mDoSaveProject = false; } } diff --git a/src/run_modes/editor/project/contents/content_manager.cpp b/src/run_modes/editor/project/contents/content_manager.cpp index f2a8572..76542f2 100644 --- a/src/run_modes/editor/project/contents/content_manager.cpp +++ b/src/run_modes/editor/project/contents/content_manager.cpp @@ -96,15 +96,15 @@ namespace lunarium { namespace editor mNextID = ID.attribute("ID").as_ullong(); - pugi::xml_node content = proj_node.child("Content"); + pugi::xml_node contents = proj_node.child("Contents"); - if (!content) + if (!contents) { - return OpRes::Fail("content_meta.xml missing Content node"); + return OpRes::Fail("content_meta.xml missing Contents node"); } // Iterate through content - for (pugi::xml_node asset = content.child("Asset"); asset; asset = asset.next_sibling("Asset")) + for (pugi::xml_node asset = contents.child("Asset"); asset; asset = asset.next_sibling("Asset")) { if (!IsValidAsset(asset)) { @@ -134,7 +134,7 @@ namespace lunarium { namespace editor } // Store asset - if (mAssets.find(pAsset->mID) == mAssets.end()) + if (mAssets.find(pAsset->mID) != mAssets.end()) { return OpRes::Fail("Asset ID collision, ID: %llu, File: %s", pAsset->GetID(), pAsset->GetFileLocation().filename().string().c_str()); @@ -283,9 +283,9 @@ namespace lunarium { namespace editor bool ContentManager::IsValidAsset(pugi::xml_node& node) { - if (!node.child("ID")) { return false; } - if (!node.child("Type")) { return false; } - if (!node.child("Location")) { return false; } + if (!node.attribute("ID")) { return false; } + if (!node.attribute("Type")) { return false; } + if (!node.attribute("Location")) { return false; } return true; } diff --git a/src/run_modes/editor/project/project.cpp b/src/run_modes/editor/project/project.cpp index d412c58..0303333 100644 --- a/src/run_modes/editor/project/project.cpp +++ b/src/run_modes/editor/project/project.cpp @@ -75,6 +75,11 @@ namespace lunarium { namespace editor mLocation = location.parent_path(); mName = location.filename().string(); + if (Failed(ContentManager::GetInstance().Load(this).LogIfFailed(Editor::LogCat))) + { + return OpRes::Fail("Could not load project: %s", location.string().c_str()); + } + mIsLoaded = true; return OpRes::OK(); } @@ -88,8 +93,7 @@ namespace lunarium { namespace editor void Project::SaveProject() { - // HACK LOGGING lol - OpRes::Fail("Project::SaveProject not implemented yet").LogIfFailed(0); + ContentManager::GetInstance().Save().LogIfFailed(Editor::LogCat); } const std::string& Project::GetName() const