2
0
mirror of https://github.com/9ParsonsB/Pulsar.git synced 2025-07-01 08:23:42 -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,24 +1,19 @@
using System;
using System.Collections.Immutable;
using System.Text;
using System.Text.Json;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Observatory.Framework.Files.Converters
namespace Observatory.Framework.Files.Converters;
class FleetCarrierTravelConverter : JsonConverter<float>
{
class FleetCarrierTravelConverter : JsonConverter<float>
public override float Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
public override float Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.String)
return Single.Parse(reader.GetString().Split(' ')[0]);
else
return reader.GetSingle();
return float.Parse(reader.GetString().Split(' ')[0]);
return reader.GetSingle();
}
public override void Write(Utf8JsonWriter writer, float value, JsonSerializerOptions options)
{
public override void Write(Utf8JsonWriter writer, float value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString());
}
}
}
}

View File

@ -1,20 +1,17 @@
using System;
using System.Text.Json;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Observatory.Framework.Files.Converters
namespace Observatory.Framework.Files.Converters;
public class IntBoolConverter : JsonConverter<bool>
{
public class IntBoolConverter : JsonConverter<bool>
public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return reader.GetInt16() == 1;
}
public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options)
{
writer.WriteNumberValue(value ? 1 : 0);
}
return reader.GetInt16() == 1;
}
}
public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options)
{
writer.WriteNumberValue(value ? 1 : 0);
}
}

View File

@ -1,22 +1,19 @@
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.Json;
namespace Observatory.Framework.Files.Converters
namespace Observatory.Framework.Files.Converters;
public class IntBoolFlexConverter : JsonConverter<bool>
{
public class IntBoolFlexConverter : JsonConverter<bool>
public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.Number)
return reader.GetInt16() == 1;
else
return reader.GetBoolean();
return reader.GetBoolean();
}
public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options)
{
public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options)
{
writer.WriteBooleanValue(value);
}
}
}
}

View File

@ -1,31 +1,26 @@
using System;
using System.Text.Json;
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>
/// Faction changed from a simple string to an object with additional state information. If we find a string convert it to an object with null state.
/// </summary>
public class LegacyFactionConverter<TFaction> : JsonConverter<TFaction> where TFaction : Faction, new()
/// <summary>
/// Faction changed from a simple string to an object with additional state information. If we find a string convert it to an object with null state.
/// </summary>
public class LegacyFactionConverter<TFaction> : JsonConverter<TFaction> where TFaction : Faction, new()
{
public override TFaction Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
public override TFaction Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.String)
{
return new TFaction { Name = reader.GetString(), FactionState = null };
}
else
{
return JsonSerializer.Deserialize<TFaction>(ref reader);
}
return JsonSerializer.Deserialize<TFaction>(ref reader);
}
public override void Write(Utf8JsonWriter writer, TFaction value, JsonSerializerOptions options)
{
public override void Write(Utf8JsonWriter writer, TFaction value, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
}
}
}

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();
}
}

View File

