Skip to content

Commit

Permalink
Merge pull request #4622 from SJuliez/fluff_images
Browse files Browse the repository at this point in the history
FluffImageHelper
  • Loading branch information
SJuliez authored Jul 16, 2023
2 parents 808d488 + f75e49f commit 210d364
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 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 @@ -206,7 +206,11 @@ private static String getImagePath(final ASCardDisplayable element) {
return DIR_NAME_PROTOMEK;
case CV:
case SV:
return DIR_NAME_VEHICLE;
if (!element.hasMovementMode("a")) {
return DIR_NAME_VEHICLE;
} // intentional fall through
case AF:
return DIR_NAME_FIGHTER;
default:
return DIR_NAME_MECH;
}
Expand Down

0 comments on commit 210d364

Please sign in to comment.