Skip to content

Commit

Permalink
FluffImageHelper.java: Corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
SJuliez committed Jul 13, 2023
1 parent 32d4e90 commit f9b4e5d
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions megamek/src/megamek/client/ui/swing/util/FluffImageHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import megamek.common.*;
import megamek.common.alphaStrike.ASCardDisplayable;
import megamek.common.alphaStrike.ASUnitType;
import megamek.common.annotations.Nullable;
import megamek.common.util.fileUtils.MegaMekFile;

Expand Down Expand Up @@ -76,17 +77,12 @@ protected static Image loadFluffImage(final Entity unit) {

/**
* Attempt to load a fluff image by combining elements of type and name.
* @param unit The unit.
* @param entity The unit.
* @return An image or {@code null}.
*/
public static @Nullable Image loadFluffImageHeuristic(final Entity unit) {
Image fluff = null;
var file = new MegaMekFile(Configuration.fluffImagesDir(), getImagePath(unit)).getFile();
File fluff_image_file = findFluffImage(file, unit.getModel(), unit.getChassis());
if (fluff_image_file != null) {
fluff = new ImageIcon(fluff_image_file.toString()).getImage();
}
return fluff;
public static @Nullable Image loadFluffImageHeuristic(final Entity entity) {
var path = new MegaMekFile(Configuration.fluffImagesDir(), getImagePath(entity));
return loadFluffImageHeuristic(path, entity.getModel(), entity.getChassis());
}

/**
Expand All @@ -95,13 +91,17 @@ protected static Image loadFluffImage(final Entity unit) {
* @return An image or null
*/
public static @Nullable Image loadFluffImageHeuristic(final ASCardDisplayable element) {
Image fluff = null;
var file = new MegaMekFile(Configuration.fluffImagesDir(), getImagePath(element)).getFile();
File fluff_image_file = findFluffImage(file, element.getModel(), element.getChassis());
var path = new MegaMekFile(Configuration.fluffImagesDir(), getImagePath(element));
return loadFluffImageHeuristic(path, element.getModel(), element.getChassis());
}

private static @Nullable Image loadFluffImageHeuristic(MegaMekFile path, String model, String chassis) {
File fluff_image_file = findFluffImage(path.getFile(), model, chassis);
if (fluff_image_file != null) {
fluff = new ImageIcon(fluff_image_file.toString()).getImage();
return new ImageIcon(fluff_image_file.toString()).getImage();
} else {
return null;
}
return fluff;
}

/**
Expand Down Expand Up @@ -184,6 +184,9 @@ protected static Image loadFluffImage(final Entity unit) {
private FluffImageHelper() { }

private static String getImagePath(final ASCardDisplayable element) {
if ((element.getASUnitType() == ASUnitType.SV) && (element.hasMovementMode("a"))) {
return DIR_NAME_CONVFIGHTER;
}
switch (element.getASUnitType()) {
case WS:
return DIR_NAME_WARSHIP;
Expand All @@ -207,6 +210,8 @@ private static String getImagePath(final ASCardDisplayable element) {
case CV:
case SV:
return DIR_NAME_VEHICLE;
case AF:
return DIR_NAME_FIGHTER;
default:
return DIR_NAME_MECH;
}
Expand Down

0 comments on commit f9b4e5d

Please sign in to comment.