mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-02-14 19:33:02 +00:00
feat: add post processors compiling iwds and ipaks
This commit is contained in:
17
src/ObjCompiling/Image/IPak/IPakCreator.cpp
Normal file
17
src/ObjCompiling/Image/IPak/IPakCreator.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "IPakCreator.h"
|
||||
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
void IPakCreator::AddImage(std::string imageName)
|
||||
{
|
||||
m_image_names.emplace_back(std::move(imageName));
|
||||
}
|
||||
|
||||
void IPakCreator::Finalize(ISearchPath& searchPath, const std::filesystem::path& outPath)
|
||||
{
|
||||
std::cout << std::format("Creating ipak with {} entries:\n", m_image_names.size());
|
||||
|
||||
for (const auto& imageName : m_image_names)
|
||||
std::cout << std::format(" {}\n", imageName);
|
||||
}
|
||||
16
src/ObjCompiling/Image/IPak/IPakCreator.h
Normal file
16
src/ObjCompiling/Image/IPak/IPakCreator.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IZoneAssetLoaderState.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
class IPakCreator : public IZoneAssetLoaderState
|
||||
{
|
||||
public:
|
||||
void AddImage(std::string imageName);
|
||||
void Finalize(ISearchPath& searchPath, const std::filesystem::path& outPath);
|
||||
|
||||
private:
|
||||
std::vector<std::string> m_image_names;
|
||||
};
|
||||
25
src/ObjCompiling/Image/ImageIPakPostProcessor.cpp
Normal file
25
src/ObjCompiling/Image/ImageIPakPostProcessor.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "ImageIPakPostProcessor.h"
|
||||
|
||||
#include "IPak/IPakCreator.h"
|
||||
|
||||
#include <format>
|
||||
|
||||
AbstractImageIPakPostProcessor::AbstractImageIPakPostProcessor(ISearchPath& searchPath, const std::filesystem::path& outDir)
|
||||
: m_search_path(searchPath),
|
||||
m_out_dir(outDir)
|
||||
{
|
||||
}
|
||||
|
||||
void AbstractImageIPakPostProcessor::PostProcessAsset(XAssetInfoGeneric& assetInfo, AssetCreationContext& context)
|
||||
{
|
||||
if (assetInfo.m_name.empty() || assetInfo.m_name[0] == ',')
|
||||
return;
|
||||
|
||||
auto* ipakCreator = context.GetZoneAssetLoaderState<IPakCreator>();
|
||||
ipakCreator->AddImage(assetInfo.m_name);
|
||||
}
|
||||
|
||||
void AbstractImageIPakPostProcessor::FinalizeZone(AssetCreationContext& context)
|
||||
{
|
||||
context.GetZoneAssetLoaderState<IPakCreator>()->Finalize(m_search_path, m_out_dir);
|
||||
}
|
||||
34
src/ObjCompiling/Image/ImageIPakPostProcessor.h
Normal file
34
src/ObjCompiling/Image/ImageIPakPostProcessor.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IAssetPostProcessor.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
class AbstractImageIPakPostProcessor : public IAssetPostProcessor
|
||||
{
|
||||
public:
|
||||
AbstractImageIPakPostProcessor(ISearchPath& searchPath, const std::filesystem::path& outDir);
|
||||
|
||||
void PostProcessAsset(XAssetInfoGeneric& assetInfo, AssetCreationContext& context) override;
|
||||
void FinalizeZone(AssetCreationContext& context) override;
|
||||
|
||||
private:
|
||||
ISearchPath& m_search_path;
|
||||
const std::filesystem::path& m_out_dir;
|
||||
};
|
||||
|
||||
template<typename AssetType> class ImageIPakPostProcessor final : public AbstractImageIPakPostProcessor
|
||||
{
|
||||
public:
|
||||
static_assert(std::is_base_of_v<IAssetBase, AssetType>);
|
||||
|
||||
ImageIPakPostProcessor(ISearchPath& searchPath, const std::filesystem::path& outDir)
|
||||
: AbstractImageIPakPostProcessor(searchPath, outDir)
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] asset_type_t GetHandlingAssetType() const override
|
||||
{
|
||||
return AssetType::EnumEntry;
|
||||
};
|
||||
};
|
||||
25
src/ObjCompiling/Image/ImageIwdPostProcessor.cpp
Normal file
25
src/ObjCompiling/Image/ImageIwdPostProcessor.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "ImageIwdPostProcessor.h"
|
||||
|
||||
#include "Iwd/IwdCreator.h"
|
||||
|
||||
#include <format>
|
||||
|
||||
AbstractImageIwdPostProcessor::AbstractImageIwdPostProcessor(ISearchPath& searchPath, const std::filesystem::path& outDir)
|
||||
: m_search_path(searchPath),
|
||||
m_out_dir(outDir)
|
||||
{
|
||||
}
|
||||
|
||||
void AbstractImageIwdPostProcessor::PostProcessAsset(XAssetInfoGeneric& assetInfo, AssetCreationContext& context)
|
||||
{
|
||||
if (assetInfo.m_name.empty() || assetInfo.m_name[0] == ',')
|
||||
return;
|
||||
|
||||
auto* iwdCreator = context.GetZoneAssetLoaderState<IwdCreator>();
|
||||
iwdCreator->AddFile(std::format("images/{}.iwi", assetInfo.m_name));
|
||||
}
|
||||
|
||||
void AbstractImageIwdPostProcessor::FinalizeZone(AssetCreationContext& context)
|
||||
{
|
||||
context.GetZoneAssetLoaderState<IwdCreator>()->Finalize(m_search_path, m_out_dir);
|
||||
}
|
||||
34
src/ObjCompiling/Image/ImageIwdPostProcessor.h
Normal file
34
src/ObjCompiling/Image/ImageIwdPostProcessor.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IAssetPostProcessor.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
class AbstractImageIwdPostProcessor : public IAssetPostProcessor
|
||||
{
|
||||
public:
|
||||
AbstractImageIwdPostProcessor(ISearchPath& searchPath, const std::filesystem::path& outDir);
|
||||
|
||||
void PostProcessAsset(XAssetInfoGeneric& assetInfo, AssetCreationContext& context) override;
|
||||
void FinalizeZone(AssetCreationContext& context) override;
|
||||
|
||||
private:
|
||||
ISearchPath& m_search_path;
|
||||
const std::filesystem::path& m_out_dir;
|
||||
};
|
||||
|
||||
template<typename AssetType> class ImageIwdPostProcessor final : public AbstractImageIwdPostProcessor
|
||||
{
|
||||
public:
|
||||
static_assert(std::is_base_of_v<IAssetBase, AssetType>);
|
||||
|
||||
ImageIwdPostProcessor(ISearchPath& searchPath, const std::filesystem::path& outDir)
|
||||
: AbstractImageIwdPostProcessor(searchPath, outDir)
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] asset_type_t GetHandlingAssetType() const override
|
||||
{
|
||||
return AssetType::EnumEntry;
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user