private void AddToUnusedSwitch(PRSwitch x) { if (x == null) { return; } char sdlKeyCodeChar = (char)CapturedSdlCode; string charString = sdlKeyCodeChar.ToString(); Dispatcher.CurrentDispatcher.Invoke(() => { SwitchKeys.Add(new KeyboardMapItemViewModel { Keycode = CapturedSdlCode, Name = x.Name, Number = x.Number, Key = sdlKeyCodeChar.ToString() }); }); AvailableSwitches.Remove(x); }
/// <summary> /// Called when [load yaml files changed]. Updates the switches from file. /// </summary> /// <returns></returns> public async override Task OnLoadYamlFilesChanged() { SwitchKeys?.Clear(); Log("Populating keyboard switch maps"); AvailableSwitches = new ObservableCollection <PRSwitch>(_skeletonGameProvider .MachineConfig.PRSwitches.Where(x => x.Name != "NOT USED").ToList()); Log($"Available switches: {AvailableSwitches?.Count}"); //Order switches and create new view models for the collection var orderedSwitch = _skeletonGameProvider.GameConfig.KeyboardSwitchMap.OrderBy(x => x.Value); foreach (var keySwitch in orderedSwitch) { //TODO: Remove? //keySwitch.Key = item.Key.Replace("\\b", "\b") //.Replace("\\r", "\r") //.Replace("\\t", "\t"); var availableSwitchFromNumber = AvailableSwitches.FirstOrDefault(x => x.Number == keySwitch.Value); if (availableSwitchFromNumber == null) { availableSwitchFromNumber = AvailableSwitches.FirstOrDefault(x => x.Name == keySwitch.Value); } if (availableSwitchFromNumber != null) { await Dispatcher.CurrentDispatcher.InvokeAsync(() => SwitchKeys.Add(new KeyboardMapItemViewModel(availableSwitchFromNumber, keySwitch)) ); AvailableSwitches.Remove(availableSwitchFromNumber); } } }