Files
Naked-Desire/Source/NakedDesire/Commissions/Constraints/DayPhaseConstraint.cpp
T
2026-06-03 15:17:02 +03:00

46 lines
1.1 KiB
C++

// © 2025 Naked People Team. All Rights Reserved.
#include "DayPhaseConstraint.h"
#include "NakedDesire/Player/NakedDesireCharacter.h"
#define LOCTEXT_NAMESPACE "Commissions.Constraints.DayPhase"
void UDayPhaseConstraint::OnActivate()
{
if (UTimeOfDaySubsystem* Time = GetTime())
Time->OnPhaseChanged.AddUniqueDynamic(this, &UDayPhaseConstraint::HandlePhaseChanged);
}
void UDayPhaseConstraint::OnDeactivate()
{
if (UTimeOfDaySubsystem* Time = GetTime())
Time->OnPhaseChanged.RemoveDynamic(this, &UDayPhaseConstraint::HandlePhaseChanged);
}
bool UDayPhaseConstraint::IsMet() const
{
const UTimeOfDaySubsystem* Time = GetTime();
return Time && Time->GetPhase() == RequiredPhase;
}
void UDayPhaseConstraint::HandlePhaseChanged(EDayPhase NewPhase)
{
NotifyChanged();
}
UTimeOfDaySubsystem* UDayPhaseConstraint::GetTime() const
{
UWorld* World = Player ? Player->GetWorld() : nullptr;
return World ? World->GetSubsystem<UTimeOfDaySubsystem>() : nullptr;
}
FText UDayPhaseConstraint::GetDescription() const
{
return (RequiredPhase == EDayPhase::Night)
? LOCTEXT("Night", "at night")
: LOCTEXT("Day", "during the day");
}
#undef LOCTEXT_NAMESPACE