public virtual void SetJsonReadyCustomParameters(List <string> parameters) { if (parameters != null) { CustomParameters.Clear(); foreach (var k in parameters) { CustomParameters.Add(GraphParameterValue.FromJson(k, null)); } } }
public virtual void SetJsonReadyParameters(Dictionary <string, string> parameters) { if (parameters != null) { Parameters = new Dictionary <string, GraphParameterValue>(); foreach (var k in parameters.Keys) { string[] split = k.Split('.'); Node n = null; NodeLookup.TryGetValue(split[0], out n); Parameters[k] = GraphParameterValue.FromJson(parameters[k], n); if (Parameters[k].IsFunction()) { var f = Parameters[k].Value as FunctionGraph; f.OnGraphUpdated += Graph_OnGraphUpdated; } } } }
public virtual void FromJson(string data) { GraphData d = JsonConvert.DeserializeObject <GraphData>(data); if (d != null) { Dictionary <string, Node> lookup = new Dictionary <string, Node>(); Dictionary <string, string> nodeData = new Dictionary <string, string>(); Name = d.name; OutputNodes = d.outputs; InputNodes = d.inputs; defaultTextureType = d.defaultTextureType; ShiftX = d.shiftX; ShiftY = d.shiftY; Zoom = d.zoom; Parameters = new Dictionary <string, GraphParameterValue>(); foreach (var k in d.parameters.Keys) { Parameters[k] = GraphParameterValue.FromJson(d.parameters[k]); } //parse node data //setup initial object instances foreach (string s in d.nodes) { Node.NodeData nd = JsonConvert.DeserializeObject <Node.NodeData>(s); if (nd != null) { string type = nd.type; if (!string.IsNullOrEmpty(type)) { try { Type t = Type.GetType(type); if (t != null) { //special case to handle output nodes if (t.Equals(typeof(OutputNode))) { OutputNode n = new OutputNode(defaultTextureType); n.ParentGraph = this; n.Id = nd.id; lookup[nd.id] = n; Nodes.Add(n); nodeData[nd.id] = s; } else if (t.Equals(typeof(InputNode))) { InputNode n = new InputNode(defaultTextureType); n.ParentGraph = this; n.Id = nd.id; lookup[nd.id] = n; Nodes.Add(n); nodeData[nd.id] = s; } else { Node n = (Node)Activator.CreateInstance(t, nd.width, nd.height, defaultTextureType); if (n != null) { n.ParentGraph = this; n.Id = nd.id; lookup[nd.id] = n; Nodes.Add(n); nodeData[nd.id] = s; } } } else { //log we could not load graph node } } catch { //log we could not load graph node } } } } NodeLookup = lookup; //apply data to nodes foreach (Node n in Nodes) { string ndata = null; nodeData.TryGetValue(n.Id, out ndata); if (!string.IsNullOrEmpty(ndata)) { n.FromJson(lookup, ndata); n.OnUpdate += N_OnUpdate; //origin sizes are only for graph instances //not actually used in the current one being edited //it is used in the ResizeWith OriginSizes[n.Id] = new Point(n.Width, n.Height); } } } }