Added error checking and logging to wire cloning logic in MapEntity.Clone (see #527)
This commit is contained in:
@@ -220,12 +220,29 @@ namespace Barotrauma
|
|||||||
|
|
||||||
var connectedItem = originalWire.Connections[n].Item;
|
var connectedItem = originalWire.Connections[n].Item;
|
||||||
if (connectedItem == null) continue;
|
if (connectedItem == null) continue;
|
||||||
|
|
||||||
//index of the item the wire is connected to
|
//index of the item the wire is connected to
|
||||||
int itemIndex = entitiesToClone.IndexOf(connectedItem);
|
int itemIndex = entitiesToClone.IndexOf(connectedItem);
|
||||||
|
if (itemIndex < 0)
|
||||||
|
{
|
||||||
|
DebugConsole.ThrowError("Error while cloning wires - item \"" + connectedItem.Name + "\" was not found in entities to clone.");
|
||||||
|
GameAnalyticsManager.AddErrorEventOnce("MapEntity.Clone:ConnectedNotFound" + connectedItem.ID,
|
||||||
|
GameAnalyticsSDK.Net.EGAErrorSeverity.Error,
|
||||||
|
"Error while cloning wires - item \"" + connectedItem.Name + "\" was not found in entities to clone.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
//index of the connection in the connectionpanel of the target item
|
//index of the connection in the connectionpanel of the target item
|
||||||
int connectionIndex = connectedItem.Connections.IndexOf(originalWire.Connections[n]);
|
int connectionIndex = connectedItem.Connections.IndexOf(originalWire.Connections[n]);
|
||||||
|
if (connectionIndex < 0)
|
||||||
|
{
|
||||||
|
DebugConsole.ThrowError("Error while cloning wires - connection \"" + originalWire.Connections[n].Name + "\" was not found in connected item \"" + connectedItem.Name + "\".");
|
||||||
|
GameAnalyticsManager.AddErrorEventOnce("MapEntity.Clone:ConnectionNotFound" + connectedItem.ID,
|
||||||
|
GameAnalyticsSDK.Net.EGAErrorSeverity.Error,
|
||||||
|
"Error while cloning wires - connection \"" + originalWire.Connections[n].Name + "\" was not found in connected item \"" + connectedItem.Name + "\".");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
(clones[itemIndex] as Item).Connections[connectionIndex].TryAddLink(cloneWire);
|
(clones[itemIndex] as Item).Connections[connectionIndex].TryAddLink(cloneWire);
|
||||||
cloneWire.Connect((clones[itemIndex] as Item).Connections[connectionIndex], false);
|
cloneWire.Connect((clones[itemIndex] as Item).Connections[connectionIndex], false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user