Merge pull request #230 from Laupetin/fix/game-name-case-insensitive

fix: make game name case insensitive
This commit is contained in:
Jan 2024-08-12 10:06:37 +02:00 committed by GitHub
commit 254918acca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 46 additions and 37 deletions

View File

@ -5,6 +5,7 @@
#include "Game/T6/GameT6.h" #include "Game/T6/GameT6.h"
#include "Game/T6/T6.h" #include "Game/T6/T6.h"
#include "ObjLoading.h" #include "ObjLoading.h"
#include "Utils/StringUtils.h"
#include <iostream> #include <iostream>
@ -108,7 +109,10 @@ void ZoneCreator::HandleMetadata(Zone* zone, const ZoneCreationContext& context)
bool ZoneCreator::SupportsGame(const std::string& gameName) const bool ZoneCreator::SupportsGame(const std::string& gameName) const
{ {
return gameName == g_GameT6.GetShortName(); auto shortName = g_GameT6.GetShortName();
utils::MakeStringLowerCase(shortName);
return gameName == shortName;
} }
std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const

View File

@ -27,6 +27,7 @@
#include <deque> #include <deque>
#include <filesystem> #include <filesystem>
#include <format>
#include <fstream> #include <fstream>
#include <regex> #include <regex>
#include <set> #include <set>
@ -58,10 +59,10 @@ constexpr const char* PROJECT_TYPE_NAMES[static_cast<unsigned>(ProjectType::MAX)
class LinkerImpl final : public Linker class LinkerImpl final : public Linker
{ {
static constexpr const char* METADATA_GAME = "game"; static constexpr auto METADATA_GAME = "game";
static constexpr const char* METADATA_GDT = "gdt"; static constexpr auto METADATA_GDT = "gdt";
static constexpr const char* METADATA_NAME = "name"; static constexpr auto METADATA_NAME = "name";
static constexpr const char* METADATA_TYPE = "type"; static constexpr auto METADATA_TYPE = "type";
LinkerArgs m_args; LinkerArgs m_args;
LinkerSearchPaths m_search_paths; LinkerSearchPaths m_search_paths;
@ -86,11 +87,11 @@ class LinkerImpl final : public Linker
std::unique_ptr<ZoneDefinition> includeDefinition; std::unique_ptr<ZoneDefinition> includeDefinition;
{ {
const auto definitionFileName = source + ".zone"; const auto definitionFileName = std::format("{}.zone", source);
const auto definitionStream = sourceSearchPath->Open(definitionFileName); const auto definitionStream = sourceSearchPath->Open(definitionFileName);
if (!definitionStream.IsOpen()) if (!definitionStream.IsOpen())
{ {
std::cout << "Could not find zone definition file for project \"" << source << "\".\n"; std::cerr << std::format("Could not find zone definition file for project \"{}\".\n", source);
return false; return false;
} }
@ -100,7 +101,7 @@ class LinkerImpl final : public Linker
if (!includeDefinition) if (!includeDefinition)
{ {
std::cout << "Failed to read zone definition file for project \"" << source << "\".\n"; std::cerr << std::format("Failed to read zone definition file for project \"{}\".\n", source);
return false; return false;
} }
@ -119,7 +120,7 @@ class LinkerImpl final : public Linker
bool ReadAssetList(const std::string& zoneName, AssetList& assetList, ISearchPath* sourceSearchPath) const bool ReadAssetList(const std::string& zoneName, AssetList& assetList, ISearchPath* sourceSearchPath) const
{ {
{ {
const auto assetListFileName = "assetlist/" + zoneName + ".csv"; const auto assetListFileName = std::format("assetlist/{}.csv", zoneName);
const auto assetListStream = sourceSearchPath->Open(assetListFileName); const auto assetListStream = sourceSearchPath->Open(assetListFileName);
if (assetListStream.IsOpen()) if (assetListStream.IsOpen())
@ -158,7 +159,7 @@ class LinkerImpl final : public Linker
AssetList assetList; AssetList assetList;
if (!ReadAssetList(assetListName, assetList, sourceSearchPath)) if (!ReadAssetList(assetListName, assetList, sourceSearchPath))
{ {
std::cerr << "Failed to read asset list \"" << assetListName << "\"\n"; std::cerr << std::format("Failed to read asset list \"{}\"\n", assetListName);
return false; return false;
} }
@ -183,7 +184,7 @@ class LinkerImpl final : public Linker
{ {
if (name != i->second->m_value) if (name != i->second->m_value)
{ {
std::cout << "Conflicting names in target \"" << targetName << "\": " << name << " != " << i->second << "\n"; std::cerr << std::format("Conflicting names in target \"{}\": {} != {}\n", targetName, name, i->second->m_value);
return false; return false;
} }
} }
@ -203,7 +204,7 @@ class LinkerImpl final : public Linker
const auto definitionStream = sourceSearchPath->Open(definitionFileName); const auto definitionStream = sourceSearchPath->Open(definitionFileName);
if (!definitionStream.IsOpen()) if (!definitionStream.IsOpen())
{ {
std::cout << "Could not find zone definition file for target \"" << targetName << "\".\n"; std::cerr << std::format("Could not find zone definition file for target \"{}\".\n", targetName);
return nullptr; return nullptr;
} }
@ -213,7 +214,7 @@ class LinkerImpl final : public Linker
if (!zoneDefinition) if (!zoneDefinition)
{ {
std::cout << "Failed to read zone definition file for target \"" << targetName << "\".\n"; std::cerr << std::format("Failed to read zone definition file for target \"{}\".\n", targetName);
return nullptr; return nullptr;
} }
@ -248,7 +249,7 @@ class LinkerImpl final : public Linker
std::vector<AssetListEntry> assetList; std::vector<AssetListEntry> assetList;
if (!ReadAssetList(ignore, context.m_ignored_assets, sourceSearchPath)) if (!ReadAssetList(ignore, context.m_ignored_assets, sourceSearchPath))
{ {
std::cout << "Failed to read asset listing for ignoring assets of project \"" << ignore << "\".\n"; std::cerr << std::format("Failed to read asset listing for ignoring assets of project \"{}\".\n", ignore);
return false; return false;
} }
} }
@ -278,7 +279,7 @@ class LinkerImpl final : public Linker
ProjectType parsedProjectType; ProjectType parsedProjectType;
if (!ProjectTypeByName(parsedProjectType, i->second->m_value)) if (!ProjectTypeByName(parsedProjectType, i->second->m_value))
{ {
std::cerr << "Not a valid project type: \"" << i->second->m_value << "\"\n"; std::cerr << std::format("Not a valid project type: \"{}\"\n", i->second->m_value);
return false; return false;
} }
@ -291,8 +292,10 @@ class LinkerImpl final : public Linker
{ {
if (projectType != parsedProjectType) if (projectType != parsedProjectType)
{ {
std::cerr << "Conflicting types in target \"" << targetName << "\": " << PROJECT_TYPE_NAMES[static_cast<unsigned>(projectType)] std::cerr << std::format("Conflicting types in target \"{}\": {} != {}\n",
<< " != " << PROJECT_TYPE_NAMES[static_cast<unsigned>(parsedProjectType)] << "\n"; targetName,
PROJECT_TYPE_NAMES[static_cast<unsigned>(projectType)],
PROJECT_TYPE_NAMES[static_cast<unsigned>(parsedProjectType)]);
return false; return false;
} }
} }
@ -324,7 +327,7 @@ class LinkerImpl final : public Linker
{ {
if (gameName != i->second->m_value) if (gameName != i->second->m_value)
{ {
std::cout << "Conflicting game names in target \"" << targetName << "\": " << gameName << " != " << i->second << "\n"; std::cerr << std::format("Conflicting game names in target \"{}\": {} != {}\n", targetName, gameName, i->second->m_value);
return false; return false;
} }
} }
@ -332,7 +335,7 @@ class LinkerImpl final : public Linker
if (firstGameEntry) if (firstGameEntry)
{ {
std::cout << "No game name was specified for target \"" << targetName << "\"\n"; std::cerr << std::format("No game name was specified for target \"{}\"\n", targetName);
return false; return false;
} }
@ -347,7 +350,7 @@ class LinkerImpl final : public Linker
const auto gdtFile = gdtSearchPath->Open(i->second->m_value + ".gdt"); const auto gdtFile = gdtSearchPath->Open(i->second->m_value + ".gdt");
if (!gdtFile.IsOpen()) if (!gdtFile.IsOpen())
{ {
std::cout << "Failed to open file for gdt \"" << i->second->m_value << "\"\n"; std::cerr << std::format("Failed to open file for gdt \"{}\"\n", i->second->m_value);
return false; return false;
} }
@ -355,7 +358,7 @@ class LinkerImpl final : public Linker
auto gdt = std::make_unique<Gdt>(); auto gdt = std::make_unique<Gdt>();
if (!gdtReader.Read(*gdt)) if (!gdtReader.Read(*gdt))
{ {
std::cout << "Failed to read gdt file \"" << i->second << "\"\n"; std::cerr << std::format("Failed to read gdt file \"{}\"\n", i->second->m_value);
return false; return false;
} }
@ -376,15 +379,17 @@ class LinkerImpl final : public Linker
return nullptr; return nullptr;
if (!GetGameNameFromZoneDefinition(context->m_game_name, targetName, zoneDefinition)) if (!GetGameNameFromZoneDefinition(context->m_game_name, targetName, zoneDefinition))
return nullptr; return nullptr;
utils::MakeStringLowerCase(context->m_game_name);
if (!LoadGdtFilesFromZoneDefinition(context->m_gdt_files, zoneDefinition, gdtSearchPath)) if (!LoadGdtFilesFromZoneDefinition(context->m_gdt_files, zoneDefinition, gdtSearchPath))
return nullptr; return nullptr;
for (const auto* assetLoader : ZONE_CREATORS) for (const auto* zoneCreator : ZONE_CREATORS)
{ {
if (assetLoader->SupportsGame(context->m_game_name)) if (zoneCreator->SupportsGame(context->m_game_name))
return assetLoader->CreateZoneForDefinition(*context); return zoneCreator->CreateZoneForDefinition(*context);
} }
std::cerr << std::format("Unsupported game: {}\n", context->m_game_name);
return nullptr; return nullptr;
} }
@ -402,12 +407,12 @@ class LinkerImpl final : public Linker
if (!ZoneWriting::WriteZone(stream, zone)) if (!ZoneWriting::WriteZone(stream, zone))
{ {
std::cout << "Writing zone failed.\n"; std::cerr << "Writing zone failed.\n";
stream.close(); stream.close();
return false; return false;
} }
std::cout << "Created zone \"" << zoneFilePath.string() << "\"\n"; std::cout << std::format("Created zone \"{}\"\n", zoneFilePath.string());
stream.close(); stream.close();
return true; return true;
@ -454,12 +459,12 @@ class LinkerImpl final : public Linker
if (!ipakWriter->Write()) if (!ipakWriter->Write())
{ {
std::cout << "Writing ipak failed.\n"; std::cerr << "Writing ipak failed.\n";
stream.close(); stream.close();
return false; return false;
} }
std::cout << "Created ipak \"" << ipakFilePath.string() << "\"\n"; std::cout << std::format("Created ipak \"{}\"\n", ipakFilePath.string());
stream.close(); stream.close();
return true; return true;
@ -472,11 +477,11 @@ class LinkerImpl final : public Linker
{ {
if (buildTargetName == targetName) if (buildTargetName == targetName)
{ {
std::cerr << "Cannot build target with same name: \"" << targetName << "\"\n"; std::cerr << std::format("Cannot build target with same name: \"{}\"\n", targetName);
return false; return false;
} }
std::cout << "Building referenced target \"" << buildTargetName << "\"\n"; std::cout << std::format("Building referenced target \"{}\"\n", buildTargetName);
return BuildProject(projectName, buildTargetName); return BuildProject(projectName, buildTargetName);
}); });
} }
@ -534,7 +539,7 @@ class LinkerImpl final : public Linker
{ {
if (!fs::is_regular_file(zonePath)) if (!fs::is_regular_file(zonePath))
{ {
std::cout << "Could not find zone file to load \"" << zonePath << "\".\n"; std::cerr << std::format("Could not find zone file to load \"{}\".\n", zonePath);
return false; return false;
} }
@ -543,13 +548,13 @@ class LinkerImpl final : public Linker
auto zone = std::unique_ptr<Zone>(ZoneLoading::LoadZone(zonePath)); auto zone = std::unique_ptr<Zone>(ZoneLoading::LoadZone(zonePath));
if (zone == nullptr) if (zone == nullptr)
{ {
std::cout << "Failed to load zone \"" << zonePath << "\".\n"; std::cerr << std::format("Failed to load zone \"{}\".\n", zonePath);
return false; return false;
} }
if (m_args.m_verbose) if (m_args.m_verbose)
{ {
std::cout << "Load zone \"" << zone->m_name << "\"\n"; std::cout << std::format("Load zone \"{}\"\n", zone->m_name);
} }
m_loaded_zones.emplace_back(std::move(zone)); m_loaded_zones.emplace_back(std::move(zone));
@ -568,7 +573,7 @@ class LinkerImpl final : public Linker
loadedZone.reset(); loadedZone.reset();
if (m_args.m_verbose) if (m_args.m_verbose)
std::cout << "Unloaded zone \"" << zoneName << "\"\n"; std::cout << std::format("Unloaded zone \"{}\"\n", zoneName);
} }
m_loaded_zones.clear(); m_loaded_zones.clear();
} }
@ -583,7 +588,7 @@ class LinkerImpl final : public Linker
} }
else if (projectSpecifier.find_first_of('/', targetNameSeparatorIndex + 1) != std::string::npos) else if (projectSpecifier.find_first_of('/', targetNameSeparatorIndex + 1) != std::string::npos)
{ {
std::cerr << "Project specifier cannot have more than one target name: \"" << projectSpecifier << "\"\n"; std::cerr << std::format("Project specifier cannot have more than one target name: \"{}\"\n", projectSpecifier);
return false; return false;
} }
else else
@ -594,13 +599,13 @@ class LinkerImpl final : public Linker
if (projectName.empty()) if (projectName.empty())
{ {
std::cerr << "Project name cannot be empty: \"" << projectSpecifier << "\"\n"; std::cerr << std::format("Project name cannot be empty: \"{}\"\n", projectSpecifier);
return false; return false;
} }
if (targetName.empty()) if (targetName.empty())
{ {
std::cerr << "Target name cannot be empty: \"" << projectSpecifier << "\"\n"; std::cerr << std::format("Target name cannot be empty: \"{}\"\n", projectSpecifier);
return false; return false;
} }