@ -1,20 +1,18 @@
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 MaterialConverter : JsonConverter<ImmutableList<Material>>
{
/// <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 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)
{
var materialComposition = new List<Material>();
@ -24,9 +22,9 @@ namespace Observatory.Framework.Files.Converters
{
if (reader.TokenType == JsonTokenType.PropertyName)
{
string name = reader.GetString();
var name = reader.GetString();
reader.Read();
int count = reader.GetInt32();
var count = reader.GetInt32();
var material = new Material
{
Name = name,
@ -43,15 +41,12 @@ namespace Observatory.Framework.Files.Converters
}
return materialComposition.ToImmutableList();
}
else
{
return (ImmutableList<Material>)JsonSerializer.Deserialize(ref reader, typeof(ImmutableList<Material>));
}
return (ImmutableList<Material>)JsonSerializer.Deserialize(ref reader, typeof(ImmutableList<Material>));
}
public override void Write(Utf8JsonWriter writer, ImmutableList<Material> value, JsonSerializerOptions options)
{
public override void Write(Utf8JsonWriter writer, ImmutableList<Material> value, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
}
}
}

View File

@ -1,41 +1,37 @@
using System;
using System.Text.Json;
using System.Text.Json;
using System.Text.Json.Serialization;
using Observatory.Framework.Files.ParameterTypes;
namespace Observatory.Framework.Files.Converters
namespace Observatory.Framework.Files.Converters;
public class MissionEffectConverter : JsonConverter<MissionEffect>
{
public class MissionEffectConverter : JsonConverter<MissionEffect>
public override MissionEffect Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
public override MissionEffect Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
var effect = reader.GetString();
//TODO: Find out all possible values
switch (effect)
{
string effect = reader.GetString();
//TODO: Find out all possible values
switch (effect)
{
case "+":
effect = "Low";
break;
case "++":
effect = "Med";
break;
case "+++":
case "++++":
case "+++++":
effect = "High";
break;
default:
break;
}
MissionEffect missionEffect = (MissionEffect)Enum.Parse(typeof(MissionEffect), effect, true);
return missionEffect;
case "+":
effect = "Low";
break;
case "++":
effect = "Med";
break;
case "+++":
case "++++":
case "+++++":
effect = "High";
break;
}
public override void Write(Utf8JsonWriter writer, MissionEffect value, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
var missionEffect = (MissionEffect)Enum.Parse(typeof(MissionEffect), effect, true);
return missionEffect;
}
}
public override void Write(Utf8JsonWriter writer, MissionEffect value, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
}

View File

@ -1,24 +1,19 @@
using System;
using System.Collections.Immutable;
using System.Text;
using System.Text.Json;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Observatory.Framework.Files.Converters
{
class MutableStringDoubleConverter : JsonConverter<object>
{
public override object Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.String)
return reader.GetString();
else
return reader.GetDouble();
}
namespace Observatory.Framework.Files.Converters;
public override void Write(Utf8JsonWriter writer, object value, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
class MutableStringDoubleConverter : JsonConverter<object>
{
public override object Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.String)
return reader.GetString();
return reader.GetDouble();
}
}
public override void Write(Utf8JsonWriter writer, object value, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
}

View File

@ -1,21 +1,19 @@
using System;
using System.Text.Json;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Observatory.Framework.Files.Converters
namespace Observatory.Framework.Files.Converters;
class PipConverter : JsonConverter<(int Sys, int Eng, int Wep)>
{
class PipConverter : JsonConverter<(int Sys, int Eng, int Wep)>
public override (int Sys, int Eng, int Wep) Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
public override (int Sys, int Eng, int Wep) Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
int[] values = (int[])JsonSerializer.Deserialize(ref reader, typeof(int[]));
var values = (int[])JsonSerializer.Deserialize(ref reader, typeof(int[]));
return (Sys: values[0], Eng: values[1], Wep: values[2]);
}
public override void Write(Utf8JsonWriter writer, (int Sys, int Eng, int Wep) value, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
return (Sys: values[0], Eng: values[1], Wep: values[2]);
}
}
public override void Write(Utf8JsonWriter writer, (int Sys, int Eng, int Wep) value, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
}

View File

@ -1,19 +1,17 @@
using System;
using System.Text.Json;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Observatory.Framework.Files.Converters
{
public class RepInfConverter : JsonConverter<int>
{
public override int Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return reader.GetString().Trim().Length;
}
namespace Observatory.Framework.Files.Converters;
public override void Write(Utf8JsonWriter writer, int value, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
public class RepInfConverter : JsonConverter<int>
{
public override int Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return reader.GetString().Trim().Length;
}
}
public override void Write(Utf8JsonWriter writer, int value, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
}

View File

@ -1,24 +1,22 @@
using System;
using System.Text.Json;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Observatory.Framework.Files.Converters
namespace Observatory.Framework.Files.Converters;
/// <summary>
/// Converting the ordered array of coordinates from the journal to a named tuple for clarity.
/// </summary>
public class StarPosConverter : JsonConverter<(double x, double y, double z)>
{
/// <summary>
/// Converting the ordered array of coordinates from the journal to a named tuple for clarity.
/// </summary>
public class StarPosConverter : JsonConverter<(double x, double y, double z)>
public override (double x, double y, double z) Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
public override (double x, double y, double z) Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
double[] values = (double[])JsonSerializer.Deserialize(ref reader, typeof(double[]));
var values = (double[])JsonSerializer.Deserialize(ref reader, typeof(double[]));
return (x: values[0], y: values[1], z: values[2]);
}
public override void Write(Utf8JsonWriter writer, (double x, double y, double z) value, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
return (x: values[0], y: values[1], z: values[2]);
}
}
public override void Write(Utf8JsonWriter writer, (double x, double y, double z) value, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
}

