diff --git a/Content.Server/GuideGenerator/ReactionJsonGenerator.cs b/Content.Server/GuideGenerator/ReactionJsonGenerator.cs index 89e02c2fa5d..116aea3cffb 100644 --- a/Content.Server/GuideGenerator/ReactionJsonGenerator.cs +++ b/Content.Server/GuideGenerator/ReactionJsonGenerator.cs @@ -9,6 +9,9 @@ namespace Content.Server.GuideGenerator; public sealed class ReactionJsonGenerator { + [ValidatePrototypeId] + private const string DefaultMixingCategory = "DummyMix"; + public static void PublishJson(StreamWriter file) { var prototype = IoCManager.Resolve(); @@ -19,6 +22,29 @@ public static void PublishJson(StreamWriter file) .Select(x => new ReactionEntry(x)) .ToDictionary(x => x.Id, x => x); + // MixingCategories + foreach (var reaction in reactions) + { + var reactionPrototype = prototype.Index(reaction.Key); + var mixingCategories = new List(); + if (reactionPrototype.MixingCategories != null) + { + foreach (var category in reactionPrototype.MixingCategories) + { + mixingCategories.Add(prototype.Index(category)); + } + } + else + { + mixingCategories.Add(prototype.Index(DefaultMixingCategory)); + } + + foreach (var mixingCategory in mixingCategories) + { + reactions[reaction.Key].MixingCategories.Add(new MixingCategoryEntry(mixingCategory)); + } + } + var serializeOptions = new JsonSerializerOptions { WriteIndented = true, diff --git a/Content.Server/GuideGenerator/ReagentEntry.cs b/Content.Server/GuideGenerator/ReagentEntry.cs index a9b969453a7..2e6b64797cd 100644 --- a/Content.Server/GuideGenerator/ReagentEntry.cs +++ b/Content.Server/GuideGenerator/ReagentEntry.cs @@ -28,11 +28,14 @@ public sealed class ReagentEntry [JsonPropertyName("color")] public string SubstanceColor { get; } + [JsonPropertyName("textColor")] + public string TextColor { get; } + [JsonPropertyName("recipes")] public List Recipes { get; } = new(); [JsonPropertyName("metabolisms")] - public Dictionary? Metabolisms { get; } + public Dictionary>? Metabolisms { get; } public ReagentEntry(ReagentPrototype proto) { @@ -42,7 +45,15 @@ public ReagentEntry(ReagentPrototype proto) Description = proto.LocalizedDescription; PhysicalDescription = proto.LocalizedPhysicalDescription; SubstanceColor = proto.SubstanceColor.ToHex(); - Metabolisms = proto.Metabolisms?.ToDictionary(x => x.Key.Id, x => x.Value); + + var r = proto.SubstanceColor.R; + var g = proto.SubstanceColor.G; + var b = proto.SubstanceColor.B; + TextColor = (0.2126f * r + 0.7152f * g + 0.0722f * b > 0.5 + ? Color.Black + : Color.White).ToHex(); + + Metabolisms = proto.Metabolisms?.ToDictionary(x => x.Key.Id, x => x.Value.Effects.Select(x => new ReagentEffectEntry(x)).ToList()); } } @@ -60,11 +71,28 @@ public sealed class ReactionEntry [JsonPropertyName("products")] public Dictionary Products { get; } + [JsonPropertyName("mixingCategories")] + public List MixingCategories { get; } = new(); + + [JsonPropertyName("minTemp")] + public float MinTemp { get; } + + [JsonPropertyName("maxTemp")] + public float MaxTemp { get; } + + [JsonPropertyName("hasMax")] + public bool HasMax { get; } + [JsonPropertyName("effects")] + public List ExportEffects { get; } + + [JsonIgnore] public List Effects { get; } public ReactionEntry(ReactionPrototype proto) { + var protoMan = IoCManager.Resolve(); + Id = proto.ID; Name = TextTools.TextTools.CapitalizeString(proto.Name); // Corvax-Wiki Reactants = @@ -75,7 +103,12 @@ public ReactionEntry(ReactionPrototype proto) proto.Products .Select(x => KeyValuePair.Create(x.Key, x.Value.Float())) .ToDictionary(x => x.Key, x => x.Value); + + ExportEffects = proto.Effects.Select(x => new ReagentEffectEntry(x)).ToList(); Effects = proto.Effects; + MinTemp = proto.MinimumTemperature; + MaxTemp = proto.MaximumTemperature; + HasMax = !float.IsPositiveInfinity(MaxTemp); } } @@ -93,3 +126,36 @@ public ReactantEntry(float amnt, bool cata) Catalyst = cata; } } + +public sealed class MixingCategoryEntry +{ + [JsonPropertyName("name")] + public string Name { get; } + + [JsonPropertyName("id")] + public string Id { get; } + + public MixingCategoryEntry(MixingCategoryPrototype proto) + { + Name = Loc.GetString(proto.VerbText); + Id = proto.ID; + } +} + +public sealed class ReagentEffectEntry +{ + [JsonPropertyName("id")] + public string Id { get; } + + [JsonPropertyName("description")] + public string Description { get; } + + public ReagentEffectEntry(ReagentEffect proto) + { + var prototype = IoCManager.Resolve(); + var entSys = IoCManager.Resolve(); + + Id = proto.GetType().Name; + Description = proto.GuidebookEffectDescription(prototype, entSys) ?? ""; + } +}