diff --git a/Config/DefaultEngine.ini b/Config/DefaultEngine.ini index cabb876..1abe330 100644 --- a/Config/DefaultEngine.ini +++ b/Config/DefaultEngine.ini @@ -20,7 +20,7 @@ GameDefaultMap=/Game/Level/HomeLand.HomeLand [/Script/Engine.RendererSettings] r.Mobile.AntiAliasing=0 -r.AntiAliasingMethod=3 +r.AntiAliasingMethod=1 r.DefaultFeature.MotionBlur=False [CoreRedirects] diff --git a/Content/Blueprint/Level/Actor/Role/BP_Rabbit.uasset b/Content/Blueprint/Level/Actor/Role/BP_Rabbit.uasset index 0f8d221..967d378 100644 Binary files a/Content/Blueprint/Level/Actor/Role/BP_Rabbit.uasset and b/Content/Blueprint/Level/Actor/Role/BP_Rabbit.uasset differ diff --git a/Content/Blueprint/Level/BP_LevelMap.uasset b/Content/Blueprint/Level/BP_LevelMap.uasset index e6e6b2e..7d1edeb 100644 Binary files a/Content/Blueprint/Level/BP_LevelMap.uasset and b/Content/Blueprint/Level/BP_LevelMap.uasset differ diff --git a/Content/Data/Level/LevelStaticResourceGenerateConfig.uasset b/Content/Data/Level/LevelStaticResourceGenerateConfig.uasset new file mode 100644 index 0000000..744625c Binary files /dev/null and b/Content/Data/Level/LevelStaticResourceGenerateConfig.uasset differ diff --git a/Content/Level/FalconPlain.umap b/Content/Level/FalconPlain.umap index 89ea3a6..1730f37 100644 Binary files a/Content/Level/FalconPlain.umap and b/Content/Level/FalconPlain.umap differ diff --git a/Content/Lua/Level/LevelGameMode.lua b/Content/Lua/Level/LevelGameMode.lua index 7c4ee56..70ebc2e 100644 --- a/Content/Lua/Level/LevelGameMode.lua +++ b/Content/Lua/Level/LevelGameMode.lua @@ -2,6 +2,15 @@ local Vector = import("Vector") local GameplayStatics = import("GameplayStatics") local BusyGameplayLibrary = import("BusyGameplayLibrary") + +--[[****************************私有函数区域******************************]]-- + +--- 生成资源点 +local function GenerateResourcePoint() + +end + + --- 保留到以后做联机内容时拓展 --- @class LevelGameMode --- @field GameMapActorClass table diff --git a/Source/BusyRabbit/Private/Level/Map/ClimateLayerComponent.cpp b/Source/BusyRabbit/Private/Level/Map/ClimateLayerComponent.cpp deleted file mode 100644 index f7bcef0..0000000 --- a/Source/BusyRabbit/Private/Level/Map/ClimateLayerComponent.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "Level/Map/ClimateLayerComponent.h" diff --git a/Source/BusyRabbit/Private/Level/Map/Components/ClimateLayerComponent.cpp b/Source/BusyRabbit/Private/Level/Map/Components/ClimateLayerComponent.cpp new file mode 100644 index 0000000..28b1a75 --- /dev/null +++ b/Source/BusyRabbit/Private/Level/Map/Components/ClimateLayerComponent.cpp @@ -0,0 +1 @@ +#include "Level/Map/Components/ClimateLayerComponent.h" diff --git a/Source/BusyRabbit/Private/Level/Map/Components/CreatureLayerComponent.cpp b/Source/BusyRabbit/Private/Level/Map/Components/CreatureLayerComponent.cpp new file mode 100644 index 0000000..ef80184 --- /dev/null +++ b/Source/BusyRabbit/Private/Level/Map/Components/CreatureLayerComponent.cpp @@ -0,0 +1 @@ +#include "Level/Map/Components/CreatureLayerComponent.h" diff --git a/Source/BusyRabbit/Private/Level/Map/Components/DecorationLayerComponent.cpp b/Source/BusyRabbit/Private/Level/Map/Components/DecorationLayerComponent.cpp new file mode 100644 index 0000000..56b7131 --- /dev/null +++ b/Source/BusyRabbit/Private/Level/Map/Components/DecorationLayerComponent.cpp @@ -0,0 +1 @@ +#include "Level/Map/Components/DecorationLayerComponent.h" diff --git a/Source/BusyRabbit/Private/Level/Map/Components/LightingLayerComponent.cpp b/Source/BusyRabbit/Private/Level/Map/Components/LightingLayerComponent.cpp new file mode 100644 index 0000000..45dc41e --- /dev/null +++ b/Source/BusyRabbit/Private/Level/Map/Components/LightingLayerComponent.cpp @@ -0,0 +1 @@ +#include "Level/Map/Components/LightingLayerComponent.h" diff --git a/Source/BusyRabbit/Private/Level/Map/Components/StaticResourceLayerComponent.cpp b/Source/BusyRabbit/Private/Level/Map/Components/StaticResourceLayerComponent.cpp new file mode 100644 index 0000000..16c0ee8 --- /dev/null +++ b/Source/BusyRabbit/Private/Level/Map/Components/StaticResourceLayerComponent.cpp @@ -0,0 +1,138 @@ +#include "Level/Map/Components/StaticResourceLayerComponent.h" +#include "Level/Map/GameMapActor.h" +#include "Level/Actor/BusyStaticResource.h" +#include "Utils/MitchellBestCandidate.h" + +static FName GetOneOfAlwaysPresent(TMap& AlwaysPresentResource) +{ + TArray NeedRemoveKeys; + for (auto& Pair : AlwaysPresentResource) + { + if (Pair.Value <= 0) + { + NeedRemoveKeys.AddUnique(Pair.Key); + } + } + for (auto& RemovedKey : NeedRemoveKeys) + { + AlwaysPresentResource.Remove(RemovedKey); + } + + if (AlwaysPresentResource.Num() == 0) + { + return FName(); + } + auto &Pair = *AlwaysPresentResource.begin(); + Pair.Value -= 1; + return Pair.Key; +} + + +inline static IGameMapInterface * GetMapActor(const UActorComponent* Component) +{ + AActor *Owner = Component->GetOwner(); + if (!Owner) return nullptr; + return Cast(Owner); +} + + +void UStaticResourceLayerComponent::GenerateResources() +{ + TArray ResourcePoints; + GenerateResourcePoints(ResourcePoints); + GenerateAlwaysPresentInfo(ResourcePoints); + + AActor *Owner = GetOwner(); + UWorld* World = GetWorld(); + + const IGameMapInterface* GameMap = Cast(Owner); + if(!Owner || !GameMap || !World) return; + + const float MapFieldSize = GameMap->Execute_GetMapFieldSize(Owner); + for (int32 Index = 0; Index < GeneratedResourcePoints.Num(); Index++) + { + const TTuple &Info = GeneratedResourcePoints[Index]; + + const auto Config = GenerateConfig->FindRow(Info.Key, TEXT("")); + + FActorSpawnParameters SpawnParameters; + SpawnParameters.Owner = Owner; + World->SpawnActor( + Config->ResourceClass, + FVector(Info.Value.X * MapFieldSize, Info.Value.Y * MapFieldSize, 50.0f), + FRotator::ZeroRotator + ); + } + + +} + +void UStaticResourceLayerComponent::GenerateResourcePoints(TArray& OutResourcePoint) +{ + OutResourcePoint.Empty(); + AActor *Owner = GetOwner(); + if (!Owner) return; + const IGameMapInterface * MapInterface = Cast(Owner); + if (!MapInterface) return; + + float MapWidth, MapHeight; + MapInterface->Execute_GetMapSize(Owner, MapWidth, MapHeight); + + const UMitchellBestCandidate *PointCreator = NewObject(); + OutResourcePoint = PointCreator->GeneratePoints(ResourcePointCount, MapWidth, MapHeight); +} + +void UStaticResourceLayerComponent::GetAlwaysPresentResourceList(TMap& OutAlwaysPresentResource)const +{ + OutAlwaysPresentResource.Empty(); + if (!GenerateConfig) return; + for (const auto& Pair : GenerateConfig->GetRowMap()) + { + const FStaticResourceGenerateConfig* RowData = reinterpret_cast(Pair.Value); + if (RowData->MinGenerateCount > 0) + { + OutAlwaysPresentResource.Add(Pair.Key, RowData->MinGenerateCount); + } + } +} + +bool UStaticResourceLayerComponent::GenerateAlwaysPresentInfo(TArray& ResourcePoints) +{ + AActor *Owner = GetOwner(); + if (!Owner) return false; + const IGameMapInterface * MapInterface = Cast(Owner); + if (!MapInterface) return false; + + TMap AlwaysPresentResource; + GetAlwaysPresentResourceList(AlwaysPresentResource); + + for (int i = ResourcePoints.Num() - 1; i >= 0; i--) // 遍历所有的资源点尝试生成资源 + { + FName CurrentSelected = GetOneOfAlwaysPresent(AlwaysPresentResource); + if (CurrentSelected.IsNone()) break; // 必须生成的资源已经全部生成了,则结束 + + const FVector2D& CurrentPoint = ResourcePoints[i]; + FGameplayTag CurrentTerrain = MapInterface->Execute_GetTerrainAt(Owner, CurrentPoint.X, CurrentPoint.Y); // 获取这个资源点的地形类型 + const auto Config = GenerateConfig->FindRow( + CurrentSelected, TEXT("") + ); + if (!Config) continue; + + if (Config->TerrainTypes.HasTag(CurrentTerrain)) // 资源的地形配置包含当前的地形,则添加进生成的列表 + { + GeneratedResourcePoints.Add(TTuple( + CurrentSelected, + FVector2D(ResourcePoints[i].X, ResourcePoints[i].Y)) + ); + ResourcePoints[i].X = ResourcePoints[i].Y = -1; + } + } + + if (!GetOneOfAlwaysPresent(AlwaysPresentResource).IsNone()) // 如果还有必须要生成的没有生成,则生成失败 + { + GeneratedResourcePoints.Empty(); + return false; + } + ResourcePoints.RemoveAll([](const FVector2D Element){ return Element.X < 0 && Element.Y < 0; }); + return true; +} diff --git a/Source/BusyRabbit/Private/Level/Map/TerrainLayerComponent.cpp b/Source/BusyRabbit/Private/Level/Map/Components/TerrainLayerComponent.cpp similarity index 85% rename from Source/BusyRabbit/Private/Level/Map/TerrainLayerComponent.cpp rename to Source/BusyRabbit/Private/Level/Map/Components/TerrainLayerComponent.cpp index 777e33c..21628f3 100644 --- a/Source/BusyRabbit/Private/Level/Map/TerrainLayerComponent.cpp +++ b/Source/BusyRabbit/Private/Level/Map/Components/TerrainLayerComponent.cpp @@ -1,4 +1,4 @@ -#include "Level/Map/TerrainLayerComponent.h" +#include "Level/Map/Components/TerrainLayerComponent.h" #include "Level/Generator/VoronoiTerrainGenerator.h" #include "Paper2D/Classes/PaperTileLayer.h" #include "Paper2D/Classes/PaperTileMapComponent.h" @@ -163,7 +163,6 @@ void UTerrainLayerComponent::BeginPlay() TArray Priority; TArray TerrainData; TArray TerrainTypes; - TArray FilteredTerrainData; for (auto TileSetConfig : TileSetConfigs) { TerrainTypes.Add(TileSetConfig.Key); @@ -172,18 +171,10 @@ void UTerrainLayerComponent::BeginPlay() GenerateTerrain(TerrainTypes, Priority, MapWidth, TerrainData); - for (auto TerrainType : TerrainTypes) - { - FilteredTerrainData.Init(false, TerrainData.Num()); - for (int32 i = 0; i < TerrainData.Num(); i++) - { - FilteredTerrainData[i] = (TerrainData[i] == TerrainType); - } - SetTerrainData(TerrainType, FilteredTerrainData); - } + SetTerrainData(TerrainData); } -void UTerrainLayerComponent::SetTerrainData(const FGameplayTag& InTerrainType, const TArray& TerrainData) +void UTerrainLayerComponent::SetTerrainDataWithType(const FGameplayTag& InTerrainType, const TArray& InTerrainData) { // 将给定的数据绘制到TileMapLayer上 UPaperTileSet* TileSet = GetMapTileSet(InTerrainType, TileSetConfigs); @@ -193,7 +184,7 @@ void UTerrainLayerComponent::SetTerrainData(const FGameplayTag& InTerrainType, c UE_LOG(LogTemp, Warning, TEXT("UTerrainLayerComponent::SetTerrainData")); return; } - if (TerrainData.Num() != MapWidth * MapHeight) + if (InTerrainData.Num() != MapWidth * MapHeight) { UE_LOG(LogTemp, Warning, TEXT("UTerrainLayerComponent::SetTerrainData")); return; @@ -206,10 +197,10 @@ void UTerrainLayerComponent::SetTerrainData(const FGameplayTag& InTerrainType, c const int32 CurRow = i * MapWidth; const int32 NextRow = (i + 1) * MapWidth; const int32 NeighborIndex = GetTileSetIndex( - TerrainData[CurRow + j], - TerrainData[CurRow + j + 1], - TerrainData[NextRow + j], - TerrainData[NextRow + j + 1] + InTerrainData[CurRow + j], + InTerrainData[CurRow + j + 1], + InTerrainData[NextRow + j], + InTerrainData[NextRow + j + 1] ); TileInfo.TileSet = TileSet; TileInfo.PackedTileIndex = DefaultNeighborDataToIdxMappings[NeighborIndex]; @@ -218,6 +209,33 @@ void UTerrainLayerComponent::SetTerrainData(const FGameplayTag& InTerrainType, c } } +void UTerrainLayerComponent::SetTerrainData(const TArray& InTerrainData) +{ + TArray Priority; + TArray FilteredTerrainData; + + for (auto &TileSetConfig : TileSetConfigs) + { + FilteredTerrainData.Init(false, InTerrainData.Num()); + for (int32 i = 0; i < InTerrainData.Num(); i++) + { + FilteredTerrainData[i] = (InTerrainData[i] == TileSetConfig.Key); + } + SetTerrainDataWithType(TileSetConfig.Key, FilteredTerrainData); + } + TerrainLayerData = InTerrainData; +} + +FGameplayTag UTerrainLayerComponent::GetTerrainAt(const int32 X, const int32 Y) +{ + const int32 Index = X + Y * MapWidth; + if (TerrainLayerData.IsValidIndex(Index)) + { + return TerrainLayerData[Index]; + } + return FGameplayTag(); +} + void UTerrainLayerComponent::SetupTerrainMeshes() { @@ -246,9 +264,8 @@ void UTerrainLayerComponent::SetupTerrainMeshes() NewTileMap->MapWidth = MapWidth; NewTileMap->MapHeight = MapHeight; - NewTileMap->TileWidth = 128; - NewTileMap->TileHeight = 128; - + NewTileMap->TileWidth = TileSetSize; + NewTileMap->TileHeight = TileSetSize; UPaperTileLayer* NewLayer = NewObject(NewTileMap); NewLayer->LayerName = FText::FromString("TerrainLayer"); diff --git a/Source/BusyRabbit/Private/Level/Map/CreatureLayerComponent.cpp b/Source/BusyRabbit/Private/Level/Map/CreatureLayerComponent.cpp deleted file mode 100644 index 1d0fe19..0000000 --- a/Source/BusyRabbit/Private/Level/Map/CreatureLayerComponent.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "Level/Map/CreatureLayerComponent.h" diff --git a/Source/BusyRabbit/Private/Level/Map/DecorationLayerComponent.cpp b/Source/BusyRabbit/Private/Level/Map/DecorationLayerComponent.cpp deleted file mode 100644 index 0329493..0000000 --- a/Source/BusyRabbit/Private/Level/Map/DecorationLayerComponent.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "Level/Map/DecorationLayerComponent.h" diff --git a/Source/BusyRabbit/Private/Level/Map/GameMapActor.cpp b/Source/BusyRabbit/Private/Level/Map/GameMapActor.cpp index 7b75303..c44578a 100644 --- a/Source/BusyRabbit/Private/Level/Map/GameMapActor.cpp +++ b/Source/BusyRabbit/Private/Level/Map/GameMapActor.cpp @@ -1,19 +1,35 @@ #include "Level/Map/GameMapActor.h" +#include "Level/Map/Components/StaticResourceLayerComponent.h" + AGameMapActor::AGameMapActor() { SceneComp = CreateDefaultSubobject(TEXT("SceneComp")); - - TerrainLayer = CreateDefaultSubobject(TEXT("TerrainLayer")); - - + ResourceLayer = CreateDefaultSubobject(TEXT("ResourceLayer")); this->RootComponent = SceneComp; } +void AGameMapActor::GetMapSize_Implementation(float& OutWidth, float& OutHeight) +{ + OutWidth = MapWidth; + OutHeight = MapHeight; +} + +FGameplayTag AGameMapActor::GetTerrainAt_Implementation(const float X, const float Y) +{ + return TerrainLayer->GetTerrainAt(X, Y); +} + +float AGameMapActor::GetMapFieldSize_Implementation() +{ + return MapFieldSize; +} + void AGameMapActor::BeginPlay() { Super::BeginPlay(); + ResourceLayer->GenerateResources(); } void AGameMapActor::EndPlay(const EEndPlayReason::Type EndPlayReason) diff --git a/Source/BusyRabbit/Private/Level/Map/LightingLayerComponent.cpp b/Source/BusyRabbit/Private/Level/Map/LightingLayerComponent.cpp deleted file mode 100644 index 423b87a..0000000 --- a/Source/BusyRabbit/Private/Level/Map/LightingLayerComponent.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "Level/Map/LightingLayerComponent.h" diff --git a/Source/BusyRabbit/Private/Level/Map/PlacementLayerComponent.cpp b/Source/BusyRabbit/Private/Level/Map/PlacementLayerComponent.cpp deleted file mode 100644 index 1bd86f2..0000000 --- a/Source/BusyRabbit/Private/Level/Map/PlacementLayerComponent.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "Level/Map/PlacementLayerComponent.h" diff --git a/Source/BusyRabbit/Private/Level/Generator/MitchellBestCandidate.cpp b/Source/BusyRabbit/Private/Utils/MitchellBestCandidate.cpp similarity index 97% rename from Source/BusyRabbit/Private/Level/Generator/MitchellBestCandidate.cpp rename to Source/BusyRabbit/Private/Utils/MitchellBestCandidate.cpp index 7ee2a7c..4b283e2 100644 --- a/Source/BusyRabbit/Private/Level/Generator/MitchellBestCandidate.cpp +++ b/Source/BusyRabbit/Private/Utils/MitchellBestCandidate.cpp @@ -1,4 +1,4 @@ -#include "Level/Generator/MitchellBestCandidate.h" +#include "Utils/MitchellBestCandidate.h" #include "Math/UnrealMathUtility.h" UMitchellBestCandidate::UMitchellBestCandidate() diff --git a/Source/BusyRabbit/Public/Level/Generator/VoronoiTerrainGenerator.h b/Source/BusyRabbit/Public/Level/Generator/VoronoiTerrainGenerator.h index 5f89d13..2820466 100644 --- a/Source/BusyRabbit/Public/Level/Generator/VoronoiTerrainGenerator.h +++ b/Source/BusyRabbit/Public/Level/Generator/VoronoiTerrainGenerator.h @@ -2,7 +2,7 @@ #include "CoreMinimal.h" #include "GameplayTagContainer.h" -#include "Level/Generator/MitchellBestCandidate.h" +#include "Utils/MitchellBestCandidate.h" #include "Level/Generator/VoronoiDiagram.h" #include "Level/Generator/TerrainGeneratorBase.h" #include "VoronoiTerrainGenerator.generated.h" diff --git a/Source/BusyRabbit/Public/Level/Map/ClimateLayerComponent.h b/Source/BusyRabbit/Public/Level/Map/Components/ClimateLayerComponent.h similarity index 100% rename from Source/BusyRabbit/Public/Level/Map/ClimateLayerComponent.h rename to Source/BusyRabbit/Public/Level/Map/Components/ClimateLayerComponent.h diff --git a/Source/BusyRabbit/Public/Level/Map/CreatureLayerComponent.h b/Source/BusyRabbit/Public/Level/Map/Components/CreatureLayerComponent.h similarity index 100% rename from Source/BusyRabbit/Public/Level/Map/CreatureLayerComponent.h rename to Source/BusyRabbit/Public/Level/Map/Components/CreatureLayerComponent.h diff --git a/Source/BusyRabbit/Public/Level/Map/DecorationLayerComponent.h b/Source/BusyRabbit/Public/Level/Map/Components/DecorationLayerComponent.h similarity index 100% rename from Source/BusyRabbit/Public/Level/Map/DecorationLayerComponent.h rename to Source/BusyRabbit/Public/Level/Map/Components/DecorationLayerComponent.h diff --git a/Source/BusyRabbit/Public/Level/Map/LightingLayerComponent.h b/Source/BusyRabbit/Public/Level/Map/Components/LightingLayerComponent.h similarity index 100% rename from Source/BusyRabbit/Public/Level/Map/LightingLayerComponent.h rename to Source/BusyRabbit/Public/Level/Map/Components/LightingLayerComponent.h diff --git a/Source/BusyRabbit/Public/Level/Map/Components/StaticResourceLayerComponent.h b/Source/BusyRabbit/Public/Level/Map/Components/StaticResourceLayerComponent.h new file mode 100644 index 0000000..4cd996c --- /dev/null +++ b/Source/BusyRabbit/Public/Level/Map/Components/StaticResourceLayerComponent.h @@ -0,0 +1,63 @@ +#pragma once + +#include "Engine/DataTable.h" +#include "GameplayTagContainer.h" +#include "StaticResourceLayerComponent.generated.h" + + + +USTRUCT(BlueprintType, Blueprintable) +struct FStaticResourceGenerateConfig: public FTableRowBase +{ + GENERATED_BODY() + + UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="备注") + FString Desc; + + UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="生成的最少数量") + int MinGenerateCount = 0; + + UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="生成权重") + int GenerateWeight = 1; + + UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="可以在哪些地形生成") + FGameplayTagContainer TerrainTypes; + + // 用于该资源生成时应该与某些资源保持多远的距离 + UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="生成距离规则") + TMap GenerateDistanceLimit; + + UPROPERTY(EditAnywhere, BlueprintReadOnly, DisplayName="需要生成的放置物类") + TSubclassOf ResourceClass; +}; + + +UCLASS(Blueprintable, Blueprintable) +class UStaticResourceLayerComponent :public UActorComponent +{ + GENERATED_BODY() +public: + void GenerateResources(); + + + +protected: + virtual void GenerateResourcePoints(TArray& OutResourcePoint); + + void GetAlwaysPresentResourceList(TMap& OutAlwaysPresentResource)const; + + bool GenerateAlwaysPresentInfo(TArray& ResourcePoints); + + +public: + UPROPERTY(EditAnywhere) + TObjectPtr GenerateConfig; + + UPROPERTY(EditAnywhere) + int ResourcePointCount = 64; + + TArray> GeneratedResourcePoints; + +protected: + +}; diff --git a/Source/BusyRabbit/Public/Level/Map/TerrainLayerComponent.h b/Source/BusyRabbit/Public/Level/Map/Components/TerrainLayerComponent.h similarity index 74% rename from Source/BusyRabbit/Public/Level/Map/TerrainLayerComponent.h rename to Source/BusyRabbit/Public/Level/Map/Components/TerrainLayerComponent.h index c0c4c10..b7d60d8 100644 --- a/Source/BusyRabbit/Public/Level/Map/TerrainLayerComponent.h +++ b/Source/BusyRabbit/Public/Level/Map/Components/TerrainLayerComponent.h @@ -44,23 +44,34 @@ public: virtual void BeginPlay() override; public: - void SetTerrainData(const FGameplayTag& InTerrainType, const TArray &TerrainData); - + UFUNCTION(BlueprintCallable) + void SetTerrainData(const TArray& InTerrainData); + UFUNCTION(BlueprintCallable) + FGameplayTag GetTerrainAt(const int32 X, const int32 Y); + protected: void SetupTerrainMeshes(); + + void SetTerrainDataWithType(const FGameplayTag& InTerrainType, const TArray &InTerrainData); protected: - UPROPERTY(EditAnywhere, BlueprintReadOnly) + UPROPERTY(EditAnywhere, BlueprintReadWrite) int32 MapWidth = 32; - UPROPERTY(EditAnywhere, BlueprintReadOnly) + UPROPERTY(EditAnywhere, BlueprintReadWrite) int32 MapHeight = 32; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + int32 TileSetSize = 128; UPROPERTY(EditAnywhere, BlueprintReadOnly) TMap> TileSetConfigs; UPROPERTY(EditAnywhere, BlueprintReadOnly) TMap> TerrainMeshes; + + UPROPERTY(BlueprintReadOnly) + TArray TerrainLayerData; }; diff --git a/Source/BusyRabbit/Public/Level/Map/GameMapActor.h b/Source/BusyRabbit/Public/Level/Map/GameMapActor.h index 76cd1a8..933ed5d 100644 --- a/Source/BusyRabbit/Public/Level/Map/GameMapActor.h +++ b/Source/BusyRabbit/Public/Level/Map/GameMapActor.h @@ -1,25 +1,78 @@ #pragma once -#include "Level/Map/TerrainLayerComponent.h" +#include "Engine/DataTable.h" +#include "LuaActor.h" +#include "Level/Map/Components/TerrainLayerComponent.h" +#include "Level/Map/Components/StaticResourceLayerComponent.h" #include "GameMapActor.generated.h" + +UINTERFACE() +class UGameMapInterface : public UInterface +{ + GENERATED_BODY() +}; + +class IGameMapInterface +{ + GENERATED_BODY() +public: + UFUNCTION(BlueprintCallable, BlueprintNativeEvent) + void GetMapSize(float &OutX, float &OutY); + + UFUNCTION(BlueprintCallable, BlueprintNativeEvent) + float GetMapFieldSize(); + + UFUNCTION(BlueprintCallable, BlueprintNativeEvent) + FGameplayTag GetTerrainAt(const float X, const float Y); +}; + + + UCLASS(Blueprintable, Blueprintable) -class AGameMapActor : public AActor +class AGameMapActor : public ALuaActor, public IGameMapInterface { GENERATED_BODY() public: AGameMapActor(); +public: + virtual void GetMapSize_Implementation(float& OutWidth, float& OutHeight) override; + virtual FGameplayTag GetTerrainAt_Implementation(const float X, const float Y) override; + virtual float GetMapFieldSize_Implementation() override; + public: virtual void BeginPlay() override; virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override; + +public: + UFUNCTION(BlueprintCallable) + const UTerrainLayerComponent* GetTerrainLayer() const + { + return TerrainLayer; + } + + + protected: - UPROPERTY(EditDefaultsOnly) + UPROPERTY(EditAnywhere, BlueprintReadOnly) + float MapWidth = 32; + UPROPERTY(EditAnywhere, BlueprintReadOnly) + float MapHeight = 32; + UPROPERTY(EditAnywhere, BlueprintReadOnly) + float MapFieldSize = 128; + + + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly) TObjectPtr TerrainLayer; + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly) + TObjectPtr ResourceLayer; + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) TObjectPtr SceneComp; + }; diff --git a/Source/BusyRabbit/Public/Level/Map/PlacementLayerComponent.h b/Source/BusyRabbit/Public/Level/Map/PlacementLayerComponent.h deleted file mode 100644 index 42ad5de..0000000 --- a/Source/BusyRabbit/Public/Level/Map/PlacementLayerComponent.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -class PlacementLayerComponent -{ -public: - -}; diff --git a/Source/BusyRabbit/Public/Level/Generator/MitchellBestCandidate.h b/Source/BusyRabbit/Public/Utils/MitchellBestCandidate.h similarity index 100% rename from Source/BusyRabbit/Public/Level/Generator/MitchellBestCandidate.h rename to Source/BusyRabbit/Public/Utils/MitchellBestCandidate.h