From fda286c6f63e2dd4dd2d0a84440e9cb374e5445c Mon Sep 17 00:00:00 2001
From: jehret <ehret@vr.rwth-aachen.de>
Date: Mon, 15 Jan 2024 16:48:36 +0100
Subject: [PATCH] use given custom ID when recovering closes #106

---
 .../Private/SFGameInstance.cpp                | 42 +++++++++++--------
 1 file changed, 24 insertions(+), 18 deletions(-)

diff --git a/Source/StudyFrameworkPlugin/Private/SFGameInstance.cpp b/Source/StudyFrameworkPlugin/Private/SFGameInstance.cpp
index b44599d..15f0a96 100644
--- a/Source/StudyFrameworkPlugin/Private/SFGameInstance.cpp
+++ b/Source/StudyFrameworkPlugin/Private/SFGameInstance.cpp
@@ -282,25 +282,31 @@ void USFGameInstance::PrepareWithStudySetup(ASFStudySetup* Setup)
 	FString ParticipantID = "";
 	if(Setup->bUseCustomParticipantIDs)
 	{
-		//ask for it:
-		bool bValidIDEntered = false;
-		while(!bValidIDEntered)
-		{
-			FString IDGiven;
-			int Result = FSFUtils::OpenCustomDialogText("Participant ID", "Please type in your ID:", "", IDGiven);
-			if (Result < 0) {
-				FSFLoggingUtils::Log("[USFGameInstance::PrepareWithStudySetup] The window for entering the participant ID was closed without giving an answer, repeat question!", false);
-				continue;
-			}
-			//check whether it was used before
-			if(USFParticipant::WasParticipantIdAlreadyUsed(IDGiven))
-			{
-				FSFUtils::OpenMessageBox("Participant ID \"" + IDGiven + "\"was already used, you have to choose another one!");
-			}
-			else
+		//if we arerecovering, restore it:
+		if (bRecoverParticipantData) {
+			ParticipantID = USFParticipant::GetLastParticipantID();
+		}
+		else {
+			//ask for it:
+			bool bValidIDEntered = false;
+			while (!bValidIDEntered)
 			{
-				ParticipantID = IDGiven;
-				bValidIDEntered = true;
+				FString IDGiven;
+				int Result = FSFUtils::OpenCustomDialogText("Participant ID", "Please type in your ID:", "", IDGiven);
+				if (Result < 0) {
+					FSFLoggingUtils::Log("[USFGameInstance::PrepareWithStudySetup] The window for entering the participant ID was closed without giving an answer, repeat question!", false);
+					continue;
+				}
+				//check whether it was used before
+				if (USFParticipant::WasParticipantIdAlreadyUsed(IDGiven))
+				{
+					FSFUtils::OpenMessageBox("Participant ID \"" + IDGiven + "\"was already used, you have to choose another one!");
+				}
+				else
+				{
+					ParticipantID = IDGiven;
+					bValidIDEntered = true;
+				}
 			}
 		}
 	}
-- 
GitLab