public static MapObjectSpecial NewFromXml(XmlNode item) { MapObjectSpecial smo = null; if (item.Name == "destroy_near") { smo = new SpecialMapObject_DestroyCircle(); } if (item.Name == "add_ai" || item.Name == "direct") { smo = new SpecialMapObject_PointTarget(); } if ((item.Name == "if_inside_box") || (item.Name == "if_inside_sphere") || (item.Name == "if_outside_box") || (item.Name == "if_outside_sphere")) { smo = new SpecialMapObject_BoxSphere(); } if (smo == null) { return(null); } smo.FromXml(item); return(smo); }
public bool IsSpaceMapEditableStatement() { if (CanBeSpaceMapEditableStatement()) { try { SpaceMap.MapObjectSpecial smo = SpaceMap.MapObjectSpecial.NewFromXml(ToXml(new XmlDocument(), true)); if (smo == null) { throw new FormatException(); } } catch (FormatException) { // The object contains expressions and cannot be edited on space map return(false); } return(true); } return(false); }
public void FromXml(string text) { XmlDocument xDoc = new XmlDocument(); try { xDoc.LoadXml(text); } catch (Exception ex) { Log.Add("Failed to load space map from xml for the following reasons:"); Log.Add(ex); return; } XmlNode root = null; foreach (XmlNode node in xDoc.ChildNodes) { if (node.Name == "createInput" || node.Name == "statementInput" || node.Name == "bgInput" || node.Name == "output") { root = node; } } if (root == null) { Log.Add("Failed to load space map from xml for the following reasons:"); Log.Add("Root node \"createInput\" or \"statementInput\" or \"bgInput\" or \"output\"not found!"); return; } if (root.Name == "createInput" || root.Name == "bgInput" || root.Name == "output") { bool bg = root.Name == "bgInput"; if (!bg) { Clear(); } foreach (XmlNode item in root.ChildNodes) { MapObjectNamed mo = MapObjectNamed.NewFromXml(item); MapObjectNameless nmo = MapObjectNameless.NewFromXml(item); if (bg) { if (mo != null) { BacgkroundNamedObjects.Add(mo); } if (nmo != null) { BackgroundNamelessObjects.Add(nmo); } } else { if (mo != null) { NamedObjects.Add(mo); } if (nmo != null) { NamelessObjects.Add(nmo); } } } } if (root.Name == "statementInput") { Clear(); SelectionSpecial = MapObjectSpecial.NewFromXml(root.ChildNodes[0]); } }