public bool Load(string nodesXMLFilename) { try { XElement x = XElement.Load(nodesXMLFilename, LoadOptions.None); XElement settings = x.Element("settings"); foreach (XElement n in x.Elements("node")) { switch (n.Attribute("type").Value) { case "do": DistancePrimitive dp = new DistancePrimitive(n.Attribute("name").Value, n.Attribute("caption").Value, n.Attribute("code").Value); foreach (XElement p in n.Elements("prop")) { dp.Properties.Add(createInputProperty(p.Attribute("type").Value, p.Attribute("name").Value, p.Attribute("default").Value)); } DistanceFieldTypes.Add(dp); break; case "distop": DistanceOperation distop = new DistanceOperation(n.Attribute("name").Value, n.Attribute("caption").Value, n.Attribute("code").Value); foreach (XElement p in n.Elements("prop")) { distop.Properties.Add(createInputProperty(p.Attribute("type").Value, p.Attribute("name").Value, p.Attribute("default").Value)); } DistanceOperations.Add(distop); break; case "domop": DomainOperation dop = new DomainOperation(n.Attribute("name").Value, n.Attribute("caption").Value, n.Attribute("code").Value); foreach (XElement p in n.Elements("prop")) { dop.Properties.Add(createInputProperty(p.Attribute("type").Value, p.Attribute("name").Value, p.Attribute("default").Value)); } DomainOperations.Add(dop); break; } } } catch (Exception e) { errors.Add("Failed to load nodes.xml (" + e.Message + ")"); return(false); } return(true); }
public bool Setup(string functionsXMLFilename) { try { XElement x = XElement.Load(functionsXMLFilename, LoadOptions.None); XElement helpers = x.Element("helpers"); foreach (XElement h in helpers.Elements("code")) { XAttribute comment = h.Attribute("comment"); HelperCode helper = new HelperCode(h.Attribute("name").Value, h.Value, comment == null ? "" : comment.Value); Helpers.Add(helper.Name, helper); } XElement nodes = x.Element("nodes"); foreach (XElement n in nodes.Elements("node")) { string code = ""; string[] requires = null; XElement func = n.Element("function"); if (func != null) { code = func.Value; XAttribute requ = func.Attribute("requires"); if (requ != null) { requires = requ.Value.Split(",".ToCharArray()); } } XAttribute com = n.Attribute("comment"); string comment = ""; if (com != null) { comment = com.Value; } SceneNode node = null; switch (n.Attribute("type").Value) { case "dp": node = new DistancePrimitive(n.Attribute("name").Value, n.Attribute("caption").Value, n.Attribute("mask").Value, code, requires, comment); DistanceFieldTypes.Add(node as DistancePrimitive); break; case "distop": node = new DistanceOperation(n.Attribute("name").Value, n.Attribute("caption").Value, n.Attribute("mask").Value, code, requires, comment); DistanceOperations.Add(node as DistanceOperation); break; case "domop": node = new DomainOperation(n.Attribute("name").Value, n.Attribute("caption").Value, n.Attribute("mask").Value, code, requires, comment); DomainOperations.Add(node as DomainOperation); break; } if (node != null && n.Element("properties") != null) { foreach (XElement p in n.Element("properties").Elements("property")) { node.Properties.Add(createInputProperty(p.Attribute("type").Value, p.Attribute("name").Value, p.Attribute("default").Value)); } } } } catch (Exception e) { errors.Add("Failed to load/parse " + functionsXMLFilename + ":\n" + e.Message); return(false); } return(true); }