Implement ZoneLoading in ZoneLoading component class

This commit is contained in:
Jan 2019-09-26 22:35:59 +02:00
parent 36cc8d3065
commit d662e5dcfa
3 changed files with 43 additions and 4 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -1,8 +1,9 @@
#pragma once
#include "Zone/Zone.h"
#include <string>
class ZoneLoading
{
public:
static bool LoadZone(const std::string& path);
static Zone* LoadZone(const std::string& path);
};