Fixed docking ports creating duplicate hulls and gaps during loading

This commit is contained in:
Joonas Rikkonen
2018-07-24 13:21:36 +03:00
parent 5e6215a37c
commit 4a8845c604
3 changed files with 23 additions and 15 deletions

View File

@@ -418,9 +418,7 @@ namespace Barotrauma.Items.Components
}
gap = new Gap(new Rectangle(hullRects[0].Right - 2, hullRects[0].Y, 4, hullRects[0].Height), true, subs[0]);
if (gapId != null) gap.ID = (ushort)gapId;
LinkHullsToGap();
if (gapId != null) gap.ID = (ushort)gapId;
}
else
{
@@ -443,19 +441,20 @@ namespace Barotrauma.Items.Components
gap = new Gap(new Rectangle(hullRects[0].X, hullRects[0].Y+2, hullRects[0].Width, 4), false, subs[0]);
if (gapId != null) gap.ID = (ushort)gapId;
LinkHullsToGap();
}
item.linkedTo.Add(hulls[0]);
item.linkedTo.Add(hulls[1]);
LinkHullsToGap();
hullIds[0] = hulls[0].ID;
hullIds[1] = hulls[1].ID;
hulls[0].ShouldBeSaved = false;
hulls[1].ShouldBeSaved = false;
item.linkedTo.Add(hulls[0]);
item.linkedTo.Add(hulls[1]);
gap.DisableHullRechecks = true;
gap.ShouldBeSaved = false;
gapId = gap.ID;
item.linkedTo.Add(gap);
foreach (Body body in bodies)

View File

@@ -29,6 +29,8 @@ namespace Barotrauma
get;
set;
}
public bool ShouldBeSaved = true;
//the position and dimensions of the entity
protected Rectangle rect;
@@ -45,7 +47,8 @@ namespace Barotrauma
private static bool resizing;
private int resizeDirX, resizeDirY;
public virtual Rectangle Rect {
public virtual Rectangle Rect
{
get { return rect; }
set { rect = value; }
}
@@ -353,15 +356,12 @@ namespace Barotrauma
foreach (ushort i in e.linkedToID)
{
MapEntity linked = FindEntityByID(i) as MapEntity;
if (linked != null) e.linkedTo.Add(linked);
if (FindEntityByID(i) is MapEntity linked) e.linkedTo.Add(linked);
}
}
List<LinkedSubmarine> linkedSubs = new List<LinkedSubmarine>();
for (int i = 0; i<mapEntityList.Count; i++)
for (int i = 0; i < mapEntityList.Count; i++)
{
if (mapEntityList[i].Submarine != sub) continue;

View File

@@ -1232,7 +1232,16 @@ namespace Barotrauma
foreach (MapEntity e in MapEntity.mapEntityList)
{
if (e.MoveWithLevel || e.Submarine != this) continue;
if (e.linkedTo == null) continue;
for (int i = e.linkedTo.Count - 1; i >= 0; i--)
{
if (!e.linkedTo[i].ShouldBeSaved) e.linkedTo.RemoveAt(i);
}
}
foreach (MapEntity e in MapEntity.mapEntityList)
{
if (e.MoveWithLevel || e.Submarine != this || !e.ShouldBeSaved) continue;
e.Save(element);
}
}