< 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: 268
Line coverage: 100%
Branch coverage
100%
Covered branches: 18
Total branches: 18
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%22100%
WithMove(...)100%22100%
WithFall(...)100%22100%
WithPlatform(...)100%22100%
WithJump(...)100%22100%
WithoutJump()100%11100%
WithSlide(...)100%22100%
WithoutSlide()100%11100%
WithWater(...)100%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
 1//=======================================================================
 2// LocomotionProfileBuilder.cs
 3//=======================================================================
 4// MIT License, Copyright (c) 2024-present David Oravsky (mrdav30)
 5// See LICENSE file in the project root for full license information.
 6//=======================================================================
 7
 8using System;
 9
 10namespace Trailblazer.Navigation.Motor;
 11
 12/// <summary>
 13/// Fluent builder for composing built-in locomotion profiles.
 14/// </summary>
 15public sealed class LocomotionProfileBuilder
 16{
 17    #region Constructor
 18
 19    /// <summary>
 20    /// Initializes a new builder.
 21    /// </summary>
 22    /// <param name="includeOptionalLocomotions">When true, seeds the builder with the default full locomotion profile.<
 119523    public LocomotionProfileBuilder(bool includeOptionalLocomotions = true)
 24    {
 119525        Move = new MoveLocomotion();
 119526        Fall = new FallLocomotion();
 119527        Platform = new PlatformLocomotion();
 28
 119529        if (includeOptionalLocomotions)
 30        {
 107131            Jump = new JumpLocomotion();
 107132            Slide = new SlideLocomotion();
 107133            Water = new WaterLocomotion();
 107134            Fly = new FlyLocomotion();
 107135            Climb = new ClimbLocomotion();
 36        }
 119537    }
 38
 39    #endregion
 40
 41    #region Properties
 42
 43    /// <summary>
 44    /// The move locomotion to install.
 45    /// </summary>
 46    public MoveLocomotion Move { get; private set; }
 47
 48    /// <summary>
 49    /// The fall locomotion to install.
 50    /// </summary>
 51    public FallLocomotion Fall { get; private set; }
 52
 53    /// <summary>
 54    /// The required platform locomotion to install.
 55    /// </summary>
 56    public PlatformLocomotion Platform { get; private set; }
 57
 58    /// <summary>
 59    /// The optional jump locomotion to install.
 60    /// </summary>
 61    public JumpLocomotion? Jump { get; private set; }
 62
 63    /// <summary>
 64    /// The optional slide locomotion to install.
 65    /// </summary>
 66    public SlideLocomotion? Slide { get; private set; }
 67
 68    /// <summary>
 69    /// The optional water locomotion to install.
 70    /// </summary>
 71    public WaterLocomotion? Water { get; private set; }
 72
 73    /// <summary>
 74    /// The optional fly locomotion to install.
 75    /// </summary>
 76    public FlyLocomotion? Fly { get; private set; }
 77
 78    /// <summary>
 79    /// The optional climb locomotion to install.
 80    /// </summary>
 81    public ClimbLocomotion? Climb { get; private set; }
 82
 83    #endregion
 84
 85    /// <summary>
 86    /// Replaces the core move locomotion.
 87    /// </summary>
 88    public LocomotionProfileBuilder WithMove(MoveLocomotion move)
 89    {
 490        Move = move ?? throw new ArgumentNullException(nameof(move));
 391        return this;
 92    }
 93
 94    /// <summary>
 95    /// Replaces the core fall locomotion.
 96    /// </summary>
 97    public LocomotionProfileBuilder WithFall(FallLocomotion fall)
 98    {
 499        Fall = fall ?? throw new ArgumentNullException(nameof(fall));
 3100        return this;
 101    }
 102
 103    /// <summary>
 104    /// Installs or replaces platform locomotion.
 105    /// </summary>
 106    public LocomotionProfileBuilder WithPlatform(PlatformLocomotion? platform = null)
 107    {
 2108        Platform = platform ?? new PlatformLocomotion();
 2109        return this;
 110    }
 111
 112    /// <summary>
 113    /// Installs or replaces jump locomotion.
 114    /// </summary>
 115    public LocomotionProfileBuilder WithJump(JumpLocomotion? jump = null)
 116    {
 78117        Jump = jump ?? new JumpLocomotion();
 78118        return this;
 119    }
 120
 121    /// <summary>
 122    /// Removes jump locomotion.
 123    /// </summary>
 124    public LocomotionProfileBuilder WithoutJump()
 125    {
 1126        Jump = null;
 1127        return this;
 128    }
 129
 130    /// <summary>
 131    /// Installs or replaces slide locomotion.
 132    /// </summary>
 133    public LocomotionProfileBuilder WithSlide(SlideLocomotion? slide = null)
 134    {
 76135        Slide = slide ?? new SlideLocomotion();
 76136        return this;
 137    }
 138
 139    /// <summary>
 140    /// Removes slide locomotion.
 141    /// </summary>
 142    public LocomotionProfileBuilder WithoutSlide()
 143    {
 1144        Slide = null;
 1145        return this;
 146    }
 147
 148    /// <summary>
 149    /// Installs or replaces water locomotion.
 150    /// </summary>
 151    public LocomotionProfileBuilder WithWater(WaterLocomotion? water = null)
 152    {
 76153        Water = water ?? new WaterLocomotion();
 76154        return this;
 155    }
 156
 157    /// <summary>
 158    /// Removes water locomotion.
 159    /// </summary>
 160    public LocomotionProfileBuilder WithoutWater()
 161    {
 1162        Water = null;
 1163        return this;
 164    }
 165
 166    /// <summary>
 167    /// Installs or replaces fly locomotion.
 168    /// </summary>
 169    public LocomotionProfileBuilder WithFly(FlyLocomotion? fly = null)
 170    {
 79171        Fly = fly ?? new FlyLocomotion();
 79172        return this;
 173    }
 174
 175    /// <summary>
 176    /// Removes fly locomotion.
 177    /// </summary>
 178    public LocomotionProfileBuilder WithoutFly()
 179    {
 1180        Fly = null;
 1181        return this;
 182    }
 183
 184    /// <summary>
 185    /// Installs or replaces climb locomotion.
 186    /// </summary>
 187    public LocomotionProfileBuilder WithClimb(ClimbLocomotion? climb = null)
 188    {
 78189        Climb = climb ?? new ClimbLocomotion();
 78190        return this;
 191    }
 192
 193    /// <summary>
 194    /// Removes climb locomotion.
 195    /// </summary>
 196    public LocomotionProfileBuilder WithoutClimb()
 197    {
 1198        Climb = null;
 1199        return this;
 200    }
 201
 202    /// <summary>
 203    /// Builds the composed locomotion profile.
 204    /// </summary>
 205    public LocomotionProfile Build()
 206    {
 1194207        return new LocomotionProfile(
 1194208            Move,
 1194209            Fall,
 1194210            Platform,
 1194211            Jump,
 1194212            Slide,
 1194213            Water,
 1194214            Fly,
 1194215            Climb);
 216    }
 217
 218    internal static LocomotionProfileBuilder FromHandler(LocomotionHandler handler)
 219    {
 2220        SwiftThrowHelper.ThrowIfNull(handler, nameof(handler));
 221
 2222        return new LocomotionProfileBuilder(includeOptionalLocomotions: false)
 2223            .WithMove(handler.Move)
 2224            .WithFall(handler.Fall)
 2225            .SetPlatform(handler.Platform)
 2226            .SetJump(handler.Jump)
 2227            .SetSlide(handler.Slide)
 2228            .SetWater(handler.Water)
 2229            .SetFly(handler.Fly)
 2230            .SetClimb(handler.Climb);
 231    }
 232
 233    private LocomotionProfileBuilder SetPlatform(PlatformLocomotion platform)
 234    {
 2235        Platform = platform;
 2236        return this;
 237    }
 238
 239    private LocomotionProfileBuilder SetJump(JumpLocomotion? jump)
 240    {
 2241        Jump = jump;
 2242        return this;
 243    }
 244
 245    private LocomotionProfileBuilder SetSlide(SlideLocomotion? slide)
 246    {
 2247        Slide = slide;
 2248        return this;
 249    }
 250
 251    private LocomotionProfileBuilder SetWater(WaterLocomotion? water)
 252    {
 2253        Water = water;
 2254        return this;
 255    }
 256
 257    private LocomotionProfileBuilder SetFly(FlyLocomotion? fly)
 258    {
 2259        Fly = fly;
 2260        return this;
 261    }
 262
 263    private LocomotionProfileBuilder SetClimb(ClimbLocomotion? climb)
 264    {
 2265        Climb = climb;
 2266        return this;
 267    }
 268}