public static GraphParameterValue FromJson(string data) { GraphParameterValueData d = JsonConvert.DeserializeObject <GraphParameterValueData>(data); if (d.isFunction) { FunctionGraph t = new FunctionGraph("temp"); t.FromJson((string)d.value); return(new GraphParameterValue(d.name, t)); } return(new GraphParameterValue(d.name, d.value)); }
public static GraphParameterValue FromJson(string data, Node n) { GraphParameterValueData d = JsonConvert.DeserializeObject <GraphParameterValueData>(data); if (d.isFunction) { //we have a chicken and egg problem here... //which comes first the node population //or the parameter population? FunctionGraph t = new FunctionGraph("temp"); t.FromJson((string)d.value); t.ParentNode = n; t.SetConnections(); return(new GraphParameterValue(d.name, t, d.description, (NodeType)d.type, d.min, d.max)); } return(new GraphParameterValue(d.name, d.value, d.description, (NodeType)d.type, d.min, d.max)); }
public virtual void SetJsonReadyCustomFunctions(List <string> functions) { if (functions != null) { CustomFunctions = new List <FunctionGraph>(); foreach (string k in functions) { FunctionGraph g = new FunctionGraph("temp"); CustomFunctions.Add(g); g.FromJson(k); } foreach (FunctionGraph g in CustomFunctions) { //set parent graph g.ParentGraph = this; //finally set connections g.SetConnections(); } } }
public virtual void SetJson(GraphParameterValueData d, Node n) { Name = d.name; type = (NodeType)d.type; inputType = (ParameterInputType)d.inputType; Id = d.id; min = d.min; max = d.max; if (d.isFunction) { FunctionGraph t = new FunctionGraph("temp"); t.AssignParentNode(n); t.FromJson((string)d.value); t.ExpectedOutput = (NodeType)d.type; t.SetConnections(); v = t; } else { v = d.value; } //then it is a matrix if (v is Newtonsoft.Json.Linq.JArray && type == NodeType.Matrix) { float[] m = DeserializeValueArray <float[]>(v); //if this fails then the ValidateValue //will simply fill it in with the corresponding //matrix identity if (m != null) { //4x4 matrix if (m.Length == 16) { Matrix4 m4 = new Matrix4(); m4.FromArray(m); v = m4; } } } //handle this in case parser actually returns it as //a float[] instead of a JArray //not sure which it will return at the moment //when it encodes it from the value field //which is classified as a generic object else if (v is float[] && type == NodeType.Matrix) { float[] m = (float[])v; if (m != null && m.Length == 16) { Matrix4 m4 = new Matrix4(); m4.FromArray(m); v = m4; } } Description = d.description; Section = d.section; //whoops forgot to check for this! //otherwise d.section from a file //without d.section is null! if (string.IsNullOrEmpty(Section)) { Section = "Default"; } ValidateValue(); }