Fixed Raw editor now checks whether field value can be placed inside this kind of tag

This commit is contained in:
Jindra Petřík
2022-11-01 20:01:22 +01:00
parent 149a2fbb90
commit e9a133058b
6 changed files with 53 additions and 11 deletions

View File

@@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file.
- Reloading SWF inside DefineBinaryData
- Working with byte ranges - caused problems when cloning tags
- All "mapped" tags have character id in parenthesis in the tag tree
- Raw editor now checks whether field value can be placed inside this kind of tag
## [16.0.1] - 2022-10-31
### Added

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.types;
import com.jpexs.decompiler.flash.tags.DefineButton2Tag;
@@ -85,6 +86,7 @@ public class BUTTONRECORD implements Serializable {
/**
* If within DefineButton2Tag: Character color transform
*/
@Conditional(tags = {DefineButton2Tag.ID})
public CXFORMWITHALPHA colorTransform;
/**
@@ -92,6 +94,7 @@ public class BUTTONRECORD implements Serializable {
* this button
*/
@SWFArray("filter")
@Conditional(value = "buttonHasFilterList", tags = {DefineButton2Tag.ID})
public List<FILTER> filterList;
/**

View File

@@ -16,6 +16,9 @@
*/
package com.jpexs.decompiler.flash.types;
import com.jpexs.decompiler.flash.tags.DefineMorphShape2Tag;
import com.jpexs.decompiler.flash.tags.DefineMorphShapeTag;
import com.jpexs.decompiler.flash.types.annotations.Conditional;
import java.io.Serializable;
/**
@@ -24,8 +27,10 @@ import java.io.Serializable;
*/
public class MORPHLINESTYLEARRAY implements Serializable {
@Conditional(tags = {DefineMorphShapeTag.ID})
public MORPHLINESTYLE[] lineStyles;
@Conditional(tags = {DefineMorphShape2Tag.ID})
public MORPHLINESTYLE2[] lineStyles2;
public LINESTYLEARRAY getLineStylesAt(int shapeNum, int ratio) {

View File

@@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.types.annotations.Conditional;
import com.jpexs.decompiler.flash.types.annotations.ConditionalType;
import java.io.IOException;
import java.io.StringReader;
import java.util.Arrays;
import java.util.EmptyStackException;
import java.util.HashSet;
import java.util.Map;
@@ -33,13 +34,19 @@ import java.util.Stack;
public class ConditionEvaluator {
private final String[] values;
private final int[] tags;
private final boolean revert;
public ConditionEvaluator(Conditional cond) {
values = cond.value();
tags = cond.tags();
revert = cond.revert();
}
public ConditionEvaluator(ConditionalType cond) {
values = cond.value();
tags = cond.tags();
revert = cond.revert();
}
private void expressionRest(Map<String, Boolean> fields, Stack<Boolean> stack, ConditionLexer lex) throws IOException, AnnotationParseException {
@@ -98,7 +105,25 @@ public class ConditionEvaluator {
}
}
public boolean eval(Map<String, Boolean> fields) throws AnnotationParseException {
public boolean eval(Map<String, Boolean> fields, int parentTagId) throws AnnotationParseException {
boolean result;
if (tags.length > 0) {
boolean tagFound = false;
for (int i = 0; i < tags.length; i++) {
if (tags[i] == parentTagId) {
tagFound = true;
break;
}
}
if (!tagFound) {
result = false;
if (revert) {
return !result;
}
return result;
}
}
ConditionLexer lex = new ConditionLexer(new StringReader(prepareCond()));
Stack<Boolean> stack = new Stack<>();
@@ -109,13 +134,21 @@ public class ConditionEvaluator {
throw new AnnotationParseException("Invalid condition:" + prepareCond(), lex.yyline());
}
if (prepareCond().isEmpty()) {
return true;
result = true;
if (revert) {
return !result;
}
return result;
}
if (stack.size() != 1) {
throw new AnnotationParseException("Invalid condition:" + prepareCond(), lex.yyline());
}
return stack.pop();
result = stack.pop();
if (revert) {
return !result;
}
return result;
}
private String prepareCond() {

View File

@@ -571,7 +571,7 @@ public class GenericTagPanel extends JPanel implements ChangeListener {
}
}
}
boolean ok = ev.eval(fields);
boolean ok = ev.eval(fields, tag.getId());
if (conditionMet) {
conditionMet = ok;
}

View File

@@ -902,7 +902,7 @@ public class GenericTagTreePanel extends GenericTagPanel {
private Object getChild(Object parent, int index, boolean limited) {
if (parent == mtroot) {
return new FieldNode(mtroot, mtroot, filterFields(this, mtroot.getClass().getSimpleName(), mtroot.getClass(), limited).get(index), -1);
return new FieldNode(mtroot, mtroot, filterFields(this, mtroot.getClass().getSimpleName(), mtroot.getClass(), limited, mtroot.getId()).get(index), -1);
}
FieldNode fnode = (FieldNode) parent;
Field field = fnode.fieldSet.get(FIELD_INDEX);
@@ -910,7 +910,7 @@ public class GenericTagTreePanel extends GenericTagPanel {
return new FieldNode(mtroot, fnode.obj, fnode.fieldSet, index);
}
parent = fnode.getValue(FIELD_INDEX);
return new FieldNode(mtroot, parent, filterFields(this, getNodePathName(fnode), parent.getClass(), limited).get(index), -1);
return new FieldNode(mtroot, parent, filterFields(this, getNodePathName(fnode), parent.getClass(), limited, mtroot.getId()).get(index), -1);
}
@Override
@@ -925,7 +925,7 @@ public class GenericTagTreePanel extends GenericTagPanel {
private int getChildCount(Object parent, boolean limited) {
if (parent == mtroot) {
return filterFields(this, mtroot.getClass().getSimpleName(), mtroot.getClass(), limited).size();
return filterFields(this, mtroot.getClass().getSimpleName(), mtroot.getClass(), limited, mtroot.getId()).size();
}
FieldNode fnode = (FieldNode) parent;
if (isLeaf(fnode)) {
@@ -946,7 +946,7 @@ public class GenericTagTreePanel extends GenericTagPanel {
}
parent = fnode.getValue(FIELD_INDEX);
return filterFields(this, getNodePathName(fnode), parent.getClass(), limited).size();
return filterFields(this, getNodePathName(fnode), parent.getClass(), limited, mtroot.getId()).size();
}
@Override
@@ -1109,7 +1109,7 @@ public class GenericTagTreePanel extends GenericTagPanel {
}
}
private static List<FieldSet> filterFields(MyTreeModel mod, String parentPath, Class<?> cls, boolean limited) {
private static List<FieldSet> filterFields(MyTreeModel mod, String parentPath, Class<?> cls, boolean limited, int parentTagId) {
List<FieldSet> ret = new ArrayList<>();
List<Field> fields = getAvailableFields(cls);
Map<String, List<Field>> tables = new HashMap<>();
@@ -1142,7 +1142,7 @@ public class GenericTagTreePanel extends GenericTagPanel {
fieldMap.put(sf, true);
}
}
if (!ev.eval(fieldMap)) {
if (!ev.eval(fieldMap, parentTagId)) {
continue;
}
} catch (AnnotationParseException | IllegalArgumentException | IllegalAccessException ex) {