Move `Bk2MnemonicLookup` to `BizHawk.Emulation.Common`
fixes a0800862b
(PR #3782)
This commit is contained in:
parent
1567bd23ec
commit
699fc8d198
|
@ -52,7 +52,7 @@ namespace BizHawk.Client.Common
|
|||
public void SyncControls(IEmulator emulator, IMovieSession session, Config config)
|
||||
{
|
||||
var def = emulator.ControllerDefinition;
|
||||
def.BuildMnemonicsCache(Bk2MnemonicLookup.MnemonicFunc(emulator.SystemId));
|
||||
def.BuildMnemonicsCache(emulator.SystemId);
|
||||
|
||||
ActiveController = BindToDefinition(def, config.AllTrollers, config.AllTrollersAnalog, config.AllTrollersFeedbacks);
|
||||
AutoFireController = BindToDefinitionAF(emulator, config.AllTrollersAutoFire, config.AutofireOn, config.AutofireOff);
|
||||
|
|
|
@ -93,7 +93,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
private void ImportInputFrame(string line)
|
||||
{
|
||||
DeSmuMEControllerDef.BuildMnemonicsCache(Bk2MnemonicLookup.MnemonicFunc(Result.Movie.SystemID));
|
||||
DeSmuMEControllerDef.BuildMnemonicsCache(Result.Movie.SystemID);
|
||||
SimpleController controller = new(DeSmuMEControllerDef);
|
||||
|
||||
controller["LidOpen"] = false;
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace BizHawk.Client.Common.movie.import
|
|||
NesRightPort = nameof(ControllerNES)
|
||||
};
|
||||
_deck = controllerSettings.Instantiate((x, y) => true).AddSystemToControllerDef();
|
||||
_deck.ControllerDef.BuildMnemonicsCache(Bk2MnemonicLookup.MnemonicFunc(Result.Movie.SystemID));
|
||||
_deck.ControllerDef.BuildMnemonicsCache(Result.Movie.SystemID);
|
||||
|
||||
// 004 4-byte little-endian unsigned int: version number, must be 2
|
||||
uint version = r.ReadUInt32();
|
||||
|
|
|
@ -119,7 +119,7 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
controllerSettings.NesLeftPort = nameof(ControllerNES);
|
||||
_deck = controllerSettings.Instantiate((_, _) => false).AddSystemToControllerDef();
|
||||
_deck.ControllerDef.BuildMnemonicsCache(Bk2MnemonicLookup.MnemonicFunc(Result.Movie.SystemID));
|
||||
_deck.ControllerDef.BuildMnemonicsCache(Result.Movie.SystemID);
|
||||
}
|
||||
}
|
||||
else if (line.StartsWith("port1", StringComparison.OrdinalIgnoreCase))
|
||||
|
@ -128,7 +128,7 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
controllerSettings.NesRightPort = nameof(ControllerNES);
|
||||
_deck = controllerSettings.Instantiate((_, _) => false).AddSystemToControllerDef();
|
||||
_deck.ControllerDef.BuildMnemonicsCache(Bk2MnemonicLookup.MnemonicFunc(Result.Movie.SystemID));
|
||||
_deck.ControllerDef.BuildMnemonicsCache(Result.Movie.SystemID);
|
||||
}
|
||||
}
|
||||
else if (line.StartsWith("port2", StringComparison.OrdinalIgnoreCase))
|
||||
|
@ -147,7 +147,7 @@ namespace BizHawk.Client.Common
|
|||
controllerSettings.NesLeftPort = nameof(FourScore);
|
||||
controllerSettings.NesRightPort = nameof(FourScore);
|
||||
_deck = controllerSettings.Instantiate((_, _) => false).AddSystemToControllerDef();
|
||||
_deck.ControllerDef.BuildMnemonicsCache(Bk2MnemonicLookup.MnemonicFunc(Result.Movie.SystemID));
|
||||
_deck.ControllerDef.BuildMnemonicsCache(Result.Movie.SystemID);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -94,7 +94,7 @@ namespace BizHawk.Client.Common.movie.import
|
|||
NesRightPort = controller2 ? nameof(ControllerNES) : nameof(UnpluggedNES)
|
||||
};
|
||||
_deck = controllerSettings.Instantiate((x, y) => true).AddSystemToControllerDef();
|
||||
_deck.ControllerDef.BuildMnemonicsCache(Bk2MnemonicLookup.MnemonicFunc(Result.Movie.SystemID));
|
||||
_deck.ControllerDef.BuildMnemonicsCache(Result.Movie.SystemID);
|
||||
syncSettings.Controls.NesLeftPort = controllerSettings.NesLeftPort;
|
||||
syncSettings.Controls.NesRightPort = controllerSettings.NesRightPort;
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ namespace BizHawk.Client.Common.movie.import
|
|||
|
||||
GPGXControlConverter controlConverter = new(input, systemId: VSystemID.Raw.GEN, cdButtons: false);
|
||||
|
||||
controlConverter.ControllerDef.BuildMnemonicsCache(Bk2MnemonicLookup.MnemonicFunc(Result.Movie.SystemID));
|
||||
controlConverter.ControllerDef.BuildMnemonicsCache(Result.Movie.SystemID);
|
||||
SimpleController controller = new(controlConverter.ControllerDef);
|
||||
|
||||
// Unknown.
|
||||
|
|
|
@ -84,7 +84,7 @@ namespace BizHawk.Client.Common.movie.import
|
|||
}
|
||||
|
||||
ControllerDefinition controllerDefinition = new BsnesControllers(ss, true).Definition;
|
||||
controllerDefinition.BuildMnemonicsCache(Bk2MnemonicLookup.MnemonicFunc(VSystemID.Raw.SNES));
|
||||
controllerDefinition.BuildMnemonicsCache(VSystemID.Raw.SNES);
|
||||
_emptyController = new SimpleController(controllerDefinition);
|
||||
_controller = new SimpleController(controllerDefinition);
|
||||
_playerCount = controllerDefinition.PlayerCount;
|
||||
|
|
|
@ -146,7 +146,7 @@ namespace BizHawk.Client.Common.movie.import
|
|||
{
|
||||
var buttons = new[] { "Up", "Down", "Left", "Right", "B1", "B2", "Run", "Select" };
|
||||
|
||||
_deck.Definition.BuildMnemonicsCache(Bk2MnemonicLookup.MnemonicFunc(Result.Movie.SystemID));
|
||||
_deck.Definition.BuildMnemonicsCache(Result.Movie.SystemID);
|
||||
SimpleController controllers = new(_deck.Definition);
|
||||
|
||||
// Split up the sections of the frame.
|
||||
|
|
|
@ -95,7 +95,7 @@ namespace BizHawk.Client.Common.movie.import
|
|||
|
||||
var ss = new SMS.SmsSyncSettings();
|
||||
var cd = new SMSControllerDeck(ss.Port1, ss.Port2, isGameGear, ss.UseKeyboard);
|
||||
cd.Definition.BuildMnemonicsCache(Bk2MnemonicLookup.MnemonicFunc(Result.Movie.SystemID));
|
||||
cd.Definition.BuildMnemonicsCache(Result.Movie.SystemID);
|
||||
SimpleController controllers = new(cd.Definition);
|
||||
|
||||
/*
|
||||
|
|
|
@ -181,7 +181,7 @@ namespace BizHawk.Client.Common
|
|||
OctoshockDll.ePeripheralType.None, OctoshockDll.ePeripheralType.None, OctoshockDll.ePeripheralType.None
|
||||
};
|
||||
SimpleController controllers = new(Octoshock.CreateControllerDefinition(settings));
|
||||
controllers.Definition.BuildMnemonicsCache(Bk2MnemonicLookup.MnemonicFunc(Result.Movie.SystemID));
|
||||
controllers.Definition.BuildMnemonicsCache(Result.Movie.SystemID);
|
||||
|
||||
string[] buttons =
|
||||
{
|
||||
|
@ -292,7 +292,7 @@ namespace BizHawk.Client.Common
|
|||
OctoshockDll.ePeripheralType.None, OctoshockDll.ePeripheralType.None, OctoshockDll.ePeripheralType.None
|
||||
};
|
||||
SimpleController controllers = new(Octoshock.CreateControllerDefinition(settings));
|
||||
controllers.Definition.BuildMnemonicsCache(Bk2MnemonicLookup.MnemonicFunc(Result.Movie.SystemID));
|
||||
controllers.Definition.BuildMnemonicsCache(Result.Movie.SystemID);
|
||||
|
||||
string[] buttons =
|
||||
{
|
||||
|
|
|
@ -189,7 +189,7 @@ namespace BizHawk.Client.Common.movie.import
|
|||
}
|
||||
|
||||
ControllerDefinition definition = new Snes9xControllers(ss).ControllerDefinition;
|
||||
definition.BuildMnemonicsCache(Bk2MnemonicLookup.MnemonicFunc(Result.Movie.SystemID));
|
||||
definition.BuildMnemonicsCache(Result.Movie.SystemID);
|
||||
SimpleController controllers = new(definition);
|
||||
|
||||
Result.Movie.LogKey = Bk2LogEntryGenerator.GenerateLogKey(definition);
|
||||
|
|
|
@ -203,7 +203,7 @@ namespace BizHawk.Client.Common.movie.import
|
|||
SimpleController controllers = isGBA
|
||||
? GbaController()
|
||||
: GbController();
|
||||
controllers.Definition.BuildMnemonicsCache(Bk2MnemonicLookup.MnemonicFunc(isGBA ? VSystemID.Raw.GBA : VSystemID.Raw.GB));
|
||||
controllers.Definition.BuildMnemonicsCache(isGBA ? VSystemID.Raw.GBA : VSystemID.Raw.GB);
|
||||
|
||||
/*
|
||||
* 01 00 A
|
||||
|
|
|
@ -106,7 +106,7 @@ namespace BizHawk.Client.Common.movie.import
|
|||
"Reset", "Power", "Previous Disk", "Next Disk", "P1 Left", "P1 Right", "P1 Up", "P1 Down", "P1 Start", "P1 A", "P1 B", "P1 C", "P1 X", "P1 Y", "P1 Z", "P1 L", "P1 R"
|
||||
}
|
||||
}.MakeImmutable());
|
||||
controllers.Definition.BuildMnemonicsCache(Bk2MnemonicLookup.MnemonicFunc(Result.Movie.SystemID));
|
||||
controllers.Definition.BuildMnemonicsCache(Result.Movie.SystemID);
|
||||
|
||||
// Split up the sections of the frame.
|
||||
var sections = line.Split(new[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace BizHawk.Client.Common
|
|||
_ => "Null Controller",
|
||||
};
|
||||
Definition = new(copyFrom: definition, withName: name);
|
||||
Definition.BuildMnemonicsCache(Bk2MnemonicLookup.MnemonicFunc(systemId));
|
||||
Definition.BuildMnemonicsCache(systemId); //TODO these aren't the same...
|
||||
}
|
||||
|
||||
public ControllerDefinition Definition { get; set; }
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
using System.Collections.Generic;
|
||||
using BizHawk.Common.StringExtensions;
|
||||
using BizHawk.Emulation.Common;
|
||||
using BizHawk.Emulation.Cores.Libretro;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
namespace BizHawk.Emulation.Common
|
||||
{
|
||||
public static class Bk2MnemonicLookup
|
||||
{
|
||||
/// <remarks>duplicated with <c>LibretroControllerDef</c></remarks>
|
||||
private const string PFX_RETROPAD = "RetroPad ";
|
||||
|
||||
public static char Lookup(string button, string systemId)
|
||||
{
|
||||
var key = button.Replace("Key ", "");
|
||||
|
@ -21,7 +22,7 @@ namespace BizHawk.Client.Common
|
|||
key = key.Substring(3);
|
||||
}
|
||||
}
|
||||
key = key.RemovePrefix(LibretroHost.LibretroControllerDef.PFX_RETROPAD);
|
||||
key = key.RemovePrefix(PFX_RETROPAD);
|
||||
|
||||
if (SystemOverrides.TryGetValue(systemId, out var overridesForSys) && overridesForSys.TryGetValue(key, out var c))
|
||||
{
|
||||
|
@ -63,8 +64,6 @@ namespace BizHawk.Client.Common
|
|||
return button;
|
||||
}
|
||||
|
||||
public static Func<string, char> MnemonicFunc(string systemId) => buttonName => Lookup(buttonName, systemId);
|
||||
|
||||
private static readonly Dictionary<string, char> BaseMnemonicLookupTable = new Dictionary<string, char>
|
||||
{
|
||||
["Power"] = 'P',
|
|
@ -40,14 +40,15 @@ namespace BizHawk.Emulation.Common
|
|||
|
||||
/// <remarks>
|
||||
/// TODO: this should probably be called in <see cref="MakeImmutable"/>,
|
||||
/// but the needed Bk2MnemonicsLookup is in Client.Common
|
||||
/// </remarks>
|
||||
public void BuildMnemonicsCache(Func<string, char> mnemonicFunc)
|
||||
public void BuildMnemonicsCache(string sysID)
|
||||
{
|
||||
if (_mutable)
|
||||
throw new InvalidOperationException($"this {nameof(ControllerDefinition)} has not yet been built and sealed; can't build mnemonics cache");
|
||||
|
||||
_mnemonicsCache ??= BoolButtons.ToDictionary(buttonName => buttonName, mnemonicFunc);
|
||||
_mnemonicsCache ??= BoolButtons.ToDictionary(
|
||||
static buttonName => buttonName,
|
||||
buttonName => Bk2MnemonicLookup.Lookup(buttonName, sysID));
|
||||
}
|
||||
|
||||
public ControllerDefinition(string name)
|
||||
|
|
|
@ -74,7 +74,7 @@ namespace BizHawk.Emulation.Cores.Libretro
|
|||
{
|
||||
private const string CAT_KEYBOARD = "RetroKeyboard";
|
||||
|
||||
public const string PFX_RETROPAD = "RetroPad ";
|
||||
private const string PFX_RETROPAD = "RetroPad ";
|
||||
|
||||
public LibretroControllerDef()
|
||||
: base(name: "LibRetro Controls"/*for compatibility*/)
|
||||
|
|
|
@ -15,12 +15,12 @@ namespace BizHawk.Tests.Client.Common.Display
|
|||
public void Initializer()
|
||||
{
|
||||
_boolController = new(new ControllerDefinition("Dummy Gamepad") { BoolButtons = { "A" } }.MakeImmutable());
|
||||
_boolController.Definition.BuildMnemonicsCache(Bk2MnemonicLookup.MnemonicFunc(VSystemID.Raw.NULL));
|
||||
_boolController.Definition.BuildMnemonicsCache(VSystemID.Raw.NULL);
|
||||
_axisController = new(
|
||||
new ControllerDefinition("Dummy Gamepad")
|
||||
.AddXYPair("Stick{0}", AxisPairOrientation.RightAndUp, 0.RangeTo(200), MidValue)
|
||||
.MakeImmutable());
|
||||
_axisController.Definition.BuildMnemonicsCache(Bk2MnemonicLookup.MnemonicFunc(VSystemID.Raw.NULL));
|
||||
_axisController.Definition.BuildMnemonicsCache(VSystemID.Raw.NULL);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
|
|
@ -14,19 +14,19 @@ namespace BizHawk.Tests.Client.Common.Movie
|
|||
public void Initializer()
|
||||
{
|
||||
_boolController = new(new ControllerDefinition("Dummy Gamepad") { BoolButtons = { "A" } }.MakeImmutable());
|
||||
_boolController.Definition.BuildMnemonicsCache(Bk2MnemonicLookup.MnemonicFunc(VSystemID.Raw.NES));
|
||||
_boolController.Definition.BuildMnemonicsCache(VSystemID.Raw.NES);
|
||||
_axisController = new(
|
||||
new ControllerDefinition("Dummy Gamepad")
|
||||
.AddXYPair("Stick{0}", AxisPairOrientation.RightAndUp, 0.RangeTo(200), 100)
|
||||
.MakeImmutable());
|
||||
_axisController.Definition.BuildMnemonicsCache(Bk2MnemonicLookup.MnemonicFunc(VSystemID.Raw.NES));
|
||||
_axisController.Definition.BuildMnemonicsCache(VSystemID.Raw.NES);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GenerateLogEntry_ExclamationForUnknownButtons()
|
||||
{
|
||||
SimpleController controller = new(new ControllerDefinition("Dummy Gamepad") { BoolButtons = { "Unknown Button" } }.MakeImmutable());
|
||||
controller.Definition.BuildMnemonicsCache(Bk2MnemonicLookup.MnemonicFunc(VSystemID.Raw.NES));
|
||||
controller.Definition.BuildMnemonicsCache(VSystemID.Raw.NES);
|
||||
controller["Unknown Button"] = true;
|
||||
var actual = Bk2LogEntryGenerator.GenerateLogEntry(controller);
|
||||
Assert.AreEqual("|!|", actual);
|
||||
|
|
Loading…
Reference in New Issue