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:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Text.Json.Serialization;
|
||||
using Content.Server.Chemistry.Components.SolutionManager;
|
||||
using Content.Server.Explosion.EntitySystems;
|
||||
using Content.Shared.Administration.Logs;
|
||||
@@ -12,21 +13,36 @@ namespace Content.Server.Chemistry.ReactionEffects
|
||||
[DataDefinition]
|
||||
public class ExplosionReactionEffect : ReagentEffect
|
||||
{
|
||||
[DataField("devastationRange")] private float _devastationRange = 1;
|
||||
[DataField("heavyImpactRange")] private float _heavyImpactRange = 2;
|
||||
[DataField("lightImpactRange")] private float _lightImpactRange = 3;
|
||||
[DataField("flashRange")] private float _flashRange;
|
||||
[DataField("devastationRange")]
|
||||
[JsonIgnore]
|
||||
private float _devastationRange = 1;
|
||||
|
||||
[DataField("heavyImpactRange")]
|
||||
[JsonIgnore]
|
||||
private float _heavyImpactRange = 2;
|
||||
|
||||
[DataField("lightImpactRange")]
|
||||
[JsonIgnore]
|
||||
private float _lightImpactRange = 3;
|
||||
|
||||
[DataField("flashRange")]
|
||||
[JsonIgnore]
|
||||
private float _flashRange;
|
||||
|
||||
/// <summary>
|
||||
/// If true, then scale ranges by intensity. If not, the ranges are the same regardless of reactant amount.
|
||||
/// </summary>
|
||||
[DataField("scaled")] private bool _scaled;
|
||||
[DataField("scaled")]
|
||||
[JsonIgnore]
|
||||
private bool _scaled;
|
||||
|
||||
/// <summary>
|
||||
/// Maximum scaling on ranges. For example, if it equals 5, then it won't scaled anywhere past
|
||||
/// 5 times the minimum reactant amount.
|
||||
/// </summary>
|
||||
[DataField("maxScale")] private float _maxScale = 1;
|
||||
[DataField("maxScale")]
|
||||
[JsonIgnore]
|
||||
private float _maxScale = 1;
|
||||
|
||||
public override bool ShouldLog => true;
|
||||
public override LogImpact LogImpact => LogImpact.High;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
@@ -16,6 +17,7 @@ namespace Content.Server.Chemistry.ReagentEffects
|
||||
/// <summary>
|
||||
/// Damage to apply every metabolism cycle. Damage Ignores resistances.
|
||||
/// </summary>
|
||||
[JsonPropertyName("damage")]
|
||||
[DataField("damage", required: true)]
|
||||
public DamageSpecifier Damage = default!;
|
||||
|
||||
@@ -23,10 +25,12 @@ namespace Content.Server.Chemistry.ReagentEffects
|
||||
/// Should this effect scale the damage by the amount of chemical in the solution?
|
||||
/// Useful for touch reactions, like styptic powder or acid.
|
||||
/// </summary>
|
||||
[JsonPropertyName("scaleByQuantity")]
|
||||
[DataField("scaleByQuantity")]
|
||||
public bool ScaleByQuantity = false;
|
||||
|
||||
[DataField("ignoreResistances")]
|
||||
[JsonPropertyName("ignoreResistances")]
|
||||
public bool IgnoreResistances = true;
|
||||
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.IO;
|
||||
using Content.Server.Administration.Managers;
|
||||
using Content.Server.Afk;
|
||||
using Content.Server.AI.Utility;
|
||||
@@ -8,6 +9,7 @@ using Content.Server.Connection;
|
||||
using Content.Server.Database;
|
||||
using Content.Server.EUI;
|
||||
using Content.Server.GameTicking;
|
||||
using Content.Server.GuideGenerator;
|
||||
using Content.Server.Info;
|
||||
using Content.Server.IoC;
|
||||
using Content.Server.Maps;
|
||||
@@ -18,15 +20,19 @@ using Content.Server.Voting.Managers;
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Kitchen;
|
||||
using Robust.Server;
|
||||
using Robust.Server.Bql;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Server.ServerStatus;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Entry
|
||||
{
|
||||
@@ -62,45 +68,66 @@ namespace Content.Server.Entry
|
||||
|
||||
IoCManager.BuildGraph();
|
||||
factory.GenerateNetIds();
|
||||
var configManager = IoCManager.Resolve<IConfigurationManager>();
|
||||
var dest = configManager.GetCVar(CCVars.DestinationFile);
|
||||
if (dest == "") //hacky but it keeps load times for the generator down.
|
||||
{
|
||||
_euiManager = IoCManager.Resolve<EuiManager>();
|
||||
_voteManager = IoCManager.Resolve<IVoteManager>();
|
||||
|
||||
_euiManager = IoCManager.Resolve<EuiManager>();
|
||||
_voteManager = IoCManager.Resolve<IVoteManager>();
|
||||
IoCManager.Resolve<IChatSanitizationManager>().Initialize();
|
||||
IoCManager.Resolve<IChatManager>().Initialize();
|
||||
|
||||
IoCManager.Resolve<IChatSanitizationManager>().Initialize();
|
||||
IoCManager.Resolve<IChatManager>().Initialize();
|
||||
var playerManager = IoCManager.Resolve<IPlayerManager>();
|
||||
|
||||
var playerManager = IoCManager.Resolve<IPlayerManager>();
|
||||
var logManager = IoCManager.Resolve<ILogManager>();
|
||||
logManager.GetSawmill("Storage").Level = LogLevel.Info;
|
||||
logManager.GetSawmill("db.ef").Level = LogLevel.Info;
|
||||
|
||||
var logManager = IoCManager.Resolve<ILogManager>();
|
||||
logManager.GetSawmill("Storage").Level = LogLevel.Info;
|
||||
logManager.GetSawmill("db.ef").Level = LogLevel.Info;
|
||||
|
||||
IoCManager.Resolve<IConnectionManager>().Initialize();
|
||||
IoCManager.Resolve<IServerDbManager>().Init();
|
||||
IoCManager.Resolve<IServerPreferencesManager>().Init();
|
||||
IoCManager.Resolve<INodeGroupFactory>().Initialize();
|
||||
IoCManager.Resolve<IGamePrototypeLoadManager>().Initialize();
|
||||
_voteManager.Initialize();
|
||||
IoCManager.Resolve<IConnectionManager>().Initialize();
|
||||
IoCManager.Resolve<IServerDbManager>().Init();
|
||||
IoCManager.Resolve<IServerPreferencesManager>().Init();
|
||||
IoCManager.Resolve<INodeGroupFactory>().Initialize();
|
||||
IoCManager.Resolve<IGamePrototypeLoadManager>().Initialize();
|
||||
_voteManager.Initialize();
|
||||
}
|
||||
}
|
||||
|
||||
public override void PostInit()
|
||||
{
|
||||
base.PostInit();
|
||||
|
||||
IoCManager.Resolve<ISandboxManager>().Initialize();
|
||||
IoCManager.Resolve<RecipeManager>().Initialize();
|
||||
IoCManager.Resolve<ActionManager>().Initialize();
|
||||
IoCManager.Resolve<BlackboardManager>().Initialize();
|
||||
IoCManager.Resolve<ConsiderationsManager>().Initialize();
|
||||
IoCManager.Resolve<IAdminManager>().Initialize();
|
||||
IoCManager.Resolve<INpcBehaviorManager>().Initialize();
|
||||
IoCManager.Resolve<IAfkManager>().Initialize();
|
||||
IoCManager.Resolve<RulesManager>().Initialize();
|
||||
_euiManager.Initialize();
|
||||
var configManager = IoCManager.Resolve<IConfigurationManager>();
|
||||
var resourceManager = IoCManager.Resolve<IResourceManager>();
|
||||
var dest = configManager.GetCVar(CCVars.DestinationFile);
|
||||
var resPath = new ResourcePath(dest).ToRootedPath();
|
||||
if (dest != "")
|
||||
{
|
||||
var file = resourceManager.UserData.OpenWriteText(resPath.WithName("chem_" + dest));
|
||||
ChemistryJsonGenerator.PublishJson(file);
|
||||
file.Flush();
|
||||
file = resourceManager.UserData.OpenWriteText(resPath.WithName("react_" + dest));
|
||||
ReactionJsonGenerator.PublishJson(file);
|
||||
file.Flush();
|
||||
IoCManager.Resolve<IBaseServer>().Shutdown("Data generation done");
|
||||
}
|
||||
else
|
||||
{
|
||||
IoCManager.Resolve<ISandboxManager>().Initialize();
|
||||
IoCManager.Resolve<RecipeManager>().Initialize();
|
||||
IoCManager.Resolve<ActionManager>().Initialize();
|
||||
IoCManager.Resolve<BlackboardManager>().Initialize();
|
||||
IoCManager.Resolve<ConsiderationsManager>().Initialize();
|
||||
IoCManager.Resolve<IAdminManager>().Initialize();
|
||||
IoCManager.Resolve<INpcBehaviorManager>().Initialize();
|
||||
IoCManager.Resolve<IAfkManager>().Initialize();
|
||||
IoCManager.Resolve<RulesManager>().Initialize();
|
||||
_euiManager.Initialize();
|
||||
|
||||
IoCManager.Resolve<IGameMapManager>().Initialize();
|
||||
IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<GameTicker>().PostInitialize();
|
||||
IoCManager.Resolve<IBqlQueryManager>().DoAutoRegistrations();
|
||||
IoCManager.Resolve<IGameMapManager>().Initialize();
|
||||
IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<GameTicker>().PostInitialize();
|
||||
IoCManager.Resolve<IBqlQueryManager>().DoAutoRegistrations();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update(ModUpdateLevel level, FrameEventArgs frameEventArgs)
|
||||
@@ -110,11 +137,11 @@ namespace Content.Server.Entry
|
||||
switch (level)
|
||||
{
|
||||
case ModUpdateLevel.PostEngine:
|
||||
{
|
||||
_euiManager.SendUpdates();
|
||||
_voteManager.Update();
|
||||
break;
|
||||
}
|
||||
{
|
||||
_euiManager.SendUpdates();
|
||||
_voteManager.Update();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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