diff --git a/Config/ModelMatching.json b/Config/ModelMatching.json index c3ae845..9aae46d 100644 --- a/Config/ModelMatching.json +++ b/Config/ModelMatching.json @@ -83,6 +83,7 @@ "Cessna 525B CitationJet CJ3+": "Cessna CJ4 Citation", "Cessna 650 Citation III": "Cessna CJ4 Citation", "Cessna 510 Citation Mustang": "Cessna CJ4 Citation", + "Cessna 560XLS Citation Excel": "Cessna CJ4 Citation", "Pilatus PC-12/47E": "TBM 930", "Piper PA-46-M600": "TBM 930", "Piper PA-46-M500": "TBM 930", diff --git a/Model/Addon.cs b/Model/Addon.cs index ccc41ad..6ea9632 100644 --- a/Model/Addon.cs +++ b/Model/Addon.cs @@ -4,5 +4,6 @@ public class Addon { public string Title; public string ModelCode; + public string Icao_Airline; } } diff --git a/Model/Aircraft.cs b/Model/Aircraft.cs index 89fe880..c09bafe 100644 --- a/Model/Aircraft.cs +++ b/Model/Aircraft.cs @@ -21,6 +21,7 @@ public class Aircraft public string TailNumber; public string Model; public string Airline; + public string IcaoAirline; public string ModelCode; #endregion Aircraft diff --git a/Util/AddonScanner.cs b/Util/AddonScanner.cs index 04b3c2b..10a623e 100644 --- a/Util/AddonScanner.cs +++ b/Util/AddonScanner.cs @@ -87,6 +87,7 @@ private static List ParseCfg(string cfgPath) string title = ""; string modelCode = ""; + string icaoAirline = ""; foreach (string line in lines) { // Use a tab to indent each line of the file. @@ -97,9 +98,10 @@ private static List ParseCfg(string cfgPath) addons.Add(curentAddon); curentAddon = null; title = ""; + icaoAirline = ""; } } - if (!line.ToLower().StartsWith("title") && !line.ToLower().StartsWith("icao_type_designator")) continue; + if (!line.ToLower().StartsWith("title") && !line.ToLower().StartsWith("icao_type_designator") && !line.ToLower().StartsWith("icao_airline")) continue; string value = line.Split('=')[1].Trim(); if (value.StartsWith("\"")) @@ -120,10 +122,14 @@ private static List ParseCfg(string cfgPath) { title = value; } - else + else if(line.ToLower().StartsWith("icao_type_designator")) { modelCode = value; } + else + { + icaoAirline = value; + } if (curentAddon == null) { @@ -132,6 +138,7 @@ private static List ParseCfg(string cfgPath) curentAddon.Title = title.Trim(); curentAddon.ModelCode = modelCode.Trim(); + curentAddon.Icao_Airline = icaoAirline.Trim(); } if (curentAddon != null && !curentAddon.Title.Contains("AirTraffic")) diff --git a/Util/LiveTrafficHandler.cs b/Util/LiveTrafficHandler.cs index 5bcc8c5..0c78988 100644 --- a/Util/LiveTrafficHandler.cs +++ b/Util/LiveTrafficHandler.cs @@ -75,6 +75,7 @@ private void ParsePlaneData(JObject planeData) int speed = (int)property.Value[5]; string callsign = (string)property.Value[16]; bool isGrounded = (bool)property.Value[14]; + string icaoAirline = (string)property.Value[18]; string airportOrigin = null; string airportDestination = null; string tailNumber = callsign; @@ -94,7 +95,7 @@ private void ParsePlaneData(JObject planeData) { tailNumber = (string)extraData["identification"]?["number"]?["default"] ?? callsign; model = (string)extraData["aircraft"]?["model"]?["text"] ?? "Airbus A320 Neo"; - modelCode = (string)extraData["aircraft"]?["model"]?["code"] ?? "A320"; + modelCode = (string)extraData["aircraft"]?["model"]?["code"] ?? "A32N"; airline = (string)extraData["airline"]?["name"] ?? "Asobo"; airportOrigin = (string)extraData["airport"]?["origin"]?["code"]?["icao"] ?? null; @@ -120,9 +121,10 @@ private void ParsePlaneData(JObject planeData) Airline = airline, AirportOrigin = airportOrigin, AirportDestination = airportDestination, - ModelCode = modelCode + ModelCode = modelCode, + IcaoAirline = icaoAirline }; - aircraft.MatchedModel = ModelMatching.MatchModel(aircraft.ModelCode, aircraft.Model, aircraft.Airline, _addons); + aircraft.MatchedModel = ModelMatching.MatchModel(aircraft.ModelCode, aircraft.Model, aircraft.Airline, aircraft.IcaoAirline, _addons); LiveTrafficAircraft.Add(aircraft); SpawnPlane(aircraft); diff --git a/Util/ModelMatching.cs b/Util/ModelMatching.cs index d44980d..c5535f9 100644 --- a/Util/ModelMatching.cs +++ b/Util/ModelMatching.cs @@ -9,7 +9,7 @@ namespace Simvars.Util { public static class ModelMatching { - public static string MatchModel(string modelCode, string model, string airline, List addons = null) + public static string MatchModel(string modelCode, string model, string airline, string icaoAirline, List addons = null) { List installedAddons = addons ?? AddonScanner.ScanAddons(); @@ -18,43 +18,48 @@ public static string MatchModel(string modelCode, string model, string airline, if (models.GetValue(model) == null) Console.WriteLine($"Failed to model match: {model}"); string matchedModel = (string)models.GetValue(model) ?? (string)models.GetValue(modelCode) ?? installedAddons.FirstOrDefault(addon => addon.ModelCode == modelCode)?.Title?.Replace("Asobo", "")?.Trim() ?? (string)models.GetValue("Default Aircraft") ?? "Airbus A320 Neo"; - if (TryFindAircraft(models, installedAddons, $"{matchedModel} {airline}") != null) + if (installedAddons.FirstOrDefault(addon => addon.Title == matchedModel) == null && installedAddons.FirstOrDefault(addon => addon.Title == matchedModel + " Asobo") == null) { - matchedModel = TryFindAircraft(models, installedAddons, $"{matchedModel} {airline}"); + Console.WriteLine($"Failed to model match: {matchedModel} not installed!"); + matchedModel = installedAddons.FirstOrDefault(addon => addon.ModelCode == modelCode)?.Title ?? "Airbus A320 Neo Asobo"; } - else if (airline.Contains("(") && TryFindAircraft(models, installedAddons, $"{matchedModel} {airline.Split('(')[0].Trim()}") != null) + + if (TryFindAircraft(models, installedAddons, matchedModel, airline, icaoAirline) != null) + { + matchedModel = TryFindAircraft(models, installedAddons, matchedModel, airline, icaoAirline); + } + else if (airline.Contains("(") && TryFindAircraft(models, installedAddons, matchedModel, airline.Split('(')[0].Trim(), icaoAirline ) != null) { - matchedModel = TryFindAircraft(models, installedAddons, $"{matchedModel} {airline.Split('(')[0].Trim()}"); + matchedModel = TryFindAircraft(models, installedAddons, matchedModel, airline.Split('(')[0].Trim(), icaoAirline); } else { if (models.GetValue(matchedModel + " Default") == null) Console.WriteLine($"Failed to model match: {matchedModel} Default"); matchedModel = (string)models.GetValue($"{matchedModel} Default") ?? installedAddons.FirstOrDefault(addon => addon.ModelCode == modelCode)?.Title ?? "Airbus A320 Neo Asobo"; - if ((string) models.GetValue($"{matchedModel} Default") != null && installedAddons.FirstOrDefault(addon => addon.Title == (string)models.GetValue($"{matchedModel} Default")) == null) - { - Console.WriteLine($"Failed to model match: {(string)models.GetValue($"{matchedModel} Default")} not installed!"); - matchedModel = installedAddons.FirstOrDefault(addon => addon.ModelCode == modelCode)?.Title ?? "Airbus A320 Neo Asobo"; - } } Console.WriteLine($"Model matched {model} {airline} with: {matchedModel}"); return matchedModel; } - private static string TryFindAircraft(JObject models, List installedAddons, string fullName) + private static string TryFindAircraft(JObject models, List installedAddons, string model, string airline, string icao) { string foundAircraft = null; - if (models.GetValue(fullName) != null) + if (models.GetValue($"{model} {airline}") != null) + { + foundAircraft = (string)models.GetValue($"{model} {airline}"); + } + else if (installedAddons.FirstOrDefault(addon => addon.Title.StartsWith($"{model} {airline} AI")) != null) { - foundAircraft = (string)models.GetValue(fullName); + foundAircraft = installedAddons.First(addon => addon.Title.StartsWith($"{model} {airline} AI")).Title; } - else if (installedAddons.FirstOrDefault(addon => addon.Title.StartsWith($"{fullName} AI")) != null) + else if (installedAddons.FirstOrDefault(addon => addon.Title.StartsWith($"{model} {airline}")) != null) { - foundAircraft = installedAddons.First(addon => addon.Title.StartsWith($"{fullName} AI")).Title; + foundAircraft = installedAddons.First(addon => addon.Title.StartsWith($"{model} {airline}")).Title; } - else if (installedAddons.FirstOrDefault(addon => addon.Title.StartsWith(fullName)) != null) + else if (installedAddons.FirstOrDefault(addon => addon.Title.StartsWith(model) && addon.Icao_Airline == icao) != null) { - foundAircraft = installedAddons.First(addon => addon.Title.StartsWith(fullName)).Title; + foundAircraft = installedAddons.First(addon => addon.Title.StartsWith(model) && addon.Icao_Airline == icao).Title; } return foundAircraft;