mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-02-17 07:40:20 -05:00
Add path XML parser (#4115)
* Add path XML parser * Update SetPathwaysFactory.cpp
This commit is contained in:
parent
844413b391
commit
08ad16e750
@ -1,5 +1,6 @@
|
|||||||
#include "soh/resource/importer/PathFactory.h"
|
#include "soh/resource/importer/PathFactory.h"
|
||||||
#include "soh/resource/type/Path.h"
|
#include "soh/resource/type/Path.h"
|
||||||
|
#include "soh/resource/logging/PathLogger.h"
|
||||||
#include "spdlog/spdlog.h"
|
#include "spdlog/spdlog.h"
|
||||||
|
|
||||||
namespace SOH {
|
namespace SOH {
|
||||||
@ -35,6 +36,60 @@ std::shared_ptr<Ship::IResource> ResourceFactoryBinaryPathV0::ReadResource(std::
|
|||||||
path->pathData.push_back(pathDataEntry);
|
path->pathData.push_back(pathDataEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (CVarGetInteger(CVAR_DEVELOPER_TOOLS("ResourceLogging"), 0)) {
|
||||||
|
LogPathAsXML(path);
|
||||||
|
}
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Ship::IResource> ResourceFactoryXMLPathV0::ReadResource(std::shared_ptr<Ship::File> file) {
|
||||||
|
if (!FileHasValidFormatAndReader(file)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto path = std::make_shared<Path>(file->InitData);
|
||||||
|
auto reader = std::get<std::shared_ptr<tinyxml2::XMLDocument>>(file->Reader);
|
||||||
|
|
||||||
|
auto pathElement = reader->RootElement();
|
||||||
|
|
||||||
|
//path->numPaths = pathElement->IntAttribute("NumPaths");
|
||||||
|
//path->paths.reserve(path->numPaths);
|
||||||
|
|
||||||
|
auto pathDataElement = pathElement->FirstChildElement();
|
||||||
|
|
||||||
|
while (pathDataElement != nullptr) {
|
||||||
|
std::vector<Vec3s> points;
|
||||||
|
//uint32_t pointCount = pathDataElement->IntAttribute("NumPoints");
|
||||||
|
//points.reserve(pointCount);
|
||||||
|
|
||||||
|
auto pointElement = pathDataElement->FirstChildElement();
|
||||||
|
|
||||||
|
while (pointElement != nullptr) {
|
||||||
|
Vec3s point;
|
||||||
|
point.x = pointElement->IntAttribute("X");
|
||||||
|
point.y = pointElement->IntAttribute("Y");
|
||||||
|
point.z = pointElement->IntAttribute("Z");
|
||||||
|
|
||||||
|
points.push_back(point);
|
||||||
|
|
||||||
|
pointElement = pointElement->NextSiblingElement();
|
||||||
|
}
|
||||||
|
|
||||||
|
PathData pathDataEntry;
|
||||||
|
//pathDataEntry.count = pointCount;
|
||||||
|
pathDataEntry.count = points.size();
|
||||||
|
|
||||||
|
path->paths.push_back(points);
|
||||||
|
pathDataEntry.points = path->paths.back().data();
|
||||||
|
|
||||||
|
path->pathData.push_back(pathDataEntry);
|
||||||
|
|
||||||
|
pathDataElement = pathDataElement->NextSiblingElement();
|
||||||
|
}
|
||||||
|
|
||||||
|
path->numPaths = path->paths.size();
|
||||||
|
|
||||||
|
return path;
|
||||||
|
};
|
||||||
} // namespace SOH
|
} // namespace SOH
|
||||||
|
@ -2,10 +2,16 @@
|
|||||||
|
|
||||||
#include "Resource.h"
|
#include "Resource.h"
|
||||||
#include "ResourceFactoryBinary.h"
|
#include "ResourceFactoryBinary.h"
|
||||||
|
#include "ResourceFactoryXML.h"
|
||||||
|
|
||||||
namespace SOH {
|
namespace SOH {
|
||||||
class ResourceFactoryBinaryPathV0 : public Ship::ResourceFactoryBinary {
|
class ResourceFactoryBinaryPathV0 : public Ship::ResourceFactoryBinary {
|
||||||
public:
|
public:
|
||||||
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file) override;
|
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ResourceFactoryXMLPathV0 : public Ship::ResourceFactoryXML {
|
||||||
|
public:
|
||||||
|
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file) override;
|
||||||
|
};
|
||||||
} // namespace SOH
|
} // namespace SOH
|
||||||
|
@ -17,6 +17,7 @@ SetPathwaysFactory::ReadResource(std::shared_ptr<Ship::ResourceInitData> initDat
|
|||||||
std::string pathFileName = reader->ReadString();
|
std::string pathFileName = reader->ReadString();
|
||||||
auto path = std::static_pointer_cast<Path>(Ship::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(pathFileName.c_str()));
|
auto path = std::static_pointer_cast<Path>(Ship::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(pathFileName.c_str()));
|
||||||
setPathways->paths.push_back(path->GetPointer());
|
setPathways->paths.push_back(path->GetPointer());
|
||||||
|
setPathways->pathFileNames.push_back(pathFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CVarGetInteger(CVAR_DEVELOPER_TOOLS("ResourceLogging"), 0)) {
|
if (CVarGetInteger(CVAR_DEVELOPER_TOOLS("ResourceLogging"), 0)) {
|
||||||
|
33
soh/soh/resource/logging/PathLogger.cpp
Normal file
33
soh/soh/resource/logging/PathLogger.cpp
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#include "soh/resource/type/Path.h"
|
||||||
|
#include "spdlog/spdlog.h"
|
||||||
|
|
||||||
|
namespace SOH {
|
||||||
|
void LogPathAsXML(std::shared_ptr<Ship::IResource> resource) {
|
||||||
|
std::shared_ptr<Path> path = std::static_pointer_cast<Path>(resource);
|
||||||
|
|
||||||
|
tinyxml2::XMLDocument doc;
|
||||||
|
tinyxml2::XMLElement* root = doc.NewElement("Path");
|
||||||
|
doc.InsertFirstChild(root);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < path->paths.size(); i += 1) {
|
||||||
|
tinyxml2::XMLElement* pathData = doc.NewElement("PathData");
|
||||||
|
|
||||||
|
for (size_t j = 0; j < path->paths[i].size(); j += 1) {
|
||||||
|
tinyxml2::XMLElement* pathPoint = doc.NewElement("PathPoint");
|
||||||
|
|
||||||
|
pathPoint->SetAttribute("X", path->paths[i][j].x);
|
||||||
|
pathPoint->SetAttribute("Y", path->paths[i][j].y);
|
||||||
|
pathPoint->SetAttribute("Z", path->paths[i][j].z);
|
||||||
|
|
||||||
|
pathData->InsertEndChild(pathPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
root->InsertEndChild(pathData);
|
||||||
|
}
|
||||||
|
|
||||||
|
tinyxml2::XMLPrinter printer;
|
||||||
|
doc.Accept(&printer);
|
||||||
|
|
||||||
|
SPDLOG_INFO("{}: {}", resource->GetInitData()->Path, printer.CStr());
|
||||||
|
}
|
||||||
|
}
|
6
soh/soh/resource/logging/PathLogger.h
Normal file
6
soh/soh/resource/logging/PathLogger.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include "Resource.h"
|
||||||
|
#include "soh/OTRGlobals.h"
|
||||||
|
|
||||||
|
namespace SOH {
|
||||||
|
void LogPathAsXML(std::shared_ptr<Ship::IResource> resource);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user