diff --git a/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test.umap b/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test.umap index d2003e9..f37d0f1 100644 --- a/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test.umap +++ b/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5a21e30d394d56b1c2061bed1b28ca77f40a64d1e85147bf1bbdfcbbe91fc2b5 -size 2267466 +oid sha256:654c333de2b64ac0da0ff144917ff839fbf97858a564007816c2aec6cc5e678a +size 2266458 diff --git a/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test_BuiltData.uasset b/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test_BuiltData.uasset index 216ce28..2100858 100644 --- a/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test_BuiltData.uasset +++ b/UnrealProject/Lost_Edge/Content/Levels/Test/L_Test_BuiltData.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6aa7b92951a49c50d63d075885fd2b0c00041360b6721a5c84d2a16f68f8c562 -size 586263 +oid sha256:4709c1328015fe0ec6ae192210f49e06972893eb6ab740df18bb7a18a181a2c0 +size 585835 diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CommonFunctions.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CommonFunctions.cpp index 8a76869..c45eec7 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CommonFunctions.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CommonFunctions.cpp @@ -53,25 +53,6 @@ TArray 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(script); - return nullptr; -} - -APlayerBase* UCommonFunctions::GetPlayer(UObject* obj) -{ - if(auto pc = UGameplayStatics::GetPlayerController(obj->GetWorld(), 0)) - if(auto pawn = pc->GetPawn()) - return Cast(pawn); - return nullptr; -} - - - namespace SlowMotion { FTimerHandle timer; diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CommonFunctions.h b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CommonFunctions.h index b5c9b17..56d9dae 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CommonFunctions.h +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CommonFunctions.h @@ -2,34 +2,33 @@ #pragma once -#include "CoreMinimal.h" #include "Kismet/BlueprintFunctionLibrary.h" #include "CommonFunctions.generated.h" DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FWorldDilationChangedDelegate, float, newDilation); +/** + * Collection of common/universal/without own scope/specific functions. + */ UCLASS() class UCommonFunctions : public UBlueprintFunctionLibrary { GENERATED_BODY() 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); + + /** "Overload" of the built-in keys translator (to not build own engine copy) */ + UFUNCTION(BlueprintPure) 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) static void DestroyActorRecursively(class AActor* actor); - UFUNCTION(BlueprintPure) - static TArray 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) @@ -41,6 +40,10 @@ public: static FWorldDilationChangedDelegate& GetWorldDilationChangedDelegate(); + + UFUNCTION(BlueprintPure) + static TArray GetRandomIntArray(int32 size = 16, int32 min = 0, int32 max = 16); + template static TArray ArrayDiff(const TArray& a, const TArray& b); template diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/ContentLoader.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/ContentLoader.cpp index 8d01c52..7e56715 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/ContentLoader.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/ContentLoader.cpp @@ -1,12 +1,12 @@ // Oleg Petruny proprietary. - #include "ContentLoader.h" -#include "CommonFunctions.h" #include "IPlatformFilePak.h" #include "Misc/FileHelper.h" +#include "CommonFunctions.h" + #include #include #include diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/ContentLoader.h b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/ContentLoader.h index 2263206..ba774d9 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/ContentLoader.h +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/ContentLoader.h @@ -10,13 +10,16 @@ UENUM(BlueprintType) enum class EContentDownloadMethod : uint8 { - ClearRandom = 0, - NonRepeatRandom, - RatingOftenRandom + ClearRandom = 0, //!< Always random from 0 to n + NonRepeatRandom, //!< Download the one that isn't downloaded in current runtime (Reset on full set) + RatingOftenRandom //!< NonRepeatRandom combined with asset rating [WIP] }; DECLARE_DYNAMIC_DELEGATE_OneParam(FContentDownloadedCallback, FString, pakFilePath); +/* + * High language wrapper for Paks(Assets) download and loading. + */ UCLASS(BlueprintType) class UContentLoader : public UObject { @@ -35,12 +38,18 @@ public: protected: virtual void BeginDestroy() override; + /** Sends http get request */ void HttpGet(const FString& url, FHttpRequestCompleteDelegate requestCompleteCallback); + /** Parses assets html/json index */ TArray ParseDirectoryIndex(const TArray& content, const FString& contentType); + /** Selects item by desired method */ FString SelectContentByMethod(const TArray& content, const EContentDownloadMethod method); + /** Reads Pak content */ FString GetPakMountContent(const FString& pakFilePath, TArray* content = nullptr); + /** Returns mount path to desired content item */ UClass* GetPakClass(const FString& pakContentPath); + /** Cache of already downloaded content at runtime (used by EContentDownloadMethod::NonRepeatRandom)*/ TArray downloadedContent; }; diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CustomGameInstance.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CustomGameInstance.cpp index 47efbb7..cfe6c93 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CustomGameInstance.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CustomGameInstance.cpp @@ -5,7 +5,6 @@ #include "Kismet/GameplayStatics.h" #include "Kismet/KismetSystemLibrary.h" -#include "CommonFunctions.h" #include "ContentLoader.h" #include "Levels/LevelBase.h" #include "PlayerBase.h" @@ -37,13 +36,14 @@ UContentLoader* UCustomGameInstance::GetContentLoader() void UCustomGameInstance::SaveGame(FName checkpointName) { - auto levelScript = UCommonFunctions::GetCurrentLevelScript(this); + auto levelScript = ALevelBase::Get(); if(!levelScript) return; - auto player = UCommonFunctions::GetPlayer(this); + auto player = APlayerBase::Get(); if(!player) return; + saveData->level = GetWorld()->GetFName(); saveData->state = levelScript->GetState(); saveData->checkpoint = checkpointName; diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/LevelBase.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/LevelBase.cpp index c182262..6ee3b48 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/LevelBase.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/LevelBase.cpp @@ -9,7 +9,6 @@ #include "Kismet/GameplayStatics.h" #include "LevelSequencePlayer.h" -#include "CommonFunctions.h" #include "CustomGameInstance.h" #include "CustomPlayerController.h" #include "Interactable/Interactable.h" @@ -19,6 +18,13 @@ #include "PlayerBase.h" #include "SaveData.h" +ALevelBase* ALevelBase::Get() +{ + if(auto GM = AMainGameModeBase::Get()) + return GM->leadLevel.Get(); + return nullptr; +} + void ALevelBase::BeginPlay() { AMainGameModeBase::leadLevel = TStrongObjectPtr{ this }; @@ -78,7 +84,7 @@ void ALevelBase::ApplySaveData() IterateToState(GI->saveData->state); - auto player = UCommonFunctions::GetPlayer(this); + auto player = APlayerBase::Get(); if(!player) return; diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/LevelBase.h b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/LevelBase.h index 3c9929d..ea28374 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/LevelBase.h +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/LevelBase.h @@ -19,6 +19,10 @@ class ALevelBase : public ALevelScriptActor GENERATED_BODY() public: + /** Returns lead level script */ + UFUNCTION(BlueprintPure, meta = (DisplayName = "Get Lead Level Script")) + static ALevelBase* Get(); + /** Iterates throught level states */ UFUNCTION(BlueprintCallable) inline void CallNextState() { ++state; NextState(); } diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/Minigame.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/Minigame.cpp index 0920fac..04186f4 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/Minigame.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Minigame/Minigame.cpp @@ -2,6 +2,8 @@ #include "Minigame.h" +#include "InputMappingContext.h" + #include "CustomPlayerController.h" #include "PlayerBase.h" diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/PlayerBase.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/PlayerBase.cpp index 8458a91..853d6ba 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/PlayerBase.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/PlayerBase.cpp @@ -1,6 +1,5 @@ // Oleg Petruny proprietary. - #include "PlayerBase.h" #include "Camera/CameraComponent.h" @@ -63,6 +62,13 @@ void APlayerBase::SetupPlayerInputComponent(UInputComponent* PlayerInputComponen ACharacter::SetupPlayerInputComponent(PlayerInputComponent); } +APlayerBase* APlayerBase::Get() +{ + if(auto PC = ACustomPlayerController::Get()) + return Cast(PC->GetPawn()); + return nullptr; +} + void APlayerBase::BeginPlay() { ACharacter::BeginPlay(); @@ -226,6 +232,11 @@ void APlayerBase::LoadInteractablesActivators() TSet instancedActivators; for(auto& act : AInteractable::interactionActivators) { + if(act.Get()) + if(auto obj = Cast(act.Get()->GetDefaultObject())) + if(!obj->AutoInstantiateInPlayer()) + continue; + if(instancedActivators.Contains(act.Get())) continue; instancedActivators.Add(act.Get()); diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/PlayerBase.h b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/PlayerBase.h index 3e000e7..7d3c691 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/PlayerBase.h +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/PlayerBase.h @@ -8,8 +8,9 @@ enum class EActivatorType : uint8; -DECLARE_DYNAMIC_MULTICAST_DELEGATE(FPlayerMovedDelegate); - +/** + * Bit collection of player locks. + */ USTRUCT(BlueprintType) struct FPlayerLock { @@ -25,17 +26,27 @@ struct FPlayerLock 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) class APlayerBase : public ACharacter { GENERATED_BODY() public: + /** setup input context, camera and inventory */ APlayerBase(); + virtual void Tick(float DeltaTime) override; virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; + UFUNCTION(BlueprintPure, meta = (DisplayName = "Get Player Base Pawn")) + static APlayerBase* Get(); + UFUNCTION(BlueprintPure) bool IsMoving(); UFUNCTION(BlueprintPure) @@ -46,22 +57,27 @@ public: void LockPlayer(const FPlayerLock lock); void UnlockPlayer(const FPlayerLock lock); void FlyMode(bool on); + + /** Force interactable activators reset */ void ResetInteractions(); + /** Switch camera possesion to passed Actor */ UFUNCTION(BlueprintCallable, Category = Character) void SwitchToView(class AActor* target); + /** Posess player camera */ UFUNCTION(BlueprintCallable, Category = Character) void ReturnPlayerView(); + /** Place item into first inventory */ UFUNCTION(BlueprintCallable, Category = Character) void TakeItemToLeftHand(class AActor* actor); + /** Place item into second inventory */ UFUNCTION(BlueprintCallable, Category = Character) void TakeItemToRightHand(class AActor* actor); + /** Check if Actor is in inventory */ UFUNCTION(BlueprintCallable, Category = Character) bool IsInInventory(const class AActor* actor); - UPROPERTY(BlueprintAssignable) - FPlayerMovedDelegate OnPlayerMoved; FVector moveVector; class AActor* leftPocketItem = nullptr; @@ -81,6 +97,7 @@ protected: UFUNCTION(BlueprintCallable, Category = Character) void SwitchRun(bool run); + /** Sets camera pitch range */ UFUNCTION(BlueprintCallable, Category = Character) void UpdatePitch(float min, float max);