#include "UIWindowSaveGame.h"

#include "Kismet/GameplayStatics.h"

const FString UZMMOUISaveGame::SlotName = TEXT("UIPrefs");

UZMMOUISaveGame* UZMMOUISaveGame::LoadOrCreate()
{
	if (UGameplayStatics::DoesSaveGameExist(SlotName, UserIndex))
	{
		if (UZMMOUISaveGame* Loaded = Cast<UZMMOUISaveGame>(
			UGameplayStatics::LoadGameFromSlot(SlotName, UserIndex)))
		{
			return Loaded;
		}
	}
	return Cast<UZMMOUISaveGame>(
		UGameplayStatics::CreateSaveGameObject(UZMMOUISaveGame::StaticClass()));
}

void UZMMOUISaveGame::SaveNow(UZMMOUISaveGame* Save)
{
	if (Save)
	{
		UGameplayStatics::SaveGameToSlot(Save, SlotName, UserIndex);
	}
}

bool UZMMOUISaveGame::TryGetWindowPosition(FName WindowId, FVector2D& OutPos) const
{
	if (const FVector2D* Found = WindowPositions.Find(WindowId))
	{
		OutPos = *Found;
		return true;
	}
	OutPos = FVector2D::ZeroVector;
	return false;
}

void UZMMOUISaveGame::SetWindowPosition(FName WindowId, FVector2D Pos)
{
	WindowPositions.Add(WindowId, Pos);
}
