Main repository of MikuMikuStudio
Revision | 8fba60d6bfa78c0de6281728ea9906e50e81bff0 (tree) |
---|---|
Time | 2013-02-27 07:53:09 |
Author | remy.bouquet@gmail.com <remy.bouquet@gmai...> |
Commiter | remy.bouquet@gmail.com |
ry to fix InputMappingBlock file
git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@10444 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
@@ -0,0 +1,69 @@ | ||
1 | +/* | |
2 | + * To change this template, choose Tools | Templates | |
3 | + * and open the template in the editor. | |
4 | + */ | |
5 | +package com.jme3.gde.materialdefinition.fileStructure.leaves; | |
6 | + | |
7 | +import com.jme3.util.blockparser.Statement; | |
8 | +import java.util.logging.Level; | |
9 | +import java.util.logging.Logger; | |
10 | + | |
11 | +/** | |
12 | + * | |
13 | + * @author Nehon | |
14 | + */ | |
15 | +public class InputMappingBlock extends MappingBlock { | |
16 | + | |
17 | + protected InputMappingBlock(int lineNumber, String line) { | |
18 | + super(lineNumber, line); | |
19 | + } | |
20 | + | |
21 | + public InputMappingBlock(Statement sta, String name) { | |
22 | + this(sta.getLineNumber(), sta.getLine()); | |
23 | + parse(sta); | |
24 | + leftNameSpace = name; | |
25 | + updateLine(); | |
26 | + } | |
27 | + | |
28 | + public InputMappingBlock(String leftVar, String rightVar, String leftVarSwizzle, String rightVarSwizzle, String leftNameSpace,String rightNameSpace, String condition) { | |
29 | + super(0, ""); | |
30 | + this.leftVar = leftVar; | |
31 | + this.rightVar = rightVar; | |
32 | + this.leftVarSwizzle = leftVarSwizzle; | |
33 | + this.leftNameSpace = leftNameSpace; | |
34 | + this.rightVarSwizzle = rightVarSwizzle; | |
35 | + this.rightNameSpace = rightNameSpace; | |
36 | + this.condition = condition; | |
37 | + updateLine(); | |
38 | + } | |
39 | + | |
40 | + @Override | |
41 | + protected final void updateLine() { | |
42 | + this.line = leftVar + (leftVarSwizzle == null ? "" : "." + leftVarSwizzle) + " = " + rightNameSpace + "." + rightVar + (rightVarSwizzle == null ? "" : "." + rightVarSwizzle) + (condition != null ? " : " + condition : ""); | |
43 | + } | |
44 | + | |
45 | + private void parse(Statement sta) { | |
46 | + try { | |
47 | + String[] split = sta.getLine().split(":"); | |
48 | + if (split.length > 1) { | |
49 | + condition = split[1].trim(); | |
50 | + } | |
51 | + String mapping = split[0].trim(); | |
52 | + String[] s = mapping.split("="); | |
53 | + String[] left = s[0].split("\\."); | |
54 | + leftVar = left[0].trim(); | |
55 | + if (left.length > 1) { | |
56 | + leftVarSwizzle = left[1].trim(); | |
57 | + } | |
58 | + String[] right = s[1].split("\\."); | |
59 | + rightNameSpace = right[0].trim(); | |
60 | + rightVar = right[1].trim(); | |
61 | + if (right.length > 2) { | |
62 | + rightVarSwizzle = right[2].trim(); | |
63 | + } | |
64 | + | |
65 | + } catch (ArrayIndexOutOfBoundsException e) { | |
66 | + Logger.getLogger(InputMappingBlock.class.getName()).log(Level.WARNING, "Parsing error line " + sta.getLineNumber() + " : " + sta.getLine()); | |
67 | + } | |
68 | + } | |
69 | +} |