Skip to content

Commit

Permalink
Clear old bindings before applying new ones
Browse files Browse the repository at this point in the history
  • Loading branch information
Somfic committed May 29, 2024
1 parent cc4b84a commit 12c5f41
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src-plugin/EliteVA/Services/Bridge/BindingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class BindingsService : VoiceAttackService
{
private readonly ILogger<BindingsService> _log;
private readonly IEliteDangerousApi _api;
private IReadOnlyCollection<Binding> _oldBindings = new List<Binding>();

public BindingsService(ILogger<BindingsService> log, IEliteDangerousApi api)
{
Expand All @@ -28,6 +29,14 @@ public override Task OnStart(IVoiceAttackProxy proxy)

private void HandleBindings(IReadOnlyCollection<Binding> bindings, BindingsContext context)
{
foreach (var oldBinding in _oldBindings)
{
_log.LogDebug("Clearing {Variable} from VoiceAttack", $"EliteAPI.{oldBinding.Name}");
VoiceAttackPlugin.Proxy.Variables.Clear("Bindings", $"EliteAPI.{oldBinding.Name}", TypeCode.String);
}

_oldBindings = bindings;

var bindsName = new FileInfo(context.SourceFile).Name;
if (!bindsName.EndsWith(".binds"))
bindsName = "standard";
Expand All @@ -36,12 +45,11 @@ private void HandleBindings(IReadOnlyCollection<Binding> bindings, BindingsConte

var layout = ReadYml("layout");

// var nonKeyboardBinidings = bindings.Where(x => x.Primary?.Device != "Keyboard" && x.Secondary?.Device != "Keyboard").ToList();

// Set keyboard keys
foreach (var b in bindings)
foreach (var b in bindings.Where(x => x.Primary?.Device == "Keyboard" || x.Secondary?.Device == "Keyboard"))
{
if (b.Primary?.Device != "Keyboard" && b.Secondary?.Device != "Keyboard")
continue;

IPrimarySecondaryBinding binding = b.Primary?.Device == "Keyboard" ? b.Primary! : b.Secondary!;

var keycode = $"[{GetKeyCode(binding.Key, layout)}]";
Expand Down

0 comments on commit 12c5f41

Please sign in to comment.