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
|
public enum GameSystem
|
||||||
{
|
{
|
||||||
Dnd5e,
|
Dnd5e,
|
||||||
Dnd3_5,
|
|
||||||
Dnd4e,
|
|
||||||
DnD2024,
|
|
||||||
Pathfinder1e,
|
|
||||||
Pathfinder2e,
|
Pathfinder2e,
|
||||||
Starfinder,
|
CallOfCthulhu7e,
|
||||||
CallOfCthulhu,
|
Shadowdark,
|
||||||
|
OldSchoolEssentials,
|
||||||
|
Dragonbane,
|
||||||
|
BladesInTheDark,
|
||||||
|
Daggerheart,
|
||||||
|
CyberpunkRed,
|
||||||
|
Mothership,
|
||||||
|
AlienRpg,
|
||||||
WarhammerFantasy,
|
WarhammerFantasy,
|
||||||
Warhammer40k,
|
VampireMasquerade5e,
|
||||||
DarkHeresy,
|
StarWarsFfg,
|
||||||
Shadowrun,
|
Genesys,
|
||||||
|
SavageWorlds,
|
||||||
GURPS,
|
GURPS,
|
||||||
Fate,
|
Fate,
|
||||||
SavageWorlds,
|
|
||||||
CyberpunkRed,
|
|
||||||
VampireTheMasquerade,
|
|
||||||
Lancer,
|
|
||||||
BladesInTheDark,
|
|
||||||
DungeonWorld,
|
DungeonWorld,
|
||||||
Numenera,
|
Ironsworn,
|
||||||
CypherSystem,
|
|
||||||
Other
|
Other
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,52 +33,49 @@ public static class GameSystemExtensions
|
|||||||
new Dictionary<GameSystem, string>
|
new Dictionary<GameSystem, string>
|
||||||
{
|
{
|
||||||
[GameSystem.Dnd5e] = "D&D 5e",
|
[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.Pathfinder2e] = "Pathfinder 2e",
|
||||||
[GameSystem.Starfinder] = "Starfinder",
|
[GameSystem.CallOfCthulhu7e] = "Call of Cthulhu 7e",
|
||||||
[GameSystem.CallOfCthulhu] = "Call of Cthulhu",
|
[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.WarhammerFantasy] = "Warhammer Fantasy",
|
||||||
[GameSystem.Warhammer40k] = "Warhammer 40,000",
|
[GameSystem.VampireMasquerade5e] = "Vampire: The Masquerade 5e",
|
||||||
[GameSystem.DarkHeresy] = "Dark Heresy",
|
[GameSystem.StarWarsFfg] = "Star Wars (FFG)",
|
||||||
[GameSystem.Shadowrun] = "Shadowrun",
|
[GameSystem.Genesys] = "Genesys",
|
||||||
|
[GameSystem.SavageWorlds] = "Savage Worlds",
|
||||||
[GameSystem.GURPS] = "GURPS",
|
[GameSystem.GURPS] = "GURPS",
|
||||||
[GameSystem.Fate] = "Fate",
|
[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.DungeonWorld] = "Dungeon World",
|
||||||
[GameSystem.Numenera] = "Numenera",
|
[GameSystem.Ironsworn] = "Ironsworn",
|
||||||
[GameSystem.CypherSystem] = "Cypher System",
|
|
||||||
[GameSystem.Other] = "Другое"
|
[GameSystem.Other] = "Другое"
|
||||||
}.ToFrozenDictionary();
|
}.ToFrozenDictionary();
|
||||||
|
|
||||||
public static string ToDisplayName(this GameSystem system) =>
|
public static string ToDisplayName(this GameSystem system) =>
|
||||||
DisplayNames.TryGetValue(system, out var name) ? name : "Другое";
|
DisplayNames.TryGetValue(system, out var name) ? name : "Другое";
|
||||||
|
|
||||||
public static GameSystem TryParseFuzzy(string input)
|
public static GameSystem? TryParseFuzzy(string input)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(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;
|
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;
|
continue;
|
||||||
|
|
||||||
var name = system.ToString();
|
var display = value.ToDisplayName().ToLowerInvariant();
|
||||||
if (name.Contains(input, StringComparison.OrdinalIgnoreCase) ||
|
if (display == normalized || display.Contains(normalized) || normalized.Contains(display))
|
||||||
input.Contains(name, StringComparison.OrdinalIgnoreCase))
|
return value;
|
||||||
{
|
|
||||||
return system;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return GameSystem.Other;
|
return GameSystem.Other;
|
||||||
|
|||||||
Reference in New Issue
Block a user