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

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Content.Server.GameObjects.Components.Weapon.Ranged.Ammunition;
using Content.Shared.GameObjects;
using Content.Shared.GameObjects.Components.Weapons.Ranged;
@@ -95,14 +96,25 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
if (serializer.Reading)
{
var magTypes = serializer.ReadDataField("magazineTypes", new List<MagazineType>());
foreach (var mag in magTypes)
serializer.DataReadWriteFunction(
"magazineTypes",
new List<MagazineType>(),
types => types.ForEach(mag => _magazineTypes |= mag),
() =>
{
_magazineTypes |= mag;
}
}
var types = new List<MagazineType>();
foreach (MagazineType mag in Enum.GetValues(typeof(MagazineType)))
{
if ((_magazineTypes & mag) != 0)
{
types.Add(mag);
}
}
return types;
});
serializer.DataField(ref _caliber, "caliber", BallisticCaliber.Unspecified);
serializer.DataField(ref _magFillPrototype, "magFillPrototype", null);
serializer.DataField(ref _autoEjectMag, "autoEjectMag", false);