Add two-way serialization in ExposeData for some of the components that are missing it (#1451)
This commit is contained in:
@@ -152,15 +152,11 @@ namespace Content.Client.GameObjects
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
if (!serializer.Reading)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var slot in serializer.ReadDataFieldCached("hands", new List<string>()))
|
||||
{
|
||||
_hands.Add(slot, null);
|
||||
}
|
||||
serializer.DataReadWriteFunction(
|
||||
"hands",
|
||||
new List<string>(),
|
||||
hands => hands.ForEach(slot => _hands.Add(slot, null)),
|
||||
() => _hands.Keys.ToList());
|
||||
|
||||
serializer.DataField(this, x => ActiveIndex, "defaultHand", _hands.Keys.LastOrDefault());
|
||||
}
|
||||
|
||||
@@ -96,14 +96,11 @@ namespace Content.Client.GameObjects.Components.Sound
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
if (serializer.Writing) return;
|
||||
serializer.TryReadDataField("schedules", out List<ScheduledSound> schedules);
|
||||
if (schedules == null) return;
|
||||
foreach (var schedule in schedules)
|
||||
{
|
||||
if (schedule == null) continue;
|
||||
AddScheduledSound(schedule);
|
||||
}
|
||||
|
||||
serializer.DataReadFunction(
|
||||
"schedules",
|
||||
new List<ScheduledSound>(),
|
||||
schedules => schedules.ForEach(AddScheduledSound));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,16 +61,10 @@ namespace Content.Server.GameObjects
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
// TODO: This does not serialize what objects are held.
|
||||
serializer.DataField(ref _orderedHands, "hands", new List<string>(0));
|
||||
if (serializer.Reading)
|
||||
{
|
||||
foreach (var handsname in _orderedHands)
|
||||
{
|
||||
AddHand(handsname);
|
||||
}
|
||||
}
|
||||
|
||||
serializer.DataReadWriteFunction("hands",
|
||||
new List<string>(0),
|
||||
hands => hands.ForEach(AddHand),
|
||||
() => _orderedHands);
|
||||
serializer.DataField(ref _activeIndex, "defaultHand", _orderedHands.LastOrDefault());
|
||||
}
|
||||
|
||||
|
||||
@@ -65,14 +65,25 @@ namespace Content.Server.GameObjects.Components.Interactable
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
if (serializer.Reading)
|
||||
{
|
||||
var qualities = serializer.ReadDataField("qualities", new List<ToolQuality>());
|
||||
foreach (var quality in qualities)
|
||||
serializer.DataReadWriteFunction(
|
||||
"qualities",
|
||||
new List<ToolQuality>(),
|
||||
qualities => qualities.ForEach(AddQuality),
|
||||
() =>
|
||||
{
|
||||
AddQuality(quality);
|
||||
}
|
||||
}
|
||||
var qualities = new List<ToolQuality>();
|
||||
|
||||
foreach (ToolQuality quality in Enum.GetValues(typeof(ToolQuality)))
|
||||
{
|
||||
if ((_qualities & quality) != 0)
|
||||
{
|
||||
qualities.Add(quality);
|
||||
}
|
||||
}
|
||||
|
||||
return qualities;
|
||||
});
|
||||
|
||||
serializer.DataField(this, mod => SpeedModifier, "speed", 1);
|
||||
serializer.DataField(this, use => UseSound, "useSound", string.Empty);
|
||||
serializer.DataField(this, collection => UseSoundCollection, "useSoundCollection", string.Empty);
|
||||
|
||||
@@ -44,19 +44,29 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _useSound, "useSound", "/Audio/Items/eatfood.ogg");
|
||||
serializer.DataField(ref _transferAmount, "transferAmount", ReagentUnit.New(5));
|
||||
serializer.DataField(ref _trashPrototype, "trash", null);
|
||||
|
||||
if (serializer.Reading)
|
||||
{
|
||||
var utensils = serializer.ReadDataField("utensils", new List<UtensilType>());
|
||||
foreach (var utensil in utensils)
|
||||
serializer.DataReadWriteFunction(
|
||||
"utensils",
|
||||
new List<UtensilType>(),
|
||||
types => types.ForEach(type => _utensilsNeeded |= type),
|
||||
() =>
|
||||
{
|
||||
_utensilsNeeded |= utensil;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
var types = new List<UtensilType>();
|
||||
|
||||
foreach (UtensilType type in Enum.GetValues(typeof(UtensilType)))
|
||||
{
|
||||
if ((_utensilsNeeded & type) != 0)
|
||||
{
|
||||
types.Add(type);
|
||||
}
|
||||
}
|
||||
|
||||
return types;
|
||||
});
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.GameObjects.Components.Nutrition;
|
||||
using Content.Server.Utility;
|
||||
using Content.Shared.GameObjects.Components.Utensil;
|
||||
@@ -83,14 +84,23 @@ namespace Content.Server.GameObjects.Components.Utensil
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
if (serializer.Reading)
|
||||
{
|
||||
var types = serializer.ReadDataField("types", new List<UtensilType>());
|
||||
foreach (var type in types)
|
||||
serializer.DataReadWriteFunction("types",
|
||||
new List<UtensilType>(),
|
||||
types => types.ForEach(AddType),
|
||||
() =>
|
||||
{
|
||||
AddType(type);
|
||||
}
|
||||
}
|
||||
var types = new List<UtensilType>();
|
||||
|
||||
foreach (UtensilType type in Enum.GetValues(typeof(UtensilType)))
|
||||
{
|
||||
if ((Types & type) != 0)
|
||||
{
|
||||
types.Add(type);
|
||||
}
|
||||
}
|
||||
|
||||
return types;
|
||||
});
|
||||
|
||||
serializer.DataField(ref _breakChance, "breakChance", 0);
|
||||
serializer.DataField(ref _breakSound, "breakSound", "/Audio/Items/snap.ogg");
|
||||
|
||||
@@ -44,15 +44,13 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _caliber, "caliber", BallisticCaliber.Unspecified);
|
||||
|
||||
if (serializer.Reading)
|
||||
{
|
||||
var capacity = serializer.ReadDataField("capacity", 6);
|
||||
_ammoSlots = new IEntity[capacity];
|
||||
}
|
||||
|
||||
// TODO: Writing?
|
||||
serializer.DataReadWriteFunction(
|
||||
"capacity",
|
||||
6,
|
||||
cap => _ammoSlots = new IEntity[cap],
|
||||
() => _ammoSlots.Length);
|
||||
serializer.DataField(ref _fillPrototype, "fillPrototype", null);
|
||||
|
||||
// Sounds
|
||||
|
||||
@@ -75,11 +75,8 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
if (serializer.Reading)
|
||||
{
|
||||
_powerCellPrototype = serializer.ReadDataField<string>("powerCellPrototype", null);
|
||||
}
|
||||
|
||||
serializer.DataField(ref _powerCellPrototype, "powerCellPrototype", null);
|
||||
serializer.DataField(ref _powerCellRemovable, "powerCellRemovable", false);
|
||||
serializer.DataField(ref _baseFireCost, "fireCost", 300);
|
||||
serializer.DataField(ref _ammoPrototype, "ammoPrototype", null);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -84,31 +84,57 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _fireRateSelector, "currentSelector", FireRateSelector.Safety);
|
||||
serializer.DataField(ref _fireRate, "fireRate", 2.0f);
|
||||
|
||||
// This hard-to-read area's dealing with recoil
|
||||
// Use degrees in yaml as it's easier to read compared to "0.0125f"
|
||||
if (serializer.Reading)
|
||||
{
|
||||
var minAngle = serializer.ReadDataField("minAngle", 0) / 2;
|
||||
_minAngle = Angle.FromDegrees(minAngle);
|
||||
// Random doubles it as it's +/- so uhh we'll just half it here for readability
|
||||
var maxAngle = serializer.ReadDataField("maxAngle", 45) / 2;
|
||||
_maxAngle = Angle.FromDegrees(maxAngle);
|
||||
var angleIncrease = serializer.ReadDataField("angleIncrease", (40 / _fireRate));
|
||||
_angleIncrease = angleIncrease * (float) Math.PI / 180;
|
||||
var angleDecay = serializer.ReadDataField("angleDecay", (float) 20);
|
||||
_angleDecay = angleDecay * (float) Math.PI / 180;
|
||||
serializer.DataField(ref _spreadRatio, "ammoSpreadRatio", 1.0f);
|
||||
serializer.DataReadWriteFunction(
|
||||
"minAngle",
|
||||
0,
|
||||
angle => _minAngle = Angle.FromDegrees(angle / 2f),
|
||||
() => _minAngle.Degrees * 2);
|
||||
|
||||
// FireRate options
|
||||
var allFireRates = serializer.ReadDataField("allSelectors", new List<FireRateSelector>());
|
||||
foreach (var fireRate in allFireRates)
|
||||
// Random doubles it as it's +/- so uhh we'll just half it here for readability
|
||||
serializer.DataReadWriteFunction(
|
||||
"maxAngle",
|
||||
45,
|
||||
angle => _maxAngle = Angle.FromDegrees(angle / 2f),
|
||||
() => _maxAngle.Degrees * 2);
|
||||
|
||||
serializer.DataReadWriteFunction(
|
||||
"angleIncrease",
|
||||
40 / _fireRate,
|
||||
angle => _angleIncrease = angle * (float) Math.PI / 180,
|
||||
() => _angleIncrease / (float) Math.PI / 180);
|
||||
|
||||
serializer.DataReadWriteFunction(
|
||||
"angleDecay",
|
||||
20f,
|
||||
angle => _angleDecay = angle * (float) Math.PI / 180,
|
||||
() => _angleDecay / (float) Math.PI / 180);
|
||||
|
||||
serializer.DataField(ref _spreadRatio, "ammoSpreadRatio", 1.0f);
|
||||
|
||||
serializer.DataReadWriteFunction(
|
||||
"allSelectors",
|
||||
new List<FireRateSelector>(),
|
||||
selectors => selectors.ForEach(selector => _allRateSelectors |= selector),
|
||||
() =>
|
||||
{
|
||||
_allRateSelectors |= fireRate;
|
||||
}
|
||||
}
|
||||
var types = new List<FireRateSelector>();
|
||||
|
||||
foreach (FireRateSelector selector in Enum.GetValues(typeof(FireRateSelector)))
|
||||
{
|
||||
if ((_allRateSelectors & selector) != 0)
|
||||
{
|
||||
types.Add(selector);
|
||||
}
|
||||
}
|
||||
|
||||
return types;
|
||||
});
|
||||
|
||||
// For simplicity we'll enforce it this way; ammo determines max spread
|
||||
if (_spreadRatio > 1.0f)
|
||||
@@ -118,6 +144,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
|
||||
}
|
||||
|
||||
serializer.DataField(ref _canMuzzleFlash, "canMuzzleFlash", true);
|
||||
|
||||
// Sounds
|
||||
serializer.DataField(ref _soundGunshot, "soundGunshot", null);
|
||||
serializer.DataField(ref _soundEmpty, "soundEmpty", "/Audio/Weapons/Guns/Empty/empty.ogg");
|
||||
|
||||
@@ -25,6 +25,9 @@ namespace Content.Server.BodySystem {
|
||||
[ViewVariables]
|
||||
private BodyTemplate _template;
|
||||
|
||||
[ViewVariables]
|
||||
private string _presetName;
|
||||
|
||||
[ViewVariables]
|
||||
private Dictionary<string, BodyPart> _partDictionary = new Dictionary<string, BodyPart>();
|
||||
|
||||
@@ -175,29 +178,46 @@ namespace Content.Server.BodySystem {
|
||||
///////// Server-specific stuff
|
||||
/////////
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer) {
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
string templateName = null;
|
||||
serializer.DataField(ref templateName, "BaseTemplate", "bodyTemplate.Humanoid");
|
||||
if (serializer.Reading) {
|
||||
if (!_prototypeManager.TryIndex(templateName, out BodyTemplatePrototype templateData))
|
||||
throw new InvalidOperationException("No BodyTemplatePrototype was found with the name " + templateName + " while loading a BodyTemplate!"); //Should never happen unless you fuck up the prototype.
|
||||
serializer.DataReadWriteFunction(
|
||||
"BaseTemplate",
|
||||
"bodyTemplate.Humanoid",
|
||||
template =>
|
||||
{
|
||||
if (!_prototypeManager.TryIndex(template, out BodyTemplatePrototype templateData))
|
||||
{
|
||||
throw new InvalidOperationException("No BodyTemplatePrototype was found with the name " + template + " while loading a BodyTemplate!"); //Should never happen unless you fuck up the prototype.
|
||||
}
|
||||
|
||||
string presetName = null;
|
||||
serializer.DataField(ref presetName, "BasePreset", "bodyPreset.BasicHuman");
|
||||
if (!_prototypeManager.TryIndex(presetName, out BodyPresetPrototype presetData))
|
||||
throw new InvalidOperationException("No BodyPresetPrototype was found with the name " + presetName + " while loading a BodyPreset!"); //Should never happen unless you fuck up the prototype.
|
||||
_template = new BodyTemplate(templateData);
|
||||
},
|
||||
() => _template.Name);
|
||||
|
||||
_template = new BodyTemplate(templateData);
|
||||
LoadBodyPreset(new BodyPreset(presetData));
|
||||
}
|
||||
serializer.DataReadWriteFunction(
|
||||
"BasePreset",
|
||||
"bodyPreset.BasicHuman",
|
||||
preset =>
|
||||
{
|
||||
if (!_prototypeManager.TryIndex(preset, out BodyPresetPrototype presetData))
|
||||
{
|
||||
throw new InvalidOperationException("No BodyPresetPrototype was found with the name " + preset + " while loading a BodyPreset!"); //Should never happen unless you fuck up the prototype.
|
||||
}
|
||||
|
||||
LoadBodyPreset(new BodyPreset(presetData));
|
||||
},
|
||||
() => _presetName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the given <see cref="BodyPreset"/> - forcefully changes all limbs found in both the preset and this template!
|
||||
/// </summary>
|
||||
public void LoadBodyPreset(BodyPreset preset) {
|
||||
public void LoadBodyPreset(BodyPreset preset)
|
||||
{
|
||||
_presetName = preset.Name;
|
||||
|
||||
foreach (var (slotName, type) in _template.Slots) {
|
||||
if (!preset.PartIDs.TryGetValue(slotName, out string partID)) { //For each slot in our BodyManagerComponent's template, try and grab what the ID of what the preset says should be inside it.
|
||||
continue; //If the preset doesn't define anything for it, continue.
|
||||
|
||||
@@ -45,16 +45,16 @@ namespace Content.Shared.Chemistry
|
||||
/// <inheritdoc />
|
||||
public void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
serializer.DataField(ref _contents, "reagents", new List<ReagentQuantity>());
|
||||
|
||||
if (serializer.Reading)
|
||||
{
|
||||
TotalVolume = ReagentUnit.New(0);
|
||||
foreach (var reagent in _contents)
|
||||
serializer.DataReadWriteFunction(
|
||||
"reagents",
|
||||
new List<ReagentQuantity>(),
|
||||
quantities =>
|
||||
{
|
||||
TotalVolume += reagent.Quantity;
|
||||
}
|
||||
}
|
||||
_contents = quantities;
|
||||
TotalVolume = ReagentUnit.New(0);
|
||||
quantities.ForEach(reagent => TotalVolume += reagent.Quantity);
|
||||
},
|
||||
() => _contents);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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", "");
|
||||
|
||||
Reference in New Issue
Block a user