using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

[System.Serializable]
public class GameData
{
    public long lastUpdated;
    public Vector3 playerPosition;

    //Inventory Variables
    public List<Item> itemsSave = new List<Item>();
    public SerializableDictionary<string, bool> coinsCollected;
    public SerializableDictionary<string, bool> inventorySave;
    public SerializableDictionary<Item, bool> itemsToLoad;
    public int coinsToLoad;
    public SerializableDictionary<string, bool> locationSave;

    //World Variables
    public SerializableDictionary<string, bool> doorsDict;
    
    //Dialogue Variables 
    public SerializableDictionary<string, string> _diaStringS;
    public SerializableDictionary<string, bool> _diaBoolS;
    public SerializableDictionary<string, float> _diaFloatS;
    public Dictionary<string, string> _diaString;
    public Dictionary<string, float> _diaFloat;
    public Dictionary<string, bool> _diaBool;

    //sounds
    public int fpsIndexToLoad;
    public bool isVSyncOnToLoad;
    public int qualityToLoad;
    public bool fullscreenToLoad;
    public float volumeMainToLoad;
    public float volumeMusicToLoad;
    public float volumeSoundsToLoad;

    public GameData() 
    {
        //Settings Variables Set
        fullscreenToLoad = false;
        isVSyncOnToLoad = false;
        fpsIndexToLoad = 2;
        qualityToLoad = 2;
        volumeMainToLoad = 0;
        volumeMusicToLoad = 0;
        volumeSoundsToLoad = 0;

        //Inventory Variables Set
        playerPosition = Vector3.zero;
        itemsSave = new List<Item>();
        coinsCollected = new SerializableDictionary<string, bool>();
        inventorySave = new SerializableDictionary<string, bool>();
        locationSave = new SerializableDictionary<string, bool>();
        coinsToLoad = 0;

        //Dialogue Variables Set
        _diaStringS = new SerializableDictionary<string, string>();
        _diaBoolS = new SerializableDictionary<string, bool>();
        _diaFloatS = new SerializableDictionary<string, float>();

        _diaBool = new Dictionary<string, bool>();
        _diaFloat = new Dictionary<string, float>();
        _diaString = new Dictionary<string, string>();

        //Worlds Variables Set
        doorsDict = new SerializableDictionary<string, bool>();
    }

    public int GetPercentageComplete() 
    {
        int totalCollected = 0;
        foreach (bool collected in coinsCollected.Values) 
        {
            if (collected) 
            {
                totalCollected++;
            }
        }

        int percentageCompleted = 0;
        if (coinsCollected.Count != 0) 
        {
            percentageCompleted = totalCollected;
        }
        return percentageCompleted;
    }

    public int GetAreasCleared() 
    {
        int clearedAreas = 75;
        foreach (bool collected in coinsCollected.Values) 
        {
            if (collected) 
            {
                clearedAreas++;
            }
        }

        return clearedAreas;
    }

}