fix(shared): align GameSystem enum with spec, make TryParseFuzzy nullable and display-name based
This commit is contained in:
@@ -5,27 +5,25 @@ namespace GmRelay.Shared.Domain;
|
||||
public enum GameSystem
|
||||
{
|
||||
Dnd5e,
|
||||
Dnd3_5,
|
||||
Dnd4e,
|
||||
DnD2024,
|
||||
Pathfinder1e,
|
||||
Pathfinder2e,
|
||||
Starfinder,
|
||||
CallOfCthulhu,
|
||||
CallOfCthulhu7e,
|
||||
Shadowdark,
|
||||
OldSchoolEssentials,
|
||||
Dragonbane,
|
||||
BladesInTheDark,
|
||||
Daggerheart,
|
||||
CyberpunkRed,
|
||||
Mothership,
|
||||
AlienRpg,
|
||||
WarhammerFantasy,
|
||||
Warhammer40k,
|
||||
DarkHeresy,
|
||||
Shadowrun,
|
||||
VampireMasquerade5e,
|
||||
StarWarsFfg,
|
||||
Genesys,
|
||||
SavageWorlds,
|
||||
GURPS,
|
||||
Fate,
|
||||
SavageWorlds,
|
||||
CyberpunkRed,
|
||||
VampireTheMasquerade,
|
||||
Lancer,
|
||||
BladesInTheDark,
|
||||
DungeonWorld,
|
||||
Numenera,
|
||||
CypherSystem,
|
||||
Ironsworn,
|
||||
Other
|
||||
}
|
||||
|
||||
@@ -35,52 +33,49 @@ public static class GameSystemExtensions
|
||||
new Dictionary<GameSystem, string>
|
||||
{
|
||||
[GameSystem.Dnd5e] = "D&D 5e",
|
||||
[GameSystem.Dnd3_5] = "D&D 3.5",
|
||||
[GameSystem.Dnd4e] = "D&D 4e",
|
||||
[GameSystem.DnD2024] = "D&D 2024",
|
||||
[GameSystem.Pathfinder1e] = "Pathfinder 1e",
|
||||
[GameSystem.Pathfinder2e] = "Pathfinder 2e",
|
||||
[GameSystem.Starfinder] = "Starfinder",
|
||||
[GameSystem.CallOfCthulhu] = "Call of Cthulhu",
|
||||
[GameSystem.CallOfCthulhu7e] = "Call of Cthulhu 7e",
|
||||
[GameSystem.Shadowdark] = "Shadowdark",
|
||||
[GameSystem.OldSchoolEssentials] = "Old School Essentials",
|
||||
[GameSystem.Dragonbane] = "Dragonbane",
|
||||
[GameSystem.BladesInTheDark] = "Blades in the Dark",
|
||||
[GameSystem.Daggerheart] = "Daggerheart",
|
||||
[GameSystem.CyberpunkRed] = "Cyberpunk RED",
|
||||
[GameSystem.Mothership] = "Mothership",
|
||||
[GameSystem.AlienRpg] = "Alien RPG",
|
||||
[GameSystem.WarhammerFantasy] = "Warhammer Fantasy",
|
||||
[GameSystem.Warhammer40k] = "Warhammer 40,000",
|
||||
[GameSystem.DarkHeresy] = "Dark Heresy",
|
||||
[GameSystem.Shadowrun] = "Shadowrun",
|
||||
[GameSystem.VampireMasquerade5e] = "Vampire: The Masquerade 5e",
|
||||
[GameSystem.StarWarsFfg] = "Star Wars (FFG)",
|
||||
[GameSystem.Genesys] = "Genesys",
|
||||
[GameSystem.SavageWorlds] = "Savage Worlds",
|
||||
[GameSystem.GURPS] = "GURPS",
|
||||
[GameSystem.Fate] = "Fate",
|
||||
[GameSystem.SavageWorlds] = "Savage Worlds",
|
||||
[GameSystem.CyberpunkRed] = "Cyberpunk Red",
|
||||
[GameSystem.VampireTheMasquerade] = "Vampire: The Masquerade",
|
||||
[GameSystem.Lancer] = "Lancer",
|
||||
[GameSystem.BladesInTheDark] = "Blades in the Dark",
|
||||
[GameSystem.DungeonWorld] = "Dungeon World",
|
||||
[GameSystem.Numenera] = "Numenera",
|
||||
[GameSystem.CypherSystem] = "Cypher System",
|
||||
[GameSystem.Ironsworn] = "Ironsworn",
|
||||
[GameSystem.Other] = "Другое"
|
||||
}.ToFrozenDictionary();
|
||||
|
||||
public static string ToDisplayName(this GameSystem system) =>
|
||||
DisplayNames.TryGetValue(system, out var name) ? name : "Другое";
|
||||
|
||||
public static GameSystem TryParseFuzzy(string input)
|
||||
public static GameSystem? TryParseFuzzy(string input)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(input))
|
||||
return GameSystem.Other;
|
||||
return null;
|
||||
|
||||
if (Enum.TryParse<GameSystem>(input, true, out var exact))
|
||||
var normalized = input.Trim().ToLowerInvariant();
|
||||
|
||||
if (Enum.TryParse<GameSystem>(normalized, true, out var exact))
|
||||
return exact;
|
||||
|
||||
foreach (var system in Enum.GetValues<GameSystem>())
|
||||
foreach (var value in Enum.GetValues<GameSystem>())
|
||||
{
|
||||
if (system == GameSystem.Other)
|
||||
if (value == GameSystem.Other)
|
||||
continue;
|
||||
|
||||
var name = system.ToString();
|
||||
if (name.Contains(input, StringComparison.OrdinalIgnoreCase) ||
|
||||
input.Contains(name, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return system;
|
||||
}
|
||||
var display = value.ToDisplayName().ToLowerInvariant();
|
||||
if (display == normalized || display.Contains(normalized) || normalized.Contains(display))
|
||||
return value;
|
||||
}
|
||||
|
||||
return GameSystem.Other;
|
||||
|
||||
Reference in New Issue
Block a user