Skip to content

Commit

Permalink
Доабвление комментов, перенесение изменение в папки корвакс
Browse files Browse the repository at this point in the history
  • Loading branch information
p.krasnoshchekov committed Apr 27, 2024
1 parent 9815fe8 commit 585150c
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 96 deletions.
19 changes: 19 additions & 0 deletions Content.Server/Corvax/GuideGenerator/MixingCategoryEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Content.Shared.Chemistry.Reaction;
using System.Text.Json.Serialization;

namespace Content.Server.Corvax.GuideGenerator;

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;
}
}
35 changes: 35 additions & 0 deletions Content.Server/Corvax/GuideGenerator/ReactionJsonGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Content.Server.Corvax.GuideGenerator;
using Content.Shared.Chemistry.Reaction;
using Robust.Shared.Prototypes;

namespace Content.Server.GuideGenerator;
public sealed partial class ReactionJsonGenerator
{
[ValidatePrototypeId<MixingCategoryPrototype>]
private const string DefaultMixingCategory = "DummyMix";

private static void AddMixingCategories(Dictionary<String, ReactionEntry> reactions, IPrototypeManager prototype)
{
foreach (var reaction in reactions)
{
var reactionPrototype = prototype.Index<ReactionPrototype>(reaction.Key);
var mixingCategories = new List<MixingCategoryPrototype>();
if (reactionPrototype.MixingCategories != null)
{
foreach (var category in reactionPrototype.MixingCategories)
{
mixingCategories.Add(prototype.Index(category));
}
}
else
{
mixingCategories.Add(prototype.Index<MixingCategoryPrototype>(DefaultMixingCategory));
}

foreach (var mixingCategory in mixingCategories)
{
reactions[reaction.Key].MixingCategories.Add(new MixingCategoryEntry(mixingCategory));
}
}
}
}
40 changes: 40 additions & 0 deletions Content.Server/Corvax/GuideGenerator/ReagentEffectEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Content.Shared.Chemistry.Reagent;
using Robust.Shared.Prototypes;
using System.Text.Json.Serialization;

namespace Content.Server.Corvax.GuideGenerator;
public sealed class ReagentEffectEntry
{
[JsonPropertyName("id")]
public string Id { get; }

[JsonPropertyName("description")]
public string Description { get; }

public ReagentEffectEntry(ReagentEffect proto)
{
var prototype = IoCManager.Resolve<IPrototypeManager>();
var entSys = IoCManager.Resolve<IEntitySystemManager>();

Id = proto.GetType().Name;
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("<span=") != -1)
{
var first = guideBookText.IndexOf("<span=") + "<span=".Length - 1;
var last = 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;
}
}
20 changes: 20 additions & 0 deletions Content.Server/Corvax/GuideGenerator/ReagentEffectsEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Content.Shared.FixedPoint;
using System.Linq;
using System.Text.Json.Serialization;

namespace Content.Server.Corvax.GuideGenerator;
public sealed class ReagentEffectsEntry
{
[JsonPropertyName("rate")]
public FixedPoint2 MetabolismRate { get; } = FixedPoint2.New(0.5f);

[JsonPropertyName("effects")]
public List<ReagentEffectEntry> Effects { get; } = new();

public ReagentEffectsEntry(Shared.Chemistry.Reagent.ReagentEffectsEntry proto)
{
MetabolismRate = proto.MetabolismRate;
Effects = proto.Effects.Select(x => new ReagentEffectEntry(x)).ToList();
}

}
30 changes: 4 additions & 26 deletions Content.Server/GuideGenerator/ReactionJsonGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@

namespace Content.Server.GuideGenerator;

