diff options
| author | Anghelo Carvajal <angheloalf95@gmail.com> | 2021-05-26 20:04:02 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-26 20:04:02 -0400 |
| commit | 4410b554e835ab7844c8eb78fd54fa3842d50f16 (patch) | |
| tree | 065b8f53d6e1052c9f7ad1917c1b3b66d5eef645 /ZAPD/ZResource.h | |
| parent | 769f5702a422d14bfb0a60a39319da4b4bf9ec1f (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/ZResource.h')
| -rw-r--r-- | ZAPD/ZResource.h | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/ZAPD/ZResource.h b/ZAPD/ZResource.h index 99d3dff..24f1f56 100644 --- a/ZAPD/ZResource.h +++ b/ZAPD/ZResource.h @@ -29,6 +29,7 @@ enum class ZResourceType { Error, Animation, + Array, Background, Blob, CollisionHeader, @@ -38,6 +39,7 @@ enum class ZResourceType Mtx, Path, Room, + RoomCommand, Scalar, Skeleton, String, @@ -47,6 +49,15 @@ enum class ZResourceType Vertex, }; +class ResourceAttribute +{ +public: + std::string key = ""; + std::string value = ""; + bool isRequired = false; + bool wasSet = false; +}; + class ZResource { public: @@ -55,7 +66,7 @@ public: uint32_t hash = 0; ZResource(ZFile* nParent); - virtual ~ZResource(); + virtual ~ZResource() = default; // Parsing from File virtual void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, @@ -66,6 +77,7 @@ public: virtual void ParseXML(tinyxml2::XMLElement* reader); virtual void ParseRawData(); virtual void DeclareReferences(const std::string& prefix); + virtual std::string GetBodySourceCode() const; virtual std::string GetSourceOutputCode(const std::string& prefix); virtual std::string GetSourceOutputHeader(const std::string& prefix); @@ -78,19 +90,20 @@ public: virtual bool IsExternalResource() const; virtual bool DoesSupportArray() const; // Can this type be wrapped in an <Array> node? virtual std::string GetSourceTypeName() const; - virtual ZResourceType GetResourceType() const; + virtual ZResourceType GetResourceType() const = 0; virtual std::string GetExternalExtension() const; // Getters/Setters - std::string GetName() const; - void SetName(std::string nName); + const std::string& GetName() const; + void SetName(const std::string& nName); const std::string& GetOutName() const; - void SetOutName(std::string nName); + void SetOutName(const std::string& nName); virtual uint32_t GetRawDataIndex() const; virtual void SetRawDataIndex(uint32_t value); - virtual size_t GetRawDataSize() const; + virtual size_t GetRawDataSize() const = 0; virtual const std::vector<uint8_t>& GetRawData() const; virtual void SetRawData(const std::vector<uint8_t>& nData); + void SetInnerNode(bool inner); bool WasDeclaredInXml() const; protected: @@ -99,10 +112,24 @@ protected: std::vector<uint8_t> rawData; uint32_t rawDataIndex; std::string sourceOutput; + bool isInner = false; // Is this resource an inner node of another resource? inside of <Array> bool canHaveInner = false; // Can this type have an inner node? bool isCustomAsset; // If set to true, create a reference for the asset in the file, but don't // actually try to extract it from the file bool declaredInXml = false; + + // Reading from this XMLs attributes should be performed in the overrided `ParseXML` method. + std::map<std::string, ResourceAttribute> registeredAttributes; + + // XML attributes registers. + // Registering XML attributes should be done in constructors. + + // The resource needs this attribute. If it is not provided, then the program will throw an + // exception. + void RegisterRequiredAttribute(const std::string& attr); + // Optional attribute. The resource has to do manual checks and manual warnings. It may or may + // not have a value. + void RegisterOptionalAttribute(const std::string& attr, const std::string& defaultValue = ""); }; uint32_t Seg2Filespace(segptr_t segmentedAddress, uint32_t parentBaseAddress); |
