mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 16:15:43 +00:00
Dump StructuredDataDef enums
This commit is contained in:
parent
5c2f7de87d
commit
02769fe21d
@ -4,7 +4,9 @@
|
|||||||
|
|
||||||
StructuredDataDefDumper::StructuredDataDefDumper(std::ostream& stream)
|
StructuredDataDefDumper::StructuredDataDefDumper(std::ostream& stream)
|
||||||
: AbstractTextDumper(stream),
|
: AbstractTextDumper(stream),
|
||||||
m_flags{}
|
m_block(Block::BLOCK_NONE),
|
||||||
|
m_flags{},
|
||||||
|
m_enum_size(0u)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -16,15 +18,12 @@ void StructuredDataDefDumper::BeginVersion(const int version)
|
|||||||
|
|
||||||
if (m_flags.m_empty_line_before_version)
|
if (m_flags.m_empty_line_before_version)
|
||||||
m_stream << "\n";
|
m_stream << "\n";
|
||||||
else
|
|
||||||
m_flags.m_empty_line_before_version = true;
|
|
||||||
|
|
||||||
Indent();
|
Indent();
|
||||||
m_stream << "version " << version << "\n";
|
m_stream << "version " << version << "\n";
|
||||||
|
|
||||||
Indent();
|
Indent();
|
||||||
m_stream << "{\n";
|
m_stream << "{\n";
|
||||||
|
|
||||||
IncIndent();
|
IncIndent();
|
||||||
|
|
||||||
m_flags.m_in_version = true;
|
m_flags.m_in_version = true;
|
||||||
@ -40,4 +39,105 @@ void StructuredDataDefDumper::EndVersion()
|
|||||||
Indent();
|
Indent();
|
||||||
m_stream << "}\n";
|
m_stream << "}\n";
|
||||||
m_flags.m_in_version = false;
|
m_flags.m_in_version = false;
|
||||||
|
m_flags.m_empty_line_before_version = true;
|
||||||
|
m_flags.m_empty_line_before_block = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StructuredDataDefDumper::BeginEnum(const std::string& enumName, const size_t enumEntryCount)
|
||||||
|
{
|
||||||
|
assert(m_flags.m_in_version);
|
||||||
|
assert(m_block == Block::BLOCK_NONE);
|
||||||
|
|
||||||
|
if (m_block != Block::BLOCK_NONE)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (m_flags.m_empty_line_before_block)
|
||||||
|
m_stream << "\n";
|
||||||
|
|
||||||
|
Indent();
|
||||||
|
m_stream << "enum " << enumName << "\n";
|
||||||
|
|
||||||
|
Indent();
|
||||||
|
m_stream << "{\n";
|
||||||
|
IncIndent();
|
||||||
|
|
||||||
|
m_block = Block::BLOCK_ENUM;
|
||||||
|
|
||||||
|
m_enum_entries.resize(enumEntryCount);
|
||||||
|
m_enum_size = enumEntryCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StructuredDataDefDumper::EndEnum()
|
||||||
|
{
|
||||||
|
assert(m_block == Block::BLOCK_ENUM);
|
||||||
|
|
||||||
|
if (m_block != Block::BLOCK_ENUM)
|
||||||
|
return;
|
||||||
|
|
||||||
|
bool firstEntry = true;
|
||||||
|
for(const auto& entry : m_enum_entries)
|
||||||
|
{
|
||||||
|
if (firstEntry)
|
||||||
|
firstEntry = false;
|
||||||
|
else
|
||||||
|
m_stream << ",\n";
|
||||||
|
|
||||||
|
Indent();
|
||||||
|
m_stream << entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!firstEntry)
|
||||||
|
m_stream << "\n";
|
||||||
|
|
||||||
|
DecIndent();
|
||||||
|
Indent();
|
||||||
|
m_stream << "};\n";
|
||||||
|
m_block = Block::BLOCK_NONE;
|
||||||
|
m_flags.m_empty_line_before_block = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StructuredDataDefDumper::WriteEnumEntry(const std::string& entryName, const size_t entryValue)
|
||||||
|
{
|
||||||
|
assert(m_block == Block::BLOCK_ENUM);
|
||||||
|
assert(entryValue < m_enum_size);
|
||||||
|
|
||||||
|
if (m_block != Block::BLOCK_ENUM || entryValue >= m_enum_size)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_enum_entries[entryValue] = entryName;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StructuredDataDefDumper::BeginStruct(const std::string& structName)
|
||||||
|
{
|
||||||
|
assert(m_flags.m_in_version);
|
||||||
|
assert(m_block == Block::BLOCK_NONE);
|
||||||
|
|
||||||
|
if (m_block != Block::BLOCK_NONE)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (m_flags.m_empty_line_before_block)
|
||||||
|
m_stream << "\n";
|
||||||
|
|
||||||
|
Indent();
|
||||||
|
m_stream << "struct " << structName << "\n";
|
||||||
|
|
||||||
|
Indent();
|
||||||
|
m_stream << "{\n";
|
||||||
|
IncIndent();
|
||||||
|
|
||||||
|
m_block = Block::BLOCK_STRUCT;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StructuredDataDefDumper::EndStruct()
|
||||||
|
{
|
||||||
|
assert(m_block == Block::BLOCK_STRUCT);
|
||||||
|
|
||||||
|
if (m_block != Block::BLOCK_STRUCT)
|
||||||
|
return;
|
||||||
|
|
||||||
|
DecIndent();
|
||||||
|
Indent();
|
||||||
|
m_stream << "};\n";
|
||||||
|
m_block = Block::BLOCK_NONE;
|
||||||
|
m_flags.m_empty_line_before_block = true;
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,38 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "Dumping/AbstractTextDumper.h"
|
#include "Dumping/AbstractTextDumper.h"
|
||||||
|
|
||||||
class StructuredDataDefDumper : AbstractTextDumper
|
class StructuredDataDefDumper : AbstractTextDumper
|
||||||
{
|
{
|
||||||
|
enum class Block
|
||||||
|
{
|
||||||
|
BLOCK_NONE = 0,
|
||||||
|
BLOCK_ENUM = 1,
|
||||||
|
BLOCK_STRUCT = 2
|
||||||
|
} m_block;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
bool m_in_version : 1;
|
bool m_in_version : 1;
|
||||||
bool m_empty_line_before_version : 1;
|
bool m_empty_line_before_version : 1;
|
||||||
|
bool m_empty_line_before_block : 1;
|
||||||
} m_flags;
|
} m_flags;
|
||||||
|
|
||||||
|
std::vector<std::string> m_enum_entries;
|
||||||
|
size_t m_enum_size;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit StructuredDataDefDumper(std::ostream& stream);
|
explicit StructuredDataDefDumper(std::ostream& stream);
|
||||||
|
|
||||||
void BeginVersion(int version);
|
void BeginVersion(int version);
|
||||||
void EndVersion();
|
void EndVersion();
|
||||||
|
|
||||||
|
void BeginEnum(const std::string& enumName, size_t enumEntryCount);
|
||||||
|
void EndEnum();
|
||||||
|
void WriteEnumEntry(const std::string& entryName, size_t entryValue);
|
||||||
|
|
||||||
|
void BeginStruct(const std::string& structName);
|
||||||
|
void EndStruct();
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
#include "AssetDumperStructuredDataDefSet.h"
|
#include "AssetDumperStructuredDataDefSet.h"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include "Dumping/StructuredDataDef/StructuredDataDefDumper.h"
|
#include "Dumping/StructuredDataDef/StructuredDataDefDumper.h"
|
||||||
|
|
||||||
using namespace IW4;
|
using namespace IW4;
|
||||||
@ -9,6 +12,30 @@ bool AssetDumperStructuredDataDefSet::ShouldDump(XAssetInfo<StructuredDataDefSet
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AssetDumperStructuredDataDefSet::DumpEnum(StructuredDataDefDumper& dumper, const int enumIndex, const StructuredDataEnum* _enum)
|
||||||
|
{
|
||||||
|
if (!_enum->entries || _enum->entryCount <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::ostringstream ss;
|
||||||
|
ss << "ENUM_" << enumIndex;
|
||||||
|
|
||||||
|
dumper.BeginEnum(ss.str(), static_cast<size_t>(_enum->entryCount));
|
||||||
|
|
||||||
|
for(auto i = 0; i < _enum->entryCount; i++)
|
||||||
|
{
|
||||||
|
const auto& entry = _enum->entries[i];
|
||||||
|
|
||||||
|
assert(entry.string);
|
||||||
|
if(!entry.string)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
dumper.WriteEnumEntry(entry.string, entry.index);
|
||||||
|
}
|
||||||
|
|
||||||
|
dumper.EndEnum();
|
||||||
|
}
|
||||||
|
|
||||||
void AssetDumperStructuredDataDefSet::DumpAsset(AssetDumpingContext& context, XAssetInfo<StructuredDataDefSet>* asset)
|
void AssetDumperStructuredDataDefSet::DumpAsset(AssetDumpingContext& context, XAssetInfo<StructuredDataDefSet>* asset)
|
||||||
{
|
{
|
||||||
const auto* set = asset->Asset();
|
const auto* set = asset->Asset();
|
||||||
@ -25,6 +52,9 @@ void AssetDumperStructuredDataDefSet::DumpAsset(AssetDumpingContext& context, XA
|
|||||||
|
|
||||||
dumper.BeginVersion(def.version);
|
dumper.BeginVersion(def.version);
|
||||||
|
|
||||||
|
for (auto enumIndex = 0; enumIndex < def.enumCount; enumIndex++)
|
||||||
|
DumpEnum(dumper, enumIndex, &def.enums[enumIndex]);
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
|
|
||||||
dumper.EndVersion();
|
dumper.EndVersion();
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Dumping/AbstractAssetDumper.h"
|
#include "Dumping/AbstractAssetDumper.h"
|
||||||
|
#include "Dumping/StructuredDataDef/StructuredDataDefDumper.h"
|
||||||
#include "Game/IW4/IW4.h"
|
#include "Game/IW4/IW4.h"
|
||||||
|
|
||||||
namespace IW4
|
namespace IW4
|
||||||
{
|
{
|
||||||
class AssetDumperStructuredDataDefSet final : public AbstractAssetDumper<StructuredDataDefSet>
|
class AssetDumperStructuredDataDefSet final : public AbstractAssetDumper<StructuredDataDefSet>
|
||||||
{
|
{
|
||||||
|
static void DumpEnum(StructuredDataDefDumper& dumper, int enumIndex, const StructuredDataEnum* _enum);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool ShouldDump(XAssetInfo<StructuredDataDefSet>* asset) override;
|
bool ShouldDump(XAssetInfo<StructuredDataDefSet>* asset) override;
|
||||||
void DumpAsset(AssetDumpingContext& context, XAssetInfo<StructuredDataDefSet>* asset) override;
|
void DumpAsset(AssetDumpingContext& context, XAssetInfo<StructuredDataDefSet>* asset) override;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user