< Summary

Information
Class: Trailblazer.Navigation.Motor.LocomotionProfileBuilder
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Navigation/Motor/Locomotion/Profiles/LocomotionProfileBuilder.cs
Line coverage
100%
Covered lines: 68
Uncovered lines: 0
Coverable lines: 68
Total lines: 262
Line coverage: 100%
Branch coverage
88%
Covered branches: 16
Total branches: 18
Branch coverage: 88.8%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%22100%
WithMove(...)100%22100%
WithFall(...)100%22100%
WithPlatform(...)100%22100%
WithJump(...)100%22100%
WithoutJump()100%11100%
WithSlide(...)50%22100%
WithoutSlide()100%11100%
WithWater(...)50%22100%
WithoutWater()100%11100%
WithFly(...)100%22100%
WithoutFly()100%11100%
WithClimb(...)100%22100%
WithoutClimb()100%11100%
Build()100%11100%
FromHandler(...)100%11100%
SetPlatform(...)100%11100%
SetJump(...)100%11100%
SetSlide(...)100%11100%
SetWater(...)100%11100%
SetFly(...)100%11100%
SetClimb(...)100%11100%

File(s)

/home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Navigation/Motor/Locomotion/Profiles/LocomotionProfileBuilder.cs

#LineLine coverage
 1using SwiftCollections;
 2using System;
 3
 4namespace Trailblazer.Navigation.Motor;
 5
 6/// <summary>
 7/// Fluent builder for composing built-in locomotion profiles.
 8/// </summary>
 9public sealed class LocomotionProfileBuilder
 10{
 11    #region Constructor
 12
 13    /// <summary>
 14    /// Initializes a new builder.
 15    /// </summary>
 16    /// <param name="includeOptionalLocomotions">When true, seeds the builder with the default full locomotion profile.<
 81817    public LocomotionProfileBuilder(bool includeOptionalLocomotions = true)
 18    {
 81819        Move = new MoveLocomotion();
 81820        Fall = new FallLocomotion();
 81821        Platform = new PlatformLocomotion();
 22
 81823        if (includeOptionalLocomotions)
 24        {
 73125            Jump = new JumpLocomotion();
 73126            Slide = new SlideLocomotion();
 73127            Water = new WaterLocomotion();
 73128            Fly = new FlyLocomotion();
 73129            Climb = new ClimbLocomotion();
 30        }
 81831    }
 32
 33    #endregion
 34
 35    #region Properties
 36
 37    /// <summary>
 38    /// The move locomotion to install.
 39    /// </summary>
 40    public MoveLocomotion Move { get; private set; }
 41
 42    /// <summary>
 43    /// The fall locomotion to install.
 44    /// </summary>
 45    public FallLocomotion Fall { get; private set; }
 46
 47    /// <summary>
 48    /// The required platform locomotion to install.
 49    /// </summary>
 50    public PlatformLocomotion Platform { get; private set; }
 51
 52    /// <summary>
 53    /// The optional jump locomotion to install.
 54    /// </summary>
 55    public JumpLocomotion? Jump { get; private set; }
 56
 57    /// <summary>
 58    /// The optional slide locomotion to install.
 59    /// </summary>
 60    public SlideLocomotion? Slide { get; private set; }
 61
 62    /// <summary>
 63    /// The optional water locomotion to install.
 64    /// </summary>
 65    public WaterLocomotion? Water { get; private set; }
 66
 67    /// <summary>
 68    /// The optional fly locomotion to install.
 69    /// </summary>
 70    public FlyLocomotion? Fly { get; private set; }
 71
 72    /// <summary>
 73    /// The optional climb locomotion to install.
 74    /// </summary>
 75    public ClimbLocomotion? Climb { get; private set; }
 76
 77    #endregion
 78
 79    /// <summary>
 80    /// Replaces the core move locomotion.
 81    /// </summary>
 82    public LocomotionProfileBuilder WithMove(MoveLocomotion move)
 83    {
 484        Move = move ?? throw new ArgumentNullException(nameof(move));
 385        return this;
 86    }
 87
 88    /// <summary>
 89    /// Replaces the core fall locomotion.
 90    /// </summary>
 91    public LocomotionProfileBuilder WithFall(FallLocomotion fall)
 92    {
 493        Fall = fall ?? throw new ArgumentNullException(nameof(fall));
 394        return this;
 95    }
 96
 97    /// <summary>
 98    /// Installs or replaces platform locomotion.
 99    /// </summary>
 100    public LocomotionProfileBuilder WithPlatform(PlatformLocomotion? platform = null)
 101    {
 2102        Platform = platform ?? new PlatformLocomotion();
 2103        return this;
 104    }
 105
 106    /// <summary>
 107    /// Installs or replaces jump locomotion.
 108    /// </summary>
 109    public LocomotionProfileBuilder WithJump(JumpLocomotion? jump = null)
 110    {
 53111        Jump = jump ?? new JumpLocomotion();
 53112        return this;
 113    }
 114
 115    /// <summary>
 116    /// Removes jump locomotion.
 117    /// </summary>
 118    public LocomotionProfileBuilder WithoutJump()
 119    {
 1120        Jump = null;
 1121        return this;
 122    }
 123
 124    /// <summary>
 125    /// Installs or replaces slide locomotion.
 126    /// </summary>
 127    public LocomotionProfileBuilder WithSlide(SlideLocomotion? slide = null)
 128    {
 51129        Slide = slide ?? new SlideLocomotion();
 51130        return this;
 131    }
 132
 133    /// <summary>
 134    /// Removes slide locomotion.
 135    /// </summary>
 136    public LocomotionProfileBuilder WithoutSlide()
 137    {
 1138        Slide = null;
 1139        return this;
 140    }
 141
 142    /// <summary>
 143    /// Installs or replaces water locomotion.
 144    /// </summary>
 145    public LocomotionProfileBuilder WithWater(WaterLocomotion? water = null)
 146    {
 51147        Water = water ?? new WaterLocomotion();
 51148        return this;
 149    }
 150
 151    /// <summary>
 152    /// Removes water locomotion.
 153    /// </summary>
 154    public LocomotionProfileBuilder WithoutWater()
 155    {
 1156        Water = null;
 1157        return this;
 158    }
 159
 160    /// <summary>
 161    /// Installs or replaces fly locomotion.
 162    /// </summary>
 163    public LocomotionProfileBuilder WithFly(FlyLocomotion? fly = null)
 164    {
 54165        Fly = fly ?? new FlyLocomotion();
 54166        return this;
 167    }
 168
 169    /// <summary>
 170    /// Removes fly locomotion.
 171    /// </summary>
 172    public LocomotionProfileBuilder WithoutFly()
 173    {
 1174        Fly = null;
 1175        return this;
 176    }
 177
 178    /// <summary>
 179    /// Installs or replaces climb locomotion.
 180    /// </summary>
 181    public LocomotionProfileBuilder WithClimb(ClimbLocomotion? climb = null)
 182    {
 53183        Climb = climb ?? new ClimbLocomotion();
 53184        return this;
 185    }
 186
 187    /// <summary>
 188    /// Removes climb locomotion.
 189    /// </summary>
 190    public LocomotionProfileBuilder WithoutClimb()
 191    {
 1192        Climb = null;
 1193        return this;
 194    }
 195
 196    /// <summary>
 197    /// Builds the composed locomotion profile.
 198    /// </summary>
 199    public LocomotionProfile Build()
 200    {
 817201        return new LocomotionProfile(
 817202            Move,
 817203            Fall,
 817204            Platform,
 817205            Jump,
 817206            Slide,
 817207            Water,
 817208            Fly,
 817209            Climb);
 210    }
 211
 212    internal static LocomotionProfileBuilder FromHandler(LocomotionHandler handler)
 213    {
 2214        SwiftThrowHelper.ThrowIfNull(handler, nameof(handler));
 215
 2216        return new LocomotionProfileBuilder(includeOptionalLocomotions: false)
 2217            .WithMove(handler.Move)
 2218            .WithFall(handler.Fall)
 2219            .SetPlatform(handler.Platform)
 2220            .SetJump(handler.Jump)
 2221            .SetSlide(handler.Slide)
 2222            .SetWater(handler.Water)
 2223            .SetFly(handler.Fly)
 2224            .SetClimb(handler.Climb);
 225    }
 226
 227    private LocomotionProfileBuilder SetPlatform(PlatformLocomotion platform)
 228    {
 2229        Platform = platform;
 2230        return this;
 231    }
 232
 233    private LocomotionProfileBuilder SetJump(JumpLocomotion? jump)
 234    {
 2235        Jump = jump;
 2236        return this;
 237    }
 238
 239    private LocomotionProfileBuilder SetSlide(SlideLocomotion? slide)
 240    {
 2241        Slide = slide;
 2242        return this;
 243    }
 244
 245    private LocomotionProfileBuilder SetWater(WaterLocomotion? water)
 246    {
 2247        Water = water;
 2248        return this;
 249    }
 250
 251    private LocomotionProfileBuilder SetFly(FlyLocomotion? fly)
 252    {
 2253        Fly = fly;
 2254        return this;
 255    }
 256
 257    private LocomotionProfileBuilder SetClimb(ClimbLocomotion? climb)
 258    {
 2259        Climb = climb;
 2260        return this;
 261    }
 262}