mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-29 19:35:53 +00:00
Added #2057 Show all assigned AS linkage classes in the item name (instead just one)
This commit is contained in:
@@ -397,7 +397,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
|
||||
private String charset = "UTF-8";
|
||||
|
||||
@Internal
|
||||
private Map<Integer, String> importedTagToClassMapping = new HashMap<>();
|
||||
private Map<Integer, LinkedHashSet<String>> importedTagToClassesMapping = new HashMap<>();
|
||||
|
||||
@Internal
|
||||
private Map<Integer, String> importedTagToExportNameMapping = new HashMap<>();
|
||||
@@ -800,7 +800,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
|
||||
}
|
||||
for (Tag t : getTags()) {
|
||||
if (t instanceof FontTag) {
|
||||
if (fontClass.equals(((FontTag) t).getClassName())) {
|
||||
if (((FontTag) t).getClassNames().contains(fontClass)) {
|
||||
return (FontTag) t;
|
||||
}
|
||||
}
|
||||
@@ -1627,12 +1627,12 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
|
||||
if (cht instanceof CharacterTag) {
|
||||
importedCharacters.add((CharacterTag) chtCopy);
|
||||
String exportName = ((CharacterTag) cht).getExportName();
|
||||
String className = ((CharacterTag) cht).getClassName();
|
||||
LinkedHashSet<String> classNames = ((CharacterTag) cht).getClassNames();
|
||||
if (exportName != null) {
|
||||
importedTagToExportNameMapping.put(importedId, exportName);
|
||||
}
|
||||
if (className != null) {
|
||||
importedTagToClassMapping.put(importedId, className);
|
||||
if (!classNames.isEmpty()) {
|
||||
importedTagToClassesMapping.put(importedId, classNames);
|
||||
}
|
||||
} else {
|
||||
chtCopy.setTimelined(this);
|
||||
@@ -1668,12 +1668,12 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
|
||||
if (cht instanceof CharacterTag) {
|
||||
importedCharacters.add((CharacterTag) chtCopy);
|
||||
String exportName = ((CharacterTag) cht).getExportName();
|
||||
String className = ((CharacterTag) cht).getClassName();
|
||||
LinkedHashSet<String> classNames = ((CharacterTag) cht).getClassNames();
|
||||
if (exportName != null) {
|
||||
importedTagToExportNameMapping.put(importedId, exportName);
|
||||
}
|
||||
if (className != null) {
|
||||
importedTagToClassMapping.put(importedId, className);
|
||||
if (!classNames.isEmpty()) {
|
||||
importedTagToClassesMapping.put(importedId, classNames);
|
||||
}
|
||||
} else {
|
||||
chtCopy.setSwf(this);
|
||||
@@ -1905,14 +1905,26 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
|
||||
}
|
||||
|
||||
public void assignClassesToSymbols() {
|
||||
HashMap<Integer, String> classes = new HashMap<>(importedTagToClassMapping);
|
||||
HashMap<Integer, LinkedHashSet<String>> classes = new HashMap<>();
|
||||
|
||||
for (int ch : importedTagToClassesMapping.keySet()) {
|
||||
classes.put(ch, new LinkedHashSet<>(importedTagToClassesMapping.get(ch)));
|
||||
}
|
||||
|
||||
Set<String> uniqueClasses = new HashSet<>();
|
||||
for (Tag t : getTags()) {
|
||||
if (t instanceof SymbolClassTag) {
|
||||
SymbolClassTag sct = (SymbolClassTag) t;
|
||||
for (int i = 0; i < sct.tags.size(); i++) {
|
||||
if ((!classes.containsKey(sct.tags.get(i))) && (!classes.containsValue(sct.names.get(i)))) {
|
||||
classes.put(sct.tags.get(i), sct.names.get(i));
|
||||
for (int i = 0; i < sct.tags.size(); i++) {
|
||||
if (!classes.containsKey(sct.tags.get(i))) {
|
||||
classes.put(sct.tags.get(i), new LinkedHashSet<>());
|
||||
}
|
||||
if (uniqueClasses.contains(sct.names.get(i))) {
|
||||
//when two characters have assigned same class, only first assignment is valid
|
||||
continue;
|
||||
}
|
||||
uniqueClasses.add(sct.names.get(i));
|
||||
classes.get(sct.tags.get(i)).add(sct.names.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1924,14 +1936,16 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
|
||||
continue;
|
||||
}
|
||||
if (classes.containsKey(ct.getCharacterId())) {
|
||||
ct.setClassName(classes.get(ct.getCharacterId()));
|
||||
ct.setClassNames(classes.get((Integer)ct.getCharacterId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
classToCharacter.clear();
|
||||
for (int ch : classes.keySet()) {
|
||||
classToCharacter.put(classes.get(ch), ch);
|
||||
for (String cls:classes.get(ch)) {
|
||||
classToCharacter.put(cls, ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.jpexs.decompiler.flash.tags.DefineScalingGridTag;
|
||||
import com.jpexs.decompiler.flash.tags.Tag;
|
||||
import com.jpexs.helpers.ByteArrayRange;
|
||||
import com.jpexs.helpers.Helper;
|
||||
import java.util.LinkedHashSet;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -28,18 +29,22 @@ import com.jpexs.helpers.Helper;
|
||||
*/
|
||||
public abstract class CharacterTag extends Tag implements CharacterIdTag {
|
||||
|
||||
protected String className;
|
||||
protected LinkedHashSet<String> classNames = new LinkedHashSet<>();
|
||||
|
||||
public CharacterTag(SWF swf, int id, String name, ByteArrayRange data) {
|
||||
super(swf, id, name, data);
|
||||
}
|
||||
|
||||
public void setClassName(String className) {
|
||||
this.className = className;
|
||||
public void setClassNames(LinkedHashSet<String> classNames) {
|
||||
this.classNames = new LinkedHashSet<>(classNames);
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return className;
|
||||
public LinkedHashSet<String> getClassNames() {
|
||||
return new LinkedHashSet<>(classNames);
|
||||
}
|
||||
|
||||
public void addClassName(String className) {
|
||||
classNames.add(className);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,8 +53,8 @@ public abstract class CharacterTag extends Tag implements CharacterIdTag {
|
||||
if (exportName != null) {
|
||||
nameAppend = ": " + Helper.escapePCodeString(exportName);
|
||||
}
|
||||
if (className != null) {
|
||||
nameAppend = ": " + Helper.escapePCodeString(className);
|
||||
if (!classNames.isEmpty()) {
|
||||
nameAppend = ": " + Helper.joinEscapePCodeString(", ", classNames);
|
||||
}
|
||||
return tagName + " (" + getCharacterId() + nameAppend + ")";
|
||||
}
|
||||
@@ -57,11 +62,11 @@ public abstract class CharacterTag extends Tag implements CharacterIdTag {
|
||||
@Override
|
||||
public String getExportFileName() {
|
||||
String result = super.getExportFileName();
|
||||
return result + "_" + getCharacterId() + (exportName != null ? "_" + exportName : "") + (className != null ? "_" + className : "");
|
||||
return result + "_" + getCharacterId() + (exportName != null ? "_" + exportName : "") + (!classNames.isEmpty() ? "_" + String.join("___",classNames) : "");
|
||||
}
|
||||
|
||||
public String getCharacterExportFileName() {
|
||||
return getCharacterId() + (exportName != null ? "_" + exportName : "") + (className != null ? "_" + className : "");
|
||||
return getCharacterId() + (exportName != null ? "_" + exportName : "") + (!classNames.isEmpty() ? "_" + String.join("___",classNames) : "");
|
||||
}
|
||||
|
||||
protected String exportName;
|
||||
|
||||
@@ -211,8 +211,8 @@ public abstract class FontTag extends DrawableTag implements AloneTag {
|
||||
if (exportName != null) {
|
||||
nameAppendList.add(exportName);
|
||||
}
|
||||
if (className != null) {
|
||||
nameAppendList.add(Helper.escapePCodeString(className));
|
||||
if (!classNames.isEmpty()) {
|
||||
nameAppendList.add(Helper.joinEscapePCodeString(", ", classNames));
|
||||
}
|
||||
String fontName = getFontNameIntag();
|
||||
if (fontName != null) {
|
||||
|
||||
@@ -1288,7 +1288,7 @@ public class Timeline {
|
||||
exporter.endGroup();
|
||||
}
|
||||
Matrix mat = Matrix.getTranslateInstance(rect.xMin, rect.yMin).preConcatenate(new Matrix(layer.matrix));
|
||||
exporter.addUse(mat, boundRect, assetName, layer.instanceName, scalingGrid == null ? null : scalingGrid.splitter, String.valueOf(drawable.getCharacterId()), drawable.getClassName());
|
||||
exporter.addUse(mat, boundRect, assetName, layer.instanceName, scalingGrid == null ? null : scalingGrid.splitter, String.valueOf(drawable.getCharacterId()), String.join("___", drawable.getClassNames()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3308,16 +3308,26 @@ public class XFLConverter {
|
||||
|
||||
private static Map<Integer, String> getCharacterClasses(ReadOnlyTagList tags) {
|
||||
Map<Integer, String> ret = new HashMap<>();
|
||||
Set<Integer> multipleClassesCharacters = new HashSet<>();
|
||||
for (Tag t : tags) {
|
||||
if (t instanceof SymbolClassTag) {
|
||||
SymbolClassTag sc = (SymbolClassTag) t;
|
||||
for (int i = 0; i < sc.tags.size(); i++) {
|
||||
if (!ret.containsKey(sc.tags.get(i)) && !ret.containsValue(sc.names.get(i))) {
|
||||
ret.put(sc.tags.get(i), sc.names.get(i));
|
||||
} else if (ret.containsKey(sc.tags.get(i))){
|
||||
multipleClassesCharacters.add(sc.tags.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i: multipleClassesCharacters) {
|
||||
ret.remove(i);
|
||||
}
|
||||
|
||||
//TODO: handle multiple classes assigned to same character (Can happen when Embed tag used with identical file)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -241,6 +241,17 @@ public class Helper {
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
public static String joinEscapePCodeString(String glue, Collection<String> collection) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String s:collection) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append(glue);
|
||||
}
|
||||
sb.append(escapePCodeString(s));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes string by adding backslashes
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user