Add possibility to override zone name in zone definition

This commit is contained in:
Jan 2023-09-28 20:52:16 +02:00
parent e36367fe01
commit bb94162be4
9 changed files with 43 additions and 11 deletions

View File

@ -64,7 +64,7 @@ bool ZoneCreator::SupportsGame(const std::string& gameName) const
std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const
{
auto zone = std::make_unique<Zone>(context.m_zone_name, 0, &g_GameIW3);
auto zone = std::make_unique<Zone>(context.m_definition->m_name, 0, &g_GameIW3);
CreateZoneAssetPools(zone.get());
for (const auto& assetEntry : context.m_definition->m_assets)

View File

@ -63,7 +63,7 @@ bool ZoneCreator::SupportsGame(const std::string& gameName) const
std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const
{
auto zone = std::make_unique<Zone>(context.m_zone_name, 0, &g_GameIW4);
auto zone = std::make_unique<Zone>(context.m_definition->m_name, 0, &g_GameIW4);
CreateZoneAssetPools(zone.get());
for (const auto& assetEntry : context.m_definition->m_assets)

View File

@ -63,7 +63,7 @@ bool ZoneCreator::SupportsGame(const std::string& gameName) const
std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const
{
auto zone = std::make_unique<Zone>(context.m_zone_name, 0, &g_GameIW5);
auto zone = std::make_unique<Zone>(context.m_definition->m_name, 0, &g_GameIW5);
CreateZoneAssetPools(zone.get());
for (const auto& assetEntry : context.m_definition->m_assets)

View File

@ -64,7 +64,7 @@ bool ZoneCreator::SupportsGame(const std::string& gameName) const
std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const
{
auto zone = std::make_unique<Zone>(context.m_zone_name, 0, &g_GameT5);
auto zone = std::make_unique<Zone>(context.m_definition->m_name, 0, &g_GameT5);
CreateZoneAssetPools(zone.get());
for (const auto& assetEntry : context.m_definition->m_assets)

View File

@ -118,7 +118,7 @@ bool ZoneCreator::SupportsGame(const std::string& gameName) const
std::unique_ptr<Zone> ZoneCreator::CreateZoneForDefinition(ZoneCreationContext& context) const
{
auto zone = std::make_unique<Zone>(context.m_zone_name, 0, &g_GameT6);
auto zone = std::make_unique<Zone>(context.m_definition->m_name, 0, &g_GameT6);
CreateZoneAssetPools(zone.get());
for (const auto& assetEntry : context.m_definition->m_assets)

View File

@ -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<ZoneDefinition> ReadZoneDefinition(const std::string& projectName, ISearchPath* sourceSearchPath) const
{
std::unique_ptr<ZoneDefinition> 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<Zone> CreateZoneForDefinition(const std::string& projectName, ZoneDefinition& zoneDefinition, ISearchPath* assetSearchPath, ISearchPath* gdtSearchPath,
ISearchPath* sourceSearchPath) const
{
auto context = std::make_unique<ZoneCreationContext>(projectName, assetSearchPath, &zoneDefinition);
const auto context = std::make_unique<ZoneCreationContext>(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;
}

View File

@ -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)
{
}

View File

@ -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 @@ public:
std::vector<AssetListEntry> m_ignored_assets;
ZoneCreationContext();
ZoneCreationContext(std::string zoneName, ISearchPath* assetSearchPath, ZoneDefinition* definition);
ZoneCreationContext(ISearchPath* assetSearchPath, ZoneDefinition* definition);
};

View File

@ -29,6 +29,7 @@ public:
class ZoneDefinition
{
public:
std::string m_name;
std::vector<std::unique_ptr<ZoneMetaDataEntry>> m_metadata;
std::unordered_multimap<std::string, ZoneMetaDataEntry*> m_metadata_lookup;
std::vector<std::string> m_includes;