diff --git a/Barotrauma/BarotraumaClient/Source/Items/Components/ItemComponent.cs b/Barotrauma/BarotraumaClient/Source/Items/Components/ItemComponent.cs index 197284497..5e854b39a 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Components/ItemComponent.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Components/ItemComponent.cs @@ -251,22 +251,5 @@ namespace Barotrauma.Items.Components yield return CoroutineStatus.Success; } - - public virtual XElement Save(XElement parentElement) - { - XElement componentElement = new XElement(name); - - foreach (RelatedItem ri in requiredItems) - { - XElement newElement = new XElement("requireditem"); - ri.Save(newElement); - componentElement.Add(newElement); - } - - ObjectProperty.SaveProperties(this, componentElement); - - parentElement.Add(componentElement); - return componentElement; - } } } diff --git a/Barotrauma/BarotraumaClient/Source/Items/Components/ItemContainer.cs b/Barotrauma/BarotraumaClient/Source/Items/Components/ItemContainer.cs index 6005dde45..513e44646 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Components/ItemContainer.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Components/ItemContainer.cs @@ -1,6 +1,5 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using System.Xml.Linq; namespace Barotrauma.Items.Components { @@ -64,20 +63,5 @@ namespace Barotrauma.Items.Components { Inventory.Draw(spriteBatch); } - - public override XElement Save(XElement parentElement) - { - XElement componentElement = base.Save(parentElement); - - string[] itemIdStrings = new string[Inventory.Items.Length]; - for (int i = 0; i < Inventory.Items.Length; i++) - { - itemIdStrings[i] = (Inventory.Items[i] == null) ? "0" : Inventory.Items[i].ID.ToString(); - } - - componentElement.Add(new XAttribute("contained", string.Join(",", itemIdStrings))); - - return componentElement; - } } } diff --git a/Barotrauma/BarotraumaClient/Source/Items/Components/Signal/Connection.cs b/Barotrauma/BarotraumaClient/Source/Items/Components/Signal/Connection.cs index bad788bc1..949859513 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Components/Signal/Connection.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Components/Signal/Connection.cs @@ -3,7 +3,6 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; using System.Linq; -using System.Xml.Linq; namespace Barotrauma.Items.Components { @@ -270,30 +269,5 @@ namespace Barotrauma.Items.Components } } } - - public void Save(XElement parentElement) - { - XElement newElement = new XElement(IsOutput ? "output" : "input", new XAttribute("name", Name)); - - Array.Sort(Wires, delegate (Wire wire1, Wire wire2) - { - if (wire1 == null) return 1; - if (wire2 == null) return -1; - return wire1.Item.ID.CompareTo(wire2.Item.ID); - }); - - for (int i = 0; i < MaxLinked; i++) - { - if (Wires[i] == null) continue; - - //Connection recipient = wires[i].OtherConnection(this); - - //int connectionIndex = recipient.item.Connections.FindIndex(x => x == recipient); - newElement.Add(new XElement("link", - new XAttribute("w", Wires[i].Item.ID.ToString()))); - } - - parentElement.Add(newElement); - } } } diff --git a/Barotrauma/BarotraumaClient/Source/Items/Components/Signal/ConnectionPanel.cs b/Barotrauma/BarotraumaClient/Source/Items/Components/Signal/ConnectionPanel.cs index c2e19882a..e66a28d9a 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Components/Signal/ConnectionPanel.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Components/Signal/ConnectionPanel.cs @@ -1,6 +1,5 @@ using Barotrauma.Networking; using Microsoft.Xna.Framework.Graphics; -using System.Xml.Linq; namespace Barotrauma.Items.Components { @@ -26,17 +25,5 @@ namespace Barotrauma.Items.Components Connection.DrawConnections(spriteBatch, this, character); } - - public override XElement Save(XElement parentElement) - { - XElement componentElement = base.Save(parentElement); - - foreach (Connection c in Connections) - { - c.Save(componentElement); - } - - return componentElement; - } } } diff --git a/Barotrauma/BarotraumaClient/Source/Items/Components/Signal/Wire.cs b/Barotrauma/BarotraumaClient/Source/Items/Components/Signal/Wire.cs index 1aa2b8b39..875e8ab1e 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Components/Signal/Wire.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Components/Signal/Wire.cs @@ -3,8 +3,6 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using System.Collections.Generic; -using System.Globalization; -using System.Xml.Linq; namespace Barotrauma.Items.Components { @@ -231,23 +229,5 @@ namespace Barotrauma.Items.Components } } } - - public override XElement Save(XElement parentElement) - { - XElement componentElement = base.Save(parentElement); - - if (nodes == null || nodes.Count == 0) return componentElement; - - string[] nodeCoords = new string[nodes.Count * 2]; - for (int i = 0; i < nodes.Count; i++) - { - nodeCoords[i * 2] = nodes[i].X.ToString(CultureInfo.InvariantCulture); - nodeCoords[i * 2 + 1] = nodes[i].Y.ToString(CultureInfo.InvariantCulture); - } - - componentElement.Add(new XAttribute("nodes", string.Join(";", nodeCoords))); - - return componentElement; - } } } diff --git a/Barotrauma/BarotraumaClient/Source/Items/Item.cs b/Barotrauma/BarotraumaClient/Source/Items/Item.cs index e81768c8d..ab3ad9eea 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Item.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Item.cs @@ -9,7 +9,6 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; -using System.Xml.Linq; namespace Barotrauma { @@ -380,55 +379,6 @@ namespace Barotrauma return true; } - public override XElement Save(XElement parentElement) - { - XElement element = new XElement("Item"); - - element.Add(new XAttribute("name", prefab.Name), - new XAttribute("ID", ID)); - - System.Diagnostics.Debug.Assert(Submarine != null); - - if (ResizeHorizontal || ResizeVertical) - { - element.Add(new XAttribute("rect", - (int)(rect.X - Submarine.HiddenSubPosition.X) + "," + - (int)(rect.Y - Submarine.HiddenSubPosition.Y) + "," + - rect.Width + "," + rect.Height)); - } - else - { - element.Add(new XAttribute("rect", - (int)(rect.X - Submarine.HiddenSubPosition.X) + "," + - (int)(rect.Y - Submarine.HiddenSubPosition.Y))); - } - - if (linkedTo != null && linkedTo.Count > 0) - { - string[] linkedToIDs = new string[linkedTo.Count]; - - for (int i = 0; i < linkedTo.Count; i++) - { - linkedToIDs[i] = linkedTo[i].ID.ToString(); - } - - element.Add(new XAttribute("linked", string.Join(",", linkedToIDs))); - } - - - ObjectProperty.SaveProperties(this, element); - - foreach (ItemComponent ic in components) - { - ic.Save(element); - } - - parentElement.Add(element); - - return element; - } - - public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime) { if (type == ServerNetObject.ENTITY_POSITION) diff --git a/Barotrauma/BarotraumaClient/Source/Map/Gap.cs b/Barotrauma/BarotraumaClient/Source/Map/Gap.cs index 6f6368938..313db6fd2 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/Gap.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/Gap.cs @@ -1,7 +1,6 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; -using System.Xml.Linq; namespace Barotrauma { @@ -58,34 +57,5 @@ namespace Barotrauma (int)Math.Max((1.5f / GameScreen.Selected.Cam.Zoom), 1.0f)); } } - - public override XElement Save(XElement parentElement) - { - XElement element = new XElement("Gap"); - - element.Add( - new XAttribute("ID", ID), - new XAttribute("horizontal", isHorizontal ? "true" : "false")); - - element.Add(new XAttribute("rect", - (int)(rect.X - Submarine.HiddenSubPosition.X) + "," + - (int)(rect.Y - Submarine.HiddenSubPosition.Y) + "," + - rect.Width + "," + rect.Height)); - - //if (linkedTo != null) - //{ - // int i = 0; - // foreach (Entity e in linkedTo) - // { - // if (e == null) continue; - // element.Add(new XAttribute("linkedto" + i, e.ID)); - // i += 1; - // } - //} - - parentElement.Add(element); - - return element; - } } } diff --git a/Barotrauma/BarotraumaClient/Source/Map/Hull.cs b/Barotrauma/BarotraumaClient/Source/Map/Hull.cs index d3bfc1c15..58e6313bb 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/Hull.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/Hull.cs @@ -4,7 +4,6 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; using System.Collections.Generic; -using System.Xml.Linq; namespace Barotrauma { @@ -323,27 +322,6 @@ namespace Barotrauma x += width; } - - } - - - public override XElement Save(XElement parentElement) - { - XElement element = new XElement("Hull"); - - element.Add - ( - new XAttribute("ID", ID), - new XAttribute("rect", - (int)(rect.X - Submarine.HiddenSubPosition.X) + "," + - (int)(rect.Y - Submarine.HiddenSubPosition.Y) + "," + - rect.Width + "," + rect.Height), - new XAttribute("water", volume) - ); - - parentElement.Add(element); - - return element; } } } diff --git a/Barotrauma/BarotraumaClient/Source/Map/LinkedSubmarine.cs b/Barotrauma/BarotraumaClient/Source/Map/LinkedSubmarine.cs index 00898f3a0..e350502af 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/LinkedSubmarine.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/LinkedSubmarine.cs @@ -3,7 +3,6 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using System.IO; -using System.Linq; using System.Xml.Linq; namespace Barotrauma @@ -145,86 +144,5 @@ namespace Barotrauma return true; } - - public override XElement Save(XElement parentElement) - { - XElement saveElement = null; - - if (sub == null) - { - if (this.saveElement == null) - { - var doc = Submarine.OpenFile(filePath); - saveElement = doc.Root; - - saveElement.Name = "LinkedSubmarine"; - - saveElement.Add(new XAttribute("filepath", filePath)); - } - else - { - saveElement = this.saveElement; - } - - if (saveElement.Attribute("pos") != null) saveElement.Attribute("pos").Remove(); - saveElement.Add(new XAttribute("pos", ToolBox.Vector2ToString(Position - Submarine.HiddenSubPosition))); - - - - var linkedPort = linkedTo.FirstOrDefault(lt => (lt is Item) && ((Item)lt).GetComponent() != null); - if (linkedPort != null) - { - if (saveElement.Attribute("linkedto") != null) saveElement.Attribute("linkedto").Remove(); - - saveElement.Add(new XAttribute("linkedto", linkedPort.ID)); - } - } - else - { - - saveElement = new XElement("LinkedSubmarine"); - - - sub.SaveToXElement(saveElement); - } - - if (sub != null) - { - bool leaveBehind = false; - if (!sub.DockedTo.Contains(Submarine.MainSub)) - { - System.Diagnostics.Debug.Assert(Submarine.MainSub.AtEndPosition || Submarine.MainSub.AtStartPosition); - if (Submarine.MainSub.AtEndPosition) - { - leaveBehind = sub.AtEndPosition != Submarine.MainSub.AtEndPosition; - } - else - { - leaveBehind = sub.AtStartPosition != Submarine.MainSub.AtStartPosition; - } - } - - - if (leaveBehind) - { - saveElement.SetAttributeValue("location", Level.Loaded.Seed); - saveElement.SetAttributeValue("worldpos", ToolBox.Vector2ToString(sub.SubBody.Position)); - - } - else - { - if (saveElement.Attribute("location") != null) saveElement.Attribute("location").Remove(); - if (saveElement.Attribute("worldpos") != null) saveElement.Attribute("worldpos").Remove(); - } - - saveElement.SetAttributeValue("pos", ToolBox.Vector2ToString(Position - Submarine.HiddenSubPosition)); - } - - - - parentElement.Add(saveElement); - - return saveElement; - } } } diff --git a/Barotrauma/BarotraumaClient/Source/Map/MapEntity.cs b/Barotrauma/BarotraumaClient/Source/Map/MapEntity.cs index aa9849dfe..e8eef30d1 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/MapEntity.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/MapEntity.cs @@ -5,7 +5,6 @@ using Microsoft.Xna.Framework.Input; using System; using System.Collections.Generic; using System.Linq; -using System.Xml.Linq; namespace Barotrauma { @@ -75,20 +74,10 @@ namespace Barotrauma get { return selectedList.Contains(this); } } - protected bool ResizeHorizontal - { - get { return prefab != null && prefab.ResizeHorizontal; } - } - protected bool ResizeVertical - { - get { return prefab != null && prefab.ResizeVertical; } - } - public virtual void Draw(SpriteBatch spriteBatch, bool editing, bool back = true) { } public virtual void DrawDamage(SpriteBatch spriteBatch, Effect damageEffect) { } - /// /// Update the selection logic in submarine editor /// @@ -635,13 +624,5 @@ namespace Barotrauma return foundEntities; } - - - public virtual XElement Save(XElement parentElement) - { - DebugConsole.ThrowError("Saving entity " + GetType() + " failed."); - return null; - } - } } diff --git a/Barotrauma/BarotraumaClient/Source/Map/Structure.cs b/Barotrauma/BarotraumaClient/Source/Map/Structure.cs index 243cfb94d..f53365916 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/Structure.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/Structure.cs @@ -16,7 +16,7 @@ namespace Barotrauma partial class Structure : MapEntity, IDamageable, IServerSerializable { - List convexHulls; + private List convexHulls; private void GenerateConvexHull() { @@ -149,39 +149,5 @@ namespace Barotrauma prefab.sprite.effects = oldEffects; } - - - public override XElement Save(XElement parentElement) - { - XElement element = new XElement("Structure"); - - element.Add(new XAttribute("name", prefab.Name), - new XAttribute("ID", ID), - new XAttribute("rect", - (int)(rect.X - Submarine.HiddenSubPosition.X) + "," + - (int)(rect.Y - Submarine.HiddenSubPosition.Y) + "," + - rect.Width + "," + rect.Height)); - - for (int i = 0; i < sections.Length; i++) - { - if (sections[i].damage == 0.0f) continue; - - var sectionElement = - new XElement("section", - new XAttribute("i", i), - new XAttribute("damage", sections[i].damage)); - - if (sections[i].gap != null) - { - sectionElement.Add(new XAttribute("gap", sections[i].gap.ID)); - } - - element.Add(sectionElement); - } - - parentElement.Add(element); - - return element; - } } } diff --git a/Barotrauma/BarotraumaClient/Source/Map/Submarine.cs b/Barotrauma/BarotraumaClient/Source/Map/Submarine.cs index 58cce015d..044f6c6e2 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/Submarine.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/Submarine.cs @@ -103,48 +103,6 @@ namespace Barotrauma } } - public bool Save() - { - return SaveAs(filePath); - } - - public bool SaveAs(string filePath) - { - name = System.IO.Path.GetFileNameWithoutExtension(filePath); - - XDocument doc = new XDocument(new XElement("Submarine")); - SaveToXElement(doc.Root); - - hash = new Md5Hash(doc); - doc.Root.Add(new XAttribute("md5hash", hash.Hash)); - - try - { - SaveUtil.CompressStringToFile(filePath, doc.ToString()); - } - catch (Exception e) - { - DebugConsole.ThrowError("Saving submarine \"" + filePath + "\" failed!", e); - return false; - } - - return true; - } - - public void SaveToXElement(XElement element) - { - element.Add(new XAttribute("name", name)); - element.Add(new XAttribute("description", Description == null ? "" : Description)); - - element.Add(new XAttribute("tags", tags.ToString())); - - foreach (MapEntity e in MapEntity.mapEntityList) - { - if (e.MoveWithLevel || e.Submarine != this) continue; - e.Save(element); - } - } - public static bool SaveCurrent(string filePath) { if (Submarine.MainSub == null) diff --git a/Barotrauma/BarotraumaClient/Source/Map/WayPoint.cs b/Barotrauma/BarotraumaClient/Source/Map/WayPoint.cs index fbdcabc0d..983249d48 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/WayPoint.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/WayPoint.cs @@ -1,8 +1,6 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; -using System.Xml.Linq; -//using Microsoft.Xna.Framework.Input; namespace Barotrauma { @@ -191,53 +189,10 @@ namespace Barotrauma propertyBox.ToolTip = "Only characters with the specified job will spawn at this spawnpoint."; } - - - - - - //GUI.Font.DrawString(spriteBatch, "Spawnpoint: " + spawnType.ToString() + " +/-", new Vector2(x, y + 40), Color.Black); - - + y = y + 30; return editingHUD; - } - - public override XElement Save(XElement parentElement) - { - if (MoveWithLevel) return null; - XElement element = new XElement("WayPoint"); - - element.Add(new XAttribute("ID", ID), - new XAttribute("x", (int)(rect.X - Submarine.HiddenSubPosition.X)), - new XAttribute("y", (int)(rect.Y - Submarine.HiddenSubPosition.Y)), - new XAttribute("spawn", spawnType)); - - if (idCardTags.Length > 0) - { - element.Add(new XAttribute("idcardtags", string.Join(",", idCardTags))); - } - - if (assignedJob != null) element.Add(new XAttribute("job", assignedJob.Name)); - - - if (ConnectedGap != null) element.Add(new XAttribute("gap", ConnectedGap.ID)); - if (Ladders != null) element.Add(new XAttribute("ladders", Ladders.Item.ID)); - - parentElement.Add(element); - - if (linkedTo != null) - { - int i = 0; - foreach (MapEntity e in linkedTo) - { - element.Add(new XAttribute("linkedto" + i, e.ID)); - i += 1; - } - } - - return element; - } + } } } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/ItemComponent.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/ItemComponent.cs index 7a884cc10..830b27903 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/ItemComponent.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/ItemComponent.cs @@ -574,6 +574,22 @@ namespace Barotrauma.Items.Components return ic; } - + + public virtual XElement Save(XElement parentElement) + { + XElement componentElement = new XElement(name); + + foreach (RelatedItem ri in requiredItems) + { + XElement newElement = new XElement("requireditem"); + ri.Save(newElement); + componentElement.Add(newElement); + } + + ObjectProperty.SaveProperties(this, componentElement); + + parentElement.Add(componentElement); + return componentElement; + } } } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/ItemContainer.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/ItemContainer.cs index a49d1f1d6..671e89075 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/ItemContainer.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/ItemContainer.cs @@ -10,10 +10,12 @@ namespace Barotrauma.Items.Components { public const int MaxInventoryCount = 4; - List containableItems; + private List containableItems; public ItemInventory Inventory; private List> itemsWithStatusEffects; + + private ushort[] itemIds; //how many items can be contained [HasDefaultValue(5, false)] @@ -240,6 +242,19 @@ namespace Barotrauma.Items.Components } } - ushort[] itemIds; + public override XElement Save(XElement parentElement) + { + XElement componentElement = base.Save(parentElement); + + string[] itemIdStrings = new string[Inventory.Items.Length]; + for (int i = 0; i < Inventory.Items.Length; i++) + { + itemIdStrings[i] = (Inventory.Items[i] == null) ? "0" : Inventory.Items[i].ID.ToString(); + } + + componentElement.Add(new XAttribute("contained", string.Join(",", itemIdStrings))); + + return componentElement; + } } } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/Connection.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/Connection.cs index 9bbb59aa4..b0d181abc 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/Connection.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/Connection.cs @@ -1,4 +1,5 @@ using Microsoft.Xna.Framework; +using System; using System.Collections.Generic; using System.Xml.Linq; @@ -205,5 +206,27 @@ namespace Barotrauma.Items.Components } } + + public void Save(XElement parentElement) + { + XElement newElement = new XElement(IsOutput ? "output" : "input", new XAttribute("name", Name)); + + Array.Sort(Wires, delegate (Wire wire1, Wire wire2) + { + if (wire1 == null) return 1; + if (wire2 == null) return -1; + return wire1.Item.ID.CompareTo(wire2.Item.ID); + }); + + for (int i = 0; i < MaxLinked; i++) + { + if (Wires[i] == null) continue; + + newElement.Add(new XElement("link", + new XAttribute("w", Wires[i].Item.ID.ToString()))); + } + + parentElement.Add(newElement); + } } } \ No newline at end of file diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/ConnectionPanel.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/ConnectionPanel.cs index a3f7dab08..4e14f7abf 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/ConnectionPanel.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/ConnectionPanel.cs @@ -108,6 +108,18 @@ namespace Barotrauma.Items.Components } } + public override XElement Save(XElement parentElement) + { + XElement componentElement = base.Save(parentElement); + + foreach (Connection c in Connections) + { + c.Save(componentElement); + } + + return componentElement; + } + protected override void RemoveComponentSpecific() { foreach (Connection c in Connections) @@ -140,7 +152,7 @@ namespace Barotrauma.Items.Components } } } - + public void ServerRead(ClientNetObject type, NetBuffer msg, Client c) { List[] wires = new List[Connections.Count]; diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/Wire.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/Wire.cs index 94c5dffd3..4b8828784 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/Wire.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/Wire.cs @@ -477,6 +477,24 @@ namespace Barotrauma.Items.Components Drawable = nodes.Any(); } + public override XElement Save(XElement parentElement) + { + XElement componentElement = base.Save(parentElement); + + if (nodes == null || nodes.Count == 0) return componentElement; + + string[] nodeCoords = new string[nodes.Count * 2]; + for (int i = 0; i < nodes.Count; i++) + { + nodeCoords[i * 2] = nodes[i].X.ToString(CultureInfo.InvariantCulture); + nodeCoords[i * 2 + 1] = nodes[i].Y.ToString(CultureInfo.InvariantCulture); + } + + componentElement.Add(new XAttribute("nodes", string.Join(";", nodeCoords))); + + return componentElement; + } + protected override void ShallowRemoveComponentSpecific() { for (int i = 0; i < 2; i++) diff --git a/Barotrauma/BarotraumaShared/Source/Items/Item.cs b/Barotrauma/BarotraumaShared/Source/Items/Item.cs index 9ff26a81e..48912e473 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Item.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Item.cs @@ -1676,7 +1676,53 @@ namespace Barotrauma break; } + } + public override XElement Save(XElement parentElement) + { + XElement element = new XElement("Item"); + + element.Add(new XAttribute("name", prefab.Name), + new XAttribute("ID", ID)); + + System.Diagnostics.Debug.Assert(Submarine != null); + + if (ResizeHorizontal || ResizeVertical) + { + element.Add(new XAttribute("rect", + (int)(rect.X - Submarine.HiddenSubPosition.X) + "," + + (int)(rect.Y - Submarine.HiddenSubPosition.Y) + "," + + rect.Width + "," + rect.Height)); + } + else + { + element.Add(new XAttribute("rect", + (int)(rect.X - Submarine.HiddenSubPosition.X) + "," + + (int)(rect.Y - Submarine.HiddenSubPosition.Y))); + } + + if (linkedTo != null && linkedTo.Count > 0) + { + string[] linkedToIDs = new string[linkedTo.Count]; + + for (int i = 0; i < linkedTo.Count; i++) + { + linkedToIDs[i] = linkedTo[i].ID.ToString(); + } + + element.Add(new XAttribute("linked", string.Join(",", linkedToIDs))); + } + + ObjectProperty.SaveProperties(this, element); + + foreach (ItemComponent ic in components) + { + ic.Save(element); + } + + parentElement.Add(element); + + return element; } public override void OnMapLoaded() diff --git a/Barotrauma/BarotraumaShared/Source/Map/Gap.cs b/Barotrauma/BarotraumaShared/Source/Map/Gap.cs index d39c31d81..0c8f027b0 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Gap.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Gap.cs @@ -685,12 +685,24 @@ namespace Barotrauma g.ID = (ushort)int.Parse(element.Attribute("ID").Value); g.linkedToID = new List(); - //int i = 0; - //while (element.Attribute("linkedto" + i) != null) - //{ - // g.linkedToID.Add(int.Parse(element.Attribute("linkedto" + i).Value)); - // i += 1; - //} + } + + public override XElement Save(XElement parentElement) + { + XElement element = new XElement("Gap"); + + element.Add( + new XAttribute("ID", ID), + new XAttribute("horizontal", isHorizontal ? "true" : "false")); + + element.Add(new XAttribute("rect", + (int)(rect.X - Submarine.HiddenSubPosition.X) + "," + + (int)(rect.Y - Submarine.HiddenSubPosition.Y) + "," + + rect.Width + "," + rect.Height)); + + parentElement.Add(element); + + return element; } } } diff --git a/Barotrauma/BarotraumaShared/Source/Map/Hull.cs b/Barotrauma/BarotraumaShared/Source/Map/Hull.cs index 0e9e56fd7..9bc5ed30c 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Hull.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Hull.cs @@ -735,6 +735,25 @@ namespace Barotrauma h.ID = (ushort)int.Parse(element.Attribute("ID").Value); } - + + public override XElement Save(XElement parentElement) + { + XElement element = new XElement("Hull"); + + element.Add + ( + new XAttribute("ID", ID), + new XAttribute("rect", + (int)(rect.X - Submarine.HiddenSubPosition.X) + "," + + (int)(rect.Y - Submarine.HiddenSubPosition.Y) + "," + + rect.Width + "," + rect.Height), + new XAttribute("water", volume) + ); + + parentElement.Add(element); + + return element; + } + } } diff --git a/Barotrauma/BarotraumaShared/Source/Map/LinkedSubmarine.cs b/Barotrauma/BarotraumaShared/Source/Map/LinkedSubmarine.cs index 60b9b6912..4c146c675 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/LinkedSubmarine.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/LinkedSubmarine.cs @@ -237,5 +237,86 @@ namespace Barotrauma sub.SetPosition(sub.WorldPosition - Submarine.WorldPosition); sub.Submarine = Submarine; } + + public override XElement Save(XElement parentElement) + { + XElement saveElement = null; + + if (sub == null) + { + if (this.saveElement == null) + { + var doc = Submarine.OpenFile(filePath); + saveElement = doc.Root; + + saveElement.Name = "LinkedSubmarine"; + + saveElement.Add(new XAttribute("filepath", filePath)); + } + else + { + saveElement = this.saveElement; + } + + if (saveElement.Attribute("pos") != null) saveElement.Attribute("pos").Remove(); + saveElement.Add(new XAttribute("pos", ToolBox.Vector2ToString(Position - Submarine.HiddenSubPosition))); + + + + var linkedPort = linkedTo.FirstOrDefault(lt => (lt is Item) && ((Item)lt).GetComponent() != null); + if (linkedPort != null) + { + if (saveElement.Attribute("linkedto") != null) saveElement.Attribute("linkedto").Remove(); + + saveElement.Add(new XAttribute("linkedto", linkedPort.ID)); + } + } + else + { + + saveElement = new XElement("LinkedSubmarine"); + + + sub.SaveToXElement(saveElement); + } + + if (sub != null) + { + bool leaveBehind = false; + if (!sub.DockedTo.Contains(Submarine.MainSub)) + { + System.Diagnostics.Debug.Assert(Submarine.MainSub.AtEndPosition || Submarine.MainSub.AtStartPosition); + if (Submarine.MainSub.AtEndPosition) + { + leaveBehind = sub.AtEndPosition != Submarine.MainSub.AtEndPosition; + } + else + { + leaveBehind = sub.AtStartPosition != Submarine.MainSub.AtStartPosition; + } + } + + + if (leaveBehind) + { + saveElement.SetAttributeValue("location", Level.Loaded.Seed); + saveElement.SetAttributeValue("worldpos", ToolBox.Vector2ToString(sub.SubBody.Position)); + + } + else + { + if (saveElement.Attribute("location") != null) saveElement.Attribute("location").Remove(); + if (saveElement.Attribute("worldpos") != null) saveElement.Attribute("worldpos").Remove(); + } + + saveElement.SetAttributeValue("pos", ToolBox.Vector2ToString(Position - Submarine.HiddenSubPosition)); + } + + + + parentElement.Add(saveElement); + + return saveElement; + } } } diff --git a/Barotrauma/BarotraumaShared/Source/Map/MapEntity.cs b/Barotrauma/BarotraumaShared/Source/Map/MapEntity.cs index 0315b2eaf..c4d645b88 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/MapEntity.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/MapEntity.cs @@ -3,10 +3,10 @@ using FarseerPhysics; using Microsoft.Xna.Framework; using System; using System.Collections.Generic; -//using Microsoft.Xna.Framework.Graphics; using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; +using System.Xml.Linq; namespace Barotrauma { @@ -89,6 +89,15 @@ namespace Barotrauma get { return false; } } + protected bool ResizeHorizontal + { + get { return prefab != null && prefab.ResizeHorizontal; } + } + protected bool ResizeVertical + { + get { return prefab != null && prefab.ResizeVertical; } + } + public virtual bool SelectableInEditor { get { return true; } @@ -374,10 +383,14 @@ namespace Barotrauma linkedSub.OnMapLoaded(); } } - - - public virtual void OnMapLoaded() { } + public virtual void OnMapLoaded() { } + + public virtual XElement Save(XElement parentElement) + { + DebugConsole.ThrowError("Saving entity " + GetType() + " failed."); + return null; + } public void RemoveLinked(MapEntity e) { diff --git a/Barotrauma/BarotraumaShared/Source/Map/Structure.cs b/Barotrauma/BarotraumaShared/Source/Map/Structure.cs index 1f6fc9355..60034959e 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Structure.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Structure.cs @@ -856,6 +856,39 @@ namespace Barotrauma } } + public override XElement Save(XElement parentElement) + { + XElement element = new XElement("Structure"); + + element.Add(new XAttribute("name", prefab.Name), + new XAttribute("ID", ID), + new XAttribute("rect", + (int)(rect.X - Submarine.HiddenSubPosition.X) + "," + + (int)(rect.Y - Submarine.HiddenSubPosition.Y) + "," + + rect.Width + "," + rect.Height)); + + for (int i = 0; i < sections.Length; i++) + { + if (sections[i].damage == 0.0f) continue; + + var sectionElement = + new XElement("section", + new XAttribute("i", i), + new XAttribute("damage", sections[i].damage)); + + if (sections[i].gap != null) + { + sectionElement.Add(new XAttribute("gap", sections[i].gap.ID)); + } + + element.Add(sectionElement); + } + + parentElement.Add(element); + + return element; + } + public override void OnMapLoaded() { foreach (WallSection s in sections) diff --git a/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs b/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs index fa2630d29..59fff3778 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs @@ -1105,6 +1105,50 @@ namespace Barotrauma return sub; } + + public bool Save() + { + return SaveAs(filePath); + } + + public bool SaveAs(string filePath) + { + name = System.IO.Path.GetFileNameWithoutExtension(filePath); + + XDocument doc = new XDocument(new XElement("Submarine")); + SaveToXElement(doc.Root); + + hash = new Md5Hash(doc); + doc.Root.Add(new XAttribute("md5hash", hash.Hash)); + + try + { + SaveUtil.CompressStringToFile(filePath, doc.ToString()); + } + catch (Exception e) + { + DebugConsole.ThrowError("Saving submarine \"" + filePath + "\" failed!", e); + return false; + } + + return true; + } + + public void SaveToXElement(XElement element) + { + element.Add(new XAttribute("name", name)); + element.Add(new XAttribute("description", Description == null ? "" : Description)); + + element.Add(new XAttribute("tags", tags.ToString())); + + foreach (MapEntity e in MapEntity.mapEntityList) + { + if (e.MoveWithLevel || e.Submarine != this) continue; + e.Save(element); + } + } + + public static bool Unloading { get; diff --git a/Barotrauma/BarotraumaShared/Source/Map/WayPoint.cs b/Barotrauma/BarotraumaShared/Source/Map/WayPoint.cs index 781351c74..1b08cfc52 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/WayPoint.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/WayPoint.cs @@ -594,6 +594,42 @@ namespace Barotrauma } } + public override XElement Save(XElement parentElement) + { + if (MoveWithLevel) return null; + XElement element = new XElement("WayPoint"); + + element.Add(new XAttribute("ID", ID), + new XAttribute("x", (int)(rect.X - Submarine.HiddenSubPosition.X)), + new XAttribute("y", (int)(rect.Y - Submarine.HiddenSubPosition.Y)), + new XAttribute("spawn", spawnType)); + + if (idCardTags.Length > 0) + { + element.Add(new XAttribute("idcardtags", string.Join(",", idCardTags))); + } + + if (assignedJob != null) element.Add(new XAttribute("job", assignedJob.Name)); + + + if (ConnectedGap != null) element.Add(new XAttribute("gap", ConnectedGap.ID)); + if (Ladders != null) element.Add(new XAttribute("ladders", Ladders.Item.ID)); + + parentElement.Add(element); + + if (linkedTo != null) + { + int i = 0; + foreach (MapEntity e in linkedTo) + { + element.Add(new XAttribute("linkedto" + i, e.ID)); + i += 1; + } + } + + return element; + } + public override void ShallowRemove() { base.ShallowRemove();