From 2b5d67346a224f716db343537be7d8411bfb01cd Mon Sep 17 00:00:00 2001 From: baz Date: Thu, 30 May 2024 16:54:25 +0100 Subject: [PATCH] Update Save System --- Source/Nakatomi/NakatomiGameInstance.cpp | 4 ++-- Source/Nakatomi/NakatomiSaveFileInfo.h | 11 +++++++++++ Source/Nakatomi/NakatomiSaveGame.h | 3 +++ Source/Nakatomi/PlayerCharacter.cpp | 6 ++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Source/Nakatomi/NakatomiGameInstance.cpp b/Source/Nakatomi/NakatomiGameInstance.cpp index 5a5023c..5421639 100644 --- a/Source/Nakatomi/NakatomiGameInstance.cpp +++ b/Source/Nakatomi/NakatomiGameInstance.cpp @@ -50,8 +50,8 @@ bool UNakatomiGameInstance::SaveGame(bool ResetDefaults) { APlayerCharacter* Player = Cast(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)); SaveGameObject->PlayerHealth = Player->GetCurrentHealthCount(); - SaveGameObject->WeaponInventory = Player->WeaponInventory; - SaveGameObject->CurrentInventorySlot = Player->GetCurrentInventorySlot(); + // SaveGameObject->CurrentInventorySlot = Player->GetCurrentInventorySlot(); + SaveGameObject->ThrowableInventory = Player->ThrowableInventory; } SaveGameObject->LevelName = GetWorld()->GetMapName(); diff --git a/Source/Nakatomi/NakatomiSaveFileInfo.h b/Source/Nakatomi/NakatomiSaveFileInfo.h index 2621e29..1ef824c 100644 --- a/Source/Nakatomi/NakatomiSaveFileInfo.h +++ b/Source/Nakatomi/NakatomiSaveFileInfo.h @@ -3,6 +3,8 @@ #pragma once #include "CoreMinimal.h" +#include "Weapon.h" +#include "Throwable.h" #include "NakatomiSaveFileInfo.generated.h" /** @@ -24,4 +26,13 @@ struct FNakatomiSaveFileInfo UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Info") FString DateTimeSaved; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Info") + TArray WeaponInventory; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Info") + TArray> ThrowableInventory; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Info") + int CurrentInventorySlot = 0; }; diff --git a/Source/Nakatomi/NakatomiSaveGame.h b/Source/Nakatomi/NakatomiSaveGame.h index 4949b41..55c23c6 100644 --- a/Source/Nakatomi/NakatomiSaveGame.h +++ b/Source/Nakatomi/NakatomiSaveGame.h @@ -28,6 +28,9 @@ public: UPROPERTY(VisibleAnywhere, Category = Player) TArray WeaponInventory; + UPROPERTY(VisibleAnywhere, Category = Player) + TArray> ThrowableInventory; + UPROPERTY(VisibleAnywhere, Category = Player) int CurrentInventorySlot = 0; diff --git a/Source/Nakatomi/PlayerCharacter.cpp b/Source/Nakatomi/PlayerCharacter.cpp index 9716cc9..cc1fcd1 100644 --- a/Source/Nakatomi/PlayerCharacter.cpp +++ b/Source/Nakatomi/PlayerCharacter.cpp @@ -87,6 +87,12 @@ void APlayerCharacter::BeginPlay() { //TODO: More loading here GetHealthComponent()->SetCurrentHealth(Save->PlayerHealth); + + if (Save->ThrowableInventory.Num() > 0) + { + ThrowableInventory.Empty(); + ThrowableInventory = Save->ThrowableInventory; + } } }