From 6173d3e21f7190e145abf3000b86f73d5cfbb5b1 Mon Sep 17 00:00:00 2001 From: "p.krasnoshchekov" Date: Fri, 26 Apr 2024 02:15:28 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=20=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82?= =?UTF-8?q?=D1=83=D1=80=D1=83=20json=20=D0=B2=D0=BE=D0=B7=D0=B2=D1=80?= =?UTF-8?q?=D0=B0=D1=89=D0=B5=D0=BD=D0=BE=20=D1=81=D0=B2=D0=BE=D0=B9=D1=81?= =?UTF-8?q?=D1=82=D0=B2=D0=BE=20rate=20=D1=83=20=D0=BC=D0=B5=D1=82=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D0=BB=D0=B8=D0=B7=D0=BC=D0=B0.=20=D0=A2=D0=B5?= =?UTF-8?q?=D0=BA=D1=81=D1=82=20=D0=B4=D0=BB=D1=8F=20=D0=B3=D0=B0=D0=B9?= =?UTF-8?q?=D0=B4=D0=B1=D1=83=D0=BA=D0=B0=20=D0=B0=D0=B4=D0=B0=D0=BF=D1=82?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=20=D0=BF=D0=BE=D0=B4=20wik?= =?UTF-8?q?i?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Content.Server/GuideGenerator/ReagentEntry.cs | 48 +++++++++++++++---- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/Content.Server/GuideGenerator/ReagentEntry.cs b/Content.Server/GuideGenerator/ReagentEntry.cs index 2e6b64797cd..0029df1de8e 100644 --- a/Content.Server/GuideGenerator/ReagentEntry.cs +++ b/Content.Server/GuideGenerator/ReagentEntry.cs @@ -1,9 +1,8 @@ using System.Linq; using System.Text.Json.Serialization; -using Content.Server.Body.Components; -using Content.Shared.Body.Prototypes; using Content.Shared.Chemistry.Reaction; using Content.Shared.Chemistry.Reagent; +using Content.Shared.FixedPoint; using Robust.Shared.Prototypes; namespace Content.Server.GuideGenerator; @@ -35,7 +34,7 @@ public sealed class ReagentEntry public List Recipes { get; } = new(); [JsonPropertyName("metabolisms")] - public Dictionary>? Metabolisms { get; } + public Dictionary? Metabolisms { get; } public ReagentEntry(ReagentPrototype proto) { @@ -53,7 +52,7 @@ public ReagentEntry(ReagentPrototype proto) ? Color.Black : Color.White).ToHex(); - Metabolisms = proto.Metabolisms?.ToDictionary(x => x.Key.Id, x => x.Value.Effects.Select(x => new ReagentEffectEntry(x)).ToList()); + Metabolisms = proto.Metabolisms?.ToDictionary(x => x.Key.Id, x => new ReagentEffectsEntry(x.Value)); } } @@ -66,7 +65,7 @@ public sealed class ReactionEntry public string Name { get; } [JsonPropertyName("reactants")] - public Dictionary Reactants { get; } + public Dictionary Reactants { get; } = new(); [JsonPropertyName("products")] public Dictionary Products { get; } @@ -84,15 +83,13 @@ public sealed class ReactionEntry public bool HasMax { get; } [JsonPropertyName("effects")] - public List ExportEffects { get; } + public List ExportEffects { get; } = new(); [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 = @@ -126,7 +123,6 @@ public ReactantEntry(float amnt, bool cata) Catalyst = cata; } } - public sealed class MixingCategoryEntry { [JsonPropertyName("name")] @@ -141,7 +137,21 @@ public MixingCategoryEntry(MixingCategoryPrototype proto) Id = proto.ID; } } +public sealed class ReagentEffectsEntry +{ + [JsonPropertyName("rate")] + public FixedPoint2 MetabolismRate { get; } = FixedPoint2.New(0.5f); + + [JsonPropertyName("effects")] + public List Effects { get; } = new(); + + public ReagentEffectsEntry(Content.Shared.Chemistry.Reagent.ReagentEffectsEntry proto) + { + MetabolismRate = proto.MetabolismRate; + Effects = proto.Effects.Select(x => new ReagentEffectEntry(x)).ToList(); + } +} public sealed class ReagentEffectEntry { [JsonPropertyName("id")] @@ -156,6 +166,24 @@ public ReagentEffectEntry(ReagentEffect proto) var entSys = IoCManager.Resolve(); Id = proto.GetType().Name; - Description = proto.GuidebookEffectDescription(prototype, entSys) ?? ""; + Description = GuidebookEffectDescriptionToWeb(proto.GuidebookEffectDescription(prototype, entSys) ?? ""); + } + + private string GuidebookEffectDescriptionToWeb(string guideBookText) + { + guideBookText = guideBookText.Replace("[", "<"); + guideBookText = guideBookText.Replace("]", ">"); + guideBookText = guideBookText.Replace("color", "span"); + + while (guideBookText.IndexOf("", first); + var replacementString = guideBookText.Substring(first, last - first); + var color = replacementString.Substring(1); + guideBookText = guideBookText.Replace(replacementString, String.Format(" style=\"color: {0};\"", color)); + } + + return guideBookText; } }