mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-08-30 21:53:15 +00:00
refactor: streamline zbarrier dumping
This commit is contained in:
11
src/ObjCommon/ZBarrier/ZBarrierCommon.cpp
Normal file
11
src/ObjCommon/ZBarrier/ZBarrierCommon.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "ZBarrierCommon.h"
|
||||
|
||||
#include <format>
|
||||
|
||||
namespace z_barrier
|
||||
{
|
||||
std::string GetFileNameForAssetName(const std::string& assetName)
|
||||
{
|
||||
return std::format("zbarrier/{}", assetName);
|
||||
}
|
||||
} // namespace z_barrier
|
8
src/ObjCommon/ZBarrier/ZBarrierCommon.h
Normal file
8
src/ObjCommon/ZBarrier/ZBarrierCommon.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace z_barrier
|
||||
{
|
||||
std::string GetFileNameForAssetName(const std::string& assetName);
|
||||
}
|
@@ -4,12 +4,14 @@
|
||||
#include "Game/T6/T6.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
#include "InfoStringLoaderZBarrierT6.h"
|
||||
#include "ZBarrier/ZBarrierCommon.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
using namespace T6;
|
||||
using namespace ::z_barrier;
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -24,7 +26,7 @@ namespace
|
||||
|
||||
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
|
||||
{
|
||||
const auto fileName = std::format("zbarrier/{}", assetName);
|
||||
const auto fileName = GetFileNameForAssetName(assetName);
|
||||
const auto file = m_search_path.Open(fileName);
|
||||
if (!file.IsOpen())
|
||||
return AssetCreationResult::NoAction();
|
||||
|
@@ -25,7 +25,7 @@
|
||||
#include "Weapon/AssetDumperWeaponAttachment.h"
|
||||
#include "Weapon/AssetDumperWeaponAttachmentUnique.h"
|
||||
#include "Weapon/AssetDumperWeaponCamo.h"
|
||||
#include "ZBarrier/AssetDumperZBarrier.h"
|
||||
#include "ZBarrier/ZBarrierDumperT6.h"
|
||||
|
||||
using namespace T6;
|
||||
|
||||
@@ -93,7 +93,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const
|
||||
DUMP_ASSET_POOL(slug::Dumper, m_slug, ASSET_TYPE_SLUG)
|
||||
// DUMP_ASSET_POOL(AssetDumperFootstepTableDef, m_footstep_table, ASSET_TYPE_FOOTSTEP_TABLE)
|
||||
// DUMP_ASSET_POOL(AssetDumperFootstepFXTableDef, m_footstep_fx_table, ASSET_TYPE_FOOTSTEPFX_TABLE)
|
||||
DUMP_ASSET_POOL(AssetDumperZBarrier, m_zbarrier, ASSET_TYPE_ZBARRIER)
|
||||
DUMP_ASSET_POOL(z_barrier::Dumper, m_zbarrier, ASSET_TYPE_ZBARRIER)
|
||||
|
||||
return true;
|
||||
|
||||
|
@@ -1,77 +0,0 @@
|
||||
#include "AssetDumperZBarrier.h"
|
||||
|
||||
#include "Game/T6/InfoString/InfoStringFromStructConverter.h"
|
||||
#include "Game/T6/ObjConstantsT6.h"
|
||||
#include "Game/T6/ZBarrier/ZBarrierFields.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <type_traits>
|
||||
|
||||
using namespace T6;
|
||||
|
||||
namespace T6
|
||||
{
|
||||
class InfoStringFromZBarrierConverter final : public InfoStringFromStructConverter
|
||||
{
|
||||
protected:
|
||||
void FillFromExtensionField(const cspField_t& field) override
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
|
||||
public:
|
||||
InfoStringFromZBarrierConverter(const ZBarrierDef* structure,
|
||||
const cspField_t* fields,
|
||||
const size_t fieldCount,
|
||||
std::function<std::string(scr_string_t)> scriptStringValueCallback)
|
||||
: InfoStringFromStructConverter(structure, fields, fieldCount, std::move(scriptStringValueCallback))
|
||||
{
|
||||
}
|
||||
};
|
||||
} // namespace T6
|
||||
|
||||
InfoString AssetDumperZBarrier::CreateInfoString(XAssetInfo<ZBarrierDef>* asset)
|
||||
{
|
||||
InfoStringFromZBarrierConverter converter(asset->Asset(),
|
||||
zbarrier_fields,
|
||||
std::extent_v<decltype(zbarrier_fields)>,
|
||||
[asset](const scr_string_t scrStr) -> std::string
|
||||
{
|
||||
assert(scrStr < asset->m_zone->m_script_strings.Count());
|
||||
if (scrStr >= asset->m_zone->m_script_strings.Count())
|
||||
return "";
|
||||
|
||||
return asset->m_zone->m_script_strings[scrStr];
|
||||
});
|
||||
|
||||
return converter.Convert();
|
||||
}
|
||||
|
||||
bool AssetDumperZBarrier::ShouldDump(XAssetInfo<ZBarrierDef>* asset)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void AssetDumperZBarrier::DumpAsset(AssetDumpingContext& context, XAssetInfo<ZBarrierDef>* asset)
|
||||
{
|
||||
// Only dump raw when no gdt available
|
||||
if (context.m_gdt)
|
||||
{
|
||||
const auto infoString = CreateInfoString(asset);
|
||||
GdtEntry gdtEntry(asset->m_name, ObjConstants::GDF_FILENAME_ZBARRIER);
|
||||
infoString.ToGdtProperties(ObjConstants::INFO_STRING_PREFIX_ZBARRIER, gdtEntry);
|
||||
context.m_gdt->WriteEntry(gdtEntry);
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto assetFile = context.OpenAssetFile("zbarrier/" + asset->m_name);
|
||||
|
||||
if (!assetFile)
|
||||
return;
|
||||
|
||||
auto& stream = *assetFile;
|
||||
const auto infoString = CreateInfoString(asset);
|
||||
const auto stringValue = infoString.ToString(ObjConstants::INFO_STRING_PREFIX_ZBARRIER);
|
||||
stream.write(stringValue.c_str(), stringValue.size());
|
||||
}
|
||||
}
|
82
src/ObjWriting/Game/T6/ZBarrier/ZBarrierDumperT6.cpp
Normal file
82
src/ObjWriting/Game/T6/ZBarrier/ZBarrierDumperT6.cpp
Normal file
@@ -0,0 +1,82 @@
|
||||
#include "ZBarrierDumperT6.h"
|
||||
|
||||
#include "Game/T6/InfoString/InfoStringFromStructConverter.h"
|
||||
#include "Game/T6/ObjConstantsT6.h"
|
||||
#include "Game/T6/ZBarrier/ZBarrierFields.h"
|
||||
#include "ZBarrier/ZBarrierCommon.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <type_traits>
|
||||
|
||||
using namespace T6;
|
||||
using namespace ::z_barrier;
|
||||
|
||||
namespace
|
||||
{
|
||||
class InfoStringFromZBarrierConverter final : public InfoStringFromStructConverter
|
||||
{
|
||||
protected:
|
||||
void FillFromExtensionField(const cspField_t& field) override
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
|
||||
public:
|
||||
InfoStringFromZBarrierConverter(const ZBarrierDef* structure,
|
||||
const cspField_t* fields,
|
||||
const size_t fieldCount,
|
||||
std::function<std::string(scr_string_t)> scriptStringValueCallback)
|
||||
: InfoStringFromStructConverter(structure, fields, fieldCount, std::move(scriptStringValueCallback))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
InfoString CreateInfoString(XAssetInfo<ZBarrierDef>* asset)
|
||||
{
|
||||
InfoStringFromZBarrierConverter converter(asset->Asset(),
|
||||
zbarrier_fields,
|
||||
std::extent_v<decltype(zbarrier_fields)>,
|
||||
[asset](const scr_string_t scrStr) -> std::string
|
||||
{
|
||||
assert(scrStr < asset->m_zone->m_script_strings.Count());
|
||||
if (scrStr >= asset->m_zone->m_script_strings.Count())
|
||||
return "";
|
||||
|
||||
return asset->m_zone->m_script_strings[scrStr];
|
||||
});
|
||||
|
||||
return converter.Convert();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace T6::z_barrier
|
||||
{
|
||||
bool Dumper::ShouldDump(XAssetInfo<ZBarrierDef>* asset)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void Dumper::DumpAsset(AssetDumpingContext& context, XAssetInfo<ZBarrierDef>* asset)
|
||||
{
|
||||
// Only dump raw when no gdt available
|
||||
if (context.m_gdt)
|
||||
{
|
||||
const auto infoString = CreateInfoString(asset);
|
||||
GdtEntry gdtEntry(asset->m_name, ObjConstants::GDF_FILENAME_ZBARRIER);
|
||||
infoString.ToGdtProperties(ObjConstants::INFO_STRING_PREFIX_ZBARRIER, gdtEntry);
|
||||
context.m_gdt->WriteEntry(gdtEntry);
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto assetFile = context.OpenAssetFile(GetFileNameForAssetName(asset->m_name));
|
||||
|
||||
if (!assetFile)
|
||||
return;
|
||||
|
||||
auto& stream = *assetFile;
|
||||
const auto infoString = CreateInfoString(asset);
|
||||
const auto stringValue = infoString.ToString(ObjConstants::INFO_STRING_PREFIX_ZBARRIER);
|
||||
stream.write(stringValue.c_str(), stringValue.size());
|
||||
}
|
||||
}
|
||||
} // namespace T6::z_barrier
|
@@ -4,14 +4,12 @@
|
||||
#include "Game/T6/T6.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
|
||||
namespace T6
|
||||
namespace T6::z_barrier
|
||||
{
|
||||
class AssetDumperZBarrier final : public AbstractAssetDumper<ZBarrierDef>
|
||||
class Dumper final : public AbstractAssetDumper<ZBarrierDef>
|
||||
{
|
||||
static InfoString CreateInfoString(XAssetInfo<ZBarrierDef>* asset);
|
||||
|
||||
protected:
|
||||
bool ShouldDump(XAssetInfo<ZBarrierDef>* asset) override;
|
||||
void DumpAsset(AssetDumpingContext& context, XAssetInfo<ZBarrierDef>* asset) override;
|
||||
};
|
||||
} // namespace T6
|
||||
} // namespace T6::z_barrier
|
Reference in New Issue
Block a user