// Oleg Petruny proprietary.


#include "QuestManager.h"

#include "Kismet/GameplayStatics.h"

#include "Levels/LevelBase.h"
#include "MainGameModeBase.h"
#include "Widgets/WidgetsManager.h"

void AQuestManager::BeginPlay()
{
    if(auto gamemode_base = UGameplayStatics::GetGameMode(GetWorld()))
    {
        gamemode = Cast<AMainGameModeBase>(gamemode_base);
        if(gamemode)
        {
            gamemode->questsUpdateDelegate.AddDynamic(this, &AQuestManager::Update);
        }
    }
}

void AQuestManager::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
    if(gamemode)
        gamemode->questsUpdateDelegate.RemoveDynamic(this, &AQuestManager::Update);
}

void AQuestManager::Update(TArray<FText> quests)
{
    if(auto WM = AMainGameModeBase::GetWidgetsManager())
        WM->UpdateJournal(quests);
}
