From 5495f88583a472cbc78c2c363f256cbe4edab81f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Aguilera=20Puerto?= Date: Thu, 18 Jun 2020 19:26:55 +0200 Subject: [PATCH] HandComponents now have a default hand, fixes crash --- .../GameObjects/Components/Items/ClientHandsComponent.cs | 4 +++- .../GameObjects/Components/GUI/ServerHandsComponent.cs | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Content.Client/GameObjects/Components/Items/ClientHandsComponent.cs b/Content.Client/GameObjects/Components/Items/ClientHandsComponent.cs index f7f1e3c815..b5ae7f7b05 100644 --- a/Content.Client/GameObjects/Components/Items/ClientHandsComponent.cs +++ b/Content.Client/GameObjects/Components/Items/ClientHandsComponent.cs @@ -59,7 +59,7 @@ namespace Content.Client.GameObjects public IEntity GetEntity(string index) { - if (_hands.TryGetValue(index, out var entity)) + if (!string.IsNullOrEmpty(index) && _hands.TryGetValue(index, out var entity)) { return entity; } @@ -166,6 +166,8 @@ namespace Content.Client.GameObjects { _hands.Add(slot, null); } + + serializer.DataField(this, x => ActiveIndex, "defaultHand", _hands.Keys.LastOrDefault()); } public override void HandleMessage(ComponentMessage message, IComponent component) diff --git a/Content.Server/GameObjects/Components/GUI/ServerHandsComponent.cs b/Content.Server/GameObjects/Components/GUI/ServerHandsComponent.cs index 7a3ac2e479..32ffcd0e82 100644 --- a/Content.Server/GameObjects/Components/GUI/ServerHandsComponent.cs +++ b/Content.Server/GameObjects/Components/GUI/ServerHandsComponent.cs @@ -3,6 +3,7 @@ using Robust.Shared.Utility; using System; using System.Collections.Generic; +using System.Linq; using Content.Server.GameObjects.EntitySystems; using Content.Server.Interfaces.GameObjects; using Content.Shared.GameObjects; @@ -68,6 +69,8 @@ namespace Content.Server.GameObjects AddHand(handsname); } } + + serializer.DataField(ref activeIndex, "defaultHand", orderedHands.LastOrDefault()); } public IEnumerable GetAllHeldItems()