Skip to content

Commit

Permalink
feat: automatically add ipak_read kvp when creating ipak
Browse files Browse the repository at this point in the history
  • Loading branch information
Laupetin committed Jan 3, 2025
1 parent 4f6c9ff commit a7fbe02
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/ObjCompiling/Image/IPak/IPakCreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "Utils/Alignment.h"

#include <algorithm>
#include <cassert>
#include <format>
#include <fstream>
#include <iostream>
Expand Down Expand Up @@ -394,6 +395,16 @@ void IPakToCreate::Build(ISearchPath& searchPath, const std::filesystem::path& o
std::cout << std::format("Created ipak {} with {} entries\n", m_name, m_image_names.size());
}

IPakCreator::IPakCreator()
: m_kvp_creator(nullptr)
{
}

void IPakCreator::Inject(ZoneAssetCreationInjection& inject)
{
m_kvp_creator = &inject.m_zone_states.GetZoneAssetCreationState<KeyValuePairsCreator>();
}

IPakToCreate* IPakCreator::GetOrAddIPak(const std::string& ipakName)
{
const auto existingIPak = m_ipak_lookup.find(ipakName);
Expand All @@ -404,6 +415,9 @@ IPakToCreate* IPakCreator::GetOrAddIPak(const std::string& ipakName)
auto* result = newIPak.get();
m_ipaks.emplace_back(std::move(newIPak));

assert(m_kvp_creator);
m_kvp_creator->AddKeyValuePair(CommonKeyValuePair("ipak_read", ipakName));

return result;
}

Expand Down
6 changes: 6 additions & 0 deletions src/ObjCompiling/Image/IPak/IPakCreator.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "Asset/IZoneAssetCreationState.h"
#include "KeyValuePairs/KeyValuePairsCreator.h"
#include "SearchPath/ISearchPath.h"

#include <filesystem>
Expand All @@ -24,10 +25,15 @@ class IPakToCreate
class IPakCreator : public IZoneAssetCreationState
{
public:
IPakCreator();

void Inject(ZoneAssetCreationInjection& inject) override;

IPakToCreate* GetOrAddIPak(const std::string& ipakName);
void Finalize(ISearchPath& searchPath, const std::filesystem::path& outPath);

private:
KeyValuePairsCreator* m_kvp_creator;
std::unordered_map<std::string, IPakToCreate*> m_ipak_lookup;
std::vector<std::unique_ptr<IPakToCreate>> m_ipaks;
};

0 comments on commit a7fbe02

Please sign in to comment.