Move IController.ToDictionary extension to BizHawk.Emulation.Common

This commit is contained in:
YoshiRulz 2020-02-28 13:18:59 +10:00
parent 848eaabf46
commit e5da8c765a
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
4 changed files with 37 additions and 32 deletions

View File

@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common
{
public sealed class JoypadApi : IJoypad

View File

@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.IO;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common
{
public sealed class MovieApi : IInputMovie

View File

@ -60,37 +60,5 @@ namespace BizHawk.Client.Common
}
return table;
}
public static IDictionary<string, dynamic> ToDictionary(this IController controller, int? controllerNum = null)
{
var buttons = new Dictionary<string, dynamic>();
foreach (var button in controller.Definition.BoolButtons)
{
if (controllerNum == null)
{
buttons[button] = controller.IsPressed(button);
}
else if (button.Length > 2 && button.Substring(0, 2) == $"P{controllerNum}")
{
var sub = button.Substring(3);
buttons[sub] = controller.IsPressed($"P{controllerNum} {sub}");
}
}
foreach (var button in controller.Definition.FloatControls)
{
if (controllerNum == null)
{
buttons[button] = controller.GetFloat(button);
}
else if (button.Length > 2 && button.Substring(0, 2) == $"P{controllerNum}")
{
var sub = button.Substring(3);
buttons[sub] = controller.GetFloat($"P{controllerNum} {sub}");
}
}
return buttons;
}
}
}

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
@ -276,5 +277,37 @@ namespace BizHawk.Emulation.Common
{
return !info.GetCustomAttributes(false).Any(a => a is FeatureNotImplementedAttribute);
}
public static IDictionary<string, dynamic> ToDictionary(this IController controller, int? controllerNum = null)
{
var buttons = new Dictionary<string, dynamic>();
foreach (var button in controller.Definition.BoolButtons)
{
if (controllerNum == null)
{
buttons[button] = controller.IsPressed(button);
}
else if (button.Length > 2 && button.Substring(0, 2) == $"P{controllerNum}")
{
var sub = button.Substring(3);
buttons[sub] = controller.IsPressed($"P{controllerNum} {sub}");
}
}
foreach (var button in controller.Definition.FloatControls)
{
if (controllerNum == null)
{
buttons[button] = controller.GetFloat(button);
}
else if (button.Length > 2 && button.Substring(0, 2) == $"P{controllerNum}")
{
var sub = button.Substring(3);
buttons[sub] = controller.GetFloat($"P{controllerNum} {sub}");
}
}
return buttons;
}
}
}