Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup related to new naming scheme and refactoring, fixes refits to blank model names. #5031

Merged
merged 1 commit into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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