Skip to content

Commit b3cf6b0

Browse files
committed
getAnyExtensionTexture supports DDS files
1 parent 296e4d8 commit b3cf6b0

1 file changed

Lines changed: 31 additions & 11 deletions

File tree

core/src/com/etheller/warsmash/util/ImageUtils.java

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import java.nio.Buffer;
1212
import java.nio.ByteBuffer;
1313
import java.nio.ByteOrder;
14+
import java.util.LinkedList;
15+
import java.util.List;
1416

1517
import javax.imageio.ImageIO;
1618

@@ -31,20 +33,38 @@ public final class ImageUtils {
3133
public static final String DEFAULT_ICON_PATH = "ReplaceableTextures\\CommandButtons\\BTNTemp.blp";
3234

3335
public static Texture getAnyExtensionTexture(final DataSource dataSource, final String path) {
34-
if (dataSource.has(path)) {
35-
BufferedImage image;
36-
try {
37-
final AnyExtensionImage imageInfo = getAnyExtensionImageFixRGB(dataSource, path, "texture");
38-
image = imageInfo.getImageData();
39-
if (image != null) {
40-
return ImageUtils.getTexture(image, imageInfo.isNeedsSRGBFix());
36+
final List<String> paths = new LinkedList<>(List.of(path));
37+
38+
if (path.length() >= 4) {
39+
final String extension = path.substring(path.length() - 4).toLowerCase();
40+
41+
if (!".dds".equals(extension)) {
42+
// Reforged has TeamColors etc. as DDS files only.
43+
paths.add(path.substring(0, path.length() - 4) + ".dds");
44+
}
45+
46+
if (!".blp".equals(extension)) {
47+
paths.add(path.substring(0, path.length() - 4) + ".blp");
48+
}
49+
}
50+
51+
for (String p : paths) {
52+
if (dataSource.has(p)) {
53+
BufferedImage image;
54+
try {
55+
final AnyExtensionImage imageInfo = getAnyExtensionImageFixRGB(dataSource, p, "texture");
56+
image = imageInfo.getImageData();
57+
if (image != null) {
58+
return ImageUtils.getTexture(image, imageInfo.isNeedsSRGBFix());
59+
}
60+
} catch (final IOException e) {
61+
return null;
4162
}
42-
} catch (final IOException e) {
43-
return null;
4463
}
45-
} else {
46-
System.err.println("Missing texture " + path);
4764
}
65+
66+
System.err.println("Missing texture " + path + " tried paths: " + String.join(",", paths));
67+
4868
return null;
4969
}
5070

0 commit comments

Comments
 (0)