Skip to content

Commit

Permalink
Door::Get<T>()
Browse files Browse the repository at this point in the history
  • Loading branch information
louis1706 committed Aug 1, 2024
1 parent 1b6fe4c commit 8df24b9
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 24 deletions.
57 changes: 43 additions & 14 deletions EXILED/Exiled.API/Features/Doors/Door.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ namespace Exiled.API.Features.Doors
using Exiled.API.Enums;
using Exiled.API.Extensions;
using Exiled.API.Features.Core;
using Exiled.API.Features.Hazards;
using Exiled.API.Interfaces;
using global::Hazards;
using Interactables.Interobjects;
using Interactables.Interobjects.DoorUtils;
using MEC;
Expand Down Expand Up @@ -309,6 +311,31 @@ public static Door Get(DoorVariant doorVariant)
return DoorVariantToDoor[doorVariant];
}

/// <summary>
/// Gets the <see cref="Door"/> by <see cref="DoorVariant"/>.
/// </summary>
/// <param name="doorVariant">The <see cref="DoorVariant"/> to convert into an door.</param>
/// <typeparam name="T">The specified <see cref="Door"/> type.</typeparam>
/// <returns>The door wrapper for the given <see cref="DoorVariant"/>.</returns>
public static T Get<T>(DoorVariant doorVariant)
where T : Door => Get(doorVariant) as T;

/// <summary>
/// Gets a <see cref="Door"/> given the specified <see cref="DoorType"/>.
/// </summary>
/// <param name="doorType">The <see cref="DoorType"/> to search for.</param>
/// <returns>The <see cref="Door"/> with the given <see cref="DoorType"/> or <see langword="null"/> if not found.</returns>
public static Door Get(DoorType doorType) => List.FirstOrDefault(x => x.Type == doorType);

/// <summary>
/// Gets the <see cref="Door"/> by <see cref="DoorVariant"/>.
/// </summary>
/// <param name="doorType">The <see cref="DoorVariant"/> to convert into an door.</param>
/// <typeparam name="T">The specified <see cref="Door"/> type.</typeparam>
/// <returns>The door wrapper for the given <see cref="DoorVariant"/>.</returns>
public static T Get<T>(DoorType doorType)
where T : Door => Get(doorType) as T;

/// <summary>
/// Gets a <see cref="Door"/> given the specified name.
/// </summary>
Expand All @@ -320,27 +347,22 @@ public static Door Get(string name)
return nameExtension is null ? null : Get(nameExtension.TargetDoor);
}

/// <summary>
/// Gets the <see cref="Door"/> by <see cref="DoorVariant"/>.
/// </summary>
/// <param name="name">The name to search for.</param>
/// <typeparam name="T">The specified <see cref="Door"/> type.</typeparam>
/// <returns>The door wrapper for the given <see cref="DoorVariant"/>.</returns>
public static T Get<T>(string name)
where T : Door => Get(name) as T;

/// <summary>
/// Gets the door object associated with a specific <see cref="UnityEngine.GameObject"/>, or creates a new one if there isn't one.
/// </summary>
/// <param name="gameObject">The base-game <see cref="UnityEngine.GameObject"/>.</param>
/// <returns>The <see cref="Door"/> with the given name or <see langword="null"/> if not found.</returns>
public static Door Get(GameObject gameObject) => gameObject is null ? null : Get(gameObject.GetComponentInChildren<DoorVariant>());

/// <summary>
/// Gets a <see cref="IEnumerable{T}"/> of <see cref="Door"/> filtered based on a predicate.
/// </summary>
/// <param name="predicate">The condition to satify.</param>
/// <returns>A <see cref="IEnumerable{T}"/> of <see cref="Door"/> which contains elements that satify the condition.</returns>
public static IEnumerable<Door> Get(Func<Door, bool> predicate) => List.Where(predicate);

/// <summary>
/// Gets a <see cref="Door"/> given the specified <see cref="DoorType"/>.
/// </summary>
/// <param name="doorType">The <see cref="DoorType"/> to search for.</param>
/// <returns>The <see cref="Door"/> with the given <see cref="DoorType"/> or <see langword="null"/> if not found.</returns>
public static Door Get(DoorType doorType) => List.FirstOrDefault(x => x.Type == doorType);

/// <summary>
/// Returns the closest <see cref="Door"/> to the given <paramref name="position"/>.
/// </summary>
Expand All @@ -367,6 +389,13 @@ public static Door Random(ZoneType type = ZoneType.Unspecified, bool onlyUnbroke
return doors[UnityEngine.Random.Range(0, doors.Count)];
}

