Fix bug where lathe databases didn't get serialized correctly. (#252)

This commit is contained in:
Víctor Aguilera Puerto
2019-06-02 01:18:54 +02:00
committed by Pieter-Jan Briers
parent dd13d969b2
commit 50bc1bff48
2 changed files with 24 additions and 17 deletions

View File

@@ -44,17 +44,5 @@ namespace Content.Server.GameObjects.Components.Research
Dirty(); Dirty();
return true; return true;
} }
private List<string> GetRecipeIdList()
{
var list = new List<string>();
foreach (var recipe in this)
{
list.Add(recipe.ID);
}
return list;
}
} }
} }

View File

@@ -75,6 +75,8 @@ namespace Content.Shared.GameObjects.Components.Research
{ {
base.ExposeData(serializer); base.ExposeData(serializer);
if (serializer.Reading)
{
var recipes = serializer.ReadDataField("recipes", new List<string>()); var recipes = serializer.ReadDataField("recipes", new List<string>());
var prototypeManager = IoCManager.Resolve<IPrototypeManager>(); var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
foreach (var id in recipes) foreach (var id in recipes)
@@ -82,6 +84,23 @@ namespace Content.Shared.GameObjects.Components.Research
if (!prototypeManager.TryIndex(id, out LatheRecipePrototype recipe)) continue; if (!prototypeManager.TryIndex(id, out LatheRecipePrototype recipe)) continue;
_recipes.Add(recipe); _recipes.Add(recipe);
} }
} else if (serializer.Writing)
{
var recipes = GetRecipeIdList();
serializer.DataField(ref recipes, "recipes", new List<string>());
}
}
public List<string> GetRecipeIdList()
{
var list = new List<string>();
foreach (var recipe in this)
{
list.Add(recipe.ID);
}
return list;
} }
public IEnumerator<LatheRecipePrototype> GetEnumerator() public IEnumerator<LatheRecipePrototype> GetEnumerator()