43 lines
1.3 KiB
C++
43 lines
1.3 KiB
C++
#include "World/WorldMapDefinition.h"
|
|
|
|
// Direct-initialised from an explicit FName: copy-initialising from a string literal would need two
|
|
// user-defined conversions (TCHAR* -> FName -> FPrimaryAssetType), which the language does not allow.
|
|
const FPrimaryAssetType UWorldMapDefinition::AssetType(FName("WorldMap"));
|
|
|
|
const FWorldMapLayer* UWorldMapDefinition::FindLayer(FName Id) const
|
|
{
|
|
return Layers.FindByPredicate([Id](const FWorldMapLayer& Layer) { return Layer.Id == Id; });
|
|
}
|
|
|
|
const FWorldMapLayer* UWorldMapDefinition::ResolveDefaultLayer() const
|
|
{
|
|
if (const FWorldMapLayer* Named = FindLayer(DefaultLayer))
|
|
{
|
|
return Named;
|
|
}
|
|
return Layers.Num() > 0 ? &Layers[0] : nullptr;
|
|
}
|
|
|
|
FName UWorldMapDefinition::NextLayerId(FName Id) const
|
|
{
|
|
if (Layers.Num() == 0)
|
|
{
|
|
return NAME_None;
|
|
}
|
|
const int32 Index = Layers.IndexOfByPredicate([Id](const FWorldMapLayer& Layer) { return Layer.Id == Id; });
|
|
// An unknown id lands on the first layer rather than on nothing, so a stale name in a saved setting
|
|
// recovers on the next press instead of leaving the map blank.
|
|
return Layers[Index == INDEX_NONE ? 0 : (Index + 1) % Layers.Num()].Id;
|
|
}
|
|
|
|
TArray<FName> UWorldMapDefinition::GetLayerIds() const
|
|
{
|
|
TArray<FName> Ids;
|
|
Ids.Reserve(Layers.Num());
|
|
for (const FWorldMapLayer& Layer : Layers)
|
|
{
|
|
Ids.Add(Layer.Id);
|
|
}
|
|
return Ids;
|
|
}
|