mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-07-04 23:00:04 +00:00
chore: use method static array for zoneloaderfactory
This commit is contained in:
@@ -1,34 +1,24 @@
|
||||
#include "ZoneLoading.h"
|
||||
|
||||
#include "Game/IW3/ZoneLoaderFactoryIW3.h"
|
||||
#include "Game/IW4/ZoneLoaderFactoryIW4.h"
|
||||
#include "Game/IW5/ZoneLoaderFactoryIW5.h"
|
||||
#include "Game/T5/ZoneLoaderFactoryT5.h"
|
||||
#include "Game/T6/ZoneLoaderFactoryT6.h"
|
||||
#include "Loading/IZoneLoaderFactory.h"
|
||||
#include "Loading/ZoneLoader.h"
|
||||
#include "Utils/ObjFileStream.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <format>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
IZoneLoaderFactory* ZoneLoaderFactories[]{
|
||||
new IW3::ZoneLoaderFactory(),
|
||||
new IW4::ZoneLoaderFactory(),
|
||||
new IW5::ZoneLoaderFactory(),
|
||||
new T5::ZoneLoaderFactory(),
|
||||
new T6::ZoneLoaderFactory(),
|
||||
};
|
||||
|
||||
std::unique_ptr<Zone> ZoneLoading::LoadZone(const std::string& path)
|
||||
{
|
||||
auto zoneName = fs::path(path).filename().replace_extension("").string();
|
||||
auto zoneName = fs::path(path).filename().replace_extension().string();
|
||||
std::ifstream file(path, std::fstream::in | std::fstream::binary);
|
||||
|
||||
if (!file.is_open())
|
||||
{
|
||||
printf("Could not open file '%s'.\n", path.c_str());
|
||||
std::cerr << std::format("Could not open file '{}'.\n", path);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -36,27 +26,27 @@ std::unique_ptr<Zone> ZoneLoading::LoadZone(const std::string& path)
|
||||
file.read(reinterpret_cast<char*>(&header), sizeof(header));
|
||||
if (file.gcount() != sizeof(header))
|
||||
{
|
||||
std::cout << "Failed to read zone header from file '" << path << "'.\n";
|
||||
std::cerr << std::format("Failed to read zone header from file '{}'.\n", path);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ZoneLoader* zoneLoader = nullptr;
|
||||
for (auto* factory : ZoneLoaderFactories)
|
||||
std::unique_ptr<ZoneLoader> zoneLoader;
|
||||
for (auto game = 0u; game < static_cast<unsigned>(GameId::COUNT); game++)
|
||||
{
|
||||
const auto* factory = IZoneLoaderFactory::GetZoneLoaderFactoryForGame(static_cast<GameId>(game));
|
||||
zoneLoader = factory->CreateLoaderForHeader(header, zoneName);
|
||||
|
||||
if (zoneLoader != nullptr)
|
||||
if (zoneLoader)
|
||||
break;
|
||||
}
|
||||
|
||||
if (zoneLoader == nullptr)
|
||||
if (!zoneLoader)
|
||||
{
|
||||
printf("Could not create factory for zone '%s'.\n", zoneName.c_str());
|
||||
std::cerr << std::format("Could not create factory for zone '{}'.\n", zoneName);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto loadedZone = zoneLoader->LoadZone(file);
|
||||
delete zoneLoader;
|
||||
|
||||
file.close();
|
||||
return std::move(loadedZone);
|
||||
|
||||
Reference in New Issue
Block a user