From b7518fa8122779181a55c2ad1aeea93068292d64 Mon Sep 17 00:00:00 2001 From: Regalis Date: Fri, 26 May 2017 20:03:38 +0300 Subject: [PATCH] Item connections are cached in the Item constructor instead of OnMapLoaded (-> buttons created mid-round work now) --- Subsurface/Source/Items/Item.cs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index a6d46d672..a2eae6222 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -408,15 +408,27 @@ namespace Barotrauma break; } } - + + //cache connections into a dictionary for faster lookups + var connectionPanel = GetComponent(); + if (connectionPanel != null) + { + connections = new Dictionary(); + foreach (Connection c in connectionPanel.Connections) + { + if (!connections.ContainsKey(c.Name)) + connections.Add(c.Name, c); + } + } + //containers need to handle collision events to notify items inside them about the impact - if (ImpactTolerance > 0.0f || GetComponent() != null) + var itemContainer = GetComponent(); + if (ImpactTolerance > 0.0f || itemContainer != null) { if (body != null) body.FarseerBody.OnCollision += OnCollision; } - var itemContainer = GetComponent(); - if (itemContainer!=null) + if (itemContainer != null) { ownInventory = itemContainer.Inventory; } @@ -2244,17 +2256,6 @@ namespace Barotrauma { ic.OnMapLoaded(); } - - //cache connections into a dictionary for faster lookups - var connectionPanel = GetComponent(); - connections = new Dictionary(); - - if (connectionPanel == null) return; - foreach (Connection c in connectionPanel.Connections) - { - if (!connections.ContainsKey(c.Name)) - connections.Add(c.Name, c); - } }