Skip to content

Commit

Permalink
Fix to use PatternAttribute for GameMode
Browse files Browse the repository at this point in the history
  • Loading branch information
y-iihoshi committed Dec 30, 2024
1 parent 7c9d748 commit f8fe466
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 21 deletions.
9 changes: 9 additions & 0 deletions TemplateGenerator/Extensions/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,13 @@ public static Dictionary<string, string> ToStringDictionary<TEnum>(this IEnumera

return source.ToDictionary(static element => element.ToShortName(), static element => element.ToString());
}

public static Dictionary<string, TValue> ToPatternKeyedDictionary<TKey, TValue>(
this IEnumerable<(TKey Key, TValue Value)> source)
where TKey : struct, Enum
{
Guard.IsNotNull(source);

return source.ToDictionary(static pair => pair.Key.ToPattern(), static pair => pair.Value);
}
}
2 changes: 1 addition & 1 deletion TemplateGenerator/Models/Definitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ public class Definitions
{
(GameMode.Story, "ゲーム本編"),
(GameMode.SpellPractice, "スペルプラクティス"),
}.ToStringKeyedDictionary();
}.ToPatternKeyedDictionary();
}
2 changes: 1 addition & 1 deletion TemplateGenerator/Models/Th15/Definitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ public class Definitions : Models.Definitions
{
(GameMode.Pointdevice, "完全無欠モード"),
(GameMode.Legacy, "レガシーモード"),
}.ToStringKeyedDictionary();
}.ToPatternKeyedDictionary();
}
4 changes: 2 additions & 2 deletions ThScoreFileConverter.Core/Models/GameMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public enum GameMode
/// <summary>
/// Story Mode.
/// </summary>
[EnumAltName("S")]
[Pattern("S")]
Story,

/// <summary>
/// Spell Practice Mode.
/// </summary>
[EnumAltName("P")]
[Pattern("P")]
SpellPractice,
}
4 changes: 2 additions & 2 deletions ThScoreFileConverter.Core/Models/Th15/GameMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public enum GameMode
/// <summary>
/// Represents the Pointdevice Mode.
/// </summary>
[EnumAltName("P")]
[Pattern("P")]
Pointdevice,

/// <summary>
/// Represents the Legacy Mode.
/// </summary>
[EnumAltName("L")]
[Pattern("L")]
Legacy,
}
7 changes: 4 additions & 3 deletions ThScoreFileConverter/Models/Th08/Parsers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
// </copyright>
//-----------------------------------------------------------------------

using ThScoreFileConverter.Core.Models;
using ThScoreFileConverter.Core.Models.Th08;
using GameMode = ThScoreFileConverter.Core.Models.GameMode;
using Level = ThScoreFileConverter.Core.Models.Level;
using LevelWithTotal = ThScoreFileConverter.Core.Models.LevelWithTotal;
using Stage = ThScoreFileConverter.Core.Models.Th08.Stage;
using StageWithTotal = ThScoreFileConverter.Core.Models.Th08.StageWithTotal;

namespace ThScoreFileConverter.Models.Th08;

Expand All @@ -20,8 +22,7 @@ internal static class Parsers
/// <summary>
/// Gets the parser of <see cref="GameMode"/>.
/// </summary>
public static EnumShortNameParser<GameMode> GameModeParser { get; } =
new EnumShortNameParser<GameMode>();
public static EnumPatternParser<GameMode> GameModeParser { get; } = new();

/// <summary>
/// Gets the parser of <see cref="Level"/>.
Expand Down
3 changes: 1 addition & 2 deletions ThScoreFileConverter/Models/Th13/Parsers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ internal static class Parsers
/// <summary>
/// Gets the parser of <see cref="GameMode"/>.
/// </summary>
public static EnumShortNameParser<GameMode> GameModeParser { get; } =
new EnumShortNameParser<GameMode>();
public static EnumPatternParser<GameMode> GameModeParser { get; } = new();

/// <summary>
/// Gets the parser of <see cref="Level"/>.
Expand Down
3 changes: 1 addition & 2 deletions ThScoreFileConverter/Models/Th14/Parsers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ internal static class Parsers
/// <summary>
/// Gets the parser of <see cref="GameMode"/>.
/// </summary>
public static EnumShortNameParser<GameMode> GameModeParser { get; } =
new EnumShortNameParser<GameMode>();
public static EnumPatternParser<GameMode> GameModeParser { get; } = new();

/// <summary>
/// Gets the parser of <see cref="Level"/>.
Expand Down
3 changes: 1 addition & 2 deletions ThScoreFileConverter/Models/Th15/Parsers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ internal static class Parsers
/// <summary>
/// Gets the parser of <see cref="GameMode"/>.
/// </summary>
public static EnumShortNameParser<GameMode> GameModeParser { get; } =
new EnumShortNameParser<GameMode>();
public static EnumPatternParser<GameMode> GameModeParser { get; } = new();

/// <summary>
/// Gets the parser of <see cref="Level"/>.
Expand Down
3 changes: 1 addition & 2 deletions ThScoreFileConverter/Models/Th16/Parsers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ internal static class Parsers
/// <summary>
/// Gets the parser of <see cref="GameMode"/>.
/// </summary>
public static EnumShortNameParser<GameMode> GameModeParser { get; } =
new EnumShortNameParser<GameMode>();
public static EnumPatternParser<GameMode> GameModeParser { get; } = new();

/// <summary>
/// Gets the parser of <see cref="Level"/>.
Expand Down
3 changes: 1 addition & 2 deletions ThScoreFileConverter/Models/Th17/Parsers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ internal static class Parsers
/// <summary>
/// Gets the parser of <see cref="GameMode"/>.
/// </summary>
public static EnumShortNameParser<GameMode> GameModeParser { get; } =
new EnumShortNameParser<GameMode>();
public static EnumPatternParser<GameMode> GameModeParser { get; } = new();

/// <summary>
/// Gets the parser of <see cref="Level"/>.
Expand Down
3 changes: 1 addition & 2 deletions ThScoreFileConverter/Models/Th18/Parsers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ internal static class Parsers
/// <summary>
/// Gets the parser of <see cref="GameMode"/>.
/// </summary>
public static EnumShortNameParser<GameMode> GameModeParser { get; } =
new EnumShortNameParser<GameMode>();
public static EnumPatternParser<GameMode> GameModeParser { get; } = new();

/// <summary>
/// Gets the parser of <see cref="Level"/>.
Expand Down

0 comments on commit f8fe466

Please sign in to comment.