Chemistry JSON dump tool and companion GitHub Action (#6134)
* fuck * oh boy * Sorted every chem into guide groups * WHY ARE YOU NOT ABSTRACT * removes the target thing in favor of simply generating everything. * eee * Add group for med * Update wiki JSON generation to use System.Text.Json * Fix error on shutdown during wiki JSON generation * First pass at automatic wiki workflow * Add a temporary workaround while the build is continuing to give errors * Update workflow to reference correct API url, track dependency. * Compile wiki actions into one job rather than two * Update page name to reference editable page * Add other JSON file and parameterize root page path * A few steps closer to using `System.Text.Json` to serialize properly * Revert System.Text.Json and return to Newtonsoft.Json. * Revert the revert. Return to System.Text.Json. This reverts commit a5ea98dfdcfab3f605ac4d82d3b110f099324308. * Add and register UniversalJsonConverter class. * Narrow triggers for update-wiki GitHub action. Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com>
This commit is contained in:
40
Content.Server/GuideGenerator/ChemistryJsonGenerator.cs
Normal file
40
Content.Server/GuideGenerator/ChemistryJsonGenerator.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using Content.Server.Administration.Logs.Converters;
|
||||
using Content.Shared.Chemistry.Reaction;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.GuideGenerator;
|
||||
|
||||
public class ChemistryJsonGenerator
|
||||
{
|
||||
public static void PublishJson(StreamWriter file)
|
||||
{
|
||||
var prototype = IoCManager.Resolve<IPrototypeManager>();
|
||||
var prototypes =
|
||||
prototype
|
||||
.EnumeratePrototypes<ReagentPrototype>()
|
||||
.Where(x => !x.Abstract)
|
||||
.Select(x => new ReagentEntry(x))
|
||||
.ToDictionary(x => x.Id, x => x);
|
||||
|
||||
var reactions =
|
||||
prototype
|
||||
.EnumeratePrototypes<ReactionPrototype>()
|
||||
.Where(x => x.Products.Count != 0);
|
||||
|
||||
foreach (var reaction in reactions)
|
||||
{
|
||||
foreach (var product in reaction.Products.Keys)
|
||||
{
|
||||
prototypes[product].Recipes.Add(reaction.ID);
|
||||
}
|
||||
}
|
||||
|
||||
file.Write(JsonSerializer.Serialize(prototypes, new JsonSerializerOptions { WriteIndented = true }));
|
||||
}
|
||||
}
|
||||
26
Content.Server/GuideGenerator/ReactionJsonGenerator.cs
Normal file
26
Content.Server/GuideGenerator/ReactionJsonGenerator.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using Content.Shared.Chemistry.Reaction;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.GuideGenerator;
|
||||
|
||||
public class ReactionJsonGenerator
|
||||
{
|
||||
public static void PublishJson(StreamWriter file)
|
||||
{
|
||||
var prototype = IoCManager.Resolve<IPrototypeManager>();
|
||||
|
||||
var reactions =
|
||||
prototype
|
||||
.EnumeratePrototypes<ReactionPrototype>()
|
||||
.Select(x => new ReactionEntry(x))
|
||||
.ToDictionary(x => x.Id, x => x);
|
||||
|
||||
file.Write(JsonSerializer.Serialize(reactions, new JsonSerializerOptions { WriteIndented = true, IncludeFields = true }));
|
||||
}
|
||||
}
|
||||
|
||||
98
Content.Server/GuideGenerator/ReagentEntry.cs
Normal file
98
Content.Server/GuideGenerator/ReagentEntry.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using Content.Server.Body.Components;
|
||||
using Content.Shared.Chemistry.Reaction;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.Converters;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.GuideGenerator;
|
||||
|
||||
public class ReagentEntry
|
||||
{
|
||||
[JsonPropertyName("id")]
|
||||
public string Id { get; }
|
||||
|
||||
[JsonPropertyName("name")]
|
||||
public string Name { get; }
|
||||
|
||||
[JsonPropertyName("group")]
|
||||
public string Group { get; }
|
||||
|
||||
[JsonPropertyName("desc")]
|
||||
public string Description { get; }
|
||||
|
||||
[JsonPropertyName("physicalDesc")]
|
||||
public string PhysicalDescription { get; }
|
||||
|
||||
[JsonPropertyName("color")]
|
||||
public string SubstanceColor { get; }
|
||||
|
||||
[JsonPropertyName("recipes")]
|
||||
public List<string> Recipes { get; } = new();
|
||||
|
||||
[JsonPropertyName("metabolisms")]
|
||||
public Dictionary<string, ReagentEffectsEntry>? Metabolisms { get; }
|
||||
|
||||
public ReagentEntry(ReagentPrototype proto)
|
||||
{
|
||||
Id = proto.ID;
|
||||
Name = proto.Name;
|
||||
Group = proto.Group;
|
||||
Description = proto.Description;
|
||||
PhysicalDescription = proto.PhysicalDescription;
|
||||
SubstanceColor = proto.SubstanceColor.ToHex();
|
||||
Metabolisms = proto.Metabolisms;
|
||||
}
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(UniversalJsonConverter<ReactionEntry>))]
|
||||
public class ReactionEntry
|
||||
{
|
||||
[JsonPropertyName("id")]
|
||||
public string Id { get; }
|
||||
|
||||
[JsonPropertyName("name")]
|
||||
public string Name { get; }
|
||||
|
||||
[JsonPropertyName("reactants")]
|
||||
public Dictionary<string, ReactantEntry> Reactants { get; }
|
||||
|
||||
[JsonPropertyName("products")]
|
||||
public Dictionary<string, float> Products { get; }
|
||||
|
||||
[JsonPropertyName("effects")]
|
||||
public List<ReagentEffect> Effects { get; }
|
||||
|
||||
public ReactionEntry(ReactionPrototype proto)
|
||||
{
|
||||
Id = proto.ID;
|
||||
Name = proto.Name;
|
||||
Reactants =
|
||||
proto.Reactants
|
||||
.Select(x => KeyValuePair.Create(x.Key, new ReactantEntry(x.Value.Amount.Float(), x.Value.Catalyst)))
|
||||
.ToDictionary(x => x.Key, x => x.Value);
|
||||
Products =
|
||||
proto.Products
|
||||
.Select(x => KeyValuePair.Create(x.Key, x.Value.Float()))
|
||||
.ToDictionary(x => x.Key, x => x.Value);
|
||||
Effects = proto.Effects;
|
||||
}
|
||||
}
|
||||
|
||||
public class ReactantEntry
|
||||
{
|
||||
[JsonPropertyName("amount")]
|
||||
public float Amount { get; }
|
||||
|
||||
[JsonPropertyName("catalyst")]
|
||||
public bool Catalyst { get; }
|
||||
|
||||
public ReactantEntry(float amnt, bool cata)
|
||||
{
|
||||
Amount = amnt;
|
||||
Catalyst = cata;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user