Skip to content

Commit

Permalink
Fixed Camouflage Directory Assignment for Null Faction Codes
Browse files Browse the repository at this point in the history
Changed the default camouflage directory to "Standard Camouflage" when the faction code is null, ensuring valid directory assignment.
  • Loading branch information
IllianiCBT committed Oct 21, 2024
1 parent f4ebf81 commit 6020003
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions MekHQ/src/mekhq/campaign/mission/AtBContract.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import mekhq.campaign.mission.atb.AtBScenarioFactory;
import mekhq.campaign.mission.enums.AtBContractType;
import mekhq.campaign.mission.enums.AtBMoraleLevel;
import mekhq.campaign.mission.enums.ContractCommandRights;
import mekhq.campaign.personnel.Bloodname;
import mekhq.campaign.personnel.Person;
import mekhq.campaign.personnel.backgrounds.BackgroundsController;
Expand Down Expand Up @@ -74,7 +73,6 @@
import java.time.LocalDate;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;

import static java.lang.Math.round;
import static megamek.client.ratgenerator.ModelRecord.NETWORK_NONE;
Expand Down Expand Up @@ -247,15 +245,19 @@ public static Camouflage pickRandomCamouflage(int currentYear, String factionCod
// Define the root directory and get the faction-specific camouflage directory
final String ROOT_DIRECTORY = "data/images/camo/";

String camouflageDirectory = getCamouflageDirectory(currentYear, factionCode);
String camouflageDirectory = "Standard Camouflage";

if (factionCode != null) {
camouflageDirectory = getCamouflageDirectory(currentYear, factionCode);
}

// Gather all files
List<Path> allPaths = null;

try {
allPaths = Files.find(Paths.get(ROOT_DIRECTORY + camouflageDirectory + '/'), Integer.MAX_VALUE,
(path, bfa) -> {return bfa.isRegularFile();})
.collect(Collectors.toList());
(path, bfa) -> bfa.isRegularFile())
.toList();
} catch (IOException e) {
logger.error("Error getting list of camouflages", e);
}
Expand All @@ -266,7 +268,7 @@ public static Camouflage pickRandomCamouflage(int currentYear, String factionCod

String fileName = randomPath.getFileName().toString();
String fileCategory = randomPath.getParent().toString()
.replaceAll("\\\\", "/"); // Is this necessary on windows machines?
.replaceAll("\\\\", "/"); // This is necessary for windows machines
fileCategory = fileCategory.replaceAll(ROOT_DIRECTORY, "");

return new Camouflage(fileCategory, fileName);
Expand Down Expand Up @@ -1934,7 +1936,7 @@ private static double estimateMekStrength(Campaign campaign, String factionCode,
// getMekSummary(int index) is NULL for salvage.
int genericBattleValue = unitTable.getMekSummary(i).loadEntity().getGenericBattleValue();
int weight = unitTable.getEntryWeight(i); // NOT 0 for salvage

totalBattleValue += battleValue * weight;
totalGBV += genericBattleValue * weight;
rollingCount += weight;
Expand Down

0 comments on commit 6020003

Please sign in to comment.