#include "UIWindowSaveGame.h"

#include "Kismet/GameplayStatics.h"

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

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

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

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

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