View File

@ -1,28 +1,26 @@
using System;
using System.Text.Json;
using System.Text.Json;
using System.Text.Json.Serialization;
using Observatory.Framework.Files.ParameterTypes;
namespace Observatory.Framework.Files.Converters
namespace Observatory.Framework.Files.Converters;
public class StationServiceConverter : JsonConverter<StationService>
{
public class StationServiceConverter : JsonConverter<StationService>
public override StationService Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
public override StationService Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
var services = StationService.None;
while (reader.Read() && reader.TokenType != JsonTokenType.EndArray)
{
StationService services = StationService.None;
while (reader.Read() && reader.TokenType != JsonTokenType.EndArray)
{
services |= (StationService)Enum.Parse(typeof(StationService), reader.GetString(), true);
}
return services;
services |= (StationService)Enum.Parse(typeof(StationService), reader.GetString(), true);
}
public override void Write(Utf8JsonWriter writer, StationService value, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
return services;
}
}
public override void Write(Utf8JsonWriter writer, StationService value, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
}

View File

@ -1,24 +1,19 @@
using System;
using System.Collections.Immutable;
using System.Text;
using System.Text.Json;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Observatory.Framework.Files.Converters
{
class StringIntConverter : JsonConverter<int>
{
public override int Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.String)
return Int32.Parse(reader.GetString());
else
return reader.GetInt32();
}
namespace Observatory.Framework.Files.Converters;
public override void Write(Utf8JsonWriter writer, int value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString());
}
class StringIntConverter : JsonConverter<int>
{
public override int Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.String)
return int.Parse(reader.GetString());
return reader.GetInt32();
}
}
public override void Write(Utf8JsonWriter writer, int value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString());
}
}

View File

@ -1,35 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.Json;
using System.Threading.Tasks;
using System.Reflection.Metadata.Ecma335;
namespace Observatory.Framework.Files.Converters
namespace Observatory.Framework.Files.Converters;
class ThargoidWarRemainingTimeConverter : JsonConverter<int>
{
class ThargoidWarRemainingTimeConverter : JsonConverter<int>
public override int Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
public override int Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.String)
{
string value = reader.GetString();
var value = reader.GetString();
int dayCount = Int32.TryParse(value.Split(' ')[0], out int days)
var dayCount = int.TryParse(value.Split(' ')[0], out var days)
? days
: 0;
return dayCount;
}
else
return reader.GetInt32();
}
return reader.GetInt32();
}
public override void Write(Utf8JsonWriter writer, int value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString() + " Days");
public override void Write(Utf8JsonWriter writer, int value, JsonSerializerOptions options)
{
writer.WriteStringValue(value + " Days");
}
}
}
}

View File

@ -1,29 +1,25 @@
using Observatory.Framework.Files.ParameterTypes;
using System;
using System.Collections.Immutable;
using System.Text;
using System.Text.Json;
using System.Text.Json;
using System.Text.Json.Serialization;
using Observatory.Framework.Files.ParameterTypes;
namespace Observatory.Framework.Files.Converters
namespace Observatory.Framework.Files.Converters;
class VoucherTypeConverter : JsonConverter<VoucherType>
{
class VoucherTypeConverter : JsonConverter<VoucherType>
public override VoucherType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
public override VoucherType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
string voucher = reader.GetString();
var voucher = reader.GetString();
if (voucher.Length == 0)
voucher = "None";
VoucherType missionEffect = (VoucherType)Enum.Parse(typeof(VoucherType), voucher, true);
var missionEffect = (VoucherType)Enum.Parse(typeof(VoucherType), voucher, true);
return missionEffect;
}
public override void Write(Utf8JsonWriter writer, VoucherType value, JsonSerializerOptions options)
{
public override void Write(Utf8JsonWriter writer, VoucherType value, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
}
}
}