Skip to content

Commit

Permalink
Fix to use IntegerParser for th09
Browse files Browse the repository at this point in the history
  • Loading branch information
y-iihoshi committed Jan 1, 2025
1 parent c8c84e3 commit 955e792
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions ThScoreFileConverter/Models/Th09/ClearReplacer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ internal sealed class ClearReplacer(
INumberFormatter formatter)
: IStringReplaceable
{
private static readonly IntegerParser TypeParser = new(@"[12]");
private static readonly string Pattern = StringHelper.Create(
$"{Definitions.FormatPrefix}CLEAR({Parsers.LevelParser.Pattern})({Parsers.CharaParser.Pattern})([12])");
$"{Definitions.FormatPrefix}CLEAR({Parsers.LevelParser.Pattern})({Parsers.CharaParser.Pattern})({TypeParser.Pattern})");

private readonly MatchEvaluator evaluator = new(match =>
{
var level = Parsers.LevelParser.Parse(match.Groups[1]);
var chara = Parsers.CharaParser.Parse(match.Groups[2].Value);
var type = IntegerHelper.Parse(match.Groups[3].Value);
var type = TypeParser.Parse(match.Groups[3]);

var count = clearCounts.TryGetValue(chara, out var clearCount)
&& clearCount.Counts.TryGetValue(level, out var c) ? c : default;
Expand Down
8 changes: 5 additions & 3 deletions ThScoreFileConverter/Models/Th09/ScoreReplacer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ internal sealed class ScoreReplacer(
INumberFormatter formatter)
: IStringReplaceable
{
private static readonly IntegerParser RankParser = new(@"[1-5]");
private static readonly IntegerParser TypeParser = new(@"[1-3]");
private static readonly string Pattern = StringHelper.Create(
$"{Definitions.FormatPrefix}SCR({Parsers.LevelParser.Pattern})({Parsers.CharaParser.Pattern})([1-5])([1-3])");
$"{Definitions.FormatPrefix}SCR({Parsers.LevelParser.Pattern})({Parsers.CharaParser.Pattern})({RankParser.Pattern})({TypeParser.Pattern})");

private readonly MatchEvaluator evaluator = new(match =>
{
var level = Parsers.LevelParser.Parse(match.Groups[1]);
var chara = Parsers.CharaParser.Parse(match.Groups[2].Value);
var rank = IntegerHelper.ToZeroBased(IntegerHelper.Parse(match.Groups[3].Value));
var type = IntegerHelper.Parse(match.Groups[4].Value);
var rank = IntegerHelper.ToZeroBased(RankParser.Parse(match.Groups[3]));
var type = TypeParser.Parse(match.Groups[4]);

var score = rankings.TryGetValue((chara, level), out var highScores) && (rank < highScores.Count)
? highScores[rank] : null;
Expand Down

0 comments on commit 955e792

Please sign in to comment.