Skip to content

Commit

Permalink
В выгрузку json на wiki рецептов и реагентов добавлены данные о: мин,…
Browse files Browse the repository at this point in the history
… макс температуре реакции, описание эффектов из гайдбука, название устройства для реакции (блендер, центрифуга..)
  • Loading branch information
p.krasnoshchekov committed Apr 25, 2024
1 parent cd80c5f commit b059f67
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 2 deletions.
26 changes: 26 additions & 0 deletions Content.Server/GuideGenerator/ReactionJsonGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ namespace Content.Server.GuideGenerator;

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

public static void PublishJson(StreamWriter file)
{
var prototype = IoCManager.Resolve<IPrototypeManager>();
Expand All @@ -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<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));
}
}

var serializeOptions = new JsonSerializerOptions
{
WriteIndented = true,
Expand Down
70 changes: 68 additions & 2 deletions Content.Server/GuideGenerator/ReagentEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ public sealed class ReagentEntry
[JsonPropertyName("color")]
public string SubstanceColor { get; }

[JsonPropertyName("textColor")]
public string TextColor { get; }

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

[JsonPropertyName("metabolisms")]
public Dictionary<string, ReagentEffectsEntry>? Metabolisms { get; }
public Dictionary<string, List<ReagentEffectEntry>>? Metabolisms { get; }

public ReagentEntry(ReagentPrototype proto)
{
Expand All @@ -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());
}
}

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

[JsonPropertyName("mixingCategories")]
public List<MixingCategoryEntry> 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<ReagentEffectEntry> ExportEffects { get; }

[JsonIgnore]
public List<ReagentEffect> Effects { get; }

public ReactionEntry(ReactionPrototype proto)
{
var protoMan = IoCManager.Resolve<IPrototypeManager>();

Id = proto.ID;
Name = TextTools.TextTools.CapitalizeString(proto.Name); // Corvax-Wiki
Reactants =
Expand All @@ -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);
}
}

Expand All @@ -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<IPrototypeManager>();
var entSys = IoCManager.Resolve<IEntitySystemManager>();

Id = proto.GetType().Name;
Description = proto.GuidebookEffectDescription(prototype, entSys) ?? "";
}
}

0 comments on commit b059f67

Please sign in to comment.