Formatting, add base class for prefabs for the cookspot, add functionality to spawn the prefabs in predetermined places based on an actor ptr

This commit is contained in:
Stefan Stefanov 2023-11-12 18:21:31 +02:00
parent 873337dec5
commit 57543aa69f
23 changed files with 36 additions and 16 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -9,11 +9,14 @@ AOvenCookspot::AOvenCookspot()
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
RootComponent = CreateDefaultSubobject<USceneComponent>("Root");
FireMesh = CreateDefaultSubobject<UStaticMeshComponent>("FireSM");
FireMesh->SetupAttachment(RootComponent);
FireElementMesh = CreateDefaultSubobject<UStaticMeshComponent>("FireElementSM");
FireElementMesh->SetupAttachment(RootComponent);
CookpotMesh = CreateDefaultSubobject<UStaticMeshComponent>("CookpotSM");
FireElementMesh->SetupAttachment(RootComponent);
FireMesh->SetupAttachment(RootComponent);
CookpotMesh->SetupAttachment(RootComponent);
}

View file

@ -24,12 +24,15 @@ public:
virtual void Tick(float DeltaTime) override;
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Oven Settings")
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TObjectPtr<USceneComponent> RootComp;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TObjectPtr<UStaticMeshComponent> FireMesh;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Oven Settings")
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TObjectPtr<UStaticMeshComponent> FireElementMesh;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Oven Settings")
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TObjectPtr<UStaticMeshComponent> CookpotMesh;
};

View file

@ -112,8 +112,19 @@ void AOvenPawn::BeginPlay()
{
Super::BeginPlay();
for (const AActor *CookspotLoc : CookspotLocations)
{
FActorSpawnParameters SpawnParameters;
auto *OvenCookspotActor =
GetWorld()->SpawnActor<AOvenCookspot>(CookstovePrefab,
CookspotLoc->GetTransform(),
SpawnParameters);
OvenCookspotActor->SetActorLocation(CookspotLoc->GetActorLocation());
CookstoveObjects.Add(OvenCookspotActor);
}
// Setup the cookstove related items
Cookstoves.AddDefaulted(CookstoveObjects.Num());
Cookstoves.AddDefaulted(CookspotLocations.Num());
checkf(Cookstoves.Num() == CookstoveObjects.Num(), TEXT("Cookstoves and CookstoveObjects have different sizes"))
}
void AOvenPawn::Tick(float DeltaTime)

View file

@ -7,6 +7,7 @@
#include "Misc/DateTime.h"
#include "Misc/Timespan.h"
#include "Engine/DataTable.h"
#include "OvenCookspot.h"
#include "OvenPawn.generated.h"
@ -84,24 +85,24 @@ struct FCookstove
/**
* @brief Updates the cookstove for this tick, if a meal is cooking, updates the stats for it and if it finishes it calculates the score, etc...
* @param DeltaTime Time between N-1 and N-2 frames in milliseconds
* @param PlayerScore Takes in the current player score in case a meal gets finished and the score must be returned
* @param DeltaTime Time between N-1 and N-2 frames in milliseconds.
* @param PlayerScore Takes in the current player score in case a meal gets finished and the score must be returned.
*/
auto Update(const float DeltaTime, int32 &PlayerScore) -> void;
/**
* @brief Returns the remaining cooking time
* @brief Returns the remaining cooking time.
*/
auto GetRemainingCookingTime() const -> FTimespan;
/**
* @brief Check if the currently cooked meal is done cooking
* @brief Check if the currently cooked meal is done cooking.
*/
auto IsMealDone() const -> bool;
/**
* @brief Finishes up cooking the current meal, setting up the necessary stats and state
* @return Returns the calculated score based on the stats of the cooked meal
* @brief Finishes up cooking the current meal, setting up the necessary stats and state.
* @return Returns the calculated score based on the stats of the cooked meal.
*/
auto FinishMeal() -> int32;
};
@ -121,7 +122,6 @@ protected:
public:
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent *PlayerInputComponent) override;
auto TrySpawningNewRandomMeal() -> bool;
@ -140,14 +140,17 @@ public:
int32 CurrentPlayerScore{0};
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Oven Settings")
TObjectPtr<AActor> CookstovePrefab;
TSubclassOf<AOvenCookspot> CookstovePrefab;
// ReSharper disable once CppUE4ProbableMemoryIssuesWithUObject
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Oven Settings")
TObjectPtr<UDataTable> RecipesDataTable;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Oven Settings")
TArray<TObjectPtr<AActor>> CookspotLocations;
private:
// An array of all the cookstoves, from left to right on the screen
TArray<TObjectPtr<AActor>> CookstoveObjects;
// An array of all the cookstoves, from left to right on the screen.
TArray<TObjectPtr<AOvenCookspot>> CookstoveObjects;
TArray<FCookstove> Cookstoves;
};