diff options
| author | Anghelo Carvajal <angheloalf95@gmail.com> | 2021-10-16 18:55:56 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-16 17:55:56 -0400 |
| commit | e7a8a48cf361a7591b88592eb3e333ddf8d3ab34 (patch) | |
| tree | 4f63eac4c2136dd74e05593ea200b2c24c284a3f /ZAPD/GameConfig.cpp | |
| parent | 3e9ed72e202b1165152d42f7d160695f9f2f233a (diff) | |
`ExternalFile`: Expose other XML's declarations during extraction (#151)
* proof of concept
* fix header include paths
* GetDeclarationAlignment and others
* this should fix this
* minor
* DeclareVar in ExtractFromXML
* fix vtx intersections
* Fix segmented vtxs
* --version
* zcollision changes
* Use GetSegmentedPtrName a lot more
* memory related stuff
* minor style fixes and use the actual symbol for zlinkanimation instead of the hex address
* Simplify lots of GetSourceOutputCode
* ZSkeleton cleanup and other changes
* Elevate unknown types in skeleton to errors
* ZAnimation cleanup
* Add ExternalFile to config
* delete some code
* Remove unused code
* fix conflicts
* format
* remove redundant constructors
* minor fixes
* fix vtx warnings
* extract every vtx as standalone files
* format
* uups
* Bugfix: don't create extra blank files
* Fix some Vtx warnings and remove "defaulting to normal" in skeleton error
* Refactor ZLimb
* Make each limb to look up in every file for dlists
* Use GetSegmentedArrayIndexedName in VTX references in dlists
* simplify simple condition
* search by type
* run format
* Revert "search by type"
This reverts commit a049bdfc94c4ab04613b354f466dee836a20508a.
* Add range checks
* uups
* Always set rangeEnd
* special case zsymbol
* Revert "Revert "search by type""
This reverts commit 3f6e77c780bd30dc7000614304021a0940168316.
* symbol fix and IsOffsetInFileRange
* Bugfix and minor checks
* run format
* Don't extract data from external files
* Fix extraction of overly big tluts
* Minor changes
* More minor fixes
* Fix clang warnings
* Remove unused parameter
* Fix merge issues
* Fix ZLimbTable::DeclareVar
* Fix limbs not naming properly their DLists
* Remove segment number check
* Fix merge problems
* Run formatter
* Maybe fix?
* path
* empty commit
* Fix a typo
* Fix merge issues
* Fix null ptr dereferencing
* Fix merge issues and some clang warnings
* Format
* Fix not-matching
* Format
* Fix merge issues
* Fix exporter
* Last fixes I hope
* Fix merge issues
* format
* fix
* fix
* I'm dumb
* format
* static fix
* Whoops
* fix asan
* Fix?
* fix
* reduce artificial changes
* reduce artificial changes 2
* reorder more stuff
* format
* fix borken thing
* Remove redundant stuff in zfile
* fix
* Format
* Fix conflict issues
* format
* cleanup header includes
* format
* Add error checks in for ExternalXMLFolder
* format
Diffstat (limited to 'ZAPD/GameConfig.cpp')
| -rw-r--r-- | ZAPD/GameConfig.cpp | 74 |
1 files changed, 59 insertions, 15 deletions
diff --git a/ZAPD/GameConfig.cpp b/ZAPD/GameConfig.cpp index 69ce045..f197493 100644 --- a/ZAPD/GameConfig.cpp +++ b/ZAPD/GameConfig.cpp @@ -2,14 +2,27 @@ #include <functional> #include <string_view> + #include "Utils/Directory.h" #include "Utils/File.h" #include "Utils/Path.h" +#include "ZFile.h" #include "tinyxml2.h" using ConfigFunc = void (GameConfig::*)(const tinyxml2::XMLElement&); -void GameConfig::ReadTexturePool(const std::string& texturePoolXmlPath) +GameConfig::~GameConfig() +{ + for (auto& declPair : segmentRefFiles) + { + for (auto& file : declPair.second) + { + delete file; + } + } +} + +void GameConfig::ReadTexturePool(const fs::path& texturePoolXmlPath) { tinyxml2::XMLDocument doc; tinyxml2::XMLError eResult = doc.LoadFile(texturePoolXmlPath.c_str()); @@ -41,7 +54,7 @@ void GameConfig::ReadTexturePool(const std::string& texturePoolXmlPath) } } -void GameConfig::GenSymbolMap(const std::string& symbolMapPath) +void GameConfig::GenSymbolMap(const fs::path& symbolMapPath) { auto symbolLines = File::ReadAllLines(symbolMapPath); @@ -58,21 +71,14 @@ void GameConfig::GenSymbolMap(const std::string& symbolMapPath) void GameConfig::ConfigFunc_SymbolMap(const tinyxml2::XMLElement& element) { std::string fileName = element.Attribute("File"); - GenSymbolMap(Path::GetDirectoryName(configFilePath) + "/" + fileName); -} - -void GameConfig::ConfigFunc_Segment(const tinyxml2::XMLElement& element) -{ - std::string fileName = element.Attribute("File"); - int32_t segNumber = element.IntAttribute("Number"); - segmentRefs[segNumber] = std::move(fileName); + GenSymbolMap(Path::GetDirectoryName(configFilePath) / fileName); } void GameConfig::ConfigFunc_ActorList(const tinyxml2::XMLElement& element) { std::string fileName = element.Attribute("File"); std::vector<std::string> lines = - File::ReadAllLines(Path::GetDirectoryName(configFilePath) + "/" + fileName); + File::ReadAllLines(Path::GetDirectoryName(configFilePath) / fileName); for (auto& line : lines) actorList.emplace_back(std::move(line)); @@ -82,7 +88,7 @@ void GameConfig::ConfigFunc_ObjectList(const tinyxml2::XMLElement& element) { std::string fileName = element.Attribute("File"); std::vector<std::string> lines = - File::ReadAllLines(Path::GetDirectoryName(configFilePath) + "/" + fileName); + File::ReadAllLines(Path::GetDirectoryName(configFilePath) / fileName); for (auto& line : lines) objectList.emplace_back(std::move(line)); @@ -91,7 +97,7 @@ void GameConfig::ConfigFunc_ObjectList(const tinyxml2::XMLElement& element) void GameConfig::ConfigFunc_TexturePool(const tinyxml2::XMLElement& element) { std::string fileName = element.Attribute("File"); - ReadTexturePool(Path::GetDirectoryName(configFilePath) + "/" + fileName); + ReadTexturePool(Path::GetDirectoryName(configFilePath) / fileName); } void GameConfig::ConfigFunc_BGConfig(const tinyxml2::XMLElement& element) @@ -100,15 +106,53 @@ void GameConfig::ConfigFunc_BGConfig(const tinyxml2::XMLElement& element) bgScreenHeight = element.IntAttribute("ScreenHeight", 240); } -void GameConfig::ReadConfigFile(const std::string& argConfigFilePath) +void GameConfig::ConfigFunc_ExternalXMLFolder(const tinyxml2::XMLElement& element) +{ + const char* pathValue = element.Attribute("Path"); + if (pathValue == nullptr) + { + throw std::runtime_error( + StringHelper::Sprintf("Parse: Fatal error in configuration file.\n" + "\t Missing 'Path' attribute in `ExternalXMLFolder` element.\n")); + } + if (externalXmlFolder != "") + { + throw std::runtime_error(StringHelper::Sprintf("Parse: Fatal error in configuration file.\n" + "\t `ExternalXMLFolder` is duplicated.\n")); + } + externalXmlFolder = pathValue; +} + +void GameConfig::ConfigFunc_ExternalFile(const tinyxml2::XMLElement& element) +{ + const char* xmlPathValue = element.Attribute("XmlPath"); + if (xmlPathValue == nullptr) + { + throw std::runtime_error( + StringHelper::Sprintf("Parse: Fatal error in configuration file.\n" + "\t Missing 'XmlPath' attribute in `ExternalFile` element.\n")); + } + const char* outPathValue = element.Attribute("OutPath"); + if (outPathValue == nullptr) + { + throw std::runtime_error( + StringHelper::Sprintf("Parse: Fatal error in configuration file.\n" + "\t Missing 'OutPath' attribute in `ExternalFile` element.\n")); + } + + externalFiles.push_back(ExternalFile(fs::path(xmlPathValue), fs::path(outPathValue))); +} + +void GameConfig::ReadConfigFile(const fs::path& argConfigFilePath) { static const std::map<std::string, ConfigFunc> ConfigFuncDictionary = { {"SymbolMap", &GameConfig::ConfigFunc_SymbolMap}, - {"Segment", &GameConfig::ConfigFunc_Segment}, {"ActorList", &GameConfig::ConfigFunc_ActorList}, {"ObjectList", &GameConfig::ConfigFunc_ObjectList}, {"TexturePool", &GameConfig::ConfigFunc_TexturePool}, {"BGConfig", &GameConfig::ConfigFunc_BGConfig}, + {"ExternalXMLFolder", &GameConfig::ConfigFunc_ExternalXMLFolder}, + {"ExternalFile", &GameConfig::ConfigFunc_ExternalFile}, }; configFilePath = argConfigFilePath; |
