Add MVP reconnect snapshots

This commit is contained in:
2026-05-18 15:23:01 -07:00
parent 3b772da73c
commit 0b9a8b7b30
7 changed files with 208 additions and 49 deletions
@@ -1,11 +1,37 @@
// Copyright Epic Games, Inc. All Rights Reserved.
#include "AgrarianGameGameMode.h"
#include "AgrarianGameCharacter.h"
#include "AgrarianDebugHUD.h"
#include "AgrarianGameState.h"
#include "AgrarianPersistenceSubsystem.h"
AAgrarianGameGameMode::AAgrarianGameGameMode()
{
GameStateClass = AAgrarianGameState::StaticClass();
HUDClass = AAgrarianDebugHUD::StaticClass();
}
void AAgrarianGameGameMode::RestartPlayer(AController* NewPlayer)
{
Super::RestartPlayer(NewPlayer);
AAgrarianGameCharacter* AgrarianCharacter = NewPlayer ? Cast<AAgrarianGameCharacter>(NewPlayer->GetPawn()) : nullptr;
UAgrarianPersistenceSubsystem* Persistence = GetGameInstance() ? GetGameInstance()->GetSubsystem<UAgrarianPersistenceSubsystem>() : nullptr;
if (AgrarianCharacter && Persistence && Persistence->RestorePlayerSnapshot(AgrarianCharacter))
{
UE_LOG(LogTemp, Log, TEXT("Agrarian restored reconnect snapshot for %s."), *AgrarianCharacter->GetName());
}
}
void AAgrarianGameGameMode::Logout(AController* Exiting)
{
AAgrarianGameCharacter* AgrarianCharacter = Exiting ? Cast<AAgrarianGameCharacter>(Exiting->GetPawn()) : nullptr;
UAgrarianPersistenceSubsystem* Persistence = GetGameInstance() ? GetGameInstance()->GetSubsystem<UAgrarianPersistenceSubsystem>() : nullptr;
if (AgrarianCharacter && Persistence)
{
Persistence->SavePlayerSnapshot(AgrarianCharacter);
}
Super::Logout(Exiting);
}