You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.3 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using System.Collections.Generic;
  4. namespace AmplifyShaderEditor
  5. {
  6. public class ActionLog
  7. {
  8. private int m_maxCount;
  9. private int m_index;
  10. private List<ActionData> m_sequence;
  11. public ActionLog(int maxCount)
  12. {
  13. m_maxCount = maxCount;
  14. m_index = 0;
  15. m_sequence = new List<ActionData>();
  16. }
  17. public void AddToLog(ActionData actionData)
  18. {
  19. if (m_sequence.Count > m_maxCount)
  20. {
  21. m_sequence.RemoveAt(0);
  22. }
  23. m_sequence.Add(actionData);
  24. m_index = m_sequence.Count - 1;
  25. }
  26. public void UndoLastAction()
  27. {
  28. if ( m_index > -1 && m_index < m_sequence.Count )
  29. m_sequence[m_index--].ExecuteReverse();
  30. }
  31. public void RedoLastAction()
  32. {
  33. if (m_index < (m_sequence.Count - 1))
  34. m_sequence[++m_index].ExecuteForward();
  35. }
  36. public void ClearLog()
  37. {
  38. m_sequence.Clear();
  39. m_index = 0;
  40. }
  41. public void Destroy()
  42. {
  43. m_sequence.Clear();
  44. m_sequence = null;
  45. }
  46. }
  47. }