From d662e5dcfa462818395a705884872bed3f093da9 Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 26 Sep 2019 22:35:59 +0200 Subject: [PATCH] Implement ZoneLoading in ZoneLoading component class --- src/Unlinker/main.cpp | 3 ++- src/ZoneLoading/ZoneLoading.cpp | 41 +++++++++++++++++++++++++++++++-- src/ZoneLoading/ZoneLoading.h | 3 ++- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/Unlinker/main.cpp b/src/Unlinker/main.cpp index 1ee7830e..c96b7439 100644 --- a/src/Unlinker/main.cpp +++ b/src/Unlinker/main.cpp @@ -79,7 +79,8 @@ int main(const int argc, const char** argv) { const std::string& zonePath = arguments[argIndex]; - if(!ZoneLoading::LoadZone(zonePath)) + Zone* zone = ZoneLoading::LoadZone(zonePath); + if(zone == nullptr) { printf("Failed to load zone '%s'.\n", zonePath.c_str()); return 1; diff --git a/src/ZoneLoading/ZoneLoading.cpp b/src/ZoneLoading/ZoneLoading.cpp index c149b756..5ae4af57 100644 --- a/src/ZoneLoading/ZoneLoading.cpp +++ b/src/ZoneLoading/ZoneLoading.cpp @@ -1,6 +1,43 @@ #include "ZoneLoading.h" +#include "Game/T6/ZoneLoaderFactoryT6.h" +#include "Utils/PathUtils.h" -bool ZoneLoading::LoadZone(const std::string& path) +IZoneLoaderFactory* zoneLoaderFactories[] { - return false; + new ZoneLoaderFactoryT6() +}; + +Zone* ZoneLoading::LoadZone(const std::string& path) +{ + std::string zoneName = utils::Path::GetFilenameWithoutExtension(path); + FileAPI::File file = FileAPI::Open(path, FileAPI::MODE_READ); + + if(!file.IsOpen()) + { + printf("Could not open file '%s'.\n", path.c_str()); + return nullptr; + } + + ZoneHeader header{}; + file.Read(&header, sizeof(ZoneHeader), 1); + + ZoneLoader* zoneLoader = nullptr; + for(auto factory : zoneLoaderFactories) + { + zoneLoader = factory->CreateLoaderForHeader(header, zoneName); + + if(zoneLoader != nullptr) + break; + } + + if(zoneLoader == nullptr) + { + printf("Could not create factory for zone '%s'.\n", zoneName.c_str()); + return nullptr; + } + + Zone* loadedZone = zoneLoader->LoadZone(&file); + + file.Close(); + return loadedZone; } \ No newline at end of file diff --git a/src/ZoneLoading/ZoneLoading.h b/src/ZoneLoading/ZoneLoading.h index 85e38cbd..293bb4b0 100644 --- a/src/ZoneLoading/ZoneLoading.h +++ b/src/ZoneLoading/ZoneLoading.h @@ -1,8 +1,9 @@ #pragma once +#include "Zone/Zone.h" #include class ZoneLoading { public: - static bool LoadZone(const std::string& path); + static Zone* LoadZone(const std::string& path); };