using System.Collections.Generic; using System.Linq; namespace BizHawk.Client.Common { public class MovieRecord { private byte[] _state = new byte[0]; private Dictionary _boolButtons = new Dictionary(); public MovieRecord(Dictionary buttons, bool captureState) { SetInput(buttons); if (captureState) { CaptureSate(); } } public Dictionary Buttons { get { return _boolButtons; } } public bool Lagged { get; private set; } #region Input Api public bool IsPressed(string buttonName) { return _boolButtons[buttonName]; } public void SetButton(string button, bool pressed) { InputChanged(new Dictionary { { button, pressed } }); _boolButtons[button] = pressed; } public void SetInput(Dictionary buttons) { InputChanged(buttons); _boolButtons.Clear(); _boolButtons = buttons; } public void CaptureSate() { Lagged = Global.Emulator.IsLagFrame; _state = (byte[])Global.Emulator.SaveStateBinary().Clone(); } public void ClearInput() { InputChanged(_boolButtons); _boolButtons.Clear(); } #endregion #region State API public IEnumerable State { get { return _state; } } public bool HasState { get { return State.Any(); } } public void ClearState() { _state = new byte[0]; } #endregion #region Event Handling public class InputEventArgs { public InputEventArgs(Dictionary editedButtons) { EditedButtons = editedButtons; } public Dictionary EditedButtons { get; private set; } } public delegate void InputEventHandler(object sender, InputEventArgs e); public event InputEventHandler OnChanged; private void InputChanged(Dictionary editedButtons) { if (OnChanged != null) { OnChanged(this, new InputEventArgs(editedButtons)); } } #endregion } }