From d9353fc1d82e5083a8eba9f7f44064739099e824 Mon Sep 17 00:00:00 2001 From: cf-Botan Date: Tue, 15 Nov 2016 16:41:59 +0100 Subject: [PATCH 1/2] Update ProjectManager.java Fixed path issues when used *.png list on sprite import --- .../uwsoft/editor/proxy/ProjectManager.java | 65 +++++-------------- 1 file changed, 16 insertions(+), 49 deletions(-) diff --git a/overlap2d/src/com/uwsoft/editor/proxy/ProjectManager.java b/overlap2d/src/com/uwsoft/editor/proxy/ProjectManager.java index 7dedb1161..94b9ef12f 100755 --- a/overlap2d/src/com/uwsoft/editor/proxy/ProjectManager.java +++ b/overlap2d/src/com/uwsoft/editor/proxy/ProjectManager.java @@ -403,7 +403,7 @@ public File importExternalAnimationIntoProject(FileHandle animationFileSource) { public void importSpriteAnimationsIntoProject(final Array fileHandles, ProgressHandler progressHandler) { - if (fileHandles == null) { + if (fileHandles == null) { return; } handler = progressHandler; @@ -413,7 +413,7 @@ public void importSpriteAnimationsIntoProject(final Array fileHandle executor.execute(() -> { String newAnimName = null; - + String rawFileName = fileHandles.get(0).name(); String fileExtension = FilenameUtils.getExtension(rawFileName); if (fileExtension.equals("png")) { @@ -425,59 +425,24 @@ public void importSpriteAnimationsIntoProject(final Array fileHandle String fileNameWithoutExt = FilenameUtils.removeExtension(rawFileName); String fileNameWithoutFrame = fileNameWithoutExt.replaceAll("\\d*$", ""); - boolean noFileNameWithoutFrame = false; if (Objects.equals(fileNameWithoutFrame, "")) { fileNameWithoutFrame = fileHandles.get(0).parent().name(); - noFileNameWithoutFrame = true; } String targetPath = currentProjectPath + "/assets/orig/sprite-animations" + File.separator + fileNameWithoutFrame; - - for (FileHandle file : fileHandles) { - File src = file.file(); - - String destName; - if (noFileNameWithoutFrame) { - destName = targetPath + File.separator + fileNameWithoutFrame + src.getName(); - } else { - destName = targetPath + File.separator + src.getName(); - } - - File dest = new File(destName); - try { - FileUtils.copyFile(src, dest); - } catch (IOException e) { - e.printStackTrace(); - } - } - - FileHandle pngsDir = new FileHandle(targetPath); - for (FileHandle entry : pngsDir.list(Overlap2DUtils.PNG_FILTER)) { - texturePacker.addImage(entry.file()); - } - - String packName = "Pack"; - targetPath = targetPath + packName; - File targetDir = new File(targetPath); - if (targetDir.exists()) { - try { - FileUtils.deleteDirectory(targetDir); - } catch (IOException e) { - e.printStackTrace(); - } + if (targetDir.exists()) + { + JOptionPane.showMessageDialog(null, "Animation already exists!", "Error", JOptionPane.ERROR_MESSAGE); + return; } - - texturePacker.pack(targetDir, fileNameWithoutFrame + packName); - - //delete newly created directory and images - try { - FileUtils.deleteDirectory(pngsDir.file()); - } catch (IOException e) { - e.printStackTrace(); + for (FileHandle file : fileHandles) { + File src = file.file(); + texturePacker.addImage(src); } - - newAnimName = fileNameWithoutFrame + packName; + + texturePacker.pack(targetDir, fileNameWithoutFrame); + newAnimName = fileNameWithoutFrame; } else { for (FileHandle fileHandle : fileHandles) { try { @@ -486,7 +451,9 @@ public void importSpriteAnimationsIntoProject(final Array fileHandle String targetPath = currentProjectPath + "/assets/orig/sprite-animations" + File.separator + fileNameWithoutExt; File targetDir = new File(targetPath); if (targetDir.exists()) { - FileUtils.deleteDirectory(targetDir); + //FileUtils.deleteDirectory(targetDir); + JOptionPane.showMessageDialog(null, "Animation already exists!", "Error", JOptionPane.ERROR_MESSAGE); + return; } for (File img : imgs) { FileUtils.copyFileToDirectory(img, targetDir); @@ -1219,4 +1186,4 @@ private boolean deleteDirectory(String path) { } return false; } -} \ No newline at end of file +} From f85cdca22cc6894f3379cd7a5398c720006586a1 Mon Sep 17 00:00:00 2001 From: cf-Botan Date: Tue, 15 Nov 2016 16:44:55 +0100 Subject: [PATCH 2/2] Update ProjectManager.java Fixed path issues when used *.png list on sprite import --- overlap2d/src/com/uwsoft/editor/proxy/ProjectManager.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/overlap2d/src/com/uwsoft/editor/proxy/ProjectManager.java b/overlap2d/src/com/uwsoft/editor/proxy/ProjectManager.java index 94b9ef12f..b2fa8f662 100755 --- a/overlap2d/src/com/uwsoft/editor/proxy/ProjectManager.java +++ b/overlap2d/src/com/uwsoft/editor/proxy/ProjectManager.java @@ -403,17 +403,14 @@ public File importExternalAnimationIntoProject(FileHandle animationFileSource) { public void importSpriteAnimationsIntoProject(final Array fileHandles, ProgressHandler progressHandler) { - if (fileHandles == null) { + if (fileHandles == null) { return; } handler = progressHandler; - ExecutorService executor = Executors.newSingleThreadExecutor(); executor.execute(() -> { - String newAnimName = null; - String rawFileName = fileHandles.get(0).name(); String fileExtension = FilenameUtils.getExtension(rawFileName); if (fileExtension.equals("png")) {