Skip to content

Commit

Permalink
restore reference between Mode and ButtonMap
Browse files Browse the repository at this point in the history
  • Loading branch information
joekolodz committed Jul 25, 2022
1 parent e94268c commit 675ffe7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/Models/HOTASDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ public void SetMode(Dictionary<int, ObservableCollection<IHotasBaseMap>> profile
{
Modes = profile;
if (Modes.Count < 1) return;
ApplyButtonMap(profile[Modes.Keys.Min()].ToObservableCollection());

ApplyButtonMap(Modes[Modes.Keys.Min()].ToObservableCollection());
Modes[Modes.Keys.Min()] = ButtonMap;
}

//todo pass in the mode profile key for the profile you want to template from
Expand Down Expand Up @@ -318,7 +320,7 @@ public void ApplyButtonMap(ObservableCollection<IHotasBaseMap> existingButtonMap
//existingButtonMap is assumed to have less button entries in this scenario. So we want to copy the data from existingButtonMap for any buttons that match between the two lists
//Any buttons that don't match means that the device has more buttons than are in the existingButtonMap list and so there is nothing to copy
//If the device has fewer buttons than exist on the existingButtonMap, then those buttons are not copied over and lost
ButtonMap = new ObservableCollection<IHotasBaseMap>();
ButtonMap?.Clear();
SeedButtonMapFromDeviceCapabilities(ButtonMap);
foreach (var source in existingButtonMap)
{
Expand Down
6 changes: 3 additions & 3 deletions src/ViewModels/HOTASCollectionViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,8 @@ private void BuildDevicesViewModelFromLoadedDevices(IHOTASCollection loadedDevic
if (d == null) continue;
}
d.SetMode(ld.Modes);
ReBuildActionsFromCatalog(deviceVm);
deviceVm.RebuildMap(d.ButtonMap);
ReBuildActionsFromCatalog(deviceVm);//assign each button their actions
deviceVm.RebuildMap(d.ButtonMap);//recreate the view model for each button now that the actions are assigned
}
}

Expand Down Expand Up @@ -495,7 +495,7 @@ private void ResetProfile()
deviceVm.ClearButtonMap();
deviceVm.RebuildMap();
}

OnPropertyChanged(nameof(ModeActivationItems));

_fileSystem.LastSavedFileName = "";
Expand Down

0 comments on commit 675ffe7

Please sign in to comment.