aboutsummaryrefslogtreecommitdiff
path: root/core/src/Model/Assets.hpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-06-30 21:38:53 -0700
committerrtk0c <[email protected]>2022-06-30 21:38:53 -0700
commit7fe47a9d5b1727a61dc724523b530762f6d6ba19 (patch)
treee95be6e66db504ed06d00b72c579565bab873277 /core/src/Model/Assets.hpp
parent2cf952088d375ac8b2f45b144462af0953436cff (diff)
Restructure project
Diffstat (limited to 'core/src/Model/Assets.hpp')
-rw-r--r--core/src/Model/Assets.hpp130
1 files changed, 0 insertions, 130 deletions
diff --git a/core/src/Model/Assets.hpp b/core/src/Model/Assets.hpp
deleted file mode 100644
index 3d90d3f..0000000
--- a/core/src/Model/Assets.hpp
+++ /dev/null
@@ -1,130 +0,0 @@
-#pragma once
-
-#include "Utils/UUID.hpp"
-#include "cplt_fwd.hpp"
-
-#include <tsl/array_map.h>
-#include <filesystem>
-#include <iosfwd>
-#include <memory>
-#include <string_view>
-
-/// A structure representing a ready-to-be-loaded asset, locating on the disk.
-/// Each asset should be identified by a unique uuid within the asset category (i.e. a workflow and a template can share the same uuid),
-/// generated on insertion to an asset list if not given by the caller.
-struct SavedAsset
-{
- std::string Name;
- /// UUID of this asset. This field is generated as a random UUID v4 upon insertion into an AssetList, if not already provided by the caller (indicated by !is_nil()).
- uuids::uuid Uuid;
- /// Extra data to be used by the AssetList/Asset implementation.
- uint64_t Payload;
-
- void ReadFromDataStream(InputDataStream& stream);
- void WriteToDataStream(OutputDataStream& stream) const;
-};
-
-class Asset
-{
-public:
- Asset();
- virtual ~Asset() = default;
-};
-
-enum class NameSelectionError
-{
- None,
- Duplicated,
- Empty,
-};
-
-class AssetList
-{
-private:
- class Private;
- std::unique_ptr<Private> mPrivate;
-
-public:
- AssetList(Project& project);
- virtual ~AssetList();
-
- Project& GetConnectedProject() const;
-
- // TODO support file watches
- void Reload();
-
- int GetCount() const;
- // TODO convert to custom iterable
- const tsl::array_map<char, SavedAsset>& GetAssets() const;
-
- const SavedAsset* FindByName(std::string_view name) const;
- const SavedAsset& Create(SavedAsset asset);
- std::unique_ptr<Asset> CreateAndLoad(SavedAsset asset);
- /// Load the asset on disk by its name.
- std::unique_ptr<Asset> Load(std::string_view name) const;
- /// Load the asset on disk by a reference to its SavedAsset instance. This function assumes that the given SavedAsset
- /// is stored in AssetList, otherwise the behavior is undefined.
- std::unique_ptr<Asset> Load(const SavedAsset& asset) const;
- const SavedAsset* Rename(std::string_view oldName, std::string_view newName);
- bool Remove(std::string_view name);
-
- int GetCacheSizeLimit() const;
- void SetCacheSizeLimit(int limit);
-
- struct ListState
- {
- const SavedAsset* SelectedAsset = nullptr;
- };
- void DisplayIconsList(ListState& state);
- void DisplayDetailsList(ListState& state);
- void DisplayControls(ListState& state);
-
-protected:
- virtual void DiscoverFiles(const std::function<void(SavedAsset)>& callback) const = 0;
-
- // Helper
- void DiscoverFilesByExtension(const std::function<void(SavedAsset)>& callback, const std::filesystem::path& containerDir, std::string_view extension) const;
- void DiscoverFilesByHeader(const std::function<void(SavedAsset)>& callback, const std::filesystem::path& containerDir, const std::function<bool(std::istream&)>& validater) const;
-
- /// Create an empty/default instance of this asset type on disk, potentially qualified by SavedAsset::Payload.
- /// Return `true` on success and `false` on failure.
- virtual bool SaveInstance(const SavedAsset& assetInfo, const Asset* asset) const = 0;
- /// The returned pointer indicate ownership to the object.
- virtual Asset* LoadInstance(const SavedAsset& assetInfo) const = 0;
- /// Create an empty/default instance of this asset type, potentially qualified by SavedAsset::Payload.
- /// The returned pointer indicate ownership to the object.
- virtual Asset* CreateInstance(const SavedAsset& assetInfo) const = 0;
- virtual bool RenameInstanceOnDisk(const SavedAsset& assetInfo, std::string_view oldName) const = 0;
-
- virtual std::string RetrieveNameFromFile(const std::filesystem::path& file) const = 0;
- virtual uuids::uuid RetrieveUuidFromFile(const std::filesystem::path& file) const = 0;
- virtual std::filesystem::path RetrievePathFromAsset(const SavedAsset& asset) const = 0;
-
- virtual void DisplayAssetCreator(ListState& state) = 0;
- virtual void DisplayDetailsTable(ListState& state) const = 0;
-};
-
-template <class T>
-class AssetListTyped : public AssetList
-{
-public:
- using AssetList::AssetList;
-
-#pragma clang diagnostic push
-#pragma ide diagnostic ignored "HidingNonVirtualFunction"
- std::unique_ptr<T> CreateAndLoad(SavedAsset asset)
- {
- return std::unique_ptr<T>(static_cast<T*>(AssetList::CreateAndLoad(asset).release()));
- }
-
- std::unique_ptr<T> Load(std::string_view name) const
- {
- return std::unique_ptr<T>(static_cast<T*>(AssetList::Load(name).release()));
- }
-
- std::unique_ptr<T> Load(const SavedAsset& asset) const
- {
- return std::unique_ptr<T>(static_cast<T*>(AssetList::Load(asset).release()));
- }
-#pragma clang diagnostic pop
-};