adds trash folder and functionality to the project, content_manager and EditorAsset classes to use the trash folder. When assets get removed they are moved to trash instead of deleted.

master
Joey Pollack 4 years ago
parent 2f27fcf8bc
commit 4a84ca0bcd

@ -7,6 +7,7 @@ Editor:
✔ Implement Run Mode interface class @high @done (2/8/2022, 4:05:17 PM) ✔ Implement Run Mode interface class @high @done (2/8/2022, 4:05:17 PM)
✔ Reference raw asset files in a "content" folder@high @done (3/3/2022, 3:15:32 PM) ✔ Reference raw asset files in a "content" folder@high @done (3/3/2022, 3:15:32 PM)
✔ Platform independant file browsing @done (2/8/2022, 4:05:29 PM) ✔ Platform independant file browsing @done (2/8/2022, 4:05:29 PM)
☐ Test the Asset Trashing system @high
☐ Scan script files to make sure they don't overwrite globals ☐ Scan script files to make sure they don't overwrite globals
☐ Figure out how to make game asset types integrate with editor asset types @critical ☐ Figure out how to make game asset types integrate with editor asset types @critical

@ -105,6 +105,13 @@ namespace lunarium { namespace editor
return OpRes::Fail("Invalid asset node in content_meta.json"); return OpRes::Fail("Invalid asset node in content_meta.json");
} }
// Check if asset is trashed
if (asset["Trashed"].get<bool>())
{
// Skip trashed assets
continue;
}
// Load Type // Load Type
AssetType type = (AssetType)asset["Type"].get<int>(); AssetType type = (AssetType)asset["Type"].get<int>();
EditorAsset* pAsset = CreateAsset(type); EditorAsset* pAsset = CreateAsset(type);
@ -115,6 +122,9 @@ namespace lunarium { namespace editor
} }
pAsset->mAssetDir = mpProject->GetAssetDirectory(); pAsset->mAssetDir = mpProject->GetAssetDirectory();
// If we got to this point the asset must not be trashed
pAsset->mIsTrashed = false;
// Load ID // Load ID
pAsset->mID = asset["ID"].get<u64>(); pAsset->mID = asset["ID"].get<u64>();
@ -168,6 +178,7 @@ namespace lunarium { namespace editor
asset["Type"] = (i32)pAsset->GetType(); asset["Type"] = (i32)pAsset->GetType();
asset["ID"] = pAsset->GetID(); asset["ID"] = pAsset->GetID();
asset["Trashed"] = pAsset->GetIsTrashed();
// TODO: This needs to be a relative path! (Relative to the project root) // TODO: This needs to be a relative path! (Relative to the project root)
asset["Location"] = pAsset->GetFileLocation().string().c_str(); asset["Location"] = pAsset->GetFileLocation().string().c_str();
@ -305,6 +316,10 @@ namespace lunarium { namespace editor
return; return;
} }
// Move the asset to a trash directory to prevent data loss
iter->second->mIsTrashed = true;
MoveAsset(iter->second, mpProject->GetTrashDirectory());
delete iter->second; delete iter->second;
mAssets.erase(iter); mAssets.erase(iter);
Save().LogIfFailed(Editor::LogCat, "Asset was removed"); Save().LogIfFailed(Editor::LogCat, "Asset was removed");

@ -11,12 +11,11 @@
namespace lunarium { namespace editor { namespace lunarium { namespace editor {
EditorAsset::EditorAsset(AssetType type) EditorAsset::EditorAsset(AssetType type)
: mType(type) : mType(type), mIsTrashed(false)
{ {
} }
AssetType EditorAsset::GetType() AssetType EditorAsset::GetType()
{ {
return mType; return mType;
@ -32,4 +31,9 @@ namespace lunarium { namespace editor {
return mLocation; return mLocation;
} }
bool EditorAsset::GetIsTrashed() const
{
return mIsTrashed;
}
}} }}

@ -26,6 +26,7 @@ namespace lunarium { namespace editor
AssetType GetType(); AssetType GetType();
uint64_t GetID(); uint64_t GetID();
std::filesystem::path GetFileLocation(); std::filesystem::path GetFileLocation();
bool GetIsTrashed() const;
[[nodiscard]] virtual OpRes LoadRawFile() = 0; [[nodiscard]] virtual OpRes LoadRawFile() = 0;
[[nodiscard]] virtual OpRes LoadFromJSON(nlohmann::json& node) = 0; [[nodiscard]] virtual OpRes LoadFromJSON(nlohmann::json& node) = 0;
@ -37,6 +38,7 @@ namespace lunarium { namespace editor
AssetType mType; AssetType mType;
uint64_t mID; uint64_t mID;
std::filesystem::path mLocation; std::filesystem::path mLocation;
bool mIsTrashed;
void SetLocation(std::filesystem::path path) { mLocation = path; } void SetLocation(std::filesystem::path path) { mLocation = path; }

@ -24,7 +24,7 @@ namespace editor
{ {
AssetBrowser::AssetBrowser(std::filesystem::path dir, Editor* pEditor) AssetBrowser::AssetBrowser(std::filesystem::path dir, Editor* pEditor)
: Panel("Asset Browser", PanelDockZone::DDZ_BOTTOM, true, (ImGuiWindowFlags)ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar), : Panel("Asset Browser", PanelDockZone::DDZ_BOTTOM, true, (ImGuiWindowFlags)ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar),
mAssetDirectory(dir), mpEditor(pEditor), mNewFolder(false), mSyncTree(false) mAssetDirectory(dir), mpEditor(pEditor), mSyncTree(false)
{ {
DefinePopups(); DefinePopups();
} }
@ -184,6 +184,8 @@ namespace editor
} }
} }
// List Assets
std::filesystem::path selected_final = mpEditor->GetProject()->MakeRelativeToAssets(mSelectedDir); std::filesystem::path selected_final = mpEditor->GetProject()->MakeRelativeToAssets(mSelectedDir);
std::vector<EditorAsset *> assets; std::vector<EditorAsset *> assets;
ContentManager::GetInstance().GetAllAssetsInDirectory(assets, selected_final); ContentManager::GetInstance().GetAllAssetsInDirectory(assets, selected_final);
@ -244,10 +246,6 @@ namespace editor
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("EditorAsset")) if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("EditorAsset"))
{ {
EditorAsset* pAsset = *((EditorAsset**) payload->Data); EditorAsset* pAsset = *((EditorAsset**) payload->Data);
// EditorAsset* pAsset = ((EditorAsset*) payload->Data);
// Logger::Info(Editor::LogCat, "Dropping asset: %s - To: %s",
// pAsset->GetFileLocation().stem().string().c_str(), dir.string().c_str());
ContentManager::GetInstance().MoveAsset(pAsset, dir / pAsset->GetFileLocation().filename()); ContentManager::GetInstance().MoveAsset(pAsset, dir / pAsset->GetFileLocation().filename());
} }
ImGui::EndDragDropTarget(); ImGui::EndDragDropTarget();

