Fixed Copy/Move with dependencies order of tags

BUTTONRECORD/CLIPACTIONRECORD swf / tag set
This commit is contained in:
Jindra Petřík
2022-11-11 21:24:36 +01:00
parent d0936e1a46
commit 968fd92cd2
8 changed files with 80 additions and 23 deletions

View File

@@ -49,6 +49,7 @@ import java.io.IOException;
import java.io.OutputStream;
import java.io.Serializable;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
@@ -643,23 +644,34 @@ public abstract class Tag implements NeedsCharacters, Exportable, Serializable {
}
public void getNeededCharactersDeep(Set<Integer> needed) {
Set<Integer> visited = new HashSet<>();
Set<Integer> needed2 = new LinkedHashSet<>();
getNeededCharacters(needed2);
List<Integer> needed3 = new ArrayList<>(needed2);
while (visited.size() != needed2.size()) {
for (int characterId : needed2) {
if (!visited.contains(characterId)) {
visited.add(characterId);
if (swf.getCharacters().containsKey(characterId)) {
swf.getCharacter(characterId).getNeededCharacters(needed2);
break;
for (int i = 0; i < needed3.size(); i++) {
int characterId = needed3.get(i);
if (swf.getCharacters().containsKey(characterId)) {
Set<Integer> needed4 = new LinkedHashSet<>();
CharacterTag character = swf.getCharacter(characterId);
character.getNeededCharacters(needed4);
List<Integer> newItems = new ArrayList<>();
for(int n : needed4) {
int index = needed3.indexOf((Integer) n);
if (index > i) {
needed3.remove(index);
}
if (!needed3.contains(n) && !newItems.contains(n)) {
newItems.add(n);
}
}
}
if (!newItems.isEmpty()) {
needed3.addAll(i, newItems);
i--;
}
}
}
for (Integer characterId : needed2) {
for (Integer characterId : needed3) {
if (swf.getCharacters().containsKey(characterId)) {
needed.add(characterId);
}

View File

@@ -192,4 +192,12 @@ public abstract class ButtonTag extends DrawableTag implements Timelined {
replaceTag(index, newTag);
}
}
@Override
public void setSwf(SWF swf, boolean deep) {
this.swf = swf;
for(BUTTONRECORD record:getRecords()) {
record.setSwfAndTag(swf, this);
}
}
}

View File

@@ -35,7 +35,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class BUTTONRECORD implements Serializable, TreeItem {
public class BUTTONRECORD implements Serializable, TreeItem, HasSwfAndTag {
@Reserved
@SWFType(value = BasicType.UB, count = 2)
@@ -149,7 +149,14 @@ public class BUTTONRECORD implements Serializable, TreeItem {
return false;
}
@Override
public ButtonTag getTag() {
return tag;
}
@Override
public void setSwfAndTag(SWF swf, Tag tag) {
this.swf = swf;
this.tag = (ButtonTag) tag;
}
}

View File

@@ -42,7 +42,7 @@ import java.util.List;
*
* @author JPEXS
*/
public class CLIPACTIONRECORD implements ASMSource, Serializable {
public class CLIPACTIONRECORD implements ASMSource, Serializable, HasSwfAndTag {
private String scriptName = "-";
private CLIPACTIONS parentClipActions;
@@ -143,6 +143,18 @@ public class CLIPACTIONRECORD implements ASMSource, Serializable {
public void setParentClipActions(CLIPACTIONS parentClipActions) {
this.parentClipActions = parentClipActions;
}
@Override
public void setSwfAndTag(SWF swf, Tag tag) {
this.swf = swf;
this.tag = tag;
}
@Override
public Tag getTag() {
return tag;
}
public CLIPACTIONRECORD(SWF swf, SWFInputStream sis, Tag tag, CLIPACTIONS parentClipActions) throws IOException {
this.swf = swf;

View File

@@ -0,0 +1,16 @@
package com.jpexs.decompiler.flash.types;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.tags.Tag;
/**
*
* @author JPEXS
*/
public interface HasSwfAndTag {
public void setSwfAndTag(SWF swf, Tag tag);
public SWF getSwf();
public Tag getTag();
}