From d0e632ad9dd4a8924fbe9a2f852f13443d81cfc9 Mon Sep 17 00:00:00 2001 From: adelikat Date: Tue, 6 Dec 2016 11:09:17 -0600 Subject: [PATCH] code cleanup in MovieZone.cs --- .../tools/Macros/MovieZone.cs | 62 ++++++++++++++----- 1 file changed, 45 insertions(+), 17 deletions(-) diff --git a/BizHawk.Client.EmuHawk/tools/Macros/MovieZone.cs b/BizHawk.Client.EmuHawk/tools/Macros/MovieZone.cs index 7921627af7..e2174bfb0e 100644 --- a/BizHawk.Client.EmuHawk/tools/Macros/MovieZone.cs +++ b/BizHawk.Client.EmuHawk/tools/Macros/MovieZone.cs @@ -1,27 +1,25 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; using System.IO; -using BizHawk.Client.Common; using BizHawk.Emulation.Common; -using BizHawk.Client.Common.InputAdapterExtensions; +using BizHawk.Client.Common; namespace BizHawk.Client.EmuHawk { public class MovieZone { - public string Name; + public string Name { get; set; } + public int Start { get; set; } + public int Length { get; set; } - public int Start; - public int Length; private string _inputKey; public string InputKey { get { return _inputKey; } set { _inputKey = value; ReSetLog(); } } + private string[] _log; public bool Replace = true; @@ -33,16 +31,20 @@ namespace BizHawk.Client.EmuHawk public MovieZone() { } + public MovieZone(IMovie movie, int start, int length, string key = "") { - Bk2LogEntryGenerator lg = Global.MovieSession.LogGeneratorInstance() as Bk2LogEntryGenerator; + var lg = Global.MovieSession.LogGeneratorInstance() as Bk2LogEntryGenerator; lg.SetSource(Global.MovieSession.MovieControllerAdapter); targetController = new Bk2ControllerAdapter(); targetController.Type = Global.Emulator.ControllerDefinition; targetController.LatchFromSource(targetController); // Reference and create all buttons if (key == "") + { key = lg.GenerateLogKey(); + } + key = key.Replace("LogKey:", "").Replace("#", ""); key = key.Substring(0, key.Length - 1); @@ -56,13 +58,17 @@ namespace BizHawk.Client.EmuHawk for (int i = 0; i < keys.Length; i++) { if (Global.Emulator.ControllerDefinition.BoolButtons.Contains(keys[i])) + { d.BoolButtons.Add(keys[i]); + } else + { d.FloatControls.Add(keys[i]); + } } - controller = new Bk2ControllerAdapter() { Type = d }; - Bk2LogEntryGenerator logGenerator = new Bk2LogEntryGenerator(""); + controller = new Bk2ControllerAdapter { Type = d }; + var logGenerator = new Bk2LogEntryGenerator(""); logGenerator.SetSource(controller); logGenerator.GenerateLogEntry(); // Reference and create all buttons. @@ -71,7 +77,9 @@ namespace BizHawk.Client.EmuHawk if (key == movieKey) { for (int i = 0; i < length; i++) + { _log[i] = movie.GetInputLogEntry(i + start); + } } else { @@ -82,25 +90,32 @@ namespace BizHawk.Client.EmuHawk } } } + private void ReSetLog() { // Get a IController that only contains buttons in key. string[] keys = _inputKey.Split('|'); - ControllerDefinition d = new ControllerDefinition(); + var d = new ControllerDefinition(); for (int i = 0; i < keys.Length; i++) { if (Global.Emulator.ControllerDefinition.BoolButtons.Contains(keys[i])) + { d.BoolButtons.Add(keys[i]); + } else + { d.FloatControls.Add(keys[i]); + } } - Bk2ControllerAdapter newController = new Bk2ControllerAdapter() { Type = d }; - Bk2LogEntryGenerator logGenerator = new Bk2LogEntryGenerator(""); + var newController = new Bk2ControllerAdapter { Type = d }; + var logGenerator = new Bk2LogEntryGenerator(""); + logGenerator.SetSource(newController); logGenerator.GenerateLogEntry(); // Reference and create all buttons. + // Reset all buttons in targetController (it may still have buttons that aren't being set here set true) - Bk2LogEntryGenerator tC = new Bk2LogEntryGenerator(""); + var tC = new Bk2LogEntryGenerator(""); tC.SetSource(targetController); targetController.SetControllersAsMnemonic(tC.EmptyEntry); for (int i = 0; i < Length; i++) @@ -117,7 +132,9 @@ namespace BizHawk.Client.EmuHawk public void PlaceZone(IMovie movie) { if (movie is TasMovie) + { (movie as TasMovie).ChangeLog.BeginNewBatch("Place Macro at " + Start); + } if (Start > movie.InputLogLength) { // Cannot place a frame here. Find a nice way around this. @@ -193,12 +210,16 @@ namespace BizHawk.Client.EmuHawk File.WriteAllLines(fileName, header); File.AppendAllLines(fileName, _log); } + public MovieZone(string fileName) { if (!File.Exists(fileName)) + { return; + } string[] readText = File.ReadAllLines(fileName); + // If the LogKey contains buttons/controls not accepted by the emulator, // tell the user and display the macro's controller name and player count _inputKey = readText[0]; @@ -240,16 +261,21 @@ namespace BizHawk.Client.EmuHawk for (int i = 0; i < keys.Length; i++) { if (Global.Emulator.ControllerDefinition.BoolButtons.Contains(keys[i])) + { d.BoolButtons.Add(keys[i]); + } else + { d.FloatControls.Add(keys[i]); + } } - controller = new Bk2ControllerAdapter() { Type = d }; + + controller = new Bk2ControllerAdapter { Type = d }; } - #region "Custom Latch" + #region Custom Latch - public void LatchFromSourceButtons(Bk2ControllerAdapter latching, IController source) + private void LatchFromSourceButtons(Bk2ControllerAdapter latching, IController source) { foreach (string button in source.Type.BoolButtons) { @@ -274,7 +300,9 @@ namespace BizHawk.Client.EmuHawk float sFloat = source.GetFloat(name); int indexRange = source.Type.FloatControls.IndexOf(name); if (sFloat == source.Type.FloatRanges[indexRange].Mid) + { latching.SetFloat(name, sFloat); + } } }