Pass `SimpleController.Definition` via ctor instead of initialiser
This commit is contained in:
parent
519fd40c32
commit
dfbce55707
|
@ -11,12 +11,15 @@ namespace BizHawk.Client.Common
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SimpleController : IController
|
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, 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> Axes { get; private set; } = new WorkingDictionary<string, int>();
|
||||||
protected WorkingDictionary<string, int> HapticFeedback { 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()
|
public void Clear()
|
||||||
{
|
{
|
||||||
Buttons = new WorkingDictionary<string, bool>();
|
Buttons = new WorkingDictionary<string, bool>();
|
||||||
|
|
|
@ -2,10 +2,15 @@
|
||||||
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
|
using BizHawk.Emulation.Common;
|
||||||
|
|
||||||
namespace BizHawk.Client.Common
|
namespace BizHawk.Client.Common
|
||||||
{
|
{
|
||||||
public class InputCoalescer : SimpleController
|
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) {}
|
protected virtual void ProcessSubsets(string button, bool state) {}
|
||||||
|
|
||||||
public void Receive(InputEvent ie)
|
public void Receive(InputEvent ie)
|
||||||
|
|
|
@ -84,9 +84,8 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
private void ImportInputFrame(string line)
|
private void ImportInputFrame(string line)
|
||||||
{
|
{
|
||||||
var controller = new SimpleController
|
SimpleController controller = new(
|
||||||
{
|
new ControllerDefinition
|
||||||
Definition = new ControllerDefinition
|
|
||||||
{
|
{
|
||||||
BoolButtons =
|
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
|
}.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("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["LidOpen"] = false;
|
||||||
controller["LidClose"] = false;
|
controller["LidClose"] = false;
|
||||||
|
|
|
@ -145,10 +145,7 @@ namespace BizHawk.Client.Common.movie.import
|
||||||
// Advance to first byte of input data.
|
// Advance to first byte of input data.
|
||||||
r.BaseStream.Position = firstFrameOffset;
|
r.BaseStream.Position = firstFrameOffset;
|
||||||
|
|
||||||
var controllers = new SimpleController
|
SimpleController controllers = new(_deck.GetDefinition());
|
||||||
{
|
|
||||||
Definition = _deck.GetDefinition()
|
|
||||||
};
|
|
||||||
|
|
||||||
string[] buttons = { "A", "B", "Select", "Start", "Up", "Down", "Left", "Right" };
|
string[] buttons = { "A", "B", "Select", "Start", "Up", "Down", "Left", "Right" };
|
||||||
bool fds = false;
|
bool fds = false;
|
||||||
|
@ -293,10 +290,7 @@ namespace BizHawk.Client.Common.movie.import
|
||||||
|
|
||||||
private void AddDeckControlButtons()
|
private void AddDeckControlButtons()
|
||||||
{
|
{
|
||||||
var controllers = new SimpleController
|
SimpleController controllers = new(_deck.GetDefinition());
|
||||||
{
|
|
||||||
Definition = _deck.GetDefinition()
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: FDS
|
// TODO: FDS
|
||||||
// Yes, this adds them to the deck definition too
|
// Yes, this adds them to the deck definition too
|
||||||
|
|
|
@ -170,10 +170,7 @@ namespace BizHawk.Client.Common
|
||||||
private readonly string[] _buttons = { "Right", "Left", "Down", "Up", "Start", "Select", "B", "A" };
|
private readonly string[] _buttons = { "Right", "Left", "Down", "Up", "Start", "Select", "B", "A" };
|
||||||
private void ImportInputFrame(string line)
|
private void ImportInputFrame(string line)
|
||||||
{
|
{
|
||||||
var controllers = new SimpleController
|
SimpleController controllers = new(_deck.GetDefinition());
|
||||||
{
|
|
||||||
Definition = _deck.GetDefinition()
|
|
||||||
};
|
|
||||||
|
|
||||||
string[] sections = line.Split(new[] {'|'}, StringSplitOptions.RemoveEmptyEntries);
|
string[] sections = line.Split(new[] {'|'}, StringSplitOptions.RemoveEmptyEntries);
|
||||||
controllers["Reset"] = sections[1][0] == '1';
|
controllers["Reset"] = sections[1][0] == '1';
|
||||||
|
@ -218,10 +215,7 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
private void AddDeckControlButtons()
|
private void AddDeckControlButtons()
|
||||||
{
|
{
|
||||||
var controllers = new SimpleController
|
SimpleController controllers = new(_deck.GetDefinition());
|
||||||
{
|
|
||||||
Definition = _deck.GetDefinition()
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: FDS
|
// TODO: FDS
|
||||||
// Yes, this adds them to the deck definition too
|
// Yes, this adds them to the deck definition too
|
||||||
|
|
|
@ -100,10 +100,7 @@ namespace BizHawk.Client.Common.movie.import
|
||||||
|
|
||||||
AddDeckControlButtons();
|
AddDeckControlButtons();
|
||||||
|
|
||||||
var controllers = new SimpleController
|
SimpleController controllers = new(_deck.GetDefinition());
|
||||||
{
|
|
||||||
Definition = _deck.GetDefinition()
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 01 Right
|
* 01 Right
|
||||||
|
@ -167,10 +164,7 @@ namespace BizHawk.Client.Common.movie.import
|
||||||
|
|
||||||
private void AddDeckControlButtons()
|
private void AddDeckControlButtons()
|
||||||
{
|
{
|
||||||
var controllers = new SimpleController
|
SimpleController controllers = new(_deck.GetDefinition());
|
||||||
{
|
|
||||||
Definition = _deck.GetDefinition()
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: FDS
|
// TODO: FDS
|
||||||
// Yes, this adds them to the deck definition too
|
// Yes, this adds them to the deck definition too
|
||||||
|
|
|
@ -89,10 +89,7 @@ namespace BizHawk.Client.Common.movie.import
|
||||||
|
|
||||||
var controlConverter = new GPGXControlConverter(input, false);
|
var controlConverter = new GPGXControlConverter(input, false);
|
||||||
|
|
||||||
var controller = new SimpleController
|
SimpleController controller = new(controlConverter.ControllerDef);
|
||||||
{
|
|
||||||
Definition = controlConverter.ControllerDef
|
|
||||||
};
|
|
||||||
|
|
||||||
// Unknown.
|
// Unknown.
|
||||||
r.ReadByte();
|
r.ReadByte();
|
||||||
|
|
|
@ -264,10 +264,7 @@ namespace BizHawk.Client.Common.movie.import
|
||||||
|
|
||||||
private IController EmptyLmsvFrame()
|
private IController EmptyLmsvFrame()
|
||||||
{
|
{
|
||||||
var emptyController = new SimpleController
|
SimpleController emptyController = new(_deck.Definition);
|
||||||
{
|
|
||||||
Definition = _deck.Definition
|
|
||||||
};
|
|
||||||
|
|
||||||
foreach (var button in emptyController.Definition.BoolButtons)
|
foreach (var button in emptyController.Definition.BoolButtons)
|
||||||
{
|
{
|
||||||
|
@ -279,10 +276,7 @@ namespace BizHawk.Client.Common.movie.import
|
||||||
|
|
||||||
private void ImportTextFrame(string line, string platform)
|
private void ImportTextFrame(string line, string platform)
|
||||||
{
|
{
|
||||||
var controllers = new SimpleController
|
SimpleController controllers = new(_deck.Definition);
|
||||||
{
|
|
||||||
Definition = _deck.Definition
|
|
||||||
};
|
|
||||||
|
|
||||||
var buttons = new[]
|
var buttons = new[]
|
||||||
{
|
{
|
||||||
|
|
|
@ -147,7 +147,7 @@ namespace BizHawk.Client.Common.movie.import
|
||||||
{
|
{
|
||||||
var buttons = new[] { "Up", "Down", "Left", "Right", "B1", "B2", "Run", "Select" };
|
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.
|
// Split up the sections of the frame.
|
||||||
string[] sections = line.Split('|');
|
string[] sections = line.Split('|');
|
||||||
|
|
|
@ -96,10 +96,7 @@ namespace BizHawk.Client.Common.movie.import
|
||||||
|
|
||||||
var ss = new SMS.SmsSyncSettings();
|
var ss = new SMS.SmsSyncSettings();
|
||||||
var cd = new SMSControllerDeck(ss.Port1, ss.Port2, isGameGear, ss.UseKeyboard);
|
var cd = new SMSControllerDeck(ss.Port1, ss.Port2, isGameGear, ss.UseKeyboard);
|
||||||
var controllers = new SimpleController
|
SimpleController controllers = new(cd.Definition);
|
||||||
{
|
|
||||||
Definition = cd.Definition
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
76543210
|
76543210
|
||||||
|
|
|
@ -172,7 +172,6 @@ namespace BizHawk.Client.Common
|
||||||
protected void ParseBinaryInputLog(BinaryReader br, IMovie movie, MiscHeaderInfo info)
|
protected void ParseBinaryInputLog(BinaryReader br, IMovie movie, MiscHeaderInfo info)
|
||||||
{
|
{
|
||||||
var settings = new Octoshock.SyncSettings();
|
var settings = new Octoshock.SyncSettings();
|
||||||
var controllers = new SimpleController();
|
|
||||||
settings.FIOConfig.Devices8 = new[]
|
settings.FIOConfig.Devices8 = new[]
|
||||||
{
|
{
|
||||||
info.Player1Type,
|
info.Player1Type,
|
||||||
|
@ -180,7 +179,7 @@ namespace BizHawk.Client.Common
|
||||||
info.Player2Type,
|
info.Player2Type,
|
||||||
OctoshockDll.ePeripheralType.None, OctoshockDll.ePeripheralType.None, OctoshockDll.ePeripheralType.None
|
OctoshockDll.ePeripheralType.None, OctoshockDll.ePeripheralType.None, OctoshockDll.ePeripheralType.None
|
||||||
};
|
};
|
||||||
controllers.Definition = Octoshock.CreateControllerDefinition(settings);
|
SimpleController controllers = new(Octoshock.CreateControllerDefinition(settings));
|
||||||
|
|
||||||
string[] buttons =
|
string[] buttons =
|
||||||
{
|
{
|
||||||
|
@ -283,7 +282,6 @@ namespace BizHawk.Client.Common
|
||||||
protected void ParseTextInputLog(BinaryReader br, IMovie movie, MiscHeaderInfo info)
|
protected void ParseTextInputLog(BinaryReader br, IMovie movie, MiscHeaderInfo info)
|
||||||
{
|
{
|
||||||
Octoshock.SyncSettings settings = new Octoshock.SyncSettings();
|
Octoshock.SyncSettings settings = new Octoshock.SyncSettings();
|
||||||
SimpleController controllers = new SimpleController();
|
|
||||||
settings.FIOConfig.Devices8 = new[]
|
settings.FIOConfig.Devices8 = new[]
|
||||||
{
|
{
|
||||||
info.Player1Type,
|
info.Player1Type,
|
||||||
|
@ -291,7 +289,7 @@ namespace BizHawk.Client.Common
|
||||||
info.Player2Type,
|
info.Player2Type,
|
||||||
OctoshockDll.ePeripheralType.None, OctoshockDll.ePeripheralType.None, OctoshockDll.ePeripheralType.None
|
OctoshockDll.ePeripheralType.None, OctoshockDll.ePeripheralType.None, OctoshockDll.ePeripheralType.None
|
||||||
};
|
};
|
||||||
controllers.Definition = Octoshock.CreateControllerDefinition(settings);
|
SimpleController controllers = new(Octoshock.CreateControllerDefinition(settings));
|
||||||
|
|
||||||
string[] buttons =
|
string[] buttons =
|
||||||
{
|
{
|
||||||
|
|
|
@ -200,10 +200,7 @@ namespace BizHawk.Client.Common.movie.import
|
||||||
Result.Movie.HeaderEntries[HeaderKeys.GameName] = gameName;
|
Result.Movie.HeaderEntries[HeaderKeys.GameName] = gameName;
|
||||||
}
|
}
|
||||||
|
|
||||||
SimpleController controllers = new SimpleController
|
SimpleController controllers = new(_deck.Definition);
|
||||||
{
|
|
||||||
Definition = _deck.Definition
|
|
||||||
};
|
|
||||||
|
|
||||||
r.BaseStream.Position = firstFrameOffset;
|
r.BaseStream.Position = firstFrameOffset;
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -296,17 +296,12 @@ namespace BizHawk.Client.Common.movie.import
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SimpleController GbController()
|
private static SimpleController GbController()
|
||||||
{
|
=> new(new ControllerDefinition
|
||||||
return new SimpleController
|
|
||||||
{
|
|
||||||
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()
|
private static SimpleController GbaController()
|
||||||
=> new SimpleController { Definition = MGBAHawk.GBAController };
|
=> new(MGBAHawk.GBAController);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,17 +100,14 @@ namespace BizHawk.Client.Common.movie.import
|
||||||
private void ImportTextFrame(string line)
|
private void ImportTextFrame(string line)
|
||||||
{
|
{
|
||||||
// Yabause only supported 1 controller
|
// Yabause only supported 1 controller
|
||||||
var controllers = new SimpleController
|
SimpleController controllers = new(new ControllerDefinition
|
||||||
{
|
|
||||||
Definition = new ControllerDefinition
|
|
||||||
{
|
{
|
||||||
Name = "Saturn Controller",
|
Name = "Saturn Controller",
|
||||||
BoolButtons = new List<string>
|
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.
|
// Split up the sections of the frame.
|
||||||
var sections = line.Split(new[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
|
var sections = line.Split(new[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
using System.Collections.Generic;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
||||||
using BizHawk.Client.Common;
|
using BizHawk.Client.Common;
|
||||||
using BizHawk.Common;
|
using BizHawk.Common;
|
||||||
using BizHawk.Emulation.Common;
|
using BizHawk.Emulation.Common;
|
||||||
|
@ -16,15 +16,8 @@ namespace BizHawk.Tests.Client.Common.Display
|
||||||
[TestInitialize]
|
[TestInitialize]
|
||||||
public void Initializer()
|
public void Initializer()
|
||||||
{
|
{
|
||||||
_boolController = new SimpleController
|
_boolController = new(new ControllerDefinition { BoolButtons = { "A" } });
|
||||||
{
|
_axisController = new(new ControllerDefinition().AddXYPair("Stick{0}", AxisPairOrientation.RightAndUp, 0.RangeTo(200), MidValue));
|
||||||
Definition = new ControllerDefinition { BoolButtons = { "A" } }
|
|
||||||
};
|
|
||||||
|
|
||||||
_axisController = new SimpleController
|
|
||||||
{
|
|
||||||
Definition = new ControllerDefinition().AddXYPair("Stick{0}", AxisPairOrientation.RightAndUp, 0.RangeTo(200), MidValue)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
|
||||||
using BizHawk.Client.Common;
|
using BizHawk.Client.Common;
|
||||||
using BizHawk.Common;
|
using BizHawk.Common;
|
||||||
using BizHawk.Emulation.Common;
|
using BizHawk.Emulation.Common;
|
||||||
|
@ -15,30 +15,16 @@ namespace BizHawk.Tests.Client.Common.Movie
|
||||||
[TestInitialize]
|
[TestInitialize]
|
||||||
public void Initializer()
|
public void Initializer()
|
||||||
{
|
{
|
||||||
_boolController = new SimpleController
|
_boolController = new(new ControllerDefinition { BoolButtons = { "A" } });
|
||||||
{
|
_axisController = new(new ControllerDefinition().AddXYPair("Stick{0}", AxisPairOrientation.RightAndUp, 0.RangeTo(200), 100));
|
||||||
Definition = new ControllerDefinition { BoolButtons = { "A" } }
|
|
||||||
};
|
|
||||||
|
|
||||||
_axisController = new SimpleController
|
|
||||||
{
|
|
||||||
Definition = new ControllerDefinition().AddXYPair("Stick{0}", AxisPairOrientation.RightAndUp, 0.RangeTo(200), 100)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void GenerateLogEntry_ExclamationForUnknownButtons()
|
public void GenerateLogEntry_ExclamationForUnknownButtons()
|
||||||
{
|
{
|
||||||
var controller = new SimpleController
|
SimpleController controller = new(new ControllerDefinition { BoolButtons = { "Unknown Button" } });
|
||||||
{
|
|
||||||
Definition = new ControllerDefinition
|
|
||||||
{
|
|
||||||
BoolButtons = new List<string> {"Unknown Button"}
|
|
||||||
},
|
|
||||||
["Unknown Button"] = true
|
|
||||||
};
|
|
||||||
|
|
||||||
var lg = new Bk2LogEntryGenerator("NES", controller);
|
var lg = new Bk2LogEntryGenerator("NES", controller);
|
||||||
|
controller["Unknown Button"] = true;
|
||||||
var actual = lg.GenerateLogEntry();
|
var actual = lg.GenerateLogEntry();
|
||||||
Assert.AreEqual("|!|", actual);
|
Assert.AreEqual("|!|", actual);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue