using UnityEngine;
using UnityEngine.SceneManagement;

// Handles scene-persistent player data
public class PlayerManager : MonoBehaviour
{
    public int CurrentToolIndex;

    #region Player Data Save/Load
    public void SavePlayerData(ref PlayerSaveData data)
    {
        data.activeToolIndex = GameManager.Instance.PlayerManager.CurrentToolIndex;
        data.dougPosition = GameManager.Instance.PlayerController.transform.position;
        data.currentScene = SceneManager.GetActiveScene().name;
    }

    public void LoadPlayerData(PlayerSaveData data)
    {
        if (data.currentScene != null && data.currentScene != SceneManager.GetActiveScene().name)
        {
            GameManager.Instance.GoToMapPoint(new MapPoint(data.currentScene, data.dougPosition), true);
        }
        else
        {
            GameManager.Instance.PlayerManager.CurrentToolIndex = data.activeToolIndex;
            GameManager.Instance.PlayerController.transform.position = data.dougPosition;
        }
    }
    #endregion
}

[System.Serializable]
public struct PlayerSaveData
{
    public int activeToolIndex;
    public Vector3 dougPosition;
    public string currentScene;
}
