From 73f82869e4cceba42c935d2480a72e3c2a6c12bf Mon Sep 17 00:00:00 2001 From: Valtos Date: Sun, 29 Sep 2024 00:45:53 +0300 Subject: [PATCH] fix chem recipes generator --- Content.Server/GuideGenerator/ChemistryJsonGenerator.cs | 3 ++- Content.Server/GuideGenerator/UniversalJsonConverter.cs | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Content.Server/GuideGenerator/ChemistryJsonGenerator.cs b/Content.Server/GuideGenerator/ChemistryJsonGenerator.cs index 7e107ce1a5..b499526a28 100644 --- a/Content.Server/GuideGenerator/ChemistryJsonGenerator.cs +++ b/Content.Server/GuideGenerator/ChemistryJsonGenerator.cs @@ -45,7 +45,8 @@ public sealed class ChemistryJsonGenerator new UniversalJsonConverter(), new UniversalJsonConverter(), new FixedPointJsonConverter() - } + }, + NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals }; file.Write(JsonSerializer.Serialize(prototypes, serializeOptions)); diff --git a/Content.Server/GuideGenerator/UniversalJsonConverter.cs b/Content.Server/GuideGenerator/UniversalJsonConverter.cs index bcf9702c1c..2e31927f95 100644 --- a/Content.Server/GuideGenerator/UniversalJsonConverter.cs +++ b/Content.Server/GuideGenerator/UniversalJsonConverter.cs @@ -73,6 +73,11 @@ namespace Content.Server.GuideGenerator // If the field has a [JsonIgnore] attribute, skip it if (Attribute.GetCustomAttribute(prop, typeof(JsonIgnoreAttribute), true) != null) continue; + // If GetIndexParameters().Length is not 0 then it means that property is indexed + // And since we cannot get its values without passing index (which type can LITERALLY BE ANYTHING) then let's just skip it + // Yeah, i know that this will lead to a potential data loss, but what i can do about it? + if (prop.GetIndexParameters().Length != 0) continue; + // If the property has a [JsonPropertyName] attribute, get the property name. Otherwise, use the property name. JsonPropertyNameAttribute? attr = (JsonPropertyNameAttribute?) Attribute.GetCustomAttribute(prop, typeof(JsonPropertyNameAttribute), true); string name = attr == null ? prop.Name : attr.Name;