Agrarsense
MapUtilities.cpp
Go to the documentation of this file.
1// Copyright (c) 2023 FrostBit Software Lab at the Lapland University of Applied Sciences
2//
3// This work is licensed under the terms of the MIT license.
4// For a copy, see <https://opensource.org/licenses/MIT>.
5
6#include "MapUtilities.h"
7#include "Engine/World.h"
8
9TArray<FString> UMapUtilities::GetAllMapNames(bool onlyAgrarsenseMapFolder, bool logResults)
10{
11 TArray<FAssetData> AssetDatas = GetAssetData(onlyAgrarsenseMapFolder);
12
13 TArray<FString> mapNames = TArray<FString>();
14 for (int32 i = 0; i < AssetDatas.Num(); ++i)
15 {
16 FAssetData& mapAssetData = AssetDatas[i];
17 auto name = mapAssetData.AssetName.ToString();
18 mapNames.Add(name);
19 }
20
21#if WITH_EDITOR
22 if (logResults)
23 {
24 UE_LOG(LogTemp, Warning, TEXT("Found %d maps. Map names:"), AssetDatas.Num());
25 for (int i = 0; i < mapNames.Num(); i++)
26 {
27 UE_LOG(LogTemp, Warning, TEXT("%s"), *mapNames[i]);
28 }
29 }
30#endif
31
32 return mapNames;
33}
34
35TArray<FString> UMapUtilities::GetAllMapPaths(bool onlyAgrarsenseMapFolder, bool logResults)
36{
37 TArray<FAssetData> AssetDatas = GetAssetData(onlyAgrarsenseMapFolder);
38
39 TArray<FString> mapPaths = TArray<FString>();
40 for (int32 i = 0; i < AssetDatas.Num(); ++i)
41 {
42 FAssetData& mapAssetData = AssetDatas[i];
43 auto name = mapAssetData.PackagePath.ToString();
44 mapPaths.Add(name);
45 }
46
47#if WITH_EDITOR
48 if (logResults)
49 {
50 UE_LOG(LogTemp, Warning, TEXT("Found %d maps. Map paths:"), AssetDatas.Num());
51 for (int i = 0; i < mapPaths.Num(); i++)
52 {
53 UE_LOG(LogTemp, Warning, TEXT("%s"), *mapPaths[i]);
54 }
55 }
56#endif
57
58 return mapPaths;
59}
60
61TArray<FAssetData>UMapUtilities::GetAllMapAssetDatas(bool onlyAgrarsenseMapFolder)
62{
63 TArray<FAssetData> AssetDatas = GetAssetData(onlyAgrarsenseMapFolder);
64
65 return AssetDatas;
66}
67
68TArray<FAssetData> UMapUtilities::GetAssetData(bool onlyAgrarsenseMapFolder)
69{
70 FString path = "/Game/"; // Search the whole project
71 if (onlyAgrarsenseMapFolder)
72 {
73 path = "/Game/Agrarsense/Maps"; // Search only in Agrarsense map folder
74 }
75
76 auto ObjectLibrary = UObjectLibrary::CreateLibrary(UWorld::StaticClass(), false, true);
77 ObjectLibrary->LoadAssetDataFromPath(path);
78 TArray<FAssetData> AssetDatas;
79 ObjectLibrary->GetAssetDataList(AssetDatas);
80
81 return AssetDatas;
82}
static TArray< FAssetData > GetAssetData(bool onlyAgrarsenseMapFolder)
static TArray< FAssetData > GetAllMapAssetDatas(bool onlyAgrarsenseMapFolder=true)
static TArray< FString > GetAllMapNames(bool onlyAgrarsenseMapFolder=true, bool logResults=false)
Definition: MapUtilities.cpp:9
static TArray< FString > GetAllMapPaths(bool onlyAgrarsenseMapFolder=true, bool logResults=false)