Browse Source

Merge origin/master

rickard 3 years ago
parent
commit
0f521a30cd

+ 36 - 0
jme3-materialeditor/src/com/jme3/gde/materialdefinition/fileStructure/DefinesBlock.java

@@ -0,0 +1,36 @@
+package com.jme3.gde.materialdefinition.fileStructure;
+
+import com.jme3.gde.materialdefinition.fileStructure.leaves.DefineBlock;
+import com.jme3.util.blockparser.Statement;
+import java.util.List;
+
+/**
+ * Handles the surrounding statement of Defines{} in a MaterialDefinition
+ * Each row is a DefineBlock
+ * @author rickard
+ */
+public final class DefinesBlock extends UberStatement {
+
+    protected DefinesBlock(int lineNumber, String line) {
+        super(lineNumber, line);
+    }
+
+    public DefinesBlock(Statement sta) {
+        this(sta.getLineNumber(), sta.getLine());
+        for (Statement statement : sta.getContents()) {
+            addStatement(new DefineBlock(statement));
+        }
+    }
+
+    public List<DefineBlock> getDefineBlocks() {
+        return getBlocks(DefineBlock.class);
+    }
+
+    public void addDefineBlock(DefineBlock block) {
+        contents.add(block);
+    }
+
+    public void removeDefineBlock(DefineBlock block) {
+        contents.remove(block);
+    }
+}

+ 4 - 2
jme3-materialeditor/src/com/jme3/gde/materialdefinition/fileStructure/TechniqueBlock.java

@@ -52,6 +52,8 @@ public class TechniqueBlock extends UberStatement {
                 addStatement(new VertexShaderNodesBlock(statement));
             } else if (statement.getLine().trim().startsWith("FragmentShaderNodes")) {
                 addStatement(new FragmentShaderNodesBlock(statement));
+            } else if (statement.getLine().trim().startsWith("Defines")) {
+                addStatement(new DefinesBlock(statement));
             } else {
                 addStatement(new UnsupportedStatement(statement));
             }
@@ -111,7 +113,7 @@ public class TechniqueBlock extends UberStatement {
             return getWorldParameters().getWorldParams();
         else {
             logger.log(Level.WARNING, "Unable to build ShaderNodes: Could not find any WorldParameters. Most likely the technique {0} is broken.", line);
-            return new ArrayList<WorldParamBlock>();
+            return new ArrayList<>();
         }
     }
 
@@ -189,7 +191,7 @@ public class TechniqueBlock extends UberStatement {
     }
 
     public List<ShaderNodeBlock> getShaderNodes() {
-        List<ShaderNodeBlock> list = new ArrayList<ShaderNodeBlock>();
+        List<ShaderNodeBlock> list = new ArrayList<>();
         
         VertexShaderNodesBlock vert_block = getBlock(VertexShaderNodesBlock.class);
         if (vert_block == null)

+ 2 - 1
jme3-materialeditor/src/com/jme3/gde/materialdefinition/fileStructure/UberStatement.java

@@ -13,7 +13,8 @@ import java.util.LinkedList;
 import java.util.List;
 
 /**
- *
+ * A statement that will be enclosed with curly braces.
+ * 
  * @author Nehon
  */
 @SuppressWarnings({"unchecked", "rawtypes"})

+ 76 - 0
jme3-materialeditor/src/com/jme3/gde/materialdefinition/fileStructure/leaves/DefineBlock.java

@@ -0,0 +1,76 @@
+package com.jme3.gde.materialdefinition.fileStructure.leaves;
+
+import com.jme3.util.blockparser.Statement;
+import java.util.Objects;
+
+/**
+ * Handles one row of Defines in a MaterialDef, ie ALBEDOMAP : AlbedoMap
+ * @author rickard
+ */
+public final class DefineBlock extends LeafStatement {
+
+    private String name;
+    private String define;
+
+    protected DefineBlock(int lineNumber, String line) {
+        super(lineNumber, line);
+    }
+
+    public DefineBlock(Statement sta) {
+        this(sta.getLineNumber(), sta.getLine());
+        parse(sta);
+        updateLine();
+    }
+
+    public DefineBlock(String name, String define) {
+        super(0, "");
+        this.name = name;
+        this.define = define;
+        updateLine();
+    }
+
+    private void updateLine() {
+        this.line = String.format("%s : %s", name, define);
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+        updateLine();
+    }
+
+    public String getDefine() {
+        return define;
+    }
+
+    public void setDefine(String define) {
+        this.define = define;
+        updateLine();
+    }
+
+    private void parse(Statement sta) {
+        String[] values = sta.getLine().split(":");
+        name = values[0].trim();
+        define = values[1].trim();
+    }
+
+    @Override
+    public int hashCode() {
+        int hash = 7;
+        hash = 67 * hash + Objects.hashCode(this.name);
+        hash = 67 * hash + Objects.hashCode(this.define);
+        return hash;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (!(obj instanceof DefineBlock)) {
+            return false;
+        }
+        return ((DefineBlock) obj).getName().equals(name) && ((DefineBlock) obj).getDefine().equals(define);
+    }
+
+}

+ 5 - 4
jme3-materialeditor/src/com/jme3/gde/materialdefinition/fileStructure/leaves/LeafStatement.java

@@ -12,13 +12,14 @@ import java.util.LinkedList;
 import java.util.List;
 
 /**
- *
+ * A statement that will not be decorated.
+ * 
  * @author Nehon
  */
 @SuppressWarnings({"unchecked", "rawtypes"})
 public class LeafStatement extends Statement {
 
-    private List listeners = Collections.synchronizedList(new LinkedList());
+    private final List listeners = Collections.synchronizedList(new LinkedList());
 
     public void addPropertyChangeListener(PropertyChangeListener pcl) {
         listeners.add(pcl);
@@ -31,8 +32,8 @@ public class LeafStatement extends Statement {
     protected void fire(String propertyName, Object old, Object nue) {
         //Passing 0 below on purpose, so you only synchronize for one atomic call:
         PropertyChangeListener[] pcls = (PropertyChangeListener[]) listeners.toArray(new PropertyChangeListener[0]);
-        for (int i = 0; i < pcls.length; i++) {
-            pcls[i].propertyChange(new PropertyChangeEvent(this, propertyName, old, nue));
+        for (PropertyChangeListener pcl : pcls) {
+            pcl.propertyChange(new PropertyChangeEvent(this, propertyName, old, nue));
         }
     }