Skip to content

Commit

Permalink
Work around an FDev bug in star name casing in status.json destinatio…
Browse files Browse the repository at this point in the history
…n data.
  • Loading branch information
Tkael committed Feb 3, 2025
1 parent 620ecd0 commit e877012
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions DataDefinitions/Body.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using Utilities;

namespace EddiDataDefinitions
Expand All @@ -30,7 +31,7 @@ public class Body : INotifyPropertyChanged

/// <summary>The short name of the body</summary>
[PublicAPI, JsonIgnore]
public string shortname => GetShortName(bodyname, systemname);
public string shortname => GetShortName(bodyname, systemname, bodyType);

/// <summary>The name of the system in which the body resides</summary>
[PublicAPI]
Expand Down Expand Up @@ -641,12 +642,18 @@ private long estimateBodyValue(bool isMapped, bool isMappedEfficiently)
return null;
}

public static string GetShortName(string bodyname, string systemname)
public static string GetShortName(string bodyname, string systemname, BodyType bodyType = null)
{
if (bodyname is null) { return null; }
return (systemname == null || bodyname == systemname || !bodyname.StartsWith(systemname))
var shortName = (systemname == null || bodyname == systemname || !bodyname.StartsWith(systemname))
? bodyname
: bodyname?.Replace(systemname, "").Trim();
: bodyname.Replace(systemname, "").Trim();
if ( bodyType == BodyType.Star && Regex.IsMatch( shortName.ToUpper(), @"(?<STARS>(?<=^|\s)[A-E]+)" ) )
{
// Status destinations can have incorrect casing on star names. Fix that here.
shortName = shortName.ToUpper();
}
return shortName;
}

public static int CompareById(Body lhs, Body rhs) => Math.Sign((lhs.bodyId - rhs.bodyId) ?? 0);
Expand Down
2 changes: 1 addition & 1 deletion SpeechService/Translations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static string GetTranslation(string val, bool useICAO = false, string typ
private static readonly Regex MOON = new Regex(@"^[a-z]$");
private static readonly Regex SUBSTARS = new Regex(@"^\bA[BCDE]?[CDE]?[DE]?[E]?\b|\bB[CDE]?[DE]?[E]?\b|\bC[DE]?[E]?\b|\bD[E]?\b$");
private static readonly Regex SYSTEMBODY = new Regex(@"^(.*?) ([A-E]+ ){0,2}(Belt(?:\s|$)|Cluster(?:\s|$)|Ring|\d{1,2}(?:\s|$)|[A-Za-z](?:\s|$)){1,12}$");
private static readonly Regex SHORTBODY = new Regex(@"(?=\S)(?<STARS>(?<=^|\s)A?B?C?D?E?)? ?(?<PLANET>(?<=^|\s)\d{1,2})? ?(?<MOON>(?<=^|\s)[a-z])? ?(?<SUBMOON>(?<=^|\s)[a-z])? ?(?>(?<=^|\s)(?<RINGORBELTGROUP>[A-Z]) (?<RINGORBELTTYPE>Belt|Ring))? ?(?>(?<=^|\s)(?<CLUSTER>Cluster) (?<CLUSTERNUMBER>\d*))?$");
private static readonly Regex SHORTBODY = new Regex(@"(?=\S)(?<STARS>(?<=^|\s)[A-E]+)? ?(?<PLANET>(?<=^|\s)\d{1,2})? ?(?<MOON>(?<=^|\s)[a-z])? ?(?<SUBMOON>(?<=^|\s)[a-z])? ?(?>(?<=^|\s)(?<RINGORBELTGROUP>[A-Z]) (?<RINGORBELTTYPE>Belt|Ring))? ?(?>(?<=^|\s)(?<CLUSTER>Cluster) (?<CLUSTERNUMBER>\d*))?$");
private static readonly Regex PROC_GEN_SYSTEM = new Regex(@"^(?<SECTOR>[\w\s'.()-]+) (?<COORDINATES>(?<l1>[A-Za-z])(?<l2>[A-Za-z])-(?<l3>[A-Za-z]) (?<mcode>[A-Za-z])(?:(?<n1>\d+)-)?(?<n2>\d+))$");
private static readonly Regex PROC_GEN_SYSTEM_BODY = new Regex(@"^(?<SYSTEM>(?<SECTOR>[\w\s'.()-]+) (?<COORDINATES>(?<l1>[A-Za-z])(?<l2>[A-Za-z])-(?<l3>[A-Za-z]) (?<mcode>[A-Za-z])(?:(?<n1>\d+)-)?(?<n2>\d+))) ?(?<BODY>.*)$");

Expand Down

0 comments on commit e877012

Please sign in to comment.