reorg controller and input adapter classes

This commit is contained in:
adelikat 2020-07-03 11:54:10 -05:00
parent 6db1d7e61d
commit c64eff6baf
10 changed files with 152 additions and 159 deletions

View File

@ -2,7 +2,7 @@
namespace BizHawk.Client.Common
{
public class AndAdapter : IController
public class AndAdapter : IInputAdapter
{
public ControllerDefinition Definition => Source.Definition;
@ -20,11 +20,11 @@ namespace BizHawk.Client.Common
// this works in the code because SourceOr is the autofire controller
public int AxisValue(string name) => Source.AxisValue(name);
internal IController Source { get; set; }
public IController Source { get; set; }
internal IController SourceAnd { get; set; }
}
public class XorAdapter : IController
public class XorAdapter : IInputAdapter
{
public ControllerDefinition Definition => Source.Definition;
@ -42,11 +42,11 @@ namespace BizHawk.Client.Common
// this works in the code because SourceOr is the autofire controller
public int AxisValue(string name) => Source.AxisValue(name);
internal IController Source { get; set; }
public IController Source { get; set; }
internal IController SourceXor { get; set; }
}
public class ORAdapter : IController
public class ORAdapter : IInputAdapter
{
public ControllerDefinition Definition => Source.Definition;
@ -60,7 +60,7 @@ namespace BizHawk.Client.Common
// this works in the code because SourceOr is the autofire controller
public int AxisValue(string name) => Source.AxisValue(name);
internal IController Source { get; set; }
public IController Source { get; set; }
internal IController SourceOr { get; set; }
}
}

View File

@ -10,4 +10,44 @@ namespace BizHawk.Client.Common
{
IController Source { get; set; }
}
public static class InputAdapterExtensions
{
/// <summary>
/// Creates a new IController that is in a state of a bitwise And of the source and target controllers
/// </summary>
public static IController And(this IController source, IController target)
{
return new AndAdapter
{
Source = source,
SourceAnd = target
};
}
/// <summary>
/// Creates a new IController that is in a state of a bitwise Xor of the source and target controllers
/// </summary>
public static IController Xor(this IController source, IController target)
{
return new XorAdapter
{
Source = source,
SourceXor = target
};
}
/// <summary>
/// Creates a new IController that is in a state of a bitwise Or of the source and target controllers
/// </summary>
public static IController Or(this IController source, IController target)
{
return new ORAdapter
{
Source = source,
SourceOr = target
};
}
}
}

View File

@ -1,44 +0,0 @@
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common.InputAdapterExtensions
{
public static class InputAdapterExtensions
{
/// <summary>
/// Creates a new IController that is in a state of a bitwise And of the source and target controllers
/// </summary>
public static IController And(this IController source, IController target)
{
return new AndAdapter
{
Source = source,
SourceAnd = target
};
}
/// <summary>
/// Creates a new IController that is in a state of a bitwise Xor of the source and target controllers
/// </summary>
public static IController Xor(this IController source, IController target)
{
return new XorAdapter
{
Source = source,
SourceXor = target
};
}
/// <summary>
/// Creates a new IController that is in a state of a bitwise Or of the source and target controllers
/// </summary>
public static IController Or(this IController source, IController target)
{
return new ORAdapter
{
Source = source,
SourceOr = target
};
}
}
}

View File

@ -1,7 +1,5 @@
using System.Collections.Generic;
using BizHawk.Emulation.Common;
using BizHawk.Client.Common.InputAdapterExtensions;
namespace BizHawk.Client.Common
{

View File

@ -6,7 +6,7 @@ using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common
{
public interface IStickyController : IController
public interface IStickyController : IInputAdapter
{
bool IsSticky(string button);
}

View File

@ -7,7 +7,7 @@ namespace BizHawk.Client.Common
/// Filters input for things called Up and Down while considering the client's AllowUD_LR option.
/// This is a bit gross but it is unclear how to do it more nicely
/// </summary>
public class UdlrControllerAdapter : IController
public class UdlrControllerAdapter : IInputAdapter
{
public IController Source { get; set; }

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using BizHawk.Emulation.Common;
using BizHawk.Client.Common;
using BizHawk.Client.Common.InputAdapterExtensions;
namespace BizHawk.Client.EmuHawk
{