Place names: one validity rule (FactionPlace.IsValidName) for NamePlaces and the place-names command

NamePlaces treats an invalid entry as absent; the command refuses a table holding one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-17 22:14:22 +02:00
commit ac259c6259
3 changed files with 8 additions and 5 deletions

View file

@ -75,5 +75,10 @@ public class FactionPlace
{
[Inspectable, JsonProperty("name"), Key(1)]
public string Name;
// The one rule for a valid place name: trimmed, non-empty and not a catalogue designation (EAC-, any case). Galaxy.NamePlaces
// treats an invalid entry as absent; AetherDb place-names refuses a table that holds one.
public static bool IsValidName(string name) =>
!string.IsNullOrEmpty(name) && name == name.Trim() && !name.StartsWith("EAC-", StringComparison.OrdinalIgnoreCase);
}

View file

@ -358,7 +358,7 @@ public class Galaxy
foreach (var faction in Factions)
{
if (!HomeZones.TryGetValue(faction, out var home)) continue;
var places = (faction.Places ?? Array.Empty<FactionPlace>()).Select(p => p?.Name).Where(n => !string.IsNullOrEmpty(n)).ToArray();
var places = (faction.Places ?? Array.Empty<FactionPlace>()).Select(p => p?.Name).Where(FactionPlace.IsValidName).ToArray();
var next = 0;
var owned = Zones.Select((zone, index) => (zone, index)).Where(z => z.zone.Owner == faction)
.OrderBy(z => z.zone.Distance[home]).ThenBy(z => z.index);

View file

@ -80,10 +80,8 @@ public static class PlaceNamesCommand
throw new InvalidOperationException("Place names row: its ShortName differs from the faction under its key (conflict).");
foreach (var name in row.Names)
{
if (string.IsNullOrEmpty(name) || name != name.Trim())
throw new InvalidOperationException("Place names row: a name is empty or untrimmed (invalid).");
if (name.StartsWith("EAC-", StringComparison.OrdinalIgnoreCase))
throw new InvalidOperationException("Place names row: a name is a catalogue designation (invalid).");
if (!FactionPlace.IsValidName(name))
throw new InvalidOperationException("Place names row: a name is empty, untrimmed or a catalogue designation (invalid).");
if (!seen.Add(name))
throw new InvalidOperationException("Place names table: a name is repeated (conflict).");
}