@ -33,7 +33,6 @@ namespace editor
std::filesystem::path mAssetDirectory; std::filesystem::path mAssetDirectory;
std::filesystem::path mSelectedDir; std::filesystem::path mSelectedDir;
Editor* mpEditor; Editor* mpEditor;
bool mNewFolder;
bool mSyncTree; bool mSyncTree;
private: private:

@ -61,6 +61,7 @@ namespace lunarium { namespace editor
std::filesystem::create_directory(mLocation / std::filesystem::path("engine")); std::filesystem::create_directory(mLocation / std::filesystem::path("engine"));
std::filesystem::create_directory(mLocation / std::filesystem::path("contents")); std::filesystem::create_directory(mLocation / std::filesystem::path("contents"));
std::filesystem::create_directory(mLocation / std::filesystem::path("contents/assets")); std::filesystem::create_directory(mLocation / std::filesystem::path("contents/assets"));
std::filesystem::create_directory(mLocation / std::filesystem::path("contents/trash"));
mpContentManager = &ContentManager::GetInstance(); mpContentManager = &ContentManager::GetInstance();
if (Failed(mpContentManager->Load(this).LogIfFailed(Editor::LogCat))) if (Failed(mpContentManager->Load(this).LogIfFailed(Editor::LogCat)))
@ -129,6 +130,12 @@ namespace lunarium { namespace editor
return GetContentDirectory() / "assets"; return GetContentDirectory() / "assets";
} }
std::filesystem::path Project::GetTrashDirectory() const
{
return GetContentDirectory() / "trash";
}
std::filesystem::path Project::MakeRelativeToRoot(std::filesystem::path abs_path, bool include_root) const std::filesystem::path Project::MakeRelativeToRoot(std::filesystem::path abs_path, bool include_root) const
{ {
return MakeRelativeTo(abs_path, mLocation, include_root); return MakeRelativeTo(abs_path, mLocation, include_root);

@ -38,6 +38,7 @@ namespace lunarium { namespace editor
std::filesystem::path GetRootDirectory() const; std::filesystem::path GetRootDirectory() const;
std::filesystem::path GetContentDirectory() const; std::filesystem::path GetContentDirectory() const;
std::filesystem::path GetAssetDirectory() const; std::filesystem::path GetAssetDirectory() const;
std::filesystem::path GetTrashDirectory() const;
// Convert an absolute path to a path relative to the project root // Convert an absolute path to a path relative to the project root
std::filesystem::path MakeRelativeToRoot(std::filesystem::path, bool include_root = false) const; std::filesystem::path MakeRelativeToRoot(std::filesystem::path, bool include_root = false) const;

@ -1,24 +0,0 @@
<?xml version="1.0"?>
<Project Name="test2.lproj">
<NextID ID="1" />
<Contents>
<Asset Type="1" ID="0" Location="D:\Projects\lunarium\build\Debug\test2\contents\assets\LinkToThePast1_sized.png" TileSizeWidth="16" TileSizeHeight="16" NumTilesCol="64" NumTilesRow="64" />
</Contents>
</Project>
{
"Project" : {
"Name" = "test2.lproj",
"NextID" = 1,
"Contents" : [
{
"Type" = 1,
"ID" = 0,
"Location" = "D:\Projects\lunarium\build\Debug\test2\contents\assets\LinkToThePast1_sized.png",
"TileSizeWidth" = 16,
"TileSizeHeight" = 16,
"NumTilesCol" = 64,
"NumTilesRow" = 64
},
]
}
}

@ -1,6 +0,0 @@
{
"Project" : {
"Name" : "test2"
}
}
Loading…
Cancel
Save