mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-25 22:27:53 -05:00
refactor: refactor ZoneDefWriter
This commit is contained in:
@ -3,15 +3,15 @@
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
ContentPrinter::ContentPrinter(Zone* zone)
|
||||
ContentPrinter::ContentPrinter(const Zone& zone)
|
||||
: m_zone(zone)
|
||||
{
|
||||
m_zone = zone;
|
||||
}
|
||||
|
||||
void ContentPrinter::PrintContent() const
|
||||
{
|
||||
const auto* pools = m_zone->m_pools.get();
|
||||
std::cout << std::format("Zone '{}' ({})\n", m_zone->m_name, m_zone->m_game->GetShortName());
|
||||
const auto* pools = m_zone.m_pools.get();
|
||||
std::cout << std::format("Zone '{}' ({})\n", m_zone.m_name, m_zone.m_game->GetShortName());
|
||||
std::cout << "Content:\n";
|
||||
|
||||
for (const auto& asset : *pools)
|
||||
|
@ -4,10 +4,11 @@
|
||||
|
||||
class ContentPrinter
|
||||
{
|
||||
Zone* m_zone;
|
||||
|
||||
public:
|
||||
explicit ContentPrinter(Zone* zone);
|
||||
explicit ContentPrinter(const Zone& zone);
|
||||
|
||||
void PrintContent() const;
|
||||
|
||||
private:
|
||||
const Zone& m_zone;
|
||||
};
|
||||
|
@ -1,17 +1,42 @@
|
||||
#include "ZoneDefWriter.h"
|
||||
|
||||
void AbstractZoneDefWriter::WriteZoneDef(std::ostream& stream, const UnlinkerArgs* args, Zone* zone) const
|
||||
#include "Game/IW3/ZoneDefWriterIW3.h"
|
||||
#include "Game/IW4/ZoneDefWriterIW4.h"
|
||||
#include "Game/IW5/ZoneDefWriterIW5.h"
|
||||
#include "Game/T5/ZoneDefWriterT5.h"
|
||||
#include "Game/T6/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 UnlinkerArgs& args, const Zone& zone) const
|
||||
{
|
||||
ZoneDefinitionOutputStream out(stream);
|
||||
|
||||
out.WriteComment(zone->m_game->GetFullName());
|
||||
out.WriteMetaData(META_DATA_KEY_GAME, zone->m_game->GetShortName());
|
||||
out.WriteComment(zone.m_game->GetFullName());
|
||||
out.WriteMetaData(META_DATA_KEY_GAME, zone.m_game->GetShortName());
|
||||
out.EmptyLine();
|
||||
|
||||
if (args->m_use_gdt)
|
||||
if (args.m_use_gdt)
|
||||
{
|
||||
out.WriteComment("Load asset gdt files");
|
||||
out.WriteMetaData(META_DATA_KEY_GDT, zone->m_name);
|
||||
out.WriteMetaData(META_DATA_KEY_GDT, zone.m_name);
|
||||
out.EmptyLine();
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
#include "UnlinkerArgs.h"
|
||||
#include "Zone/Definition/ZoneDefinitionStream.h"
|
||||
#include "Zone/Zone.h"
|
||||
|
||||
class IZoneDefWriter
|
||||
{
|
||||
@ -14,19 +13,20 @@ public:
|
||||
IZoneDefWriter& operator=(const IZoneDefWriter& other) = default;
|
||||
IZoneDefWriter& operator=(IZoneDefWriter&& other) noexcept = default;
|
||||
|
||||
virtual bool CanHandleZone(Zone* zone) const = 0;
|
||||
virtual void WriteZoneDef(std::ostream& stream, const UnlinkerArgs* args, Zone* zone) const = 0;
|
||||
virtual void WriteZoneDef(std::ostream& stream, const UnlinkerArgs& args, const Zone& zone) const = 0;
|
||||
|
||||
static const IZoneDefWriter* GetZoneDefWriterForGame(GameId game);
|
||||
};
|
||||
|
||||
class AbstractZoneDefWriter : public IZoneDefWriter
|
||||
{
|
||||
protected:
|
||||
static constexpr const char* META_DATA_KEY_GAME = "game";
|
||||
static constexpr const char* META_DATA_KEY_GDT = "gdt";
|
||||
static constexpr auto META_DATA_KEY_GAME = "game";
|
||||
static constexpr auto META_DATA_KEY_GDT = "gdt";
|
||||
|
||||
virtual void WriteMetaData(ZoneDefinitionOutputStream& stream, const UnlinkerArgs* args, Zone* zone) const = 0;
|
||||
virtual void WriteContent(ZoneDefinitionOutputStream& stream, const UnlinkerArgs* args, Zone* zone) const = 0;
|
||||
virtual void WriteMetaData(ZoneDefinitionOutputStream& stream, const UnlinkerArgs& args, const Zone& zone) const = 0;
|
||||
virtual void WriteContent(ZoneDefinitionOutputStream& stream, const UnlinkerArgs& args, const Zone& zone) const = 0;
|
||||
|
||||
public:
|
||||
void WriteZoneDef(std::ostream& stream, const UnlinkerArgs* args, Zone* zone) const override;
|
||||
void WriteZoneDef(std::ostream& stream, const UnlinkerArgs& args, const Zone& zone) const override;
|
||||
};
|
||||
|
Reference in New Issue
Block a user