From 50bc1bff487821dd89404458c91d4d2b15023e75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Aguilera=20Puerto?= <6766154+Zumorica@users.noreply.github.com> Date: Sun, 2 Jun 2019 01:18:54 +0200 Subject: [PATCH] Fix bug where lathe databases didn't get serialized correctly. (#252) --- .../Research/LatheDatabaseComponent.cs | 12 -------- .../Research/SharedLatheDatabaseComponent.cs | 29 +++++++++++++++---- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/Content.Server/GameObjects/Components/Research/LatheDatabaseComponent.cs b/Content.Server/GameObjects/Components/Research/LatheDatabaseComponent.cs index b0d6c85e37..f6fcb395d5 100644 --- a/Content.Server/GameObjects/Components/Research/LatheDatabaseComponent.cs +++ b/Content.Server/GameObjects/Components/Research/LatheDatabaseComponent.cs @@ -44,17 +44,5 @@ namespace Content.Server.GameObjects.Components.Research Dirty(); return true; } - - private List GetRecipeIdList() - { - var list = new List(); - - foreach (var recipe in this) - { - list.Add(recipe.ID); - } - - return list; - } } } diff --git a/Content.Shared/GameObjects/Components/Research/SharedLatheDatabaseComponent.cs b/Content.Shared/GameObjects/Components/Research/SharedLatheDatabaseComponent.cs index 1471889e94..91ae1c1737 100644 --- a/Content.Shared/GameObjects/Components/Research/SharedLatheDatabaseComponent.cs +++ b/Content.Shared/GameObjects/Components/Research/SharedLatheDatabaseComponent.cs @@ -75,15 +75,34 @@ namespace Content.Shared.GameObjects.Components.Research { base.ExposeData(serializer); - var recipes = serializer.ReadDataField("recipes", new List()); - var prototypeManager = IoCManager.Resolve(); - foreach (var id in recipes) + if (serializer.Reading) { - if (!prototypeManager.TryIndex(id, out LatheRecipePrototype recipe)) continue; - _recipes.Add(recipe); + var recipes = serializer.ReadDataField("recipes", new List()); + var prototypeManager = IoCManager.Resolve(); + foreach (var id in recipes) + { + if (!prototypeManager.TryIndex(id, out LatheRecipePrototype recipe)) continue; + _recipes.Add(recipe); + } + } else if (serializer.Writing) + { + var recipes = GetRecipeIdList(); + serializer.DataField(ref recipes, "recipes", new List()); } } + public List GetRecipeIdList() + { + var list = new List(); + + foreach (var recipe in this) + { + list.Add(recipe.ID); + } + + return list; + } + public IEnumerator GetEnumerator() { return _recipes.GetEnumerator();