#include "TrackPathPointFactory.h" #include "../type/TrackPathPointData.h" #include "spdlog/spdlog.h" #include "libultraship/libultra/gbi.h" #include "tinyxml2.h" namespace MK64 { std::shared_ptr ResourceFactoryBinaryTrackPathPointsV0::ReadResource(std::shared_ptr file, std::shared_ptr initData) { if (!FileHasValidFormatAndReader(file, initData)) { return nullptr; } auto section = std::make_shared(initData); auto reader = std::get>(file->Reader); uint32_t count = reader->ReadUInt32(); section->TrackPathPointList.reserve(count); for (uint32_t i = 0; i < count; i++) { TrackPathPoint data; data.x = reader->ReadInt16(); data.y = reader->ReadInt16(); data.z = reader->ReadInt16(); data.trackSectionId = reader->ReadUInt16(); section->TrackPathPointList.push_back(data); } return section; } std::shared_ptr ResourceFactoryXMLTrackPathPointsV0::ReadResource(std::shared_ptr file, std::shared_ptr initData) { if (!FileHasValidFormatAndReader(file, initData)) { return nullptr; } auto paths = std::make_shared(initData); auto root = std::get>(file->Reader)->FirstChildElement(); auto path = root->FirstChildElement("TrackWaypoint"); while (path != nullptr) { std::vector waypointPath; // Temporary container for this path int32_t pathIndex = path->IntAttribute("type", 0); // Default to 0 if not set auto pointElem = path->FirstChildElement("Point"); while (pointElem != nullptr) { TrackPathPoint point; point.x = pointElem->IntAttribute("X"); point.y = pointElem->IntAttribute("Y"); point.z = pointElem->IntAttribute("Z"); point.trackSectionId = pointElem->IntAttribute("ID"); waypointPath.push_back(point); // Push to temp vector pointElem = pointElem->NextSiblingElement("Point"); } paths->PathObject.push_back({waypointPath, pathIndex});// PathList.push_back(waypointPath); // Push full path to outer list path = path->NextSiblingElement("TrackPathPoint"); } return paths; } } // namespace MK64