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