Refactor pass

This commit is contained in:
Stefan Stefanov 2023-11-12 16:41:24 +02:00
parent 1fa1a725b3
commit 873337dec5
2 changed files with 13 additions and 5 deletions

View file

@ -32,7 +32,9 @@ auto FCookstove::Setup(const UDataTable *DataTablePtr, const int32 MealID,
auto FCookstove::GetMealFromTable(const UDataTable *DataTablePtr, const int32 MealID) -> FMeal
{
if (DataTablePtr == nullptr || MealID < 0)
{
return FMeal{};
}
const FName MealRowName = DataTablePtr->GetRowNames()[MealID];
FMeal *Meal = DataTablePtr->FindRow<FMeal>(MealRowName, "");
@ -40,7 +42,7 @@ auto FCookstove::GetMealFromTable(const UDataTable *DataTablePtr, const int32 Me
return *Meal;
}
void FCookstove::SetCookingTime(const FTimespan CookingTimespan)
auto FCookstove::SetCookingTime(const FTimespan CookingTimespan) -> void
{
StartTime = FDateTime::Now();
EndTime = StartTime + CookingTimespan;
@ -50,7 +52,9 @@ void FCookstove::Update(const float DeltaTime, int32 &PlayerScore)
{
// If the id is not set, we have no work
if (CurrentMealID == -1 || CurrentlyCooking == false)
{
return;
}
// HeatHalfRange can be used to calculate an acceptable range
if (CurrentHeat < TargetHeat - HeatHalfRange)
@ -63,14 +67,18 @@ void FCookstove::Update(const float DeltaTime, int32 &PlayerScore)
}
if (IsMealDone())
{
PlayerScore += FinishMeal();
}
}
auto FCookstove::GetRemainingCookingTime() const -> FTimespan
{
const FDateTime Now = FDateTime::Now();
if (Now >= EndTime)
{
return 0.0;
}
return (EndTime - Now).GetTotalMilliseconds();
}
@ -129,7 +137,7 @@ void AOvenPawn::SetupPlayerInputComponent(UInputComponent *PlayerInputComponent)
}
auto AOvenPawn::TrySpawningNewRandomMeal() -> bool
bool AOvenPawn::TrySpawningNewRandomMeal()
{
bool bSuccess{false};
for (FCookstove Cookstove : Cookstoves)

View file

@ -80,14 +80,14 @@ struct FCookstove
static auto GetMealFromTable(const UDataTable *DataTablePtr, int32 MealID) -> FMeal;
void SetCookingTime(const FTimespan CookingTimespan);
auto SetCookingTime(const FTimespan CookingTimespan) -> void;
/**
* @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
*/
void Update(const float DeltaTime, int32 &PlayerScore);
auto Update(const float DeltaTime, int32 &PlayerScore) -> void;
/**
* @brief Returns the remaining cooking time
@ -124,7 +124,7 @@ public:
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent *PlayerInputComponent) override;
bool TrySpawningNewRandomMeal();
auto TrySpawningNewRandomMeal() -> bool;
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Oven Settings")