using UnityEngine;
using System.Collections;
using Framework.Entities;
using Framework.Extensions;
using System.Linq;
using System.Collections.Generic;
using Framework.InteractionSystem;
using Framework.Utility;
using Project.Actors;

namespace Project.Player
{
    public class PlayerMemory : CoreBehaviour
    {
        private Woundable woundable;

        protected override void InnerAwake()
        {
            AddGlobalActionHandler<PlayerInput.LevelChangeAction>(this, LevelChange);
            this.woundable = GetComponent<Woundable>();
            if(Application.loadedLevel != 0)
            {
                this.woundable.wounds = PlayerPrefs.GetInt("Wounds");
                Debug.Log("Get: " + PlayerPrefs.GetInt("Wounds"));
            }
            else
            {
                this.woundable.wounds = 0;
                Save();
            }
        }

        public void Save()
        {
            PlayerPrefs.SetInt("Wounds", this.woundable.wounds);
            PlayerPrefs.Save();
        }

        protected void LevelChange(PlayerInput.LevelChangeAction action)
        {
            Save();
        }
    }
}