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

public class UndoStack : MonoBehaviour {

    [SerializeField]
    private float stackCount = 10;

    private DeformationManager _deformationManager;

    private LinkedList<IUndoAction> undoStack;

	public void InitializeUndoStack(DeformationManager deformationManager)
    {
        undoStack = new LinkedList<IUndoAction>();
        _deformationManager = deformationManager;
    }

    public void StepBack()
    {
        if (undoStack.Count == 0)
        {
            return;
        }
        IUndoAction action = undoStack.Last.Value;
        undoStack.RemoveLast();
        action.RevertAction(_deformationManager);
    }

    public void AddStep(IUndoAction action)
    {
        action.SetupUndoAction(_deformationManager);
        if (undoStack.Count >= 10)
        {
            undoStack.RemoveFirst();
        }

        undoStack.AddLast(action);
    }
}
