< Summary

Information
Class: Trailblazer.Pathing.TraversalLegend
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Authoring/TraversalLegend.cs
Line coverage
100%
Covered lines: 33
Uncovered lines: 0
Coverable lines: 33
Total lines: 79
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
CreateBuiltIn()100%11100%
Register(...)100%44100%
TryGetEntry(...)100%11100%
NormalizeToken(...)100%44100%

File(s)

/home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Authoring/TraversalLegend.cs

#LineLine coverage
 1using SwiftCollections;
 2using System;
 3using System.Runtime.CompilerServices;
 4
 5namespace Trailblazer.Pathing;
 6
 7/// <summary>
 8/// Maps authoring tokens into chart cells and generated transition media.
 9/// </summary>
 10public sealed class TraversalLegend
 11{
 4612    private readonly SwiftDictionary<string, TraversalLegendEntry> _entries =
 4613        new(8, StringComparer.Ordinal);
 14
 15    /// <summary>
 16    /// Creates a built-in traversal legend with predefined token mappings.
 17    /// </summary>
 18    /// <returns>A traversal legend with built-in entries.</returns>
 19    public static TraversalLegend CreateBuiltIn()
 20    {
 4521        var legend = new TraversalLegend();
 22        // These tokens intentionally contribute no chart traversal and no generated transition anchor.
 4523        legend.Register(string.Empty, TraversalLegendEntry.SkipCell());
 4524        legend.Register(".", TraversalLegendEntry.SkipCell());
 4525        legend.Register("X", TraversalLegendEntry.SkipCell());
 4526        legend.Register("S", TraversalLegendEntry.Solid(NavigationChartCell.Solid));
 4527        legend.Register("SC", new TraversalLegendEntry(new NavigationChartCell(
 4528            TraversalMedia.Solid,
 4529            flags: NavigationChartCellFlags.ClimbSurfaceHint)));
 4530        legend.Register("G", TraversalLegendEntry.Gas());
 4531        legend.Register("L", TraversalLegendEntry.Liquid());
 4532        legend.Register("LC", new TraversalLegendEntry(
 4533            new NavigationChartCell(
 4534                TraversalMedia.Solid | TraversalMedia.Liquid,
 4535                flags: NavigationChartCellFlags.ClimbSurfaceHint),
 4536            TraversalMedia.Solid | TraversalMedia.Liquid));
 4537        legend.Register("SG", new TraversalLegendEntry(
 4538            NavigationChartCell.SolidGas,
 4539            TraversalMedia.Solid | TraversalMedia.Gas));
 4540        legend.Register("SL", new TraversalLegendEntry(
 4541            NavigationChartCell.SolidLiquid,
 4542            TraversalMedia.Solid | TraversalMedia.Liquid));
 4543        return legend;
 44    }
 45
 46    /// <summary>
 47    /// Registers a new token mapping in the legend.
 48    /// Tokens are normalized by trimming whitespace, and cannot include the transition marker character '!'.
 49    /// </summary>
 50    /// <param name="token">The token to register.</param>
 51    /// <param name="entry">The legend entry associated with the token.</param>
 52    /// <returns>True if the token was successfully registered; false if the token already exists in the legend.</return
 53    /// <exception cref="ArgumentException">Thrown if the token contains invalid characters.</exception>
 54    public bool Register(string token, TraversalLegendEntry entry)
 55    {
 45456        string normalizedToken = NormalizeToken(token);
 45457        if (normalizedToken.Contains('!'))
 158            throw new ArgumentException("Legend tokens cannot include transition marker characters.", nameof(token));
 59
 45360        if (_entries.ContainsKey(normalizedToken))
 161            return false;
 62
 45263        _entries.Add(normalizedToken, entry);
 45264        return true;
 65    }
 66
 67    /// <summary>
 68    /// Attempts to retrieve the legend entry associated with the specified token.
 69    /// </summary>
 70    /// <param name="token">The token to look up in the legend.</param>
 71    /// <param name="entry">When this method returns, contains the legend entry associated with the specified token, if 
 72    /// <returns>True if the token was found in the legend; otherwise, false.</returns>
 73    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 74    public bool TryGetEntry(string token, out TraversalLegendEntry entry) =>
 12275            _entries.TryGetValue(NormalizeToken(token), out entry);
 76
 77    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 57678    private static string NormalizeToken(string token) => token?.Trim() ?? string.Empty;
 79}