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