2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-07-04 02:01:51 +00:00

chore: fix loading and writing code for T6

This commit is contained in:
Jan
2024-12-31 12:38:01 +01:00
parent d8bc156ffd
commit 83d13aa166
193 changed files with 4129 additions and 4208 deletions

View File

@ -0,0 +1,53 @@
#include "GdtLoaderZBarrierT6.h"
#include "Game/T6/ObjConstantsT6.h"
#include "Game/T6/T6.h"
#include "InfoString/InfoString.h"
#include "InfoStringLoaderZBarrierT6.h"
#include <cstring>
#include <format>
#include <iostream>
using namespace T6;
namespace
{
class GdtLoaderZBarrier final : public AssetCreator<AssetZBarrier>
{
public:
GdtLoaderZBarrier(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone)
: m_gdt(gdt),
m_info_string_loader(memory, searchPath, zone)
{
}
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{
const auto* gdtEntry = m_gdt.GetGdtEntryByGdfAndName(ObjConstants::GDF_FILENAME_ZBARRIER, assetName);
if (gdtEntry == nullptr)
return AssetCreationResult::NoAction();
InfoString infoString;
if (!infoString.FromGdtProperties(*gdtEntry))
{
std::cerr << std::format("Failed to read zbarrier gdt entry: \"{}\"\n", assetName);
return AssetCreationResult::Failure();
}
return m_info_string_loader.CreateAsset(assetName, infoString, context);
}
private:
IGdtQueryable& m_gdt;
InfoStringLoaderZBarrier m_info_string_loader;
};
} // namespace
namespace T6
{
std::unique_ptr<AssetCreator<AssetZBarrier>> CreateGdtZBarrierLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone)
{
return std::make_unique<GdtLoaderZBarrier>(memory, searchPath, gdt, zone);
}
} // namespace T6

View File

@ -0,0 +1,14 @@
#pragma once
#include "Asset/IAssetCreator.h"
#include "Game/T6/T6.h"
#include "Gdt/IGdtQueryable.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
#include <memory>
namespace T6
{
std::unique_ptr<AssetCreator<AssetZBarrier>> CreateGdtZBarrierLoader(MemoryManager& memory, ISearchPath& searchPath, IGdtQueryable& gdt, Zone& zone);
} // namespace T6

View File

@ -0,0 +1,83 @@
#include "InfoStringLoaderZBarrierT6.h"
#include "Game/T6/InfoString/InfoStringToStructConverter.h"
#include "Game/T6/T6.h"
#include "Game/T6/ZBarrier/ZBarrierFields.h"
#include <cassert>
#include <cstring>
#include <format>
#include <iostream>
#include <limits>
using namespace T6;
namespace
{
class InfoStringToZBarrierConverter final : public InfoStringToStructConverter
{
protected:
bool ConvertExtensionField(const cspField_t& field, const std::string& value) override
{
assert(false);
return false;
}
public:
InfoStringToZBarrierConverter(const InfoString& infoString,
ZBarrierDef& zbarrier,
ZoneScriptStrings& zoneScriptStrings,
MemoryManager& memory,
AssetCreationContext& context,
AssetRegistration<AssetZBarrier>& registration,
const cspField_t* fields,
const size_t fieldCount)
: InfoStringToStructConverter(infoString, &zbarrier, zoneScriptStrings, memory, context, registration, fields, fieldCount)
{
}
};
void CalculateZBarrierFields(ZBarrierDef& zbarrier)
{
auto foundEnd = false;
for (auto i = 0u; i < std::extent_v<decltype(ZBarrierDef::boards)>; i++)
{
if (zbarrier.boards[i].pBoardModel == nullptr)
{
foundEnd = true;
zbarrier.numBoardsInBarrier = i;
break;
}
}
if (!foundEnd)
zbarrier.numBoardsInBarrier = std::extent_v<decltype(ZBarrierDef::boards)>;
}
} // namespace
InfoStringLoaderZBarrier::InfoStringLoaderZBarrier(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
: m_memory(memory),
m_search_path(searchPath),
m_zone(zone)
{
}
AssetCreationResult InfoStringLoaderZBarrier::CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context)
{
auto* zbarrier = m_memory.Alloc<ZBarrierDef>();
zbarrier->name = m_memory.Dup(assetName.c_str());
AssetRegistration<AssetZBarrier> registration(assetName, zbarrier);
InfoStringToZBarrierConverter converter(
infoString, *zbarrier, m_zone.m_script_strings, m_memory, context, registration, zbarrier_fields, std::extent_v<decltype(zbarrier_fields)>);
if (!converter.Convert())
{
std::cerr << std::format("Failed to parse zbarrier: \"{}\"\n", assetName);
return AssetCreationResult::Failure();
}
CalculateZBarrierFields(*zbarrier);
return AssetCreationResult::Success(context.AddAsset(std::move(registration)));
}

View File

@ -0,0 +1,21 @@
#pragma once
#include "Asset/AssetCreationContext.h"
#include "Asset/AssetCreationResult.h"
#include "InfoString/InfoString.h"
namespace T6
{
class InfoStringLoaderZBarrier
{
public:
InfoStringLoaderZBarrier(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
AssetCreationResult CreateAsset(const std::string& assetName, const InfoString& infoString, AssetCreationContext& context);
private:
MemoryManager& m_memory;
ISearchPath& m_search_path;
Zone& m_zone;
};
} // namespace T6

View File

@ -0,0 +1,54 @@
#include "RawLoaderZBarrierT6.h"
#include "Game/T6/ObjConstantsT6.h"
#include "Game/T6/T6.h"
#include "InfoString/InfoString.h"
#include "InfoStringLoaderZBarrierT6.h"
#include <cstring>
#include <format>
#include <iostream>
using namespace T6;
namespace
{
class RawLoaderZBarrier final : public AssetCreator<AssetZBarrier>
{
public:
RawLoaderZBarrier(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
: m_search_path(searchPath),
m_info_string_loader(memory, searchPath, zone)
{
}
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{
const auto fileName = std::format("zbarrier/{}", assetName);
const auto file = m_search_path.Open(fileName);
if (!file.IsOpen())
return AssetCreationResult::NoAction();
InfoString infoString;
if (!infoString.FromStream(ObjConstants::INFO_STRING_PREFIX_ZBARRIER, *file.m_stream))
{
std::cerr << std::format("Could not parse as info string file: \"{}\"\n", fileName);
return AssetCreationResult::Failure();
}
return m_info_string_loader.CreateAsset(assetName, infoString, context);
}
private:
ISearchPath& m_search_path;
InfoStringLoaderZBarrier m_info_string_loader;
};
} // namespace
namespace T6
{
std::unique_ptr<AssetCreator<AssetZBarrier>> CreateRawZBarrierLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone)
{
return std::make_unique<RawLoaderZBarrier>(memory, searchPath, zone);
}
} // namespace T6

View File

@ -0,0 +1,13 @@
#pragma once
#include "Asset/IAssetCreator.h"
#include "Game/T6/T6.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
#include <memory>
namespace T6
{
std::unique_ptr<AssetCreator<AssetZBarrier>> CreateRawZBarrierLoader(MemoryManager& memory, ISearchPath& searchPath, Zone& zone);
} // namespace T6