2014-06-15 14:44:26 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
using BizHawk.Common;
|
|
|
|
|
using BizHawk.Emulation.Common;
|
|
|
|
|
|
|
|
|
|
namespace BizHawk.Client.Common
|
|
|
|
|
{
|
|
|
|
|
public class Bk2ControllerAdapter : IMovieController
|
|
|
|
|
{
|
2014-06-21 14:33:33 +00:00
|
|
|
|
private string _logKey = string.Empty;
|
|
|
|
|
|
|
|
|
|
public Bk2ControllerAdapter(string key)
|
|
|
|
|
{
|
|
|
|
|
_logKey = key;
|
|
|
|
|
SetLogOverride();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetLogOverride()
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(_logKey))
|
|
|
|
|
{
|
|
|
|
|
// TODO: this could be cleaned up into a LINQ select
|
|
|
|
|
List<List<string>> controls = new List<List<string>>();
|
|
|
|
|
var groups = _logKey.Split(new[] { "#" }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
foreach (var group in groups)
|
|
|
|
|
{
|
|
|
|
|
var buttons = group.Split(new[] { "|" }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
|
|
|
|
controls.Add(buttons);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_type.ControlsFromLog = controls;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-15 14:44:26 +00:00
|
|
|
|
#region IController Implementation
|
|
|
|
|
|
|
|
|
|
public bool this[string button]
|
|
|
|
|
{
|
|
|
|
|
get { return MyBoolButtons[button]; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsPressed(string button)
|
|
|
|
|
{
|
|
|
|
|
return MyBoolButtons[button];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float GetFloat(string name)
|
|
|
|
|
{
|
|
|
|
|
return MyFloatControls[name];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region IMovieController Implementation
|
|
|
|
|
|
2014-06-21 14:33:33 +00:00
|
|
|
|
private Bk2ControllerDefinition _type = new Bk2ControllerDefinition();
|
|
|
|
|
|
|
|
|
|
public ControllerDefinition Type
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_type = new Bk2ControllerDefinition(value);
|
|
|
|
|
SetLogOverride();
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-15 14:44:26 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// latches one player from the source
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void LatchPlayerFromSource(IController playerSource, int playerNum)
|
|
|
|
|
{
|
|
|
|
|
foreach (string button in playerSource.Type.BoolButtons)
|
|
|
|
|
{
|
|
|
|
|
var bnp = ButtonNameParser.Parse(button);
|
|
|
|
|
if (bnp == null)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bnp.PlayerNum != playerNum)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool val = playerSource[button];
|
|
|
|
|
MyBoolButtons[button] = val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// latches all buttons from the provided source
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void LatchFromSource(IController source)
|
|
|
|
|
{
|
|
|
|
|
foreach (string button in Type.BoolButtons)
|
|
|
|
|
{
|
|
|
|
|
MyBoolButtons[button] = source[button];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (string name in Type.FloatControls)
|
|
|
|
|
{
|
|
|
|
|
MyFloatControls[name] = source.GetFloat(name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// latches all buttons from the supplied mnemonic string
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void SetControllersAsMnemonic(string mnemonic)
|
|
|
|
|
{
|
2014-06-17 00:33:33 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(mnemonic))
|
2014-06-16 01:39:36 +00:00
|
|
|
|
{
|
2014-06-21 14:33:33 +00:00
|
|
|
|
var def = Global.Emulator.ControllerDefinition;
|
2014-06-17 00:33:33 +00:00
|
|
|
|
var trimmed = mnemonic.Replace("|", "");
|
2014-06-21 11:56:30 +00:00
|
|
|
|
var buttons = Type.ControlsOrdered.SelectMany(x => x).ToList();
|
|
|
|
|
var iterator = 0;
|
|
|
|
|
var boolIt = 0;
|
|
|
|
|
var floatIt = 0;
|
2014-06-17 00:33:33 +00:00
|
|
|
|
|
2014-06-21 11:56:30 +00:00
|
|
|
|
for (int i = 0; i < buttons.Count; i++)
|
2014-06-17 00:33:33 +00:00
|
|
|
|
{
|
2014-06-21 14:33:33 +00:00
|
|
|
|
var b = buttons[i];
|
|
|
|
|
if (def.BoolButtons.Contains(buttons[i]))
|
2014-06-21 11:56:30 +00:00
|
|
|
|
{
|
2014-06-21 14:33:33 +00:00
|
|
|
|
MyBoolButtons[buttons[i]] = trimmed[iterator] == '.' ? false : true;
|
2014-06-21 11:56:30 +00:00
|
|
|
|
iterator++;
|
|
|
|
|
boolIt++;
|
|
|
|
|
}
|
2014-06-21 14:33:33 +00:00
|
|
|
|
else if (def.FloatControls.Contains(buttons[i]))
|
2014-06-21 11:56:30 +00:00
|
|
|
|
{
|
|
|
|
|
var temp = trimmed.Substring(iterator, 3);
|
|
|
|
|
var val = int.Parse(temp);
|
|
|
|
|
|
2014-06-21 14:33:33 +00:00
|
|
|
|
MyFloatControls[buttons[i]] = val;
|
2014-06-21 11:56:30 +00:00
|
|
|
|
iterator += 4;
|
|
|
|
|
floatIt++;
|
|
|
|
|
}
|
2014-06-17 00:33:33 +00:00
|
|
|
|
}
|
2014-06-16 01:39:36 +00:00
|
|
|
|
}
|
2014-06-15 14:44:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2014-06-21 14:33:33 +00:00
|
|
|
|
public class Bk2ControllerDefinition : ControllerDefinition
|
|
|
|
|
{
|
|
|
|
|
public Bk2ControllerDefinition()
|
|
|
|
|
: base()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Bk2ControllerDefinition(ControllerDefinition source)
|
|
|
|
|
: base(source)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<List<string>> ControlsFromLog = new List<List<string>>();
|
|
|
|
|
|
|
|
|
|
public override IEnumerable<IEnumerable<string>> ControlsOrdered
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (ControlsFromLog.Any())
|
|
|
|
|
{
|
|
|
|
|
return ControlsFromLog;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.ControlsOrdered;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-15 14:44:26 +00:00
|
|
|
|
private readonly WorkingDictionary<string, bool> MyBoolButtons = new WorkingDictionary<string, bool>();
|
|
|
|
|
private readonly WorkingDictionary<string, float> MyFloatControls = new WorkingDictionary<string, float>();
|
|
|
|
|
}
|
|
|
|
|
}
|