]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Make some prototypes use frozen collections (#22576)
authorLeon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Mon, 25 Dec 2023 04:12:22 +0000 (23:12 -0500)
committerGitHub <noreply@github.com>
Mon, 25 Dec 2023 04:12:22 +0000 (15:12 +1100)
* Make some prototypes use frozen collections

* poke tests

* Remove frozen dictionary enumeration

Content.Server/Body/Systems/MetabolizerSystem.cs
Content.Server/Chemistry/Commands/DumpReagentGuideText.cs
Content.Server/GuideGenerator/ReagentEntry.cs
Content.Server/Nutrition/EntitySystems/DrinkSystem.cs
Content.Shared/Chemistry/Reagent/ReagentPrototype.cs

index 5233b0166c13998fc1d610245a27ed9a986fcb89..c8851b49acac05448a1e2274eab39eb501b03859 100644 (file)
@@ -156,10 +156,9 @@ namespace Content.Server.Body.Systems
 
                 foreach (var group in meta.MetabolismGroups)
                 {
-                    if (!proto.Metabolisms.ContainsKey(group.Id))
+                    if (!proto.Metabolisms.TryGetValue(group.Id, out var entry))
                         continue;
 
-                    var entry = proto.Metabolisms[group.Id];
                     var rate = entry.MetabolismRate * group.MetabolismRateModifier;
 
                     // Remove $rate, as long as there's enough reagent there to actually remove that much
index 70a79254d6b5acfd8d52504aa0ed4b0aba9e5ddb..563708b8f36c0e126c244b6be6e7f54a4e61da17 100644 (file)
@@ -36,7 +36,7 @@ public sealed class DumpReagentGuideText : IConsoleCommand
             return;
         }
 
-        foreach (var (_, entry) in reagent.Metabolisms)
+        foreach (var entry in reagent.Metabolisms.Values)
         {
             foreach (var effect in entry.Effects)
             {
index 5c9ec40fd4f496969a61dd3f411776216bb59c74..ab9e75820607767e33e719ebd14c69cbf78e8e36 100644 (file)
@@ -32,7 +32,7 @@ public sealed class ReagentEntry
     public List<string> Recipes { get; } = new();
 
     [JsonPropertyName("metabolisms")]
-    public Dictionary<ProtoId<MetabolismGroupPrototype>, ReagentEffectsEntry>? Metabolisms { get; }
+    public Dictionary<string, ReagentEffectsEntry>? Metabolisms { get; }
 
     public ReagentEntry(ReagentPrototype proto)
     {
@@ -42,7 +42,7 @@ public sealed class ReagentEntry
         Description = proto.LocalizedDescription;
         PhysicalDescription = proto.LocalizedPhysicalDescription;
         SubstanceColor = proto.SubstanceColor.ToHex();
-        Metabolisms = proto.Metabolisms;
+        Metabolisms = proto.Metabolisms?.ToDictionary(x => x.Key.Id, x => x.Value);
     }
 }
 
index e45c904591e37e8ec91c02303695e5d58af3ed75..e41c834c80ae2e85db5e8eeaad023c53c8b904a9 100644 (file)
@@ -112,7 +112,7 @@ public sealed class DrinkSystem : EntitySystem
             if (reagent.Metabolisms == null)
                 continue;
 
-            foreach ((var _, var entry) in reagent.Metabolisms)
+            foreach (var entry in reagent.Metabolisms.Values)
             {
                 foreach (var effect in entry.Effects)
                 {
index 1603d3d647f12a3aee2513dd9296f87b1a28b1fd..c9ce5f357c55e81320162527b98908f137eb73c5 100644 (file)
@@ -1,4 +1,5 @@
-using System.Linq;
+using System.Collections.Frozen;
+using System.Linq;
 using System.Text.Json.Serialization;
 using Content.Shared.Administration.Logs;
 using Content.Shared.Body.Prototypes;
@@ -14,7 +15,6 @@ using Robust.Shared.Random;
 using Robust.Shared.Serialization;
 using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
 using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Array;
-using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
 using Robust.Shared.Utility;
 
 namespace Content.Shared.Chemistry.Reagent
@@ -103,7 +103,7 @@ namespace Content.Shared.Chemistry.Reagent
         public float Viscosity;
 
         [DataField(serverOnly: true)]
-        public Dictionary<ProtoId<MetabolismGroupPrototype>, ReagentEffectsEntry>? Metabolisms;
+        public FrozenDictionary<ProtoId<MetabolismGroupPrototype>, ReagentEffectsEntry>? Metabolisms;
 
         [DataField(serverOnly: true)]
         public Dictionary<ProtoId<ReactiveGroupPrototype>, ReactiveReagentEffectEntry>? ReactiveEffects;