Fixed #1961 Characters can use characterId 0, PlaceObject can use depth 0

Changed #1961 SoundStreamHead on main timeline is exported/imported with identifier "-1"
This commit is contained in:
Jindra Petřík
2023-02-04 18:08:53 +01:00
parent d2c15e4b60
commit aaa354804e
9 changed files with 27 additions and 26 deletions

View File

@@ -989,10 +989,8 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
logger.log(Level.SEVERE, "SWF already contains characterId={0}", characterId);
}
if (characterId != 0) {
characters.put(characterId, (CharacterTag) t);
characterIdTags.put(characterId, new ArrayList<>());
}
characters.put(characterId, (CharacterTag) t);
characterIdTags.put(characterId, new ArrayList<>());
} else if (characterIdTags.containsKey(characterId)) {
characterIdTags.get(characterId).add((CharacterIdTag) t);
}

View File

@@ -75,7 +75,7 @@ public class SoundStreamHead2Tag extends SoundStreamHeadTypeTag {
public int latencySeek;
@Internal
private int virtualCharacterId = 0;
private int virtualCharacterId = -1;
/**
* Constructor
@@ -251,7 +251,7 @@ public class SoundStreamHead2Tag extends SoundStreamHeadTypeTag {
@Override
public String toString() {
return getName() + (virtualCharacterId > 0 ? " (" + virtualCharacterId + ")" : "");
return getName() + " (" + virtualCharacterId + ")";
}
//getNeededCharacters intentionally not defined

View File

@@ -32,7 +32,6 @@ import com.jpexs.decompiler.flash.types.sound.SoundExportFormat;
import com.jpexs.decompiler.flash.types.sound.SoundFormat;
import com.jpexs.helpers.ByteArrayRange;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
@@ -85,7 +84,7 @@ public class SoundStreamHeadTag extends SoundStreamHeadTypeTag {
public int latencySeek;
@Internal
private int virtualCharacterId = 0;
private int virtualCharacterId = -1;
/**
* Constructor
@@ -261,7 +260,7 @@ public class SoundStreamHeadTag extends SoundStreamHeadTypeTag {
@Override
public String toString() {
return getName() + (virtualCharacterId > 0 ? " (" + virtualCharacterId + ")" : "");
return getName() + " (" + virtualCharacterId + ")";
}
//getNeededCharacters intentionally not defined

View File

@@ -70,7 +70,7 @@ public class DefineExternalStreamSound extends Tag implements CharacterIdTag, So
public static final int SOUND_FORMAT_WAV = 0;
@Internal
private int virtualCharacterId = 0;
private int virtualCharacterId = -1;
/**
* Gets data bytes
@@ -243,7 +243,7 @@ public class DefineExternalStreamSound extends Tag implements CharacterIdTag, So
@Override
public String toString() {
return getName() + (virtualCharacterId > 0 ? " (" + virtualCharacterId + ")" : "");
return getName() + " (" + virtualCharacterId + ")";
}
@Override

View File

@@ -439,14 +439,14 @@ public class Timeline {
createASPackages();
if (timelined instanceof SWF) {
// popuplate only for main timeline
populateSoundStreamBlocks(0, timelined.getTags());
populateSoundStreamBlocks(-1, timelined.getTags());
}
initialized = true;
}
private synchronized void detectTweens() {
for (int d = 1; d <= maxDepth; d++) {
for (int d = 0; d <= maxDepth; d++) {
int characterId = -1;
String charClassName = null;
int len = 0;
@@ -486,7 +486,7 @@ public class Timeline {
private synchronized void calculateMaxDepthFrames() {
depthMaxFrame.clear();
for (int d = 1; d <= maxDepth; d++) {
for (int d = 0; d <= maxDepth; d++) {
for (int f = frames.size() - 1; f >= 0; f--) {
if (frames.get(f).layers.get(d) != null) {
depthMaxFrame.put(d, f);
@@ -1037,7 +1037,7 @@ public class Timeline {
int maxDepth = getMaxDepth();
int clipCount = 0;
for (int i = 1; i <= maxDepth; i++) {
for (int i = 0; i <= maxDepth; i++) {
boolean clipChanged = clipCount != clips.size();
for (int c = 0; c < clips.size(); c++) {
if (clips.get(c).depth < i) {
@@ -1200,7 +1200,7 @@ public class Timeline {
int maxDepth = getMaxDepth();
int clipCount = 0;
Element clipGroup = null;
for (int i = 1; i <= maxDepth; i++) {
for (int i = 0; i <= maxDepth; i++) {
boolean clipChanged = clipCount != clips.size();
for (int c = 0; c < clips.size(); c++) {
if (clips.get(c).depth < i) {
@@ -1422,7 +1422,7 @@ public class Timeline {
public boolean isSingleFrame(int frame) {
Frame frameObj = getFrame(frame);
for (int i = 1; i <= maxDepth; i++) {
for (int i = 0; i <= maxDepth; i++) {
if (!frameObj.layers.containsKey(i)) {
continue;
}

View File

@@ -1017,7 +1017,7 @@ public class XFLConverter {
return layer;
}
private static int getLayerCount(ReadOnlyTagList tags) {
private static int getMaxDepth(ReadOnlyTagList tags) {
int maxDepth = 0;
for (Tag t : tags) {
if (t instanceof PlaceObjectTypeTag) {
@@ -2944,7 +2944,7 @@ public class XFLConverter {
index++;
}
int layerCount = getLayerCount(timelineTags);
int maxDepth = getMaxDepth(timelineTags);
List<Integer> clipFrameSplitters = new ArrayList<>();
List<PlaceObjectTypeTag> clipPlaces = new ArrayList<>();
@@ -2995,13 +2995,13 @@ public class XFLConverter {
clipPlaces.add(null);
Map<Integer, List<Integer>> depthToFramesList = new HashMap<>();
for (int d = layerCount; d >= 1; d--) {
for (int d = maxDepth; d >= 0; d--) {
depthToFramesList.put(d, new ArrayList<>());
for (int i = 0; i < frameCount; i++) {
depthToFramesList.get(d).add(i);
}
}
for (int d = layerCount; d >= 1; d--) {
for (int d = maxDepth; d >= 0; d--) {
for (int p = 0; p < clipPlaces.size() - 1; p++) {
PlaceObjectTypeTag po = clipPlaces.get(p);
@@ -3054,8 +3054,8 @@ public class XFLConverter {
}
}
int soundLayerIndex = layerCount;
layerCount++;
int soundLayerIndex = maxDepth;
maxDepth++;
convertSoundLayer(soundLayerIndex, timelineTags, files, writer);
writer.writeEndElement();
writer.writeEndElement();