aboutsummaryrefslogtreecommitdiff
path: root/app/source/Cplt/Model/Assets.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'app/source/Cplt/Model/Assets.cpp')
-rw-r--r--app/source/Cplt/Model/Assets.cpp81
1 files changed, 27 insertions, 54 deletions
diff --git a/app/source/Cplt/Model/Assets.cpp b/app/source/Cplt/Model/Assets.cpp
index 0dfe847..42eacf3 100644
--- a/app/source/Cplt/Model/Assets.cpp
+++ b/app/source/Cplt/Model/Assets.cpp
@@ -17,27 +17,23 @@ using namespace std::literals::string_view_literals;
namespace fs = std::filesystem;
template <class TSavedAsset, class TStream>
-void OperateStreamForSavedAsset(TSavedAsset& cell, TStream& proxy)
-{
+void OperateStreamForSavedAsset(TSavedAsset& cell, TStream& proxy) {
proxy.template ObjectAdapted<DataStreamAdapters::String>(cell.Name);
proxy.template ObjectAdapted<DataStreamAdapters::Uuid>(cell.Uuid);
proxy.Value(cell.Payload);
}
-void SavedAsset::ReadFromDataStream(InputDataStream& stream)
-{
+void SavedAsset::ReadFromDataStream(InputDataStream& stream) {
::OperateStreamForSavedAsset(*this, stream);
}
-void SavedAsset::WriteToDataStream(OutputDataStream& stream) const
-{
+void SavedAsset::WriteToDataStream(OutputDataStream& stream) const {
::OperateStreamForSavedAsset(*this, stream);
}
Asset::Asset() = default;
-class AssetList::Private
-{
+class AssetList::Private {
public:
Project* ConnectedProject;
tsl::array_map<char, SavedAsset> Assets;
@@ -49,8 +45,7 @@ public:
std::string NewName;
NameSelectionError NewNameError = NameSelectionError::Empty;
- void ShowErrors() const
- {
+ void ShowErrors() const {
switch (NewNameError) {
case NameSelectionError::None: break;
case NameSelectionError::Duplicated:
@@ -62,13 +57,11 @@ public:
}
}
- bool HasErrors() const
- {
+ bool HasErrors() const {
return NewNameError != NameSelectionError::None;
}
- void Validate(const AssetList& self)
- {
+ void Validate(const AssetList& self) {
if (NewName.empty()) {
NewNameError = NameSelectionError::Empty;
return;
@@ -85,23 +78,19 @@ public:
};
AssetList::AssetList(Project& project)
- : mPrivate{ std::make_unique<Private>() }
-{
+ : mPrivate{ std::make_unique<Private>() } {
mPrivate->ConnectedProject = &project;
}
// Write an empty destructor here so std::unique_ptr's destructor can see AssetList::Private's implementation
-AssetList::~AssetList()
-{
+AssetList::~AssetList() {
}
-Project& AssetList::GetConnectedProject() const
-{
+Project& AssetList::GetConnectedProject() const {
return *mPrivate->ConnectedProject;
}
-void AssetList::Reload()
-{
+void AssetList::Reload() {
// TODO fix asset dicovery loading
mPrivate->Assets.clear();
mPrivate->Cache.clear();
@@ -110,18 +99,15 @@ void AssetList::Reload()
});
}
-int AssetList::GetCount() const
-{
+int AssetList::GetCount() const {
return mPrivate->Assets.size();
}
-const tsl::array_map<char, SavedAsset>& AssetList::GetAssets() const
-{
+const tsl::array_map<char, SavedAsset>& AssetList::GetAssets() const {
return mPrivate->Assets;
}
-const SavedAsset* AssetList::FindByName(std::string_view name) const
-{
+const SavedAsset* AssetList::FindByName(std::string_view name) const {
auto iter = mPrivate->Assets.find(name);
if (iter != mPrivate->Assets.end()) {
return &iter.value();
@@ -130,8 +116,7 @@ const SavedAsset* AssetList::FindByName(std::string_view name) const
}
}
-const SavedAsset& AssetList::Create(SavedAsset asset)
-{
+const SavedAsset& AssetList::Create(SavedAsset asset) {
auto [iter, DISCARD] = mPrivate->Assets.insert(asset.Name, SavedAsset{});
auto& savedAsset = iter.value();
@@ -145,15 +130,13 @@ const SavedAsset& AssetList::Create(SavedAsset asset)
return savedAsset;
}
-std::unique_ptr<Asset> AssetList::CreateAndLoad(SavedAsset assetIn)
-{
+std::unique_ptr<Asset> AssetList::CreateAndLoad(SavedAsset assetIn) {
auto& savedAsset = Create(std::move(assetIn));
auto asset = std::unique_ptr<Asset>(CreateInstance(savedAsset));
return asset;
}
-std::unique_ptr<Asset> AssetList::Load(std::string_view name) const
-{
+std::unique_ptr<Asset> AssetList::Load(std::string_view name) const {
if (auto savedAsset = FindByName(name)) {
auto asset = Load(*savedAsset);
return asset;
@@ -162,13 +145,11 @@ std::unique_ptr<Asset> AssetList::Load(std::string_view name) const
}
}
-std::unique_ptr<Asset> AssetList::Load(const SavedAsset& asset) const
-{
+std::unique_ptr<Asset> AssetList::Load(const SavedAsset& asset) const {
return std::unique_ptr<Asset>(LoadInstance(asset));
}
-const SavedAsset* AssetList::Rename(std::string_view oldName, std::string_view newName)
-{
+const SavedAsset* AssetList::Rename(std::string_view oldName, std::string_view newName) {
auto iter = mPrivate->Assets.find(oldName);
if (iter == mPrivate->Assets.end()) return nullptr;
@@ -183,8 +164,7 @@ const SavedAsset* AssetList::Rename(std::string_view oldName, std::string_view n
return &newIter.value();
}
-bool AssetList::Remove(std::string_view name)
-{
+bool AssetList::Remove(std::string_view name) {
auto iter = mPrivate->Assets.find(name);
if (iter == mPrivate->Assets.end()) {
return false;
@@ -197,29 +177,24 @@ bool AssetList::Remove(std::string_view name)
return true;
}
-int AssetList::GetCacheSizeLimit() const
-{
+int AssetList::GetCacheSizeLimit() const {
return mPrivate->CacheSizeLimit;
}
-void AssetList::SetCacheSizeLimit(int limit)
-{
+void AssetList::SetCacheSizeLimit(int limit) {
mPrivate->CacheSizeLimit = limit;
}
-void AssetList::DisplayIconsList(ListState& state)
-{
+void AssetList::DisplayIconsList(ListState& state) {
// TODO
}
-void AssetList::DisplayDetailsList(ListState& state)
-{
+void AssetList::DisplayDetailsList(ListState& state) {
// Note: stub function remained here in case any state processing needs to be done before issuing to implementers
DisplayDetailsTable(state);
}
-void AssetList::DisplayControls(ListState& state)
-{
+void AssetList::DisplayControls(ListState& state) {
auto& ps = mPrivate->PopupPrivateState;
bool openedDummy = true;
@@ -280,8 +255,7 @@ void AssetList::DisplayControls(ListState& state)
}
}
-void AssetList::DiscoverFilesByExtension(const std::function<void(SavedAsset)>& callback, const fs::path& containerDir, std::string_view extension) const
-{
+void AssetList::DiscoverFilesByExtension(const std::function<void(SavedAsset)>& callback, const fs::path& containerDir, std::string_view extension) const {
for (auto entry : fs::directory_iterator(containerDir)) {
if (!entry.is_regular_file()) continue;
@@ -300,7 +274,6 @@ void AssetList::DiscoverFilesByExtension(const std::function<void(SavedAsset)>&
}
}
-void AssetList::DiscoverFilesByHeader(const std::function<void(SavedAsset)>& callback, const fs::path& containerDir, const std::function<bool(std::istream&)>& validater) const
-{
+void AssetList::DiscoverFilesByHeader(const std::function<void(SavedAsset)>& callback, const fs::path& containerDir, const std::function<bool(std::istream&)>& validater) const {
// TODO
}