Clean up usages of `ControllerDefinition.ControlsOrdered`
This commit is contained in:
parent
8b1a1393a9
commit
25ccca8bbb
|
@ -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)
|
||||
: ' ');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,8 +16,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
private IList<ControlMap> _controlsOrdered;
|
||||
|
||||
private IList<ControlMap> ControlsOrdered => _controlsOrdered ??= _type.ControlsOrdered
|
||||
.SelectMany(c => c) // flatten
|
||||
private IList<ControlMap> ControlsOrdered => _controlsOrdered ??= _type.OrderedControlsFlat
|
||||
.Select(c => new ControlMap
|
||||
{
|
||||
Name = c,
|
||||
|
|
|
@ -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<string, string> Map()
|
||||
{
|
||||
var dict = new Dictionary<string, string>();
|
||||
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();
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -23,6 +23,8 @@ namespace BizHawk.Emulation.Common
|
|||
|
||||
private IReadOnlyList<IReadOnlyList<string>> _orderedControls = null;
|
||||
|
||||
private IReadOnlyList<string> _orderedControlsFlat = null;
|
||||
|
||||
/// <summary>starts with console buttons, then each player's buttons individually</summary>
|
||||
public IReadOnlyList<IReadOnlyList<string>> ControlsOrdered
|
||||
{
|
||||
|
@ -37,6 +39,8 @@ namespace BizHawk.Emulation.Common
|
|||
|
||||
public readonly string Name;
|
||||
|
||||
public IReadOnlyList<string> OrderedControlsFlat => _orderedControlsFlat ??= ControlsOrdered.SelectMany(static s => s).ToList();
|
||||
|
||||
public ControllerDefinition(string name)
|
||||
=> Name = name;
|
||||
|
||||
|
|
Loading…
Reference in New Issue