refactor: preprocessors for wiimote and joycon compilation
This commit is contained in:
parent
65d562ee74
commit
72750c3388
11 changed files with 63 additions and 32 deletions
|
@ -1,11 +1,33 @@
|
|||
namespace SwitchSlidePresenter;
|
||||
using ControllerSlidePresenter.GamepadReader;
|
||||
|
||||
namespace ControllerSlidePresenter;
|
||||
|
||||
public static class ControllerSelector {
|
||||
public static IGamepadReader? GetReader() {
|
||||
Console.WriteLine("Write a number to select controller type:");
|
||||
Console.WriteLine("[1] - JoyCon");
|
||||
Console.WriteLine("[2] - Wiimote");
|
||||
private static readonly List<(string name, IGamepadReader reader)> Readers = [
|
||||
#if JoyCon
|
||||
("JoyCon", new JoyConRead()),
|
||||
#endif
|
||||
#if Wiimote
|
||||
("Wiimote", new WiimoteRead())
|
||||
#endif
|
||||
];
|
||||
|
||||
public static IGamepadReader? GetReader() {
|
||||
if (Readers.Count == 1)
|
||||
return Readers[0].reader;
|
||||
|
||||
Console.WriteLine("Write a number to select controller type:");
|
||||
for (int i = 0; i < Readers.Count; i++)
|
||||
Console.WriteLine($"[{i+1}] - {Readers[i].name}");
|
||||
|
||||
int? id = GetReaderIndex();
|
||||
if (id == null)
|
||||
return null;
|
||||
|
||||
return Readers[id.Value].reader;
|
||||
}
|
||||
|
||||
private static int? GetReaderIndex() {
|
||||
string? line = Console.ReadLine();
|
||||
if (line == null) {
|
||||
Console.WriteLine("Invalid input.");
|
||||
|
@ -15,13 +37,11 @@ public static class ControllerSelector {
|
|||
Console.WriteLine("Invalid number.");
|
||||
return null;
|
||||
}
|
||||
|
||||
return GetReader(id);
|
||||
if (id <= 0 || id >= Readers.Count) {
|
||||
Console.WriteLine("Invalid number");
|
||||
return null;
|
||||
}
|
||||
|
||||
private static IGamepadReader? GetReader(int id) => id switch {
|
||||
1 => new JoyConRead(),
|
||||
2 => new WiimoteRead(),
|
||||
_ => null
|
||||
};
|
||||
return id - 1;
|
||||
}
|
||||
}
|
|
@ -5,22 +5,26 @@
|
|||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>SwitchSlidePresenter</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('Windows'))">
|
||||
<DefineConstants>OS_WINDOWS</DefineConstants>
|
||||
<DefineConstants>$(DefineConstants);OS_WINDOWS</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('Linux'))">
|
||||
<DefineConstants>OS_LINUX</DefineConstants>
|
||||
<DefineConstants>$(DefineConstants);OS_LINUX</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('OSX'))">
|
||||
<DefineConstants>OS_MAC</DefineConstants>
|
||||
<DefineConstants>$(DefineConstants);OS_MAC</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<DefineConstants>$(DefineConstants);JoyCon</DefineConstants>
|
||||
<DefineConstants>$(DefineConstants);Wiimote</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="JoyCon.NET" Version="1.0.1" />
|
||||
<PackageReference Include="WiimoteLib.NetCore" Version="1.0.0" />
|
||||
<PackageReference Include="JoyCon.NET" Version="1.0.1" Condition="$(DefineConstants.Contains(JoyCon))" />
|
||||
<PackageReference Include="WiimoteLib.NetCore" Version="1.0.0" Condition="$(DefineConstants.Contains(Wiimote))" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
namespace SwitchSlidePresenter;
|
||||
namespace ControllerSlidePresenter.GamepadReader;
|
||||
|
||||
public interface IGamepadReader {
|
||||
public event Action NextSlide;
|
|
@ -1,11 +1,12 @@
|
|||
using System.Text;
|
||||
#if JoyCon
|
||||
using System.Text;
|
||||
using HidSharp;
|
||||
using wtf.cluster.JoyCon;
|
||||
using wtf.cluster.JoyCon.ExtraData;
|
||||
using wtf.cluster.JoyCon.InputData;
|
||||
using wtf.cluster.JoyCon.InputReports;
|
||||
|
||||
namespace SwitchSlidePresenter;
|
||||
namespace ControllerSlidePresenter.GamepadReader;
|
||||
|
||||
public class JoyConRead : IGamepadReader {
|
||||
public event Action NextSlide;
|
||||
|
@ -90,3 +91,4 @@ public class JoyConRead : IGamepadReader {
|
|||
return input.ZLorZR || input.Down;
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -1,6 +1,7 @@
|
|||
using WiimoteLib.NetCore;
|
||||
#if Wiimote
|
||||
using WiimoteLib.NetCore;
|
||||
|
||||
namespace SwitchSlidePresenter;
|
||||
namespace ControllerSlidePresenter.GamepadReader;
|
||||
|
||||
public class WiimoteRead : IGamepadReader {
|
||||
public event Action NextSlide;
|
||||
|
@ -47,3 +48,4 @@ public class WiimoteRead : IGamepadReader {
|
|||
return input.A || input.Right;
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -1,4 +1,4 @@
|
|||
namespace SwitchSlidePresenter.InputSender;
|
||||
namespace ControllerSlidePresenter.InputSender;
|
||||
|
||||
public interface IInputSender {
|
||||
void NextSlide();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#if OS_LINUX
|
||||
namespace SwitchSlidePresenter.InputSender;
|
||||
namespace ControllerSlidePresenter.InputSender;
|
||||
|
||||
public class LinuxInputSender : IInputSender {
|
||||
public void NextSlide() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#if OS_MAC
|
||||
namespace SwitchSlidePresenter.InputSender;
|
||||
namespace ControllerSlidePresenter.InputSender;
|
||||
|
||||
public class MacInputSender : IInputSender {
|
||||
public void NextSlide() {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
using System.Runtime.InteropServices;
|
||||
using Win32Api;
|
||||
|
||||
namespace SwitchSlidePresenter.InputSender;
|
||||
namespace ControllerSlidePresenter.InputSender;
|
||||
|
||||
public class WindowsInputSender : IInputSender {
|
||||
private const uint INPUT_KEYBOARD = 1;
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
namespace SwitchSlidePresenter {
|
||||
using ControllerSlidePresenter.GamepadReader;
|
||||
|
||||
namespace ControllerSlidePresenter {
|
||||
internal abstract class Program {
|
||||
private static async Task Main() {
|
||||
IGamepadReader? reader = ControllerSelector.GetReader();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using SwitchSlidePresenter.InputSender;
|
||||
using ControllerSlidePresenter.GamepadReader;
|
||||
using ControllerSlidePresenter.InputSender;
|
||||
|
||||
namespace SwitchSlidePresenter;
|
||||
namespace ControllerSlidePresenter;
|
||||
|
||||
public class SlideSwitcher : IDisposable {
|
||||
private readonly IGamepadReader? _reader;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue