mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-08-30 21:53:15 +00:00
refactor: streamline phys constraints dumping
This commit is contained in:
11
src/ObjCommon/PhysConstraints/PhysConstraintsCommon.cpp
Normal file
11
src/ObjCommon/PhysConstraints/PhysConstraintsCommon.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "PhysConstraintsCommon.h"
|
||||
|
||||
#include <format>
|
||||
|
||||
namespace phys_constraints
|
||||
{
|
||||
std::string GetFileNameForAssetName(const std::string& assetName)
|
||||
{
|
||||
return std::format("physconstraints/{}", assetName);
|
||||
}
|
||||
} // namespace phys_constraints
|
8
src/ObjCommon/PhysConstraints/PhysConstraintsCommon.h
Normal file
8
src/ObjCommon/PhysConstraints/PhysConstraintsCommon.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace phys_constraints
|
||||
{
|
||||
std::string GetFileNameForAssetName(const std::string& assetName);
|
||||
}
|
@@ -4,6 +4,7 @@
|
||||
#include "Game/T6/T6.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
#include "InfoStringLoaderPhysConstraintsT6.h"
|
||||
#include "PhysConstraints/PhysConstraintsCommon.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <format>
|
||||
@@ -24,7 +25,7 @@ namespace
|
||||
|
||||
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
|
||||
{
|
||||
const auto fileName = std::format("physconstraints/{}", assetName);
|
||||
const auto fileName = phys_constraints::GetFileNameForAssetName(assetName);
|
||||
const auto file = m_search_path.Open(fileName);
|
||||
if (!file.IsOpen())
|
||||
return AssetCreationResult::NoAction();
|
||||
|
@@ -6,7 +6,6 @@
|
||||
#include "Image/ImageDumperT5.h"
|
||||
#include "Localize/LocalizeDumperT5.h"
|
||||
#include "ObjWriting.h"
|
||||
#include "PhysConstraints/AssetDumperPhysConstraints.h"
|
||||
#include "PhysPreset/AssetDumperPhysPreset.h"
|
||||
#include "RawFile/AssetDumperRawFile.h"
|
||||
#include "Sound/AssetDumperSndBank.h"
|
||||
|
@@ -9,7 +9,7 @@
|
||||
#include "Localize/LocalizeDumperT6.h"
|
||||
#include "Maps/MapEntsDumperT6.h"
|
||||
#include "ObjWriting.h"
|
||||
#include "PhysConstraints/AssetDumperPhysConstraints.h"
|
||||
#include "PhysConstraints/PhysConstraintsInfoStringDumperT6.h"
|
||||
#include "PhysPreset/AssetDumperPhysPreset.h"
|
||||
#include "Qdb/AssetDumperQdb.h"
|
||||
#include "RawFile/AssetDumperRawFile.h"
|
||||
@@ -47,7 +47,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const
|
||||
const auto* assetPools = dynamic_cast<GameAssetPoolT6*>(context.m_zone.m_pools.get());
|
||||
|
||||
DUMP_ASSET_POOL(AssetDumperPhysPreset, m_phys_preset, ASSET_TYPE_PHYSPRESET)
|
||||
DUMP_ASSET_POOL(AssetDumperPhysConstraints, m_phys_constraints, ASSET_TYPE_PHYSCONSTRAINTS)
|
||||
DUMP_ASSET_POOL(phys_constraints::InfoStringDumper, m_phys_constraints, ASSET_TYPE_PHYSCONSTRAINTS)
|
||||
// DUMP_ASSET_POOL(AssetDumperDestructibleDef, m_destructible_def, ASSET_TYPE_DESTRUCTIBLEDEF)
|
||||
// DUMP_ASSET_POOL(AssetDumperXAnimParts, m_xanim_parts, ASSET_TYPE_XANIMPARTS)
|
||||
DUMP_ASSET_POOL(AssetDumperXModel, m_xmodel, ASSET_TYPE_XMODEL)
|
||||
|
@@ -1,88 +0,0 @@
|
||||
#include "AssetDumperPhysConstraints.h"
|
||||
|
||||
#include "Game/T6/InfoString/InfoStringFromStructConverter.h"
|
||||
#include "Game/T6/ObjConstantsT6.h"
|
||||
#include "Game/T6/PhysConstraints/PhysConstraintsFields.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <type_traits>
|
||||
|
||||
using namespace T6;
|
||||
|
||||
namespace T6
|
||||
{
|
||||
class InfoStringFromPhysConstraintsConverter final : public InfoStringFromStructConverter
|
||||
{
|
||||
protected:
|
||||
void FillFromExtensionField(const cspField_t& field) override
|
||||
{
|
||||
switch (static_cast<constraintsFieldType_t>(field.iFieldType))
|
||||
{
|
||||
case CFT_TYPE:
|
||||
FillFromEnumInt(std::string(field.szName), field.iOffset, s_constraintTypeNames, std::extent_v<decltype(s_constraintTypeNames)>);
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
InfoStringFromPhysConstraintsConverter(const PhysConstraints* 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 AssetDumperPhysConstraints::CreateInfoString(XAssetInfo<PhysConstraints>* asset)
|
||||
{
|
||||
assert(asset->Asset()->count <= 4);
|
||||
|
||||
InfoStringFromPhysConstraintsConverter converter(asset->Asset(),
|
||||
phys_constraints_fields,
|
||||
std::extent_v<decltype(phys_constraints_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 AssetDumperPhysConstraints::ShouldDump(XAssetInfo<PhysConstraints>* asset)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void AssetDumperPhysConstraints::DumpAsset(AssetDumpingContext& context, XAssetInfo<PhysConstraints>* 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_PHYS_CONSTRAINTS);
|
||||
infoString.ToGdtProperties(ObjConstants::INFO_STRING_PREFIX_PHYS_CONSTRAINTS, gdtEntry);
|
||||
context.m_gdt->WriteEntry(gdtEntry);
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto assetFile = context.OpenAssetFile("physconstraints/" + asset->m_name);
|
||||
|
||||
if (!assetFile)
|
||||
return;
|
||||
|
||||
auto& stream = *assetFile;
|
||||
const auto infoString = CreateInfoString(asset);
|
||||
const auto stringValue = infoString.ToString(ObjConstants::INFO_STRING_PREFIX_PHYS_CONSTRAINTS);
|
||||
stream.write(stringValue.c_str(), stringValue.size());
|
||||
}
|
||||
}
|
@@ -0,0 +1,93 @@
|
||||
#include "PhysConstraintsInfoStringDumperT6.h"
|
||||
|
||||
#include "Game/T6/InfoString/InfoStringFromStructConverter.h"
|
||||
#include "Game/T6/ObjConstantsT6.h"
|
||||
#include "Game/T6/PhysConstraints/PhysConstraintsFields.h"
|
||||
#include "PhysConstraints/PhysConstraintsCommon.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <type_traits>
|
||||
|
||||
using namespace T6;
|
||||
using namespace ::phys_constraints;
|
||||
|
||||
namespace
|
||||
{
|
||||
class InfoStringFromPhysConstraintsConverter final : public InfoStringFromStructConverter
|
||||
{
|
||||
protected:
|
||||
void FillFromExtensionField(const cspField_t& field) override
|
||||
{
|
||||
switch (static_cast<constraintsFieldType_t>(field.iFieldType))
|
||||
{
|
||||
case CFT_TYPE:
|
||||
FillFromEnumInt(std::string(field.szName), field.iOffset, s_constraintTypeNames, std::extent_v<decltype(s_constraintTypeNames)>);
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
InfoStringFromPhysConstraintsConverter(const PhysConstraints* 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<PhysConstraints>* asset)
|
||||
{
|
||||
assert(asset->Asset()->count <= 4);
|
||||
|
||||
InfoStringFromPhysConstraintsConverter converter(asset->Asset(),
|
||||
phys_constraints_fields,
|
||||
std::extent_v<decltype(phys_constraints_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::phys_constraints
|
||||
{
|
||||
bool InfoStringDumper::ShouldDump(XAssetInfo<PhysConstraints>* asset)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void InfoStringDumper::DumpAsset(AssetDumpingContext& context, XAssetInfo<PhysConstraints>* 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_PHYS_CONSTRAINTS);
|
||||
infoString.ToGdtProperties(ObjConstants::INFO_STRING_PREFIX_PHYS_CONSTRAINTS, 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_PHYS_CONSTRAINTS);
|
||||
stream.write(stringValue.c_str(), stringValue.size());
|
||||
}
|
||||
}
|
||||
} // namespace T6::phys_constraints
|
@@ -4,14 +4,12 @@
|
||||
#include "Game/T6/T6.h"
|
||||
#include "InfoString/InfoString.h"
|
||||
|
||||
namespace T6
|
||||
namespace T6::phys_constraints
|
||||
{
|
||||
class AssetDumperPhysConstraints final : public AbstractAssetDumper<PhysConstraints>
|
||||
class InfoStringDumper final : public AbstractAssetDumper<PhysConstraints>
|
||||
{
|
||||
static InfoString CreateInfoString(XAssetInfo<PhysConstraints>* asset);
|
||||
|
||||
protected:
|
||||
bool ShouldDump(XAssetInfo<PhysConstraints>* asset) override;
|
||||
void DumpAsset(AssetDumpingContext& context, XAssetInfo<PhysConstraints>* asset) override;
|
||||
};
|
||||
} // namespace T6
|
||||
} // namespace T6::phys_constraints
|
Reference in New Issue
Block a user