#include "Template.hpp" #include #include #include #include #include #include #include #include #include #include #include using namespace std::literals::string_view_literals; namespace fs = std::filesystem; Template::Template(Kind kind) : mKind{ kind } { } Template::Kind Template::GetKind() const { return mKind; } void TemplateAssetList::DiscoverFiles(const std::function& callback) const { auto dir = GetConnectedProject().GetTemplatesDirectory(); DiscoverFilesByExtension(callback, dir, ".cplt-template"sv); } std::string TemplateAssetList::RetrieveNameFromFile(const fs::path& file) const { auto res = DataArchive::LoadFile(file); if (!res) return ""; auto& stream = res.value(); SavedAsset assetInfo; stream.ReadObject(assetInfo); return assetInfo.Name; } uuids::uuid TemplateAssetList::RetrieveUuidFromFile(const fs::path& file) const { return uuids::uuid::from_string(file.stem().string()); } fs::path TemplateAssetList::RetrievePathFromAsset(const SavedAsset& asset) const { auto fileName = uuids::to_string(asset.Uuid); return GetConnectedProject().GetTemplatePath(fileName); } bool TemplateAssetList::SaveInstance(const SavedAsset& assetInfo, const Asset* asset) const { auto path = RetrievePathFromAsset(assetInfo); auto res = DataArchive::SaveFile(path); if (!res) return false; auto& stream = res.value(); stream.WriteObject(assetInfo); // This cast is fine: calls to this class will always be wrapped in TypedAssetList, which will ensure `asset` points to some Template if (auto tmpl = static_cast(asset)) { // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast) stream.WriteObject(*tmpl); } return true; } static std::unique_ptr