diff --git a/src/BizHawk.Client.Common/display/IInputDisplayGenerator.cs b/src/BizHawk.Client.Common/display/IInputDisplayGenerator.cs index 3865bbd529..8bead2a010 100644 --- a/src/BizHawk.Client.Common/display/IInputDisplayGenerator.cs +++ b/src/BizHawk.Client.Common/display/IInputDisplayGenerator.cs @@ -1,5 +1,5 @@ -using System.Linq; -using System.Text; +using System.Text; + using BizHawk.Emulation.Common; namespace BizHawk.Client.Common @@ -31,32 +31,26 @@ namespace BizHawk.Client.Common { var sb = new StringBuilder(); - foreach (var group in _source.Definition.ControlsOrdered) + foreach (var button in _source.Definition.OrderedControlsFlat) { - if (group.Any()) + if (_source.Definition.Axes.TryGetValue(button, out var range)) { - foreach (var button in group) - { - if (_source.Definition.Axes.TryGetValue(button, out var range)) - { - var val = _source.AxisValue(button); + var val = _source.AxisValue(button); - if (val == range.Neutral) - { - sb.Append(" "); - } - else - { - sb.Append(val.ToString().PadLeft(5, ' ')).Append(','); - } - } - else if (_source.Definition.BoolButtons.Contains(button)) - { - sb.Append(_source.IsPressed(button) - ? Bk2MnemonicLookup.Lookup(button, _systemId) - : ' '); - } + if (val == range.Neutral) + { + sb.Append(" "); } + else + { + sb.Append(val.ToString().PadLeft(5, ' ')).Append(','); + } + } + else if (_source.Definition.BoolButtons.Contains(button)) + { + sb.Append(_source.IsPressed(button) + ? Bk2MnemonicLookup.Lookup(button, _systemId) + : ' '); } } diff --git a/src/BizHawk.Client.Common/movie/bk2/Bk2Controller.cs b/src/BizHawk.Client.Common/movie/bk2/Bk2Controller.cs index 6145e90c5b..b261b29fff 100755 --- a/src/BizHawk.Client.Common/movie/bk2/Bk2Controller.cs +++ b/src/BizHawk.Client.Common/movie/bk2/Bk2Controller.cs @@ -16,8 +16,7 @@ namespace BizHawk.Client.Common private IList _controlsOrdered; - private IList ControlsOrdered => _controlsOrdered ??= _type.ControlsOrdered - .SelectMany(c => c) // flatten + private IList ControlsOrdered => _controlsOrdered ??= _type.OrderedControlsFlat .Select(c => new ControlMap { Name = c, diff --git a/src/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs b/src/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs index c0168eed28..9d8940d1d1 100644 --- a/src/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs +++ b/src/BizHawk.Client.Common/movie/bk2/Bk2LogEntryGenerator.cs @@ -28,7 +28,7 @@ namespace BizHawk.Client.Common var sb = new StringBuilder(); sb.Append("LogKey:"); - foreach (var group in _source.Definition.ControlsOrdered.Where(c => c.Any())) + foreach (var group in _source.Definition.ControlsOrdered.Where(static c => c.Count is not 0)) { sb.Append('#'); foreach (var button in group) @@ -43,18 +43,15 @@ namespace BizHawk.Client.Common public IDictionary Map() { var dict = new Dictionary(); - foreach (var group in _source.Definition.ControlsOrdered.Where(c => c.Any())) + foreach (var button in _source.Definition.OrderedControlsFlat) { - foreach (var button in group) + if (_source.Definition.BoolButtons.Contains(button)) { - if (_source.Definition.BoolButtons.Contains(button)) - { - dict.Add(button, Bk2MnemonicLookup.Lookup(button, _systemId).ToString()); - } - else if (_source.Definition.Axes.ContainsKey(button)) - { - dict.Add(button, Bk2MnemonicLookup.LookupAxis(button, _systemId)); - } + dict.Add(button, Bk2MnemonicLookup.Lookup(button, _systemId).ToString()); + } + else if (_source.Definition.Axes.ContainsKey(button)) + { + dict.Add(button, Bk2MnemonicLookup.LookupAxis(button, _systemId)); } } @@ -67,35 +64,23 @@ namespace BizHawk.Client.Common sb.Append('|'); - foreach (var group in _source.Definition.ControlsOrdered) + foreach (var group in _source.Definition.ControlsOrdered.Where(static c => c.Count is not 0)) { - if (group.Any()) + foreach (var button in group) { - foreach (var button in group) + if (_source.Definition.Axes.TryGetValue(button, out var range)) { - if (_source.Definition.Axes.TryGetValue(button, out var range)) - { - var val = createEmpty ? range.Neutral : _source.AxisValue(button); - - sb.Append(val.ToString().PadLeft(5, ' ')).Append(','); - } - else if (_source.Definition.BoolButtons.Contains(button)) - { - if (createEmpty) - { - sb.Append('.'); - } - else - { - sb.Append(_source.IsPressed(button) - ? Bk2MnemonicLookup.Lookup(button, _systemId) - : '.'); - } - } + var val = createEmpty ? range.Neutral : _source.AxisValue(button); + sb.Append(val.ToString().PadLeft(5, ' ')).Append(','); + } + else if (_source.Definition.BoolButtons.Contains(button)) + { + sb.Append(!createEmpty && _source.IsPressed(button) + ? Bk2MnemonicLookup.Lookup(button, _systemId) + : '.'); } - - sb.Append('|'); } + sb.Append('|'); } return sb.ToString(); diff --git a/src/BizHawk.Client.Common/movie/import/YmvImport.cs b/src/BizHawk.Client.Common/movie/import/YmvImport.cs index e809999131..1f3c35d5e6 100644 --- a/src/BizHawk.Client.Common/movie/import/YmvImport.cs +++ b/src/BizHawk.Client.Common/movie/import/YmvImport.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using System.Linq; + using BizHawk.Emulation.Common; namespace BizHawk.Client.Common.movie.import @@ -121,8 +121,8 @@ namespace BizHawk.Client.Common.movie.import controllers["Reset"] = true; } - var buttonNames = controllers.Definition.ControlsOrdered.Skip(1).First().ToList(); - + var buttonNames = controllers.Definition.ControlsOrdered[1]; + // Only count lines with that have the right number of buttons and are for valid players. if (sections[1].Length == buttonNames.Count) { diff --git a/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs b/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs index e574999bb4..5e903ec711 100644 --- a/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs +++ b/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs @@ -23,6 +23,8 @@ namespace BizHawk.Emulation.Common private IReadOnlyList> _orderedControls = null; + private IReadOnlyList _orderedControlsFlat = null; + /// starts with console buttons, then each player's buttons individually public IReadOnlyList> ControlsOrdered { @@ -37,6 +39,8 @@ namespace BizHawk.Emulation.Common public readonly string Name; + public IReadOnlyList OrderedControlsFlat => _orderedControlsFlat ??= ControlsOrdered.SelectMany(static s => s).ToList(); + public ControllerDefinition(string name) => Name = name;