Make some prototypes use frozen collections (#22576)

* Make some prototypes use frozen collections

* poke tests

* Remove frozen dictionary enumeration
This commit is contained in:
Leon Friedrich
2023-12-24 23:12:22 -05:00
committed by GitHub
parent 78354052ea
commit 8587c3778a
5 changed files with 8 additions and 9 deletions

View File

@@ -156,10 +156,9 @@ namespace Content.Server.Body.Systems
foreach (var group in meta.MetabolismGroups) foreach (var group in meta.MetabolismGroups)
{ {
if (!proto.Metabolisms.ContainsKey(group.Id)) if (!proto.Metabolisms.TryGetValue(group.Id, out var entry))
continue; continue;
var entry = proto.Metabolisms[group.Id];
var rate = entry.MetabolismRate * group.MetabolismRateModifier; var rate = entry.MetabolismRate * group.MetabolismRateModifier;
// Remove $rate, as long as there's enough reagent there to actually remove that much // Remove $rate, as long as there's enough reagent there to actually remove that much

View File

@@ -36,7 +36,7 @@ public sealed class DumpReagentGuideText : IConsoleCommand
return; return;
} }
foreach (var (_, entry) in reagent.Metabolisms) foreach (var entry in reagent.Metabolisms.Values)
{ {
foreach (var effect in entry.Effects) foreach (var effect in entry.Effects)
{ {

View File

@@ -32,7 +32,7 @@ public sealed class ReagentEntry
public List<string> Recipes { get; } = new(); public List<string> Recipes { get; } = new();
[JsonPropertyName("metabolisms")] [JsonPropertyName("metabolisms")]
public Dictionary<ProtoId<MetabolismGroupPrototype>, ReagentEffectsEntry>? Metabolisms { get; } public Dictionary<string, ReagentEffectsEntry>? Metabolisms { get; }
public ReagentEntry(ReagentPrototype proto) public ReagentEntry(ReagentPrototype proto)
{ {
@@ -42,7 +42,7 @@ public sealed class ReagentEntry
Description = proto.LocalizedDescription; Description = proto.LocalizedDescription;
PhysicalDescription = proto.LocalizedPhysicalDescription; PhysicalDescription = proto.LocalizedPhysicalDescription;
SubstanceColor = proto.SubstanceColor.ToHex(); SubstanceColor = proto.SubstanceColor.ToHex();
Metabolisms = proto.Metabolisms; Metabolisms = proto.Metabolisms?.ToDictionary(x => x.Key.Id, x => x.Value);
} }
} }

View File

@@ -112,7 +112,7 @@ public sealed class DrinkSystem : EntitySystem
if (reagent.Metabolisms == null) if (reagent.Metabolisms == null)
continue; continue;
foreach ((var _, var entry) in reagent.Metabolisms) foreach (var entry in reagent.Metabolisms.Values)
{ {
foreach (var effect in entry.Effects) foreach (var effect in entry.Effects)
{ {

View File

@@ -1,4 +1,5 @@
using System.Linq; using System.Collections.Frozen;
using System.Linq;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using Content.Shared.Administration.Logs; using Content.Shared.Administration.Logs;
using Content.Shared.Body.Prototypes; using Content.Shared.Body.Prototypes;
@@ -14,7 +15,6 @@ using Robust.Shared.Random;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; 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.Array;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
using Robust.Shared.Utility; using Robust.Shared.Utility;
namespace Content.Shared.Chemistry.Reagent namespace Content.Shared.Chemistry.Reagent
@@ -103,7 +103,7 @@ namespace Content.Shared.Chemistry.Reagent
public float Viscosity; public float Viscosity;
[DataField(serverOnly: true)] [DataField(serverOnly: true)]
public Dictionary<ProtoId<MetabolismGroupPrototype>, ReagentEffectsEntry>? Metabolisms; public FrozenDictionary<ProtoId<MetabolismGroupPrototype>, ReagentEffectsEntry>? Metabolisms;
[DataField(serverOnly: true)] [DataField(serverOnly: true)]
public Dictionary<ProtoId<ReactiveGroupPrototype>, ReactiveReagentEffectEntry>? ReactiveEffects; public Dictionary<ProtoId<ReactiveGroupPrototype>, ReactiveReagentEffectEntry>? ReactiveEffects;