2
0
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:
Xjph
2021-10-21 19:31:32 -02:30
committed by GitHub
parent 456c80198a
commit 4c1031b8f9
371 changed files with 7565 additions and 5 deletions

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

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

View File

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

View File

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

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

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

View File

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

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

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

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

View File

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

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

View File

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