93 lines
2.4 KiB
C++
93 lines
2.4 KiB
C++
// Oleg Petruny proprietary.
|
|
|
|
|
|
#include "LevelBase.h"
|
|
|
|
#include "EngineUtils.h"
|
|
#include "LevelSequencePlayer.h"
|
|
|
|
#include "CommonFunctions.h"
|
|
#include "CustomGameInstanceBase.h"
|
|
#include "Interactable/Interactable.h"
|
|
#include "Levels/Checkpoint.h"
|
|
#include "PlayerBase.h"
|
|
#include "SaveData.h"
|
|
|
|
void ALevelBase::BeginPlay()
|
|
{
|
|
ALevelScriptActor::BeginPlay();
|
|
|
|
BroadcastNewLevelBeginPlay();
|
|
StartLevelAnimations();
|
|
ApplySaveData();
|
|
}
|
|
|
|
void ALevelBase::IterateToState(int32 to)
|
|
{
|
|
while(state < to)
|
|
CallNextState();
|
|
}
|
|
|
|
void ALevelBase::BroadcastNewLevelBeginPlay()
|
|
{
|
|
if(auto GI = Cast<UCustomGameInstanceBase>(GetWorld()->GetGameInstance()))
|
|
GI->OnLevelBeginned.Broadcast(GetFName());
|
|
}
|
|
|
|
void ALevelBase::StartLevelAnimations()
|
|
{
|
|
FMovieSceneSequencePlaybackSettings playbackSettings;
|
|
playbackSettings.bAutoPlay = true;
|
|
FMovieSceneSequenceLoopCount playbackLoopCount;
|
|
playbackLoopCount.Value = -1;
|
|
playbackSettings.LoopCount = playbackLoopCount;
|
|
for(auto& sequence : onBeginPlaySequences)
|
|
{
|
|
ALevelSequenceActor* sequenceActor;
|
|
auto sequencePlayer = ULevelSequencePlayer::CreateLevelSequencePlayer(GetWorld(), sequence.LoadSynchronous(), playbackSettings, sequenceActor);
|
|
onBeginPlaySequencesActors.Add(sequenceActor);
|
|
}
|
|
}
|
|
|
|
void ALevelBase::ApplySaveData()
|
|
{
|
|
auto GI = UCustomGameInstanceBase::GetGameInstance();
|
|
if(!GI || !GI->saveData || GI->saveData->level != GetWorld()->GetFName())
|
|
return;
|
|
|
|
IterateToState(GI->saveData->state);
|
|
|
|
auto player = UCommonFunctions::GetPlayer(this);
|
|
if(!player)
|
|
return;
|
|
|
|
for(TActorIterator<ACheckpoint> it(GetWorld()); it; ++it)
|
|
{
|
|
if(it->GetFName() == GI->saveData->checkpoint)
|
|
{
|
|
player->SetActorLocation(it->GetActorLocation(), false, nullptr, ETeleportType::ResetPhysics);
|
|
player->Controller->SetControlRotation(it->GetActorRotation());
|
|
break;
|
|
}
|
|
}
|
|
|
|
int pocketItems = 0;
|
|
for(TActorIterator<AInteractable> it(GetWorld()); it; ++it)
|
|
{
|
|
if(it->GetFName() == GI->saveData->playerLeftPocketItem)
|
|
{
|
|
++pocketItems;
|
|
player->TakeItemToLeftHand(*it);
|
|
}
|
|
else if(it->GetFName() == GI->saveData->playerRightPocketItem)
|
|
{
|
|
++pocketItems;
|
|
player->TakeItemToRightHand(*it);
|
|
}
|
|
if(pocketItems > 1)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|