diff options
| author | Ethan Roseman <ethteck@gmail.com> | 2021-03-18 16:40:58 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-18 16:40:58 +0900 |
| commit | dc55bcdbc8b03318072edfe6c13d839b0c57638c (patch) | |
| tree | 273c99a7599c947f01d0753f822d56b567d7a495 /ZAPD/ZArray.cpp | |
| parent | 4d0d6cf32e194c03ad7755bc34a68f05cf189f6b (diff) | |
| parent | 5e95bed8fd98fe0967d4c6808199d681ec5079e5 (diff) | |
Merge branch 'master' into new-jenkins-agent
Diffstat (limited to 'ZAPD/ZArray.cpp')
| -rw-r--r-- | ZAPD/ZArray.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/ZAPD/ZArray.cpp b/ZAPD/ZArray.cpp new file mode 100644 index 0000000..4be7656 --- /dev/null +++ b/ZAPD/ZArray.cpp @@ -0,0 +1,73 @@ +#include "ZArray.h" +#include "ZFile.h" +#include "Globals.h" +#include "StringHelper.h" + +ZArray::ZArray() +{ + +} + +void ZArray::ParseXML(tinyxml2::XMLElement* reader) +{ + ZResource::ParseXML(reader); + + arrayCnt = reader->IntAttribute("Count", 0); + testFile = new ZFile(ZFileMode::Extract, reader, Globals::Instance->baseRomPath, "", parent->GetName(), true); +} + +// TODO: This is a bit hacky, but until we refactor how ZFile parses the XML, it'll have to do. +std::string ZArray::GetSourceOutputCode(const std::string& prefix) +{ + std::string output = ""; + + if (testFile->resources.size() <= 0) + { + throw StringHelper::Sprintf("Error! Array needs at least one sub-element.\n"); + } + + ZResource* res = testFile->resources[0]; + int resSize = res->GetRawDataSize(); + + if (!res->DoesSupportArray()) + { + throw std::runtime_error(StringHelper::Sprintf("Error! Resource %s does not support being wrapped in an array!\n", res->GetName().c_str())); + } + + for (int i = 0; i < arrayCnt; i++) + { + int childIndex = rawDataIndex + (i * resSize); + res->SetRawDataIndex(childIndex); + res->ParseRawData(); + std::string test = res->GetSourceOutputCode(""); + //output += " { " + testFile->declarations[childIndex]->text + " }"; + output += testFile->declarations[childIndex]->text; + + if (i < arrayCnt - 1) + output += ",\n"; + + int bp = 0; + } + + if (parent != nullptr) + parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(), res->GetSourceTypeName(), name, arrayCnt, output); + + return ""; +} + +int ZArray::GetRawDataSize() +{ + return arrayCnt * testFile->resources[0]->GetRawDataSize(); +} + +ZArray* ZArray::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, const int rawDataIndex, const std::string& nRelPath, ZFile* nParent) +{ + ZArray* arr = new ZArray(); + arr->rawData = nRawData; + arr->rawDataIndex = rawDataIndex; + arr->parent = nParent; + arr->ParseXML(reader); + //arr->ParseRawData(); + + return arr; +} |
