From 138cdaba5bc8620e73ad965c00574843bc64065f Mon Sep 17 00:00:00 2001 From: py01 <60152240+collinlunn@users.noreply.github.com> Date: Thu, 14 Jan 2021 23:40:10 -0600 Subject: [PATCH] Enable nullable in ReactionPrototype & ReagentPrototype (#3005) * Enable nullable in ReactionPrototype & ReagentPrototype * Remove unecessary sets * Fix updates branch * Review fixes Co-authored-by: py01 --- .../EntitySystems/ChemicalReactionSystem.cs | 4 ++- Content.Shared/Chemistry/ReactionPrototype.cs | 17 +++++++----- Content.Shared/Chemistry/ReagentPrototype.cs | 27 ++++++++++--------- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/Content.Server/GameObjects/EntitySystems/ChemicalReactionSystem.cs b/Content.Server/GameObjects/EntitySystems/ChemicalReactionSystem.cs index 2fde1f8f59..5d4ad7c567 100644 --- a/Content.Server/GameObjects/EntitySystems/ChemicalReactionSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/ChemicalReactionSystem.cs @@ -1,3 +1,4 @@ +#nullable enable using Content.Shared.Chemistry; using Content.Shared.GameObjects.EntitySystems; using Robust.Server.GameObjects.EntitySystems; @@ -11,7 +12,8 @@ namespace Content.Server.GameObjects.EntitySystems.NewFolder { base.OnReaction(reaction, owner, unitReactions); - Get().PlayAtCoords(reaction.Sound, owner.Transform.Coordinates); + if (reaction.Sound != null) + Get().PlayAtCoords(reaction.Sound, owner.Transform.Coordinates); } } } diff --git a/Content.Shared/Chemistry/ReactionPrototype.cs b/Content.Shared/Chemistry/ReactionPrototype.cs index 02799b9229..7f2f9eb006 100644 --- a/Content.Shared/Chemistry/ReactionPrototype.cs +++ b/Content.Shared/Chemistry/ReactionPrototype.cs @@ -1,3 +1,4 @@ +#nullable enable using System.Collections.Generic; using Content.Server.Interfaces.Chemistry; using Content.Shared.Interfaces; @@ -15,11 +16,11 @@ namespace Content.Shared.Chemistry [Prototype("reaction")] public class ReactionPrototype : IPrototype, IIndexedPrototype { - private string _id; - private string _name; - private Dictionary _reactants; - private Dictionary _products; - private List _effects; + private string _id = default!; + private string _name = default!; + private Dictionary _reactants = default!; + private Dictionary _products = default!; + private List _effects = default!; public string ID => _id; public string Name => _name; @@ -36,7 +37,7 @@ namespace Content.Shared.Chemistry /// public IReadOnlyList Effects => _effects; - public string Sound { get; private set; } + public string? Sound { get; private set; } [Dependency] private readonly IModuleManager _moduleManager = default!; @@ -56,6 +57,10 @@ namespace Content.Shared.Chemistry //Some implementations of IReactionEffect can't currently be moved to shared, so this is here to prevent the client from breaking when reading server-only IReactionEffects. serializer.DataField(ref _effects, "effects", new List()); } + else + { + _effects = new(); //To ensure _effects isn't null since it is only serializable on the server right snow + } } } diff --git a/Content.Shared/Chemistry/ReagentPrototype.cs b/Content.Shared/Chemistry/ReagentPrototype.cs index 208d1d7e0d..2c27e6f824 100644 --- a/Content.Shared/Chemistry/ReagentPrototype.cs +++ b/Content.Shared/Chemistry/ReagentPrototype.cs @@ -1,4 +1,5 @@ -using System; +#nullable enable +using System; using System.Collections.Generic; using Content.Shared.Interfaces; using Content.Shared.Interfaces.Chemistry; @@ -18,16 +19,16 @@ namespace Content.Shared.Chemistry { [Dependency] private readonly IModuleManager _moduleManager = default!; - private string _id; - private string _name; - private string _description; - private string _physicalDescription; + private string _id = default!; + private string _name = default!; + private string _description = default!; + private string _physicalDescription = default!; private Color _substanceColor; - private string _spritePath; - private List _metabolism; - private List _tileReactions; - private List _plantMetabolism; - private float _customPlantMetabolism = 1f; + private string _spritePath = default!; + private List _metabolism = default!; + private List _tileReactions = default!; + private List _plantMetabolism = default!; + private float _customPlantMetabolism; public string ID => _id; public string Name => _name; @@ -60,15 +61,17 @@ namespace Content.Shared.Chemistry if (_moduleManager.IsServerModule) { + //Implementations of the needed interfaces are currently server-only, so they cannot be read on client serializer.DataField(ref _metabolism, "metabolism", new List { new DefaultMetabolizable() }); serializer.DataField(ref _tileReactions, "tileReactions", new List { }); serializer.DataField(ref _plantMetabolism, "plantMetabolism", new List { }); } else { + //ensure the following fields cannot null since they can only be serialized on server right now _metabolism = new List { new DefaultMetabolizable() }; - _tileReactions = new List(0); - _plantMetabolism = new List(0); + _tileReactions = new(); + _plantMetabolism = new(); } }