Skip to content

Commit

Permalink
Merge pull request #4740 from IllianiCBT/toe_getEligibleCommandersNpe
Browse files Browse the repository at this point in the history
Fixed Bad Merge
  • Loading branch information
IllianiCBT authored Aug 28, 2024
2 parents 2aa91b2 + 664fb04 commit a41468a
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions MekHQ/src/mekhq/campaign/force/Force.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ public Camouflage getCamouflage() {
}

public Camouflage getCamouflageOrElse(final Camouflage camouflage) {
return getCamouflage().hasDefaultCategory()
? ((getParentForce() == null) ? camouflage : getParentForce().getCamouflageOrElse(camouflage))
: getCamouflage();
return getCamouflage().hasDefaultCategory() ? ((getParentForce() == null) ? camouflage : getParentForce().getCamouflageOrElse(camouflage)) : getCamouflage();
}

public void setCamouflage(Camouflage camouflage) {
Expand Down Expand Up @@ -434,11 +432,7 @@ public void setOverrideForceCommanderID(UUID overrideForceCommanderID) {
* @return a list of UUIDs representing the eligible commanders
*/
public List<UUID> getEligibleCommanders(Campaign campaign) {
List<UUID> eligibleCommanders = getUnits().stream()
.map(unitId -> campaign.getUnit(unitId).getCommander() != null ?
campaign.getUnit(unitId).getCommander().getId() : null)
.filter(Objects::nonNull)
.collect(Collectors.toList());
List<UUID> eligibleCommanders = getUnits().stream().map(unitId -> campaign.getUnit(unitId).getCommander() != null ? campaign.getUnit(unitId).getCommander().getId() : null).filter(Objects::nonNull).collect(Collectors.toList());

// this means the force contains no Units, so we check against the leaders of the sub-forces
if (eligibleCommanders.isEmpty()) {
Expand Down Expand Up @@ -521,16 +515,10 @@ public void removeSubForce(int id) {
*/
public List<LayeredForceIconOperationalStatus> updateForceIconOperationalStatus(final Campaign campaign) {
// First, update all subForces, collecting their unit statuses into a single list
final List<LayeredForceIconOperationalStatus> statuses = getSubForces().stream()
.flatMap(subForce -> subForce.updateForceIconOperationalStatus(campaign).stream())
.collect(Collectors.toList());
final List<LayeredForceIconOperationalStatus> statuses = getSubForces().stream().flatMap(subForce -> subForce.updateForceIconOperationalStatus(campaign).stream()).collect(Collectors.toList());

// Then, Add the units assigned to this force
statuses.addAll(getUnits().stream()
.map(campaign::getUnit)
.filter(Objects::nonNull)
.map(LayeredForceIconOperationalStatus::determineLayeredForceIconOperationalStatus)
.toList());
statuses.addAll(getUnits().stream().map(campaign::getUnit).filter(Objects::nonNull).map(LayeredForceIconOperationalStatus::determineLayeredForceIconOperationalStatus).toList());

// Can only update the icon for LayeredForceIcons, but still need to return the processed
// units for parent force updates
Expand All @@ -547,12 +535,7 @@ public List<LayeredForceIconOperationalStatus> updateForceIconOperationalStatus(
final int index = (int) Math.round(statuses.stream().mapToInt(Enum::ordinal).sum() / (statuses.size() * 1.0));
final LayeredForceIconOperationalStatus status = LayeredForceIconOperationalStatus.values()[index];
((LayeredForceIcon) getForceIcon()).getPieces().put(LayeredForceIconLayer.SPECIAL_MODIFIER, new ArrayList<>());
((LayeredForceIcon) getForceIcon()).getPieces().get(LayeredForceIconLayer.SPECIAL_MODIFIER)
.add(new ForcePieceIcon(
LayeredForceIconLayer.SPECIAL_MODIFIER,
MekHQ.getMHQOptions().getNewDayForceIconOperationalStatusStyle().getPath(),
status.getFilename())
);
((LayeredForceIcon) getForceIcon()).getPieces().get(LayeredForceIconLayer.SPECIAL_MODIFIER).add(new ForcePieceIcon(LayeredForceIconLayer.SPECIAL_MODIFIER, MekHQ.getMHQOptions().getNewDayForceIconOperationalStatusStyle().getPath(), status.getFilename()));
}

return statuses;
Expand Down Expand Up @@ -708,8 +691,7 @@ public Vector<Object> getAllChildren(Campaign campaign) {
}
}
}
units.sort((u1, u2) -> ((Comparable<Integer>) u2.getCommander().getRankNumeric())
.compareTo(u1.getCommander().getRankNumeric()));
units.sort((u1, u2) -> ((Comparable<Integer>) u2.getCommander().getRankNumeric()).compareTo(u1.getCommander().getRankNumeric()));

children.addAll(units);
children.addAll(unmannedUnits);
Expand Down

0 comments on commit a41468a

Please sign in to comment.