Support signed power point affixes

This commit is contained in:
2026-03-15 13:30:16 +01:00
parent 1c03ca4586
commit cc6df978ef
6 changed files with 158 additions and 47 deletions

View File

@@ -3,6 +3,7 @@
@using System.Diagnostics.CodeAnalysis
@using RolemasterDb.App.Domain
@using RolemasterDb.App.Features
@using PowerPointModifierNotation = RolemasterDb.CriticalParsing.PowerPointModifierNotation
@if (EffectiveEffects.Count > 0)
{
@@ -61,7 +62,7 @@
CriticalEffectCodes.DirectHits => $"+{effect.ValueInteger?.ToString() ?? string.Empty}",
CriticalEffectCodes.FoePenalty
or CriticalEffectCodes.AttackerBonusNextRound => effect.Modifier?.ToString() ?? string.Empty,
CriticalEffectCodes.PowerPointModifier => effect.ValueExpression ?? string.Empty,
CriticalEffectCodes.PowerPointModifier => PowerPointModifierNotation.FormatSignedExpression(effect.ValueExpression) ?? string.Empty,
_ => effect.ValueInteger?.ToString()
?? effect.Modifier?.ToString()
?? effect.ValueExpression

View File

@@ -1,4 +1,5 @@
using System.Text.RegularExpressions;
using RolemasterDb.CriticalParsing;
namespace RolemasterDb.App.Features;
@@ -72,25 +73,10 @@ public static class CriticalQuickNotationFormatter
private static string? FormatPowerPointModifier(string? valueExpression, string? sourceText)
{
var expression = CollapseWhitespace(valueExpression);
if (string.IsNullOrWhiteSpace(expression))
{
return sourceText;
}
expression = expression.Trim();
if (expression.StartsWith('+'))
{
expression = expression[1..];
}
if (expression.StartsWith('(') && expression.EndsWith(')') && expression.Length > 2)
{
expression = expression[1..^1].Trim();
}
expression = Regex.Replace(expression, @"\s+", string.Empty);
return $"+{expression}pp";
var expression = PowerPointModifierNotation.FormatSignedExpression(valueExpression);
return string.IsNullOrWhiteSpace(expression)
? sourceText
: $"{expression}pp";
}
private static string CollapseWhitespace(string? value) =>