summaryrefslogtreecommitdiff
path: root/ZAPD/ZMtx.cpp
diff options
context:
space:
mode:
authorAnghelo Carvajal <angheloalf95@gmail.com>2021-04-02 20:36:44 -0300
committerGitHub <noreply@github.com>2021-04-02 19:36:44 -0400
commit19c2ea3d474de1b74781417f4b58782396c0aa50 (patch)
treeb731567ddb3bf73279626c2ce9b91ab9e6786288 /ZAPD/ZMtx.cpp
parent65146cf747468a336401dcf7552322aba4d7c038 (diff)
Add Mtx extraction (#105)
* ZMtx resource Signed-off-by: Angie <angheloalf95@gmail.com> * remove extra braces Signed-off-by: Angie <angheloalf95@gmail.com> * make dlist extracts mtx Signed-off-by: Angie <angheloalf95@gmail.com> * run format Signed-off-by: angie <angheloalf95@gmail.com>
Diffstat (limited to 'ZAPD/ZMtx.cpp')
-rw-r--r--ZAPD/ZMtx.cpp113
1 files changed, 113 insertions, 0 deletions
diff --git a/ZAPD/ZMtx.cpp b/ZAPD/ZMtx.cpp
new file mode 100644
index 0000000..423b880
--- /dev/null
+++ b/ZAPD/ZMtx.cpp
@@ -0,0 +1,113 @@
+#include "ZMtx.h"
+#include "BitConverter.h"
+#include "StringHelper.h"
+#include "ZFile.h"
+
+ZMtx::ZMtx(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, int nRawDataIndex,
+ ZFile* nParent)
+{
+ rawData.assign(nRawData.begin(), nRawData.end());
+ rawDataIndex = nRawDataIndex;
+ parent = nParent;
+
+ ParseXML(reader);
+ ParseRawData();
+}
+
+ZMtx::ZMtx(const std::string& prefix, const std::vector<uint8_t>& nRawData, int nRawDataIndex,
+ ZFile* nParent)
+{
+ rawData.assign(nRawData.begin(), nRawData.end());
+ rawDataIndex = nRawDataIndex;
+ parent = nParent;
+
+ name = GetDefaultName(prefix.c_str(), rawDataIndex);
+
+ ParseRawData();
+}
+
+void ZMtx::ParseRawData()
+{
+ ZResource::ParseRawData();
+
+ for (size_t i = 0; i < 4; ++i)
+ {
+ for (size_t j = 0; j < 4; ++j)
+ {
+ mtx[i][j] = BitConverter::ToInt32BE(rawData, rawDataIndex + (i * 4 + j) * 4);
+ }
+ }
+}
+
+ZMtx* ZMtx::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
+ int nRawDataIndex, ZFile* nParent)
+{
+ ZMtx* mtx = new ZMtx(reader, nRawData, nRawDataIndex, nParent);
+
+ mtx->DeclareVar("", "");
+
+ return mtx;
+}
+
+int ZMtx::GetRawDataSize()
+{
+ return 64;
+}
+
+void ZMtx::DeclareVar(const std::string& prefix, const std::string& bodyStr)
+{
+ std::string auxName = name;
+ if (name == "")
+ {
+ auxName = GetDefaultName(prefix, rawDataIndex);
+ }
+ parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align8, GetRawDataSize(),
+ GetSourceTypeName(), auxName, bodyStr);
+}
+
+std::string ZMtx::GetBodySourceCode()
+{
+ std::string bodyStr = "\n";
+ for (const auto& row : mtx)
+ {
+ bodyStr += " ";
+ for (int32_t val : row)
+ {
+ bodyStr += StringHelper::Sprintf("%-11i, ", val);
+ }
+ bodyStr += "\n";
+ }
+ return bodyStr;
+}
+
+std::string ZMtx::GetSourceOutputCode(const std::string& prefix)
+{
+ std::string bodyStr = GetBodySourceCode();
+
+ Declaration* decl = parent->GetDeclaration(rawDataIndex);
+ if (decl == nullptr)
+ {
+ DeclareVar(prefix, bodyStr);
+ }
+ else
+ {
+ decl->text = bodyStr;
+ }
+
+ return "";
+}
+
+std::string ZMtx::GetDefaultName(const std::string& prefix, uint32_t address)
+{
+ return StringHelper::Sprintf("%sMtx_%06X", prefix.c_str(), address);
+}
+
+std::string ZMtx::GetSourceTypeName()
+{
+ return "Mtx";
+}
+
+ZResourceType ZMtx::GetResourceType()
+{
+ return ZResourceType::Mtx;
+}