Skip to content

Commit 1d5c9d0

Browse files
committed
Fix bug when scaling atlases with subfolders.
1 parent b6bb03b commit 1d5c9d0

File tree

2 files changed

+37
-30
lines changed

2 files changed

+37
-30
lines changed

adventure-editor/src/main/java/com/bladecoder/engineeditor/common/DesktopUtils.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ public class DesktopUtils {
3434
public static void browse(Component parent, String uri) {
3535
boolean error = false;
3636

37-
if (Desktop.isDesktopSupported()
38-
&& Desktop.getDesktop().isSupported(Action.BROWSE)) {
37+
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Action.BROWSE)) {
3938
try {
4039
Desktop.getDesktop().browse(new URI(uri));
4140
} catch (URISyntaxException ex) {
@@ -68,8 +67,13 @@ public static void removeDir(String dir) throws IOException {
6867
File files[] = f.listFiles();
6968

7069
if (files != null)
71-
for (File f2 : files)
72-
Files.delete(f2.toPath());
70+
for (File f2 : files) {
71+
if (f2.isDirectory()) {
72+
removeDir(f2.getAbsolutePath());
73+
} else {
74+
Files.delete(f2.toPath());
75+
}
76+
}
7377

7478
Files.deleteIfExists(f.toPath());
7579
}

adventure-editor/src/main/java/com/bladecoder/engineeditor/ui/CreateResolutionDialog.java

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.io.File;
1919
import java.io.IOException;
2020

21+
import com.badlogic.gdx.scenes.scene2d.Stage;
2122
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
2223
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
2324
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent;
@@ -37,76 +38,78 @@ public class CreateResolutionDialog extends EditDialog {
3738
private static final String INFO = "Create a new resolution. Scale all atlases and images of the game.";
3839

3940
private InputPanel scale;
40-
41+
4142
protected ChangeListener listener;
42-
43+
4344
String atlasDir = Ctx.project.getAssetPath() + Project.ATLASES_PATH;
4445
String uiDir = Ctx.project.getAssetPath() + Project.UI_PATH;
4546
String imageDir = Ctx.project.getAssetPath() + Project.IMAGE_PATH;
4647

4748
public CreateResolutionDialog(Skin skin) {
4849
super("CREATE RESOLUTION", skin);
49-
50-
scale = InputPanelFactory.createInputPanel(skin, "Scale",
51-
"Scale relative to the world resolution", Param.Type.FLOAT, true);
50+
51+
scale = InputPanelFactory.createInputPanel(skin, "Scale", "Scale relative to the world resolution",
52+
Param.Type.FLOAT, true);
5253

5354
addInputPanel(scale);
54-
55+
5556
setInfo(INFO);
5657
}
5758

5859
@Override
5960
protected void ok() {
60-
61-
Message.showMsg(getStage(), "Creating resolution...", true);
62-
61+
62+
final Stage stage = getStage();
63+
64+
Message.showMsg(stage, "Creating resolution...", true);
65+
6366
Timer.schedule(new Task() {
6467
@Override
65-
public void run() {
68+
public void run() {
6669
createResolution();
6770

68-
String msg = scaleImages();
69-
70-
if(listener != null)
71+
String msg = scaleImages();
72+
73+
if (listener != null)
7174
listener.changed(new ChangeEvent(), CreateResolutionDialog.this);
72-
75+
7376
Message.hideMsg();
74-
75-
if(msg != null)
76-
Message.showMsgDialog(getStage(), "Error creating resolution", msg);
77+
78+
if (msg != null)
79+
Message.showMsgDialog(stage, "Error creating resolution", msg);
7780
}
78-
},1);
81+
}, 1);
7982
}
80-
83+
8184
private void createResolution() {
8285
// float s = Float.parseFloat(scale.getText());
8386
// String prefix = (int)(Ctx.project.getWorld().getWidth() * s) + "_" + (int)(Ctx.project.getWorld().getHeight() * s);
8487
String prefix = scale.getText().trim();
85-
88+
8689
new File(atlasDir + "/" + prefix).mkdir();
8790
new File(uiDir + "/" + prefix).mkdir();
88-
new File(imageDir + "/" + prefix).mkdir();
91+
new File(imageDir + "/" + prefix).mkdir();
8992
}
9093

9194
private String scaleImages() {
92-
95+
9396
float s = Float.parseFloat(scale.getText());
9497
// String prefix = (int)(Ctx.project.getWorld().getWidth() * s) + "_" + (int)(Ctx.project.getWorld().getHeight() * s);
9598
String prefix = scale.getText().trim();
96-
99+
97100
// COPY ASSETS FROM WORLD RESOLUTION SCALED
98101
String wPrefix = Ctx.project.getResDir();
99-
102+
100103
try {
101104
ImageUtils.scaleDirFiles(new File(uiDir + "/" + wPrefix), new File(uiDir + "/" + prefix), s);
102105
ImageUtils.scaleDirFiles(new File(imageDir + "/" + wPrefix), new File(imageDir + "/" + prefix), s);
103-
106+
104107
ImageUtils.scaleDirAtlases(new File(atlasDir + "/" + wPrefix), new File(atlasDir + "/" + prefix), s);
105108
ImageUtils.scaleDirAtlases(new File(uiDir + "/" + wPrefix), new File(uiDir + "/" + prefix), s);
106109
} catch (IOException e) {
107110
return e.getMessage();
108111
}
109-
112+
110113
return null;
111114
}
112115

0 commit comments

Comments
 (0)