/// <summary>
/// Gets a <see cref="IEnumerable{T}"/> of <see cref="Door"/> filtered based on a predicate.
/// </summary>
/// <param name="predicate">The condition to satify.</param>
/// <returns>A <see cref="IEnumerable{T}"/> of <see cref="Door"/> which contains elements that satify the condition.</returns>
public static IEnumerable<Door> Get(Func<Door, bool> predicate) => List.Where(predicate);

/// <summary>
/// Locks all <see cref="Door">doors</see> given the specified <see cref="ZoneType"/>.
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions EXILED/Exiled.API/Features/Hazards/Hazard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ public static Hazard Get(EnvironmentalHazard environmentalHazard) =>
/// <summary>
/// Gets the <see cref="Hazard"/> by <see cref="EnvironmentalHazard"/>.
/// </summary>
/// <param name="itemBase">The <see cref="EnvironmentalHazard"/> to convert into an hazard.</param>
/// <param name="environmentalHazard">The <see cref="EnvironmentalHazard"/> to convert into an hazard.</param>
/// <typeparam name="T">The specified <see cref="Hazard"/> type.</typeparam>
/// <returns>The hazard wrapper for the given <see cref="EnvironmentalHazard"/>.</returns>
public static T Get<T>(EnvironmentalHazard itemBase)
where T : Hazard => Get(itemBase) as T;
public static T Get<T>(EnvironmentalHazard environmentalHazard)
where T : Hazard => Get(environmentalHazard) as T;

/// <summary>
/// Gets the hazard by the room where it's located.
Expand Down
4 changes: 2 additions & 2 deletions EXILED/Exiled.API/Features/Lift.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ internal Lift(ElevatorChamber elevator)
/// <summary>
/// Gets a value of the internal doors list.
/// </summary>
public IReadOnlyCollection<Doors.ElevatorDoor> Doors => internalDoorsList.Select(x => Door.Get(x).As<Doors.ElevatorDoor>()).ToList();
public IReadOnlyCollection<Doors.ElevatorDoor> Doors => internalDoorsList.Select(x => Door.Get<Doors.ElevatorDoor>(x)).ToList();

/// <summary>
/// Gets a <see cref="IEnumerable{T}"/> of <see cref="Player"/> in the <see cref="Room"/>.
Expand Down Expand Up @@ -201,7 +201,7 @@ public float AnimationTime
/// <summary>
/// Gets the <see cref="CurrentDestination"/>.
/// </summary>
public Doors.ElevatorDoor CurrentDestination => Door.Get(Base.CurrentDestination).As<Doors.ElevatorDoor>();
public Doors.ElevatorDoor CurrentDestination => Door.Get<Doors.ElevatorDoor>(Base.CurrentDestination);

/// <summary>
/// Gets a <see cref="IEnumerable{T}"/> of <see cref="Lift"/> which contains all the <see cref="Lift"/> instances from the specified <see cref="Status"/>.
Expand Down
6 changes: 3 additions & 3 deletions EXILED/Exiled.API/Features/Pickups/Pickup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,11 @@ public static Pickup Get(ItemPickupBase pickupBase)
/// <summary>
/// Gets an existing <see cref="Pickup"/> or creates a new instance of one.
/// </summary>
/// <param name="itemBase">The <see cref="ItemPickupBase"/> to convert into an pickup.</param>
/// <param name="pickupBase">The <see cref="ItemPickupBase"/> to convert into an pickup.</param>
/// <typeparam name="T">The specified <see cref="Pickup"/> type.</typeparam>
/// <returns>The pickup wrapper for the given <see cref="ItemPickupBase"/>.</returns>
public static T Get<T>(ItemPickupBase itemBase)
where T : Pickup => Get(itemBase) as T;
public static T Get<T>(ItemPickupBase pickupBase)
where T : Pickup => Get(pickupBase) as T;

/// <summary>
/// Gets the <see cref="Pickup"/> given a <see cref="Serial"/>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public StartPryingGateEventArgs(Player player, PryableDoor gate, bool isAllowed
{
Player = player;
Scp096 = player.Role.As<Scp096Role>();
Gate = Door.Get(gate).As<Gate>();
Gate = Door.Get<Gate>(gate);
IsAllowed = isAllowed;
}

Expand Down
2 changes: 1 addition & 1 deletion EXILED/Exiled.Events/Patches/Generic/DoorList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static void Postfix(DoorVariant __instance)
foreach (DoorVariant subDoor in checkpoint.Base.SubDoors)
{
subDoor.RegisterRooms();
BreakableDoor targetDoor = Door.Get(subDoor).Cast<BreakableDoor>();
BreakableDoor targetDoor = Door.Get<BreakableDoor>(subDoor);

targetDoor.ParentCheckpointDoor = checkpoint;
checkpoint.SubDoorsValue.Add(targetDoor);
Expand Down

0 comments on commit 8df24b9

Please sign in to comment.