imgration 14/12/2025
This commit is contained in:
77
include/project_parser.hpp
Normal file
77
include/project_parser.hpp
Normal file
@@ -0,0 +1,77 @@
|
||||
#pragma once
|
||||
|
||||
#include "project_parser.h"
|
||||
|
||||
|
||||
|
||||
template <typename AssetTypes = TypeCollection<>>
|
||||
auto FindAssetFiles(std::string_view project_root)
|
||||
{
|
||||
using AssetsContainer = typename AssetTypes::template AsContainedType<unordered_map_guid>;
|
||||
AssetsContainer Assets{};
|
||||
|
||||
for (const auto& entry : std::filesystem::recursive_directory_iterator(project_root))
|
||||
{
|
||||
if (entry.is_directory()) continue;
|
||||
|
||||
std::string extension = entry.path().extension().string();
|
||||
|
||||
if (extension == std::string_view(".meta")) continue;
|
||||
|
||||
AssetTypes::ForEachT([&Assets, &extension, &entry]<typename AssetT>()
|
||||
{
|
||||
constexpr auto assetExtensions = AssetT::Extensions;
|
||||
|
||||
for (auto assetExtension : assetExtensions)
|
||||
{
|
||||
if (extension == assetExtension)
|
||||
{
|
||||
static_assert(std::is_base_of_v<AssetBase, AssetT>, "Asset Type must derive from AssetBase");
|
||||
|
||||
AssetT asset{};
|
||||
asset.Path = entry.path();
|
||||
asset.GUID = GetAssetGUIDFromFile(entry.path().string() + ".meta");
|
||||
std::get<std::unordered_map<AssetGUID, AssetT>>(Assets).emplace(asset.GUID, std::move(asset));
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return Assets;
|
||||
}
|
||||
|
||||
template <typename AssetTypes = TypeCollection<>, typename ProjectType>
|
||||
void InitializeAssetFiles(ProjectType& project)
|
||||
{
|
||||
AssetTypes::ForEachT([&project]<typename AssetT>()
|
||||
{
|
||||
std::string buffer{};
|
||||
|
||||
auto& assetMap = std::get<std::unordered_map<AssetGUID, AssetT>>(project.Assets);
|
||||
for (auto& [guid, asset] : assetMap)
|
||||
{
|
||||
buffer.clear();
|
||||
std::ifstream file(asset.Path);
|
||||
buffer.assign(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>());
|
||||
|
||||
asset.Parse(project, buffer);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
template <
|
||||
typename AssetTypes = TypeCollection<>,
|
||||
typename UnityTypes = TypeCollection<>,
|
||||
typename MonobehaviourTypes = TypeCollection<>
|
||||
>
|
||||
ParsedProject<UnityTypes, MonobehaviourTypes, AssetTypes> ParseProject(const std::filesystem::path& projectRoot)
|
||||
{
|
||||
auto project = ParsedProject<UnityTypes, MonobehaviourTypes, AssetTypes>{projectRoot};
|
||||
|
||||
project.Assets = FindAssetFiles<AssetTypes>(projectRoot.generic_string());
|
||||
|
||||
InitializeAssetFiles<AssetTypes>(project);
|
||||
|
||||
return project;
|
||||
}
|
||||
Reference in New Issue
Block a user