| | | 1 | | using System; |
| | | 2 | | |
| | | 3 | | namespace Trailblazer.Navigation.Motor; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Describes the installed locomotion modules for a object motor. |
| | | 7 | | /// </summary> |
| | | 8 | | public sealed class LocomotionProfile |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// Initializes a new locomotion profile. |
| | | 12 | | /// </summary> |
| | 875 | 13 | | public LocomotionProfile( |
| | 875 | 14 | | MoveLocomotion move, |
| | 875 | 15 | | FallLocomotion fall, |
| | 875 | 16 | | PlatformLocomotion? platform = null, |
| | 875 | 17 | | JumpLocomotion? jump = null, |
| | 875 | 18 | | SlideLocomotion? slide = null, |
| | 875 | 19 | | WaterLocomotion? water = null, |
| | 875 | 20 | | FlyLocomotion? fly = null, |
| | 875 | 21 | | ClimbLocomotion? climb = null) |
| | | 22 | | { |
| | 875 | 23 | | Move = move ?? throw new ArgumentNullException(nameof(move)); |
| | 874 | 24 | | Fall = fall ?? throw new ArgumentNullException(nameof(fall)); |
| | 873 | 25 | | Platform = platform ?? new PlatformLocomotion(); |
| | 873 | 26 | | Jump = jump; |
| | 873 | 27 | | Slide = slide; |
| | 873 | 28 | | Water = water; |
| | 873 | 29 | | Fly = fly; |
| | 873 | 30 | | Climb = climb; |
| | 873 | 31 | | } |
| | | 32 | | |
| | | 33 | | /// <summary> |
| | | 34 | | /// Core movement configuration for the motor. |
| | | 35 | | /// </summary> |
| | | 36 | | public MoveLocomotion Move { get; } |
| | | 37 | | |
| | | 38 | | /// <summary> |
| | | 39 | | /// Fall-state configuration for the motor. |
| | | 40 | | /// </summary> |
| | | 41 | | public FallLocomotion Fall { get; } |
| | | 42 | | |
| | | 43 | | /// <summary> |
| | | 44 | | /// Required moving-platform locomotion. |
| | | 45 | | /// </summary> |
| | | 46 | | public PlatformLocomotion Platform { get; } |
| | | 47 | | |
| | | 48 | | /// <summary> |
| | | 49 | | /// Optional jump locomotion. |
| | | 50 | | /// </summary> |
| | | 51 | | public JumpLocomotion? Jump { get; } |
| | | 52 | | |
| | | 53 | | /// <summary> |
| | | 54 | | /// Optional slide locomotion. |
| | | 55 | | /// </summary> |
| | | 56 | | public SlideLocomotion? Slide { get; } |
| | | 57 | | |
| | | 58 | | /// <summary> |
| | | 59 | | /// Optional water locomotion. |
| | | 60 | | /// </summary> |
| | | 61 | | public WaterLocomotion? Water { get; } |
| | | 62 | | |
| | | 63 | | /// <summary> |
| | | 64 | | /// Optional flight locomotion. |
| | | 65 | | /// </summary> |
| | | 66 | | public FlyLocomotion? Fly { get; } |
| | | 67 | | |
| | | 68 | | /// <summary> |
| | | 69 | | /// Optional climb locomotion. |
| | | 70 | | /// </summary> |
| | | 71 | | public ClimbLocomotion? Climb { get; } |
| | | 72 | | |
| | | 73 | | /// <summary> |
| | | 74 | | /// Gets the installed locomotion flags for this profile. |
| | | 75 | | /// </summary> |
| | | 76 | | public LocomotionKind InstalledKinds |
| | | 77 | | { |
| | | 78 | | get |
| | | 79 | | { |
| | 6 | 80 | | LocomotionKind result = LocomotionKind.Core; |
| | | 81 | | |
| | 6 | 82 | | if (Jump != null) |
| | 5 | 83 | | result |= LocomotionKind.Jump; |
| | | 84 | | |
| | 6 | 85 | | if (Slide != null) |
| | 2 | 86 | | result |= LocomotionKind.Slide; |
| | | 87 | | |
| | 6 | 88 | | if (Water != null) |
| | 4 | 89 | | result |= LocomotionKind.Water; |
| | | 90 | | |
| | 6 | 91 | | if (Fly != null) |
| | 3 | 92 | | result |= LocomotionKind.Fly; |
| | | 93 | | |
| | 6 | 94 | | if (Climb != null) |
| | 4 | 95 | | result |= LocomotionKind.Climb; |
| | | 96 | | |
| | 6 | 97 | | return result; |
| | | 98 | | } |
| | | 99 | | } |
| | | 100 | | |
| | | 101 | | /// <summary> |
| | | 102 | | /// Creates the default profile with all built-in locomotions installed. |
| | | 103 | | /// </summary> |
| | | 104 | | public static LocomotionProfile CreateDefault() |
| | | 105 | | { |
| | 730 | 106 | | return new LocomotionProfileBuilder().Build(); |
| | | 107 | | } |
| | | 108 | | |
| | | 109 | | /// <summary> |
| | | 110 | | /// Creates a minimal profile with only required locomotion behavior installed. |
| | | 111 | | /// </summary> |
| | | 112 | | public static LocomotionProfile CreateCoreOnly() |
| | | 113 | | { |
| | 26 | 114 | | return new LocomotionProfileBuilder(includeOptionalLocomotions: false).Build(); |
| | | 115 | | } |
| | | 116 | | |
| | | 117 | | /// <summary> |
| | | 118 | | /// Creates a new builder seeded with the default full locomotion profile. |
| | | 119 | | /// </summary> |
| | | 120 | | public static LocomotionProfileBuilder CreateBuilder() |
| | | 121 | | { |
| | 1 | 122 | | return new LocomotionProfileBuilder(); |
| | | 123 | | } |
| | | 124 | | |
| | | 125 | | /// <summary> |
| | | 126 | | /// Creates a new builder seeded from the currently installed handler locomotions. |
| | | 127 | | /// </summary> |
| | | 128 | | internal static LocomotionProfileBuilder CreateBuilder(LocomotionHandler handler) |
| | | 129 | | { |
| | 2 | 130 | | return LocomotionProfileBuilder.FromHandler(handler); |
| | | 131 | | } |
| | | 132 | | } |