mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-01-11 19:21:50 +00:00
chore: move ZoneDefinitionWriter from Unlinker to ZoneCommon
This commit is contained in:
35
src/ZoneCommon/Game/IW3/Zone/Definition/ZoneDefWriterIW3.cpp
Normal file
35
src/ZoneCommon/Game/IW3/Zone/Definition/ZoneDefWriterIW3.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "ZoneDefWriterIW3.h"
|
||||
|
||||
#include "Game/IW3/GameAssetPoolIW3.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
using namespace IW3;
|
||||
|
||||
void ZoneDefWriter::WriteMetaData(ZoneDefinitionOutputStream& stream, const Zone& zone) const {}
|
||||
|
||||
void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone& zone) const
|
||||
{
|
||||
const auto* pools = dynamic_cast<GameAssetPoolIW3*>(zone.m_pools.get());
|
||||
|
||||
assert(pools);
|
||||
if (!pools)
|
||||
return;
|
||||
|
||||
// Localized strings are all collected in one string file. So only add this to the zone file.
|
||||
if (!pools->m_localize->m_asset_lookup.empty())
|
||||
stream.WriteEntry(*pools->GetAssetTypeName(ASSET_TYPE_LOCALIZE_ENTRY), zone.m_name);
|
||||
|
||||
for (const auto& asset : *pools)
|
||||
{
|
||||
switch (asset->m_type)
|
||||
{
|
||||
case ASSET_TYPE_LOCALIZE_ENTRY:
|
||||
break;
|
||||
|
||||
default:
|
||||
stream.WriteEntry(*pools->GetAssetTypeName(asset->m_type), asset->m_name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
src/ZoneCommon/Game/IW3/Zone/Definition/ZoneDefWriterIW3.h
Normal file
13
src/ZoneCommon/Game/IW3/Zone/Definition/ZoneDefWriterIW3.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "Zone/Definition/ZoneDefWriter.h"
|
||||
|
||||
namespace IW3
|
||||
{
|
||||
class ZoneDefWriter final : public AbstractZoneDefWriter
|
||||
{
|
||||
protected:
|
||||
void WriteMetaData(ZoneDefinitionOutputStream& stream, const Zone& zone) const override;
|
||||
void WriteContent(ZoneDefinitionOutputStream& stream, const Zone& zone) const override;
|
||||
};
|
||||
} // namespace IW3
|
||||
35
src/ZoneCommon/Game/IW4/Zone/Definition/ZoneDefWriterIW4.cpp
Normal file
35
src/ZoneCommon/Game/IW4/Zone/Definition/ZoneDefWriterIW4.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "ZoneDefWriterIW4.h"
|
||||
|
||||
#include "Game/IW4/GameAssetPoolIW4.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
void ZoneDefWriter::WriteMetaData(ZoneDefinitionOutputStream& stream, const Zone& zone) const {}
|
||||
|
||||
void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone& zone) const
|
||||
{
|
||||
const auto* pools = dynamic_cast<GameAssetPoolIW4*>(zone.m_pools.get());
|
||||
|
||||
assert(pools);
|
||||
if (!pools)
|
||||
return;
|
||||
|
||||
// Localized strings are all collected in one string file. So only add this to the zone file.
|
||||
if (!pools->m_localize->m_asset_lookup.empty())
|
||||
stream.WriteEntry(*pools->GetAssetTypeName(ASSET_TYPE_LOCALIZE_ENTRY), zone.m_name);
|
||||
|
||||
for (const auto& asset : *pools)
|
||||
{
|
||||
switch (asset->m_type)
|
||||
{
|
||||
case ASSET_TYPE_LOCALIZE_ENTRY:
|
||||
break;
|
||||
|
||||
default:
|
||||
stream.WriteEntry(*pools->GetAssetTypeName(asset->m_type), asset->m_name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
src/ZoneCommon/Game/IW4/Zone/Definition/ZoneDefWriterIW4.h
Normal file
13
src/ZoneCommon/Game/IW4/Zone/Definition/ZoneDefWriterIW4.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "Zone/Definition/ZoneDefWriter.h"
|
||||
|
||||
namespace IW4
|
||||
{
|
||||
class ZoneDefWriter final : public AbstractZoneDefWriter
|
||||
{
|
||||
protected:
|
||||
void WriteMetaData(ZoneDefinitionOutputStream& stream, const Zone& zone) const override;
|
||||
void WriteContent(ZoneDefinitionOutputStream& stream, const Zone& zone) const override;
|
||||
};
|
||||
} // namespace IW4
|
||||
35
src/ZoneCommon/Game/IW5/Zone/Definition/ZoneDefWriterIW5.cpp
Normal file
35
src/ZoneCommon/Game/IW5/Zone/Definition/ZoneDefWriterIW5.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "ZoneDefWriterIW5.h"
|
||||
|
||||
#include "Game/IW5/GameAssetPoolIW5.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
using namespace IW5;
|
||||
|
||||
void ZoneDefWriter::WriteMetaData(ZoneDefinitionOutputStream& stream, const Zone& zone) const {}
|
||||
|
||||
void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone& zone) const
|
||||
{
|
||||
const auto* pools = dynamic_cast<GameAssetPoolIW5*>(zone.m_pools.get());
|
||||
|
||||
assert(pools);
|
||||
if (!pools)
|
||||
return;
|
||||
|
||||
// Localized strings are all collected in one string file. So only add this to the zone file.
|
||||
if (!pools->m_localize->m_asset_lookup.empty())
|
||||
stream.WriteEntry(*pools->GetAssetTypeName(ASSET_TYPE_LOCALIZE_ENTRY), zone.m_name);
|
||||
|
||||
for (const auto& asset : *pools)
|
||||
{
|
||||
switch (asset->m_type)
|
||||
{
|
||||
case ASSET_TYPE_LOCALIZE_ENTRY:
|
||||
break;
|
||||
|
||||
default:
|
||||
stream.WriteEntry(*pools->GetAssetTypeName(asset->m_type), asset->m_name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
src/ZoneCommon/Game/IW5/Zone/Definition/ZoneDefWriterIW5.h
Normal file
13
src/ZoneCommon/Game/IW5/Zone/Definition/ZoneDefWriterIW5.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "Zone/Definition/ZoneDefWriter.h"
|
||||
|
||||
namespace IW5
|
||||
{
|
||||
class ZoneDefWriter final : public AbstractZoneDefWriter
|
||||
{
|
||||
protected:
|
||||
void WriteMetaData(ZoneDefinitionOutputStream& stream, const Zone& zone) const override;
|
||||
void WriteContent(ZoneDefinitionOutputStream& stream, const Zone& zone) const override;
|
||||
};
|
||||
} // namespace IW5
|
||||
35
src/ZoneCommon/Game/T5/Zone/Definition/ZoneDefWriterT5.cpp
Normal file
35
src/ZoneCommon/Game/T5/Zone/Definition/ZoneDefWriterT5.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "ZoneDefWriterT5.h"
|
||||
|
||||
#include "Game/T5/GameAssetPoolT5.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
using namespace T5;
|
||||
|
||||
void ZoneDefWriter::WriteMetaData(ZoneDefinitionOutputStream& stream, const Zone& zone) const {}
|
||||
|
||||
void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone& zone) const
|
||||
{
|
||||
const auto* pools = dynamic_cast<GameAssetPoolT5*>(zone.m_pools.get());
|
||||
|
||||
assert(pools);
|
||||
if (!pools)
|
||||
return;
|
||||
|
||||
// Localized strings are all collected in one string file. So only add this to the zone file.
|
||||
if (!pools->m_localize->m_asset_lookup.empty())
|
||||
stream.WriteEntry(*pools->GetAssetTypeName(ASSET_TYPE_LOCALIZE_ENTRY), zone.m_name);
|
||||
|
||||
for (const auto& asset : *pools)
|
||||
{
|
||||
switch (asset->m_type)
|
||||
{
|
||||
case ASSET_TYPE_LOCALIZE_ENTRY:
|
||||
break;
|
||||
|
||||
default:
|
||||
stream.WriteEntry(*pools->GetAssetTypeName(asset->m_type), asset->m_name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
src/ZoneCommon/Game/T5/Zone/Definition/ZoneDefWriterT5.h
Normal file
13
src/ZoneCommon/Game/T5/Zone/Definition/ZoneDefWriterT5.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "Zone/Definition/ZoneDefWriter.h"
|
||||
|
||||
namespace T5
|
||||
{
|
||||
class ZoneDefWriter final : public AbstractZoneDefWriter
|
||||
{
|
||||
protected:
|
||||
void WriteMetaData(ZoneDefinitionOutputStream& stream, const Zone& zone) const override;
|
||||
void WriteContent(ZoneDefinitionOutputStream& stream, const Zone& zone) const override;
|
||||
};
|
||||
} // namespace T5
|
||||
92
src/ZoneCommon/Game/T6/Zone/Definition/ZoneDefWriterT6.cpp
Normal file
92
src/ZoneCommon/Game/T6/Zone/Definition/ZoneDefWriterT6.cpp
Normal file
@@ -0,0 +1,92 @@
|
||||
#include "ZoneDefWriterT6.h"
|
||||
|
||||
#include "Game/T6/CommonT6.h"
|
||||
#include "Game/T6/GameAssetPoolT6.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
using namespace T6;
|
||||
|
||||
namespace
|
||||
{
|
||||
class KeyValuePairKnownKey
|
||||
{
|
||||
public:
|
||||
std::string m_key;
|
||||
int m_hash;
|
||||
|
||||
explicit KeyValuePairKnownKey(std::string key)
|
||||
{
|
||||
m_key = std::move(key);
|
||||
m_hash = Common::Com_HashKey(m_key.c_str(), 64);
|
||||
}
|
||||
};
|
||||
|
||||
const KeyValuePairKnownKey KEY_VALUE_PAIR_KNOWN_KEYS[]{
|
||||
KeyValuePairKnownKey("ipak_read"),
|
||||
KeyValuePairKnownKey("ipak_write"),
|
||||
KeyValuePairKnownKey("initial_xmodels"),
|
||||
KeyValuePairKnownKey("initial_materials"),
|
||||
};
|
||||
|
||||
void WriteKeyValuePair(ZoneDefinitionOutputStream& stream, const KeyValuePair& kvp)
|
||||
{
|
||||
for (const auto& knownKey : KEY_VALUE_PAIR_KNOWN_KEYS)
|
||||
{
|
||||
if (knownKey.m_hash == kvp.keyHash)
|
||||
{
|
||||
stream.WriteMetaData("level." + knownKey.m_key, kvp.value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
std::ostringstream str;
|
||||
str << "level.@" << std::setfill('0') << std::setw(sizeof(int) * 2) << std::hex << kvp.keyHash;
|
||||
stream.WriteMetaData(str.str(), kvp.value);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void ZoneDefWriter::WriteMetaData(ZoneDefinitionOutputStream& stream, const Zone& zone) const
|
||||
{
|
||||
const auto* assetPoolT6 = dynamic_cast<GameAssetPoolT6*>(zone.m_pools.get());
|
||||
if (assetPoolT6 && !assetPoolT6->m_key_value_pairs->m_asset_lookup.empty())
|
||||
{
|
||||
for (const auto* kvpAsset : *assetPoolT6->m_key_value_pairs)
|
||||
{
|
||||
const auto* keyValuePairs = kvpAsset->Asset();
|
||||
for (auto varIndex = 0u; varIndex < keyValuePairs->numVariables; varIndex++)
|
||||
WriteKeyValuePair(stream, keyValuePairs->keyValuePairs[varIndex]);
|
||||
}
|
||||
|
||||
stream.EmptyLine();
|
||||
}
|
||||
}
|
||||
|
||||
void ZoneDefWriter::WriteContent(ZoneDefinitionOutputStream& stream, const Zone& zone) const
|
||||
{
|
||||
const auto* pools = dynamic_cast<GameAssetPoolT6*>(zone.m_pools.get());
|
||||
|
||||
assert(pools);
|
||||
if (!pools)
|
||||
return;
|
||||
|
||||
// Localized strings are all collected in one string file. So only add this to the zone file.
|
||||
if (!pools->m_localize->m_asset_lookup.empty())
|
||||
stream.WriteEntry(*pools->GetAssetTypeName(ASSET_TYPE_LOCALIZE_ENTRY), zone.m_name);
|
||||
|
||||
for (const auto& asset : *pools)
|
||||
{
|
||||
switch (asset->m_type)
|
||||
{
|
||||
case ASSET_TYPE_LOCALIZE_ENTRY:
|
||||
case ASSET_TYPE_KEYVALUEPAIRS: // KeyValuePairs should be included as zone file metadata and not as content
|
||||
break;
|
||||
|
||||
default:
|
||||
stream.WriteEntry(*pools->GetAssetTypeName(asset->m_type), asset->m_name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
src/ZoneCommon/Game/T6/Zone/Definition/ZoneDefWriterT6.h
Normal file
13
src/ZoneCommon/Game/T6/Zone/Definition/ZoneDefWriterT6.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "Zone/Definition/ZoneDefWriter.h"
|
||||
|
||||
namespace T6
|
||||
{
|
||||
class ZoneDefWriter final : public AbstractZoneDefWriter
|
||||
{
|
||||
protected:
|
||||
void WriteMetaData(ZoneDefinitionOutputStream& stream, const Zone& zone) const override;
|
||||
void WriteContent(ZoneDefinitionOutputStream& stream, const Zone& zone) const override;
|
||||
};
|
||||
} // namespace T6
|
||||
46
src/ZoneCommon/Zone/Definition/ZoneDefWriter.cpp
Normal file
46
src/ZoneCommon/Zone/Definition/ZoneDefWriter.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include "ZoneDefWriter.h"
|
||||
|
||||
#include "Game/IW3/Zone/Definition/ZoneDefWriterIW3.h"
|
||||
#include "Game/IW4/Zone/Definition/ZoneDefWriterIW4.h"
|
||||
#include "Game/IW5/Zone/Definition/ZoneDefWriterIW5.h"
|
||||
#include "Game/T5/Zone/Definition/ZoneDefWriterT5.h"
|
||||
#include "Game/T6/Zone/Definition/ZoneDefWriterT6.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
const IZoneDefWriter* IZoneDefWriter::GetZoneDefWriterForGame(GameId game)
|
||||
{
|
||||
static const IZoneDefWriter* zoneDefWriters[static_cast<unsigned>(GameId::COUNT)]{
|
||||
new IW3::ZoneDefWriter(),
|
||||
new IW4::ZoneDefWriter(),
|
||||
new IW5::ZoneDefWriter(),
|
||||
new T5::ZoneDefWriter(),
|
||||
new T6::ZoneDefWriter(),
|
||||
};
|
||||
|
||||
assert(static_cast<unsigned>(game) < static_cast<unsigned>(GameId::COUNT));
|
||||
const auto* result = zoneDefWriters[static_cast<unsigned>(game)];
|
||||
assert(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void AbstractZoneDefWriter::WriteZoneDef(std::ostream& stream, const Zone& zone, const bool useGdt) const
|
||||
{
|
||||
ZoneDefinitionOutputStream out(stream);
|
||||
const auto* game = IGame::GetGameById(zone.m_game_id);
|
||||
|
||||
out.WriteComment(game->GetFullName());
|
||||
out.WriteMetaData(META_DATA_KEY_GAME, game->GetShortName());
|
||||
out.EmptyLine();
|
||||
|
||||
if (useGdt)
|
||||
{
|
||||
out.WriteComment("Load asset gdt files");
|
||||
out.WriteMetaData(META_DATA_KEY_GDT, zone.m_name);
|
||||
out.EmptyLine();
|
||||
}
|
||||
|
||||
WriteMetaData(out, zone);
|
||||
WriteContent(out, zone);
|
||||
}
|
||||
32
src/ZoneCommon/Zone/Definition/ZoneDefWriter.h
Normal file
32
src/ZoneCommon/Zone/Definition/ZoneDefWriter.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "Zone/Definition/ZoneDefinitionStream.h"
|
||||
#include "Zone/Zone.h"
|
||||
|
||||
class IZoneDefWriter
|
||||
{
|
||||
public:
|
||||
IZoneDefWriter() = default;
|
||||
virtual ~IZoneDefWriter() = default;
|
||||
IZoneDefWriter(const IZoneDefWriter& other) = default;
|
||||
IZoneDefWriter(IZoneDefWriter&& other) noexcept = default;
|
||||
IZoneDefWriter& operator=(const IZoneDefWriter& other) = default;
|
||||
IZoneDefWriter& operator=(IZoneDefWriter&& other) noexcept = default;
|
||||
|
||||
virtual void WriteZoneDef(std::ostream& stream, const Zone& zone, bool useGdt) const = 0;
|
||||
|
||||
static const IZoneDefWriter* GetZoneDefWriterForGame(GameId game);
|
||||
};
|
||||
|
||||
class AbstractZoneDefWriter : public IZoneDefWriter
|
||||
{
|
||||
protected:
|
||||
static constexpr auto META_DATA_KEY_GAME = "game";
|
||||
static constexpr auto META_DATA_KEY_GDT = "gdt";
|
||||
|
||||
virtual void WriteMetaData(ZoneDefinitionOutputStream& stream, const Zone& zone) const = 0;
|
||||
virtual void WriteContent(ZoneDefinitionOutputStream& stream, const Zone& zone) const = 0;
|
||||
|
||||
public:
|
||||
void WriteZoneDef(std::ostream& stream, const Zone& zone, bool useGdt) const override;
|
||||
};
|
||||
Reference in New Issue
Block a user