2
0
mirror of https://github.com/9ParsonsB/Pulsar.git synced 2025-12-15 20:34:58 +01:00

Update Journal File Handling

Now Correctly deserializes Journal events
This commit is contained in:
2024-05-12 12:55:28 +10:00
parent e59ca066ab
commit bd811c861c
29 changed files with 714 additions and 442 deletions

View File

@@ -11,42 +11,44 @@ namespace Observatory.Framework.Files.Converters;
/// </summary>
public class MaterialConverter : JsonConverter<ImmutableList<Material>>
{
public override ImmutableList<Material> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
public override ImmutableList<Material> Read(ref Utf8JsonReader reader, Type typeToConvert,
JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.StartObject)
if (reader.TokenType == JsonTokenType.StartObject)
{
var materialComposition = new List<Material>();
while (reader.Read())
{
var materialComposition = new List<Material>();
while (reader.Read())
if (reader.TokenType != JsonTokenType.EndObject)
{
if (reader.TokenType != JsonTokenType.EndObject)
if (reader.TokenType == JsonTokenType.PropertyName)
{
if (reader.TokenType == JsonTokenType.PropertyName)
var name = reader.GetString();
reader.Read();
var count = reader.GetInt32();
var material = new Material
{
var name = reader.GetString();
reader.Read();
var count = reader.GetInt32();
var material = new Material
{
Name = name,
Name_Localised = name,
Count = count
};
materialComposition.Add(material);
}
}
else
{
break;
Name = name,
Name_Localised = name,
Count = count
};
materialComposition.Add(material);
}
}
return materialComposition.ToImmutableList();
else
{
break;
}
}
return (ImmutableList<Material>)JsonSerializer.Deserialize(ref reader, typeof(ImmutableList<Material>));
return materialComposition.ToImmutableList();
}
return JsonSerializer.Deserialize<ImmutableList<Material>>(ref reader, options)!;
}
public override void Write(Utf8JsonWriter writer, ImmutableList<Material> value, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
JsonSerializer.Serialize(writer, value, options);
}
}