From f2e52988c1ffca05efefe0909070eef6b954c486 Mon Sep 17 00:00:00 2001 From: adelikat Date: Tue, 14 Apr 2020 21:23:47 -0500 Subject: [PATCH] simplify some IMovieSession stuff --- BizHawk.Client.Common/Api/Classes/JoypadApi.cs | 8 ++++---- BizHawk.Client.Common/movie/MovieSession.cs | 4 ++-- .../movie/interfaces/IMovieSession.cs | 9 ++++++++- BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs | 8 ++++---- .../tools/TAStudio/TAStudioClipboard.cs | 14 +++++++------- 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/BizHawk.Client.Common/Api/Classes/JoypadApi.cs b/BizHawk.Client.Common/Api/Classes/JoypadApi.cs index b1fbf1664b..c3478652ac 100644 --- a/BizHawk.Client.Common/Api/Classes/JoypadApi.cs +++ b/BizHawk.Client.Common/Api/Classes/JoypadApi.cs @@ -28,18 +28,18 @@ namespace BizHawk.Client.Common public void SetFromMnemonicStr(string inputLogEntry) { - var lg = Global.MovieSession.GenerateMovieController(Global.Emulator.ControllerDefinition); + var controller = Global.MovieSession.GenerateMovieController(); try { - lg.SetFromMnemonic(inputLogEntry); + controller.SetFromMnemonic(inputLogEntry); } catch (Exception) { LogCallback($"invalid mnemonic string: {inputLogEntry}"); return; } - foreach (var button in lg.Definition.BoolButtons) Global.InputManager.ButtonOverrideAdapter.SetButton(button, lg.IsPressed(button)); - foreach (var floatButton in lg.Definition.AxisControls) Global.InputManager.ButtonOverrideAdapter.SetAxis(floatButton, lg.AxisValue(floatButton)); + foreach (var button in controller.Definition.BoolButtons) Global.InputManager.ButtonOverrideAdapter.SetButton(button, controller.IsPressed(button)); + foreach (var floatButton in controller.Definition.AxisControls) Global.InputManager.ButtonOverrideAdapter.SetAxis(floatButton, controller.AxisValue(floatButton)); } public void Set(Dictionary buttons, int? controller = null) diff --git a/BizHawk.Client.Common/movie/MovieSession.cs b/BizHawk.Client.Common/movie/MovieSession.cs index eb1ae74089..c40254f368 100644 --- a/BizHawk.Client.Common/movie/MovieSession.cs +++ b/BizHawk.Client.Common/movie/MovieSession.cs @@ -52,10 +52,10 @@ namespace BizHawk.Client.Common MovieController = new Bk2Controller(definition); } - public IMovieController GenerateMovieController(ControllerDefinition definition) + public IMovieController GenerateMovieController() { // TODO: expose Movie.LogKey and pass in here - return new Bk2Controller("", definition); + return new Bk2Controller("", MovieController.Definition); } // Convenience property that gets the controller state from the movie for the most recent frame diff --git a/BizHawk.Client.Common/movie/interfaces/IMovieSession.cs b/BizHawk.Client.Common/movie/interfaces/IMovieSession.cs index 0383ef8a1d..87b6c3f591 100644 --- a/BizHawk.Client.Common/movie/interfaces/IMovieSession.cs +++ b/BizHawk.Client.Common/movie/interfaces/IMovieSession.cs @@ -13,9 +13,16 @@ namespace BizHawk.Client.Common IController PreviousFrame { get; } IController CurrentInput { get; } + /// + /// Recreates MovieController with the given controller definition + /// void CreateMovieController(ControllerDefinition definition); - IMovieController GenerateMovieController(ControllerDefinition definition); + /// + /// Creates a instance based on the + /// current button definition + /// + IMovieController GenerateMovieController(); bool ReadOnly { get; set; } bool MovieIsQueued { get; } diff --git a/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs b/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs index 691b863133..88d74ff6ed 100644 --- a/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs +++ b/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs @@ -779,13 +779,13 @@ namespace BizHawk.Client.EmuHawk if (index < _bestBotAttempt.Log.Count) { var logEntry = _bestBotAttempt.Log[index]; - var lg = Global.MovieSession.GenerateMovieController(Emulator.ControllerDefinition); - lg.SetFromMnemonic(logEntry); + var controller = Global.MovieSession.GenerateMovieController(); + controller.SetFromMnemonic(logEntry); - foreach (var button in lg.Definition.BoolButtons) + foreach (var button in controller.Definition.BoolButtons) { // TODO: make an input adapter specifically for the bot? - Global.InputManager.ButtonOverrideAdapter.SetButton(button, lg.IsPressed(button)); + Global.InputManager.ButtonOverrideAdapter.SetButton(button, controller.IsPressed(button)); } } else diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudioClipboard.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudioClipboard.cs index 84ca02c4b3..e9ba82ce0c 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudioClipboard.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudioClipboard.cs @@ -27,20 +27,20 @@ namespace BizHawk.Client.EmuHawk { try { - var lg = Global.MovieSession.GenerateMovieController(Global.Emulator.ControllerDefinition); - lg.SetFromMnemonic(inputLogEntry); + var controller = Global.MovieSession.GenerateMovieController(); + controller.SetFromMnemonic(inputLogEntry); - foreach (var button in lg.Definition.BoolButtons) + foreach (var button in controller.Definition.BoolButtons) { - Global.InputManager.ButtonOverrideAdapter.SetButton(button, lg.IsPressed(button)); + Global.InputManager.ButtonOverrideAdapter.SetButton(button, controller.IsPressed(button)); } - foreach (var floatButton in lg.Definition.AxisControls) + foreach (var floatButton in controller.Definition.AxisControls) { - Global.InputManager.ButtonOverrideAdapter.SetAxis(floatButton, lg.AxisValue(floatButton)); + Global.InputManager.ButtonOverrideAdapter.SetAxis(floatButton, controller.AxisValue(floatButton)); } - return lg; + return controller; } catch (Exception) {