From c0295316f551f97bf0f483b5352f3675c8f0f590 Mon Sep 17 00:00:00 2001 From: adelikat Date: Fri, 10 Jan 2014 23:08:56 +0000 Subject: [PATCH] Some Movie 2.0 reorg --- .../BizHawk.Client.Common.csproj | 8 +- .../ControllerLookups/MnemonicGenerators.cs | 179 ------------------ .../MnemonicGenerators/IMnemonicGenerator.cs | 43 +++++ .../MnemonicGenerators/IMnemonicPorts.cs | 49 +++++ .../MnemonicGeneratorFactory.cs | 0 .../MnemonicGenerators/MnemonicGenerators.cs | 101 ++++++++++ .../NesMnemonicGenerator.cs | 0 7 files changed, 198 insertions(+), 182 deletions(-) delete mode 100644 BizHawk.Client.Common/movie/ControllerLookups/MnemonicGenerators.cs create mode 100644 BizHawk.Client.Common/movie/MnemonicGenerators/IMnemonicGenerator.cs create mode 100644 BizHawk.Client.Common/movie/MnemonicGenerators/IMnemonicPorts.cs rename BizHawk.Client.Common/movie/{ControllerLookups => MnemonicGenerators}/MnemonicGeneratorFactory.cs (100%) create mode 100644 BizHawk.Client.Common/movie/MnemonicGenerators/MnemonicGenerators.cs rename BizHawk.Client.Common/movie/{ControllerLookups => MnemonicGenerators}/NesMnemonicGenerator.cs (100%) diff --git a/BizHawk.Client.Common/BizHawk.Client.Common.csproj b/BizHawk.Client.Common/BizHawk.Client.Common.csproj index ff6bde7b47..14683f9fbd 100644 --- a/BizHawk.Client.Common/BizHawk.Client.Common.csproj +++ b/BizHawk.Client.Common/BizHawk.Client.Common.csproj @@ -123,13 +123,15 @@ - - - + + + + + diff --git a/BizHawk.Client.Common/movie/ControllerLookups/MnemonicGenerators.cs b/BizHawk.Client.Common/movie/ControllerLookups/MnemonicGenerators.cs deleted file mode 100644 index 591b7e3f51..0000000000 --- a/BizHawk.Client.Common/movie/ControllerLookups/MnemonicGenerators.cs +++ /dev/null @@ -1,179 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -using BizHawk.Common; -using BizHawk.Emulation.Common; - -namespace BizHawk.Client.Common -{ - public interface IMnemonicGenerator - { - IController Source { get; set; } - - string Name { get; } - - /// - /// Will be prepended to all button names - /// Example: "P1" - /// - string ControllerPrefix { get; set; } - - void Add(string key, char value); - - char this[string key] { get; } - bool IsEmpty { get; } - string MnemonicString { get; } - - /// - /// Returns a string that represents an empty or default mnemonic - /// - string EmptyMnemonicString { get; } - - // Analog TODO: this assumes the Generator is boolean - /// - /// Parses a segment of a full mnemonic string (the content between pipes) - /// Note: this assume the pipes are not being passed in! - /// - IDictionary ParseMnemonicSegment(string mnemonicSegment); - - // Analog Support TODO: this assume the Generator is boolean - //Dictionary GetBoolButtons(); - - Dictionary AvailableMnemonics { get; } - } - - /// - /// A console specific collection of Mnemonic generators - /// This handles includes all the "business" logic specific to the console - /// - public interface IMnemonicPorts - { - /// - /// Total number of available controller ports (this does not include the console controls - /// - int Count { get; } - - /// - /// Source controller to read input state from - /// - IController Source { get; set; } - - /// - /// Gets or sets the given port with an IMnemonicGenerator implementation - /// Ports are zero based - /// Set will throw an InvalidOperationException if a particular implementation is not allowed, this is platform specific logic such as NES doesn't allow a zapper in port 0, etc - /// Both will throw an ArgumentOutOfRangeException exception if portNum is not less than Count - /// - IMnemonicGenerator this[int portNum] { get; set; } - - /// - /// Gets an IMnemonicGenerator implementation that represents the buttons and controls on the console itself (Reset, Power, etc) - /// - IMnemonicGenerator ConsoleControls { get; } - - Dictionary ParseMnemonicString(string mnemonicStr); - - // Analog TODO: this assume the generators are boolean - Dictionary GetBoolButtons(); - - // TODO: this shouldn't be required, refactor MovieRecord - string GenerateMnemonicString(Dictionary buttons); - - string EmptyMnemonic { get; } - - Dictionary AvailableMnemonics { get; } - } - - public class BooleanControllerMnemonicGenerator : IMnemonicGenerator - { - private NamedDictionary _controllerMnemonics; - - public BooleanControllerMnemonicGenerator(string name, IDictionary mnemonics) - { - _controllerMnemonics = new NamedDictionary(name); - foreach (var kvp in mnemonics) - { - _controllerMnemonics.Add(kvp.Key, kvp.Value); - } - } - - public void Add(string key, char value) - { - _controllerMnemonics.Add(key, value); - } - - public Dictionary AvailableMnemonics - { - get - { - return _controllerMnemonics.ToDictionary(kvp => ControllerPrefix + " " + kvp.Key, kvp => kvp.Value); - } - } - - public IController Source { get; set; } - public string ControllerPrefix { get; set; } - public string Name - { - get { return _controllerMnemonics.Name; } - } - - public char this[string key] - { - get - { - return _controllerMnemonics[ControllerPrefix + " " + key]; - } - } - - public bool IsEmpty - { - get - { - return _controllerMnemonics.All(kvp => !this.Source.IsPressed(kvp.Key)); - } - } - - public string MnemonicString - { - get - { - var sb = new StringBuilder(_controllerMnemonics.Count); - foreach (var kvp in _controllerMnemonics) - { - sb.Append(Source.IsPressed(kvp.Key) ? kvp.Value : '.'); - } - - return sb.ToString(); - } - } - - public string EmptyMnemonicString - { - get - { - var sb = new StringBuilder(_controllerMnemonics.Count); - foreach (var kvp in _controllerMnemonics) - { - sb.Append('.'); - } - - return sb.ToString(); - } - } - - public IDictionary ParseMnemonicSegment(string mnemonicSegment) - { - var buttons = new Dictionary(); - var keys = _controllerMnemonics.Select(kvp => kvp.Key).ToList(); - - for (int i = 0; i < mnemonicSegment.Length; i++) - { - buttons.Add(keys[i], mnemonicSegment[i] != '.'); - } - - return buttons; - } - } -} diff --git a/BizHawk.Client.Common/movie/MnemonicGenerators/IMnemonicGenerator.cs b/BizHawk.Client.Common/movie/MnemonicGenerators/IMnemonicGenerator.cs new file mode 100644 index 0000000000..6e1a683687 --- /dev/null +++ b/BizHawk.Client.Common/movie/MnemonicGenerators/IMnemonicGenerator.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BizHawk.Client.Common +{ + public interface IMnemonicGenerator + { + IController Source { get; set; } + + string Name { get; } + + /// + /// Will be prepended to all button names + /// Example: "P1" + /// + string ControllerPrefix { get; set; } + + void Add(string key, char value); + + char this[string key] { get; } + bool IsEmpty { get; } + string MnemonicString { get; } + + /// + /// Returns a string that represents an empty or default mnemonic + /// + string EmptyMnemonicString { get; } + + // Analog TODO: this assumes the Generator is boolean + /// + /// Parses a segment of a full mnemonic string (the content between pipes) + /// Note: this assume the pipes are not being passed in! + /// + IDictionary ParseMnemonicSegment(string mnemonicSegment); + + // Analog Support TODO: this assume the Generator is boolean + //Dictionary GetBoolButtons(); + + Dictionary AvailableMnemonics { get; } + } +} diff --git a/BizHawk.Client.Common/movie/MnemonicGenerators/IMnemonicPorts.cs b/BizHawk.Client.Common/movie/MnemonicGenerators/IMnemonicPorts.cs new file mode 100644 index 0000000000..ba21a4964e --- /dev/null +++ b/BizHawk.Client.Common/movie/MnemonicGenerators/IMnemonicPorts.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BizHawk.Client.Common +{ + /// + /// A console specific collection of Mnemonic generators + /// This handles includes all the "business" logic specific to the console + /// + public interface IMnemonicPorts + { + /// + /// Total number of available controller ports (this does not include the console controls + /// + int Count { get; } + + /// + /// Source controller to read input state from + /// + IController Source { get; set; } + + /// + /// Gets or sets the given port with an IMnemonicGenerator implementation + /// Ports are zero based + /// Set will throw an InvalidOperationException if a particular implementation is not allowed, this is platform specific logic such as NES doesn't allow a zapper in port 0, etc + /// Both will throw an ArgumentOutOfRangeException exception if portNum is not less than Count + /// + IMnemonicGenerator this[int portNum] { get; set; } + + /// + /// Gets an IMnemonicGenerator implementation that represents the buttons and controls on the console itself (Reset, Power, etc) + /// + IMnemonicGenerator ConsoleControls { get; } + + Dictionary ParseMnemonicString(string mnemonicStr); + + // Analog TODO: this assume the generators are boolean + Dictionary GetBoolButtons(); + + // TODO: this shouldn't be required, refactor MovieRecord + string GenerateMnemonicString(Dictionary buttons); + + string EmptyMnemonic { get; } + + Dictionary AvailableMnemonics { get; } + } +} diff --git a/BizHawk.Client.Common/movie/ControllerLookups/MnemonicGeneratorFactory.cs b/BizHawk.Client.Common/movie/MnemonicGenerators/MnemonicGeneratorFactory.cs similarity index 100% rename from BizHawk.Client.Common/movie/ControllerLookups/MnemonicGeneratorFactory.cs rename to BizHawk.Client.Common/movie/MnemonicGenerators/MnemonicGeneratorFactory.cs diff --git a/BizHawk.Client.Common/movie/MnemonicGenerators/MnemonicGenerators.cs b/BizHawk.Client.Common/movie/MnemonicGenerators/MnemonicGenerators.cs new file mode 100644 index 0000000000..10cc44d602 --- /dev/null +++ b/BizHawk.Client.Common/movie/MnemonicGenerators/MnemonicGenerators.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using BizHawk.Common; +using BizHawk.Emulation.Common; + +namespace BizHawk.Client.Common +{ + public class BooleanControllerMnemonicGenerator : IMnemonicGenerator + { + private NamedDictionary _controllerMnemonics; + + public BooleanControllerMnemonicGenerator(string name, IDictionary mnemonics) + { + _controllerMnemonics = new NamedDictionary(name); + foreach (var kvp in mnemonics) + { + _controllerMnemonics.Add(kvp.Key, kvp.Value); + } + } + + public void Add(string key, char value) + { + _controllerMnemonics.Add(key, value); + } + + public Dictionary AvailableMnemonics + { + get + { + return _controllerMnemonics.ToDictionary(kvp => ControllerPrefix + " " + kvp.Key, kvp => kvp.Value); + } + } + + public IController Source { get; set; } + public string ControllerPrefix { get; set; } + public string Name + { + get { return _controllerMnemonics.Name; } + } + + public char this[string key] + { + get + { + return _controllerMnemonics[ControllerPrefix + " " + key]; + } + } + + public bool IsEmpty + { + get + { + return _controllerMnemonics.All(kvp => !this.Source.IsPressed(kvp.Key)); + } + } + + public string MnemonicString + { + get + { + var sb = new StringBuilder(_controllerMnemonics.Count); + foreach (var kvp in _controllerMnemonics) + { + sb.Append(Source.IsPressed(kvp.Key) ? kvp.Value : '.'); + } + + return sb.ToString(); + } + } + + public string EmptyMnemonicString + { + get + { + var sb = new StringBuilder(_controllerMnemonics.Count); + foreach (var kvp in _controllerMnemonics) + { + sb.Append('.'); + } + + return sb.ToString(); + } + } + + public IDictionary ParseMnemonicSegment(string mnemonicSegment) + { + var buttons = new Dictionary(); + var keys = _controllerMnemonics.Select(kvp => kvp.Key).ToList(); + + for (int i = 0; i < mnemonicSegment.Length; i++) + { + buttons.Add(keys[i], mnemonicSegment[i] != '.'); + } + + return buttons; + } + } +} diff --git a/BizHawk.Client.Common/movie/ControllerLookups/NesMnemonicGenerator.cs b/BizHawk.Client.Common/movie/MnemonicGenerators/NesMnemonicGenerator.cs similarity index 100% rename from BizHawk.Client.Common/movie/ControllerLookups/NesMnemonicGenerator.cs rename to BizHawk.Client.Common/movie/MnemonicGenerators/NesMnemonicGenerator.cs