diff --git a/src/Linker/Game/IW3/ZoneCreatorIW3.cpp b/src/Linker/Game/IW3/ZoneCreatorIW3.cpp index b43561564..23d230c2b 100644 --- a/src/Linker/Game/IW3/ZoneCreatorIW3.cpp +++ b/src/Linker/Game/IW3/ZoneCreatorIW3.cpp @@ -64,7 +64,7 @@ bool ZoneCreator::SupportsGame(const std::string& gameName) const std::unique_ptr ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const { - auto zone = std::make_unique(context.m_zone_name, 0, &g_GameIW3); + auto zone = std::make_unique(context.m_definition->m_name, 0, &g_GameIW3); CreateZoneAssetPools(zone.get()); for (const auto& assetEntry : context.m_definition->m_assets) diff --git a/src/Linker/Game/IW4/ZoneCreatorIW4.cpp b/src/Linker/Game/IW4/ZoneCreatorIW4.cpp index b14fe3086..3f1751684 100644 --- a/src/Linker/Game/IW4/ZoneCreatorIW4.cpp +++ b/src/Linker/Game/IW4/ZoneCreatorIW4.cpp @@ -63,7 +63,7 @@ bool ZoneCreator::SupportsGame(const std::string& gameName) const std::unique_ptr ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const { - auto zone = std::make_unique(context.m_zone_name, 0, &g_GameIW4); + auto zone = std::make_unique(context.m_definition->m_name, 0, &g_GameIW4); CreateZoneAssetPools(zone.get()); for (const auto& assetEntry : context.m_definition->m_assets) diff --git a/src/Linker/Game/IW5/ZoneCreatorIW5.cpp b/src/Linker/Game/IW5/ZoneCreatorIW5.cpp index 62e93ac87..9a1b1ac24 100644 --- a/src/Linker/Game/IW5/ZoneCreatorIW5.cpp +++ b/src/Linker/Game/IW5/ZoneCreatorIW5.cpp @@ -63,7 +63,7 @@ bool ZoneCreator::SupportsGame(const std::string& gameName) const std::unique_ptr ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const { - auto zone = std::make_unique(context.m_zone_name, 0, &g_GameIW5); + auto zone = std::make_unique(context.m_definition->m_name, 0, &g_GameIW5); CreateZoneAssetPools(zone.get()); for (const auto& assetEntry : context.m_definition->m_assets) diff --git a/src/Linker/Game/T5/ZoneCreatorT5.cpp b/src/Linker/Game/T5/ZoneCreatorT5.cpp index 2826f2580..7bd314781 100644 --- a/src/Linker/Game/T5/ZoneCreatorT5.cpp +++ b/src/Linker/Game/T5/ZoneCreatorT5.cpp @@ -64,7 +64,7 @@ bool ZoneCreator::SupportsGame(const std::string& gameName) const std::unique_ptr ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const { - auto zone = std::make_unique(context.m_zone_name, 0, &g_GameT5); + auto zone = std::make_unique(context.m_definition->m_name, 0, &g_GameT5); CreateZoneAssetPools(zone.get()); for (const auto& assetEntry : context.m_definition->m_assets) diff --git a/src/Linker/Game/T6/ZoneCreatorT6.cpp b/src/Linker/Game/T6/ZoneCreatorT6.cpp index 965d6f44b..90f5f14d8 100644 --- a/src/Linker/Game/T6/ZoneCreatorT6.cpp +++ b/src/Linker/Game/T6/ZoneCreatorT6.cpp @@ -118,7 +118,7 @@ bool ZoneCreator::SupportsGame(const std::string& gameName) const std::unique_ptr ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const { - auto zone = std::make_unique(context.m_zone_name, 0, &g_GameT6); + auto zone = std::make_unique(context.m_definition->m_name, 0, &g_GameT6); CreateZoneAssetPools(zone.get()); for (const auto& assetEntry : context.m_definition->m_assets) diff --git a/src/Linker/Linker.cpp b/src/Linker/Linker.cpp index 58e8edf64..511b881bf 100644 --- a/src/Linker/Linker.cpp +++ b/src/Linker/Linker.cpp @@ -42,6 +42,7 @@ const IZoneCreator* const ZONE_CREATORS[] class Linker::Impl { + static constexpr const char* METADATA_NAME = "name"; static constexpr const char* METADATA_GAME = "game"; static constexpr const char* METADATA_GDT = "gdt"; @@ -277,6 +278,33 @@ class Linker::Impl return true; } + static bool GetNameFromZoneDefinition(std::string& name, const std::string& projectName, const ZoneDefinition& zoneDefinition) + { + auto firstNameEntry = true; + const auto [rangeBegin, rangeEnd] = zoneDefinition.m_metadata_lookup.equal_range(METADATA_NAME); + for (auto i = rangeBegin; i != rangeEnd; ++i) + { + if (firstNameEntry) + { + name = i->second->m_value; + firstNameEntry = false; + } + else + { + if (name != i->second->m_value) + { + std::cout << "Conflicting names in project \"" << projectName << "\": " << name << " != " << i->second << std::endl; + return false; + } + } + } + + if (firstNameEntry) + name = projectName; + + return true; + } + std::unique_ptr ReadZoneDefinition(const std::string& projectName, ISearchPath* sourceSearchPath) const { std::unique_ptr zoneDefinition; @@ -299,6 +327,9 @@ class Linker::Impl return nullptr; } + if (!GetNameFromZoneDefinition(zoneDefinition->m_name, projectName, *zoneDefinition)) + return nullptr; + if (!IncludeAdditionalZoneDefinitions(projectName, *zoneDefinition, sourceSearchPath)) return nullptr; @@ -425,7 +456,7 @@ class Linker::Impl std::unique_ptr CreateZoneForDefinition(const std::string& projectName, ZoneDefinition& zoneDefinition, ISearchPath* assetSearchPath, ISearchPath* gdtSearchPath, ISearchPath* sourceSearchPath) const { - auto context = std::make_unique(projectName, assetSearchPath, &zoneDefinition); + const auto context = std::make_unique(assetSearchPath, &zoneDefinition); if (!ProcessZoneDefinitionIgnores(projectName, *context, sourceSearchPath)) return nullptr; if (!GetGameNameFromZoneDefinition(context->m_game_name, projectName, zoneDefinition)) @@ -461,6 +492,8 @@ class Linker::Impl return false; } + std::cout << "Created zone \"" << zoneFilePath.string() << "\"\n"; + stream.close(); return true; } diff --git a/src/Linker/ZoneCreation/ZoneCreationContext.cpp b/src/Linker/ZoneCreation/ZoneCreationContext.cpp index d63a82be1..481816943 100644 --- a/src/Linker/ZoneCreation/ZoneCreationContext.cpp +++ b/src/Linker/ZoneCreation/ZoneCreationContext.cpp @@ -6,9 +6,8 @@ ZoneCreationContext::ZoneCreationContext() { } -ZoneCreationContext::ZoneCreationContext(std::string zoneName, ISearchPath* assetSearchPath, ZoneDefinition* definition) - : m_zone_name(std::move(zoneName)), - m_asset_search_path(assetSearchPath), +ZoneCreationContext::ZoneCreationContext(ISearchPath* assetSearchPath, ZoneDefinition* definition) + : m_asset_search_path(assetSearchPath), m_definition(definition) { } diff --git a/src/Linker/ZoneCreation/ZoneCreationContext.h b/src/Linker/ZoneCreation/ZoneCreationContext.h index d03ccbde6..2db20e1d4 100644 --- a/src/Linker/ZoneCreation/ZoneCreationContext.h +++ b/src/Linker/ZoneCreation/ZoneCreationContext.h @@ -12,7 +12,6 @@ class ZoneCreationContext { public: - std::string m_zone_name; std::string m_game_name; ISearchPath* m_asset_search_path; ZoneDefinition* m_definition; @@ -20,5 +19,5 @@ class ZoneCreationContext std::vector m_ignored_assets; ZoneCreationContext(); - ZoneCreationContext(std::string zoneName, ISearchPath* assetSearchPath, ZoneDefinition* definition); + ZoneCreationContext(ISearchPath* assetSearchPath, ZoneDefinition* definition); }; diff --git a/src/ZoneCommon/Zone/Definition/ZoneDefinition.h b/src/ZoneCommon/Zone/Definition/ZoneDefinition.h index ee6ccdeab..2a093f8dc 100644 --- a/src/ZoneCommon/Zone/Definition/ZoneDefinition.h +++ b/src/ZoneCommon/Zone/Definition/ZoneDefinition.h @@ -29,6 +29,7 @@ class ZoneMetaDataEntry class ZoneDefinition { public: + std::string m_name; std::vector> m_metadata; std::unordered_multimap m_metadata_lookup; std::vector m_includes;