Skip to content

Commit

Permalink
Fix to use IntegerParser for th10.5
Browse files Browse the repository at this point in the history
  • Loading branch information
y-iihoshi committed Jan 1, 2025
1 parent 8d2192b commit 599353b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
6 changes: 4 additions & 2 deletions ThScoreFileConverter/Models/Th105/CardForDeckReplacer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using ThScoreFileConverter.Core.Models;
using ThScoreFileConverter.Core.Models.Th105;
using ThScoreFileConverter.Helpers;

Expand All @@ -18,8 +19,9 @@ namespace ThScoreFileConverter.Models.Th105;
// %T105DC[ww][x][yy][z]
internal sealed class CardForDeckReplacer : IStringReplaceable
{
private static readonly IntegerParser CardNumberParser = new(@"\d{2}");
private static readonly string Pattern = StringHelper.Create(
$@"{Definitions.FormatPrefix}DC({Parsers.CharaParser.Pattern})({Parsers.CardTypeParser.Pattern})(\d{{2}})([NC])");
$@"{Definitions.FormatPrefix}DC({Parsers.CharaParser.Pattern})({Parsers.CardTypeParser.Pattern})({CardNumberParser.Pattern})([NC])");

private readonly MatchEvaluator evaluator;

Expand All @@ -33,7 +35,7 @@ public CardForDeckReplacer(
{
var chara = Parsers.CharaParser.Parse(match.Groups[1].Value);
var cardType = Parsers.CardTypeParser.Parse(match.Groups[2]);
var number = IntegerHelper.Parse(match.Groups[3].Value);
var number = CardNumberParser.Parse(match.Groups[3]);
var type = match.Groups[4].Value.ToUpperInvariant();

ICardForDeck cardForDeck;
Expand Down
5 changes: 3 additions & 2 deletions ThScoreFileConverter/Models/Th105/CardReplacerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ protected CardReplacerBase(
{
var numLevels = EnumHelper<Level>.NumValues;
var numDigits = IntegerHelper.GetNumDigits(enemyCardIdTable.Max(pair => pair.Value.Count()) * numLevels);
var cardNumberParser = new IntegerParser($@"\d{{{numDigits}}}");

this.pattern = StringHelper.Create($@"{formatPrefix}CARD(\d{{{numDigits}}})({charaParser.Pattern})([NR])");
this.pattern = StringHelper.Create($@"{formatPrefix}CARD({cardNumberParser.Pattern})({charaParser.Pattern})([NR])");
this.evaluator = new MatchEvaluator(match =>
{
var number = IntegerHelper.Parse(match.Groups[1].Value);
var number = cardNumberParser.Parse(match.Groups[1]);
var chara = charaParser.Parse(match.Groups[2]);
var type = match.Groups[3].Value.ToUpperInvariant();

Expand Down
9 changes: 6 additions & 3 deletions ThScoreFileConverter/Models/Th105/CareerReplacerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace ThScoreFileConverter.Models.Th105;
internal class CareerReplacerBase<TChara> : IStringReplaceable
where TChara : struct, Enum
{
private static readonly IntegerParser TypeParser = new(@"[1-3]");

private readonly string pattern;
private readonly MatchEvaluator evaluator;

Expand All @@ -35,13 +37,14 @@ protected CareerReplacerBase(
{
var numLevels = EnumHelper<Level>.NumValues;
var numDigits = IntegerHelper.GetNumDigits(enemyCardIdTable.Max(pair => pair.Value.Count()) * numLevels);
var cardNumberParser = new IntegerParser($@"\d{{{numDigits}}}");

this.pattern = StringHelper.Create($@"{formatPrefix}C(\d{{{numDigits}}})({charaParser.Pattern})([1-3])");
this.pattern = StringHelper.Create($@"{formatPrefix}C({cardNumberParser.Pattern})({charaParser.Pattern})({TypeParser.Pattern})");
this.evaluator = new MatchEvaluator(match =>
{
var number = IntegerHelper.Parse(match.Groups[1].Value);
var number = cardNumberParser.Parse(match.Groups[1]);
var chara = charaParser.Parse(match.Groups[2]);
var type = IntegerHelper.Parse(match.Groups[3].Value);
var type = TypeParser.Parse(match.Groups[3]);

if (!canReplace(number, chara, type))
return match.ToString();
Expand Down
6 changes: 4 additions & 2 deletions ThScoreFileConverter/Models/Th105/CollectRateReplacerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace ThScoreFileConverter.Models.Th105;
internal class CollectRateReplacerBase<TChara> : IStringReplaceable
where TChara : struct, Enum
{
private static readonly IntegerParser TypeParser = new(@"[12]");

private readonly string pattern;
private readonly MatchEvaluator evaluator;

Expand All @@ -34,12 +36,12 @@ protected CollectRateReplacerBase(
INumberFormatter formatter)
{
this.pattern = StringHelper.Create(
$"{formatPrefix}CRG({levelWithTotalParser.Pattern})({charaParser.Pattern})([1-2])");
$"{formatPrefix}CRG({levelWithTotalParser.Pattern})({charaParser.Pattern})({TypeParser.Pattern})");
this.evaluator = new MatchEvaluator(match =>
{
var level = levelWithTotalParser.Parse(match.Groups[1]);
var chara = charaParser.Parse(match.Groups[2]);
var type = IntegerHelper.Parse(match.Groups[3].Value);
var type = TypeParser.Parse(match.Groups[3]);

if (!canReplace(level, chara, type))
return match.ToString();
Expand Down

0 comments on commit 599353b

Please sign in to comment.