Skip to content

Commit 95c0717

Browse files
committed
✨ make a distinction between valid and invalid bindings
semver: minor
1 parent f474d48 commit 95c0717

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

EliteAPI/Bindings/BindingsUtils.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
using System.Collections.Generic;
33
using System.IO;
44

5-
public class BindingsUtils
5+
namespace EliteAPI.Bindings;
6+
7+
public static class BindingsUtils
68
{
79
private static readonly Dictionary<string, string> KeyCodeMap = new(StringComparer.OrdinalIgnoreCase)
810
{
@@ -183,7 +185,7 @@ private static DirectoryInfo GetOptionsDirectory()
183185
return new DirectoryInfo(Path.Combine(localAppData, "Frontier Developments", "Elite Dangerous", "Options"));
184186
}
185187

186-
internal static string GetKeyCode(string key)
188+
internal static string GetKeyCode(string? key)
187189
{
188190
if (key == null)
189191
return "-1";
@@ -192,4 +194,4 @@ internal static string GetKeyCode(string key)
192194

193195
return $"[{keyCode}]";
194196
}
195-
}
197+
}

EliteAPI/bindings/Binding.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public readonly struct Binding
88

99
public string Key { get; init; }
1010

11-
public string KeyCode => $"{string.Join("", Modifiers?.Select(m => m.KeyCode) ?? Enumerable.Empty<string>())}{BindingsUtils.GetKeyCode(Key)}";
11+
public string KeyCode => $"{string.Join("", Modifiers?.Select(m => m.KeyCode) ?? [])}{BindingsUtils.GetKeyCode(Key)}";
1212

1313
public Binding[]? Modifiers { get; init; }
1414

EliteAPI/bindings/Control.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public readonly struct Control
1313
public bool? IsInverted { get; init; }
1414

1515
public float? Deadzone { get; init; }
16+
17+
public bool IsValid => !string.IsNullOrEmpty(KeyCode);
1618

1719
public string KeyCode { get {
1820
if (Primary is { Device: "Keyboard" })

0 commit comments

Comments
 (0)