Compare commits

...

2 Commits

Author SHA1 Message Date
baz 2b5d67346a Update Save System 2024-05-30 16:54:25 +01:00
baz 804a752aa5 Move save logic from NakatomiCharacter to PlayerCharacter 2024-05-28 01:55:46 +01:00
5 changed files with 32 additions and 12 deletions

View File

@ -5,7 +5,6 @@
#include "NakatomiCMC.h" #include "NakatomiCMC.h"
#include "NakatomiGameInstance.h" #include "NakatomiGameInstance.h"
#include "Kismet/GameplayStatics.h"
// Sets default values // Sets default values
ANakatomiCharacter::ANakatomiCharacter(const FObjectInitializer& ObjectInitializer) : Super( ANakatomiCharacter::ANakatomiCharacter(const FObjectInitializer& ObjectInitializer) : Super(
@ -32,15 +31,6 @@ void ANakatomiCharacter::BeginPlay()
SetInventoryToDefault(); SetInventoryToDefault();
NakatomiCMC = Cast<UNakatomiCMC>(GetCharacterMovement()); NakatomiCMC = Cast<UNakatomiCMC>(GetCharacterMovement());
if (UNakatomiGameInstance* gameInstance = Cast<UNakatomiGameInstance>(UGameplayStatics::GetGameInstance(GetWorld())))
{
if (UNakatomiSaveGame* Save = gameInstance->GetSaveGameObject())
{
//TODO: More loading here
GetHealthComponent()->SetCurrentHealth(Save->PlayerHealth);
}
}
} }
// Called every frame // Called every frame

View File

@ -50,8 +50,8 @@ bool UNakatomiGameInstance::SaveGame(bool ResetDefaults)
{ {
APlayerCharacter* Player = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)); APlayerCharacter* Player = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
SaveGameObject->PlayerHealth = Player->GetCurrentHealthCount(); SaveGameObject->PlayerHealth = Player->GetCurrentHealthCount();
SaveGameObject->WeaponInventory = Player->WeaponInventory; // SaveGameObject->CurrentInventorySlot = Player->GetCurrentInventorySlot();
SaveGameObject->CurrentInventorySlot = Player->GetCurrentInventorySlot(); SaveGameObject->ThrowableInventory = Player->ThrowableInventory;
} }
SaveGameObject->LevelName = GetWorld()->GetMapName(); SaveGameObject->LevelName = GetWorld()->GetMapName();

View File

@ -3,6 +3,8 @@
#pragma once #pragma once
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "Weapon.h"
#include "Throwable.h"
#include "NakatomiSaveFileInfo.generated.h" #include "NakatomiSaveFileInfo.generated.h"
/** /**
@ -24,4 +26,13 @@ struct FNakatomiSaveFileInfo
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Info") UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Info")
FString DateTimeSaved; FString DateTimeSaved;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Info")
TArray<AWeapon*> WeaponInventory;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Info")
TArray<TSubclassOf<AThrowable>> ThrowableInventory;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Info")
int CurrentInventorySlot = 0;
}; };

View File

@ -28,6 +28,9 @@ public:
UPROPERTY(VisibleAnywhere, Category = Player) UPROPERTY(VisibleAnywhere, Category = Player)
TArray<AWeapon*> WeaponInventory; TArray<AWeapon*> WeaponInventory;
UPROPERTY(VisibleAnywhere, Category = Player)
TArray<TSubclassOf<AThrowable>> ThrowableInventory;
UPROPERTY(VisibleAnywhere, Category = Player) UPROPERTY(VisibleAnywhere, Category = Player)
int CurrentInventorySlot = 0; int CurrentInventorySlot = 0;

View File

@ -13,6 +13,7 @@
#include "InputTriggers.h" #include "InputTriggers.h"
#include "InteractableComponent.h" #include "InteractableComponent.h"
#include "NakatomiCMC.h" #include "NakatomiCMC.h"
#include "NakatomiGameInstance.h"
#include "WeaponThrowable.h" #include "WeaponThrowable.h"
#include "NiagaraFunctionLibrary.h" #include "NiagaraFunctionLibrary.h"
#include "GameFramework/CharacterMovementComponent.h" #include "GameFramework/CharacterMovementComponent.h"
@ -80,6 +81,21 @@ void APlayerCharacter::BeginPlay()
AimSensitivity = DefaultAimSensitivity; AimSensitivity = DefaultAimSensitivity;
if (UNakatomiGameInstance* gameInstance = Cast<UNakatomiGameInstance>(UGameplayStatics::GetGameInstance(GetWorld())))
{
if (UNakatomiSaveGame* Save = gameInstance->GetSaveGameObject())
{
//TODO: More loading here
GetHealthComponent()->SetCurrentHealth(Save->PlayerHealth);
if (Save->ThrowableInventory.Num() > 0)
{
ThrowableInventory.Empty();
ThrowableInventory = Save->ThrowableInventory;
}
}
}
if (!this->ActorHasTag(FName("Player"))) if (!this->ActorHasTag(FName("Player")))
{ {
this->Tags.Add(FName("Player")); this->Tags.Add(FName("Player"));