diff --git a/Content.Client/Guidebook/Controls/GuideReagentReaction.xaml.cs b/Content.Client/Guidebook/Controls/GuideReagentReaction.xaml.cs index 66d3f693b8..464f700b06 100644 --- a/Content.Client/Guidebook/Controls/GuideReagentReaction.xaml.cs +++ b/Content.Client/Guidebook/Controls/GuideReagentReaction.xaml.cs @@ -36,7 +36,7 @@ public sealed partial class GuideReagentReaction : BoxContainer, ISearchableCont Container container = ReactantsContainer; SetReagents(prototype.Reactants, ref container, protoMan); Container productContainer = ProductsContainer; - var products = new Dictionary(prototype.Products); + var products = new Dictionary, FixedPoint2>(prototype.Products); foreach (var (reagent, reactantProto) in prototype.Reactants) { if (reactantProto.Catalyst) @@ -101,11 +101,11 @@ public sealed partial class GuideReagentReaction : BoxContainer, ISearchableCont ReactantsContainer.Visible = true; ReactantsContainer.AddChild(label); - if (prototype.Reagent != null) + if (prototype.Reagent is {} reagent) { - var quantity = new Dictionary + var quantity = new Dictionary, FixedPoint2> { - { prototype.Reagent, FixedPoint2.New(0.21f) } + { reagent, FixedPoint2.New(0.21f) } }; Container productContainer = ProductsContainer; SetReagents(quantity, ref productContainer, protoMan, false); @@ -113,9 +113,9 @@ public sealed partial class GuideReagentReaction : BoxContainer, ISearchableCont SetMixingCategory(categories, null, sysMan); } - private void SetReagents(List reagents, ref Container container, IPrototypeManager protoMan, bool addLinks = true) + private static void SetReagents(List reagents, ref Container container, IPrototypeManager protoMan, bool addLinks = true) { - var amounts = new Dictionary(); + var amounts = new Dictionary, FixedPoint2>(); foreach (var (reagent, quantity) in reagents) { amounts.Add(reagent.Prototype, quantity); @@ -123,13 +123,13 @@ public sealed partial class GuideReagentReaction : BoxContainer, ISearchableCont SetReagents(amounts, ref container, protoMan, addLinks); } - private void SetReagents( - Dictionary reactants, + private static void SetReagents( + Dictionary, ReactantInfo> reactants, ref Container container, IPrototypeManager protoMan, bool addLinks = true) { - var amounts = new Dictionary(); + var amounts = new Dictionary, FixedPoint2>(); foreach (var (reagent, reactantPrototype) in reactants) { amounts.Add(reagent, reactantPrototype.Amount); @@ -137,22 +137,7 @@ public sealed partial class GuideReagentReaction : BoxContainer, ISearchableCont SetReagents(amounts, ref container, protoMan, addLinks); } - [PublicAPI] - private void SetReagents( - Dictionary, ReactantPrototype> reactants, - ref Container container, - IPrototypeManager protoMan, - bool addLinks = true) - { - var amounts = new Dictionary(); - foreach (var (reagent, reactantPrototype) in reactants) - { - amounts.Add(reagent, reactantPrototype.Amount); - } - SetReagents(amounts, ref container, protoMan, addLinks); - } - - private void SetReagents(Dictionary reagents, ref Container container, IPrototypeManager protoMan, bool addLinks = true) + private static void SetReagents(Dictionary, FixedPoint2> reagents, ref Container container, IPrototypeManager protoMan, bool addLinks = true) { foreach (var (product, amount) in reagents.OrderByDescending(p => p.Value)) { diff --git a/Content.Server/GuideGenerator/ReagentEntry.cs b/Content.Server/GuideGenerator/ReagentEntry.cs index 4a0e104205..df269332b1 100644 --- a/Content.Server/GuideGenerator/ReagentEntry.cs +++ b/Content.Server/GuideGenerator/ReagentEntry.cs @@ -55,10 +55,10 @@ public sealed class ReactionEntry public string Name { get; } [JsonPropertyName("reactants")] - public Dictionary Reactants { get; } + public Dictionary, ReactantEntry> Reactants { get; } [JsonPropertyName("products")] - public Dictionary Products { get; } + public Dictionary, float> Products { get; } [JsonPropertyName("effects")] public List Effects { get; } diff --git a/Content.Shared/Chemistry/Reaction/ChemicalReactionSystem.cs b/Content.Shared/Chemistry/Reaction/ChemicalReactionSystem.cs index fb1a3e5524..c13c9982a7 100644 --- a/Content.Shared/Chemistry/Reaction/ChemicalReactionSystem.cs +++ b/Content.Shared/Chemistry/Reaction/ChemicalReactionSystem.cs @@ -11,7 +11,6 @@ using Robust.Shared.Network; using Robust.Shared.Prototypes; using Robust.Shared.Utility; - namespace Content.Shared.Chemistry.Reaction { public sealed partial class ChemicalReactionSystem : EntitySystem @@ -36,12 +35,12 @@ namespace Content.Shared.Chemistry.Reaction /// A cache of all reactions indexed by at most ONE of their required reactants. /// I.e., even if a reaction has more than one reagent, it will only ever appear once in this dictionary. /// - private FrozenDictionary> _reactionsSingle = default!; + private FrozenDictionary, List> _reactionsSingle = default!; /// /// A cache of all reactions indexed by one of their required reactants. /// - private FrozenDictionary> _reactions = default!; + private FrozenDictionary, List> _reactions = default!; public override void Initialize() { @@ -57,7 +56,7 @@ namespace Content.Shared.Chemistry.Reaction private void InitializeReactionCache() { // Construct single-reaction dictionary. - var dict = new Dictionary>(); + var dict = new Dictionary, List>(); foreach (var reaction in ProtoMan.EnumeratePrototypes()) { // For this dictionary we only need to cache based on the first reagent. @@ -92,7 +91,7 @@ namespace Content.Shared.Chemistry.Reaction /// /// Checks if a solution can undergo a specified reaction. /// - /// The solution to check. + /// The solution to check. /// The reaction to check. /// How many times this reaction can occur. /// @@ -166,7 +165,7 @@ namespace Content.Shared.Chemistry.Reaction /// Perform a reaction on a solution. This assumes all reaction criteria are met. /// Removes the reactants from the solution, adds products, and returns a list of products. /// - private List PerformReaction(Entity soln, ReactionPrototype reaction, FixedPoint2 unitReactions) + private List> PerformReaction(Entity soln, ReactionPrototype reaction, FixedPoint2 unitReactions) { var (uid, comp) = soln; var solution = comp.Solution; @@ -184,7 +183,7 @@ namespace Content.Shared.Chemistry.Reaction } //Create products - var products = new List(); + var products = new List>(); foreach (var product in reaction.Products) { products.Add(product.Key); @@ -226,7 +225,7 @@ namespace Content.Shared.Chemistry.Reaction /// private bool ProcessReactions(Entity soln, SortedSet reactions, ReactionMixerComponent? mixerComponent) { - List? products = null; + List>? products = null; // attempt to perform any applicable reaction foreach (var reaction in reactions) diff --git a/Content.Shared/Chemistry/Reaction/ReactionPrototype.cs b/Content.Shared/Chemistry/Reaction/ReactionPrototype.cs index c9a24ec550..da9be43579 100644 --- a/Content.Shared/Chemistry/Reaction/ReactionPrototype.cs +++ b/Content.Shared/Chemistry/Reaction/ReactionPrototype.cs @@ -4,7 +4,6 @@ using Content.Shared.EntityEffects; using Content.Shared.FixedPoint; using Robust.Shared.Audio; using Robust.Shared.Prototypes; -using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary; namespace Content.Shared.Chemistry.Reaction { @@ -24,8 +23,8 @@ namespace Content.Shared.Chemistry.Reaction /// /// Reactants required for the reaction to occur. /// - [DataField("reactants", customTypeSerializer:typeof(PrototypeIdDictionarySerializer))] - public Dictionary Reactants = new(); + [DataField] + public Dictionary, ReactantInfo> Reactants = new(); /// /// The minimum temperature the reaction can occur at. @@ -36,7 +35,7 @@ namespace Content.Shared.Chemistry.Reaction /// /// If true, this reaction will attempt to conserve thermal energy. /// - [DataField("conserveEnergy")] + [DataField] public bool ConserveEnergy = true; /// @@ -54,8 +53,8 @@ namespace Content.Shared.Chemistry.Reaction /// /// Reagents created when the reaction occurs. /// - [DataField("products", customTypeSerializer:typeof(PrototypeIdDictionarySerializer))] - public Dictionary Products = new(); + [DataField] + public Dictionary, FixedPoint2> Products = new(); /// /// Effects to be triggered when the reaction occurs. @@ -66,10 +65,10 @@ namespace Content.Shared.Chemistry.Reaction /// How dangerous is this effect? Stuff like bicaridine should be low, while things like methamphetamine /// or potas/water should be high. /// - [DataField("impact", serverOnly: true)] public LogImpact Impact = LogImpact.Low; + [DataField(serverOnly: true)] public LogImpact Impact = LogImpact.Low; // TODO SERV3: Empty on the client, (de)serialize on the server with module manager is server module - [DataField("sound", serverOnly: true)] public SoundSpecifier Sound { get; private set; } = new SoundPathSpecifier("/Audio/Effects/Chemistry/bubbles.ogg"); + [DataField(serverOnly: true)] public SoundSpecifier Sound { get; private set; } = new SoundPathSpecifier("/Audio/Effects/Chemistry/bubbles.ogg"); /// /// If true, this reaction will only consume only integer multiples of the reactant amounts. If there are not @@ -117,23 +116,13 @@ namespace Content.Shared.Chemistry.Reaction } /// - /// Prototype for chemical reaction reactants. + /// Details about a reactant in a reaction. /// - [DataDefinition] - public sealed partial class ReactantPrototype - { - [DataField("amount")] - private FixedPoint2 _amount = FixedPoint2.New(1); - [DataField("catalyst")] - private bool _catalyst; - - /// - /// Minimum amount of the reactant needed for the reaction to occur. - /// - public FixedPoint2 Amount => _amount; - /// - /// Whether or not the reactant is a catalyst. Catalysts aren't removed when a reaction occurs. - /// - public bool Catalyst => _catalyst; - } + /// Minimum amount of the reactant needed for the reaction to occur. + /// Whether or not the reactant is a catalyst. Catalysts aren't removed when a reaction occurs. + [DataRecord] + public partial record struct ReactantInfo( + FixedPoint2 Amount, + bool Catalyst + ); }