Enable nullable in ReactionPrototype & ReagentPrototype (#3005)

* Enable nullable in ReactionPrototype & ReagentPrototype

* Remove unecessary sets

* Fix updates branch

* Review fixes

Co-authored-by: py01 <pyronetics01@gmail.com>
This commit is contained in:
py01
2021-01-14 23:40:10 -06:00
committed by GitHub
parent 3079ddd962
commit 138cdaba5b
3 changed files with 29 additions and 19 deletions

View File

@@ -1,3 +1,4 @@
#nullable enable
using Content.Shared.Chemistry;
using Content.Shared.GameObjects.EntitySystems;
using Robust.Server.GameObjects.EntitySystems;
@@ -11,6 +12,7 @@ namespace Content.Server.GameObjects.EntitySystems.NewFolder
{
base.OnReaction(reaction, owner, unitReactions);
if (reaction.Sound != null)
Get<AudioSystem>().PlayAtCoords(reaction.Sound, owner.Transform.Coordinates);
}
}

View File

@@ -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<string, ReactantPrototype> _reactants;
private Dictionary<string, ReagentUnit> _products;
private List<IReactionEffect> _effects;
private string _id = default!;
private string _name = default!;
private Dictionary<string, ReactantPrototype> _reactants = default!;
private Dictionary<string, ReagentUnit> _products = default!;
private List<IReactionEffect> _effects = default!;
public string ID => _id;
public string Name => _name;
@@ -36,7 +37,7 @@ namespace Content.Shared.Chemistry
/// </summary>
public IReadOnlyList<IReactionEffect> 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<IReactionEffect>());
}
else
{
_effects = new(); //To ensure _effects isn't null since it is only serializable on the server right snow
}
}
}

View File

@@ -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<IMetabolizable> _metabolism;
private List<ITileReaction> _tileReactions;
private List<IPlantMetabolizable> _plantMetabolism;
private float _customPlantMetabolism = 1f;
private string _spritePath = default!;
private List<IMetabolizable> _metabolism = default!;
private List<ITileReaction> _tileReactions = default!;
private List<IPlantMetabolizable> _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<IMetabolizable> { new DefaultMetabolizable() });
serializer.DataField(ref _tileReactions, "tileReactions", new List<ITileReaction> { });
serializer.DataField(ref _plantMetabolism, "plantMetabolism", new List<IPlantMetabolizable> { });
}
else
{
//ensure the following fields cannot null since they can only be serialized on server right now
_metabolism = new List<IMetabolizable> { new DefaultMetabolizable() };
_tileReactions = new List<ITileReaction>(0);
_plantMetabolism = new List<IPlantMetabolizable>(0);
_tileReactions = new();
_plantMetabolism = new();
}
}