public IEffectPartInfo Load(XElement partNode) { var info = new CollisionEffectPartInfo(); var rects = new List<HitBoxInfo>(); HashSet<string> enables = new HashSet<string>(); info.ClearEnabled = partNode.Element("Clear") != null; var enable = partNode.Element("Enabled"); if (enable != null) { info.Enabled = enable.GetValue<bool>(); } foreach (var box in partNode.Elements("Hitbox")) { var boxinfo = new HitBoxInfo() { Box = new RectangleF() { X = box.GetAttribute<float>("x"), Y = box.GetAttribute<float>("y"), Width = box.GetAttribute<float>("width"), Height = box.GetAttribute<float>("height") }, ContactDamage = box.TryAttribute<float>("damage"), Environment = box.TryAttribute<bool>("environment", true), PushAway = box.TryAttribute<bool>("pushaway", true), PropertiesName = box.TryAttribute<string>("properties", "Default") }; foreach (var groupnode in box.Elements("Hits")) boxinfo.Hits.Add(groupnode.Value); foreach (var groupnode in box.Elements("Group")) boxinfo.Groups.Add(groupnode.Value); foreach (var resistNode in box.Elements("Resist")) { var resistName = resistNode.GetAttribute<string>("name"); float mult = resistNode.GetAttribute<float>("multiply"); boxinfo.Resistance.Add(resistName, mult); } rects.Add(boxinfo); } foreach (var enableBox in partNode.Elements("EnableBox")) { enables.Add(enableBox.GetAttribute<string>("name")); } info.HitBoxes = rects; info.EnabledBoxes = enables; return info; }
private static HitBoxInfo GetHitbox(XElement boxnode) { float width = boxnode.GetAttribute<float>("width"); float height = boxnode.GetAttribute<float>("height"); float x = boxnode.GetAttribute<float>("x"); float y = boxnode.GetAttribute<float>("y"); var box = new HitBoxInfo() { Name = boxnode.TryAttribute<string>("name"), Box = new Common.Geometry.RectangleF(x, y, width, height), ContactDamage = boxnode.TryAttribute<float>("damage"), Environment = boxnode.TryAttribute<bool>("environment", true), PushAway = boxnode.TryAttribute<bool>("pushaway", true), PropertiesName = boxnode.TryAttribute<string>("properties", "Default") }; return box; }
private void WriteHitbox(HitBoxInfo box, XmlWriter writer) { writer.WriteStartElement("Hitbox"); if (box.Name != null) writer.WriteAttributeString("name", box.Name); writer.WriteAttributeString("x", box.Box.X.ToString()); writer.WriteAttributeString("y", box.Box.Y.ToString()); writer.WriteAttributeString("width", box.Box.Width.ToString()); writer.WriteAttributeString("height", box.Box.Height.ToString()); if (box.PropertiesName != null) writer.WriteAttributeString("properties", box.PropertiesName); if (box.ContactDamage != 0) writer.WriteAttributeString("damage", box.ContactDamage.ToString()); writer.WriteAttributeString("environment", box.Environment.ToString()); writer.WriteAttributeString("pushaway", box.PushAway.ToString()); foreach (var hit in box.Hits) writer.WriteElementString("Hits", hit); foreach (var group in box.Groups) writer.WriteElementString("Group", group); foreach (var resist in box.Resistance) { writer.WriteStartElement("Resist"); writer.WriteAttributeString("name", resist.Key); writer.WriteAttributeString("multiply", resist.Value.ToString()); writer.WriteEndElement(); } writer.WriteEndElement(); }