Skip to content

Commit

Permalink
fix: more random profile id
Browse files Browse the repository at this point in the history
  • Loading branch information
Scoppio committed Dec 29, 2024
1 parent 6771ceb commit b4f5231
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.util.List;
import java.util.Random;
import java.util.ResourceBundle;
import java.util.stream.Collectors;

import static megamek.client.ui.swing.ClientGUI.*;

Expand Down Expand Up @@ -387,8 +388,10 @@ private void persistProfile() {
//noinspection unchecked
var model = (DecisionTableModel<TWDecision>) profileDecisionTable.getModel();
if (profileId <= 0) {
var maxId = sharedData.getProfiles().stream().map(TWProfile::getId).max(Integer::compareTo).orElse(0);
profileId = new Random().nextInt(maxId + 1, Integer.MAX_VALUE);
var ids = sharedData.getProfiles().stream().map(TWProfile::getId).collect(Collectors.toSet());
while (ids.contains(profileId) || profileId <= 0) {
profileId = new Random().nextInt(1, Integer.MAX_VALUE);
}
}
var decisions = model.getDecisions().stream().map(e -> (Decision<Entity, Entity>) e).toList();
sharedData.addProfile(new TWProfile(profileId, profileNameTextField.getText(), descriptionTextField.getText(), decisions));
Expand Down

0 comments on commit b4f5231

Please sign in to comment.