1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-22 13:50:14 +00:00
msfs-popout-panel-manager/Model/UserProfile.cs

101 lines
2.9 KiB
C#
Raw Normal View History

2022-06-30 23:53:08 +00:00
using CommunityToolkit.Mvvm.ComponentModel;
using Newtonsoft.Json;
2022-04-18 03:38:33 +00:00
using System;
2022-01-27 13:40:04 +00:00
using System.Collections.ObjectModel;
namespace MSFSPopoutPanelManager.Model
{
2022-06-30 23:53:08 +00:00
public class UserProfile : ObservableObject
2022-01-27 13:40:04 +00:00
{
public UserProfile()
{
PanelSourceCoordinates = new ObservableCollection<PanelSourceCoordinate>();
PanelConfigs = new ObservableCollection<PanelConfig>();
2022-04-18 16:24:00 +00:00
BindingAircraftLiveries = new ObservableCollection<string>();
2022-01-27 13:40:04 +00:00
IsLocked = false;
}
public int ProfileId { get; set; }
public string ProfileName { get; set; }
2022-04-18 03:38:33 +00:00
[JsonConverter(typeof(SingleValueArrayConvertor<string>))]
2022-04-18 16:24:00 +00:00
public ObservableCollection<string> BindingAircraftLiveries { get; set; }
2022-01-27 13:40:04 +00:00
public bool IsLocked { get; set; }
2022-07-06 18:09:10 +00:00
public ObservableCollection<PanelSourceCoordinate> PanelSourceCoordinates { get; set; }
2022-01-27 13:40:04 +00:00
public ObservableCollection<PanelConfig> PanelConfigs { get; set; }
public bool PowerOnRequiredForColdStart { get; set; }
public void Reset()
{
PanelSourceCoordinates.Clear();
PanelConfigs.Clear();
IsLocked = false;
}
[JsonIgnore]
public bool IsActive { get; set; }
[JsonIgnore]
2022-04-18 16:24:00 +00:00
public bool HasBindingAircraftLiveries
2022-01-27 13:40:04 +00:00
{
2022-04-18 16:24:00 +00:00
get { return BindingAircraftLiveries.Count > 0; }
2022-01-27 13:40:04 +00:00
}
2022-04-18 16:24:00 +00:00
2022-07-06 18:09:10 +00:00
[JsonIgnore]
public bool HasPanelSourceCoordinates
{
get { return PanelSourceCoordinates.Count > 0; }
}
2022-04-18 16:24:00 +00:00
#region Legacy Properties
// Support pre-Version 3.3 tag for one time conversion
[JsonConverter(typeof(SingleValueArrayConvertor<string>))]
public ObservableCollection<string> BindingPlaneTitle
{
set { BindingAircraftLiveries = value; }
}
#endregion
2022-04-18 03:38:33 +00:00
}
public class SingleValueArrayConvertor<T> : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return true;
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
object val = new object();
2022-06-30 23:53:08 +00:00
if (reader.TokenType == JsonToken.String)
2022-04-18 03:38:33 +00:00
{
var instance = (string)serializer.Deserialize(reader, typeof(string));
val = new ObservableCollection<string>() { instance };
}
2022-06-30 23:53:08 +00:00
else if (reader.TokenType == JsonToken.StartArray)
2022-04-18 03:38:33 +00:00
{
val = serializer.Deserialize(reader, objectType);
}
2022-06-30 23:53:08 +00:00
else if (reader.TokenType == JsonToken.Null)
2022-04-18 03:38:33 +00:00
{
val = new ObservableCollection<string>();
}
return val;
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
serializer.Serialize(writer, value);
}
}
2022-01-27 13:40:04 +00:00
}