Skip to content

Commit

Permalink
Fixed crash from null background texture resource name. Fixed a test …
Browse files Browse the repository at this point in the history
…case for icon replacement.
  • Loading branch information
jeheydorn committed Dec 5, 2024
1 parent e15eb00 commit 93f97c1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/nortantis/MapSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,7 @@ public boolean equalsIgnoringEdits(MapSettings other)
* @return Piece 1 - The path Piece 2 - An optional warning message.
*/
public Tuple2<Path, String> getBackgroundImagePath()
{
{
if (backgroundTextureSource == TextureSource.File && StringUtils.isEmpty(backgroundTextureImage))
{
return new Tuple2<>(Assets.getBackgroundTextureResourcePath(backgroundTextureResource, customImagesPath),
Expand Down
4 changes: 3 additions & 1 deletion src/nortantis/swing/IconsTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -731,10 +732,11 @@ private Image createIconPreview(MapSettings settings, List<Image> images, int sc

Image previewImage;

Path backgroundImagePath = settings.getBackgroundImagePath().getFirst();
Tuple4<Image, ImageHelper.ColorifyAlgorithm, Image, ImageHelper.ColorifyAlgorithm> tuple = ThemePanel
.createBackgroundImageDisplaysImages(size, settings.backgroundRandomSeed, settings.colorizeOcean, settings.colorizeLand,
settings.generateBackground, settings.generateBackgroundFromTexture,
settings.getBackgroundImagePath().getFirst().toString());
backgroundImagePath == null ? null : backgroundImagePath.toString());
if (iconType == IconType.decorations)
{
previewImage = tuple.getFirst();
Expand Down
5 changes: 5 additions & 0 deletions src/nortantis/util/Assets.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ public static Path getBackgroundTextureResourcePath(NamedResource resource, Stri
{
return null;
}
if (StringUtils.isEmpty(resource.name) || StringUtils.isEmpty(resource.artPack))
{
// I don't know how, but in a stack trace of a crash I found that resource.name was null, so I'm adding this to be safe.
return null;
}
Path artPackPath = getArtPackPath(resource.artPack, customImagesFolder);
if (artPackPath == null)
{
Expand Down
18 changes: 9 additions & 9 deletions test/nortantis/test/MapCreatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,31 +238,31 @@ public void iconReplacementsWithMissingIconTypes()
}).getWarningMessages();

assertTrue(warnings.contains(
"The art pack 'custom' no longer has tree images, so it does not have tree the image group 'pine'. The art pack 'nortantis' will be used instead because it has the same image group folder name. These trees are not visible because they were drawn at low density, but may become visible if you change the tree height in the Effects tab."));
"The art pack 'custom' no longer has tree images, so it does not have the tree image group 'pine'. The art pack 'nortantis' will be used instead because it has the same image group folder name. These trees are not visible because they were drawn at low density, but may become visible if you change the tree height in the Effects tab."));
assertTrue(warnings.contains(
"The art pack 'custom' no longer has tree images, so it does not have tree the image group 'generated deciduous 6'. The art pack 'nortantis' will be used instead because it has tree images. These trees are not visible because they were drawn at low density, but may become visible if you change the tree height in the Effects tab."));
"The art pack 'custom' no longer has tree images, so it does not have the tree image group 'generated deciduous 6'. The art pack 'nortantis' will be used instead because it has tree images. These trees are not visible because they were drawn at low density, but may become visible if you change the tree height in the Effects tab."));
assertTrue(warnings.contains(
"Unable to find the tree image group 'generated deciduous 6' in art pack 'nortantis'. The group 'original pine' in that art pack will be used instead. These trees are not visible because they were drawn at low density, but may become visible if you change the tree height in the Effects tab."));
assertTrue(warnings.contains(
"The art pack 'custom' no longer has mountain images, so it does not have mountain the image group 'jagged'. The art pack 'nortantis' will be used instead because it has mountain images."));
"The art pack 'custom' no longer has mountain images, so it does not have the mountain image group 'jagged'. The art pack 'nortantis' will be used instead because it has mountain images."));
assertTrue(warnings.contains(
"Unable to find the mountain image group 'jagged' in art pack 'nortantis'. The group 'round' in that art pack will be used instead."));
assertTrue(warnings.contains(
"The art pack 'custom' no longer has hill images, so it does not have hill the image group 'jagged'. The art pack 'nortantis' will be used instead because it has hill images."));
"The art pack 'custom' no longer has hill images, so it does not have the hill image group 'jagged'. The art pack 'nortantis' will be used instead because it has hill images."));
assertTrue(warnings.contains(
"Unable to find the hill image group 'jagged' in art pack 'nortantis'. The group 'round' in that art pack will be used instead."));
assertTrue(warnings.contains(
"The art pack 'custom' no longer has sand images, so it does not have sand the image group 'dunes'. The art pack 'nortantis' will be used instead because it has the same image group folder name."));
"The art pack 'custom' no longer has sand images, so it does not have the sand image group 'dunes'. The art pack 'nortantis' will be used instead because it has the same image group folder name."));
assertTrue(warnings.contains(
"The art pack 'custom' no longer has hill images, so it does not have hill the image group 'sharp'. The art pack 'nortantis' will be used instead because it has the same image group folder name."));
"The art pack 'custom' no longer has hill images, so it does not have the hill image group 'sharp'. The art pack 'nortantis' will be used instead because it has the same image group folder name."));
assertTrue(warnings.contains(
"The art pack 'custom' no longer has tree images, so it does not have tree the image group 'generated deciduous 6'. The art pack 'nortantis' will be used instead because it has tree images."));
"The art pack 'custom' no longer has tree images, so it does not have the tree image group 'generated deciduous 6'. The art pack 'nortantis' will be used instead because it has tree images."));
assertTrue(warnings.contains(
"Unable to find the tree image group 'generated deciduous 6' in art pack 'nortantis'. The group 'original pine' in that art pack will be used instead."));
assertTrue(warnings.contains(
"The art pack 'custom' no longer has tree images, so it does not have tree the image group 'pine'. The art pack 'nortantis' will be used instead because it has the same image group folder name."));
"The art pack 'custom' no longer has tree images, so it does not have the tree image group 'pine'. The art pack 'nortantis' will be used instead because it has the same image group folder name."));
assertTrue(warnings.contains(
"The art pack 'custom' no longer has mountain images, so it does not have mountain the image group 'sharp'. The art pack 'nortantis' will be used instead because it has the same image group folder name."));
"The art pack 'custom' no longer has mountain images, so it does not have the mountain image group 'sharp'. The art pack 'nortantis' will be used instead because it has the same image group folder name."));
assertTrue(warnings.contains(
"The art pack 'custom' no longer has decoration images, so it does not have the icon 'compass 1 ' from decoration image group 'compasses'. The art pack 'nortantis' will be used instead because it has the same image group folder and image name."));
assertTrue(warnings.contains(
Expand Down

0 comments on commit 93f97c1

Please sign in to comment.