Compare commits
No commits in common. "c941024ecf4d603a7086d8b982b6a98e6a42fced" and "b4faa6ce0ca01c80766ae7afb52ce0beda1f8bed" have entirely different histories.
c941024ecf
...
b4faa6ce0c
|
@ -3,9 +3,6 @@
|
|||
|
||||
#include "NakatomiGameInstance.h"
|
||||
|
||||
#include "PlayerCharacter.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
|
||||
UNakatomiAIAttackTokenManager* UNakatomiGameInstance::GetAIAttackTokenManager()
|
||||
{
|
||||
return IsValid(AIAttackTokenManager) ? AIAttackTokenManager : (AIAttackTokenManager = NewObject<UNakatomiAIAttackTokenManager>(this, TEXT("AI Attack Token Manager")));
|
||||
|
@ -22,89 +19,3 @@ void UNakatomiGameInstance::SetCurrentLevelManager(UNakatomiLevelManager* NewLev
|
|||
{
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
#include "Engine/GameInstance.h"
|
||||
#include "NakatomiAIAttackTokenManager.h"
|
||||
#include "NakatomiLevelManager.h"
|
||||
#include "NakatomiSaveFileInfo.h"
|
||||
#include "NakatomiSaveGame.h"
|
||||
#include "NakatomiGameInstance.generated.h"
|
||||
|
||||
/**
|
||||
|
@ -27,9 +25,6 @@ private:
|
|||
UPROPERTY()
|
||||
UNakatomiAIAttackTokenManager* AIAttackTokenManager;
|
||||
|
||||
UPROPERTY()
|
||||
UNakatomiSaveGame* SaveGameObject = nullptr;
|
||||
|
||||
public:
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
|
@ -40,19 +35,4 @@ public:
|
|||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
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();
|
||||
};
|
||||
|
|
|
@ -3,25 +3,13 @@
|
|||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "NakatomiSaveFileInfo.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
USTRUCT(BlueprintType)
|
||||
struct FNakatomiSaveFileInfo
|
||||
class NAKATOMI_API NakatomiSaveFileInfo
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Info")
|
||||
FString SaveSlotName;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Info")
|
||||
FString PlayerName;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Info")
|
||||
FString CurrentLevel;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Info")
|
||||
FString DateTimeSaved;
|
||||
public:
|
||||
NakatomiSaveFileInfo();
|
||||
~NakatomiSaveFileInfo();
|
||||
};
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Weapon.h"
|
||||
#include "GameFramework/SaveGame.h"
|
||||
#include "NakatomiSaveGame.generated.h"
|
||||
|
||||
|
@ -15,25 +14,4 @@ class NAKATOMI_API UNakatomiSaveGame : public USaveGame
|
|||
{
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue