content loader, player, common functions
This commit is contained in:
parent
ac44138607
commit
2774995fab
BIN
UnrealProject/Lost_Edge/Content/Levels/Test/L_Test.umap
(Stored with Git LFS)
BIN
UnrealProject/Lost_Edge/Content/Levels/Test/L_Test.umap
(Stored with Git LFS)
Binary file not shown.
BIN
UnrealProject/Lost_Edge/Content/Levels/Test/L_Test_BuiltData.uasset
(Stored with Git LFS)
BIN
UnrealProject/Lost_Edge/Content/Levels/Test/L_Test_BuiltData.uasset
(Stored with Git LFS)
Binary file not shown.
@ -53,25 +53,6 @@ TArray<int32> UCommonFunctions::GetRandomIntArray(int32 size, int32 min, int32 m
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
ALevelBase* UCommonFunctions::GetCurrentLevelScript(UObject* obj)
|
|
||||||
{
|
|
||||||
if(auto world = obj->GetWorld())
|
|
||||||
if(auto level = world->GetCurrentLevel())
|
|
||||||
if(auto script = level->GetLevelScriptActor())
|
|
||||||
return Cast<ALevelBase>(script);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
APlayerBase* UCommonFunctions::GetPlayer(UObject* obj)
|
|
||||||
{
|
|
||||||
if(auto pc = UGameplayStatics::GetPlayerController(obj->GetWorld(), 0))
|
|
||||||
if(auto pawn = pc->GetPawn())
|
|
||||||
return Cast<APlayerBase>(pawn);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace SlowMotion
|
namespace SlowMotion
|
||||||
{
|
{
|
||||||
FTimerHandle timer;
|
FTimerHandle timer;
|
||||||
|
@ -2,34 +2,33 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
|
||||||
#include "Kismet/BlueprintFunctionLibrary.h"
|
#include "Kismet/BlueprintFunctionLibrary.h"
|
||||||
|
|
||||||
#include "CommonFunctions.generated.h"
|
#include "CommonFunctions.generated.h"
|
||||||
|
|
||||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FWorldDilationChangedDelegate, float, newDilation);
|
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FWorldDilationChangedDelegate, float, newDilation);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collection of common/universal/without own scope/specific functions.
|
||||||
|
*/
|
||||||
UCLASS()
|
UCLASS()
|
||||||
class UCommonFunctions : public UBlueprintFunctionLibrary
|
class UCommonFunctions : public UBlueprintFunctionLibrary
|
||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/** Returns true if the object is UE class template (used for copy/archetype/meta system but not on the level) */
|
||||||
|
UFUNCTION(BlueprintPure)
|
||||||
static bool IsNonGameObject(class UObject* object);
|
static bool IsNonGameObject(class UObject* object);
|
||||||
|
|
||||||
|
/** "Overload" of the built-in keys translator (to not build own engine copy) */
|
||||||
|
UFUNCTION(BlueprintPure)
|
||||||
static FText GetKeyDisplayName(struct FKey key);
|
static FText GetKeyDisplayName(struct FKey key);
|
||||||
|
|
||||||
|
/** Recursively destroy actor and all its childs (the default Destroy doesn't have consistent behavior) */
|
||||||
UFUNCTION(BlueprintCallable, Category = Actor)
|
UFUNCTION(BlueprintCallable, Category = Actor)
|
||||||
static void DestroyActorRecursively(class AActor* actor);
|
static void DestroyActorRecursively(class AActor* actor);
|
||||||
|
|
||||||
UFUNCTION(BlueprintPure)
|
|
||||||
static TArray<int32> GetRandomIntArray(int32 size = 16, int32 min = 0, int32 max = 16);
|
|
||||||
|
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable, Category = Level)
|
|
||||||
static class ALevelBase* GetCurrentLevelScript(class UObject* obj);
|
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable, Category = Player)
|
|
||||||
static class APlayerBase* GetPlayer(class UObject* obj);
|
|
||||||
|
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable, Category = World)
|
UFUNCTION(BlueprintCallable, Category = World)
|
||||||
@ -41,6 +40,10 @@ public:
|
|||||||
static FWorldDilationChangedDelegate& GetWorldDilationChangedDelegate();
|
static FWorldDilationChangedDelegate& GetWorldDilationChangedDelegate();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintPure)
|
||||||
|
static TArray<int32> GetRandomIntArray(int32 size = 16, int32 min = 0, int32 max = 16);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static TArray<T> ArrayDiff(const TArray<T>& a, const TArray<T>& b);
|
static TArray<T> ArrayDiff(const TArray<T>& a, const TArray<T>& b);
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
// Oleg Petruny proprietary.
|
// Oleg Petruny proprietary.
|
||||||
|
|
||||||
|
|
||||||
#include "ContentLoader.h"
|
#include "ContentLoader.h"
|
||||||
|
|
||||||
#include "CommonFunctions.h"
|
|
||||||
#include "IPlatformFilePak.h"
|
#include "IPlatformFilePak.h"
|
||||||
#include "Misc/FileHelper.h"
|
#include "Misc/FileHelper.h"
|
||||||
|
|
||||||
|
#include "CommonFunctions.h"
|
||||||
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -10,13 +10,16 @@
|
|||||||
UENUM(BlueprintType)
|
UENUM(BlueprintType)
|
||||||
enum class EContentDownloadMethod : uint8
|
enum class EContentDownloadMethod : uint8
|
||||||
{
|
{
|
||||||
ClearRandom = 0,
|
ClearRandom = 0, //!< Always random from 0 to n
|
||||||
NonRepeatRandom,
|
NonRepeatRandom, //!< Download the one that isn't downloaded in current runtime (Reset on full set)
|
||||||
RatingOftenRandom
|
RatingOftenRandom //!< NonRepeatRandom combined with asset rating [WIP]
|
||||||
};
|
};
|
||||||
|
|
||||||
DECLARE_DYNAMIC_DELEGATE_OneParam(FContentDownloadedCallback, FString, pakFilePath);
|
DECLARE_DYNAMIC_DELEGATE_OneParam(FContentDownloadedCallback, FString, pakFilePath);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* High language wrapper for Paks(Assets) download and loading.
|
||||||
|
*/
|
||||||
UCLASS(BlueprintType)
|
UCLASS(BlueprintType)
|
||||||
class UContentLoader : public UObject
|
class UContentLoader : public UObject
|
||||||
{
|
{
|
||||||
@ -35,12 +38,18 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
virtual void BeginDestroy() override;
|
virtual void BeginDestroy() override;
|
||||||
|
|
||||||
|
/** Sends http get request */
|
||||||
void HttpGet(const FString& url, FHttpRequestCompleteDelegate requestCompleteCallback);
|
void HttpGet(const FString& url, FHttpRequestCompleteDelegate requestCompleteCallback);
|
||||||
|
/** Parses assets html/json index */
|
||||||
TArray<FString> ParseDirectoryIndex(const TArray<uint8>& content, const FString& contentType);
|
TArray<FString> ParseDirectoryIndex(const TArray<uint8>& content, const FString& contentType);
|
||||||
|
/** Selects item by desired method */
|
||||||
FString SelectContentByMethod(const TArray<FString>& content, const EContentDownloadMethod method);
|
FString SelectContentByMethod(const TArray<FString>& content, const EContentDownloadMethod method);
|
||||||
|
|
||||||
|
/** Reads Pak content */
|
||||||
FString GetPakMountContent(const FString& pakFilePath, TArray<FString>* content = nullptr);
|
FString GetPakMountContent(const FString& pakFilePath, TArray<FString>* content = nullptr);
|
||||||
|
/** Returns mount path to desired content item */
|
||||||
UClass* GetPakClass(const FString& pakContentPath);
|
UClass* GetPakClass(const FString& pakContentPath);
|
||||||
|
|
||||||
|
/** Cache of already downloaded content at runtime (used by EContentDownloadMethod::NonRepeatRandom)*/
|
||||||
TArray<FString> downloadedContent;
|
TArray<FString> downloadedContent;
|
||||||
};
|
};
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
#include "Kismet/GameplayStatics.h"
|
#include "Kismet/GameplayStatics.h"
|
||||||
#include "Kismet/KismetSystemLibrary.h"
|
#include "Kismet/KismetSystemLibrary.h"
|
||||||
|
|
||||||
#include "CommonFunctions.h"
|
|
||||||
#include "ContentLoader.h"
|
#include "ContentLoader.h"
|
||||||
#include "Levels/LevelBase.h"
|
#include "Levels/LevelBase.h"
|
||||||
#include "PlayerBase.h"
|
#include "PlayerBase.h"
|
||||||
@ -37,13 +36,14 @@ UContentLoader* UCustomGameInstance::GetContentLoader()
|
|||||||
|
|
||||||
void UCustomGameInstance::SaveGame(FName checkpointName)
|
void UCustomGameInstance::SaveGame(FName checkpointName)
|
||||||
{
|
{
|
||||||
auto levelScript = UCommonFunctions::GetCurrentLevelScript(this);
|
auto levelScript = ALevelBase::Get();
|
||||||
if(!levelScript)
|
if(!levelScript)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto player = UCommonFunctions::GetPlayer(this);
|
auto player = APlayerBase::Get();
|
||||||
if(!player)
|
if(!player)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
saveData->level = GetWorld()->GetFName();
|
saveData->level = GetWorld()->GetFName();
|
||||||
saveData->state = levelScript->GetState();
|
saveData->state = levelScript->GetState();
|
||||||
saveData->checkpoint = checkpointName;
|
saveData->checkpoint = checkpointName;
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
#include "Kismet/GameplayStatics.h"
|
#include "Kismet/GameplayStatics.h"
|
||||||
#include "LevelSequencePlayer.h"
|
#include "LevelSequencePlayer.h"
|
||||||
|
|
||||||
#include "CommonFunctions.h"
|
|
||||||
#include "CustomGameInstance.h"
|
#include "CustomGameInstance.h"
|
||||||
#include "CustomPlayerController.h"
|
#include "CustomPlayerController.h"
|
||||||
#include "Interactable/Interactable.h"
|
#include "Interactable/Interactable.h"
|
||||||
@ -19,6 +18,13 @@
|
|||||||
#include "PlayerBase.h"
|
#include "PlayerBase.h"
|
||||||
#include "SaveData.h"
|
#include "SaveData.h"
|
||||||
|
|
||||||
|
ALevelBase* ALevelBase::Get()
|
||||||
|
{
|
||||||
|
if(auto GM = AMainGameModeBase::Get())
|
||||||
|
return GM->leadLevel.Get();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void ALevelBase::BeginPlay()
|
void ALevelBase::BeginPlay()
|
||||||
{
|
{
|
||||||
AMainGameModeBase::leadLevel = TStrongObjectPtr<ALevelBase>{ this };
|
AMainGameModeBase::leadLevel = TStrongObjectPtr<ALevelBase>{ this };
|
||||||
@ -78,7 +84,7 @@ void ALevelBase::ApplySaveData()
|
|||||||
|
|
||||||
IterateToState(GI->saveData->state);
|
IterateToState(GI->saveData->state);
|
||||||
|
|
||||||
auto player = UCommonFunctions::GetPlayer(this);
|
auto player = APlayerBase::Get();
|
||||||
if(!player)
|
if(!player)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -19,6 +19,10 @@ class ALevelBase : public ALevelScriptActor
|
|||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/** Returns lead level script */
|
||||||
|
UFUNCTION(BlueprintPure, meta = (DisplayName = "Get Lead Level Script"))
|
||||||
|
static ALevelBase* Get();
|
||||||
|
|
||||||
/** Iterates throught level states */
|
/** Iterates throught level states */
|
||||||
UFUNCTION(BlueprintCallable)
|
UFUNCTION(BlueprintCallable)
|
||||||
inline void CallNextState() { ++state; NextState(); }
|
inline void CallNextState() { ++state; NextState(); }
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include "Minigame.h"
|
#include "Minigame.h"
|
||||||
|
|
||||||
|
#include "InputMappingContext.h"
|
||||||
|
|
||||||
#include "CustomPlayerController.h"
|
#include "CustomPlayerController.h"
|
||||||
#include "PlayerBase.h"
|
#include "PlayerBase.h"
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
// Oleg Petruny proprietary.
|
// Oleg Petruny proprietary.
|
||||||
|
|
||||||
|
|
||||||
#include "PlayerBase.h"
|
#include "PlayerBase.h"
|
||||||
|
|
||||||
#include "Camera/CameraComponent.h"
|
#include "Camera/CameraComponent.h"
|
||||||
@ -63,6 +62,13 @@ void APlayerBase::SetupPlayerInputComponent(UInputComponent* PlayerInputComponen
|
|||||||
ACharacter::SetupPlayerInputComponent(PlayerInputComponent);
|
ACharacter::SetupPlayerInputComponent(PlayerInputComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
APlayerBase* APlayerBase::Get()
|
||||||
|
{
|
||||||
|
if(auto PC = ACustomPlayerController::Get())
|
||||||
|
return Cast<APlayerBase>(PC->GetPawn());
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void APlayerBase::BeginPlay()
|
void APlayerBase::BeginPlay()
|
||||||
{
|
{
|
||||||
ACharacter::BeginPlay();
|
ACharacter::BeginPlay();
|
||||||
@ -226,6 +232,11 @@ void APlayerBase::LoadInteractablesActivators()
|
|||||||
TSet<UClass*> instancedActivators;
|
TSet<UClass*> instancedActivators;
|
||||||
for(auto& act : AInteractable::interactionActivators)
|
for(auto& act : AInteractable::interactionActivators)
|
||||||
{
|
{
|
||||||
|
if(act.Get())
|
||||||
|
if(auto obj = Cast<UInteractableActivator>(act.Get()->GetDefaultObject()))
|
||||||
|
if(!obj->AutoInstantiateInPlayer())
|
||||||
|
continue;
|
||||||
|
|
||||||
if(instancedActivators.Contains(act.Get()))
|
if(instancedActivators.Contains(act.Get()))
|
||||||
continue;
|
continue;
|
||||||
instancedActivators.Add(act.Get());
|
instancedActivators.Add(act.Get());
|
||||||
|
@ -8,8 +8,9 @@
|
|||||||
|
|
||||||
enum class EActivatorType : uint8;
|
enum class EActivatorType : uint8;
|
||||||
|
|
||||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FPlayerMovedDelegate);
|
/**
|
||||||
|
* Bit collection of player locks.
|
||||||
|
*/
|
||||||
USTRUCT(BlueprintType)
|
USTRUCT(BlueprintType)
|
||||||
struct FPlayerLock
|
struct FPlayerLock
|
||||||
{
|
{
|
||||||
@ -25,17 +26,27 @@ struct FPlayerLock
|
|||||||
static FPlayerLock All();
|
static FPlayerLock All();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for player pawn.
|
||||||
|
* Synchronizes movement speed with fps, manages camera and inventory,
|
||||||
|
* prepares for work with interactables, and manages basic player input.
|
||||||
|
*/
|
||||||
UCLASS(Blueprintable, BlueprintType)
|
UCLASS(Blueprintable, BlueprintType)
|
||||||
class APlayerBase : public ACharacter
|
class APlayerBase : public ACharacter
|
||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/** setup input context, camera and inventory */
|
||||||
APlayerBase();
|
APlayerBase();
|
||||||
|
|
||||||
|
|
||||||
virtual void Tick(float DeltaTime) override;
|
virtual void Tick(float DeltaTime) override;
|
||||||
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintPure, meta = (DisplayName = "Get Player Base Pawn"))
|
||||||
|
static APlayerBase* Get();
|
||||||
|
|
||||||
UFUNCTION(BlueprintPure)
|
UFUNCTION(BlueprintPure)
|
||||||
bool IsMoving();
|
bool IsMoving();
|
||||||
UFUNCTION(BlueprintPure)
|
UFUNCTION(BlueprintPure)
|
||||||
@ -46,22 +57,27 @@ public:
|
|||||||
void LockPlayer(const FPlayerLock lock);
|
void LockPlayer(const FPlayerLock lock);
|
||||||
void UnlockPlayer(const FPlayerLock lock);
|
void UnlockPlayer(const FPlayerLock lock);
|
||||||
void FlyMode(bool on);
|
void FlyMode(bool on);
|
||||||
|
|
||||||
|
/** Force interactable activators reset */
|
||||||
void ResetInteractions();
|
void ResetInteractions();
|
||||||
|
|
||||||
|
/** Switch camera possesion to passed Actor */
|
||||||
UFUNCTION(BlueprintCallable, Category = Character)
|
UFUNCTION(BlueprintCallable, Category = Character)
|
||||||
void SwitchToView(class AActor* target);
|
void SwitchToView(class AActor* target);
|
||||||
|
/** Posess player camera */
|
||||||
UFUNCTION(BlueprintCallable, Category = Character)
|
UFUNCTION(BlueprintCallable, Category = Character)
|
||||||
void ReturnPlayerView();
|
void ReturnPlayerView();
|
||||||
|
|
||||||
|
/** Place item into first inventory */
|
||||||
UFUNCTION(BlueprintCallable, Category = Character)
|
UFUNCTION(BlueprintCallable, Category = Character)
|
||||||
void TakeItemToLeftHand(class AActor* actor);
|
void TakeItemToLeftHand(class AActor* actor);
|
||||||
|
/** Place item into second inventory */
|
||||||
UFUNCTION(BlueprintCallable, Category = Character)
|
UFUNCTION(BlueprintCallable, Category = Character)
|
||||||
void TakeItemToRightHand(class AActor* actor);
|
void TakeItemToRightHand(class AActor* actor);
|
||||||
|
/** Check if Actor is in inventory */
|
||||||
UFUNCTION(BlueprintCallable, Category = Character)
|
UFUNCTION(BlueprintCallable, Category = Character)
|
||||||
bool IsInInventory(const class AActor* actor);
|
bool IsInInventory(const class AActor* actor);
|
||||||
|
|
||||||
UPROPERTY(BlueprintAssignable)
|
|
||||||
FPlayerMovedDelegate OnPlayerMoved;
|
|
||||||
FVector moveVector;
|
FVector moveVector;
|
||||||
|
|
||||||
class AActor* leftPocketItem = nullptr;
|
class AActor* leftPocketItem = nullptr;
|
||||||
@ -81,6 +97,7 @@ protected:
|
|||||||
UFUNCTION(BlueprintCallable, Category = Character)
|
UFUNCTION(BlueprintCallable, Category = Character)
|
||||||
void SwitchRun(bool run);
|
void SwitchRun(bool run);
|
||||||
|
|
||||||
|
/** Sets camera pitch range */
|
||||||
UFUNCTION(BlueprintCallable, Category = Character)
|
UFUNCTION(BlueprintCallable, Category = Character)
|
||||||
void UpdatePitch(float min, float max);
|
void UpdatePitch(float min, float max);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user