Skip to content

Commit

Permalink
Cleanup related to new naming scheme and refactoring.
Browse files Browse the repository at this point in the history
Removed old kludges obsoleted by getFullChassis()
Refactoring of retrieveOriginalUnit() to enable
refactoring of populateRefits() that properly throws exceptions.
  • Loading branch information
Setsul committed Oct 10, 2024
1 parent 2a8f5f5 commit 9173982
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
22 changes: 10 additions & 12 deletions MekHQ/src/mekhq/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -1331,23 +1331,21 @@ public static int selectBestBayFor(Entity cargo, Entity transport) {
* @throws EntityLoadingException
*/
public static MekSummary retrieveOriginalUnit(Entity newE) throws EntityLoadingException {
MekSummaryCache cacheInstance = MekSummaryCache.getInstance();
cacheInstance.loadMekData();

// this might be better with refreshUnitData() and/or elsewhere
MekSummaryCache.getInstance().loadMekData();
// I need to change the new entity to the one from the mtf file now, so that
// equipment numbers will match
MekSummary summary = cacheInstance.getMek(newE.getFullChassis() + ' ' + newE.getModel());

if (null == summary) {
// Attempt to deal with new naming convention directly
summary = cacheInstance.getMek(
newE.getChassis() + " (" + newE.getClanChassisName() + ") " + newE.getModel());
}
return retrieveUnit(newE.getShortNameRaw());
}

public static MekSummary retrieveUnit(String shortNameRaw) throws EntityLoadingException {
MekSummary summary = MekSummaryCache.getInstance().getMek(shortNameRaw);

// If we got this far with no summary loaded, give up
if (null == summary) {
throw new EntityLoadingException(String.format("Could not load %s %s from the mek cache",
newE.getChassis(), newE.getModel()));
throw new EntityLoadingException(String.format("Could not load %s from the mek cache",
shortNameRaw));
}

return summary;
Expand Down
13 changes: 4 additions & 9 deletions MekHQ/src/mekhq/gui/dialog/ChooseRefitDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

import megamek.client.ui.preferences.JWindowPreference;
import megamek.client.ui.preferences.PreferencesNode;
import megamek.codeUtilities.StringUtility;
import megamek.common.Entity;
import megamek.common.MekFileParser;
import megamek.common.MekSummary;
Expand Down Expand Up @@ -287,17 +288,11 @@ private void refitTableValueChanged() {
private void populateRefits() {
List<Refit> refits = new ArrayList<>();
Entity e = unit.getEntity();
String chassis = e.getFullChassis();
for (String model : Utilities.getAllVariants(e, campaign)) {
MekSummary summary = MekSummaryCache.getInstance().getMek(e.getFullChassis() + " " + model);
if (null == summary) {
// Attempt to deal with new naming scheme directly
summary = MekSummaryCache.getInstance()
.getMek(e.getChassis() + " (" + e.getClanChassisName() + ") " + model);
if (null == summary) {
continue;
}
}
model = StringUtility.isNullOrBlank(model) ? "" : " " + model;
try {
MekSummary summary = Utilities.retrieveUnit(chassis + model);
Entity refitEn = new MekFileParser(summary.getSourceFile(), summary.getEntryName()).getEntity();
if (null != refitEn) {
Refit r = new Refit(unit, refitEn, false, false, false);
Expand Down

0 comments on commit 9173982

Please sign in to comment.