Skip to content

Commit

Permalink
Merge pull request #2408 from SJuliez/Issue2302
Browse files Browse the repository at this point in the history
Issue #2302: fix Map Size in lobby when decreasing map size
  • Loading branch information
sixlettervariables authored Nov 19, 2020
2 parents 50b6a9b + dbb7d25 commit 7e157af
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions megamek/src/megamek/common/MapSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,11 @@ public void setMapSize(int mapWidth, int mapHeight) {
if ((mapWidth <= 0) || (mapHeight <= 0)) {
throw new IllegalArgumentException("Total map area must be positive");
}

// If the map has become smaller, shrink the list by removing surplus elements
if (mapWidth * mapHeight < boardsSelected.size()) {
boardsSelected.subList(mapWidth * mapHeight, boardsSelected.size()).clear();
}

this.mapWidth = mapWidth;
this.mapHeight = mapHeight;
Expand All @@ -584,6 +589,8 @@ public void setMapSize(int mapWidth, int mapHeight) {
boardsSelected.set(i, null);
}
}

// Fill the list with null elements if the map has grown
while (boardsSelected.size() < (mapWidth * mapHeight)) {
boardsSelected.add(null);
}
Expand Down

0 comments on commit 7e157af

Please sign in to comment.