Skip to content

Commit 8df24b9

Browse files
committed
Door::Get<T>()
1 parent 1b6fe4c commit 8df24b9

File tree

6 files changed

+53
-24
lines changed

6 files changed

+53
-24
lines changed

EXILED/Exiled.API/Features/Doors/Door.cs

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ namespace Exiled.API.Features.Doors
1414
using Exiled.API.Enums;
1515
using Exiled.API.Extensions;
1616
using Exiled.API.Features.Core;
17+
using Exiled.API.Features.Hazards;
1718
using Exiled.API.Interfaces;
19+
using global::Hazards;
1820
using Interactables.Interobjects;
1921
using Interactables.Interobjects.DoorUtils;
2022
using MEC;
@@ -309,6 +311,31 @@ public static Door Get(DoorVariant doorVariant)
309311
return DoorVariantToDoor[doorVariant];
310312
}
311313

314+
/// <summary>
315+
/// Gets the <see cref="Door"/> by <see cref="DoorVariant"/>.
316+
/// </summary>
317+
/// <param name="doorVariant">The <see cref="DoorVariant"/> to convert into an door.</param>
318+
/// <typeparam name="T">The specified <see cref="Door"/> type.</typeparam>
319+
/// <returns>The door wrapper for the given <see cref="DoorVariant"/>.</returns>
320+
public static T Get<T>(DoorVariant doorVariant)
321+
where T : Door => Get(doorVariant) as T;
322+
323+
/// <summary>
324+
/// Gets a <see cref="Door"/> given the specified <see cref="DoorType"/>.
325+
/// </summary>
326+
/// <param name="doorType">The <see cref="DoorType"/> to search for.</param>
327+
/// <returns>The <see cref="Door"/> with the given <see cref="DoorType"/> or <see langword="null"/> if not found.</returns>
328+
public static Door Get(DoorType doorType) => List.FirstOrDefault(x => x.Type == doorType);
329+
330+
/// <summary>
331+
/// Gets the <see cref="Door"/> by <see cref="DoorVariant"/>.
332+
/// </summary>
333+
/// <param name="doorType">The <see cref="DoorVariant"/> to convert into an door.</param>
334+
/// <typeparam name="T">The specified <see cref="Door"/> type.</typeparam>
335+
/// <returns>The door wrapper for the given <see cref="DoorVariant"/>.</returns>
336+
public static T Get<T>(DoorType doorType)
337+
where T : Door => Get(doorType) as T;
338+
312339
/// <summary>
313340
/// Gets a <see cref="Door"/> given the specified name.
314341
/// </summary>
@@ -320,27 +347,22 @@ public static Door Get(string name)
320347
return nameExtension is null ? null : Get(nameExtension.TargetDoor);
321348
}
322349

350+
/// <summary>
351+
/// Gets the <see cref="Door"/> by <see cref="DoorVariant"/>.
352+
/// </summary>
353+
/// <param name="name">The name to search for.</param>
354+
/// <typeparam name="T">The specified <see cref="Door"/> type.</typeparam>
355+
/// <returns>The door wrapper for the given <see cref="DoorVariant"/>.</returns>
356+
public static T Get<T>(string name)
357+
where T : Door => Get(name) as T;
358+
323359
/// <summary>
324360
/// Gets the door object associated with a specific <see cref="UnityEngine.GameObject"/>, or creates a new one if there isn't one.
325361
/// </summary>
326362
/// <param name="gameObject">The base-game <see cref="UnityEngine.GameObject"/>.</param>
327363
/// <returns>The <see cref="Door"/> with the given name or <see langword="null"/> if not found.</returns>
328364
public static Door Get(GameObject gameObject) => gameObject is null ? null : Get(gameObject.GetComponentInChildren<DoorVariant>());
329365

330-
/// <summary>
331-
/// Gets a <see cref="IEnumerable{T}"/> of <see cref="Door"/> filtered based on a predicate.
332-
/// </summary>
333-
/// <param name="predicate">The condition to satify.</param>
334-
/// <returns>A <see cref="IEnumerable{T}"/> of <see cref="Door"/> which contains elements that satify the condition.</returns>
335-
public static IEnumerable<Door> Get(Func<Door, bool> predicate) => List.Where(predicate);
336-
337-
/// <summary>
338-
/// Gets a <see cref="Door"/> given the specified <see cref="DoorType"/>.
339-
/// </summary>
340-
/// <param name="doorType">The <see cref="DoorType"/> to search for.</param>
341-
/// <returns>The <see cref="Door"/> with the given <see cref="DoorType"/> or <see langword="null"/> if not found.</returns>
342-
public static Door Get(DoorType doorType) => List.FirstOrDefault(x => x.Type == doorType);
343-
344366
/// <summary>
345367
/// Returns the closest <see cref="Door"/> to the given <paramref name="position"/>.
346368
/// </summary>
@@ -367,6 +389,13 @@ public static Door Random(ZoneType type = ZoneType.Unspecified, bool onlyUnbroke
367389
return doors[UnityEngine.Random.Range(0, doors.Count)];
368390
}
369391

