Skip to content

Commit

Permalink
Better modelmatching
Browse files Browse the repository at this point in the history
  • Loading branch information
GewoonJaap committed Aug 10, 2021
1 parent 4d17205 commit b10df27
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions Model/Addon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ public class Addon
public string Title;
public string ModelCode;
public string Icao_Airline;
public bool BaseAircraft;
}
}
2 changes: 1 addition & 1 deletion Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@
// You can specify all the values or you can default the Build and Revision Numbers by using the '*'
// as shown below: [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("2.2.0.0")]
[assembly: AssemblyFileVersion("2.3.0.0")]
19 changes: 13 additions & 6 deletions Util/AddonScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private static List<Addon> GetInstalledAddons(string communityFolder)
try
{
JObject manifest = JObject.Parse(File.ReadAllText(addonDirectory + "\\manifest.json"));
if (((string)manifest["content_type"])?.ToLower() != "aircraft") continue;
if (((string)manifest["content_type"])?.ToLower() != "aircraft" && ((string)manifest["content_type"])?.ToLower() != "livery") continue;
}
catch (Exception)
{
Expand Down Expand Up @@ -96,6 +96,7 @@ private static List<Addon> ParseCfg(string cfgPath)
string title = "";
string modelCode = "";
string icaoAirline = "";
int foundBaseAircraft = 0;
foreach (string line in lines)
{
// Use a tab to indent each line of the file.
Expand Down Expand Up @@ -126,29 +127,35 @@ private static List<Addon> ParseCfg(string cfgPath)
value = value.Split(';')[0].Trim();
}

if(value.Trim() == "") continue;
if (value.Trim() == "") continue;

if (line.ToLower().StartsWith("title"))
{
title = value;
}
else if (line.ToLower().StartsWith("icao_type_designator"))
{
if (foundBaseAircraft == 0)
{
foundBaseAircraft = 1;
}
modelCode = value;
}
else
{
icaoAirline = value;
}

if (curentAddon == null)
{
curentAddon = new Addon();
}
curentAddon ??= new Addon();

curentAddon.Title = title.Trim();
curentAddon.ModelCode = modelCode.Trim();
curentAddon.Icao_Airline = icaoAirline.Trim();
if (foundBaseAircraft == 1)
{
curentAddon.BaseAircraft = true;
foundBaseAircraft = 2;
}
}

if (curentAddon != null && !curentAddon.Title.Contains("AirTraffic"))
Expand Down
2 changes: 1 addition & 1 deletion Util/LiveTrafficHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private void ParsePlaneData(JObject planeData)
double longitude = (double)property.Value[2];
double latitude = (double)property.Value[1];
int heading = (int)property.Value[3];
double altimeter = Math.Round((int)property.Value[4] * 0.3048);
double altimeter = (int)property.Value[4];//Math.Round((int)property.Value[4] * 0.3048);
int speed = (int)property.Value[5];
string callsign = (string)property.Value[16];
bool isGrounded = (bool)property.Value[14];
Expand Down
2 changes: 1 addition & 1 deletion Util/ModelMatching.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static string MatchModel(Aircraft aircraft, List<Addon> addons = null)

Log.Information($"Model matching: {aircraft.model} with airline: {aircraft.airline}, airline ICAO Code: {aircraft.icaoAirline} and modelCode {aircraft.modelCode}");
JObject models = JObject.Parse(File.ReadAllText(@".\Config\ModelMatching.json"));
string matchedModel = (string)models.GetValue(aircraft.model) ?? (string)models.GetValue(aircraft.modelCode) ?? installedAddons.FirstOrDefault(addon => (addon.ModelCode == aircraft.modelCode || addon.Title.Contains(aircraft.shortModel) || addon.Title.Contains(aircraft.shorterModelCode)) && addon.Icao_Airline == "")?.Title ?? installedAddons.FirstOrDefault(addon => addon.ModelCode.Contains(aircraft.shorterModelCode) || addon.Title.Contains(aircraft.shorterModelCode))?.Title ?? (string)models.GetValue("Default Aircraft") ?? "Airbus A320 Neo";
string matchedModel = (string)models.GetValue(aircraft.model) ?? (string)models.GetValue(aircraft.modelCode) ?? installedAddons.FirstOrDefault(addon => ((addon.ModelCode == aircraft.modelCode || addon.Title.Contains(aircraft.shortModel) || addon.Title.Contains(aircraft.shorterModelCode)) && addon.Icao_Airline == "") && addon.BaseAircraft)?.Title ?? installedAddons.FirstOrDefault(addon => (addon.ModelCode == aircraft.modelCode || addon.Title.Contains(aircraft.shortModel) || addon.Title.Contains(aircraft.shorterModelCode)) && addon.Icao_Airline == "")?.Title ?? installedAddons.FirstOrDefault(addon => addon.ModelCode.Contains(aircraft.shorterModelCode) || addon.Title.Contains(aircraft.shorterModelCode))?.Title ?? (string)models.GetValue("Default Aircraft") ?? "Airbus A320 Neo";

matchedModel = matchedModel.Replace("Asobo", "")?.Trim();

Expand Down

0 comments on commit b10df27

Please sign in to comment.