From 4410b554e835ab7844c8eb78fd54fa3842d50f16 Mon Sep 17 00:00:00 2001 From: Anghelo Carvajal Date: Wed, 26 May 2021 20:04:02 -0400 Subject: Check XML resource attributes (#126) * register attibutes * fix array problems * cutscene problems * Set inner * fix merge * ups * Run format * small cleaning * A small blob cleanup * Simplify the logic a bit * ups * Fix merge problem * Fix merge issues * Fix merge issues * fix merge-produced type * Fix merge issues * run format and update easteregg * register ZPath attributes * dumb problems * How dumb can I be? * future proof change * empty commit * Check if Width and Height attributes of ZTexture has only decimal digits --- ZAPD/ZPath.cpp | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'ZAPD/ZPath.cpp') diff --git a/ZAPD/ZPath.cpp b/ZAPD/ZPath.cpp index 63970ae..39e06fb 100644 --- a/ZAPD/ZPath.cpp +++ b/ZAPD/ZPath.cpp @@ -10,6 +10,7 @@ REGISTER_ZFILENODE(Path, ZPath); ZPath::ZPath(ZFile* nParent) : ZResource(nParent) { numPaths = 1; + RegisterOptionalAttribute("NumPaths", "1"); } void ZPath::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, @@ -25,16 +26,13 @@ void ZPath::ParseXML(tinyxml2::XMLElement* reader) { ZResource::ParseXML(reader); - const char* numPathsXml = reader->Attribute("NumPaths"); - if (numPathsXml != nullptr) - { - numPaths = StringHelper::StrToL(std::string(numPathsXml)); - if (numPaths < 1) - throw std::runtime_error( - StringHelper::Sprintf("ZPath::ParseXML: Fatal error in '%s'.\n" - "\t Invalid value for attribute 'NumPaths': '%i'\n", - name.c_str(), numPaths)); - } + numPaths = StringHelper::StrToL(registeredAttributes.at("NumPaths").value); + + if (numPaths < 1) + throw std::runtime_error( + StringHelper::Sprintf("ZPath::ParseXML: Fatal error in '%s'.\n" + "\t Invalid value for attribute 'NumPaths': '%i'\n", + name.c_str(), numPaths)); } void ZPath::ParseRawData() @@ -72,7 +70,7 @@ std::string ZPath::GetBodySourceCode() const size_t index = 0; for (const auto& entry : pathways) { - declaration += entry.GetBodySourceCode(); + declaration += StringHelper::Sprintf("\t{ %s },", entry.GetBodySourceCode().c_str()); if (index < pathways.size() - 1) declaration += "\n"; @@ -102,6 +100,11 @@ std::string ZPath::GetSourceTypeName() const return "Path"; } +ZResourceType ZPath::GetResourceType() const +{ + return ZResourceType::Path; +} + size_t ZPath::GetRawDataSize() const { return pathways.size() * pathways.at(0).GetRawDataSize(); @@ -183,13 +186,23 @@ std::string PathwayEntry::GetBodySourceCode() const if (Globals::Instance->game == ZGame::MM_RETAIL) declaration += - StringHelper::Sprintf(" { %i, %i, %i, %s },", numPoints, unk1, unk2, listName.c_str()); + StringHelper::Sprintf("%i, %i, %i, %s", numPoints, unk1, unk2, listName.c_str()); else - declaration += StringHelper::Sprintf(" { %i, %s },", numPoints, listName.c_str()); + declaration += StringHelper::Sprintf("%i, %s", numPoints, listName.c_str()); return declaration; } +std::string PathwayEntry::GetSourceTypeName() const +{ + return "Path"; +} + +ZResourceType PathwayEntry::GetResourceType() const +{ + return ZResourceType::Path; +} + size_t PathwayEntry::GetRawDataSize() const { return 0x08; -- cgit v1.2.3