Share critical cell parsing across app and importer
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
|
||||
using RolemasterDb.App.Domain;
|
||||
using SharedParsing = RolemasterDb.CriticalParsing;
|
||||
|
||||
namespace RolemasterDb.ImportTool.Parsing;
|
||||
|
||||
@@ -559,12 +560,17 @@ internal static class CriticalTableParserSupport
|
||||
List<ParsedCriticalResult> parsedResults,
|
||||
List<string> validationErrors)
|
||||
{
|
||||
var sharedLegend = ToSharedAffixLegend(affixLegend);
|
||||
|
||||
foreach (var cellEntry in cellEntries)
|
||||
{
|
||||
var content = CriticalCellTextParser.Parse(cellEntry.Lines, affixLegend);
|
||||
var content = SharedParsing.CriticalCellTextParser.Parse(cellEntry.Lines, sharedLegend);
|
||||
validationErrors.AddRange(content.ValidationErrors.Select(error =>
|
||||
$"Cell '{BuildCellIdentifier(cellEntry)}': {error}"));
|
||||
|
||||
var effects = content.Effects.Select(ToImportToolEffect).ToList();
|
||||
var branches = content.Branches.Select(ToImportToolBranch).ToList();
|
||||
|
||||
parsedCells.Add(new ParsedCriticalCellArtifact(
|
||||
cellEntry.GroupKey,
|
||||
cellEntry.RollBandLabel,
|
||||
@@ -574,8 +580,8 @@ internal static class CriticalTableParserSupport
|
||||
content.RawCellText,
|
||||
content.DescriptionText,
|
||||
content.RawAffixText,
|
||||
content.Effects,
|
||||
content.Branches));
|
||||
effects,
|
||||
branches));
|
||||
|
||||
parsedResults.Add(new ParsedCriticalResult(
|
||||
cellEntry.GroupKey,
|
||||
@@ -584,11 +590,44 @@ internal static class CriticalTableParserSupport
|
||||
content.RawCellText,
|
||||
content.DescriptionText,
|
||||
content.RawAffixText,
|
||||
content.Effects,
|
||||
content.Branches));
|
||||
effects,
|
||||
branches));
|
||||
}
|
||||
}
|
||||
|
||||
private static SharedParsing.AffixLegend ToSharedAffixLegend(AffixLegend affixLegend) =>
|
||||
new(
|
||||
affixLegend.SymbolEffects,
|
||||
affixLegend.ClassificationSymbols.Except(affixLegend.EffectSymbols).ToList(),
|
||||
affixLegend.SupportsFoePenalty,
|
||||
affixLegend.SupportsAttackerBonus,
|
||||
affixLegend.SupportsPowerPointModifier);
|
||||
|
||||
private static ParsedCriticalEffect ToImportToolEffect(SharedParsing.ParsedCriticalEffect effect) =>
|
||||
new(
|
||||
effect.EffectCode,
|
||||
effect.Target,
|
||||
effect.ValueInteger,
|
||||
effect.ValueExpression,
|
||||
effect.DurationRounds,
|
||||
effect.PerRound,
|
||||
effect.Modifier,
|
||||
effect.BodyPart,
|
||||
effect.IsPermanent,
|
||||
effect.SourceType,
|
||||
effect.SourceText);
|
||||
|
||||
private static ParsedCriticalBranch ToImportToolBranch(SharedParsing.ParsedCriticalBranch branch) =>
|
||||
new(
|
||||
branch.BranchKind,
|
||||
branch.ConditionKey,
|
||||
branch.ConditionText,
|
||||
branch.RawText,
|
||||
branch.DescriptionText,
|
||||
branch.RawAffixText,
|
||||
branch.Effects.Select(ToImportToolEffect).ToList(),
|
||||
branch.SortOrder);
|
||||
|
||||
private static string BuildCellIdentifier(ColumnarCellEntry cellEntry) =>
|
||||
cellEntry.GroupKey is null
|
||||
? $"{cellEntry.RollBandLabel}/{cellEntry.ColumnKey}"
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\RolemasterDb.CriticalParsing\RolemasterDb.CriticalParsing.csproj" />
|
||||
<ProjectReference Include="..\RolemasterDb.App\RolemasterDb.App.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user