diff --git a/Content.Client/GameObjects/Components/Items/ClientHandsComponent.cs b/Content.Client/GameObjects/Components/Items/ClientHandsComponent.cs index f9411094a1..301f600838 100644 --- a/Content.Client/GameObjects/Components/Items/ClientHandsComponent.cs +++ b/Content.Client/GameObjects/Components/Items/ClientHandsComponent.cs @@ -152,15 +152,11 @@ namespace Content.Client.GameObjects { base.ExposeData(serializer); - if (!serializer.Reading) - { - return; - } - - foreach (var slot in serializer.ReadDataFieldCached("hands", new List())) - { - _hands.Add(slot, null); - } + serializer.DataReadWriteFunction( + "hands", + new List(), + hands => hands.ForEach(slot => _hands.Add(slot, null)), + () => _hands.Keys.ToList()); serializer.DataField(this, x => ActiveIndex, "defaultHand", _hands.Keys.LastOrDefault()); } diff --git a/Content.Client/GameObjects/Components/Sound/LoopingSoundComponent.cs b/Content.Client/GameObjects/Components/Sound/LoopingSoundComponent.cs index 3d83002d3f..6c6473a3f1 100644 --- a/Content.Client/GameObjects/Components/Sound/LoopingSoundComponent.cs +++ b/Content.Client/GameObjects/Components/Sound/LoopingSoundComponent.cs @@ -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 schedules); - if (schedules == null) return; - foreach (var schedule in schedules) - { - if (schedule == null) continue; - AddScheduledSound(schedule); - } + + serializer.DataReadFunction( + "schedules", + new List(), + schedules => schedules.ForEach(AddScheduledSound)); } } } diff --git a/Content.Server/GameObjects/Components/GUI/ServerHandsComponent.cs b/Content.Server/GameObjects/Components/GUI/ServerHandsComponent.cs index b43b315899..9e48f57663 100644 --- a/Content.Server/GameObjects/Components/GUI/ServerHandsComponent.cs +++ b/Content.Server/GameObjects/Components/GUI/ServerHandsComponent.cs @@ -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(0)); - if (serializer.Reading) - { - foreach (var handsname in _orderedHands) - { - AddHand(handsname); - } - } - + serializer.DataReadWriteFunction("hands", + new List(0), + hands => hands.ForEach(AddHand), + () => _orderedHands); serializer.DataField(ref _activeIndex, "defaultHand", _orderedHands.LastOrDefault()); } diff --git a/Content.Server/GameObjects/Components/Interactable/ToolComponent.cs b/Content.Server/GameObjects/Components/Interactable/ToolComponent.cs index 1f647ef0e4..1e4002bae8 100644 --- a/Content.Server/GameObjects/Components/Interactable/ToolComponent.cs +++ b/Content.Server/GameObjects/Components/Interactable/ToolComponent.cs @@ -65,14 +65,25 @@ namespace Content.Server.GameObjects.Components.Interactable { base.ExposeData(serializer); - if (serializer.Reading) - { - var qualities = serializer.ReadDataField("qualities", new List()); - foreach (var quality in qualities) + serializer.DataReadWriteFunction( + "qualities", + new List(), + qualities => qualities.ForEach(AddQuality), + () => { - AddQuality(quality); - } - } + var qualities = new List(); + + 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); diff --git a/Content.Server/GameObjects/Components/Nutrition/FoodComponent.cs b/Content.Server/GameObjects/Components/Nutrition/FoodComponent.cs index dc2da33143..8f86b72bd3 100644 --- a/Content.Server/GameObjects/Components/Nutrition/FoodComponent.cs +++ b/Content.Server/GameObjects/Components/Nutrition/FoodComponent.cs @@ -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()); - foreach (var utensil in utensils) + serializer.DataReadWriteFunction( + "utensils", + new List(), + types => types.ForEach(type => _utensilsNeeded |= type), + () => { - _utensilsNeeded |= utensil; - Dirty(); - } - } + var types = new List(); + + foreach (UtensilType type in Enum.GetValues(typeof(UtensilType))) + { + if ((_utensilsNeeded & type) != 0) + { + types.Add(type); + } + } + + return types; + }); } public override void Initialize() diff --git a/Content.Server/GameObjects/Components/Utensil/UtensilComponent.cs b/Content.Server/GameObjects/Components/Utensil/UtensilComponent.cs index 9c0a843aa5..da8f272b28 100644 --- a/Content.Server/GameObjects/Components/Utensil/UtensilComponent.cs +++ b/Content.Server/GameObjects/Components/Utensil/UtensilComponent.cs @@ -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()); - foreach (var type in types) + serializer.DataReadWriteFunction("types", + new List(), + types => types.ForEach(AddType), + () => { - AddType(type); - } - } + var types = new List(); + + 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"); diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/RevolverBarrelComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/RevolverBarrelComponent.cs index c873127b11..ee28884cdc 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/RevolverBarrelComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/RevolverBarrelComponent.cs @@ -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 diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerBatteryBarrelComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerBatteryBarrelComponent.cs index 155fa86804..556223aad8 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerBatteryBarrelComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerBatteryBarrelComponent.cs @@ -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("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); diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerMagazineBarrelComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerMagazineBarrelComponent.cs index b792cabae5..36fd3a5909 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerMagazineBarrelComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerMagazineBarrelComponent.cs @@ -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()); - foreach (var mag in magTypes) + + serializer.DataReadWriteFunction( + "magazineTypes", + new List(), + types => types.ForEach(mag => _magazineTypes |= mag), + () => { - _magazineTypes |= mag; - } - } + var types = new List(); + + 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); diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerRangedBarrelComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerRangedBarrelComponent.cs index 0098b043c9..e0c5eaf89f 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerRangedBarrelComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerRangedBarrelComponent.cs @@ -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()); - 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(), + selectors => selectors.ForEach(selector => _allRateSelectors |= selector), + () => { - _allRateSelectors |= fireRate; - } - } + var types = new List(); + + 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"); diff --git a/Content.Server/Health/BodySystem/BodyManagerComponent.cs b/Content.Server/Health/BodySystem/BodyManagerComponent.cs index 90406c4a72..0ced485cfb 100644 --- a/Content.Server/Health/BodySystem/BodyManagerComponent.cs +++ b/Content.Server/Health/BodySystem/BodyManagerComponent.cs @@ -25,6 +25,9 @@ namespace Content.Server.BodySystem { [ViewVariables] private BodyTemplate _template; + [ViewVariables] + private string _presetName; + [ViewVariables] private Dictionary _partDictionary = new Dictionary(); @@ -103,7 +106,7 @@ namespace Content.Server.BodySystem { } /// - /// Returns whether the given slot name exists within the current . + /// Returns whether the given slot name exists within the current . /// public bool SlotExists(string slotName) { @@ -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); } /// /// Loads the given - forcefully changes all limbs found in both the preset and this template! /// - 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. @@ -289,7 +309,7 @@ namespace Content.Server.BodySystem { } /// - /// Disconnects the given reference, potentially dropping other BodyParts if they were hanging off it. + /// Disconnects the given reference, potentially dropping other BodyParts if they were hanging off it. /// public void DisconnectBodyPart(BodyPart part, bool dropEntity) { if (!_partDictionary.ContainsValue(part)) @@ -314,7 +334,7 @@ namespace Content.Server.BodySystem { } /// - /// Internal string version of DisconnectBodyPart for performance purposes. Yes, it is actually more performant. + /// Internal string version of DisconnectBodyPart for performance purposes. Yes, it is actually more performant. /// private void DisconnectBodyPartByName(string name, bool dropEntity) { if (!TryGetBodyPart(name, out BodyPart part)) diff --git a/Content.Shared/Chemistry/Solution.cs b/Content.Shared/Chemistry/Solution.cs index 7c452f0ddb..ff2e15ec64 100644 --- a/Content.Shared/Chemistry/Solution.cs +++ b/Content.Shared/Chemistry/Solution.cs @@ -45,16 +45,16 @@ namespace Content.Shared.Chemistry /// public void ExposeData(ObjectSerializer serializer) { - serializer.DataField(ref _contents, "reagents", new List()); - - if (serializer.Reading) - { - TotalVolume = ReagentUnit.New(0); - foreach (var reagent in _contents) + serializer.DataReadWriteFunction( + "reagents", + new List(), + quantities => { - TotalVolume += reagent.Quantity; - } - } + _contents = quantities; + TotalVolume = ReagentUnit.New(0); + quantities.ForEach(reagent => TotalVolume += reagent.Quantity); + }, + () => _contents); } /// diff --git a/Content.Shared/GameObjects/Components/Cargo/SharedGalacticMarketComponent.cs b/Content.Shared/GameObjects/Components/Cargo/SharedGalacticMarketComponent.cs index 4a047a44a1..51cdcf2893 100644 --- a/Content.Shared/GameObjects/Components/Cargo/SharedGalacticMarketComponent.cs +++ b/Content.Shared/GameObjects/Components/Cargo/SharedGalacticMarketComponent.cs @@ -65,23 +65,25 @@ namespace Content.Shared.GameObjects.Components.Cargo { base.ExposeData(serializer); - if (serializer.Reading) - { - var products = serializer.ReadDataField("products", new List()); - var prototypeManager = IoCManager.Resolve(); - _products.Clear(); - foreach (var id in products) + serializer.DataReadWriteFunction( + "products", + new List(), + 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()); - } + var prototypeManager = IoCManager.Resolve(); + + _products.Clear(); + foreach (var id in products) + { + if (!prototypeManager.TryIndex(id, out CargoProductPrototype product)) + { + continue; + } + + _products.Add(product); + } + }, + GetProductIdList); } } diff --git a/Content.Shared/GameObjects/Components/Materials/MaterialComponent.cs b/Content.Shared/GameObjects/Components/Materials/MaterialComponent.cs index bfe966bd83..dbdb325bea 100644 --- a/Content.Shared/GameObjects/Components/Materials/MaterialComponent.cs +++ b/Content.Shared/GameObjects/Components/Materials/MaterialComponent.cs @@ -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; } diff --git a/Content.Shared/GameObjects/Components/Research/SharedLatheDatabaseComponent.cs b/Content.Shared/GameObjects/Components/Research/SharedLatheDatabaseComponent.cs index fea10d01f4..3044aeef52 100644 --- a/Content.Shared/GameObjects/Components/Research/SharedLatheDatabaseComponent.cs +++ b/Content.Shared/GameObjects/Components/Research/SharedLatheDatabaseComponent.cs @@ -74,20 +74,23 @@ namespace Content.Shared.GameObjects.Components.Research { base.ExposeData(serializer); - if (serializer.Reading) - { - var recipes = serializer.ReadDataField("recipes", new List()); - var prototypeManager = IoCManager.Resolve(); - foreach (var id in recipes) + serializer.DataReadWriteFunction( + "recipes", + new List(), + 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()); - } + var prototypeManager = IoCManager.Resolve(); + + foreach (var id in recipes) + { + if (prototypeManager.TryIndex(id, out LatheRecipePrototype recipe)) + { + _recipes.Add(recipe); + } + } + }, + GetRecipeIdList); + } public List GetRecipeIdList() diff --git a/Content.Shared/GameObjects/Components/Research/SharedProtolatheDatabaseComponent.cs b/Content.Shared/GameObjects/Components/Research/SharedProtolatheDatabaseComponent.cs index 9fb52757fe..39d5d82051 100644 --- a/Content.Shared/GameObjects/Components/Research/SharedProtolatheDatabaseComponent.cs +++ b/Content.Shared/GameObjects/Components/Research/SharedProtolatheDatabaseComponent.cs @@ -26,20 +26,22 @@ namespace Content.Shared.GameObjects.Components.Research { base.ExposeData(serializer); - if (serializer.Reading) - { - var recipes = serializer.ReadDataField("protolatherecipes", new List()); - var prototypeManager = IoCManager.Resolve(); - foreach (var id in recipes) + serializer.DataReadWriteFunction( + "protolatherecipes", + new List(), + 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()); - } + var prototypeManager = IoCManager.Resolve(); + + foreach (var id in recipes) + { + if (prototypeManager.TryIndex(id, out LatheRecipePrototype recipe)) + { + _protolatheRecipes.Add(recipe); + } + } + }, + GetProtolatheRecipeIdList); } /// diff --git a/Content.Shared/GameObjects/Components/Research/SharedTechnologyDatabaseComponent.cs b/Content.Shared/GameObjects/Components/Research/SharedTechnologyDatabaseComponent.cs index d76b42260f..4a573270b0 100644 --- a/Content.Shared/GameObjects/Components/Research/SharedTechnologyDatabaseComponent.cs +++ b/Content.Shared/GameObjects/Components/Research/SharedTechnologyDatabaseComponent.cs @@ -83,20 +83,21 @@ namespace Content.Shared.GameObjects.Components.Research { base.ExposeData(serializer); - if (serializer.Reading) - { - var techs = serializer.ReadDataField("technologies", new List()); - var prototypeManager = IoCManager.Resolve(); - foreach (var id in techs) + serializer.DataReadWriteFunction( + "technologies", + new List(), + 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()); - } + var prototypeManager = IoCManager.Resolve(); + + foreach (var id in techs) + { + if (prototypeManager.TryIndex(id, out TechnologyPrototype tech)) + { + _technologies.Add(tech); + } + } + }, GetTechnologyIdList); } } diff --git a/Content.Shared/GameObjects/Components/SharedStackComponent.cs b/Content.Shared/GameObjects/Components/SharedStackComponent.cs index 1ea9fc0105..57ef706559 100644 --- a/Content.Shared/GameObjects/Components/SharedStackComponent.cs +++ b/Content.Shared/GameObjects/Components/SharedStackComponent.cs @@ -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; } diff --git a/Content.Shared/GameObjects/Components/Sound/SharedLoopingSoundComponent.cs b/Content.Shared/GameObjects/Components/Sound/SharedLoopingSoundComponent.cs index b09d353b27..262f5f8091 100644 --- a/Content.Shared/GameObjects/Components/Sound/SharedLoopingSoundComponent.cs +++ b/Content.Shared/GameObjects/Components/Sound/SharedLoopingSoundComponent.cs @@ -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", "");