From 8270c5f997a22ffd8684da6036fab82d212103a4 Mon Sep 17 00:00:00 2001 From: adelikat Date: Thu, 11 Jun 2020 12:27:22 -0500 Subject: [PATCH] put classes in MultitrackRecording into separate files, and make a few of them internal --- .../movie/MultitrackRecording.cs | 171 ------------------ .../movie/multitrack/ButtonNameParser.cs | 37 ++++ .../movie/multitrack/MultitrackRecorder.cs | 83 +++++++++ .../MultitrackRewiringControllerAdapter.cs | 55 ++++++ 4 files changed, 175 insertions(+), 171 deletions(-) delete mode 100644 src/BizHawk.Client.Common/movie/MultitrackRecording.cs create mode 100644 src/BizHawk.Client.Common/movie/multitrack/ButtonNameParser.cs create mode 100644 src/BizHawk.Client.Common/movie/multitrack/MultitrackRecorder.cs create mode 100644 src/BizHawk.Client.Common/movie/multitrack/MultitrackRewiringControllerAdapter.cs diff --git a/src/BizHawk.Client.Common/movie/MultitrackRecording.cs b/src/BizHawk.Client.Common/movie/MultitrackRecording.cs deleted file mode 100644 index 1de5d236e7..0000000000 --- a/src/BizHawk.Client.Common/movie/MultitrackRecording.cs +++ /dev/null @@ -1,171 +0,0 @@ -using BizHawk.Emulation.Common; - -namespace BizHawk.Client.Common -{ - public class MultitrackRecorder - { - public MultitrackRecorder() - { - Restart(1); - } - - internal MultitrackRewiringControllerAdapter RewiringAdapter { get; } = new MultitrackRewiringControllerAdapter(); - - public bool IsActive { get; set; } - public int CurrentPlayer { get; private set; } - public int PlayerCount { get; private set; } - public bool RecordAll { get; private set; } - - /// - /// Gets a user friendly multi-track status - /// - public string Status - { - get - { - if (!IsActive) - { - return ""; - } - - if (RecordAll) - { - return "Recording All"; - } - - if (CurrentPlayer == 0) - { - return "Recording None"; - } - - return $"Recording Player {CurrentPlayer}"; - } - } - - public void Restart(int playerCount) - { - PlayerCount = playerCount; - IsActive = false; - CurrentPlayer = 0; - RecordAll = false; - } - - public void SelectAll() - { - CurrentPlayer = 0; - RecordAll = true; - } - - public void SelectNone() - { - RecordAll = false; - CurrentPlayer = 0; - } - - public void Increment() - { - RecordAll = false; - CurrentPlayer++; - if (CurrentPlayer > PlayerCount) - { - CurrentPlayer = 1; - } - } - - public void Decrement() - { - RecordAll = false; - CurrentPlayer--; - if (CurrentPlayer < 1) - { - CurrentPlayer = PlayerCount; - } - } - } - - /// - /// rewires player1 controls to playerN - /// - public class MultitrackRewiringControllerAdapter : IInputAdapter - { - public IController Source { get; set; } - public int PlayerSource { get; set; } = -1; - public int PlayerTargetMask { get; set; } - - public ControllerDefinition Definition => Source.Definition; - - public bool IsPressed(string button) - { - return Source.IsPressed(RemapButtonName(button)); - } - - public int AxisValue(string name) - { - return Source.AxisValue(RemapButtonName(name)); - } - - private string RemapButtonName(string button) - { - // Do we even have a source? - if (PlayerSource == -1) - { - return button; - } - - // See if we're being asked for a button that we know how to rewire - var bnp = ButtonNameParser.Parse(button); - - if (bnp == null) - { - return button; - } - - // Ok, this looks like a normal `P1 Button` type thing. we can handle it - // Were we supposed to replace this one? - int foundPlayerMask = 1 << bnp.PlayerNum; - if ((PlayerTargetMask & foundPlayerMask) == 0) - { - return button; - } - - // Ok, we were. swap out the source player and then grab his button - bnp.PlayerNum = PlayerSource; - return bnp.ToString(); - } - } - - public class ButtonNameParser - { - public static ButtonNameParser Parse(string button) - { - // See if we're being asked for a button that we know how to rewire - var parts = button.Split(' '); - - if (parts.Length < 2) - { - return null; - } - - if (parts[0][0] != 'P') - { - return null; - } - - if (!int.TryParse(parts[0].Substring(1), out var player)) - { - return null; - } - - return new ButtonNameParser - { - PlayerNum = player, - ButtonPart = button.Substring(parts[0].Length + 1) - }; - } - - public int PlayerNum { get; set; } - public string ButtonPart { get; private set; } - - public override string ToString() => $"P{PlayerNum} {ButtonPart}"; - } -} diff --git a/src/BizHawk.Client.Common/movie/multitrack/ButtonNameParser.cs b/src/BizHawk.Client.Common/movie/multitrack/ButtonNameParser.cs new file mode 100644 index 0000000000..946a880532 --- /dev/null +++ b/src/BizHawk.Client.Common/movie/multitrack/ButtonNameParser.cs @@ -0,0 +1,37 @@ +namespace BizHawk.Client.Common +{ + internal class ButtonNameParser + { + public static ButtonNameParser Parse(string button) + { + // See if we're being asked for a button that we know how to rewire + var parts = button.Split(' '); + + if (parts.Length < 2) + { + return null; + } + + if (parts[0][0] != 'P') + { + return null; + } + + if (!int.TryParse(parts[0].Substring(1), out var player)) + { + return null; + } + + return new ButtonNameParser + { + PlayerNum = player, + ButtonPart = button.Substring(parts[0].Length + 1) + }; + } + + public int PlayerNum { get; set; } + public string ButtonPart { get; private set; } + + public override string ToString() => $"P{PlayerNum} {ButtonPart}"; + } +} diff --git a/src/BizHawk.Client.Common/movie/multitrack/MultitrackRecorder.cs b/src/BizHawk.Client.Common/movie/multitrack/MultitrackRecorder.cs new file mode 100644 index 0000000000..295284aaa1 --- /dev/null +++ b/src/BizHawk.Client.Common/movie/multitrack/MultitrackRecorder.cs @@ -0,0 +1,83 @@ +namespace BizHawk.Client.Common +{ + public class MultitrackRecorder + { + public MultitrackRecorder() + { + Restart(1); + } + + internal MultitrackRewiringControllerAdapter RewiringAdapter { get; } = new MultitrackRewiringControllerAdapter(); + + public bool IsActive { get; set; } + public int CurrentPlayer { get; private set; } + public int PlayerCount { get; private set; } + public bool RecordAll { get; private set; } + + /// + /// Gets a user friendly multi-track status + /// + public string Status + { + get + { + if (!IsActive) + { + return ""; + } + + if (RecordAll) + { + return "Recording All"; + } + + if (CurrentPlayer == 0) + { + return "Recording None"; + } + + return $"Recording Player {CurrentPlayer}"; + } + } + + public void Restart(int playerCount) + { + PlayerCount = playerCount; + IsActive = false; + CurrentPlayer = 0; + RecordAll = false; + } + + public void SelectAll() + { + CurrentPlayer = 0; + RecordAll = true; + } + + public void SelectNone() + { + RecordAll = false; + CurrentPlayer = 0; + } + + public void Increment() + { + RecordAll = false; + CurrentPlayer++; + if (CurrentPlayer > PlayerCount) + { + CurrentPlayer = 1; + } + } + + public void Decrement() + { + RecordAll = false; + CurrentPlayer--; + if (CurrentPlayer < 1) + { + CurrentPlayer = PlayerCount; + } + } + } +} diff --git a/src/BizHawk.Client.Common/movie/multitrack/MultitrackRewiringControllerAdapter.cs b/src/BizHawk.Client.Common/movie/multitrack/MultitrackRewiringControllerAdapter.cs new file mode 100644 index 0000000000..7e4655345a --- /dev/null +++ b/src/BizHawk.Client.Common/movie/multitrack/MultitrackRewiringControllerAdapter.cs @@ -0,0 +1,55 @@ +using BizHawk.Emulation.Common; + +namespace BizHawk.Client.Common +{ + /// + /// rewires player1 controls to playerN + /// + internal class MultitrackRewiringControllerAdapter : IInputAdapter + { + public IController Source { get; set; } + public int PlayerSource { get; set; } = -1; + public int PlayerTargetMask { get; set; } + + public ControllerDefinition Definition => Source.Definition; + + public bool IsPressed(string button) + { + return Source.IsPressed(RemapButtonName(button)); + } + + public int AxisValue(string name) + { + return Source.AxisValue(RemapButtonName(name)); + } + + private string RemapButtonName(string button) + { + // Do we even have a source? + if (PlayerSource == -1) + { + return button; + } + + // See if we're being asked for a button that we know how to rewire + var bnp = ButtonNameParser.Parse(button); + + if (bnp == null) + { + return button; + } + + // Ok, this looks like a normal `P1 Button` type thing. we can handle it + // Were we supposed to replace this one? + int foundPlayerMask = 1 << bnp.PlayerNum; + if ((PlayerTargetMask & foundPlayerMask) == 0) + { + return button; + } + + // Ok, we were. swap out the source player and then grab his button + bnp.PlayerNum = PlayerSource; + return bnp.ToString(); + } + } +}