public sealed class ReactionJsonGenerator
public sealed partial class ReactionJsonGenerator
{
[ValidatePrototypeId<MixingCategoryPrototype>]
private const string DefaultMixingCategory = "DummyMix";

public static void PublishJson(StreamWriter file)
{
var prototype = IoCManager.Resolve<IPrototypeManager>();
Expand All @@ -22,28 +19,9 @@ 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<ReactionPrototype>(reaction.Key);
var mixingCategories = new List<MixingCategoryPrototype>();
if (reactionPrototype.MixingCategories != null)
{
foreach (var category in reactionPrototype.MixingCategories)
{
mixingCategories.Add(prototype.Index(category));
}
}
else
{
mixingCategories.Add(prototype.Index<MixingCategoryPrototype>(DefaultMixingCategory));
}

foreach (var mixingCategory in mixingCategories)
{
reactions[reaction.Key].MixingCategories.Add(new MixingCategoryEntry(mixingCategory));
}
}
// Corvax-Wiki-Start
if (reactions is not null) AddMixingCategories(reactions, prototype);
// Corvax-Wiki-End

var serializeOptions = new JsonSerializerOptions
{
Expand Down
81 changes: 11 additions & 70 deletions Content.Server/GuideGenerator/ReagentEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
using System.Text.Json.Serialization;
using Content.Shared.Chemistry.Reaction;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Robust.Shared.Prototypes;
using Content.Server.Corvax.GuideGenerator;

namespace Content.Server.GuideGenerator;

Expand All @@ -28,13 +27,13 @@ public sealed class ReagentEntry
public string SubstanceColor { get; }

[JsonPropertyName("textColor")]
public string TextColor { get; }
public string TextColor { get; } // Corvax-Wiki

[JsonPropertyName("recipes")]
public List<string> Recipes { get; } = new();

[JsonPropertyName("metabolisms")]
public Dictionary<string, ReagentEffectsEntry>? Metabolisms { get; }
public Dictionary<string, Corvax.GuideGenerator.ReagentEffectsEntry>? Metabolisms { get; } // Corvax-Wiki

public ReagentEntry(ReagentPrototype proto)
{
Expand All @@ -45,14 +44,16 @@ public ReagentEntry(ReagentPrototype proto)
PhysicalDescription = proto.LocalizedPhysicalDescription;
SubstanceColor = proto.SubstanceColor.ToHex();

// Corvax-Wiki-Start
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 => new ReagentEffectsEntry(x.Value));
Metabolisms = proto.Metabolisms?.ToDictionary(x => x.Key.Id, x => new Corvax.GuideGenerator.ReagentEffectsEntry(x.Value));
// Corvax-Wiki-End
}
}

Expand All @@ -70,6 +71,7 @@ public sealed class ReactionEntry
[JsonPropertyName("products")]
public Dictionary<string, float> Products { get; }

// Corvax-Wiki-Start
[JsonPropertyName("mixingCategories")]
public List<MixingCategoryEntry> MixingCategories { get; } = new();

Expand All @@ -86,6 +88,7 @@ public sealed class ReactionEntry
public List<ReagentEffectEntry> ExportEffects { get; } = new();

[JsonIgnore]
// Corvax-Wiki-End
public List<ReagentEffect> Effects { get; }

public ReactionEntry(ReactionPrototype proto)
Expand All @@ -100,12 +103,14 @@ public ReactionEntry(ReactionPrototype proto)
proto.Products
.Select(x => KeyValuePair.Create(x.Key, x.Value.Float()))
.ToDictionary(x => x.Key, x => x.Value);
Effects = proto.Effects;

// Corvax-Wiki-Start
ExportEffects = proto.Effects.Select(x => new ReagentEffectEntry(x)).ToList();
Effects = proto.Effects;
MinTemp = proto.MinimumTemperature;
MaxTemp = proto.MaximumTemperature;
HasMax = !float.IsPositiveInfinity(MaxTemp);
// Corvax-Wiki-End
}
}

Expand All @@ -123,67 +128,3 @@ 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 ReagentEffectsEntry
{
[JsonPropertyName("rate")]
public FixedPoint2 MetabolismRate { get; } = FixedPoint2.New(0.5f);

[JsonPropertyName("effects")]
public List<ReagentEffectEntry> 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")]
public string Id { get; }

[JsonPropertyName("description")]
public string Description { get; }

public ReagentEffectEntry(ReagentEffect proto)
{
var prototype = IoCManager.Resolve<IPrototypeManager>();
var entSys = IoCManager.Resolve<IEntitySystemManager>();

Id = proto.GetType().Name;
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("<span=") != -1)
{
var first = guideBookText.IndexOf("<span=") + "<span=".Length - 1;
var last = 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;
}
}

0 comments on commit 585150c

Please sign in to comment.