summaryrefslogtreecommitdiff
path: root/ZAPD/ZTexture.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/ZTexture.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/ZTexture.cpp')
-rw-r--r--ZAPD/ZTexture.cpp43
1 files changed, 24 insertions, 19 deletions
diff --git a/ZAPD/ZTexture.cpp b/ZAPD/ZTexture.cpp
index f1629de..b47fd23 100644
--- a/ZAPD/ZTexture.cpp
+++ b/ZAPD/ZTexture.cpp
@@ -14,10 +14,15 @@ ZTexture::ZTexture(ZFile* nParent) : ZResource(nParent)
{
width = 0;
height = 0;
+
+ RegisterRequiredAttribute("Width");
+ RegisterRequiredAttribute("Height");
+ RegisterRequiredAttribute("Format");
+ RegisterOptionalAttribute("TlutOffset");
}
void ZTexture::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
- const uint32_t nRawDataIndex)
+ uint32_t nRawDataIndex)
{
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
@@ -65,41 +70,41 @@ void ZTexture::ParseXML(tinyxml2::XMLElement* reader)
{
ZResource::ParseXML(reader);
- if (reader->Attribute("Width") != nullptr)
- {
- width = atoi(reader->Attribute("Width"));
- }
- else
- {
- throw std::runtime_error("Width == nullptr for asset " +
- std::string(reader->Attribute("Name")));
- }
+ std::string widthXml = registeredAttributes.at("Width").value;
+ std::string heightXml = registeredAttributes.at("Height").value;
- if (reader->Attribute("Height") != nullptr)
+ if (!StringHelper::HasOnlyDigits(widthXml))
{
- height = atoi(reader->Attribute("Height"));
+ throw std::runtime_error(StringHelper::Sprintf(
+ "ZTexture::ParseXML: Error in %s\n"
+ "\t Value of 'Width' attribute has non-decimal digits: '%s'.\n",
+ name.c_str(), widthXml.c_str()));
}
- else
+ if (!StringHelper::HasOnlyDigits(heightXml))
{
- throw std::runtime_error("Height == nullptr for asset " +
- std::string(reader->Attribute("Name")));
+ throw std::runtime_error(StringHelper::Sprintf(
+ "ZTexture::ParseXML: Error in %s\n"
+ "\t Value of 'Height' attribute has non-decimal digits: '%s'.\n",
+ name.c_str(), heightXml.c_str()));
}
- std::string formatStr = reader->Attribute("Format");
+ width = StringHelper::StrToL(widthXml);
+ height = StringHelper::StrToL(heightXml);
+ std::string formatStr = registeredAttributes.at("Format").value;
format = GetTextureTypeFromString(formatStr);
if (format == TextureType::Error)
throw std::runtime_error("Format " + formatStr + " is not supported!");
- auto tlutOffsetXml = reader->Attribute("TlutOffset");
- if (tlutOffsetXml != nullptr)
+ const auto& tlutOffsetAttr = registeredAttributes.at("TlutOffset");
+ if (tlutOffsetAttr.wasSet)
{
switch (format)
{
case TextureType::Palette4bpp:
case TextureType::Palette8bpp:
- tlutOffset = StringHelper::StrToL(std::string(tlutOffsetXml), 16);
+ tlutOffset = StringHelper::StrToL(tlutOffsetAttr.value, 16);
break;
default: