summaryrefslogtreecommitdiff
path: root/ZAPD/ZArray.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ZAPD/ZArray.cpp')
-rw-r--r--ZAPD/ZArray.cpp68
1 files changed, 53 insertions, 15 deletions
diff --git a/ZAPD/ZArray.cpp b/ZAPD/ZArray.cpp
index f46ee8d..9c562f0 100644
--- a/ZAPD/ZArray.cpp
+++ b/ZAPD/ZArray.cpp
@@ -1,5 +1,7 @@
#include "ZArray.h"
+
#include <cassert>
+
#include "Globals.h"
#include "Utils/StringHelper.h"
#include "ZFile.h"
@@ -53,30 +55,56 @@ void ZArray::ParseXML(tinyxml2::XMLElement* reader)
}
}
-std::string ZArray::GetSourceOutputCode([[maybe_unused]] const std::string& prefix)
+Declaration* ZArray::DeclareVar(const std::string& prefix, const std::string& bodyStr)
{
- std::string output = "";
+ std::string auxName = name;
- for (size_t i = 0; i < arrayCnt; i++)
- {
- output += resList.at(i)->GetBodySourceCode();
- output += ",";
+ if (name == "")
+ auxName = GetDefaultName(prefix);
- if (i < arrayCnt - 1)
- output += "\n";
+ ZResource* res = resList.at(0);
+ Declaration* decl;
+ if (res->IsExternalResource())
+ {
+ auto filepath = Globals::Instance->outputPath / name;
+ std::string includePath = StringHelper::Sprintf("%s.%s.inc", filepath.c_str(),
+ res->GetExternalExtension().c_str());
+ decl = parent->AddDeclarationIncludeArray(rawDataIndex, includePath, GetRawDataSize(),
+ GetSourceTypeName(), name, arrayCnt);
+ decl->text = bodyStr;
+ decl->isExternal = true;
+ }
+ else
+ {
+ decl =
+ parent->AddDeclarationArray(rawDataIndex, GetDeclarationAlignment(), GetRawDataSize(),
+ GetSourceTypeName(), name, arrayCnt, bodyStr);
}
- Declaration* decl =
- parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::Align4, GetRawDataSize(),
- resList.at(0)->GetSourceTypeName(), name, arrayCnt, output);
decl->staticConf = staticConf;
-
- return "";
+ return decl;
}
-std::string ZArray::GetSourceTypeName() const
+std::string ZArray::GetBodySourceCode() const
{
- return resList.at(0)->GetSourceTypeName();
+ std::string output = "";
+
+ for (size_t i = 0; i < arrayCnt; i++)
+ {
+ const auto& res = resList[i];
+ output += "\t";
+
+ if (res->GetResourceType() == ZResourceType::Scalar ||
+ res->GetResourceType() == ZResourceType::Vertex)
+ output += resList.at(i)->GetBodySourceCode();
+ else
+ output += StringHelper::Sprintf("{ %s }", resList.at(i)->GetBodySourceCode().c_str());
+
+ if (i < arrayCnt - 1 || res->IsExternalResource())
+ output += ",\n";
+ }
+
+ return output;
}
size_t ZArray::GetRawDataSize() const
@@ -87,7 +115,17 @@ size_t ZArray::GetRawDataSize() const
return size;
}
+std::string ZArray::GetSourceTypeName() const
+{
+ return resList.at(0)->GetSourceTypeName();
+}
+
ZResourceType ZArray::GetResourceType() const
{
return ZResourceType::Array;
}
+
+DeclarationAlignment ZArray::GetDeclarationAlignment() const
+{
+ return resList.at(0)->GetDeclarationAlignment();
+}