392+
/// <summary>
393+
/// Gets a <see cref="IEnumerable{T}"/> of <see cref="Door"/> filtered based on a predicate.
394+
/// </summary>
395+
/// <param name="predicate">The condition to satify.</param>
396+
/// <returns>A <see cref="IEnumerable{T}"/> of <see cref="Door"/> which contains elements that satify the condition.</returns>
397+
public static IEnumerable<Door> Get(Func<Door, bool> predicate) => List.Where(predicate);
398+
370399
/// <summary>
371400
/// Locks all <see cref="Door">doors</see> given the specified <see cref="ZoneType"/>.
372401
/// </summary>

EXILED/Exiled.API/Features/Hazards/Hazard.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ public static Hazard Get(EnvironmentalHazard environmentalHazard) =>
126126
/// <summary>
127127
/// Gets the <see cref="Hazard"/> by <see cref="EnvironmentalHazard"/>.
128128
/// </summary>
129-
/// <param name="itemBase">The <see cref="EnvironmentalHazard"/> to convert into an hazard.</param>
129+
/// <param name="environmentalHazard">The <see cref="EnvironmentalHazard"/> to convert into an hazard.</param>
130130
/// <typeparam name="T">The specified <see cref="Hazard"/> type.</typeparam>
131131
/// <returns>The hazard wrapper for the given <see cref="EnvironmentalHazard"/>.</returns>
132-
public static T Get<T>(EnvironmentalHazard itemBase)
133-
where T : Hazard => Get(itemBase) as T;
132+
public static T Get<T>(EnvironmentalHazard environmentalHazard)
133+
where T : Hazard => Get(environmentalHazard) as T;
134134

135135
/// <summary>
136136
/// Gets the hazard by the room where it's located.

EXILED/Exiled.API/Features/Lift.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ internal Lift(ElevatorChamber elevator)
7676
/// <summary>
7777
/// Gets a value of the internal doors list.
7878
/// </summary>
79-
public IReadOnlyCollection<Doors.ElevatorDoor> Doors => internalDoorsList.Select(x => Door.Get(x).As<Doors.ElevatorDoor>()).ToList();
79+
public IReadOnlyCollection<Doors.ElevatorDoor> Doors => internalDoorsList.Select(x => Door.Get<Doors.ElevatorDoor>(x)).ToList();
8080

8181
/// <summary>
8282
/// Gets a <see cref="IEnumerable{T}"/> of <see cref="Player"/> in the <see cref="Room"/>.
@@ -201,7 +201,7 @@ public float AnimationTime
201201
/// <summary>
202202
/// Gets the <see cref="CurrentDestination"/>.
203203
/// </summary>
204-
public Doors.ElevatorDoor CurrentDestination => Door.Get(Base.CurrentDestination).As<Doors.ElevatorDoor>();
204+
public Doors.ElevatorDoor CurrentDestination => Door.Get<Doors.ElevatorDoor>(Base.CurrentDestination);
205205

206206
/// <summary>
207207
/// Gets a <see cref="IEnumerable{T}"/> of <see cref="Lift"/> which contains all the <see cref="Lift"/> instances from the specified <see cref="Status"/>.

EXILED/Exiled.API/Features/Pickups/Pickup.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,11 @@ public static Pickup Get(ItemPickupBase pickupBase)
341341
/// <summary>
342342
/// Gets an existing <see cref="Pickup"/> or creates a new instance of one.
343343
/// </summary>
344-
/// <param name="itemBase">The <see cref="ItemPickupBase"/> to convert into an pickup.</param>
344+
/// <param name="pickupBase">The <see cref="ItemPickupBase"/> to convert into an pickup.</param>
345345
/// <typeparam name="T">The specified <see cref="Pickup"/> type.</typeparam>
346346
/// <returns>The pickup wrapper for the given <see cref="ItemPickupBase"/>.</returns>
347-
public static T Get<T>(ItemPickupBase itemBase)
348-
where T : Pickup => Get(itemBase) as T;
347+
public static T Get<T>(ItemPickupBase pickupBase)
348+
where T : Pickup => Get(pickupBase) as T;
349349

350350
/// <summary>
351351
/// Gets the <see cref="Pickup"/> given a <see cref="Serial"/>.

EXILED/Exiled.Events/EventArgs/Scp096/StartPryingGateEventArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public StartPryingGateEventArgs(Player player, PryableDoor gate, bool isAllowed
3636
{
3737
Player = player;
3838
Scp096 = player.Role.As<Scp096Role>();
39-
Gate = Door.Get(gate).As<Gate>();
39+
Gate = Door.Get<Gate>(gate);
4040
IsAllowed = isAllowed;
4141
}
4242

EXILED/Exiled.Events/Patches/Generic/DoorList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private static void Postfix(DoorVariant __instance)
5050
foreach (DoorVariant subDoor in checkpoint.Base.SubDoors)
5151
{
5252
subDoor.RegisterRooms();
53-
BreakableDoor targetDoor = Door.Get(subDoor).Cast<BreakableDoor>();
53+
BreakableDoor targetDoor = Door.Get<BreakableDoor>(subDoor);
5454

5555
targetDoor.ParentCheckpointDoor = checkpoint;
5656
checkpoint.SubDoorsValue.Add(targetDoor);

0 commit comments

Comments
 (0)