From b059f677ba8b5630c9168e1b0d0035f109cb544b Mon Sep 17 00:00:00 2001 From: "p.krasnoshchekov" Date: Thu, 25 Apr 2024 06:00:04 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=20=D0=B2=D1=8B=D0=B3=D1=80=D1=83=D0=B7?= =?UTF-8?q?=D0=BA=D1=83=20json=20=D0=BD=D0=B0=20wiki=20=D1=80=D0=B5=D1=86?= =?UTF-8?q?=D0=B5=D0=BF=D1=82=D0=BE=D0=B2=20=D0=B8=20=D1=80=D0=B5=D0=B0?= =?UTF-8?q?=D0=B3=D0=B5=D0=BD=D1=82=D0=BE=D0=B2=20=D0=B4=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D0=B5=20=D0=BE:=20=D0=BC=D0=B8=D0=BD,=20=D0=BC=D0=B0=D0=BA?= =?UTF-8?q?=D1=81=20=D1=82=D0=B5=D0=BC=D0=BF=D0=B5=D1=80=D0=B0=D1=82=D1=83?= =?UTF-8?q?=D1=80=D0=B5=20=D1=80=D0=B5=D0=B0=D0=BA=D1=86=D0=B8=D0=B8,=20?= =?UTF-8?q?=D0=BE=D0=BF=D0=B8=D1=81=D0=B0=D0=BD=D0=B8=D0=B5=20=D1=8D=D1=84?= =?UTF-8?q?=D1=84=D0=B5=D0=BA=D1=82=D0=BE=D0=B2=20=D0=B8=D0=B7=20=D0=B3?= =?UTF-8?q?=D0=B0=D0=B9=D0=B4=D0=B1=D1=83=D0=BA=D0=B0,=20=D0=BD=D0=B0?= =?UTF-8?q?=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D1=83=D1=81=D1=82=D1=80?= =?UTF-8?q?=D0=BE=D0=B9=D1=81=D1=82=D0=B2=D0=B0=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B0=D0=BA=D1=86=D0=B8=D0=B8=20(=D0=B1=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B4=D0=B5=D1=80,=20=D1=86=D0=B5=D0=BD=D1=82?= =?UTF-8?q?=D1=80=D0=B8=D1=84=D1=83=D0=B3=D0=B0..)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GuideGenerator/ReactionJsonGenerator.cs | 26 +++++++ Content.Server/GuideGenerator/ReagentEntry.cs | 70 ++++++++++++++++++- 2 files changed, 94 insertions(+), 2 deletions(-) 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) ?? ""; + } +}