summaryrefslogtreecommitdiff
path: root/ZAPD/ZPath.cpp
diff options
context:
space:
mode:
authorAnghelo Carvajal <angheloalf95@gmail.com>2021-05-26 20:04:02 -0400
committerGitHub <noreply@github.com>2021-05-26 20:04:02 -0400
commit4410b554e835ab7844c8eb78fd54fa3842d50f16 (patch)
tree065b8f53d6e1052c9f7ad1917c1b3b66d5eef645 /ZAPD/ZPath.cpp
parent769f5702a422d14bfb0a60a39319da4b4bf9ec1f (diff)
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
Diffstat (limited to 'ZAPD/ZPath.cpp')
-rw-r--r--ZAPD/ZPath.cpp39
1 files changed, 26 insertions, 13 deletions
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<uint8_t>& 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;