Skip to content

Commit

Permalink
Fix to use IntegerParser for th15
Browse files Browse the repository at this point in the history
  • Loading branch information
y-iihoshi committed Jan 1, 2025
1 parent f352789 commit d411f1e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
8 changes: 5 additions & 3 deletions ThScoreFileConverter/Models/Th15/CareerReplacer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ internal sealed class CareerReplacer(
IReadOnlyDictionary<CharaWithTotal, IClearData> clearDataDictionary, INumberFormatter formatter)
: IStringReplaceable
{
private static readonly IntegerParser CardNumberParser = new(@"\d{3}");
private static readonly IntegerParser TypeParser = new(@"[12]");
private static readonly string Pattern = StringHelper.Create(
$@"{Definitions.FormatPrefix}C({Parsers.GameModeParser.Pattern})(\d{{3}})({Parsers.CharaWithTotalParser.Pattern})([12])");
$@"{Definitions.FormatPrefix}C({Parsers.GameModeParser.Pattern})({CardNumberParser.Pattern})({Parsers.CharaWithTotalParser.Pattern})({TypeParser.Pattern})");

private readonly MatchEvaluator evaluator = new(match =>
{
var mode = Parsers.GameModeParser.Parse(match.Groups[1]);
var number = IntegerHelper.Parse(match.Groups[2].Value);
var number = CardNumberParser.Parse(match.Groups[2]);
var chara = Parsers.CharaWithTotalParser.Parse(match.Groups[3].Value);
var type = IntegerHelper.Parse(match.Groups[4].Value);
var type = TypeParser.Parse(match.Groups[4]);

Func<Th13.ISpellCard<Level>, int> getCount = type switch
{
Expand Down
6 changes: 4 additions & 2 deletions ThScoreFileConverter/Models/Th15/CharaExReplacer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using ThScoreFileConverter.Core.Models;
using ThScoreFileConverter.Core.Models.Th15;
using ThScoreFileConverter.Helpers;

Expand All @@ -19,8 +20,9 @@ namespace ThScoreFileConverter.Models.Th15;
// %T15CHARAEX[w][x][yy][z]
internal sealed class CharaExReplacer : IStringReplaceable
{
private static readonly IntegerParser TypeParser = new(@"[1-3]");
private static readonly string Pattern = StringHelper.Create(
$"{Definitions.FormatPrefix}CHARAEX({Parsers.GameModeParser.Pattern})({Parsers.LevelWithTotalParser.Pattern})({Parsers.CharaWithTotalParser.Pattern})([1-3])");
$"{Definitions.FormatPrefix}CHARAEX({Parsers.GameModeParser.Pattern})({Parsers.LevelWithTotalParser.Pattern})({Parsers.CharaWithTotalParser.Pattern})({TypeParser.Pattern})");

private readonly MatchEvaluator evaluator;

Expand All @@ -32,7 +34,7 @@ public CharaExReplacer(
var mode = Parsers.GameModeParser.Parse(match.Groups[1]);
var level = Parsers.LevelWithTotalParser.Parse(match.Groups[2]);
var chara = Parsers.CharaWithTotalParser.Parse(match.Groups[3].Value);
var type = IntegerHelper.Parse(match.Groups[4].Value);
var type = TypeParser.Parse(match.Groups[4]);

Func<IClearDataPerGameMode, long> getValueByType = (level, type) switch
{
Expand Down
6 changes: 4 additions & 2 deletions ThScoreFileConverter/Models/Th15/CharaReplacer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using ThScoreFileConverter.Core.Models;
using ThScoreFileConverter.Core.Models.Th15;
using ThScoreFileConverter.Helpers;

Expand All @@ -19,8 +20,9 @@ namespace ThScoreFileConverter.Models.Th15;
// %T15CHARA[x][yy][z]
internal sealed class CharaReplacer : IStringReplaceable
{
private static readonly IntegerParser TypeParser = new(@"[1-3]");
private static readonly string Pattern = StringHelper.Create(
$"{Definitions.FormatPrefix}CHARA({Parsers.GameModeParser.Pattern})({Parsers.CharaWithTotalParser.Pattern})([1-3])");
$"{Definitions.FormatPrefix}CHARA({Parsers.GameModeParser.Pattern})({Parsers.CharaWithTotalParser.Pattern})({TypeParser.Pattern})");

private readonly MatchEvaluator evaluator;

Expand All @@ -31,7 +33,7 @@ public CharaReplacer(
{
var mode = Parsers.GameModeParser.Parse(match.Groups[1]);
var chara = Parsers.CharaWithTotalParser.Parse(match.Groups[2].Value);
var type = IntegerHelper.Parse(match.Groups[3].Value);
var type = TypeParser.Parse(match.Groups[3]);

Func<IClearDataPerGameMode, long> getValueByType = type switch
{
Expand Down
8 changes: 5 additions & 3 deletions ThScoreFileConverter/Models/Th15/ScoreReplacer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ namespace ThScoreFileConverter.Models.Th15;
// %T15SCR[v][w][xx][y][z]
internal sealed class ScoreReplacer : IStringReplaceable
{
private static readonly IntegerParser RankParser = new(@"\d");
private static readonly IntegerParser TypeParser = new(@"[1-6]");
private static readonly string Pattern = StringHelper.Create(
$@"{Definitions.FormatPrefix}SCR({Parsers.GameModeParser.Pattern})({Parsers.LevelParser.Pattern})({Parsers.CharaParser.Pattern})(\d)([1-6])");
$@"{Definitions.FormatPrefix}SCR({Parsers.GameModeParser.Pattern})({Parsers.LevelParser.Pattern})({Parsers.CharaParser.Pattern})({RankParser.Pattern})({TypeParser.Pattern})");

private readonly MatchEvaluator evaluator;

Expand All @@ -33,8 +35,8 @@ public ScoreReplacer(
var mode = Parsers.GameModeParser.Parse(match.Groups[1]);
var level = (LevelWithTotal)Parsers.LevelParser.Parse(match.Groups[2]);
var chara = (CharaWithTotal)Parsers.CharaParser.Parse(match.Groups[3].Value);
var rank = IntegerHelper.ToZeroBased(IntegerHelper.Parse(match.Groups[4].Value));
var type = IntegerHelper.Parse(match.Groups[5].Value);
var rank = IntegerHelper.ToZeroBased(RankParser.Parse(match.Groups[4]));
var type = TypeParser.Parse(match.Groups[5]);

#if false // FIXME
if (level == LevelWithTotal.Extra)
Expand Down

0 comments on commit d411f1e

Please sign in to comment.