From ac479eb0986ee80eafe93dfe02b5fc28bbe5bc05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Fri, 17 Nov 2023 20:11:02 +0100 Subject: [PATCH] Added #2119 Bulk imported assets can also match filenames based on assigned classname, not just character id prefix --- CHANGELOG.md | 1 + .../flash/importers/ImageImporter.java | 19 ++++++++++++++++++- .../flash/importers/MovieImporter.java | 14 ++++++++++++++ .../flash/importers/ShapeImporter.java | 14 ++++++++++++++ .../flash/importers/SoundImporter.java | 16 ++++++++++++++++ .../flash/importers/SpriteImporter.java | 15 +++++++++++++++ 6 files changed, 78 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bc54509f..61ec4ef13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file. - [#2123] FLA export - show some progress info - Label that flex compiler is used (when it's enabled in settings) - [#2119] Option to export assets with names like their assigned classes via SymbolClass, without character id +- [#2119] Bulk imported assets can also match filenames based on assigned classname, not just character id prefix ### Fixed - [#2021], [#2000] Caret position in editors when using tabs and / or unicode diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ImageImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ImageImporter.java index ddc6dbc3b..8a9c9ee35 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ImageImporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ImageImporter.java @@ -235,15 +235,32 @@ public class ImageImporter extends TagImporter { } List existingFilesForImageTag = new ArrayList<>(); List existingAlphaFilesForImageTag = new ArrayList<>(); + List classNameExpectedFileNames = new ArrayList<>(); + for (String className : imageTag.getClassNames()) { + classNameExpectedFileNames.add(Helper.makeFileName(className)); + } - for (File f : allFiles) { + for (File f : allFiles) { if (f.getName().startsWith("" + characterId + ".") || f.getName().startsWith("" + characterId + "_")) { existingFilesForImageTag.add(f); + } else { + String nameNoExt = f.getName(); + if (nameNoExt.contains(".")) { + nameNoExt = nameNoExt.substring(0, nameNoExt.lastIndexOf(".")); + } + if (classNameExpectedFileNames.contains(nameNoExt)) { + existingFilesForImageTag.add(f); + } } } for (File f : alphaFiles) { if (f.getName().startsWith("" + characterId + ".") || f.getName().startsWith("" + characterId + "_")) { existingAlphaFilesForImageTag.add(f); + } else { + String nameNoExt = f.getName().substring(0, f.getName().length() - ".alpha.png".length()); + if (classNameExpectedFileNames.contains(nameNoExt)) { + existingAlphaFilesForImageTag.add(f); + } } } existingFilesForImageTag.sort(new Comparator() { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/MovieImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/MovieImporter.java index 77dcd6384..123c09482 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/MovieImporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/MovieImporter.java @@ -77,9 +77,23 @@ public class MovieImporter { if (tag instanceof DefineVideoStreamTag) { DefineVideoStreamTag movieTag = (DefineVideoStreamTag) tag; List existingFilesForMovieTag = new ArrayList<>(); + + List classNameExpectedFileNames = new ArrayList<>(); + for (String className : movieTag.getClassNames()) { + classNameExpectedFileNames.add(Helper.makeFileName(className)); + } + for (File f : allFiles) { if (f.getName().startsWith("" + characterId + ".") || f.getName().startsWith("" + characterId + "_")) { existingFilesForMovieTag.add(f); + } else { + String nameNoExt = f.getName(); + if (nameNoExt.contains(".")) { + nameNoExt = nameNoExt.substring(0, nameNoExt.lastIndexOf(".")); + } + if (classNameExpectedFileNames.contains(nameNoExt)) { + existingFilesForMovieTag.add(f); + } } } existingFilesForMovieTag.sort(new Comparator() { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ShapeImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ShapeImporter.java index c1248ec5d..0fbf29749 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ShapeImporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ShapeImporter.java @@ -215,9 +215,23 @@ public class ShapeImporter { if (tag instanceof ShapeTag) { ShapeTag shapeTag = (ShapeTag) tag; List existingFilesForShapeTag = new ArrayList<>(); + + List classNameExpectedFileNames = new ArrayList<>(); + for (String className : shapeTag.getClassNames()) { + classNameExpectedFileNames.add(Helper.makeFileName(className)); + } + for (File f : allFiles) { if (f.getName().startsWith("" + characterId + ".") || f.getName().startsWith("" + characterId + "_")) { existingFilesForShapeTag.add(f); + } else { + String nameNoExt = f.getName(); + if (nameNoExt.contains(".")) { + nameNoExt = nameNoExt.substring(0, nameNoExt.lastIndexOf(".")); + } + if (classNameExpectedFileNames.contains(nameNoExt)) { + existingFilesForShapeTag.add(f); + } } } existingFilesForShapeTag.sort(new Comparator() { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/SoundImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/SoundImporter.java index 879306842..2aad805ef 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/SoundImporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/SoundImporter.java @@ -515,9 +515,25 @@ public class SoundImporter { for (SoundTag tag : soundTags) { int characterId = tag.getCharacterId(); List existingFilesForSoundTag = new ArrayList<>(); + + List classNameExpectedFileNames = new ArrayList<>(); + if (tag instanceof CharacterTag) { + for (String className : ((CharacterTag) tag).getClassNames()) { + classNameExpectedFileNames.add(Helper.makeFileName(className)); + } + } + for (File f : allFiles) { if (f.getName().startsWith("" + characterId + ".") || f.getName().startsWith("" + characterId + "_")) { existingFilesForSoundTag.add(f); + } else { + String nameNoExt = f.getName(); + if (nameNoExt.contains(".")) { + nameNoExt = nameNoExt.substring(0, nameNoExt.lastIndexOf(".")); + } + if (classNameExpectedFileNames.contains(nameNoExt)) { + existingFilesForSoundTag.add(f); + } } } existingFilesForSoundTag.sort(new Comparator() { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/SpriteImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/SpriteImporter.java index 4a66b6d55..79d77b56e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/SpriteImporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/SpriteImporter.java @@ -27,6 +27,7 @@ import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.CharacterIdTag; import com.jpexs.decompiler.flash.tags.base.CharacterTag; import com.jpexs.decompiler.flash.tags.base.PlaceObjectTypeTag; +import com.jpexs.helpers.Helper; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.File; @@ -173,9 +174,23 @@ public class SpriteImporter { if (tag instanceof DefineSpriteTag) { DefineSpriteTag spriteTag = (DefineSpriteTag) tag; List existingFilesForSpriteTag = new ArrayList<>(); + + List classNameExpectedFileNames = new ArrayList<>(); + for (String className : spriteTag.getClassNames()) { + classNameExpectedFileNames.add(Helper.makeFileName(className)); + } + for (File f : allFiles) { if (f.getName().startsWith("" + characterId + ".") || f.getName().startsWith("" + characterId + "_")) { existingFilesForSpriteTag.add(f); + } else { + String nameNoExt = f.getName(); + if (nameNoExt.contains(".")) { + nameNoExt = nameNoExt.substring(0, nameNoExt.lastIndexOf(".")); + } + if (classNameExpectedFileNames.contains(nameNoExt)) { + existingFilesForSpriteTag.add(f); + } } } existingFilesForSpriteTag.sort(new Comparator() {