2
0
mirror of https://github.com/9ParsonsB/Pulsar.git synced 2025-07-03 01:03:41 -04:00

Initial Commit

This commit is contained in:
2024-04-13 15:54:59 +10:00
parent 8e178cbb7b
commit 63ed43f4af
459 changed files with 8039 additions and 20504 deletions

View File

@ -1,56 +1,51 @@
using System;
using System.Collections.Immutable;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Text.Json;
using System.Text.Json.Serialization;
using Observatory.Framework.Files.ParameterTypes;
namespace Observatory.Framework.Files.Converters
namespace Observatory.Framework.Files.Converters;
/// <summary>
/// The format used for materials changed from an object with a key for each material to an array of objects containing "name" and "percent".
/// Need to handle both if we're going to read historical data. This reads the old format into a class reflecting the new structure.
/// </summary>
public class MaterialCompositionConverter : JsonConverter<ImmutableList<MaterialComposition>>
{
/// <summary>
/// The format used for materials changed from an object with a key for each material to an array of objects containing "name" and "percent".
/// Need to handle both if we're going to read historical data. This reads the old format into a class reflecting the new structure.
/// </summary>
public class MaterialCompositionConverter : JsonConverter<ImmutableList<MaterialComposition>>
public override ImmutableList<MaterialComposition> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
public override ImmutableList<MaterialComposition> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
if (reader.TokenType == JsonTokenType.StartObject)
{
if (reader.TokenType == JsonTokenType.StartObject)
var materialComposition = new List<MaterialComposition>();
while (reader.Read())
{
var materialComposition = new List<MaterialComposition>();
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 percent = reader.GetSingle();
var material = new MaterialComposition
{
string name = reader.GetString();
reader.Read();
float percent = reader.GetSingle();
var material = new MaterialComposition
{
Name = name,
Percent = percent
};
materialComposition.Add(material);
}
}
else
{
break;
Name = name,
Percent = percent
};
materialComposition.Add(material);
}
}
return materialComposition.ToImmutableList();
}
else
{
return (ImmutableList<MaterialComposition>)JsonSerializer.Deserialize(ref reader, typeof(ImmutableList<MaterialComposition>));
else
{
break;
}
}
return materialComposition.ToImmutableList();
}
public override void Write(Utf8JsonWriter writer, ImmutableList<MaterialComposition> value, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
return (ImmutableList<MaterialComposition>)JsonSerializer.Deserialize(ref reader, typeof(ImmutableList<MaterialComposition>));
}
}
public override void Write(Utf8JsonWriter writer, ImmutableList<MaterialComposition> value, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
}