mirror of
https://github.com/9ParsonsB/Pulsar.git
synced 2025-07-01 08:23:42 -04:00
Reorganize all observatory core projects into monorepo (#25)
* chore: move all observatory repos to core * only save journal folder on change, don't constantly re-check during monitoring * chore: monorepo project changes * chore: monorepo migration
This commit is contained in:
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Observatory.Framework.Files.Converters
|
||||
{
|
||||
class FleetCarrierTravelConverter : JsonConverter<float>
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, float value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStringValue(value.ToString());
|
||||
}
|
||||
}
|
||||
}
|
20
ObservatoryFramework/Files/Converters/IntBoolConverter.cs
Normal file
20
ObservatoryFramework/Files/Converters/IntBoolConverter.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Observatory.Framework.Files.Converters
|
||||
{
|
||||
|
||||
public class IntBoolConverter : JsonConverter<bool>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Observatory.Framework.Files.Converters
|
||||
{
|
||||
public class IntBoolFlexConverter : JsonConverter<bool>
|
||||
{
|
||||
public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType == JsonTokenType.Number)
|
||||
return reader.GetInt16() == 1;
|
||||
else
|
||||
return reader.GetBoolean();
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteBooleanValue(value);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Observatory.Framework.Files.ParameterTypes;
|
||||
|
||||
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()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, TFaction value, JsonSerializerOptions options)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Observatory.Framework.Files.ParameterTypes;
|
||||
|
||||
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>>
|
||||
{
|
||||
public override ImmutableList<MaterialComposition> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType == JsonTokenType.StartObject)
|
||||
{
|
||||
var materialComposition = new List<MaterialComposition>();
|
||||
while (reader.Read())
|
||||
{
|
||||
if (reader.TokenType != JsonTokenType.EndObject)
|
||||
{
|
||||
if (reader.TokenType == JsonTokenType.PropertyName)
|
||||
{
|
||||
string name = reader.GetString();
|
||||
reader.Read();
|
||||
float percent = reader.GetSingle();
|
||||
var material = new MaterialComposition
|
||||
{
|
||||
Name = name,
|
||||
Percent = percent
|
||||
};
|
||||
materialComposition.Add(material);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return materialComposition.ToImmutableList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return (ImmutableList<MaterialComposition>)JsonSerializer.Deserialize(ref reader, typeof(ImmutableList<MaterialComposition>));
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, ImmutableList<MaterialComposition> value, JsonSerializerOptions options)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
56
ObservatoryFramework/Files/Converters/MaterialConverter.cs
Normal file
56
ObservatoryFramework/Files/Converters/MaterialConverter.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Observatory.Framework.Files.ParameterTypes;
|
||||
|
||||
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>>
|
||||
{
|
||||
public override ImmutableList<Material> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType == JsonTokenType.StartObject)
|
||||
{
|
||||
var materialComposition = new List<Material>();
|
||||
while (reader.Read())
|
||||
{
|
||||
if (reader.TokenType != JsonTokenType.EndObject)
|
||||
{
|
||||
if (reader.TokenType == JsonTokenType.PropertyName)
|
||||
{
|
||||
string name = reader.GetString();
|
||||
reader.Read();
|
||||
int count = reader.GetInt32();
|
||||
var material = new Material
|
||||
{
|
||||
Name = name,
|
||||
Count = count
|
||||
};
|
||||
materialComposition.Add(material);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return materialComposition.ToImmutableList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return (ImmutableList<Material>)JsonSerializer.Deserialize(ref reader, typeof(ImmutableList<Material>));
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, ImmutableList<Material> value, JsonSerializerOptions options)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Observatory.Framework.Files.ParameterTypes;
|
||||
|
||||
namespace Observatory.Framework.Files.Converters
|
||||
{
|
||||
public class MissionEffectConverter : JsonConverter<MissionEffect>
|
||||
{
|
||||
public override MissionEffect Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
string effect = reader.GetString();
|
||||
//TODO: Find out all possible values
|
||||
switch (effect)
|
||||
{
|
||||
case "+":
|
||||
effect = "Low";
|
||||
break;
|
||||
case "++":
|
||||
effect = "Med";
|
||||
break;
|
||||
case "+++++":
|
||||
effect = "High";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
MissionEffect missionEffect = (MissionEffect)Enum.Parse(typeof(MissionEffect), effect, true);
|
||||
|
||||
return missionEffect;
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, MissionEffect value, JsonSerializerOptions options)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
21
ObservatoryFramework/Files/Converters/PipConverter.cs
Normal file
21
ObservatoryFramework/Files/Converters/PipConverter.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Observatory.Framework.Files.Converters
|
||||
{
|
||||
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)
|
||||
{
|
||||
int[] 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();
|
||||
}
|
||||
}
|
||||
}
|
19
ObservatoryFramework/Files/Converters/RepInfConverter.cs
Normal file
19
ObservatoryFramework/Files/Converters/RepInfConverter.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
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;
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, int value, JsonSerializerOptions options)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
24
ObservatoryFramework/Files/Converters/StarPosConverter.cs
Normal file
24
ObservatoryFramework/Files/Converters/StarPosConverter.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
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)>
|
||||
{
|
||||
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[]));
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Observatory.Framework.Files.ParameterTypes;
|
||||
|
||||
namespace Observatory.Framework.Files.Converters
|
||||
{
|
||||
public class StationServiceConverter : JsonConverter<StationService>
|
||||
{
|
||||
public override StationService Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
StationService services = StationService.None;
|
||||
|
||||
while (reader.Read() && reader.TokenType != JsonTokenType.EndArray)
|
||||
{
|
||||
services |= (StationService)Enum.Parse(typeof(StationService), reader.GetString(), true);
|
||||
}
|
||||
|
||||
return services;
|
||||
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, StationService value, JsonSerializerOptions options)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
24
ObservatoryFramework/Files/Converters/StringIntConverter.cs
Normal file
24
ObservatoryFramework/Files/Converters/StringIntConverter.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using System.Text;
|
||||
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();
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, int value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStringValue(value.ToString());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
using Observatory.Framework.Files.ParameterTypes;
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Observatory.Framework.Files.Converters
|
||||
{
|
||||
class VoucherTypeConverter : JsonConverter<VoucherType>
|
||||
{
|
||||
public override VoucherType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
string voucher = reader.GetString();
|
||||
|
||||
if (voucher.Length == 0)
|
||||
voucher = "None";
|
||||
|
||||
VoucherType missionEffect = (VoucherType)Enum.Parse(typeof(VoucherType), voucher, true);
|
||||
|
||||
return missionEffect;
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, VoucherType value, JsonSerializerOptions options)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user