Add two-way serialization in ExposeData for some of the components that are missing it (#1451)

This commit is contained in:
DrSmugleaf
2020-07-23 01:46:09 +02:00
committed by GitHub
parent 989025b222
commit a8b3c99075
19 changed files with 252 additions and 172 deletions

View File

@@ -65,23 +65,25 @@ namespace Content.Shared.GameObjects.Components.Cargo
{
base.ExposeData(serializer);
if (serializer.Reading)
{
var products = serializer.ReadDataField("products", new List<string>());
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
_products.Clear();
foreach (var id in products)
serializer.DataReadWriteFunction(
"products",
new List<string>(),
products =>
{
if (!prototypeManager.TryIndex(id, out CargoProductPrototype product))
continue;
_products.Add(product);
}
}
else if (serializer.Writing)
{
var products = GetProductIdList();
serializer.DataField(ref products, "products", new List<string>());
}
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
_products.Clear();
foreach (var id in products)
{
if (!prototypeManager.TryIndex(id, out CargoProductPrototype product))
{
continue;
}
_products.Add(product);
}
},
GetProductIdList);
}
}

View File

@@ -28,7 +28,7 @@ namespace Content.Shared.GameObjects.Components.Materials
base.ExposeData(serializer);
// TODO: Writing.
if (!serializer.Reading)
if (serializer.Writing)
{
return;
}
@@ -61,7 +61,7 @@ namespace Content.Shared.GameObjects.Components.Materials
public void ExposeData(ObjectSerializer serializer)
{
if (!serializer.Reading)
if (serializer.Writing)
{
return;
}

View File

@@ -74,20 +74,23 @@ namespace Content.Shared.GameObjects.Components.Research
{
base.ExposeData(serializer);
if (serializer.Reading)
{
var recipes = serializer.ReadDataField("recipes", new List<string>());
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
foreach (var id in recipes)
serializer.DataReadWriteFunction(
"recipes",
new List<string>(),
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<string>());
}
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
foreach (var id in recipes)
{
if (prototypeManager.TryIndex(id, out LatheRecipePrototype recipe))
{
_recipes.Add(recipe);
}
}
},
GetRecipeIdList);
}
public List<string> GetRecipeIdList()

View File

@@ -26,20 +26,22 @@ namespace Content.Shared.GameObjects.Components.Research
{
base.ExposeData(serializer);
if (serializer.Reading)
{
var recipes = serializer.ReadDataField("protolatherecipes", new List<string>());
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
foreach (var id in recipes)
serializer.DataReadWriteFunction(
"protolatherecipes",
new List<string>(),
recipes =>
{
if (!prototypeManager.TryIndex(id, out LatheRecipePrototype recipe)) continue;
_protolatheRecipes.Add(recipe);
}
} else if (serializer.Writing)
{
var recipes = GetProtolatheRecipeIdList();
serializer.DataField(ref recipes, "protolatherecipes", new List<string>());
}
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
foreach (var id in recipes)
{
if (prototypeManager.TryIndex(id, out LatheRecipePrototype recipe))
{
_protolatheRecipes.Add(recipe);
}
}
},
GetProtolatheRecipeIdList);
}
/// <summary>

View File

@@ -83,20 +83,21 @@ namespace Content.Shared.GameObjects.Components.Research
{
base.ExposeData(serializer);
if (serializer.Reading)
{
var techs = serializer.ReadDataField("technologies", new List<string>());
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
foreach (var id in techs)
serializer.DataReadWriteFunction(
"technologies",
new List<string>(),
techs =>
{
if (!prototypeManager.TryIndex(id, out TechnologyPrototype tech)) continue;
_technologies.Add(tech);
}
} else if (serializer.Writing)
{
var techs = GetTechnologyIdList();
serializer.DataField(ref techs, "technologies", new List<string>());
}
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
foreach (var id in techs)
{
if (prototypeManager.TryIndex(id, out TechnologyPrototype tech))
{
_technologies.Add(tech);
}
}
}, GetTechnologyIdList);
}
}

View File

@@ -53,7 +53,7 @@ namespace Content.Shared.GameObjects.Components
serializer.DataFieldCached(ref _maxCount, "max", 50);
serializer.DataFieldCached(ref _count, "count", MaxCount);
if (!serializer.Reading)
if (serializer.Writing)
{
return;
}

View File

@@ -108,7 +108,7 @@ namespace Content.Shared.GameObjects.Components.Sound
public void ExposeData(ObjectSerializer serializer)
{
if (!serializer.Reading)
if (serializer.Writing)
return;
Filename = serializer.ReadDataField("filename", "");