Compare commits

..

No commits in common. "c941024ecf4d603a7086d8b982b6a98e6a42fced" and "b4faa6ce0ca01c80766ae7afb52ce0beda1f8bed" have entirely different histories.

4 changed files with 4 additions and 147 deletions

View File

@ -3,9 +3,6 @@
#include "NakatomiGameInstance.h" #include "NakatomiGameInstance.h"
#include "PlayerCharacter.h"
#include "Kismet/GameplayStatics.h"
UNakatomiAIAttackTokenManager* UNakatomiGameInstance::GetAIAttackTokenManager() UNakatomiAIAttackTokenManager* UNakatomiGameInstance::GetAIAttackTokenManager()
{ {
return IsValid(AIAttackTokenManager) ? AIAttackTokenManager : (AIAttackTokenManager = NewObject<UNakatomiAIAttackTokenManager>(this, TEXT("AI Attack Token Manager"))); return IsValid(AIAttackTokenManager) ? AIAttackTokenManager : (AIAttackTokenManager = NewObject<UNakatomiAIAttackTokenManager>(this, TEXT("AI Attack Token Manager")));
@ -22,89 +19,3 @@ void UNakatomiGameInstance::SetCurrentLevelManager(UNakatomiLevelManager* NewLev
{ {
currentLevelManager = NewLevelManager; currentLevelManager = NewLevelManager;
} }
UNakatomiSaveGame* UNakatomiGameInstance::LoadGameFromSlot(FString SaveSlotName)
{
if (UNakatomiSaveGame* Save = Cast<UNakatomiSaveGame>(UGameplayStatics::LoadGameFromSlot(SaveSlotName, 0)))
{
SaveGameObject = Save;
return SaveGameObject;
}
return nullptr;
}
bool UNakatomiGameInstance::SaveGame(bool ResetDefaults)
{
if (SaveGameObject == nullptr)
{
UE_LOG(LogTemp, Warning, TEXT("SaveGame called without a loaded save game object."));
return false;
}
if (ResetDefaults)
{
SaveGameObject->ResetPlayerValuesToDefault();
}
else
{
APlayerCharacter* Player = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
SaveGameObject->PlayerHealth = Player->GetCurrentHealthCount();
SaveGameObject->WeaponInventory = Player->WeaponInventory;
SaveGameObject->CurrentInventorySlot = Player->GetCurrentInventorySlot();
}
SaveGameObject->LevelName = GetWorld()->GetMapName();
SaveGameObject->LevelName.RemoveFromStart(GetWorld()->StreamingLevelsPrefix);
return UGameplayStatics::SaveGameToSlot(SaveGameObject, SaveGameObject->PlayerName, 0);
}
UNakatomiSaveGame* UNakatomiGameInstance::GetSaveGameObject()
{
return SaveGameObject;
}
// TODO: This should either fail or append number if a save already exists with the same name
UNakatomiSaveGame* UNakatomiGameInstance::CreateNewSaveGame(FString PlayerName)
{
if (UNakatomiSaveGame* Save = Cast<UNakatomiSaveGame>(
UGameplayStatics::CreateSaveGameObject(UNakatomiSaveGame::StaticClass())))
{
SaveGameObject->PlayerName = PlayerName;
if (UGameplayStatics::SaveGameToSlot(Save, PlayerName, 0))
{
SaveGameObject = Save;
return SaveGameObject;
}
}
return nullptr;
}
TArray<FNakatomiSaveFileInfo> UNakatomiGameInstance::GetAllSaveFilesFromDisk()
{
TArray<FNakatomiSaveFileInfo> Files;
IFileManager& FileManager = IFileManager::Get();
FString SavedGamesFolder = FString{FPaths::ProjectSavedDir()} + "SaveGames/";
TArray<FString> FileNames;
FileManager.FindFiles(FileNames, *SavedGamesFolder, TEXT("*.sav"));
for (FString FileName : FileNames)
{
FileName.RemoveFromEnd(".sav");
if (UNakatomiSaveGame* saveGameObject = Cast<UNakatomiSaveGame>(UGameplayStatics::LoadGameFromSlot(FileName, 0)))
{
Files.Add({FileName,
saveGameObject->PlayerName,
saveGameObject->LevelName,
FileManager.GetTimeStamp(*(SavedGamesFolder + FileName + ".sav")).ToString()});
}
}
return Files;
}

View File

@ -6,8 +6,6 @@
#include "Engine/GameInstance.h" #include "Engine/GameInstance.h"
#include "NakatomiAIAttackTokenManager.h" #include "NakatomiAIAttackTokenManager.h"
#include "NakatomiLevelManager.h" #include "NakatomiLevelManager.h"
#include "NakatomiSaveFileInfo.h"
#include "NakatomiSaveGame.h"
#include "NakatomiGameInstance.generated.h" #include "NakatomiGameInstance.generated.h"
/** /**
@ -27,9 +25,6 @@ private:
UPROPERTY() UPROPERTY()
UNakatomiAIAttackTokenManager* AIAttackTokenManager; UNakatomiAIAttackTokenManager* AIAttackTokenManager;
UPROPERTY()
UNakatomiSaveGame* SaveGameObject = nullptr;
public: public:
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
@ -40,19 +35,4 @@ public:
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
void SetCurrentLevelManager(UNakatomiLevelManager* NewLevelManager); void SetCurrentLevelManager(UNakatomiLevelManager* NewLevelManager);
UFUNCTION(BlueprintCallable)
UNakatomiSaveGame* LoadGameFromSlot(FString SaveSlotName);
UFUNCTION(BlueprintCallable)
bool SaveGame(bool ResetDefaults);
UFUNCTION(BlueprintCallable)
UNakatomiSaveGame* GetSaveGameObject();
UFUNCTION(BlueprintCallable)
UNakatomiSaveGame* CreateNewSaveGame(FString PlayerName);
UFUNCTION(BlueprintCallable)
TArray<FNakatomiSaveFileInfo> GetAllSaveFilesFromDisk();
}; };

View File

@ -3,25 +3,13 @@
#pragma once #pragma once
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "NakatomiSaveFileInfo.generated.h"
/** /**
* *
*/ */
USTRUCT(BlueprintType) class NAKATOMI_API NakatomiSaveFileInfo
struct FNakatomiSaveFileInfo
{ {
GENERATED_BODY() public:
NakatomiSaveFileInfo();
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Info") ~NakatomiSaveFileInfo();
FString SaveSlotName;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Info")
FString PlayerName;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Info")
FString CurrentLevel;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Info")
FString DateTimeSaved;
}; };

View File

@ -3,7 +3,6 @@
#pragma once #pragma once
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "Weapon.h"
#include "GameFramework/SaveGame.h" #include "GameFramework/SaveGame.h"
#include "NakatomiSaveGame.generated.h" #include "NakatomiSaveGame.generated.h"
@ -14,26 +13,5 @@ UCLASS()
class NAKATOMI_API UNakatomiSaveGame : public USaveGame class NAKATOMI_API UNakatomiSaveGame : public USaveGame
{ {
GENERATED_BODY() GENERATED_BODY()
public:
UPROPERTY(VisibleAnywhere, Category = Basic)
FString PlayerName = "Player Name";
UPROPERTY(VisibleAnywhere, Category = Level)
FString LevelName = "Level1";
UPROPERTY(VisibleAnywhere, Category = Player)
float PlayerHealth = 100.0f;
UPROPERTY(VisibleAnywhere, Category = Player)
TArray<AWeapon*> WeaponInventory;
UPROPERTY(VisibleAnywhere, Category = Player)
int CurrentInventorySlot = 0;
UFUNCTION(BlueprintCallable)
void ResetPlayerValuesToDefault()
{
PlayerHealth = 100.0f;
}
}; };