Refactor pass
This commit is contained in:
parent
1fa1a725b3
commit
873337dec5
2 changed files with 13 additions and 5 deletions
|
|
@ -32,7 +32,9 @@ auto FCookstove::Setup(const UDataTable *DataTablePtr, const int32 MealID,
|
||||||
auto FCookstove::GetMealFromTable(const UDataTable *DataTablePtr, const int32 MealID) -> FMeal
|
auto FCookstove::GetMealFromTable(const UDataTable *DataTablePtr, const int32 MealID) -> FMeal
|
||||||
{
|
{
|
||||||
if (DataTablePtr == nullptr || MealID < 0)
|
if (DataTablePtr == nullptr || MealID < 0)
|
||||||
|
{
|
||||||
return FMeal{};
|
return FMeal{};
|
||||||
|
}
|
||||||
|
|
||||||
const FName MealRowName = DataTablePtr->GetRowNames()[MealID];
|
const FName MealRowName = DataTablePtr->GetRowNames()[MealID];
|
||||||
FMeal *Meal = DataTablePtr->FindRow<FMeal>(MealRowName, "");
|
FMeal *Meal = DataTablePtr->FindRow<FMeal>(MealRowName, "");
|
||||||
|
|
@ -40,7 +42,7 @@ auto FCookstove::GetMealFromTable(const UDataTable *DataTablePtr, const int32 Me
|
||||||
return *Meal;
|
return *Meal;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FCookstove::SetCookingTime(const FTimespan CookingTimespan)
|
auto FCookstove::SetCookingTime(const FTimespan CookingTimespan) -> void
|
||||||
{
|
{
|
||||||
StartTime = FDateTime::Now();
|
StartTime = FDateTime::Now();
|
||||||
EndTime = StartTime + CookingTimespan;
|
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 the id is not set, we have no work
|
||||||
if (CurrentMealID == -1 || CurrentlyCooking == false)
|
if (CurrentMealID == -1 || CurrentlyCooking == false)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// HeatHalfRange can be used to calculate an acceptable range
|
// HeatHalfRange can be used to calculate an acceptable range
|
||||||
if (CurrentHeat < TargetHeat - HeatHalfRange)
|
if (CurrentHeat < TargetHeat - HeatHalfRange)
|
||||||
|
|
@ -63,14 +67,18 @@ void FCookstove::Update(const float DeltaTime, int32 &PlayerScore)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsMealDone())
|
if (IsMealDone())
|
||||||
|
{
|
||||||
PlayerScore += FinishMeal();
|
PlayerScore += FinishMeal();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto FCookstove::GetRemainingCookingTime() const -> FTimespan
|
auto FCookstove::GetRemainingCookingTime() const -> FTimespan
|
||||||
{
|
{
|
||||||
const FDateTime Now = FDateTime::Now();
|
const FDateTime Now = FDateTime::Now();
|
||||||
if (Now >= EndTime)
|
if (Now >= EndTime)
|
||||||
|
{
|
||||||
return 0.0;
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
return (EndTime - Now).GetTotalMilliseconds();
|
return (EndTime - Now).GetTotalMilliseconds();
|
||||||
}
|
}
|
||||||
|
|
@ -129,7 +137,7 @@ void AOvenPawn::SetupPlayerInputComponent(UInputComponent *PlayerInputComponent)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto AOvenPawn::TrySpawningNewRandomMeal() -> bool
|
bool AOvenPawn::TrySpawningNewRandomMeal()
|
||||||
{
|
{
|
||||||
bool bSuccess{false};
|
bool bSuccess{false};
|
||||||
for (FCookstove Cookstove : Cookstoves)
|
for (FCookstove Cookstove : Cookstoves)
|
||||||
|
|
|
||||||
|
|
@ -80,14 +80,14 @@ struct FCookstove
|
||||||
|
|
||||||
static auto GetMealFromTable(const UDataTable *DataTablePtr, int32 MealID) -> FMeal;
|
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...
|
* @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 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 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
|
* @brief Returns the remaining cooking time
|
||||||
|
|
@ -124,7 +124,7 @@ public:
|
||||||
// Called to bind functionality to input
|
// Called to bind functionality to input
|
||||||
virtual void SetupPlayerInputComponent(class UInputComponent *PlayerInputComponent) override;
|
virtual void SetupPlayerInputComponent(class UInputComponent *PlayerInputComponent) override;
|
||||||
|
|
||||||
bool TrySpawningNewRandomMeal();
|
auto TrySpawningNewRandomMeal() -> bool;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Oven Settings")
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Oven Settings")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue