diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index c9cb36130..f90a2f4f4 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -329,6 +329,7 @@ OTRGlobals::OTRGlobals() { loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Animation", static_cast(SOH::ResourceType::SOH_Animation), 0); loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "PlayerAnimation", static_cast(SOH::ResourceType::SOH_PlayerAnimation), 0); loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Room", static_cast(SOH::ResourceType::SOH_Room), 0); // Is room scene? maybe? + loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_XML, "Room", static_cast(SOH::ResourceType::SOH_Room), 0); // Is room scene? maybe? loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "CollisionHeader", static_cast(SOH::ResourceType::SOH_CollisionHeader), 0); loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_XML, "CollisionHeader", static_cast(SOH::ResourceType::SOH_CollisionHeader), 0); loader->RegisterResourceFactory(std::make_shared(), RESOURCE_FORMAT_BINARY, "Skeleton", static_cast(SOH::ResourceType::SOH_Skeleton), 0); diff --git a/soh/soh/resource/importer/SceneFactory.cpp b/soh/soh/resource/importer/SceneFactory.cpp index 679d574cb..c537cb312 100644 --- a/soh/soh/resource/importer/SceneFactory.cpp +++ b/soh/soh/resource/importer/SceneFactory.cpp @@ -105,4 +105,127 @@ std::shared_ptr ResourceFactoryBinarySceneV0::ReadResource(std:: return scene; }; + +ResourceFactoryXMLSceneV0::ResourceFactoryXMLSceneV0() { + sceneCommandFactories[SceneCommandID::SetLightingSettings] = std::make_shared(); + sceneCommandFactories[SceneCommandID::SetWind] = std::make_shared(); + sceneCommandFactories[SceneCommandID::SetExitList] = std::make_shared(); + sceneCommandFactories[SceneCommandID::SetTimeSettings] = std::make_shared(); + sceneCommandFactories[SceneCommandID::SetSkyboxModifier] = std::make_shared(); + sceneCommandFactories[SceneCommandID::SetEchoSettings] = std::make_shared(); + sceneCommandFactories[SceneCommandID::SetSoundSettings] = std::make_shared(); + sceneCommandFactories[SceneCommandID::SetSkyboxSettings] = std::make_shared(); + sceneCommandFactories[SceneCommandID::SetRoomBehavior] = std::make_shared(); + sceneCommandFactories[SceneCommandID::SetCsCamera] = std::make_shared(); + sceneCommandFactories[SceneCommandID::SetCameraSettings] = std::make_shared(); + sceneCommandFactories[SceneCommandID::SetRoomList] = std::make_shared(); + sceneCommandFactories[SceneCommandID::SetCollisionHeader] = std::make_shared(); + sceneCommandFactories[SceneCommandID::SetEntranceList] = std::make_shared(); + sceneCommandFactories[SceneCommandID::SetSpecialObjects] = std::make_shared(); + sceneCommandFactories[SceneCommandID::SetObjectList] = std::make_shared(); + sceneCommandFactories[SceneCommandID::SetStartPositionList] = std::make_shared(); + sceneCommandFactories[SceneCommandID::SetActorList] = std::make_shared(); + sceneCommandFactories[SceneCommandID::SetTransitionActorList] = std::make_shared(); + sceneCommandFactories[SceneCommandID::EndMarker] = std::make_shared(); + sceneCommandFactories[SceneCommandID::SetAlternateHeaders] = std::make_shared(); + sceneCommandFactories[SceneCommandID::SetPathways] = std::make_shared(); + sceneCommandFactories[SceneCommandID::SetCutscenes] = std::make_shared(); + sceneCommandFactories[SceneCommandID::SetLightList] = std::make_shared(); + sceneCommandFactories[SceneCommandID::SetMesh] = std::make_shared(); +} + +std::vector commandNames = { + "SetStartPositionList", + "SetActorList", + "SetCsCamera", + "SetCollisionHeader", + "SetRoomList", + "SetWind", + "SetEntranceList", + "SetSpecialObjects", + "SetRoomBehavior", + "Unused09", + "SetMesh", + "SetObjectList", + "SetLightList", + "SetPathways", + "SetTransitionActorList", + "SetLightingSettings", + "SetTimeSettings", + "SetSkyboxSettings", + "SetSkyboxModifier", + "SetExitList", + "EndMarker", + "SetSoundSettings", + "SetEchoSettings", + "SetCutscenes", + "SetAlternateHeaders", + "SetCameraSettings", +}; + +SceneCommandID GetCommandID(std::string commandName) { + for (int i = 0; i < commandNames.size(); i++) { + if (commandNames[i] == commandName) { + return (SceneCommandID)i; + } + } + + return SceneCommandID::Error; +} + +void ResourceFactoryXMLSceneV0::ParseSceneCommands(std::shared_ptr scene, std::shared_ptr reader) { + auto child = reader->RootElement()->FirstChildElement(); + + int i = 0; + + while (child != nullptr) { + scene->commands.push_back(ParseSceneCommand(scene, child, i)); + + child = child->NextSiblingElement(); + i += 1; + } +} + +std::shared_ptr ResourceFactoryXMLSceneV0::ParseSceneCommand(std::shared_ptr scene, + tinyxml2::XMLElement* child, uint32_t index) { + std::string commandName = child->Name(); + SceneCommandID cmdID = GetCommandID(commandName); + + if (cmdID == SceneCommandID::Error) { + SPDLOG_ERROR("Failed to load scene command with name {} in scene {}", commandName, scene->GetInitData()->Path); + return nullptr; + } + + std::shared_ptr result = nullptr; + auto commandFactory = ResourceFactoryXMLSceneV0::sceneCommandFactories[cmdID]; + + if (commandFactory != nullptr) { + auto initData = std::make_shared(); + initData->Id = scene->GetInitData()->Id; + initData->Type = static_cast(ResourceType::SOH_SceneCommand); + initData->Path = scene->GetInitData()->Path + "/SceneCommand" + std::to_string(index); + initData->ResourceVersion = scene->GetInitData()->ResourceVersion; + result = std::static_pointer_cast(commandFactory->ReadResource(initData, child)); + // Cache the resource? + } + + if (result == nullptr) { + SPDLOG_ERROR("Failed to load scene command of type {} in scene {}", (uint32_t)cmdID, scene->GetInitData()->Path); + } + + return result; +} + +std::shared_ptr ResourceFactoryXMLSceneV0::ReadResource(std::shared_ptr file) { + if (!FileHasValidFormatAndReader(file)) { + return nullptr; + } + + auto scene = std::make_shared(file->InitData); + auto reader = std::get>(file->Reader); + + ParseSceneCommands(scene, reader); + + return scene; +}; } // namespace SOH diff --git a/soh/soh/resource/importer/SceneFactory.h b/soh/soh/resource/importer/SceneFactory.h index 5dfed2739..a1b345f7d 100644 --- a/soh/soh/resource/importer/SceneFactory.h +++ b/soh/soh/resource/importer/SceneFactory.h @@ -5,6 +5,7 @@ #include "soh/resource/importer/scenecommand/SceneCommandFactory.h" #include "Resource.h" #include "ResourceFactoryBinary.h" +#include "ResourceFactoryXML.h" namespace SOH { class ResourceFactoryBinarySceneV0 : public LUS::ResourceFactoryBinary { @@ -22,4 +23,20 @@ class ResourceFactoryBinarySceneV0 : public LUS::ResourceFactoryBinary { protected: std::shared_ptr ParseSceneCommand(std::shared_ptr scene, std::shared_ptr reader, uint32_t index); }; + +class ResourceFactoryXMLSceneV0 : public LUS::ResourceFactoryXML { + public: + ResourceFactoryXMLSceneV0(); + + std::shared_ptr ReadResource(std::shared_ptr file) override; + void ParseSceneCommands(std::shared_ptr scene, std::shared_ptr reader); + + // Doing something very similar to what we do on the ResourceLoader. + // Eventually, scene commands should be moved up to the ResourceLoader as well. + // They can not right now because the exporter does not give them a proper resource type enum value, + // and the exporter does not export the commands with a proper OTR header. + static inline std::unordered_map> sceneCommandFactories; +protected: + std::shared_ptr ParseSceneCommand(std::shared_ptr scene, tinyxml2::XMLElement* child, uint32_t index); +}; } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/EndMarkerFactory.cpp b/soh/soh/resource/importer/scenecommand/EndMarkerFactory.cpp index ffcf17410..a1d671349 100644 --- a/soh/soh/resource/importer/scenecommand/EndMarkerFactory.cpp +++ b/soh/soh/resource/importer/scenecommand/EndMarkerFactory.cpp @@ -9,6 +9,30 @@ EndMarkerFactory::ReadResource(std::shared_ptr initData, ReadCommandId(endMarker, reader); + //LogEndMarkerAsXML(endMarker); + return endMarker; } + +std::shared_ptr EndMarkerFactoryXML::ReadResource(std::shared_ptr initData, + tinyxml2::XMLElement* reader) { + auto endMarker = std::make_shared(initData); + + endMarker->cmdId = SceneCommandID::EndMarker; + + return endMarker; +} + +void LogEndMarkerAsXML(std::shared_ptr resource) { + std::shared_ptr endMarker = std::static_pointer_cast(resource); + + tinyxml2::XMLDocument doc; + tinyxml2::XMLElement* root = doc.NewElement("EndMarker"); + doc.InsertFirstChild(root); + + tinyxml2::XMLPrinter printer; + doc.Accept(&printer); + + SPDLOG_INFO("{}: {}", resource->GetInitData()->Path, printer.CStr()); +} } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/EndMarkerFactory.h b/soh/soh/resource/importer/scenecommand/EndMarkerFactory.h index 486aaa2fb..6481f5025 100644 --- a/soh/soh/resource/importer/scenecommand/EndMarkerFactory.h +++ b/soh/soh/resource/importer/scenecommand/EndMarkerFactory.h @@ -7,4 +7,12 @@ class EndMarkerFactory : public SceneCommandFactoryBinaryV0 { public: std::shared_ptr ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; }; + +class EndMarkerFactoryXML : public SceneCommandFactoryXMLV0 { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, tinyxml2::XMLElement* reader) override; +}; + +void LogEndMarkerAsXML(std::shared_ptr resource); } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SceneCommandFactory.h b/soh/soh/resource/importer/scenecommand/SceneCommandFactory.h index 4cebc4a64..15c3a8ade 100644 --- a/soh/soh/resource/importer/scenecommand/SceneCommandFactory.h +++ b/soh/soh/resource/importer/scenecommand/SceneCommandFactory.h @@ -13,4 +13,12 @@ class SceneCommandFactoryBinaryV0 { protected: void ReadCommandId(std::shared_ptr command, std::shared_ptr reader); }; + +class SceneCommandFactoryXMLV0 { + public: + virtual std::shared_ptr ReadResource(std::shared_ptr initData, tinyxml2::XMLElement* reader) = 0; + + protected: + void ReadCommandId(std::shared_ptr command, tinyxml2::XMLElement* reader); +}; } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetActorListFactory.cpp b/soh/soh/resource/importer/scenecommand/SetActorListFactory.cpp index 86deea193..ab9c142d8 100644 --- a/soh/soh/resource/importer/scenecommand/SetActorListFactory.cpp +++ b/soh/soh/resource/importer/scenecommand/SetActorListFactory.cpp @@ -26,6 +26,65 @@ SetActorListFactory::ReadResource(std::shared_ptr initDat setActorList->actorList.push_back(entry); } + //LogActorListAsXML(setActorList); + return setActorList; } + +std::shared_ptr SetActorListFactoryXML::ReadResource(std::shared_ptr initData, + tinyxml2::XMLElement* reader) { + auto setActorList = std::make_shared(initData); + + setActorList->cmdId = SceneCommandID::SetActorList; + + auto child = reader->FirstChildElement(); + + while (child != nullptr) { + std::string childName = child->Name(); + if (childName == "ActorEntry") { + ActorEntry entry; + entry.id = child->IntAttribute("Id"); + entry.pos.x = child->IntAttribute("PosX"); + entry.pos.y = child->IntAttribute("PosY"); + entry.pos.z = child->IntAttribute("PosZ"); + entry.rot.x = child->IntAttribute("RotX"); + entry.rot.y = child->IntAttribute("RotY"); + entry.rot.z = child->IntAttribute("RotZ"); + entry.params = child->IntAttribute("Params"); + setActorList->actorList.push_back(entry); + } + + child = child->NextSiblingElement(); + } + + setActorList->numActors = setActorList->actorList.size(); + + return setActorList; +} + +void LogActorListAsXML(std::shared_ptr resource) { + std::shared_ptr setActorList = std::static_pointer_cast(resource); + + tinyxml2::XMLDocument doc; + tinyxml2::XMLElement* root = doc.NewElement("SetActorList"); + doc.InsertFirstChild(root); + + for (size_t i = 0; i < setActorList->numActors; i++) { + tinyxml2::XMLElement* entry = doc.NewElement("ActorEntry"); + entry->SetAttribute("Id", setActorList->actorList[i].id); + entry->SetAttribute("PosX", setActorList->actorList[i].pos.x); + entry->SetAttribute("PosY", setActorList->actorList[i].pos.y); + entry->SetAttribute("PosZ", setActorList->actorList[i].pos.z); + entry->SetAttribute("RotX", setActorList->actorList[i].rot.x); + entry->SetAttribute("RotY", setActorList->actorList[i].rot.y); + entry->SetAttribute("RotZ", setActorList->actorList[i].rot.z); + entry->SetAttribute("Params", setActorList->actorList[i].params); + root->InsertEndChild(entry); + } + + tinyxml2::XMLPrinter printer; + doc.Accept(&printer); + + SPDLOG_INFO("{}: {}", resource->GetInitData()->Path, printer.CStr()); +} } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetActorListFactory.h b/soh/soh/resource/importer/scenecommand/SetActorListFactory.h index 49a269cfe..c2ff18653 100644 --- a/soh/soh/resource/importer/scenecommand/SetActorListFactory.h +++ b/soh/soh/resource/importer/scenecommand/SetActorListFactory.h @@ -8,4 +8,12 @@ class SetActorListFactory : public SceneCommandFactoryBinaryV0 { std::shared_ptr ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; }; + +class SetActorListFactoryXML : public SceneCommandFactoryXMLV0 { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, tinyxml2::XMLElement* reader) override; +}; + +void LogActorListAsXML(std::shared_ptr resource); } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetAlternateHeadersFactory.cpp b/soh/soh/resource/importer/scenecommand/SetAlternateHeadersFactory.cpp index 833d0af8c..9f741f5e0 100644 --- a/soh/soh/resource/importer/scenecommand/SetAlternateHeadersFactory.cpp +++ b/soh/soh/resource/importer/scenecommand/SetAlternateHeadersFactory.cpp @@ -21,6 +21,50 @@ std::shared_ptr SetAlternateHeadersFactory::ReadResource(std::sh } } + //LogAlternateHeadersAsXML(setAlternateHeaders); + return setAlternateHeaders; } + +std::shared_ptr SetAlternateHeadersFactoryXML::ReadResource(std::shared_ptr initData, + tinyxml2::XMLElement* reader) { + auto setAlternateHeaders = std::make_shared(initData); + + setAlternateHeaders->cmdId = SceneCommandID::SetAlternateHeaders; + + auto child = reader->FirstChildElement(); + + while (child != nullptr) { + std::string childName = child->Name(); + if (childName == "AlternateHeader") { + for (uint32_t i = 0; i < setAlternateHeaders->numHeaders; i++) { + auto headerName = std::string(child->Attribute("HeaderName")); + if (!headerName.empty()) { + setAlternateHeaders->headers.push_back(std::static_pointer_cast(LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(headerName.c_str()))); + } else { + setAlternateHeaders->headers.push_back(nullptr); + } + } + } + + child = child->NextSiblingElement(); + } + + setAlternateHeaders->numHeaders = setAlternateHeaders->headers.size(); + + return setAlternateHeaders; +} + +void LogAlternateHeadersAsXML(std::shared_ptr resource) { + std::shared_ptr setAlternateHeaders = std::static_pointer_cast(resource); + + tinyxml2::XMLDocument doc; + tinyxml2::XMLElement* root = doc.NewElement("SetAlternateHeaders"); + doc.InsertFirstChild(root); + + tinyxml2::XMLPrinter printer; + doc.Accept(&printer); + + SPDLOG_INFO("{}: {}", resource->GetInitData()->Path, printer.CStr()); +} } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetAlternateHeadersFactory.h b/soh/soh/resource/importer/scenecommand/SetAlternateHeadersFactory.h index 2bc430c0b..84e730905 100644 --- a/soh/soh/resource/importer/scenecommand/SetAlternateHeadersFactory.h +++ b/soh/soh/resource/importer/scenecommand/SetAlternateHeadersFactory.h @@ -8,4 +8,10 @@ class SetAlternateHeadersFactory : public SceneCommandFactoryBinaryV0 { std::shared_ptr ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; }; + +class SetAlternateHeadersFactoryXML : public SceneCommandFactoryXMLV0 { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, tinyxml2::XMLElement* reader) override; +}; } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetCameraSettingsFactory.cpp b/soh/soh/resource/importer/scenecommand/SetCameraSettingsFactory.cpp index 7e2911a17..98648751c 100644 --- a/soh/soh/resource/importer/scenecommand/SetCameraSettingsFactory.cpp +++ b/soh/soh/resource/importer/scenecommand/SetCameraSettingsFactory.cpp @@ -12,6 +12,36 @@ std::shared_ptr SetCameraSettingsFactory::ReadResource(std::shar setCameraSettings->settings.cameraMovement = reader->ReadInt8(); setCameraSettings->settings.worldMapArea = reader->ReadInt32(); + //LogCameraSettingsAsXML(setCameraSettings); + return setCameraSettings; } + +std::shared_ptr SetCameraSettingsFactoryXML::ReadResource(std::shared_ptr initData, + tinyxml2::XMLElement* reader) { + auto setCameraSettings = std::make_shared(initData); + + setCameraSettings->cmdId = SceneCommandID::SetCameraSettings; + + setCameraSettings->settings.cameraMovement = reader->IntAttribute("CameraMovement"); + setCameraSettings->settings.worldMapArea = reader->IntAttribute("WorldMapArea"); + + return setCameraSettings; +} + +void LogCameraSettingsAsXML(std::shared_ptr resource) { + std::shared_ptr setCameraSettings = std::static_pointer_cast(resource); + + tinyxml2::XMLDocument doc; + tinyxml2::XMLElement* root = doc.NewElement("SetCameraSettings"); + doc.InsertFirstChild(root); + + root->SetAttribute("CameraMovement", setCameraSettings->settings.cameraMovement); + root->SetAttribute("WorldMapArea", setCameraSettings->settings.worldMapArea); + + tinyxml2::XMLPrinter printer; + doc.Accept(&printer); + + SPDLOG_INFO("{}: {}", resource->GetInitData()->Path, printer.CStr()); +} } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetCameraSettingsFactory.h b/soh/soh/resource/importer/scenecommand/SetCameraSettingsFactory.h index 2f1db272f..263c23444 100644 --- a/soh/soh/resource/importer/scenecommand/SetCameraSettingsFactory.h +++ b/soh/soh/resource/importer/scenecommand/SetCameraSettingsFactory.h @@ -8,4 +8,12 @@ class SetCameraSettingsFactory : public SceneCommandFactoryBinaryV0 { std::shared_ptr ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; }; + +class SetCameraSettingsFactoryXML : public SceneCommandFactoryXMLV0 { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, tinyxml2::XMLElement* reader) override; +}; + +void LogCameraSettingsAsXML(std::shared_ptr resource); } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetCollisionHeaderFactory.cpp b/soh/soh/resource/importer/scenecommand/SetCollisionHeaderFactory.cpp index bb83dc57b..502e3b020 100644 --- a/soh/soh/resource/importer/scenecommand/SetCollisionHeaderFactory.cpp +++ b/soh/soh/resource/importer/scenecommand/SetCollisionHeaderFactory.cpp @@ -13,6 +13,35 @@ std::shared_ptr SetCollisionHeaderFactory::ReadResource(std::sha setCollisionHeader->fileName = reader->ReadString(); setCollisionHeader->collisionHeader = std::static_pointer_cast(LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(setCollisionHeader->fileName.c_str())); + //LogSetCollisionHeaderAsXML(setCollisionHeader); + return setCollisionHeader; } + +std::shared_ptr SetCollisionHeaderFactoryXML::ReadResource(std::shared_ptr initData, + tinyxml2::XMLElement* reader) { + auto setCollisionHeader = std::make_shared(initData); + + setCollisionHeader->cmdId = SceneCommandID::SetCollisionHeader; + + setCollisionHeader->fileName = reader->Attribute("FileName"); + setCollisionHeader->collisionHeader = std::static_pointer_cast(LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(setCollisionHeader->fileName.c_str())); + + return setCollisionHeader; +} + +void LogSetCollisionHeaderAsXML(std::shared_ptr resource) { + std::shared_ptr setCollisionHeader = std::static_pointer_cast(resource); + + tinyxml2::XMLDocument doc; + tinyxml2::XMLElement* root = doc.NewElement("SetCollisionHeader"); + doc.InsertFirstChild(root); + + root->SetAttribute("FileName", setCollisionHeader->fileName.c_str()); + + tinyxml2::XMLPrinter printer; + doc.Accept(&printer); + + SPDLOG_INFO("{}: {}", resource->GetInitData()->Path, printer.CStr()); +} } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetCollisionHeaderFactory.h b/soh/soh/resource/importer/scenecommand/SetCollisionHeaderFactory.h index b80ee34b4..2f04c8ffe 100644 --- a/soh/soh/resource/importer/scenecommand/SetCollisionHeaderFactory.h +++ b/soh/soh/resource/importer/scenecommand/SetCollisionHeaderFactory.h @@ -8,4 +8,12 @@ class SetCollisionHeaderFactory : public SceneCommandFactoryBinaryV0 { std::shared_ptr ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; }; + +class SetCollisionHeaderFactoryXML : public SceneCommandFactoryXMLV0 { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, tinyxml2::XMLElement* reader) override; +}; + +void LogSetCollisionHeaderAsXML(std::shared_ptr resource); } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetCsCameraFactory.cpp b/soh/soh/resource/importer/scenecommand/SetCsCameraFactory.cpp index 84c277989..52b1d0fd7 100644 --- a/soh/soh/resource/importer/scenecommand/SetCsCameraFactory.cpp +++ b/soh/soh/resource/importer/scenecommand/SetCsCameraFactory.cpp @@ -14,6 +14,30 @@ SetCsCameraFactory::ReadResource(std::shared_ptr initData // OTRTODO: FINISH! + //LogCsCameraAsXML(setCsCamera); + return setCsCamera; } + +std::shared_ptr SetCsCameraFactoryXML::ReadResource(std::shared_ptr initData, + tinyxml2::XMLElement* reader) { + auto setCsCamera = std::make_shared(initData); + + setCsCamera->cmdId = SceneCommandID::SetCsCamera; + + return setCsCamera; +} + +void LogCsCameraAsXML(std::shared_ptr resource) { + std::shared_ptr setCsCamera = std::static_pointer_cast(resource); + + tinyxml2::XMLDocument doc; + tinyxml2::XMLElement* root = doc.NewElement("SetCsCamera"); + doc.InsertFirstChild(root); + + tinyxml2::XMLPrinter printer; + doc.Accept(&printer); + + SPDLOG_INFO("{}: {}", resource->GetInitData()->Path, printer.CStr()); +} } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetCsCameraFactory.h b/soh/soh/resource/importer/scenecommand/SetCsCameraFactory.h index 08dc8e3c3..4bfccea19 100644 --- a/soh/soh/resource/importer/scenecommand/SetCsCameraFactory.h +++ b/soh/soh/resource/importer/scenecommand/SetCsCameraFactory.h @@ -8,4 +8,12 @@ class SetCsCameraFactory : public SceneCommandFactoryBinaryV0 { std::shared_ptr ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; }; + +class SetCsCameraFactoryXML : public SceneCommandFactoryXMLV0 { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, tinyxml2::XMLElement* reader) override; +}; + +void LogCsCameraAsXML(std::shared_ptr resource); } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetCutscenesFactory.cpp b/soh/soh/resource/importer/scenecommand/SetCutscenesFactory.cpp index 30f72d168..e6330fc28 100644 --- a/soh/soh/resource/importer/scenecommand/SetCutscenesFactory.cpp +++ b/soh/soh/resource/importer/scenecommand/SetCutscenesFactory.cpp @@ -13,6 +13,35 @@ SetCutscenesFactory::ReadResource(std::shared_ptr initDat setCutscenes->fileName = reader->ReadString(); setCutscenes->cutscene = std::static_pointer_cast(LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(setCutscenes->fileName.c_str())); + //LogCutscenesAsXML(setCutscenes); + return setCutscenes; } + +std::shared_ptr SetCutscenesFactoryXML::ReadResource(std::shared_ptr initData, + tinyxml2::XMLElement* reader) { + auto setCutscenes = std::make_shared(initData); + + setCutscenes->cmdId = SceneCommandID::SetCutscenes; + + setCutscenes->fileName = reader->Attribute("FileName"); + setCutscenes->cutscene = std::static_pointer_cast(LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(setCutscenes->fileName.c_str())); + + return setCutscenes; +} + +void LogCutscenesAsXML(std::shared_ptr resource) { + std::shared_ptr setCutscenes = std::static_pointer_cast(resource); + + tinyxml2::XMLDocument doc; + tinyxml2::XMLElement* root = doc.NewElement("SetCutscenes"); + doc.InsertFirstChild(root); + + root->SetAttribute("FileName", setCutscenes->fileName.c_str()); + + tinyxml2::XMLPrinter printer; + doc.Accept(&printer); + + SPDLOG_INFO("{}: {}", resource->GetInitData()->Path, printer.CStr()); +} } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetCutscenesFactory.h b/soh/soh/resource/importer/scenecommand/SetCutscenesFactory.h index bbbe38c98..56541c095 100644 --- a/soh/soh/resource/importer/scenecommand/SetCutscenesFactory.h +++ b/soh/soh/resource/importer/scenecommand/SetCutscenesFactory.h @@ -8,4 +8,12 @@ class SetCutscenesFactory : public SceneCommandFactoryBinaryV0 { std::shared_ptr ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; }; + +class SetCutscenesFactoryXML : public SceneCommandFactoryXMLV0 { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, tinyxml2::XMLElement* reader) override; +}; + +void LogCutscenesAsXML(std::shared_ptr resource); } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetEchoSettingsFactory.cpp b/soh/soh/resource/importer/scenecommand/SetEchoSettingsFactory.cpp index e9c3381cb..ea7fdc09a 100644 --- a/soh/soh/resource/importer/scenecommand/SetEchoSettingsFactory.cpp +++ b/soh/soh/resource/importer/scenecommand/SetEchoSettingsFactory.cpp @@ -11,6 +11,34 @@ SetEchoSettingsFactory::ReadResource(std::shared_ptr init setEchoSettings->settings.echo = reader->ReadInt8(); + //LogEchoSettingsAsXML(setEchoSettings); + return setEchoSettings; } + +std::shared_ptr SetEchoSettingsFactoryXML::ReadResource(std::shared_ptr initData, + tinyxml2::XMLElement* reader) { + auto setEchoSettings = std::make_shared(initData); + + setEchoSettings->cmdId = SceneCommandID::SetEchoSettings; + + setEchoSettings->settings.echo = reader->IntAttribute("Echo"); + + return setEchoSettings; +} + +void LogEchoSettingsAsXML(std::shared_ptr resource) { + std::shared_ptr setEchoSettings = std::static_pointer_cast(resource); + + tinyxml2::XMLDocument doc; + tinyxml2::XMLElement* root = doc.NewElement("SetEchoSettings"); + doc.InsertFirstChild(root); + + root->SetAttribute("Echo", setEchoSettings->settings.echo); + + tinyxml2::XMLPrinter printer; + doc.Accept(&printer); + + SPDLOG_INFO("{}: {}", resource->GetInitData()->Path, printer.CStr()); +} } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetEchoSettingsFactory.h b/soh/soh/resource/importer/scenecommand/SetEchoSettingsFactory.h index 99bda6eae..e3c381c7a 100644 --- a/soh/soh/resource/importer/scenecommand/SetEchoSettingsFactory.h +++ b/soh/soh/resource/importer/scenecommand/SetEchoSettingsFactory.h @@ -8,4 +8,12 @@ class SetEchoSettingsFactory : public SceneCommandFactoryBinaryV0 { std::shared_ptr ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; }; + +class SetEchoSettingsFactoryXML : public SceneCommandFactoryXMLV0 { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, tinyxml2::XMLElement* reader) override; +}; + +void LogEchoSettingsAsXML(std::shared_ptr resource); } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetEntranceListFactory.cpp b/soh/soh/resource/importer/scenecommand/SetEntranceListFactory.cpp index 766bb82da..8444d21d5 100644 --- a/soh/soh/resource/importer/scenecommand/SetEntranceListFactory.cpp +++ b/soh/soh/resource/importer/scenecommand/SetEntranceListFactory.cpp @@ -20,6 +20,53 @@ SetEntranceListFactory::ReadResource(std::shared_ptr init setEntranceList->entrances.push_back(entranceEntry); } + //LogEntranceListAsXML(setEntranceList); + return setEntranceList; } + +std::shared_ptr SetEntranceListFactoryXML::ReadResource(std::shared_ptr initData, + tinyxml2::XMLElement* reader) { + auto setEntranceList = std::make_shared(initData); + + setEntranceList->cmdId = SceneCommandID::SetEntranceList; + + auto child = reader->FirstChildElement(); + + while (child != nullptr) { + std::string childName = child->Name(); + if (childName == "EntranceEntry") { + EntranceEntry entry; + entry.spawn = child->IntAttribute("Spawn"); + entry.room = child->IntAttribute("Room"); + setEntranceList->entrances.push_back(entry); + } + + child = child->NextSiblingElement(); + } + + setEntranceList->numEntrances = setEntranceList->entrances.size(); + + return setEntranceList; +} + +void LogEntranceListAsXML(std::shared_ptr resource) { + std::shared_ptr setEntranceList = std::static_pointer_cast(resource); + + tinyxml2::XMLDocument doc; + tinyxml2::XMLElement* root = doc.NewElement("SetEntranceList"); + doc.InsertFirstChild(root); + + for (size_t i = 0; i < setEntranceList->numEntrances; i++) { + tinyxml2::XMLElement* entry = doc.NewElement("EntranceEntry"); + entry->SetAttribute("Spawn", setEntranceList->entrances[i].spawn); + entry->SetAttribute("Room", setEntranceList->entrances[i].room); + root->InsertEndChild(entry); + } + + tinyxml2::XMLPrinter printer; + doc.Accept(&printer); + + SPDLOG_INFO("{}: {}", resource->GetInitData()->Path, printer.CStr()); +} } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetEntranceListFactory.h b/soh/soh/resource/importer/scenecommand/SetEntranceListFactory.h index 35b7fba62..dc76d7239 100644 --- a/soh/soh/resource/importer/scenecommand/SetEntranceListFactory.h +++ b/soh/soh/resource/importer/scenecommand/SetEntranceListFactory.h @@ -8,4 +8,12 @@ class SetEntranceListFactory : public SceneCommandFactoryBinaryV0 { std::shared_ptr ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; }; + +class SetEntranceListFactoryXML : public SceneCommandFactoryXMLV0 { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, tinyxml2::XMLElement* reader) override; +}; + +void LogEntranceListAsXML(std::shared_ptr resource); } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetExitListFactory.cpp b/soh/soh/resource/importer/scenecommand/SetExitListFactory.cpp index 5fef9d096..e84054e1b 100644 --- a/soh/soh/resource/importer/scenecommand/SetExitListFactory.cpp +++ b/soh/soh/resource/importer/scenecommand/SetExitListFactory.cpp @@ -15,6 +15,49 @@ SetExitListFactory::ReadResource(std::shared_ptr initData setExitList->exits.push_back(reader->ReadUInt16()); } + //LogExitListAsXML(setExitList); + return setExitList; } + +std::shared_ptr SetExitListFactoryXML::ReadResource(std::shared_ptr initData, + tinyxml2::XMLElement* reader) { + auto setExitList = std::make_shared(initData); + + setExitList->cmdId = SceneCommandID::SetExitList; + + auto child = reader->FirstChildElement(); + + while (child != nullptr) { + std::string childName = child->Name(); + if (childName == "ExitEntry") { + setExitList->exits.push_back(child->IntAttribute("Id")); + } + + child = child->NextSiblingElement(); + } + + setExitList->numExits = setExitList->exits.size(); + + return setExitList; +} + +void LogExitListAsXML(std::shared_ptr resource) { + std::shared_ptr setExitList = std::static_pointer_cast(resource); + + tinyxml2::XMLDocument doc; + tinyxml2::XMLElement* root = doc.NewElement("SetExitList"); + doc.InsertFirstChild(root); + + for (size_t i = 0; i < setExitList->numExits; i++) { + tinyxml2::XMLElement* entry = doc.NewElement("ExitEntry"); + entry->SetAttribute("Id", setExitList->exits[i]); + root->InsertEndChild(entry); + } + + tinyxml2::XMLPrinter printer; + doc.Accept(&printer); + + SPDLOG_INFO("{}: {}", resource->GetInitData()->Path, printer.CStr()); +} } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetExitListFactory.h b/soh/soh/resource/importer/scenecommand/SetExitListFactory.h index d82e8f04a..b38f140a8 100644 --- a/soh/soh/resource/importer/scenecommand/SetExitListFactory.h +++ b/soh/soh/resource/importer/scenecommand/SetExitListFactory.h @@ -8,4 +8,12 @@ class SetExitListFactory : public SceneCommandFactoryBinaryV0 { std::shared_ptr ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; }; + +class SetExitListFactoryXML : public SceneCommandFactoryXMLV0 { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, tinyxml2::XMLElement* reader) override; +}; + +void LogExitListAsXML(std::shared_ptr resource); } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetLightListFactory.cpp b/soh/soh/resource/importer/scenecommand/SetLightListFactory.cpp index 2d05631cd..658b09042 100644 --- a/soh/soh/resource/importer/scenecommand/SetLightListFactory.cpp +++ b/soh/soh/resource/importer/scenecommand/SetLightListFactory.cpp @@ -30,6 +30,85 @@ SetLightListFactory::ReadResource(std::shared_ptr initDat setLightList->lightList.push_back(light); } + //LogLightListAsXML(setLightList); + return setLightList; } + +std::shared_ptr SetLightListFactoryXML::ReadResource(std::shared_ptr initData, + tinyxml2::XMLElement* reader) { + auto setLightList = std::make_shared(initData); + + setLightList->cmdId = SceneCommandID::SetLightList; + + auto child = reader->FirstChildElement(); + + while (child != nullptr) { + std::string childName = child->Name(); + if (childName == "LightInfo") { + LightInfo light; + light.type = child->IntAttribute("Type"); + if (false/*light.type == LIGHT_DIRECTIONAL*/) { + light.params.dir.x = child->IntAttribute("X"); + light.params.dir.y = child->IntAttribute("Y"); + light.params.dir.z = child->IntAttribute("Z"); + light.params.dir.color[0] = child->IntAttribute("ColorR"); + light.params.dir.color[1] = child->IntAttribute("ColorG"); + light.params.dir.color[2] = child->IntAttribute("ColorB"); + } else { + light.params.point.x = child->IntAttribute("X"); + light.params.point.y = child->IntAttribute("Y"); + light.params.point.z = child->IntAttribute("Z"); + light.params.point.color[0] = child->IntAttribute("ColorR"); + light.params.point.color[1] = child->IntAttribute("ColorG"); + light.params.point.color[2] = child->IntAttribute("ColorB"); + light.params.point.drawGlow = child->IntAttribute("DrawGlow"); + light.params.point.radius = child->IntAttribute("Radius"); + } + setLightList->lightList.push_back(light); + } + + child = child->NextSiblingElement(); + } + + setLightList->numLights = setLightList->lightList.size(); + + return setLightList; +} + +void LogLightListAsXML(std::shared_ptr resource) { + std::shared_ptr setLightList = std::static_pointer_cast(resource); + + tinyxml2::XMLDocument doc; + tinyxml2::XMLElement* root = doc.NewElement("SetLightList"); + doc.InsertFirstChild(root); + + for (size_t i = 0; i < setLightList->numLights; i++) { + tinyxml2::XMLElement* light = doc.NewElement("LightInfo"); + light->SetAttribute("Type", setLightList->lightList[i].type); + if (false/*setLightList->lightList[i].type == LIGHT_DIRECTIONAL*/) { + light->SetAttribute("X", setLightList->lightList[i].params.dir.x); + light->SetAttribute("Y", setLightList->lightList[i].params.dir.y); + light->SetAttribute("Z", setLightList->lightList[i].params.dir.z); + light->SetAttribute("ColorR", setLightList->lightList[i].params.dir.color[0]); + light->SetAttribute("ColorG", setLightList->lightList[i].params.dir.color[1]); + light->SetAttribute("ColorB", setLightList->lightList[i].params.dir.color[2]); + } else { + light->SetAttribute("X", setLightList->lightList[i].params.point.x); + light->SetAttribute("Y", setLightList->lightList[i].params.point.y); + light->SetAttribute("Z", setLightList->lightList[i].params.point.z); + light->SetAttribute("ColorR", setLightList->lightList[i].params.point.color[0]); + light->SetAttribute("ColorG", setLightList->lightList[i].params.point.color[1]); + light->SetAttribute("ColorB", setLightList->lightList[i].params.point.color[2]); + light->SetAttribute("DrawGlow", setLightList->lightList[i].params.point.drawGlow); + light->SetAttribute("Radius", setLightList->lightList[i].params.point.radius); + } + root->InsertEndChild(light); + } + + tinyxml2::XMLPrinter printer; + doc.Accept(&printer); + + SPDLOG_INFO("{}: {}", resource->GetInitData()->Path, printer.CStr()); +} } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetLightListFactory.h b/soh/soh/resource/importer/scenecommand/SetLightListFactory.h index 1c4a6e9dc..d1d6073c2 100644 --- a/soh/soh/resource/importer/scenecommand/SetLightListFactory.h +++ b/soh/soh/resource/importer/scenecommand/SetLightListFactory.h @@ -8,4 +8,12 @@ class SetLightListFactory : public SceneCommandFactoryBinaryV0 { std::shared_ptr ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; }; + +class SetLightListFactoryXML : public SceneCommandFactoryXMLV0 { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, tinyxml2::XMLElement* reader) override; +}; + +void LogLightListAsXML(std::shared_ptr resource); } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetLightingSettingsFactory.cpp b/soh/soh/resource/importer/scenecommand/SetLightingSettingsFactory.cpp index d0a7b89d5..9c576a9df 100644 --- a/soh/soh/resource/importer/scenecommand/SetLightingSettingsFactory.cpp +++ b/soh/soh/resource/importer/scenecommand/SetLightingSettingsFactory.cpp @@ -43,6 +43,94 @@ std::shared_ptr SetLightingSettingsFactory::ReadResource(std::sh setLightingSettings->settings.push_back(lightSettings); } + //LogLightingSettingsAsXML(setLightingSettings); + return setLightingSettings; } + +std::shared_ptr SetLightingSettingsFactoryXML::ReadResource(std::shared_ptr initData, + tinyxml2::XMLElement* reader) { + auto setLightingSettings = std::make_shared(initData); + + setLightingSettings->cmdId = SceneCommandID::SetLightingSettings; + + auto child = reader->FirstChildElement(); + + while (child != nullptr) { + std::string childName = child->Name(); + if (childName == "LightingSetting") { + EnvLightSettings lightSettings; + lightSettings.ambientColor[0] = child->IntAttribute("AmbientColorR"); + lightSettings.ambientColor[1] = child->IntAttribute("AmbientColorG"); + lightSettings.ambientColor[2] = child->IntAttribute("AmbientColorB"); + + lightSettings.light1Dir[0] = child->IntAttribute("Light1DirX"); + lightSettings.light1Dir[1] = child->IntAttribute("Light1DirY"); + lightSettings.light1Dir[2] = child->IntAttribute("Light1DirZ"); + lightSettings.light1Color[0] = child->IntAttribute("Light1ColorR"); + lightSettings.light1Color[1] = child->IntAttribute("Light1ColorG"); + lightSettings.light1Color[2] = child->IntAttribute("Light1ColorB"); + + lightSettings.light2Dir[0] = child->IntAttribute("Light2DirX"); + lightSettings.light2Dir[1] = child->IntAttribute("Light2DirY"); + lightSettings.light2Dir[2] = child->IntAttribute("Light2DirZ"); + lightSettings.light2Color[0] = child->IntAttribute("Light2ColorR"); + lightSettings.light2Color[1] = child->IntAttribute("Light2ColorG"); + lightSettings.light2Color[2] = child->IntAttribute("Light2ColorB"); + + lightSettings.fogColor[0] = child->IntAttribute("FogColorR"); + lightSettings.fogColor[1] = child->IntAttribute("FogColorG"); + lightSettings.fogColor[2] = child->IntAttribute("FogColorB"); + lightSettings.fogNear = child->IntAttribute("FogNear"); + lightSettings.fogFar = child->IntAttribute("FogFar"); + setLightingSettings->settings.push_back(lightSettings); + } + + child = child->NextSiblingElement(); + } + + return setLightingSettings; +} + +void LogLightingSettingsAsXML(std::shared_ptr resource) { + std::shared_ptr setLightingSettings = std::static_pointer_cast(resource); + + tinyxml2::XMLDocument doc; + tinyxml2::XMLElement* root = doc.NewElement("SetLightingSettings"); + doc.InsertFirstChild(root); + + for (size_t i = 0; i < setLightingSettings->settings.size(); i++) { + tinyxml2::XMLElement* entry = doc.NewElement("LightingSetting"); + entry->SetAttribute("AmbientColorR", setLightingSettings->settings[i].ambientColor[0]); + entry->SetAttribute("AmbientColorG", setLightingSettings->settings[i].ambientColor[1]); + entry->SetAttribute("AmbientColorB", setLightingSettings->settings[i].ambientColor[2]); + + entry->SetAttribute("Light1DirX", setLightingSettings->settings[i].light1Dir[0]); + entry->SetAttribute("Light1DirY", setLightingSettings->settings[i].light1Dir[1]); + entry->SetAttribute("Light1DirZ", setLightingSettings->settings[i].light1Dir[2]); + entry->SetAttribute("Light1ColorR", setLightingSettings->settings[i].light1Color[0]); + entry->SetAttribute("Light1ColorG", setLightingSettings->settings[i].light1Color[1]); + entry->SetAttribute("Light1ColorB", setLightingSettings->settings[i].light1Color[2]); + + entry->SetAttribute("Light2DirX", setLightingSettings->settings[i].light2Dir[0]); + entry->SetAttribute("Light2DirY", setLightingSettings->settings[i].light2Dir[1]); + entry->SetAttribute("Light2DirZ", setLightingSettings->settings[i].light2Dir[2]); + entry->SetAttribute("Light2ColorR", setLightingSettings->settings[i].light2Color[0]); + entry->SetAttribute("Light2ColorG", setLightingSettings->settings[i].light2Color[1]); + entry->SetAttribute("Light2ColorB", setLightingSettings->settings[i].light2Color[2]); + + entry->SetAttribute("FogColorR", setLightingSettings->settings[i].fogColor[0]); + entry->SetAttribute("FogColorG", setLightingSettings->settings[i].fogColor[1]); + entry->SetAttribute("FogColorB", setLightingSettings->settings[i].fogColor[2]); + entry->SetAttribute("FogNear", setLightingSettings->settings[i].fogNear); + entry->SetAttribute("FogFar", setLightingSettings->settings[i].fogFar); + + root->InsertEndChild(entry); + } + + tinyxml2::XMLPrinter printer; + doc.Accept(&printer); + + SPDLOG_INFO("{}: {}", resource->GetInitData()->Path, printer.CStr()); +} } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetLightingSettingsFactory.h b/soh/soh/resource/importer/scenecommand/SetLightingSettingsFactory.h index df25600e2..e7b0d7aeb 100644 --- a/soh/soh/resource/importer/scenecommand/SetLightingSettingsFactory.h +++ b/soh/soh/resource/importer/scenecommand/SetLightingSettingsFactory.h @@ -8,4 +8,12 @@ class SetLightingSettingsFactory : public SceneCommandFactoryBinaryV0 { std::shared_ptr ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; }; + +class SetLightingSettingsFactoryXML : public SceneCommandFactoryXMLV0 { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, tinyxml2::XMLElement* reader) override; +}; + +void LogLightingSettingsAsXML(std::shared_ptr resource); } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetMeshFactory.cpp b/soh/soh/resource/importer/scenecommand/SetMeshFactory.cpp index 8c17ecc07..3141bb8bc 100644 --- a/soh/soh/resource/importer/scenecommand/SetMeshFactory.cpp +++ b/soh/soh/resource/importer/scenecommand/SetMeshFactory.cpp @@ -45,6 +45,8 @@ SetMeshFactory::ReadResource(std::shared_ptr initData, st dlist.opa = meshOpa != "" ? (Gfx*)(opaRes ? opaRes->GetRawPointer() : nullptr) : 0; dlist.xlu = meshXlu != "" ? (Gfx*)(xluRes ? xluRes->GetRawPointer() : nullptr) : 0; + setMesh->opaPaths.push_back(meshOpa); + setMesh->xluPaths.push_back(meshXlu); setMesh->dlists.push_back(dlist); } else if (setMesh->meshHeader.base.type == 1) { PolygonDlist pType; @@ -106,6 +108,8 @@ SetMeshFactory::ReadResource(std::shared_ptr initData, st pType.opa = meshOpa != "" ? (Gfx*)(opaRes ? opaRes->GetRawPointer() : nullptr) : 0; pType.xlu = meshXlu != "" ? (Gfx*)(xluRes ? xluRes->GetRawPointer() : nullptr) : 0; + setMesh->opaPaths.push_back(meshOpa); + setMesh->xluPaths.push_back(meshXlu); setMesh->dlists.push_back(pType); } else if (setMesh->meshHeader.base.type == 2) { PolygonDlist2 dlist; @@ -124,6 +128,8 @@ SetMeshFactory::ReadResource(std::shared_ptr initData, st dlist.opa = (Gfx*)(opaRes ? opaRes->GetRawPointer() : nullptr); dlist.xlu = (Gfx*)(xluRes ? xluRes->GetRawPointer() : nullptr); + setMesh->opaPaths.push_back(meshOpa); + setMesh->xluPaths.push_back(meshXlu); setMesh->dlists2.push_back(dlist); } else { SPDLOG_ERROR("Tried to load mesh in SetMesh scene header with type that doesn't exist: {}", setMesh->meshHeader.base.type); @@ -141,6 +147,274 @@ SetMeshFactory::ReadResource(std::shared_ptr initData, st SPDLOG_ERROR("Tried to load mesh in SetMesh scene header with type that doesn't exist: {}", setMesh->meshHeader.base.type); } + //LogMeshAsXML(setMesh); + return setMesh; } + +std::shared_ptr SetMeshFactoryXML::ReadResource(std::shared_ptr initData, + tinyxml2::XMLElement* reader) { + auto setMesh = std::make_shared(initData); + + setMesh->cmdId = SceneCommandID::SetMesh; + + setMesh->data = reader->IntAttribute("Data"); + + setMesh->meshHeader.base.type = reader->IntAttribute("MeshHeaderType"); + int32_t polyNum = 1; + + if (setMesh->meshHeader.base.type != 1) { + polyNum = reader->IntAttribute("PolyNum"); + if (setMesh->meshHeader.base.type == 0) { + setMesh->meshHeader.polygon0.num = polyNum; + } else if (setMesh->meshHeader.base.type == 2) { + setMesh->meshHeader.polygon2.num = polyNum; + } else { + SPDLOG_ERROR("Tried to load mesh in SetMesh scene header with type that doesn't exist: {}", setMesh->meshHeader.base.type); + } + } + + if (setMesh->meshHeader.base.type == 2) { + setMesh->dlists2.reserve(polyNum); + } else { + setMesh->dlists.reserve(setMesh->meshHeader.polygon0.num); + } + + auto child = reader->FirstChildElement(); + + while (child != nullptr) { + std::string childName = child->Name(); + if (childName != "Polygon") { + child = child->NextSiblingElement(); + continue; + } + + if (setMesh->meshHeader.base.type == 0) { + PolygonDlist dlist; + + int32_t polyType = child->IntAttribute("PolyType"); // Unused + std::string meshOpa = child->Attribute("MeshOpa"); + std::string meshXlu = child->Attribute("MeshXlu"); + + auto opaRes = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(meshOpa.c_str()); + auto xluRes = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(meshXlu.c_str()); + dlist.opa = meshOpa != "" ? (Gfx*)(opaRes ? opaRes->GetRawPointer() : nullptr) : 0; + dlist.xlu = meshXlu != "" ? (Gfx*)(xluRes ? xluRes->GetRawPointer() : nullptr) : 0; + + setMesh->opaPaths.push_back(meshOpa); + setMesh->xluPaths.push_back(meshXlu); + setMesh->dlists.push_back(dlist); + } else if (setMesh->meshHeader.base.type == 1) { + PolygonDlist pType; + + setMesh->meshHeader.polygon1.format = child->IntAttribute("Format"); + std::string imgOpa = child->Attribute("ImgOpa"); + std::string imgXlu = child->Attribute("ImgXlu"); + + auto opaRes = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(imgOpa.c_str()); + auto xluRes = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(imgXlu.c_str()); + pType.opa = imgOpa != "" ? (Gfx*)(opaRes ? opaRes->GetRawPointer() : nullptr) : 0; + pType.xlu = imgXlu != "" ? (Gfx*)(xluRes ? xluRes->GetRawPointer() : nullptr) : 0; + + int32_t bgImageCount = child->IntAttribute("BgImageCount"); + setMesh->images.reserve(bgImageCount); + + auto grandChild = child->FirstChildElement(); + + while (grandChild != nullptr) { + std::string grandChildName = grandChild->Name(); + if (grandChildName != "BgImage") { + grandChild = grandChild->NextSiblingElement(); + continue; + } + BgImage image; + image.unk_00 = grandChild->IntAttribute("Unknown_00"); + image.id = grandChild->IntAttribute("Id"); + std::string imagePath = "__OTR__" + std::string(grandChild->Attribute("ImagePath")); + setMesh->imagePaths.push_back(imagePath); + image.source = (void*)setMesh->imagePaths.back().c_str(); + image.unk_0C = grandChild->IntAttribute("Unknown_0C"); + image.tlut = grandChild->IntAttribute("TLUT"); + image.width = grandChild->IntAttribute("Width"); + image.height = grandChild->IntAttribute("Height"); + image.fmt = grandChild->IntAttribute("Fmt"); + image.siz = grandChild->IntAttribute("Siz"); + image.mode0 = grandChild->IntAttribute("Mode0"); + image.tlutCount = grandChild->IntAttribute("TLUTCount"); + + if (setMesh->meshHeader.polygon1.format == 1) { + setMesh->meshHeader.polygon1.single.source = image.source; + setMesh->meshHeader.polygon1.single.unk_0C = image.unk_0C; + setMesh->meshHeader.polygon1.single.tlut = (void*)image.tlut; // OTRTODO: type of bgimage.tlut should be uintptr_t + setMesh->meshHeader.polygon1.single.width = image.width; + setMesh->meshHeader.polygon1.single.height = image.height; + setMesh->meshHeader.polygon1.single.fmt = image.fmt; + setMesh->meshHeader.polygon1.single.siz = image.siz; + setMesh->meshHeader.polygon1.single.mode0 = image.mode0; + setMesh->meshHeader.polygon1.single.tlutCount = image.tlutCount; + } else { + setMesh->images.push_back(image); + } + + grandChild = grandChild->NextSiblingElement(); + } + + if (setMesh->meshHeader.polygon1.format != 1) { + setMesh->meshHeader.polygon1.multi.count = bgImageCount; + } + + int32_t polyType = child->IntAttribute("PolyType"); // Unused?? + + std::string meshOpa = child->Attribute("MeshOpa"); + std::string meshXlu = child->Attribute("MeshXlu"); + + opaRes = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(meshOpa.c_str()); + xluRes = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(meshXlu.c_str()); + pType.opa = meshOpa != "" ? (Gfx*)(opaRes ? opaRes->GetRawPointer() : nullptr) : 0; + pType.xlu = meshXlu != "" ? (Gfx*)(xluRes ? xluRes->GetRawPointer() : nullptr) : 0; + + setMesh->opaPaths.push_back(meshOpa); + setMesh->xluPaths.push_back(meshXlu); + setMesh->dlists.push_back(pType); + } else if (setMesh->meshHeader.base.type == 2) { + PolygonDlist2 dlist; + + int32_t polyType = child->IntAttribute("PolyType"); // Unused + dlist.pos.x = child->IntAttribute("PosX"); + dlist.pos.y = child->IntAttribute("PosY"); + dlist.pos.z = child->IntAttribute("PosZ"); + dlist.unk_06 = child->IntAttribute("Unknown"); + + std::string meshOpa = child->Attribute("MeshOpa"); + std::string meshXlu = child->Attribute("MeshXlu"); + + auto opaRes = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(meshOpa.c_str()); + auto xluRes = LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(meshXlu.c_str()); + dlist.opa = meshOpa != "" ? (Gfx*)(opaRes ? opaRes->GetRawPointer() : nullptr) : 0; + dlist.xlu = meshXlu != "" ? (Gfx*)(xluRes ? xluRes->GetRawPointer() : nullptr) : 0; + + setMesh->opaPaths.push_back(meshOpa); + setMesh->xluPaths.push_back(meshXlu); + setMesh->dlists2.push_back(dlist); + } else { + SPDLOG_ERROR("Tried to load mesh in SetMesh scene header with type that doesn't exist: {}", setMesh->meshHeader.base.type); + } + + child = child->NextSiblingElement(); + } + + if (setMesh->meshHeader.base.type == 2) { + setMesh->meshHeader.polygon2.start = setMesh->dlists2.data(); + } else if (setMesh->meshHeader.base.type == 0) { + setMesh->meshHeader.polygon0.start = setMesh->dlists.data(); + } else if (setMesh->meshHeader.base.type == 1) { + setMesh->meshHeader.polygon1.multi.list = setMesh->images.data(); + setMesh->meshHeader.polygon1.dlist = (Gfx*)setMesh->dlists.data(); + } else { + SPDLOG_ERROR("Tried to load mesh in SetMesh scene header with type that doesn't exist: {}", setMesh->meshHeader.base.type); + } + + return setMesh; +} + +void LogMeshAsXML(std::shared_ptr resource) { + std::shared_ptr setMesh = std::static_pointer_cast(resource); + + tinyxml2::XMLDocument doc; + tinyxml2::XMLElement* root = doc.NewElement("SetMesh"); + doc.InsertFirstChild(root); + + root->SetAttribute("Data", setMesh->data); + root->SetAttribute("MeshHeaderType", setMesh->meshHeader.base.type); + + if (setMesh->meshHeader.base.type == 0) { + root->SetAttribute("PolyNum", setMesh->meshHeader.polygon0.num); + PolygonDlist* dlist = (PolygonDlist*)setMesh->meshHeader.polygon0.start; + for (int i = 0; i < setMesh->meshHeader.polygon0.num; i += 1) { + tinyxml2::XMLElement* polygon = doc.NewElement("Polygon"); + polygon->SetAttribute("PolyType", "0"); + polygon->SetAttribute("MeshOpa", setMesh->opaPaths[i].c_str()); + polygon->SetAttribute("MeshXlu", setMesh->xluPaths[i].c_str()); + + root->InsertEndChild(polygon); + } + dlist += 1; + } else if (setMesh->meshHeader.base.type == 1) { + root->SetAttribute("PolyNum", "1"); + tinyxml2::XMLElement* polygon = doc.NewElement("Polygon"); + polygon->SetAttribute("Format", setMesh->meshHeader.polygon1.format); + polygon->SetAttribute("ImgOpa", ""); + polygon->SetAttribute("ImgXlu", ""); + + if (setMesh->meshHeader.polygon1.format == 1) { + polygon->SetAttribute("BgImageCount", "0"); + } else { + polygon->SetAttribute("BgImageCount", setMesh->meshHeader.polygon1.multi.count); + } + + polygon->SetAttribute("PolyType", "0"); + + polygon->SetAttribute("MeshOpa", setMesh->opaPaths[0].c_str()); + polygon->SetAttribute("MeshXlu", setMesh->xluPaths[0].c_str()); + + root->InsertEndChild(polygon); + + BgImage* image = setMesh->meshHeader.polygon1.multi.list; + int count = setMesh->meshHeader.polygon1.format == 1 ? 1 : setMesh->meshHeader.polygon1.multi.count; + for (int i = 0; i < count; i += 1) { + tinyxml2::XMLElement* bgImage = doc.NewElement("BgImage"); + if (setMesh->meshHeader.polygon1.format == 1) { + bgImage->SetAttribute("Unknown_00", image->unk_00); + bgImage->SetAttribute("Id", image->id); + bgImage->SetAttribute("ImagePath", setMesh->imagePaths[i].c_str()); + bgImage->SetAttribute("Unknown_0C", setMesh->meshHeader.polygon1.single.unk_0C); + bgImage->SetAttribute("TLUT", setMesh->meshHeader.polygon1.single.tlut); + bgImage->SetAttribute("Width", setMesh->meshHeader.polygon1.single.width); + bgImage->SetAttribute("Height", setMesh->meshHeader.polygon1.single.height); + bgImage->SetAttribute("Fmt", setMesh->meshHeader.polygon1.single.fmt); + bgImage->SetAttribute("Siz", setMesh->meshHeader.polygon1.single.siz); + bgImage->SetAttribute("Mode0", setMesh->meshHeader.polygon1.single.mode0); + bgImage->SetAttribute("TLUTCount", setMesh->meshHeader.polygon1.single.tlutCount); + } else { + bgImage->SetAttribute("Unknown_00", image->unk_00); + bgImage->SetAttribute("Id", image->id); + bgImage->SetAttribute("ImagePath", setMesh->imagePaths[i].c_str()); + bgImage->SetAttribute("Unknown_0C", image->unk_0C); + bgImage->SetAttribute("TLUT", image->tlut); + bgImage->SetAttribute("Width", image->width); + bgImage->SetAttribute("Height", image->height); + bgImage->SetAttribute("Fmt", image->fmt); + bgImage->SetAttribute("Siz", image->siz); + bgImage->SetAttribute("Mode0", image->mode0); + bgImage->SetAttribute("TLUTCount", image->tlutCount); + } + polygon->InsertEndChild(bgImage); + + image += 1; + } + } else if (setMesh->meshHeader.base.type == 2) { + root->SetAttribute("PolyNum", setMesh->meshHeader.polygon2.num); + PolygonDlist2* dlist = (PolygonDlist2*)setMesh->meshHeader.polygon2.start; + for (int i = 0; i < setMesh->meshHeader.polygon2.num; i += 1) { + tinyxml2::XMLElement* polygon = doc.NewElement("Polygon"); + polygon->SetAttribute("PolyType", "0"); + + polygon->SetAttribute("PosX", dlist->pos.x); + polygon->SetAttribute("PosY", dlist->pos.y); + polygon->SetAttribute("PosZ", dlist->pos.z); + polygon->SetAttribute("Unknown", dlist->unk_06); + + polygon->SetAttribute("MeshOpa", setMesh->opaPaths[i].c_str()); + polygon->SetAttribute("MeshXlu", setMesh->xluPaths[i].c_str()); + + root->InsertEndChild(polygon); + dlist += 1; + } + } + + tinyxml2::XMLPrinter printer; + doc.Accept(&printer); + + SPDLOG_INFO("{}: {}", resource->GetInitData()->Path, printer.CStr()); +} } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetMeshFactory.h b/soh/soh/resource/importer/scenecommand/SetMeshFactory.h index a912bdd37..8f210f9dc 100644 --- a/soh/soh/resource/importer/scenecommand/SetMeshFactory.h +++ b/soh/soh/resource/importer/scenecommand/SetMeshFactory.h @@ -8,4 +8,12 @@ class SetMeshFactory : public SceneCommandFactoryBinaryV0 { std::shared_ptr ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; }; + +class SetMeshFactoryXML : public SceneCommandFactoryXMLV0 { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, tinyxml2::XMLElement* reader) override; +}; + +void LogMeshAsXML(std::shared_ptr resource); } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetObjectListFactory.cpp b/soh/soh/resource/importer/scenecommand/SetObjectListFactory.cpp index b84befb3b..426eb7230 100644 --- a/soh/soh/resource/importer/scenecommand/SetObjectListFactory.cpp +++ b/soh/soh/resource/importer/scenecommand/SetObjectListFactory.cpp @@ -15,6 +15,49 @@ SetObjectListFactory::ReadResource(std::shared_ptr initDa setObjectList->objects.push_back(reader->ReadUInt16()); } + //LogObjectListAsXML(setObjectList); + return setObjectList; } + +std::shared_ptr SetObjectListFactoryXML::ReadResource(std::shared_ptr initData, + tinyxml2::XMLElement* reader) { + auto setObjectList = std::make_shared(initData); + + setObjectList->cmdId = SceneCommandID::SetObjectList; + + auto child = reader->FirstChildElement(); + + while (child != nullptr) { + std::string childName = child->Name(); + if (childName == "ObjectEntry") { + setObjectList->objects.push_back(child->IntAttribute("Id")); + } + + child = child->NextSiblingElement(); + } + + setObjectList->numObjects = setObjectList->objects.size(); + + return setObjectList; +} + +void LogObjectListAsXML(std::shared_ptr resource) { + std::shared_ptr setObjectList = std::static_pointer_cast(resource); + + tinyxml2::XMLDocument doc; + tinyxml2::XMLElement* root = doc.NewElement("SetObjectList"); + doc.InsertFirstChild(root); + + for (size_t i = 0; i < setObjectList->numObjects; i++) { + tinyxml2::XMLElement* entry = doc.NewElement("ObjectEntry"); + entry->SetAttribute("Id", setObjectList->objects[i]); + root->InsertEndChild(entry); + } + + tinyxml2::XMLPrinter printer; + doc.Accept(&printer); + + SPDLOG_INFO("{}: {}", resource->GetInitData()->Path, printer.CStr()); +} } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetObjectListFactory.h b/soh/soh/resource/importer/scenecommand/SetObjectListFactory.h index 4c2f002c0..7d0f45591 100644 --- a/soh/soh/resource/importer/scenecommand/SetObjectListFactory.h +++ b/soh/soh/resource/importer/scenecommand/SetObjectListFactory.h @@ -8,4 +8,12 @@ class SetObjectListFactory : public SceneCommandFactoryBinaryV0 { std::shared_ptr ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; }; + +class SetObjectListFactoryXML : public SceneCommandFactoryXMLV0 { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, tinyxml2::XMLElement* reader) override; +}; + +void LogObjectListAsXML(std::shared_ptr resource); } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetPathwaysFactory.cpp b/soh/soh/resource/importer/scenecommand/SetPathwaysFactory.cpp index 61534ba48..d2a878f98 100644 --- a/soh/soh/resource/importer/scenecommand/SetPathwaysFactory.cpp +++ b/soh/soh/resource/importer/scenecommand/SetPathwaysFactory.cpp @@ -18,6 +18,52 @@ SetPathwaysFactory::ReadResource(std::shared_ptr initData setPathways->paths.push_back(path->GetPointer()); } + //LogPathwaysAsXML(setPathways); + return setPathways; } + +std::shared_ptr SetPathwaysFactoryXML::ReadResource(std::shared_ptr initData, + tinyxml2::XMLElement* reader) { + auto setPathways = std::make_shared(initData); + + setPathways->cmdId = SceneCommandID::SetPathways; + + auto child = reader->FirstChildElement(); + + while (child != nullptr) { + std::string childName = child->Name(); + if (childName == "Pathway") { + std::string pathFileName = child->Attribute("FilePath"); + auto path = std::static_pointer_cast(LUS::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(pathFileName.c_str())); + setPathways->paths.push_back(path->GetPointer()); + setPathways->pathFileNames.push_back(pathFileName); + } + + child = child->NextSiblingElement(); + } + + setPathways->numPaths = setPathways->paths.size(); + + return setPathways; +} + +void LogPathwaysAsXML(std::shared_ptr resource) { + std::shared_ptr setPathways = std::static_pointer_cast(resource); + + tinyxml2::XMLDocument doc; + tinyxml2::XMLElement* root = doc.NewElement("SetPathways"); + doc.InsertFirstChild(root); + + for (size_t i = 0; i < setPathways->pathFileNames.size(); i++) { + tinyxml2::XMLElement* pathway = doc.NewElement("Pathway"); + pathway->SetAttribute("FilePath", setPathways->pathFileNames[i].c_str()); + root->InsertEndChild(pathway); + } + + tinyxml2::XMLPrinter printer; + doc.Accept(&printer); + + SPDLOG_INFO("{}: {}", resource->GetInitData()->Path, printer.CStr()); +} } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetPathwaysFactory.h b/soh/soh/resource/importer/scenecommand/SetPathwaysFactory.h index c622c820d..289a98201 100644 --- a/soh/soh/resource/importer/scenecommand/SetPathwaysFactory.h +++ b/soh/soh/resource/importer/scenecommand/SetPathwaysFactory.h @@ -8,4 +8,12 @@ class SetPathwaysFactory : public SceneCommandFactoryBinaryV0 { std::shared_ptr ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; }; + +class SetPathwaysFactoryXML : public SceneCommandFactoryXMLV0 { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, tinyxml2::XMLElement* reader) override; +}; + +void LogPathwaysAsXML(std::shared_ptr resource); } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetRoomBehaviorFactory.cpp b/soh/soh/resource/importer/scenecommand/SetRoomBehaviorFactory.cpp index e4601e59c..5ad5d12e6 100644 --- a/soh/soh/resource/importer/scenecommand/SetRoomBehaviorFactory.cpp +++ b/soh/soh/resource/importer/scenecommand/SetRoomBehaviorFactory.cpp @@ -12,6 +12,36 @@ SetRoomBehaviorFactory::ReadResource(std::shared_ptr init setRoomBehavior->roomBehavior.gameplayFlags = reader->ReadInt8(); setRoomBehavior->roomBehavior.gameplayFlags2 = reader->ReadInt32(); + //LogRoomBehaviorAsXML(setRoomBehavior); + return setRoomBehavior; } + +std::shared_ptr SetRoomBehaviorFactoryXML::ReadResource(std::shared_ptr initData, + tinyxml2::XMLElement* reader) { + auto setRoomBehavior = std::make_shared(initData); + + setRoomBehavior->cmdId = SceneCommandID::SetRoomBehavior; + + setRoomBehavior->roomBehavior.gameplayFlags = reader->IntAttribute("GameplayFlags1"); + setRoomBehavior->roomBehavior.gameplayFlags2 = reader->IntAttribute("GameplayFlags2"); + + return setRoomBehavior; +} + +void LogRoomBehaviorAsXML(std::shared_ptr resource) { + std::shared_ptr setRoomBehavior = std::static_pointer_cast(resource); + + tinyxml2::XMLDocument doc; + tinyxml2::XMLElement* root = doc.NewElement("SetRoomBehavior"); + doc.InsertFirstChild(root); + + root->SetAttribute("GameplayFlags1", setRoomBehavior->roomBehavior.gameplayFlags); + root->SetAttribute("GameplayFlags2", setRoomBehavior->roomBehavior.gameplayFlags2); + + tinyxml2::XMLPrinter printer; + doc.Accept(&printer); + + SPDLOG_INFO("{}: {}", resource->GetInitData()->Path, printer.CStr()); +} } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetRoomBehaviorFactory.h b/soh/soh/resource/importer/scenecommand/SetRoomBehaviorFactory.h index 70a53ba1e..885817aa9 100644 --- a/soh/soh/resource/importer/scenecommand/SetRoomBehaviorFactory.h +++ b/soh/soh/resource/importer/scenecommand/SetRoomBehaviorFactory.h @@ -8,4 +8,12 @@ class SetRoomBehaviorFactory : public SceneCommandFactoryBinaryV0 { std::shared_ptr ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; }; + +class SetRoomBehaviorFactoryXML : public SceneCommandFactoryXMLV0 { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, tinyxml2::XMLElement* reader) override; +}; + +void LogRoomBehaviorAsXML(std::shared_ptr resource); } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetRoomListFactory.cpp b/soh/soh/resource/importer/scenecommand/SetRoomListFactory.cpp index 7726877a1..c9a9d606f 100644 --- a/soh/soh/resource/importer/scenecommand/SetRoomListFactory.cpp +++ b/soh/soh/resource/importer/scenecommand/SetRoomListFactory.cpp @@ -23,6 +23,57 @@ SetRoomListFactory::ReadResource(std::shared_ptr initData setRoomList->rooms.push_back(room); } + //LogRoomListAsXML(setRoomList); + return setRoomList; } + +std::shared_ptr SetRoomListFactoryXML::ReadResource(std::shared_ptr initData, + tinyxml2::XMLElement* reader) { + auto setRoomList = std::make_shared(initData); + + setRoomList->cmdId = SceneCommandID::SetRoomList; + + auto child = reader->FirstChildElement(); + + while (child != nullptr) { + std::string childName = child->Name(); + if (childName == "RoomEntry") { + RomFile room; + + setRoomList->fileNames.push_back(child->Attribute("Path")); + + room.fileName = (char*)setRoomList->fileNames.back().c_str(); + room.vromStart = child->IntAttribute("VromStart"); + room.vromEnd = child->IntAttribute("VromEnd"); + + setRoomList->rooms.push_back(room); + } + + child = child->NextSiblingElement(); + } + + setRoomList->numRooms = setRoomList->rooms.size(); + + return setRoomList; +} + +void LogRoomListAsXML(std::shared_ptr resource) { + std::shared_ptr setRoomList = std::static_pointer_cast(resource); + + tinyxml2::XMLDocument doc; + tinyxml2::XMLElement* root = doc.NewElement("SetRoomList"); + doc.InsertFirstChild(root); + + for (size_t i = 0; i < setRoomList->numRooms; i++) { + tinyxml2::XMLElement* entry = doc.NewElement("RoomEntry"); + entry->SetAttribute("Path", setRoomList->fileNames[i].c_str()); + root->InsertEndChild(entry); + } + + tinyxml2::XMLPrinter printer; + doc.Accept(&printer); + + SPDLOG_INFO("{}: {}", resource->GetInitData()->Path, printer.CStr()); +} } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetRoomListFactory.h b/soh/soh/resource/importer/scenecommand/SetRoomListFactory.h index 6bf9eaa5c..62edc3a4e 100644 --- a/soh/soh/resource/importer/scenecommand/SetRoomListFactory.h +++ b/soh/soh/resource/importer/scenecommand/SetRoomListFactory.h @@ -8,4 +8,12 @@ class SetRoomListFactory : public SceneCommandFactoryBinaryV0 { std::shared_ptr ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; }; + +class SetRoomListFactoryXML : public SceneCommandFactoryXMLV0 { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, tinyxml2::XMLElement* reader) override; +}; + +void LogRoomListAsXML(std::shared_ptr resource); } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetSkyboxModifierFactory.cpp b/soh/soh/resource/importer/scenecommand/SetSkyboxModifierFactory.cpp index 291ae578c..99f265009 100644 --- a/soh/soh/resource/importer/scenecommand/SetSkyboxModifierFactory.cpp +++ b/soh/soh/resource/importer/scenecommand/SetSkyboxModifierFactory.cpp @@ -12,6 +12,36 @@ std::shared_ptr SetSkyboxModifierFactory::ReadResource(std::shar setSkyboxModifier->modifier.skyboxDisabled = reader->ReadInt8(); setSkyboxModifier->modifier.sunMoonDisabled = reader->ReadInt8(); + //LogSkyboxModifierAsXML(setSkyboxModifier); + return setSkyboxModifier; } + +std::shared_ptr SetSkyboxModifierFactoryXML::ReadResource(std::shared_ptr initData, + tinyxml2::XMLElement* reader) { + auto setSkyboxModifier = std::make_shared(initData); + + setSkyboxModifier->cmdId = SceneCommandID::SetSkyboxModifier; + + setSkyboxModifier->modifier.skyboxDisabled = reader->IntAttribute("SkyboxDisabled"); + setSkyboxModifier->modifier.sunMoonDisabled = reader->IntAttribute("SunMoonDisabled"); + + return setSkyboxModifier; +} + +void LogSkyboxModifierAsXML(std::shared_ptr resource) { + std::shared_ptr setSkyboxModifier = std::static_pointer_cast(resource); + + tinyxml2::XMLDocument doc; + tinyxml2::XMLElement* root = doc.NewElement("SetSkyboxModifier"); + doc.InsertFirstChild(root); + + root->SetAttribute("SkyboxDisabled", setSkyboxModifier->modifier.skyboxDisabled); + root->SetAttribute("SunMoonDisabled", setSkyboxModifier->modifier.sunMoonDisabled); + + tinyxml2::XMLPrinter printer; + doc.Accept(&printer); + + SPDLOG_INFO("{}: {}", resource->GetInitData()->Path, printer.CStr()); +} } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetSkyboxModifierFactory.h b/soh/soh/resource/importer/scenecommand/SetSkyboxModifierFactory.h index d467cc73d..beb6a26dc 100644 --- a/soh/soh/resource/importer/scenecommand/SetSkyboxModifierFactory.h +++ b/soh/soh/resource/importer/scenecommand/SetSkyboxModifierFactory.h @@ -8,4 +8,12 @@ class SetSkyboxModifierFactory : public SceneCommandFactoryBinaryV0 { std::shared_ptr ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; }; + +class SetSkyboxModifierFactoryXML : public SceneCommandFactoryXMLV0 { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, tinyxml2::XMLElement* reader) override; +}; + +void LogSkyboxModifierAsXML(std::shared_ptr resource); } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetSkyboxSettingsFactory.cpp b/soh/soh/resource/importer/scenecommand/SetSkyboxSettingsFactory.cpp index f3e726b07..c9b7a6929 100644 --- a/soh/soh/resource/importer/scenecommand/SetSkyboxSettingsFactory.cpp +++ b/soh/soh/resource/importer/scenecommand/SetSkyboxSettingsFactory.cpp @@ -14,6 +14,40 @@ std::shared_ptr SetSkyboxSettingsFactory::ReadResource(std::shar setSkyboxSettings->settings.weather = reader->ReadInt8(); setSkyboxSettings->settings.indoors = reader->ReadInt8(); + //LogSkyboxSettingsAsXML(setSkyboxSettings); + return setSkyboxSettings; } + +std::shared_ptr SetSkyboxSettingsFactoryXML::ReadResource(std::shared_ptr initData, + tinyxml2::XMLElement* reader) { + auto setSkyboxSettings = std::make_shared(initData); + + setSkyboxSettings->cmdId = SceneCommandID::SetSkyboxSettings; + + setSkyboxSettings->settings.unk = reader->IntAttribute("Unknown"); + setSkyboxSettings->settings.skyboxId = reader->IntAttribute("SkyboxId"); + setSkyboxSettings->settings.weather = reader->IntAttribute("Weather"); + setSkyboxSettings->settings.indoors = reader->IntAttribute("Indoors"); + + return setSkyboxSettings; +} + +void LogSkyboxSettingsAsXML(std::shared_ptr resource) { + std::shared_ptr setSkyboxSettings = std::static_pointer_cast(resource); + + tinyxml2::XMLDocument doc; + tinyxml2::XMLElement* root = doc.NewElement("SetSkyboxSettings"); + doc.InsertFirstChild(root); + + root->SetAttribute("Unknown", setSkyboxSettings->settings.unk); + root->SetAttribute("SkyboxId", setSkyboxSettings->settings.skyboxId); + root->SetAttribute("Weather", setSkyboxSettings->settings.weather); + root->SetAttribute("Indoors", setSkyboxSettings->settings.indoors); + + tinyxml2::XMLPrinter printer; + doc.Accept(&printer); + + SPDLOG_INFO("{}: {}", resource->GetInitData()->Path, printer.CStr()); +} } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetSkyboxSettingsFactory.h b/soh/soh/resource/importer/scenecommand/SetSkyboxSettingsFactory.h index 581e56122..e5c01f963 100644 --- a/soh/soh/resource/importer/scenecommand/SetSkyboxSettingsFactory.h +++ b/soh/soh/resource/importer/scenecommand/SetSkyboxSettingsFactory.h @@ -8,4 +8,12 @@ class SetSkyboxSettingsFactory : public SceneCommandFactoryBinaryV0 { std::shared_ptr ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; }; + +class SetSkyboxSettingsFactoryXML : public SceneCommandFactoryXMLV0 { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, tinyxml2::XMLElement* reader) override; +}; + +void LogSkyboxSettingsAsXML(std::shared_ptr resource); } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetSoundSettingsFactory.cpp b/soh/soh/resource/importer/scenecommand/SetSoundSettingsFactory.cpp index f85178e22..06f8ac34c 100644 --- a/soh/soh/resource/importer/scenecommand/SetSoundSettingsFactory.cpp +++ b/soh/soh/resource/importer/scenecommand/SetSoundSettingsFactory.cpp @@ -13,6 +13,38 @@ std::shared_ptr SetSoundSettingsFactory::ReadResource(std::share setSoundSettings->settings.natureAmbienceId = reader->ReadInt8(); setSoundSettings->settings.seqId = reader->ReadInt8(); + //LogSoundSettingsAsXML(setSoundSettings); + return setSoundSettings; } + +std::shared_ptr SetSoundSettingsFactoryXML::ReadResource(std::shared_ptr initData, + tinyxml2::XMLElement* reader) { + auto setSoundSettings = std::make_shared(initData); + + setSoundSettings->cmdId = SceneCommandID::SetSoundSettings; + + setSoundSettings->settings.reverb = reader->IntAttribute("Reverb"); + setSoundSettings->settings.natureAmbienceId = reader->IntAttribute("NatureAmbienceId"); + setSoundSettings->settings.seqId = reader->IntAttribute("SeqId"); + + return setSoundSettings; +} + +void LogSoundSettingsAsXML(std::shared_ptr resource) { + std::shared_ptr setSoundSettings = std::static_pointer_cast(resource); + + tinyxml2::XMLDocument doc; + tinyxml2::XMLElement* root = doc.NewElement("SetSoundSettings"); + doc.InsertFirstChild(root); + + root->SetAttribute("Reverb", setSoundSettings->settings.reverb); + root->SetAttribute("NatureAmbienceId", setSoundSettings->settings.natureAmbienceId); + root->SetAttribute("SeqId", setSoundSettings->settings.seqId); + + tinyxml2::XMLPrinter printer; + doc.Accept(&printer); + + SPDLOG_INFO("{}: {}", resource->GetInitData()->Path, printer.CStr()); +} } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetSoundSettingsFactory.h b/soh/soh/resource/importer/scenecommand/SetSoundSettingsFactory.h index e1c4efb03..4764612a4 100644 --- a/soh/soh/resource/importer/scenecommand/SetSoundSettingsFactory.h +++ b/soh/soh/resource/importer/scenecommand/SetSoundSettingsFactory.h @@ -8,4 +8,12 @@ class SetSoundSettingsFactory : public SceneCommandFactoryBinaryV0 { std::shared_ptr ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; }; + +class SetSoundSettingsFactoryXML : public SceneCommandFactoryXMLV0 { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, tinyxml2::XMLElement* reader) override; +}; + +void LogSoundSettingsAsXML(std::shared_ptr resource); } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetSpecialObjectsFactory.cpp b/soh/soh/resource/importer/scenecommand/SetSpecialObjectsFactory.cpp index b7fd21aa4..41e81e9aa 100644 --- a/soh/soh/resource/importer/scenecommand/SetSpecialObjectsFactory.cpp +++ b/soh/soh/resource/importer/scenecommand/SetSpecialObjectsFactory.cpp @@ -12,6 +12,36 @@ std::shared_ptr SetSpecialObjectsFactory::ReadResource(std::shar setSpecialObjects->specialObjects.elfMessage = reader->ReadInt8(); setSpecialObjects->specialObjects.globalObject = reader->ReadInt16(); + //LogSpecialObjectsAsXML(setSpecialObjects); + return setSpecialObjects; } + +std::shared_ptr SetSpecialObjectsFactoryXML::ReadResource(std::shared_ptr initData, + tinyxml2::XMLElement* reader) { + auto setSpecialObjects = std::make_shared(initData); + + setSpecialObjects->cmdId = SceneCommandID::SetSpecialObjects; + + setSpecialObjects->specialObjects.elfMessage = reader->IntAttribute("ElfMessage"); + setSpecialObjects->specialObjects.globalObject = reader->IntAttribute("GlobalObject"); + + return setSpecialObjects; +} + +void LogSpecialObjectsAsXML(std::shared_ptr resource) { + std::shared_ptr setSpecialObjects = std::static_pointer_cast(resource); + + tinyxml2::XMLDocument doc; + tinyxml2::XMLElement* root = doc.NewElement("SetSpecialObjects"); + doc.InsertFirstChild(root); + + root->SetAttribute("ElfMessage", setSpecialObjects->specialObjects.elfMessage); + root->SetAttribute("GlobalObject", setSpecialObjects->specialObjects.globalObject); + + tinyxml2::XMLPrinter printer; + doc.Accept(&printer); + + SPDLOG_INFO("{}: {}", resource->GetInitData()->Path, printer.CStr()); +} } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetSpecialObjectsFactory.h b/soh/soh/resource/importer/scenecommand/SetSpecialObjectsFactory.h index 503cfb61f..8e2c7b60c 100644 --- a/soh/soh/resource/importer/scenecommand/SetSpecialObjectsFactory.h +++ b/soh/soh/resource/importer/scenecommand/SetSpecialObjectsFactory.h @@ -8,4 +8,12 @@ class SetSpecialObjectsFactory : public SceneCommandFactoryBinaryV0 { std::shared_ptr ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; }; + +class SetSpecialObjectsFactoryXML : public SceneCommandFactoryXMLV0 { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, tinyxml2::XMLElement* reader) override; +}; + +void LogSpecialObjectsAsXML(std::shared_ptr resource); } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetStartPositionListFactory.cpp b/soh/soh/resource/importer/scenecommand/SetStartPositionListFactory.cpp index 3165b4361..73ac0b827 100644 --- a/soh/soh/resource/importer/scenecommand/SetStartPositionListFactory.cpp +++ b/soh/soh/resource/importer/scenecommand/SetStartPositionListFactory.cpp @@ -26,6 +26,65 @@ std::shared_ptr SetStartPositionListFactory::ReadResource(std::s setStartPositionList->startPositions.push_back(entry); } + //LogStartPositionListAsXML(setStartPositionList); + return setStartPositionList; } + +std::shared_ptr SetStartPositionListFactoryXML::ReadResource(std::shared_ptr initData, + tinyxml2::XMLElement* reader) { + auto setStartPositionList = std::make_shared(initData); + + setStartPositionList->cmdId = SceneCommandID::SetStartPositionList; + + auto child = reader->FirstChildElement(); + + while (child != nullptr) { + std::string childName = child->Name(); + if (childName == "StartPositionEntry") { + ActorEntry entry; + entry.id = child->IntAttribute("Id"); + entry.pos.x = child->IntAttribute("PosX"); + entry.pos.y = child->IntAttribute("PosY"); + entry.pos.z = child->IntAttribute("PosZ"); + entry.rot.x = child->IntAttribute("RotX"); + entry.rot.y = child->IntAttribute("RotY"); + entry.rot.z = child->IntAttribute("RotZ"); + entry.params = child->IntAttribute("Params"); + setStartPositionList->startPositions.push_back(entry); + } + + child = child->NextSiblingElement(); + } + + setStartPositionList->numStartPositions = setStartPositionList->startPositions.size(); + + return setStartPositionList; +} + +void LogStartPositionListAsXML(std::shared_ptr resource) { + std::shared_ptr setStartPositionList = std::static_pointer_cast(resource); + + tinyxml2::XMLDocument doc; + tinyxml2::XMLElement* root = doc.NewElement("SetStartPositionList"); + doc.InsertFirstChild(root); + + for (size_t i = 0; i < setStartPositionList->numStartPositions; i++) { + tinyxml2::XMLElement* entry = doc.NewElement("StartPositionEntry"); + entry->SetAttribute("Id", setStartPositionList->startPositions[i].id); + entry->SetAttribute("PosX", setStartPositionList->startPositions[i].pos.x); + entry->SetAttribute("PosY", setStartPositionList->startPositions[i].pos.y); + entry->SetAttribute("PosZ", setStartPositionList->startPositions[i].pos.z); + entry->SetAttribute("RotX", setStartPositionList->startPositions[i].rot.x); + entry->SetAttribute("RotY", setStartPositionList->startPositions[i].rot.y); + entry->SetAttribute("RotZ", setStartPositionList->startPositions[i].rot.z); + entry->SetAttribute("Params", setStartPositionList->startPositions[i].params); + root->InsertEndChild(entry); + } + + tinyxml2::XMLPrinter printer; + doc.Accept(&printer); + + SPDLOG_INFO("{}: {}", resource->GetInitData()->Path, printer.CStr()); +} } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetStartPositionListFactory.h b/soh/soh/resource/importer/scenecommand/SetStartPositionListFactory.h index b07901f05..30ffdaab0 100644 --- a/soh/soh/resource/importer/scenecommand/SetStartPositionListFactory.h +++ b/soh/soh/resource/importer/scenecommand/SetStartPositionListFactory.h @@ -8,4 +8,12 @@ class SetStartPositionListFactory : public SceneCommandFactoryBinaryV0 { std::shared_ptr ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; }; + +class SetStartPositionListFactoryXML : public SceneCommandFactoryXMLV0 { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, tinyxml2::XMLElement* reader) override; +}; + +void LogStartPositionListAsXML(std::shared_ptr resource); } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetTimeSettingsFactory.cpp b/soh/soh/resource/importer/scenecommand/SetTimeSettingsFactory.cpp index d83b24583..2dff3ac50 100644 --- a/soh/soh/resource/importer/scenecommand/SetTimeSettingsFactory.cpp +++ b/soh/soh/resource/importer/scenecommand/SetTimeSettingsFactory.cpp @@ -13,6 +13,38 @@ SetTimeSettingsFactory::ReadResource(std::shared_ptr init setTimeSettings->settings.minute = reader->ReadInt8(); setTimeSettings->settings.timeIncrement = reader->ReadInt8(); + //LogTimeSettingsAsXML(setTimeSettings); + return setTimeSettings; } + +std::shared_ptr SetTimeSettingsFactoryXML::ReadResource(std::shared_ptr initData, + tinyxml2::XMLElement* reader) { + auto setTimeSettings = std::make_shared(initData); + + setTimeSettings->cmdId = SceneCommandID::SetTimeSettings; + + setTimeSettings->settings.hour = reader->IntAttribute("Hour"); + setTimeSettings->settings.minute = reader->IntAttribute("Minute"); + setTimeSettings->settings.timeIncrement = reader->IntAttribute("TimeIncrement"); + + return setTimeSettings; +} + +void LogTimeSettingsAsXML(std::shared_ptr resource) { + std::shared_ptr setTimeSettings = std::static_pointer_cast(resource); + + tinyxml2::XMLDocument doc; + tinyxml2::XMLElement* root = doc.NewElement("SetTimeSettings"); + doc.InsertFirstChild(root); + + root->SetAttribute("Hour", setTimeSettings->settings.hour); + root->SetAttribute("Minute", setTimeSettings->settings.minute); + root->SetAttribute("TimeIncrement", setTimeSettings->settings.timeIncrement); + + tinyxml2::XMLPrinter printer; + doc.Accept(&printer); + + SPDLOG_INFO("{}: {}", resource->GetInitData()->Path, printer.CStr()); +} } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetTimeSettingsFactory.h b/soh/soh/resource/importer/scenecommand/SetTimeSettingsFactory.h index d1336f788..363d9fe9a 100644 --- a/soh/soh/resource/importer/scenecommand/SetTimeSettingsFactory.h +++ b/soh/soh/resource/importer/scenecommand/SetTimeSettingsFactory.h @@ -8,4 +8,12 @@ class SetTimeSettingsFactory : public SceneCommandFactoryBinaryV0 { std::shared_ptr ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; }; + +class SetTimeSettingsFactoryXML : public SceneCommandFactoryXMLV0 { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, tinyxml2::XMLElement* reader) override; +}; + +void LogTimeSettingsAsXML(std::shared_ptr resource); } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetTransitionActorListFactory.cpp b/soh/soh/resource/importer/scenecommand/SetTransitionActorListFactory.cpp index c751ad611..31e7826d0 100644 --- a/soh/soh/resource/importer/scenecommand/SetTransitionActorListFactory.cpp +++ b/soh/soh/resource/importer/scenecommand/SetTransitionActorListFactory.cpp @@ -28,6 +28,69 @@ std::shared_ptr SetTransitionActorListFactory::ReadResource(std: setTransitionActorList->transitionActorList.push_back(entry); } + //LogTransitionActorListAsXML(setTransitionActorList); + return setTransitionActorList; } + +std::shared_ptr SetTransitionActorListFactoryXML::ReadResource(std::shared_ptr initData, + tinyxml2::XMLElement* reader) { + auto setTransitionActorList = std::make_shared(initData); + + setTransitionActorList->cmdId = SceneCommandID::SetTransitionActorList; + + auto child = reader->FirstChildElement(); + + while (child != nullptr) { + std::string childName = child->Name(); + if (childName == "TransitionActorEntry") { + TransitionActorEntry entry; + entry.sides[0].room = child->IntAttribute("FrontSideRoom"); + entry.sides[0].effects = child->IntAttribute("FrontSideEffects"); + entry.sides[1].room = child->IntAttribute("BackSideRoom"); + entry.sides[1].effects = child->IntAttribute("BackSideEffects"); + entry.id = child->IntAttribute("Id"); + entry.pos.x = child->IntAttribute("PosX"); + entry.pos.y = child->IntAttribute("PosY"); + entry.pos.z = child->IntAttribute("PosZ"); + entry.rotY = child->IntAttribute("RotY"); + entry.params = child->IntAttribute("Params"); + setTransitionActorList->transitionActorList.push_back(entry); + } + + child = child->NextSiblingElement(); + } + + setTransitionActorList->numTransitionActors = setTransitionActorList->transitionActorList.size(); + + return setTransitionActorList; +} + +void LogTransitionActorListAsXML(std::shared_ptr resource) { + std::shared_ptr setTransitionActorList = std::static_pointer_cast(resource); + + tinyxml2::XMLDocument doc; + tinyxml2::XMLElement* root = doc.NewElement("SetTransitionActorList"); + doc.InsertFirstChild(root); + + for (size_t i = 0; i < setTransitionActorList->numTransitionActors; i++) { + tinyxml2::XMLElement* entry = doc.NewElement("TransitionActorEntry"); + entry->SetAttribute("FrontSideRoom", setTransitionActorList->transitionActorList[i].sides[0].room); + entry->SetAttribute("FrontSideEffects", setTransitionActorList->transitionActorList[i].sides[0].effects); + entry->SetAttribute("BackSideRoom", setTransitionActorList->transitionActorList[i].sides[1].room); + entry->SetAttribute("BackSideEffects", setTransitionActorList->transitionActorList[i].sides[1].effects); + entry->SetAttribute("Id", setTransitionActorList->transitionActorList[i].id); + entry->SetAttribute("PosX", setTransitionActorList->transitionActorList[i].pos.x); + entry->SetAttribute("PosY", setTransitionActorList->transitionActorList[i].pos.y); + entry->SetAttribute("PosZ", setTransitionActorList->transitionActorList[i].pos.z); + entry->SetAttribute("RotY", setTransitionActorList->transitionActorList[i].rotY); + entry->SetAttribute("Params", setTransitionActorList->transitionActorList[i].params); + root->InsertEndChild(entry); + } + + tinyxml2::XMLPrinter printer; + doc.Accept(&printer); + + SPDLOG_INFO("{}: {}", resource->GetInitData()->Path, printer.CStr()); +} } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetTransitionActorListFactory.h b/soh/soh/resource/importer/scenecommand/SetTransitionActorListFactory.h index c8fb65f9a..574f9dae0 100644 --- a/soh/soh/resource/importer/scenecommand/SetTransitionActorListFactory.h +++ b/soh/soh/resource/importer/scenecommand/SetTransitionActorListFactory.h @@ -8,4 +8,12 @@ class SetTransitionActorListFactory : public SceneCommandFactoryBinaryV0 { std::shared_ptr ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; }; + +class SetTransitionActorListFactoryXML : public SceneCommandFactoryXMLV0 { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, tinyxml2::XMLElement* reader) override; +}; + +void LogTransitionActorListAsXML(std::shared_ptr resource); } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetWindSettingsFactory.cpp b/soh/soh/resource/importer/scenecommand/SetWindSettingsFactory.cpp index 3208004ce..b3c0bd55f 100644 --- a/soh/soh/resource/importer/scenecommand/SetWindSettingsFactory.cpp +++ b/soh/soh/resource/importer/scenecommand/SetWindSettingsFactory.cpp @@ -14,6 +14,40 @@ SetWindSettingsFactory::ReadResource(std::shared_ptr init setWind->settings.windSouth = reader->ReadInt8(); setWind->settings.windSpeed = reader->ReadUByte(); + //LogWindSettingsAsXML(setWind); + return setWind; } + +std::shared_ptr SetWindSettingsFactoryXML::ReadResource(std::shared_ptr initData, + tinyxml2::XMLElement* reader) { + auto setWind = std::make_shared(initData); + + setWind->cmdId = SceneCommandID::SetWind; + + setWind->settings.windWest = reader->IntAttribute("WindWest"); + setWind->settings.windVertical = reader->IntAttribute("WindVertical"); + setWind->settings.windSouth = reader->IntAttribute("WindSouth"); + setWind->settings.windSpeed = reader->IntAttribute("WindSpeed"); + + return setWind; +} + +void LogWindSettingsAsXML(std::shared_ptr resource) { + std::shared_ptr setWindSettings = std::static_pointer_cast(resource); + + tinyxml2::XMLDocument doc; + tinyxml2::XMLElement* root = doc.NewElement("SetWindSettings"); + doc.InsertFirstChild(root); + + root->SetAttribute("WindWest", setWindSettings->settings.windWest); + root->SetAttribute("WindVertical", setWindSettings->settings.windVertical); + root->SetAttribute("WindSouth", setWindSettings->settings.windSouth); + root->SetAttribute("WindSpeed", setWindSettings->settings.windSpeed); + + tinyxml2::XMLPrinter printer; + doc.Accept(&printer); + + SPDLOG_INFO("{}: {}", resource->GetInitData()->Path, printer.CStr()); +} } // namespace SOH diff --git a/soh/soh/resource/importer/scenecommand/SetWindSettingsFactory.h b/soh/soh/resource/importer/scenecommand/SetWindSettingsFactory.h index 6cc9fbc1b..71e0e402c 100644 --- a/soh/soh/resource/importer/scenecommand/SetWindSettingsFactory.h +++ b/soh/soh/resource/importer/scenecommand/SetWindSettingsFactory.h @@ -8,4 +8,12 @@ class SetWindSettingsFactory : public SceneCommandFactoryBinaryV0 { std::shared_ptr ReadResource(std::shared_ptr initData, std::shared_ptr reader) override; }; + +class SetWindSettingsFactoryXML : public SceneCommandFactoryXMLV0 { + public: + std::shared_ptr + ReadResource(std::shared_ptr initData, tinyxml2::XMLElement* reader) override; +}; + +void LogWindSettingsAsXML(std::shared_ptr resource); } // namespace SOH diff --git a/soh/soh/resource/type/scenecommand/SetMesh.h b/soh/soh/resource/type/scenecommand/SetMesh.h index 33ab24202..5d4f99c6b 100644 --- a/soh/soh/resource/type/scenecommand/SetMesh.h +++ b/soh/soh/resource/type/scenecommand/SetMesh.h @@ -94,6 +94,8 @@ class SetMesh : public SceneCommand { uint8_t data; uint8_t meshHeaderType; + std::vector opaPaths; + std::vector xluPaths; std::vector dlists; std::vector dlists2; std::vector imagePaths; diff --git a/soh/soh/resource/type/scenecommand/SetPathways.h b/soh/soh/resource/type/scenecommand/SetPathways.h index cf875cf5e..9f22130a6 100644 --- a/soh/soh/resource/type/scenecommand/SetPathways.h +++ b/soh/soh/resource/type/scenecommand/SetPathways.h @@ -18,6 +18,7 @@ class SetPathways : public SceneCommand { size_t GetPointerSize(); uint32_t numPaths; + std::vector pathFileNames; std::vector paths; }; }; // namespace LUS