public override MapEntity Clone() { var clone = new Structure(rect, Prefab, Submarine) { defaultRect = defaultRect }; foreach (KeyValuePair <string, SerializableProperty> property in SerializableProperties) { if (!property.Value.Attributes.OfType <Editable>().Any()) { continue; } clone.SerializableProperties[property.Key].TrySetValue(clone, property.Value.GetValue(this)); } if (FlippedX) { clone.FlipX(false); } if (FlippedY) { clone.FlipY(false); } return(clone); }
public static Structure Load(XElement element, Submarine submarine) { string name = element.Attribute("name").Value; string identifier = element.GetAttributeString("identifier", ""); StructurePrefab prefab = FindPrefab(name, identifier); if (prefab == null) { DebugConsole.ThrowError("Error loading structure - structure prefab \"" + name + "\" (identifier \"" + identifier + "\") not found."); return(null); } Rectangle rect = element.GetAttributeRect("rect", Rectangle.Empty); Structure s = new Structure(rect, prefab, submarine) { Submarine = submarine, ID = (ushort)int.Parse(element.Attribute("ID").Value) }; foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString()) { case "section": int index = subElement.GetAttributeInt("i", -1); if (index == -1) { continue; } s.Sections[index].damage = subElement.GetAttributeFloat("damage", 0.0f); break; } } if (element.GetAttributeBool("flippedx", false)) { s.FlipX(false); } if (element.GetAttributeBool("flippedy", false)) { s.FlipY(false); } SerializableProperty.DeserializeProperties(s, element); //structures with a body drop a shadow by default if (element.Attribute("usedropshadow") == null) { s.UseDropShadow = prefab.Body; } return(s); }