mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-10 14:58:10 -05:00
ZoneWriting stuff
This commit is contained in:
@ -1,7 +1,179 @@
|
||||
#include "ZoneWriteTemplate.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "Internal/BaseTemplate.h"
|
||||
|
||||
class ZoneWriteTemplate::Internal final : BaseTemplate
|
||||
{
|
||||
enum class MemberWriteType
|
||||
{
|
||||
ARRAY_POINTER,
|
||||
DYNAMIC_ARRAY,
|
||||
EMBEDDED,
|
||||
EMBEDDED_ARRAY,
|
||||
POINTER_ARRAY,
|
||||
SINGLE_POINTER
|
||||
};
|
||||
|
||||
static std::string WriterClassName(StructureInformation* asset)
|
||||
{
|
||||
std::ostringstream str;
|
||||
str << "Writer_" << asset->m_definition->m_name;
|
||||
return str.str();
|
||||
}
|
||||
|
||||
void PrintHeaderConstructor() const
|
||||
{
|
||||
LINE(WriterClassName(m_env.m_asset) << "("<<m_env.m_asset->m_definition->GetFullName()<<"* asset, Zone* zone, IZoneOutputStream* stream);")
|
||||
}
|
||||
|
||||
void PrintHeaderMainWriteMethodDeclaration(const StructureInformation* info) const
|
||||
{
|
||||
LINE("void Write(" << info->m_definition->GetFullName() << "** pAsset);")
|
||||
}
|
||||
|
||||
void PrintHeaderGetNameMethodDeclaration(const StructureInformation* info) const
|
||||
{
|
||||
LINE("static std::string GetAssetName("<<info->m_definition->GetFullName()<<"* pAsset);")
|
||||
}
|
||||
|
||||
void PrintConstructorMethod()
|
||||
{
|
||||
LINE(WriterClassName(m_env.m_asset) << "::" << WriterClassName(m_env.m_asset) << "("<<m_env.m_asset->m_definition->GetFullName()<<"* asset, Zone* zone, IZoneOutputStream* stream)")
|
||||
|
||||
m_intendation++;
|
||||
LINE_START(": AssetWriter(zone->m_pools->GetAsset("<<m_env.m_asset->m_asset_enum_entry->m_name<<", GetAssetName(asset))"<<", zone, stream)")
|
||||
LINE_END("")
|
||||
m_intendation--;
|
||||
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
m_intendation--;
|
||||
LINE("}")
|
||||
}
|
||||
|
||||
void PrintMainWriteMethod()
|
||||
{
|
||||
LINE("void " << WriterClassName(m_env.m_asset) << "::Write(" << m_env.m_asset->m_definition->GetFullName() << "** pAsset)")
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
LINE("assert(pAsset != nullptr);")
|
||||
|
||||
m_intendation--;
|
||||
LINE("}")
|
||||
}
|
||||
|
||||
void PrintGetNameMethod()
|
||||
{
|
||||
LINE("std::string " << WriterClassName(m_env.m_asset) << "::GetAssetName(" << m_env.m_asset->m_definition->GetFullName() << "* pAsset)")
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
if (!m_env.m_asset->m_name_chain.empty())
|
||||
{
|
||||
LINE_START("return pAsset")
|
||||
|
||||
auto first = true;
|
||||
for (auto* member : m_env.m_asset->m_name_chain)
|
||||
{
|
||||
if (first)
|
||||
{
|
||||
first = false;
|
||||
LINE_MIDDLE("->" << member->m_member->m_name)
|
||||
}
|
||||
else
|
||||
{
|
||||
LINE_MIDDLE("." << member->m_member->m_name)
|
||||
}
|
||||
}
|
||||
LINE_END(";")
|
||||
}
|
||||
else
|
||||
{
|
||||
LINE("return \"" << m_env.m_asset->m_definition->m_name << "\";")
|
||||
}
|
||||
|
||||
m_intendation--;
|
||||
LINE("}")
|
||||
}
|
||||
|
||||
public:
|
||||
Internal(std::ostream& stream, RenderingContext* context)
|
||||
: BaseTemplate(stream, context)
|
||||
{
|
||||
}
|
||||
|
||||
void Header()
|
||||
{
|
||||
LINE("// ====================================================================")
|
||||
LINE("// This file has been generated by ZoneCodeGenerator.")
|
||||
LINE("// Do not modify. ")
|
||||
LINE("// Any changes will be discarded when regenerating.")
|
||||
LINE("// ====================================================================")
|
||||
LINE("")
|
||||
LINE("#pragma once")
|
||||
LINE("")
|
||||
LINE("#include \"Writing/AssetWriter.h\"")
|
||||
LINE("#include \"Game/" << m_env.m_game << "/" << m_env.m_game << ".h\"")
|
||||
LINE("#include <string>")
|
||||
LINE("")
|
||||
LINE("namespace " << m_env.m_game)
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
LINE("class " << WriterClassName(m_env.m_asset) << " final : public AssetWriter")
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
PrintHeaderGetNameMethodDeclaration(m_env.m_asset);
|
||||
LINE("")
|
||||
|
||||
m_intendation--;
|
||||
LINE("public:")
|
||||
m_intendation++;
|
||||
PrintHeaderConstructor();
|
||||
PrintHeaderMainWriteMethodDeclaration(m_env.m_asset);
|
||||
|
||||
m_intendation--;
|
||||
LINE("};")
|
||||
m_intendation--;
|
||||
LINE("}")
|
||||
}
|
||||
|
||||
void Source()
|
||||
{
|
||||
LINE("// ====================================================================")
|
||||
LINE("// This file has been generated by ZoneCodeGenerator.")
|
||||
LINE("// Do not modify. ")
|
||||
LINE("// Any changes will be discarded when regenerating.")
|
||||
LINE("// ====================================================================")
|
||||
LINE("")
|
||||
LINE("#include \"" << Lower(m_env.m_asset->m_definition->m_name) << "_write_db.h\"")
|
||||
LINE("#include <cassert>")
|
||||
LINE("")
|
||||
|
||||
if (!m_env.m_referenced_assets.empty())
|
||||
{
|
||||
LINE("// Referenced Assets:")
|
||||
for (auto* type : m_env.m_referenced_assets)
|
||||
{
|
||||
LINE("#include \"../" << Lower(type->m_type->m_name) << "/" << Lower(type->m_type->m_name) << "_write_db.h\"")
|
||||
}
|
||||
LINE("")
|
||||
}
|
||||
LINE("using namespace " << m_env.m_game << ";")
|
||||
LINE("")
|
||||
PrintConstructorMethod();
|
||||
LINE("")
|
||||
PrintMainWriteMethod();
|
||||
LINE("")
|
||||
PrintGetNameMethod();
|
||||
}
|
||||
};
|
||||
|
||||
std::vector<CodeTemplateFile> ZoneWriteTemplate::GetFilesToRender(RenderingContext* context)
|
||||
{
|
||||
std::vector<CodeTemplateFile> files;
|
||||
@ -27,4 +199,18 @@ std::vector<CodeTemplateFile> ZoneWriteTemplate::GetFilesToRender(RenderingConte
|
||||
|
||||
void ZoneWriteTemplate::RenderFile(std::ostream& stream, const int fileTag, RenderingContext* context)
|
||||
{
|
||||
Internal internal(stream, context);
|
||||
|
||||
if (fileTag == TAG_HEADER)
|
||||
{
|
||||
internal.Header();
|
||||
}
|
||||
else if (fileTag == TAG_SOURCE)
|
||||
{
|
||||
internal.Source();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Unknown tag for ZoneWriteTemplate: " << fileTag << "\n";
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ class ZoneWriteTemplate final : public ICodeTemplate
|
||||
static constexpr int TAG_HEADER = 1;
|
||||
static constexpr int TAG_SOURCE = 2;
|
||||
|
||||
class Internal;
|
||||
|
||||
public:
|
||||
std::vector<CodeTemplateFile> GetFilesToRender(RenderingContext* context) override;
|
||||
void RenderFile(std::ostream& stream, int fileTag, RenderingContext* context) override;
|
||||
|
Reference in New Issue
Block a user