Skip to content

Commit

Permalink
Fixes 561 and refactors how TexturePanel handles texture name components
Browse files Browse the repository at this point in the history
  • Loading branch information
neph1 committed Mar 2, 2024
1 parent d3045ca commit d6df89b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,17 @@ private void displayPreview() {
// visible for tests
protected String extractTextureName(final String property) {
final String[] textureNameComponents = property.split("\"");
if(property.endsWith("\"")) {
// texture name is last in property
return textureNameComponents[textureNameComponents.length - 1];
final int length = textureNameComponents.length;
if(property.endsWith("\"") || length == 1) {
// texture name is last in property, or it's empty
return textureNameComponents[length - 1].trim();
}
// has extra properties after name, return segment second to last
return textureNameComponents[textureNameComponents.length - 2];
return textureNameComponents[length - 2].trim();
}

// visible for tests
protected void updateFlipRepeat() {
String propertyValue = "";
final List<String> segments = new ArrayList<>();
if (flip) {
segments.add(FLIP);
Expand Down Expand Up @@ -285,7 +285,7 @@ private void texturePreviewMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FI
@Override
protected void readProperty() {
java.awt.EventQueue.invokeLater(() -> {
String prop = property.getValue();
String prop = property.getValue().trim();
if (prop.contains(FLIP)) {
flip = true;
prop = prop.replace(FLIP, EMPTY).trim();
Expand Down Expand Up @@ -334,8 +334,9 @@ public void setTexture(String name) {
textureName = "\"" + name + "\"";
}
property.setValue(textureName);
displayPreview();

updateFlipRepeat();
displayPreview();
java.awt.EventQueue.invokeLater(() -> {
fireChanged();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public TexturePanelTest() {
String textureNameWithSpaces = "\"texture name with spaces.jpg\"";
String textureNameWithSpaceAndModifier = "Flip Repeat \"texture name with spaces.jpg\"";
String textureName = "\"simple_name.jpg\"";
String textureNameWithExtraInfo = "\"simple_name.jpg\" LINEAR";
String textureNameWithExtraInfo = "Flip \"simple_name.jpg\" LINEAR";

@Test
public void testExtractTextureName() {
Expand Down

0 comments on commit d6df89b

Please sign in to comment.