mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-07-26 09:50:38 +00:00
feat: templated MapEnts dumper (#923)
Relates to https://github.com/Laupetin/OpenAssetTools/issues/626
This commit is contained in:
@@ -59,7 +59,7 @@ using `Linker`):
|
||||
| ComWorld | ❌ | ❌ | |
|
||||
| GameWorldSp | ❌ | ❌ | |
|
||||
| GameWorldMp | ❌ | ❌ | |
|
||||
| MapEnts | ❌ | ❌ | |
|
||||
| MapEnts | ⁉️ | ❌ | Entity string can be exported. Binary data currently not. |
|
||||
| FxWorld | ❌ | ❌ | |
|
||||
| GfxWorld | ❌ | ❌ | |
|
||||
| GfxLightDef | ✅ | ✅ | |
|
||||
@@ -101,7 +101,7 @@ using `Linker`):
|
||||
| GlassWorld | ❌ | ❌ | |
|
||||
| PathData | ❌ | ❌ | |
|
||||
| VehicleTrack | ❌ | ❌ | |
|
||||
| MapEnts | ❌ | ❌ | |
|
||||
| MapEnts | ⁉️ | ❌ | Entity string can be exported. Binary data currently not. |
|
||||
| FxWorld | ❌ | ❌ | |
|
||||
| GfxWorld | ❌ | ❌ | |
|
||||
| GfxLightDef | ✅ | ✅ | |
|
||||
@@ -211,7 +211,7 @@ using `Linker`):
|
||||
| ComWorld | ❌ | ❌ | |
|
||||
| GameWorldSp | ❌ | ❌ | |
|
||||
| GameWorldMp | ❌ | ❌ | |
|
||||
| MapEnts | ✅ | ❌ | |
|
||||
| MapEnts | ⁉️ | ❌ | Entity string can be exported. Binary data currently not. |
|
||||
| GfxWorld | ❌ | ❌ | |
|
||||
| GfxLightDef | ✅ | ✅ | |
|
||||
| Font_s | ✅ | ✅ | |
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
#include "MapEntsDumperIW3.h"
|
||||
|
||||
#include "Maps/MapEntsCommon.h"
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
namespace map_ents
|
||||
{
|
||||
void DumperIW3::DumpAsset(AssetDumpingContext& context, const XAssetInfo<AssetMapEnts::Type>& asset)
|
||||
{
|
||||
const auto* mapEnts = asset.Asset();
|
||||
const auto assetFile = context.OpenAssetFile(GetEntsFileNameForAssetName(asset.m_name));
|
||||
|
||||
if (!assetFile)
|
||||
return;
|
||||
|
||||
auto& stream = *assetFile;
|
||||
stream.write(mapEnts->entityString, std::max(mapEnts->numEntityChars - 1, 0));
|
||||
}
|
||||
} // namespace map_ents
|
||||
@@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/IW3/IW3.h"
|
||||
|
||||
namespace map_ents
|
||||
{
|
||||
class DumperIW3 final : public AbstractAssetDumper<IW3::AssetMapEnts>
|
||||
{
|
||||
protected:
|
||||
void DumpAsset(AssetDumpingContext& context, const XAssetInfo<IW3::MapEnts>& asset) override;
|
||||
};
|
||||
} // namespace map_ents
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
#include "Game/IW3/Font/FontDumperIW3.h"
|
||||
#include "Game/IW3/Image/ImageDumperIW3.h"
|
||||
#include "Game/IW3/Maps/MapEntsDumperIW3.h"
|
||||
#include "Game/IW3/Material/MaterialJsonDumperIW3.h"
|
||||
#include "Game/IW3/Techset/TechsetDumperIW3.h"
|
||||
#include "Game/IW3/XAnim/XAnimDumperIW3.h"
|
||||
#include "Game/IW3/XModel/XModelDumperIW3.h"
|
||||
#include "LightDef/LightDefDumperIW3.h"
|
||||
#include "Localize/LocalizeDumperIW3.h"
|
||||
#include "Maps/MapEntsDumperIW3.h"
|
||||
#include "PhysPreset/PhysPresetInfoStringDumperIW3.h"
|
||||
#include "RawFile/RawFileDumperIW3.h"
|
||||
#include "Sound/LoadedSoundDumperIW3.h"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "Game/IW4/Font/FontDumperIW4.h"
|
||||
#include "Game/IW4/Image/ImageDumperIW4.h"
|
||||
#include "Game/IW4/Maps/MapEntsDumperIW4.h"
|
||||
#include "Game/IW4/Material/MaterialJsonDumperIW4.h"
|
||||
#include "Game/IW4/Techset/PixelShaderDumperIW4.h"
|
||||
#include "Game/IW4/Techset/TechsetDumperIW4.h"
|
||||
@@ -55,7 +56,7 @@ void ObjWriter::RegisterAssetDumpers(AssetDumpingContext& context)
|
||||
// REGISTER_DUMPER(AssetDumperComWorld)
|
||||
// REGISTER_DUMPER(AssetDumperGameWorldSp)
|
||||
// REGISTER_DUMPER(AssetDumperGameWorldMp)
|
||||
// REGISTER_DUMPER(AssetDumperMapEnts)
|
||||
RegisterAssetDumper(std::make_unique<map_ents::DumperIW4>());
|
||||
// REGISTER_DUMPER(AssetDumperFxWorld)
|
||||
// REGISTER_DUMPER(AssetDumperGfxWorld)
|
||||
RegisterAssetDumper(std::make_unique<light_def::DumperIW4>());
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "Game/IW4/XAnim/XAnimDumperIW4.h"
|
||||
#include "Game/IW5/Font/FontDumperIW5.h"
|
||||
#include "Game/IW5/Image/ImageDumperIW5.h"
|
||||
#include "Game/IW5/Maps/MapEntsDumperIW5.h"
|
||||
#include "Game/IW5/Material/MaterialJsonDumperIW5.h"
|
||||
#include "Game/IW5/Techset/PixelShaderDumperIW5.h"
|
||||
#include "Game/IW5/Techset/TechsetDumperIW5.h"
|
||||
@@ -51,7 +52,7 @@ void ObjWriter::RegisterAssetDumpers(AssetDumpingContext& context)
|
||||
// REGISTER_DUMPER(AssetDumperGlassWorld)
|
||||
// REGISTER_DUMPER(AssetDumperPathData)
|
||||
// REGISTER_DUMPER(AssetDumperVehicleTrack)
|
||||
// REGISTER_DUMPER(AssetDumperMapEnts)
|
||||
RegisterAssetDumper(std::make_unique<map_ents::DumperIW5>());
|
||||
// REGISTER_DUMPER(AssetDumperFxWorld)
|
||||
// REGISTER_DUMPER(AssetDumperGfxWorld)
|
||||
RegisterAssetDumper(std::make_unique<light_def::DumperIW5>());
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
#include "MapEntsDumperT4.h"
|
||||
|
||||
#include "Maps/MapEntsCommon.h"
|
||||
|
||||
using namespace T4;
|
||||
|
||||
namespace map_ents
|
||||
{
|
||||
void DumperT4::DumpAsset(AssetDumpingContext& context, const XAssetInfo<AssetMapEnts::Type>& asset)
|
||||
{
|
||||
const auto* mapEnts = asset.Asset();
|
||||
const auto assetFile = context.OpenAssetFile(GetEntsFileNameForAssetName(asset.m_name));
|
||||
|
||||
if (!assetFile)
|
||||
return;
|
||||
|
||||
auto& stream = *assetFile;
|
||||
stream.write(mapEnts->entityString, std::max(mapEnts->numEntityChars - 1, 0));
|
||||
}
|
||||
} // namespace map_ents
|
||||
@@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/T4/T4.h"
|
||||
|
||||
namespace map_ents
|
||||
{
|
||||
class DumperT4 final : public AbstractAssetDumper<T4::AssetMapEnts>
|
||||
{
|
||||
protected:
|
||||
void DumpAsset(AssetDumpingContext& context, const XAssetInfo<T4::MapEnts>& asset) override;
|
||||
};
|
||||
} // namespace map_ents
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
#include "Game/T4/Font/FontDumperT4.h"
|
||||
#include "Game/T4/Image/ImageDumperT4.h"
|
||||
#include "Game/T4/Maps/MapEntsDumperT4.h"
|
||||
#include "Game/T4/Material/MaterialJsonDumperT4.h"
|
||||
#include "Game/T4/XAnim/XAnimDumperT4.h"
|
||||
#include "Game/T4/XModel/XModelDumperT4.h"
|
||||
#include "Localize/LocalizeDumperT4.h"
|
||||
#include "Maps/MapEntsDumperT4.h"
|
||||
#include "PhysConstraints/PhysConstraintsInfoStringDumperT4.h"
|
||||
#include "RawFile/RawFileDumperT4.h"
|
||||
#include "Sound/LoadedSoundDumperT4.h"
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
#include "MapEntsDumperT5.h"
|
||||
|
||||
#include "Maps/MapEntsCommon.h"
|
||||
|
||||
using namespace T5;
|
||||
|
||||
namespace map_ents
|
||||
{
|
||||
void DumperT5::DumpAsset(AssetDumpingContext& context, const XAssetInfo<AssetMapEnts::Type>& asset)
|
||||
{
|
||||
const auto* mapEnts = asset.Asset();
|
||||
const auto assetFile = context.OpenAssetFile(GetEntsFileNameForAssetName(asset.m_name));
|
||||
|
||||
if (!assetFile)
|
||||
return;
|
||||
|
||||
auto& stream = *assetFile;
|
||||
stream.write(mapEnts->entityString, std::max(mapEnts->numEntityChars - 1, 0));
|
||||
}
|
||||
} // namespace map_ents
|
||||
@@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/T5/T5.h"
|
||||
|
||||
namespace map_ents
|
||||
{
|
||||
class DumperT5 final : public AbstractAssetDumper<T5::AssetMapEnts>
|
||||
{
|
||||
protected:
|
||||
void DumpAsset(AssetDumpingContext& context, const XAssetInfo<T5::AssetMapEnts::Type>& asset) override;
|
||||
};
|
||||
} // namespace map_ents
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
#include "Game/T5/Font/FontDumperT5.h"
|
||||
#include "Game/T5/Image/ImageDumperT5.h"
|
||||
#include "Game/T5/Maps/MapEntsDumperT5.h"
|
||||
#include "Game/T5/Material/MaterialJsonDumperT5.h"
|
||||
#include "Game/T5/Techset/TechsetDumperT5.h"
|
||||
#include "Game/T5/XAnim/XAnimDumperT5.h"
|
||||
#include "Game/T5/XModel/XModelDumperT5.h"
|
||||
#include "LightDef/LightDefDumperT5.h"
|
||||
#include "Localize/LocalizeDumperT5.h"
|
||||
#include "Maps/MapEntsDumperT5.h"
|
||||
#include "PhysConstraints/PhysConstraintsInfoStringDumperT5.h"
|
||||
#include "PhysPreset/PhysPresetInfoStringDumperT5.h"
|
||||
#include "RawFile/RawFileDumperT5.h"
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
#include "MapEntsDumperT6.h"
|
||||
|
||||
#include "Maps/MapEntsCommon.h"
|
||||
|
||||
using namespace T6;
|
||||
|
||||
namespace map_ents
|
||||
{
|
||||
void DumperT6::DumpAsset(AssetDumpingContext& context, const XAssetInfo<AssetMapEnts::Type>& asset)
|
||||
{
|
||||
const auto* mapEnts = asset.Asset();
|
||||
const auto assetFile = context.OpenAssetFile(GetEntsFileNameForAssetName(asset.m_name));
|
||||
|
||||
if (!assetFile)
|
||||
return;
|
||||
|
||||
auto& stream = *assetFile;
|
||||
stream.write(mapEnts->entityString, std::max(mapEnts->numEntityChars - 1, 0));
|
||||
}
|
||||
} // namespace map_ents
|
||||
@@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/T6/T6.h"
|
||||
|
||||
namespace map_ents
|
||||
{
|
||||
class DumperT6 final : public AbstractAssetDumper<T6::AssetMapEnts>
|
||||
{
|
||||
protected:
|
||||
void DumpAsset(AssetDumpingContext& context, const XAssetInfo<T6::AssetMapEnts::Type>& asset) override;
|
||||
};
|
||||
} // namespace map_ents
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "FontIcon/FontIconDumperT6.h"
|
||||
#include "Game/T6/Font/FontDumperT6.h"
|
||||
#include "Game/T6/Image/ImageDumperT6.h"
|
||||
#include "Game/T6/Maps/MapEntsDumperT6.h"
|
||||
#include "Game/T6/Material/MaterialJsonDumperT6.h"
|
||||
#include "Game/T6/Techset/TechsetDumperT6.h"
|
||||
#include "Game/T6/XAnim/XAnimDumperT6.h"
|
||||
@@ -11,7 +12,6 @@
|
||||
#include "LightDef/LightDefDumperT6.h"
|
||||
#include "Localize/LocalizeDumperT6.h"
|
||||
#include "Maps/AddonMapEntsDumperT6.h"
|
||||
#include "Maps/MapEntsDumperT6.h"
|
||||
#include "PhysConstraints/PhysConstraintsInfoStringDumperT6.h"
|
||||
#include "PhysPreset/PhysPresetInfoStringDumperT6.h"
|
||||
#include "Qdb/QdbDumperT6.h"
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
#options GAME (IW3, IW4, IW5, T4, T5, T6)
|
||||
|
||||
#filename "Game/" + GAME + "/Maps/MapEntsDumper" + GAME + ".cpp"
|
||||
|
||||
// This file was templated.
|
||||
// See MapEntsDumper.cpp.template.
|
||||
// Do not modify, changes will be lost.
|
||||
|
||||
#set DUMPER_HEADER "\"MapEntsDumper" + GAME + ".h\""
|
||||
#include DUMPER_HEADER
|
||||
|
||||
#include "Maps/MapEntsCommon.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
using namespace GAME;
|
||||
|
||||
#set CLASS_NAME "Dumper" + GAME
|
||||
|
||||
namespace map_ents
|
||||
{
|
||||
void CLASS_NAME::DumpAsset(AssetDumpingContext& context, const XAssetInfo<AssetMapEnts::Type>& asset)
|
||||
{
|
||||
const auto* mapEnts = asset.Asset();
|
||||
const auto assetFile = context.OpenAssetFile(GetEntsFileNameForAssetName(asset.m_name));
|
||||
|
||||
if (!assetFile)
|
||||
return;
|
||||
|
||||
auto& stream = *assetFile;
|
||||
stream.write(mapEnts->entityString, std::max(mapEnts->numEntityChars - 1, 0));
|
||||
}
|
||||
} // namespace map_ents
|
||||
@@ -0,0 +1,24 @@
|
||||
#options GAME (IW3, IW4, IW5, T4, T5, T6)
|
||||
|
||||
#filename "Game/" + GAME + "/Maps/MapEntsDumper" + GAME + ".h"
|
||||
|
||||
#set GAME_HEADER "\"Game/" + GAME + "/" + GAME + ".h\""
|
||||
#set CLASS_NAME "Dumper" + GAME
|
||||
|
||||
// This file was templated.
|
||||
// See MapEntsDumper.h.template.
|
||||
// Do not modify, changes will be lost.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include GAME_HEADER
|
||||
|
||||
namespace map_ents
|
||||
{
|
||||
class CLASS_NAME final : public AbstractAssetDumper<GAME::AssetMapEnts>
|
||||
{
|
||||
protected:
|
||||
void DumpAsset(AssetDumpingContext& context, const XAssetInfo<GAME::AssetMapEnts::Type>& asset) override;
|
||||
};
|
||||
} // namespace map_ents
|
||||
@@ -0,0 +1,47 @@
|
||||
#include "Game/IW4/Maps/MapEntsDumperIW4.h"
|
||||
#include "SearchPath/MockOutputPath.h"
|
||||
#include "SearchPath/MockSearchPath.h"
|
||||
#include "ZoneLoading.h"
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
namespace
|
||||
{
|
||||
TEST_CASE("MapEnts dumper writes entity string (IW4)", "[iw4][mapents][system]")
|
||||
{
|
||||
constexpr auto MAP_ENTS_NAME = "maps/mp/test_map.d3dbsp";
|
||||
char entityString[] = R"({
|
||||
"classname" "worldspawn"
|
||||
}
|
||||
)";
|
||||
|
||||
TriggerModel triggerModel{};
|
||||
Stage stage{};
|
||||
MapEnts mapEnts{};
|
||||
mapEnts.name = MAP_ENTS_NAME;
|
||||
mapEnts.entityString = entityString;
|
||||
mapEnts.numEntityChars = sizeof(entityString);
|
||||
mapEnts.trigger.count = 1;
|
||||
mapEnts.trigger.models = &triggerModel;
|
||||
mapEnts.stages = &stage;
|
||||
mapEnts.stageCount = 1;
|
||||
|
||||
Zone zone("MockZone", 0, GameId::IW4, GamePlatform::PC);
|
||||
zone.m_pools.AddAsset(std::make_unique<XAssetInfo<MapEnts>>(ASSET_TYPE_MAP_ENTS, mapEnts.name, &mapEnts));
|
||||
|
||||
MockSearchPath mockObjPath;
|
||||
MockOutputPath mockOutput;
|
||||
AssetDumpingContext dumpingContext(zone, "", mockOutput, mockObjPath, std::nullopt);
|
||||
map_ents::DumperIW4 dumper;
|
||||
dumper.Dump(dumpingContext);
|
||||
|
||||
const auto* dumpedFile = mockOutput.GetMockedFile("maps/mp/test_map.d3dbsp.ents");
|
||||
REQUIRE(dumpedFile != nullptr);
|
||||
REQUIRE(dumpedFile->m_data.size() == sizeof(entityString) - 1);
|
||||
REQUIRE(dumpedFile->AsString() == entityString);
|
||||
}
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user