Pass `SimpleController.Definition` via ctor instead of initialiser

This commit is contained in:
YoshiRulz 2021-12-04 23:11:56 +10:00 committed by James Groom
parent 519fd40c32
commit dfbce55707
16 changed files with 44 additions and 102 deletions

View File

@ -11,12 +11,15 @@ namespace BizHawk.Client.Common
/// </summary>
public class SimpleController : IController
{
public ControllerDefinition Definition { get; set; }
public ControllerDefinition Definition { get; }
protected WorkingDictionary<string, bool> Buttons { get; private set; } = new WorkingDictionary<string, bool>();
protected WorkingDictionary<string, int> Axes { get; private set; } = new WorkingDictionary<string, int>();
protected WorkingDictionary<string, int> HapticFeedback { get; private set; } = new WorkingDictionary<string, int>();
public SimpleController(ControllerDefinition definition)
=> Definition = definition;
public void Clear()
{
Buttons = new WorkingDictionary<string, bool>();

View File

@ -2,10 +2,15 @@
using System.Linq;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common
{
public class InputCoalescer : SimpleController
{
public InputCoalescer()
: base(NullController.Instance.Definition) {} // is Definition ever read on these subclasses? --yoshi
protected virtual void ProcessSubsets(string button, bool state) {}
public void Receive(InputEvent ie)

View File

@ -84,9 +84,8 @@ namespace BizHawk.Client.Common
private void ImportInputFrame(string line)
{
var controller = new SimpleController
{
Definition = new ControllerDefinition
SimpleController controller = new(
new ControllerDefinition
{
BoolButtons =
{
@ -94,8 +93,7 @@ namespace BizHawk.Client.Common
}
}.AddXYPair("Touch {0}", AxisPairOrientation.RightAndUp, 0.RangeTo(255), 128, 0.RangeTo(191), 96) //TODO verify direction against hardware
.AddAxis("Mic Input", 0.RangeTo(2047), 0)
.AddAxis("GBA Light Sensor", 0.RangeTo(10), 0)
};
.AddAxis("GBA Light Sensor", 0.RangeTo(10), 0));
controller["LidOpen"] = false;
controller["LidClose"] = false;

View File

@ -145,10 +145,7 @@ namespace BizHawk.Client.Common.movie.import
// Advance to first byte of input data.
r.BaseStream.Position = firstFrameOffset;
var controllers = new SimpleController
{
Definition = _deck.GetDefinition()
};
SimpleController controllers = new(_deck.GetDefinition());
string[] buttons = { "A", "B", "Select", "Start", "Up", "Down", "Left", "Right" };
bool fds = false;
@ -293,10 +290,7 @@ namespace BizHawk.Client.Common.movie.import
private void AddDeckControlButtons()
{
var controllers = new SimpleController
{
Definition = _deck.GetDefinition()
};
SimpleController controllers = new(_deck.GetDefinition());
// TODO: FDS
// Yes, this adds them to the deck definition too

View File

@ -170,10 +170,7 @@ namespace BizHawk.Client.Common
private readonly string[] _buttons = { "Right", "Left", "Down", "Up", "Start", "Select", "B", "A" };
private void ImportInputFrame(string line)
{
var controllers = new SimpleController
{
Definition = _deck.GetDefinition()
};
SimpleController controllers = new(_deck.GetDefinition());
string[] sections = line.Split(new[] {'|'}, StringSplitOptions.RemoveEmptyEntries);
controllers["Reset"] = sections[1][0] == '1';
@ -218,10 +215,7 @@ namespace BizHawk.Client.Common
private void AddDeckControlButtons()
{
var controllers = new SimpleController
{
Definition = _deck.GetDefinition()
};
SimpleController controllers = new(_deck.GetDefinition());
// TODO: FDS
// Yes, this adds them to the deck definition too

View File

@ -100,10 +100,7 @@ namespace BizHawk.Client.Common.movie.import
AddDeckControlButtons();
var controllers = new SimpleController
{
Definition = _deck.GetDefinition()
};
SimpleController controllers = new(_deck.GetDefinition());
/*
* 01 Right
@ -167,10 +164,7 @@ namespace BizHawk.Client.Common.movie.import
private void AddDeckControlButtons()
{
var controllers = new SimpleController
{
Definition = _deck.GetDefinition()
};
SimpleController controllers = new(_deck.GetDefinition());
// TODO: FDS
// Yes, this adds them to the deck definition too

View File

@ -89,10 +89,7 @@ namespace BizHawk.Client.Common.movie.import
var controlConverter = new GPGXControlConverter(input, false);
var controller = new SimpleController
{
Definition = controlConverter.ControllerDef
};
SimpleController controller = new(controlConverter.ControllerDef);
// Unknown.
r.ReadByte();

View File

@ -264,10 +264,7 @@ namespace BizHawk.Client.Common.movie.import
private IController EmptyLmsvFrame()
{
var emptyController = new SimpleController
{
Definition = _deck.Definition
};
SimpleController emptyController = new(_deck.Definition);
foreach (var button in emptyController.Definition.BoolButtons)
{
@ -279,10 +276,7 @@ namespace BizHawk.Client.Common.movie.import
private void ImportTextFrame(string line, string platform)
{
var controllers = new SimpleController
{
Definition = _deck.Definition
};
SimpleController controllers = new(_deck.Definition);
var buttons = new[]
{

View File

@ -147,7 +147,7 @@ namespace BizHawk.Client.Common.movie.import
{
var buttons = new[] { "Up", "Down", "Left", "Right", "B1", "B2", "Run", "Select" };
var controllers = new SimpleController { Definition = _deck.Definition };
SimpleController controllers = new(_deck.Definition);
// Split up the sections of the frame.
string[] sections = line.Split('|');

View File

@ -96,10 +96,7 @@ namespace BizHawk.Client.Common.movie.import
var ss = new SMS.SmsSyncSettings();
var cd = new SMSControllerDeck(ss.Port1, ss.Port2, isGameGear, ss.UseKeyboard);
var controllers = new SimpleController
{
Definition = cd.Definition
};
SimpleController controllers = new(cd.Definition);
/*
76543210

View File

@ -172,7 +172,6 @@ namespace BizHawk.Client.Common
protected void ParseBinaryInputLog(BinaryReader br, IMovie movie, MiscHeaderInfo info)
{
var settings = new Octoshock.SyncSettings();
var controllers = new SimpleController();
settings.FIOConfig.Devices8 = new[]
{
info.Player1Type,
@ -180,7 +179,7 @@ namespace BizHawk.Client.Common
info.Player2Type,
OctoshockDll.ePeripheralType.None, OctoshockDll.ePeripheralType.None, OctoshockDll.ePeripheralType.None
};
controllers.Definition = Octoshock.CreateControllerDefinition(settings);
SimpleController controllers = new(Octoshock.CreateControllerDefinition(settings));
string[] buttons =
{
@ -283,7 +282,6 @@ namespace BizHawk.Client.Common
protected void ParseTextInputLog(BinaryReader br, IMovie movie, MiscHeaderInfo info)
{
Octoshock.SyncSettings settings = new Octoshock.SyncSettings();
SimpleController controllers = new SimpleController();
settings.FIOConfig.Devices8 = new[]
{
info.Player1Type,
@ -291,7 +289,7 @@ namespace BizHawk.Client.Common
info.Player2Type,
OctoshockDll.ePeripheralType.None, OctoshockDll.ePeripheralType.None, OctoshockDll.ePeripheralType.None
};
controllers.Definition = Octoshock.CreateControllerDefinition(settings);
SimpleController controllers = new(Octoshock.CreateControllerDefinition(settings));
string[] buttons =
{

View File

@ -200,10 +200,7 @@ namespace BizHawk.Client.Common.movie.import
Result.Movie.HeaderEntries[HeaderKeys.GameName] = gameName;
}
SimpleController controllers = new SimpleController
{
Definition = _deck.Definition
};
SimpleController controllers = new(_deck.Definition);
r.BaseStream.Position = firstFrameOffset;
/*

View File

@ -296,17 +296,12 @@ namespace BizHawk.Client.Common.movie.import
}
private static SimpleController GbController()
{
return new SimpleController
=> new(new ControllerDefinition
{
Definition = new ControllerDefinition
{
BoolButtons = { "Up", "Down", "Left", "Right", "Start", "Select", "B", "A", "Power" }
}
};
}
BoolButtons = { "Up", "Down", "Left", "Right", "Start", "Select", "B", "A", "Power" }
});
private static SimpleController GbaController()
=> new SimpleController { Definition = MGBAHawk.GBAController };
=> new(MGBAHawk.GBAController);
}
}

View File

@ -100,17 +100,14 @@ namespace BizHawk.Client.Common.movie.import
private void ImportTextFrame(string line)
{
// Yabause only supported 1 controller
var controllers = new SimpleController
SimpleController controllers = new(new ControllerDefinition
{
Definition = new ControllerDefinition
Name = "Saturn Controller",
BoolButtons = new List<string>
{
Name = "Saturn Controller",
BoolButtons = new List<string>
{
"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"
}
"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"
}
};
});
// Split up the sections of the frame.
var sections = line.Split(new[] { "|" }, StringSplitOptions.RemoveEmptyEntries);

View File

@ -1,5 +1,5 @@
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using BizHawk.Client.Common;
using BizHawk.Common;
using BizHawk.Emulation.Common;
@ -16,15 +16,8 @@ namespace BizHawk.Tests.Client.Common.Display
[TestInitialize]
public void Initializer()
{
_boolController = new SimpleController
{
Definition = new ControllerDefinition { BoolButtons = { "A" } }
};
_axisController = new SimpleController
{
Definition = new ControllerDefinition().AddXYPair("Stick{0}", AxisPairOrientation.RightAndUp, 0.RangeTo(200), MidValue)
};
_boolController = new(new ControllerDefinition { BoolButtons = { "A" } });
_axisController = new(new ControllerDefinition().AddXYPair("Stick{0}", AxisPairOrientation.RightAndUp, 0.RangeTo(200), MidValue));
}
[TestMethod]

View File

@ -1,5 +1,5 @@
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using BizHawk.Client.Common;
using BizHawk.Common;
using BizHawk.Emulation.Common;
@ -15,30 +15,16 @@ namespace BizHawk.Tests.Client.Common.Movie
[TestInitialize]
public void Initializer()
{
_boolController = new SimpleController
{
Definition = new ControllerDefinition { BoolButtons = { "A" } }
};
_axisController = new SimpleController
{
Definition = new ControllerDefinition().AddXYPair("Stick{0}", AxisPairOrientation.RightAndUp, 0.RangeTo(200), 100)
};
_boolController = new(new ControllerDefinition { BoolButtons = { "A" } });
_axisController = new(new ControllerDefinition().AddXYPair("Stick{0}", AxisPairOrientation.RightAndUp, 0.RangeTo(200), 100));
}
[TestMethod]
public void GenerateLogEntry_ExclamationForUnknownButtons()
{
var controller = new SimpleController
{
Definition = new ControllerDefinition
{
BoolButtons = new List<string> {"Unknown Button"}
},
["Unknown Button"] = true
};
SimpleController controller = new(new ControllerDefinition { BoolButtons = { "Unknown Button" } });
var lg = new Bk2LogEntryGenerator("NES", controller);
controller["Unknown Button"] = true;
var actual = lg.GenerateLogEntry();
Assert.AreEqual("|!|", actual);
}