#include "Assets.hpp" #include #include #include namespace fs = std::filesystem; Asset::Asset() { } std::unique_ptr AssetCategory::CreateEmptyUnique(const SavedAsset& diskForm) const { return std::unique_ptr(CreateEmpty(diskForm)); } std::unique_ptr AssetCategory::LoadUnique(const SavedAsset& diskForm) const { return std::unique_ptr(Load(diskForm)); } void AssetCategory::DiscoverFilesByExtension(const std::function& callback, const std::filesystem::path& containerDir, std::string_view extension) { for (auto entry : fs::directory_iterator(containerDir)) { if (!entry.is_regular_file()) continue; // If the caller provided an extension to match against, and it doesn't equal to current file extension, skip if (!extension.empty() && entry.path().extension() != extension) { continue; } callback(SavedAsset{ .Path = entry.path(), .Name = entry.path().stem().string(), }); } } void AssetCategory::DiscoverFilesByHeader(const std::function& callback, const std::filesystem::__cxx11::path& containerDir, const std::function& validater) { // TODO } AssetList::AssetList(const AssetCategory& loader) : mLoader{ &loader } { } void AssetList::Reload() { mLoader->DiscoverFiles([this](SavedAsset asset) -> void { Create(std::move(asset)); }); } const SavedAsset* AssetList::FindByName(std::string_view name) const { auto iter = mAssets.find(name); if (iter != mAssets.end()) { return &iter.value(); } else { return nullptr; } } const SavedAsset& AssetList::Create(SavedAsset asset) { auto [iter, DISCARD] = mAssets.insert(asset.Name, SavedAsset{}); auto& savedAsset = iter.value(); mLoader->CreateEmpty(asset); savedAsset = std::move(asset); return savedAsset; } std::unique_ptr AssetList::CreateAndLoad(SavedAsset assetIn) { auto& savedAsset = Create(std::move(assetIn)); auto asset = std::unique_ptr(mLoader->CreateEmpty(savedAsset)); return asset; } std::unique_ptr AssetList::LoadFromDisk(std::string_view name) const { if (auto savedAsset = FindByName(name)) { auto asset = mLoader->LoadUnique(*savedAsset); return asset; } } bool AssetList::Rename(std::string_view oldName, std::string_view newName) { } bool AssetList::Remove(std::string_view name) { } int AssetList::GetCacheSizeLimit() const { return mCacheSizeLimit; } void AssetList::SetCacheSizeLimit(int limit) { mCacheSizeLimit = limit; } void AssetList::DrawBigIcons(DrawState& state) { // TODO } void AssetList::DrawDetails(DrawState& state) { mLoader->SetupDetailsTable("AssetDetailsTable"); for (auto& asset : mAssets) { mLoader->DrawDetailsTableRow(asset); ImGui::TableNextRow(); } ImGui::EndTable(); }