// Oleg Petruny proprietary.

#pragma once

#include "Engine/GameInstance.h"

#include "CustomGameInstance.generated.h"

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FLevelBeginnedDelegate, FName, levelName);

/**
 * Expands basic UE game instance.
 * Manages saves, handles content loader and can shutdown the game.
 */
UCLASS()
class UCustomGameInstance : public UGameInstance
{
    GENERATED_BODY()

public:
    /** Instantiates content loader, dummy save data and applies settings */
    virtual void Init() override;

    UFUNCTION(BlueprintPure, meta = (DisplayName = "Get Custom Game Instance"))
    static UCustomGameInstance* Get();

    UFUNCTION(BlueprintPure)
    static class UContentLoader* GetContentLoader();

    UFUNCTION(BlueprintCallable, Category = Save)
    void SaveGame(FName checkpointName);
    UFUNCTION(BlueprintCallable, Category = Save)
    void LoadGame();
    UFUNCTION(BlueprintCallable)
    void ExitGame();

    static UCustomGameInstance* instance;

    /** Public delegate called by ALevelBase instance on instantiation */
    FLevelBeginnedDelegate OnLevelBeginned;

    UPROPERTY(VisibleAnywhere)
    class USaveData* saveData = nullptr;

protected:
    UPROPERTY()
    class UContentLoader* contentLoader;

};
