Fixed an issue with J3MLoader thinking certain texture path patterns with new texture options still looked like old style and hence ignoring new options and getting the texture path wrong.

This commit is contained in:
Daniel Johansson 2016-03-07 16:38:43 +00:00
parent e530fa644b
commit 9f9cb824cd
3 changed files with 22 additions and 5 deletions

View File

@ -169,9 +169,23 @@ public class J3MLoader implements AssetLoader {
return matchList;
}
private boolean isTexturePathDeclaredTheTraditionalWay(final int numberOfValues, final int numberOfTextureOptions, final String texturePath) {
return (numberOfValues > 1 && (texturePath.startsWith("Flip Repeat ") || texturePath.startsWith("Flip ") ||
texturePath.startsWith("Repeat ") || texturePath.startsWith("Repeat Flip "))) || numberOfTextureOptions == 0;
private boolean isTexturePathDeclaredTheTraditionalWay(final List<TextureOptionValue> optionValues, final String texturePath) {
final boolean startsWithOldStyle = texturePath.startsWith("Flip Repeat ") || texturePath.startsWith("Flip ") ||
texturePath.startsWith("Repeat ") || texturePath.startsWith("Repeat Flip ");
if (!startsWithOldStyle) {
return false;
}
if (optionValues.size() == 1 && (optionValues.get(0).textureOption == TextureOption.Flip || optionValues.get(0).textureOption == TextureOption.Repeat)) {
return true;
} else if (optionValues.size() == 2 && optionValues.get(0).textureOption == TextureOption.Flip && optionValues.get(1).textureOption == TextureOption.Repeat) {
return true;
} else if (optionValues.size() == 2 && optionValues.get(0).textureOption == TextureOption.Repeat && optionValues.get(1).textureOption == TextureOption.Flip) {
return true;
}
return false;
}
private Texture parseTextureType(final VarType type, final String value) {
@ -187,7 +201,7 @@ public class J3MLoader implements AssetLoader {
String texturePath = value.trim();
// If there are no valid "new" texture options specified but the path is split into several parts, lets parse the old way.
if (isTexturePathDeclaredTheTraditionalWay(textureValues.size(), textureOptionValues.size(), texturePath)) {
if (isTexturePathDeclaredTheTraditionalWay(textureOptionValues, texturePath)) {
boolean flipY = false;
if (texturePath.startsWith("Flip Repeat ") || texturePath.startsWith("Repeat Flip ")) {

View File

@ -80,6 +80,7 @@ public class J3MLoaderTest {
final Texture textureMin = Mockito.mock(Texture.class);
final Texture textureMag = Mockito.mock(Texture.class);
final Texture textureCombined = Mockito.mock(Texture.class);
final Texture textureLooksLikeOldStyle = Mockito.mock(Texture.class);
final TextureKey textureKeyNoParameters = setupMockForTexture("Empty", "empty.png", false, textureNoParameters);
final TextureKey textureKeyFlip = setupMockForTexture("Flip", "flip.png", true, textureFlip);
@ -88,6 +89,7 @@ public class J3MLoaderTest {
setupMockForTexture("Min", "min.png", false, textureMin);
setupMockForTexture("Mag", "mag.png", false, textureMag);
setupMockForTexture("Combined", "combined.png", true, textureCombined);
setupMockForTexture("LooksLikeOldStyle", "oldstyle.png", true, textureLooksLikeOldStyle);
j3MLoader.load(assetInfo);

View File

@ -6,6 +6,7 @@ Material Test : matdef.j3md {
Min: MinTrilinear "min.png"
Mag: MagBilinear "mag.png"
RepeatAxis: WrapRepeat_T "repeat-axis.png"
Combined: MagNearest MinBilinearNoMipMaps Flip WrapRepeat "combined.png"
Combined: Flip MagNearest MinBilinearNoMipMaps WrapRepeat "combined.png"
LooksLikeOldStyle: Flip WrapRepeat "oldstyle.png"
}
}