Skip to content

Commit

Permalink
feature: Add meaningful display for Selector-like elements
Browse files Browse the repository at this point in the history
  • Loading branch information
amis92 committed Mar 19, 2020
1 parent e940774 commit 7834fbd
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/WarHub.GodMode/Data/NodeDisplayExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using WarHub.ArmouryModel.Source;
using System.Globalization;
using WarHub.ArmouryModel.Source;
using WarHub.GodMode.SourceAnalysis;
using static System.FormattableString;

namespace WarHub.GodMode.Data
{
Expand Down Expand Up @@ -58,6 +60,12 @@ public static string GetNodeDisplayTitle(this GamesystemContext ctx, SourceNode
EntryLinkNode link => GetLinkNameFromTargetOrSelf(link),
InfoLinkNode link => GetLinkNameFromTargetOrSelf(link),
INameableNode named => named.Name,
ConditionNode cond =>
Invariant($"if {cond.Type} {FormatValue(cond.Value, cond.PercentValue)} {cond.Field} in {cond.Scope} of {cond.ChildId}"),
ConditionGroupNode condGroup => Invariant($"{condGroup.Type}"),
ConstraintNode constr =>
Invariant($"{constr.Type} {FormatValue(constr.Value, constr.PercentValue)} {constr.Field} in {constr.Scope}"),
ModifierNode mod => GetModifierTitle(mod),
_ => node.Kind.ToString()
};

Expand All @@ -67,6 +75,23 @@ string GetLinkNameFromTargetOrSelf<T>(T link) where T : SourceNode, INameableNod
? ctx.GetNodeDisplayTitle(target)
: link.Name;
}

string GetModifierTitle(ModifierNode mod)
{
var typeText = mod.Type switch
{
ModifierKind.Increment => " by",
ModifierKind.Decrement => " by",
ModifierKind.Set => " to",
ModifierKind.Append => " with",
_ => ""
};
return Invariant($"{mod.Type} {mod.Field}{typeText} {mod.Value}");
}
string FormatValue(decimal number, bool percent)
{
return number.ToString(percent ? "P" : "G", CultureInfo.InvariantCulture);
}
}
}
}

0 comments on commit 7834fbd

Please sign in to comment.