Files
oot/tools/ZAPD/ZAPD/ZArray.cpp
T
Nicholas Estelami 0432011bd9 Updated to use latest version of ZAPD (#777)
* Updated config file

* Added missing files

* Temporarily removed asm_processor changes.

* git subrepo pull --force tools/ZAPD

subrepo:
  subdir:   "tools/ZAPD"
  merged:   "96ffc1e62"
upstream:
  origin:   "https://github.com/zeldaret/ZAPD.git"
  branch:   "master"
  commit:   "96ffc1e62"
git-subrepo:
  version:  "0.4.3"
  origin:   "???"
  commit:   "???"

* git subrepo pull --force tools/ZAPD

subrepo:
  subdir:   "tools/ZAPD"
  merged:   "179af7d11"
upstream:
  origin:   "https://github.com/zeldaret/ZAPD.git"
  branch:   "master"
  commit:   "179af7d11"
git-subrepo:
  version:  "0.4.3"
  origin:   "???"
  commit:   "???"

* Cleanup and fixes.

* git subrepo pull --force tools/ZAPD

subrepo:
  subdir:   "tools/ZAPD"
  merged:   "50ad2fe78"
upstream:
  origin:   "https://github.com/zeldaret/ZAPD.git"
  branch:   "master"
  commit:   "50ad2fe78"
git-subrepo:
  version:  "0.4.3"
  origin:   "???"
  commit:   "???"

* Makefile fix

* git subrepo pull --force tools/ZAPD

subrepo:
  subdir:   "tools/ZAPD"
  merged:   "b9120803e"
upstream:
  origin:   "https://github.com/zeldaret/ZAPD.git"
  branch:   "master"
  commit:   "b9120803e"
git-subrepo:
  version:  "0.4.3"
  origin:   "???"
  commit:   "???"

Co-authored-by: Jack Walker <7463599+Jack-Walker@users.noreply.github.com>
2021-04-30 23:23:22 +02:00

79 lines
2.1 KiB
C++

#include "ZArray.h"
#include "Globals.h"
#include "StringHelper.h"
#include "ZFile.h"
REGISTER_ZFILENODE(Array, ZArray);
ZArray::ZArray(ZFile* nParent) : ZResource(nParent)
{
canHaveInner = true;
}
ZArray::~ZArray()
{
delete testFile;
}
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(), "ZArray subfile", 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 std::runtime_error(
StringHelper::Sprintf("Error! Array needs at least one sub-element.\n"));
ZResource* res = testFile->resources[0];
size_t 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 (size_t i = 0; i < arrayCnt; i++)
{
size_t 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";
}
if (parent != nullptr)
parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(),
res->GetSourceTypeName(), name, arrayCnt, output);
return "";
}
size_t ZArray::GetRawDataSize()
{
return arrayCnt * testFile->resources[0]->GetRawDataSize();
}
void ZArray::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
const uint32_t nRawDataIndex, const std::string& nRelPath)
{
rawData = nRawData;
rawDataIndex = nRawDataIndex;
ParseXML(reader);
// arr->ParseRawData();
}