Skip to content

Commit

Permalink
Fix duplicate key error with edit mode's unit deletion. (#11747)
Browse files Browse the repository at this point in the history
Fix duplicate key error with edit mode's unit deletion.

This can happen if a unit chooser is brought up and the user manually selects both a transport and a unit loaded onto it. The unit loaded onto it will be added twice due to also being added as a dependent.
  • Loading branch information
asvitkine authored Jul 8, 2023
1 parent 525893e commit fce2d31
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -344,11 +345,12 @@ public Collection<Unit> getSelected() {
* killed).
*/
public List<Unit> getSelected(final boolean selectDependents) {
final List<Unit> selectedUnits = new ArrayList<>();
// Use a Set to avoid duplicates in the case where dependents are also manually selected.
final var selectedUnits = new HashSet<Unit>();
for (final ChooserEntry entry : entries) {
addToCollection(selectedUnits, entry, entry.getFinalHit(), selectDependents);
}
return selectedUnits;
return new ArrayList<>(selectedUnits);
}

/** Only applicable if this dialog was constructed using multiple hit points. */
Expand Down

0 comments on commit fce2d31

Please sign in to comment.