Skip to content

Commit e37e6f2

Browse files
committed
🔊 update keybinding logging
semver: chore
1 parent 55a8369 commit e37e6f2

5 files changed

Lines changed: 24 additions & 59 deletions

File tree

EliteAPI.Tests/BindingTests.cs

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class BindingParserTests
99
[Fact]
1010
public void Parse_Sample_File()
1111
{
12-
string xml = File.ReadAllText("Bindings/test.binds");
12+
string xml = File.ReadAllText("TestFiles/Bindings/test.binds");
1313

1414
var content = BindingParser.Parse(xml);
1515

@@ -73,16 +73,7 @@ public void Parse_Should_Treat_NoDevice_EmptyKey_As_Unbound()
7373
.Parse(xml)
7474
.ToDictionary(c => c.Name);
7575

76-
controls.Should().ContainKeys("MouseReset", "RollLeftButton");
77-
78-
foreach (var control in controls.Values)
79-
{
80-
control.Primary.HasValue.Should().BeFalse();
81-
control.Secondary.HasValue.Should().BeFalse();
82-
control.IsToggle.Should().BeNull();
83-
control.IsInverted.Should().BeNull();
84-
control.Deadzone.Should().BeNull();
85-
}
76+
controls.Should().NotContainKeys("MouseReset", "RollLeftButton");
8677
}
8778

8879
[Fact]
@@ -113,54 +104,7 @@ public void Parse_Should_Map_Binding_Element_To_Primary_And_Read_Inverted_And_De
113104
control.IsToggle.Should().BeNull();
114105
control.Deadzone.Should().Be(0.25f);
115106
}
116-
117-
[Fact]
118-
public void Parse_Should_Handle_All_ToggleOn_Variants()
119-
{
120-
const string xml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
121-
<Root>
122-
<!-- Explicit false -->
123-
<BlockMouseDecay>
124-
<Primary Device=""{NoDevice}"" Key="""" />
125-
<Secondary Device=""{NoDevice}"" Key="""" />
126-
<ToggleOn Value=""0"" />
127-
</BlockMouseDecay>
128-
129-
<!-- Explicit true -->
130-
<ToggleFlightAssist>
131-
<Primary Device=""Keyboard"" Key=""Key_Z"" />
132-
<Secondary Device=""{NoDevice}"" Key="""" />
133-
<ToggleOn Value=""1"" />
134-
</ToggleFlightAssist>
135-
136-
<!-- No Value attribute, taken from HCS pattern -->
137-
<YawToRollButton>
138-
<Primary Device=""{NoDevice}"" Key="""" />
139-
<Secondary Device=""{NoDevice}"" Key="""" />
140-
<ToggleOn />
141-
</YawToRollButton>
142-
143-
<!-- No ToggleOn at all -->
144-
<MouseReset>
145-
<Primary Device=""{NoDevice}"" Key="""" />
146-
<Secondary Device=""{NoDevice}"" Key="""" />
147-
</MouseReset>
148-
</Root>";
149-
150-
var controls = BindingParser
151-
.Parse(xml)
152-
.ToDictionary(c => c.Name);
153-
154-
controls["BlockMouseDecay"].IsToggle.Should().BeFalse();
155-
controls["ToggleFlightAssist"].IsToggle.Should().BeTrue();
156-
157-
// Presence of <ToggleOn /> with no Value attribute – treat as true
158-
controls["YawToRollButton"].IsToggle.Should().BeTrue();
159-
160-
// No <ToggleOn> element at all
161-
controls["MouseReset"].IsToggle.Should().BeNull();
162-
}
163-
107+
164108
[Fact]
165109
public void Parse_Should_Read_Modifiers_On_Primary_And_Secondary()
166110
{

EliteAPI/EliteDangerousApi.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,10 @@ private void HandleBindingsPreset(string presetContent)
305305
var bindings = BindingParser.Parse(File.ReadAllText(file.FullName));
306306

307307
Log.Info($"Loaded {bindings.Count} keybindings from preset '{preset}'");
308+
foreach (var binding in bindings.Where(x => x.IsValid))
309+
Log.Debug($" OK: {binding.Name}: {binding.KeyCode} ({binding.ToDebugString()})");
310+
foreach (var binding in bindings.Where(x => !x.IsValid))
311+
Log.Debug($" NOT OK: {binding.Name}: {binding.ToDebugString()}");
308312

309313
foreach (var handler in _bindingsHandlers)
310314
SafeInvoke.Invoke("handling keybindings change", handler, bindings);

EliteAPI/bindings/Binding.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,12 @@ public Binding(string device, string key, Binding[]? modifiers = null)
1818
Key = key;
1919
Modifiers = modifiers;
2020
}
21+
22+
public string ToDebugString()
23+
{
24+
var modifiers = Modifiers is null || Modifiers.Length == 0
25+
? string.Empty
26+
: $"{string.Join("+", Modifiers.Select(m => m.Key))}+";
27+
return $"{modifiers}{Key}";
28+
}
2129
}

EliteAPI/bindings/BindingParser.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public static IReadOnlyCollection<Control> Parse(string xml)
1818
var controls = root.Elements()
1919
.Where(HasBindingElements)
2020
.Select(ParseElement)
21+
.Where(x => x.Primary.HasValue || x.Secondary.HasValue)
2122
.ToArray();
2223

2324
return controls;

EliteAPI/bindings/Control.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Linq;
2+
13
namespace EliteAPI.Bindings;
24

35
public readonly struct Control
@@ -25,4 +27,10 @@ public string KeyCode { get {
2527

2628
return string.Empty;
2729
}}
30+
31+
public string ToDebugString()
32+
{
33+
var bindings = ((Binding?[])[ Primary, Secondary]).Where(b => b.HasValue).Select(x => x!.Value.ToDebugString()).ToArray();
34+
return string.Join(", ", bindings);
35+
}
2836
}

0 commit comments

Comments
 (0)