Skip to content

Commit

Permalink
Bugfix for pal target selection breaking after re-running solver
Browse files Browse the repository at this point in the history
  • Loading branch information
tylercamp committed Apr 14, 2024
1 parent dc2d200 commit 7c5f0b0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions PalCalc.UI/ViewModel/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ private void UpdateTargetsList()
UpdatePalTarget();
}

private void UpdatePalTarget() => PalTarget = new PalTargetViewModel(PalTargetList.SelectedTarget);
private void UpdatePalTarget()
{
if (PalTargetList.SelectedTarget != null)
PalTarget = new PalTargetViewModel(PalTargetList.SelectedTarget);
}

private void SaveSelection_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
Expand Down Expand Up @@ -103,7 +107,8 @@ public void RunSolver()
}
else
{
PalTarget.InitialPalSpecifier.CopyFrom(PalTarget.CurrentPalSpecifier);
PalTargetList.Replace(PalTarget.InitialPalSpecifier, PalTarget.CurrentPalSpecifier);
PalTargetList.SelectedTarget = PalTarget.CurrentPalSpecifier;
}

var outputFolder = Storage.SaveFileDataPath(SaveSelection.SelectedGame.Value);
Expand Down
6 changes: 6 additions & 0 deletions PalCalc.UI/ViewModel/PalTargetListViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,11 @@ public PalTargetListViewModel(IEnumerable<PalSpecifierViewModel> existingSpecs)
private PalSpecifierViewModel selectedTarget;

public void Add(PalSpecifierViewModel value) => targets.Insert(1, value);

public void Replace(PalSpecifierViewModel oldValue, PalSpecifierViewModel newValue)
{
var oldIndex = targets.IndexOf(oldValue);
targets[oldIndex] = newValue;
}
}
}

0 comments on commit 7c5f0b0

Please sign in to comment.