Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed importSpriteAnimationsIntoProject for better performance and remove the 'Pack' behavior. #419

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 14 additions & 50 deletions overlap2d/src/com/uwsoft/editor/proxy/ProjectManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,10 @@ public void importSpriteAnimationsIntoProject(final Array<FileHandle> fileHandle
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")) {
Expand All @@ -425,59 +422,24 @@ public void importSpriteAnimationsIntoProject(final Array<FileHandle> 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 {
Expand All @@ -486,7 +448,9 @@ public void importSpriteAnimationsIntoProject(final Array<FileHandle> 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);
Expand Down Expand Up @@ -1219,4 +1183,4 @@ private boolean deleteDirectory(String path) {
}
return false;
}
}
}