From 488c9892a031c9904a03b1d076d38767a4e86b70 Mon Sep 17 00:00:00 2001 From: Lumi Date: Sat, 2 May 2026 19:50:52 +0100 Subject: [PATCH 1/6] feat: admin toy extensions --- .../Extensions/AdminToyExtensions.LightToy.cs | 66 ++++++ SecretAPI/Extensions/AdminToyExtensions.cs | 200 ++++++++++++++++++ 2 files changed, 266 insertions(+) create mode 100644 SecretAPI/Extensions/AdminToyExtensions.LightToy.cs create mode 100644 SecretAPI/Extensions/AdminToyExtensions.cs diff --git a/SecretAPI/Extensions/AdminToyExtensions.LightToy.cs b/SecretAPI/Extensions/AdminToyExtensions.LightToy.cs new file mode 100644 index 0000000..3999b61 --- /dev/null +++ b/SecretAPI/Extensions/AdminToyExtensions.LightToy.cs @@ -0,0 +1,66 @@ +namespace SecretAPI.Extensions; + +using LabApi.Features.Wrappers; +using UnityEngine; + +public static partial class AdminToyExtensions +{ + extension(LightSourceToy toy) + { + public LightSourceToy WithIntensity(float intensity) + { + toy.Intensity = intensity; + return toy; + } + + public LightSourceToy WithRange(float range) + { + toy.Range = range; + return toy; + } + + public LightSourceToy WithColor(Color color) + { + toy.Color = color; + return toy; + } + + public LightSourceToy WithShadowType(LightShadows type) + { + toy.ShadowType = type; + return toy; + } + + public LightSourceToy WithShadowStrength(float strength) + { + toy.ShadowStrength = strength; + return toy; + } + + public LightSourceToy WithType(LightType lightType) + { + toy.Type = lightType; + return toy; + } + +#pragma warning disable CS0618 // Type or member is obsolete + public LightSourceToy WithShape(LightShape shape) +#pragma warning restore CS0618 // Type or member is obsolete + { + toy.Shape = shape; + return toy; + } + + public LightSourceToy WithSpotAngle(float angle) + { + toy.SpotAngle = angle; + return toy; + } + + public LightSourceToy WithInnerSpotAngle(float angle) + { + toy.InnerSpotAngle = angle; + return toy; + } + } +} \ No newline at end of file diff --git a/SecretAPI/Extensions/AdminToyExtensions.cs b/SecretAPI/Extensions/AdminToyExtensions.cs new file mode 100644 index 0000000..623bed8 --- /dev/null +++ b/SecretAPI/Extensions/AdminToyExtensions.cs @@ -0,0 +1,200 @@ +namespace SecretAPI.Extensions; + +using System; +using AdminToys; +using LabApi.Features.Wrappers; +using UnityEngine; +using CapybaraToy = LabApi.Features.Wrappers.CapybaraToy; +using PrimitiveObjectToy = LabApi.Features.Wrappers.PrimitiveObjectToy; +using TextToy = LabApi.Features.Wrappers.TextToy; +using WaypointToy = LabApi.Features.Wrappers.WaypointToy; + +public static partial class AdminToyExtensions +{ + extension(T toy) + where T : AdminToy + { + public T WithPosition(Vector3 pos) + { + toy.Position = pos; + return toy; + } + + public T WithRotation(Quaternion rot) + { + toy.Rotation = rot; + return toy; + } + + public T WithScale(Vector3 scale) + { + toy.Scale = scale; + return toy; + } + } + + extension(CameraToy toy) + { + public CameraToy WithLabel(string label) + { + toy.Label = label; + return toy; + } + + public CameraToy WithRoom(Room room) + { + toy.Room = room; + return toy; + } + + public CameraToy WithVerticalConstraints(Vector2 constraint) + { + toy.VerticalConstraints = constraint; + return toy; + } + + public CameraToy WithHorizontalConstraints(Vector2 constraint) + { + toy.HorizontalConstraint = constraint; + return toy; + } + + public CameraToy WithZoomConstraints(Vector2 constraint) + { + toy.ZoomConstraints = constraint; + return toy; + } + } + + public static CapybaraToy WithCollidersEnabled(this CapybaraToy toy, bool enabled) + { + toy.CollidersEnabled = enabled; + return toy; + } + + extension(InteractableToy toy) + { + public InteractableToy WhenInteracted(Action action) + { + toy.OnInteracted += action; + return toy; + } + + public InteractableToy WhenSearching(Action action) + { + toy.OnSearching += action; + return toy; + } + + public InteractableToy WhenSearched(Action action) + { + toy.OnSearched += action; + return toy; + } + + public InteractableToy WhenSearchAborted(Action action) + { + toy.OnSearchAborted += action; + return toy; + } + + public InteractableToy WithShape(InvisibleInteractableToy.ColliderShape shape) + { + toy.Shape = shape; + return toy; + } + + public InteractableToy WithInteractionDuration(float duration) + { + toy.InteractionDuration = duration; + return toy; + } + + public InteractableToy IsLocked(bool locked) + { + toy.IsLocked = locked; + return toy; + } + } + + extension(PrimitiveObjectToy toy) + { + public bool Collidable + { + get => (toy.Flags & PrimitiveFlags.Collidable) == PrimitiveFlags.Collidable; + set => toy.Flags = value ? toy.Flags | PrimitiveFlags.Collidable : toy.Flags & ~PrimitiveFlags.Collidable; + } + + public bool Visible + { + get => (toy.Flags & PrimitiveFlags.Visible) == PrimitiveFlags.Visible; + set => toy.Flags = value ? toy.Flags | PrimitiveFlags.Visible : toy.Flags & ~PrimitiveFlags.Visible; + } + + public PrimitiveObjectToy WithCollidable(bool collidable) + { + toy.Collidable = collidable; + return toy; + } + + public PrimitiveObjectToy WithVisible(bool visible) + { + toy.Visible = visible; + return toy; + } + + public PrimitiveObjectToy WithType(PrimitiveType type) + { + toy.Type = type; + return toy; + } + + public PrimitiveObjectToy WithColor(Color color) + { + toy.Color = color; + return toy; + } + + public PrimitiveObjectToy WithFlags(PrimitiveFlags flags) + { + toy.Flags = flags; + return toy; + } + } + + extension(TextToy toy) + { + public TextToy WithText(string text) + { + toy.TextFormat = text; + return toy; + } + + public TextToy WithSize(Vector2 size) + { + toy.DisplaySize = size; + return toy; + } + } + + extension(WaypointToy toy) + { + public WaypointToy WithBoundsSize(Vector3 size) + { + toy.BoundsSize = size; + return toy; + } + + public WaypointToy WithVisualiseBounds(bool visible) + { + toy.VisualizeBounds = visible; + return toy; + } + + public WaypointToy WithPriorityBias(float bias) + { + toy.PriorityBias = bias; + return toy; + } + } +} \ No newline at end of file From e43343bfb344eef561691098b5aa1a474bfa68bc Mon Sep 17 00:00:00 2001 From: Lumi Date: Sat, 2 May 2026 20:33:48 +0100 Subject: [PATCH 2/6] feat: reorganisation --- .../Extensions/AdminToyExtensions.LightToy.cs | 66 ------ SecretAPI/Extensions/AdminToyExtensions.cs | 200 ------------------ .../AdminToys/AdminToyExtensions.Camera.cs | 68 ++++++ .../AdminToyExtensions.Interactable.cs | 91 ++++++++ .../AdminToys/AdminToyExtensions.Light.cs | 114 ++++++++++ .../AdminToys/AdminToyExtensions.Primitive.cs | 87 ++++++++ .../AdminToys/AdminToyExtensions.Text.cs | 35 +++ .../AdminToys/AdminToyExtensions.Waypoint.cs | 46 ++++ .../AdminToys/AdminToyExtensions.cs | 60 ++++++ 9 files changed, 501 insertions(+), 266 deletions(-) delete mode 100644 SecretAPI/Extensions/AdminToyExtensions.LightToy.cs delete mode 100644 SecretAPI/Extensions/AdminToyExtensions.cs create mode 100644 SecretAPI/Extensions/AdminToys/AdminToyExtensions.Camera.cs create mode 100644 SecretAPI/Extensions/AdminToys/AdminToyExtensions.Interactable.cs create mode 100644 SecretAPI/Extensions/AdminToys/AdminToyExtensions.Light.cs create mode 100644 SecretAPI/Extensions/AdminToys/AdminToyExtensions.Primitive.cs create mode 100644 SecretAPI/Extensions/AdminToys/AdminToyExtensions.Text.cs create mode 100644 SecretAPI/Extensions/AdminToys/AdminToyExtensions.Waypoint.cs create mode 100644 SecretAPI/Extensions/AdminToys/AdminToyExtensions.cs diff --git a/SecretAPI/Extensions/AdminToyExtensions.LightToy.cs b/SecretAPI/Extensions/AdminToyExtensions.LightToy.cs deleted file mode 100644 index 3999b61..0000000 --- a/SecretAPI/Extensions/AdminToyExtensions.LightToy.cs +++ /dev/null @@ -1,66 +0,0 @@ -namespace SecretAPI.Extensions; - -using LabApi.Features.Wrappers; -using UnityEngine; - -public static partial class AdminToyExtensions -{ - extension(LightSourceToy toy) - { - public LightSourceToy WithIntensity(float intensity) - { - toy.Intensity = intensity; - return toy; - } - - public LightSourceToy WithRange(float range) - { - toy.Range = range; - return toy; - } - - public LightSourceToy WithColor(Color color) - { - toy.Color = color; - return toy; - } - - public LightSourceToy WithShadowType(LightShadows type) - { - toy.ShadowType = type; - return toy; - } - - public LightSourceToy WithShadowStrength(float strength) - { - toy.ShadowStrength = strength; - return toy; - } - - public LightSourceToy WithType(LightType lightType) - { - toy.Type = lightType; - return toy; - } - -#pragma warning disable CS0618 // Type or member is obsolete - public LightSourceToy WithShape(LightShape shape) -#pragma warning restore CS0618 // Type or member is obsolete - { - toy.Shape = shape; - return toy; - } - - public LightSourceToy WithSpotAngle(float angle) - { - toy.SpotAngle = angle; - return toy; - } - - public LightSourceToy WithInnerSpotAngle(float angle) - { - toy.InnerSpotAngle = angle; - return toy; - } - } -} \ No newline at end of file diff --git a/SecretAPI/Extensions/AdminToyExtensions.cs b/SecretAPI/Extensions/AdminToyExtensions.cs deleted file mode 100644 index 623bed8..0000000 --- a/SecretAPI/Extensions/AdminToyExtensions.cs +++ /dev/null @@ -1,200 +0,0 @@ -namespace SecretAPI.Extensions; - -using System; -using AdminToys; -using LabApi.Features.Wrappers; -using UnityEngine; -using CapybaraToy = LabApi.Features.Wrappers.CapybaraToy; -using PrimitiveObjectToy = LabApi.Features.Wrappers.PrimitiveObjectToy; -using TextToy = LabApi.Features.Wrappers.TextToy; -using WaypointToy = LabApi.Features.Wrappers.WaypointToy; - -public static partial class AdminToyExtensions -{ - extension(T toy) - where T : AdminToy - { - public T WithPosition(Vector3 pos) - { - toy.Position = pos; - return toy; - } - - public T WithRotation(Quaternion rot) - { - toy.Rotation = rot; - return toy; - } - - public T WithScale(Vector3 scale) - { - toy.Scale = scale; - return toy; - } - } - - extension(CameraToy toy) - { - public CameraToy WithLabel(string label) - { - toy.Label = label; - return toy; - } - - public CameraToy WithRoom(Room room) - { - toy.Room = room; - return toy; - } - - public CameraToy WithVerticalConstraints(Vector2 constraint) - { - toy.VerticalConstraints = constraint; - return toy; - } - - public CameraToy WithHorizontalConstraints(Vector2 constraint) - { - toy.HorizontalConstraint = constraint; - return toy; - } - - public CameraToy WithZoomConstraints(Vector2 constraint) - { - toy.ZoomConstraints = constraint; - return toy; - } - } - - public static CapybaraToy WithCollidersEnabled(this CapybaraToy toy, bool enabled) - { - toy.CollidersEnabled = enabled; - return toy; - } - - extension(InteractableToy toy) - { - public InteractableToy WhenInteracted(Action action) - { - toy.OnInteracted += action; - return toy; - } - - public InteractableToy WhenSearching(Action action) - { - toy.OnSearching += action; - return toy; - } - - public InteractableToy WhenSearched(Action action) - { - toy.OnSearched += action; - return toy; - } - - public InteractableToy WhenSearchAborted(Action action) - { - toy.OnSearchAborted += action; - return toy; - } - - public InteractableToy WithShape(InvisibleInteractableToy.ColliderShape shape) - { - toy.Shape = shape; - return toy; - } - - public InteractableToy WithInteractionDuration(float duration) - { - toy.InteractionDuration = duration; - return toy; - } - - public InteractableToy IsLocked(bool locked) - { - toy.IsLocked = locked; - return toy; - } - } - - extension(PrimitiveObjectToy toy) - { - public bool Collidable - { - get => (toy.Flags & PrimitiveFlags.Collidable) == PrimitiveFlags.Collidable; - set => toy.Flags = value ? toy.Flags | PrimitiveFlags.Collidable : toy.Flags & ~PrimitiveFlags.Collidable; - } - - public bool Visible - { - get => (toy.Flags & PrimitiveFlags.Visible) == PrimitiveFlags.Visible; - set => toy.Flags = value ? toy.Flags | PrimitiveFlags.Visible : toy.Flags & ~PrimitiveFlags.Visible; - } - - public PrimitiveObjectToy WithCollidable(bool collidable) - { - toy.Collidable = collidable; - return toy; - } - - public PrimitiveObjectToy WithVisible(bool visible) - { - toy.Visible = visible; - return toy; - } - - public PrimitiveObjectToy WithType(PrimitiveType type) - { - toy.Type = type; - return toy; - } - - public PrimitiveObjectToy WithColor(Color color) - { - toy.Color = color; - return toy; - } - - public PrimitiveObjectToy WithFlags(PrimitiveFlags flags) - { - toy.Flags = flags; - return toy; - } - } - - extension(TextToy toy) - { - public TextToy WithText(string text) - { - toy.TextFormat = text; - return toy; - } - - public TextToy WithSize(Vector2 size) - { - toy.DisplaySize = size; - return toy; - } - } - - extension(WaypointToy toy) - { - public WaypointToy WithBoundsSize(Vector3 size) - { - toy.BoundsSize = size; - return toy; - } - - public WaypointToy WithVisualiseBounds(bool visible) - { - toy.VisualizeBounds = visible; - return toy; - } - - public WaypointToy WithPriorityBias(float bias) - { - toy.PriorityBias = bias; - return toy; - } - } -} \ No newline at end of file diff --git a/SecretAPI/Extensions/AdminToys/AdminToyExtensions.Camera.cs b/SecretAPI/Extensions/AdminToys/AdminToyExtensions.Camera.cs new file mode 100644 index 0000000..dbb5996 --- /dev/null +++ b/SecretAPI/Extensions/AdminToys/AdminToyExtensions.Camera.cs @@ -0,0 +1,68 @@ +namespace SecretAPI.Extensions.AdminToys; + +using LabApi.Features.Wrappers; +using UnityEngine; + +/// +/// Extensions for camera toys. +/// +public static partial class AdminToyExtensions +{ + extension(CameraToy toy) + { + /// + /// Modify the label of this . + /// + /// The label. + /// The modified . + public CameraToy WithLabel(string label) + { + toy.Label = label; + return toy; + } + + /// + /// Modify the room of this . + /// + /// The room. + /// The modified . + public CameraToy WithRoom(Room room) + { + toy.Room = room; + return toy; + } + + /// + /// Modify the vertical constrains of this . + /// + /// The constraints. + /// The modified . + public CameraToy WithVerticalConstraints(Vector2 constraint) + { + toy.VerticalConstraints = constraint; + return toy; + } + + /// + /// Modify the horizontal constrains of this . + /// + /// The constraints. + /// The modified . + public CameraToy WithHorizontalConstraints(Vector2 constraint) + { + toy.HorizontalConstraint = constraint; + return toy; + } + + /// + /// Modify the zoom constrains of this . + /// + /// The constraints. + /// The modified . + public CameraToy WithZoomConstraints(Vector2 constraint) + { + toy.ZoomConstraints = constraint; + return toy; + } + } +} \ No newline at end of file diff --git a/SecretAPI/Extensions/AdminToys/AdminToyExtensions.Interactable.cs b/SecretAPI/Extensions/AdminToys/AdminToyExtensions.Interactable.cs new file mode 100644 index 0000000..e5394fe --- /dev/null +++ b/SecretAPI/Extensions/AdminToys/AdminToyExtensions.Interactable.cs @@ -0,0 +1,91 @@ +namespace SecretAPI.Extensions.AdminToys; + +using System; +using global::AdminToys; +using LabApi.Features.Wrappers; + +/// +/// Extensions for interactable toys. +/// +public static partial class AdminToyExtensions +{ + extension(InteractableToy toy) + { + /// + /// Call an when this is interacted with. + /// + /// The to run. + /// The modified . + public InteractableToy WhenInteracted(Action action) + { + toy.OnInteracted += action; + return toy; + } + + /// + /// Call an when this is being searched. + /// + /// The to run. + /// The modified . + public InteractableToy WhenSearching(Action action) + { + toy.OnSearching += action; + return toy; + } + + /// + /// Call an when this has been searched. + /// + /// The to run. + /// The modified . + public InteractableToy WhenSearched(Action action) + { + toy.OnSearched += action; + return toy; + } + + /// + /// Call an when this has had an aborted search. + /// + /// The to run. + /// The modified . + public InteractableToy WhenSearchAborted(Action action) + { + toy.OnSearchAborted += action; + return toy; + } + + /// + /// Modify the shape of this . + /// + /// The shape. + /// The modified . + public InteractableToy WithShape(InvisibleInteractableToy.ColliderShape shape) + { + toy.Shape = shape; + return toy; + } + + /// + /// Modify how long a user should interact with before triggering the event. + /// + /// The duration. + /// The modified . + public InteractableToy WithInteractionDuration(float duration) + { + toy.InteractionDuration = duration; + return toy; + } + + /// + /// Modify whether this can be interacted with. + /// + /// The lock state. + /// The modified . + public InteractableToy IsLocked(bool locked) + { + toy.IsLocked = locked; + return toy; + } + } +} \ No newline at end of file diff --git a/SecretAPI/Extensions/AdminToys/AdminToyExtensions.Light.cs b/SecretAPI/Extensions/AdminToys/AdminToyExtensions.Light.cs new file mode 100644 index 0000000..fd4ff69 --- /dev/null +++ b/SecretAPI/Extensions/AdminToys/AdminToyExtensions.Light.cs @@ -0,0 +1,114 @@ +namespace SecretAPI.Extensions.AdminToys; + +using LabApi.Features.Wrappers; +using UnityEngine; + +/// +/// Extensions for Light Source Toys. +/// +public static partial class AdminToyExtensions +{ + extension(LightSourceToy toy) + { + /// + /// Modify the intensity of this . + /// + /// The intensity. + /// The modified . + public LightSourceToy WithIntensity(float intensity) + { + toy.Intensity = intensity; + return toy; + } + + /// + /// Modify the range of this . + /// + /// The range. + /// The modified . + public LightSourceToy WithRange(float range) + { + toy.Range = range; + return toy; + } + + /// + /// Modify the color of this . + /// + /// The color. + /// The modified . + public LightSourceToy WithColor(Color color) + { + toy.Color = color; + return toy; + } + + /// + /// Modify the shadow type of this . + /// + /// The shadow type. + /// The modified . + public LightSourceToy WithShadowType(LightShadows type) + { + toy.ShadowType = type; + return toy; + } + + /// + /// Modify the shadow strength of this . + /// + /// The strength. + /// The modified . + public LightSourceToy WithShadowStrength(float strength) + { + toy.ShadowStrength = strength; + return toy; + } + + /// + /// Modify the type of this . + /// + /// The type. + /// The modified . + public LightSourceToy WithType(LightType lightType) + { + toy.Type = lightType; + return toy; + } + + /// + /// Modify the shape of this . + /// + /// The shape. + /// The modified . +#pragma warning disable CS0618 // Type or member is obsolete + public LightSourceToy WithShape(LightShape shape) +#pragma warning restore CS0618 // Type or member is obsolete + { + toy.Shape = shape; + return toy; + } + + /// + /// Modify the spot angle of this . + /// + /// The angle. + /// The modified . + public LightSourceToy WithSpotAngle(float angle) + { + toy.SpotAngle = angle; + return toy; + } + + /// + /// Modify the inner spot angle of this . + /// + /// The angle. + /// The modified . + public LightSourceToy WithInnerSpotAngle(float angle) + { + toy.InnerSpotAngle = angle; + return toy; + } + } +} \ No newline at end of file diff --git a/SecretAPI/Extensions/AdminToys/AdminToyExtensions.Primitive.cs b/SecretAPI/Extensions/AdminToys/AdminToyExtensions.Primitive.cs new file mode 100644 index 0000000..f7ff3c5 --- /dev/null +++ b/SecretAPI/Extensions/AdminToys/AdminToyExtensions.Primitive.cs @@ -0,0 +1,87 @@ +namespace SecretAPI.Extensions.AdminToys; + +using global::AdminToys; +using UnityEngine; +using PrimitiveObjectToy = LabApi.Features.Wrappers.PrimitiveObjectToy; + +/// +/// Extensions for primitive object toys. +/// +public static partial class AdminToyExtensions +{ + extension(PrimitiveObjectToy toy) + { + /// + /// Gets or sets a value indicating whether this is collidable. + /// + public bool Collidable + { + get => (toy.Flags & PrimitiveFlags.Collidable) == PrimitiveFlags.Collidable; + set => toy.Flags = value ? toy.Flags | PrimitiveFlags.Collidable : toy.Flags & ~PrimitiveFlags.Collidable; + } + + /// + /// Gets or sets a value indicating whether this is visible. + /// + public bool Visible + { + get => (toy.Flags & PrimitiveFlags.Visible) == PrimitiveFlags.Visible; + set => toy.Flags = value ? toy.Flags | PrimitiveFlags.Visible : toy.Flags & ~PrimitiveFlags.Visible; + } + + /// + /// Modify whether this is collidable. + /// + /// The collidable state. + /// The modified . + public PrimitiveObjectToy WithCollidable(bool collidable) + { + toy.Collidable = collidable; + return toy; + } + + /// + /// Modify whether this is visible. + /// + /// The visibility state. + /// The modified . + public PrimitiveObjectToy WithVisible(bool visible) + { + toy.Visible = visible; + return toy; + } + + /// + /// Modify the type of this . + /// + /// The type. + /// The modified . + public PrimitiveObjectToy WithType(PrimitiveType type) + { + toy.Type = type; + return toy; + } + + /// + /// Modify the color of this . + /// + /// The color. + /// The modified . + public PrimitiveObjectToy WithColor(Color color) + { + toy.Color = color; + return toy; + } + + /// + /// Modify the flags of this . + /// + /// The flags. + /// The modified . + public PrimitiveObjectToy WithFlags(PrimitiveFlags flags) + { + toy.Flags = flags; + return toy; + } + } +} \ No newline at end of file diff --git a/SecretAPI/Extensions/AdminToys/AdminToyExtensions.Text.cs b/SecretAPI/Extensions/AdminToys/AdminToyExtensions.Text.cs new file mode 100644 index 0000000..0a3a743 --- /dev/null +++ b/SecretAPI/Extensions/AdminToys/AdminToyExtensions.Text.cs @@ -0,0 +1,35 @@ +namespace SecretAPI.Extensions.AdminToys; + +using LabApi.Features.Wrappers; +using UnityEngine; + +/// +/// Extension methods for text toys. +/// +public static partial class AdminToyExtensions +{ + extension(TextToy toy) + { + /// + /// Modify the text of this . + /// + /// The text. + /// The modified . + public TextToy WithText(string text) + { + toy.TextFormat = text; + return toy; + } + + /// + /// Modify the size of this . + /// + /// The size. + /// The modified . + public TextToy WithSize(Vector2 size) + { + toy.DisplaySize = size; + return toy; + } + } +} \ No newline at end of file diff --git a/SecretAPI/Extensions/AdminToys/AdminToyExtensions.Waypoint.cs b/SecretAPI/Extensions/AdminToys/AdminToyExtensions.Waypoint.cs new file mode 100644 index 0000000..0e4e906 --- /dev/null +++ b/SecretAPI/Extensions/AdminToys/AdminToyExtensions.Waypoint.cs @@ -0,0 +1,46 @@ +namespace SecretAPI.Extensions.AdminToys; + +using LabApi.Features.Wrappers; +using UnityEngine; + +/// +/// Extension methods for waypoint toys. +/// +public static partial class AdminToyExtensions +{ + extension(WaypointToy toy) + { + /// + /// Modify the bounds size of this . + /// + /// The size. + /// The modified . + public WaypointToy WithBoundsSize(Vector3 size) + { + toy.BoundsSize = size; + return toy; + } + + /// + /// Modify whether this has visible bounds. + /// + /// The visibility state. + /// The modified . + public WaypointToy WithVisualiseBounds(bool visible) + { + toy.VisualizeBounds = visible; + return toy; + } + + /// + /// Modify the priority bias of this . + /// + /// The bias. + /// The modified . + public WaypointToy WithPriorityBias(float bias) + { + toy.PriorityBias = bias; + return toy; + } + } +} \ No newline at end of file diff --git a/SecretAPI/Extensions/AdminToys/AdminToyExtensions.cs b/SecretAPI/Extensions/AdminToys/AdminToyExtensions.cs new file mode 100644 index 0000000..dd65e2f --- /dev/null +++ b/SecretAPI/Extensions/AdminToys/AdminToyExtensions.cs @@ -0,0 +1,60 @@ +namespace SecretAPI.Extensions.AdminToys; + +using LabApi.Features.Wrappers; +using UnityEngine; +using CapybaraToy = LabApi.Features.Wrappers.CapybaraToy; + +/// +/// Extensions for admin toys. +/// +public static partial class AdminToyExtensions +{ + extension(T toy) + where T : AdminToy + { + /// + /// Modify the position of the . + /// + /// The position to change to. + /// The modified . + public T WithPosition(Vector3 pos) + { + toy.Position = pos; + return toy; + } + + /// + /// Modify the rotation of the . + /// + /// The rotation to change to. + /// The modified . + public T WithRotation(Quaternion rot) + { + toy.Rotation = rot; + return toy; + } + + /// + /// Modify the scale of the . + /// + /// The scale to change to. + /// The modified . + public T WithScale(Vector3 scale) + { + toy.Scale = scale; + return toy; + } + } + + /// + /// Updates whether the capybara has enabled colliders. + /// + /// The . + /// Whether the colliders are enabled. + /// The modified . + public static CapybaraToy WithCollidersEnabled(this CapybaraToy toy, bool enabled) + { + toy.CollidersEnabled = enabled; + return toy; + } +} \ No newline at end of file From 38661927c6434f2e23ea3b1dd5f440686d6bd2e4 Mon Sep 17 00:00:00 2001 From: Lumi Date: Sat, 2 May 2026 20:36:16 +0100 Subject: [PATCH 3/6] docs: fix T cref error --- SecretAPI/Extensions/AdminToys/AdminToyExtensions.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/SecretAPI/Extensions/AdminToys/AdminToyExtensions.cs b/SecretAPI/Extensions/AdminToys/AdminToyExtensions.cs index dd65e2f..68e3a73 100644 --- a/SecretAPI/Extensions/AdminToys/AdminToyExtensions.cs +++ b/SecretAPI/Extensions/AdminToys/AdminToyExtensions.cs @@ -13,10 +13,10 @@ public static partial class AdminToyExtensions where T : AdminToy { /// - /// Modify the position of the . + /// Modify the position of this . /// /// The position to change to. - /// The modified . + /// The modified . public T WithPosition(Vector3 pos) { toy.Position = pos; @@ -24,10 +24,10 @@ public T WithPosition(Vector3 pos) } /// - /// Modify the rotation of the . + /// Modify the rotation of this . /// /// The rotation to change to. - /// The modified . + /// The modified . public T WithRotation(Quaternion rot) { toy.Rotation = rot; @@ -35,10 +35,10 @@ public T WithRotation(Quaternion rot) } /// - /// Modify the scale of the . + /// Modify the scale of this . /// /// The scale to change to. - /// The modified . + /// The modified . public T WithScale(Vector3 scale) { toy.Scale = scale; From 1173fb00094d44d6423684f83bbc3a9c9e66d006 Mon Sep 17 00:00:00 2001 From: Lumi Date: Mon, 4 May 2026 11:06:09 +0100 Subject: [PATCH 4/6] feat: item extensions --- .../Items/ItemExtensions.Firearms.cs | 57 ++++++++++++++++ .../Items/ItemExtensions.MicroHID.cs | 57 ++++++++++++++++ .../Extensions/Items/ItemExtensions.Scp127.cs | 35 ++++++++++ .../Items/ItemExtensions.Scp1509.cs | 67 +++++++++++++++++++ SecretAPI/Extensions/Items/ItemExtensions.cs | 35 ++++++++++ 5 files changed, 251 insertions(+) create mode 100644 SecretAPI/Extensions/Items/ItemExtensions.Firearms.cs create mode 100644 SecretAPI/Extensions/Items/ItemExtensions.MicroHID.cs create mode 100644 SecretAPI/Extensions/Items/ItemExtensions.Scp127.cs create mode 100644 SecretAPI/Extensions/Items/ItemExtensions.Scp1509.cs create mode 100644 SecretAPI/Extensions/Items/ItemExtensions.cs diff --git a/SecretAPI/Extensions/Items/ItemExtensions.Firearms.cs b/SecretAPI/Extensions/Items/ItemExtensions.Firearms.cs new file mode 100644 index 0000000..fbe50e6 --- /dev/null +++ b/SecretAPI/Extensions/Items/ItemExtensions.Firearms.cs @@ -0,0 +1,57 @@ +namespace SecretAPI.Extensions.Items; + +using LabApi.Features.Wrappers; + +/// +/// Extensions for firearms. +/// +public static partial class ItemExtensions +{ + extension(T item) + where T : FirearmItem + { + /// + /// Modifies the stored ammo in this . + /// + /// The ammo. + /// The modified . + public T WithStoredAmmo(int ammo) + { + item.StoredAmmo = ammo; + return item; + } + + /// + /// Modifies whether the magazine is inserted in this . + /// + /// Whether the magazine is inserted. + /// The modified . + public T WithMagazineInserted(bool magazineInserted) + { + item.MagazineInserted = magazineInserted; + return item; + } + + /// + /// Modifies whether the firearm is cocked in this . + /// + /// Whether the firearm is cocked. + /// The modified . + public T WithCocked(bool cocked) + { + item.Cocked = cocked; + return item; + } + + /// + /// Modifies the chambered ammo in this . + /// + /// The ammo. + /// The modified . + public T WithChamberedAmmo(int ammo) + { + item.ChamberedAmmo = ammo; + return item; + } + } +} \ No newline at end of file diff --git a/SecretAPI/Extensions/Items/ItemExtensions.MicroHID.cs b/SecretAPI/Extensions/Items/ItemExtensions.MicroHID.cs new file mode 100644 index 0000000..c2977a6 --- /dev/null +++ b/SecretAPI/Extensions/Items/ItemExtensions.MicroHID.cs @@ -0,0 +1,57 @@ +namespace SecretAPI.Extensions.Items; + +using InventorySystem.Items.MicroHID.Modules; +using LabApi.Features.Wrappers; + +/// +/// Extensions for Micro H.I.D. +/// +public static partial class ItemExtensions +{ + extension(MicroHIDItem item) + { + /// + /// Modify the energy of this . + /// + /// The energy. + /// The modified . + public MicroHIDItem WithEnergy(float energy) + { + item.Energy = energy; + return item; + } + + /// + /// Modify the broken state of this . + /// + /// Whether the item is broken or not. + /// The modified . + public MicroHIDItem WithBrokenState(bool brokenState) + { + item.IsBroken = brokenState; + return item; + } + + /// + /// Modify the phase of this . + /// + /// The phase. + /// The modified . + public MicroHIDItem WithPhase(MicroHidPhase phase) + { + item.Phase = phase; + return item; + } + + /// + /// Modify the firing mode of this . + /// + /// The firing mode. + /// The modified . + public MicroHIDItem WithFiringMode(MicroHidFiringMode mode) + { + item.FiringMode = mode; + return item; + } + } +} \ No newline at end of file diff --git a/SecretAPI/Extensions/Items/ItemExtensions.Scp127.cs b/SecretAPI/Extensions/Items/ItemExtensions.Scp127.cs new file mode 100644 index 0000000..1f1ba8c --- /dev/null +++ b/SecretAPI/Extensions/Items/ItemExtensions.Scp127.cs @@ -0,0 +1,35 @@ +namespace SecretAPI.Extensions.Items; + +using InventorySystem.Items.Firearms.Modules.Scp127; +using LabApi.Features.Wrappers; + +/// +/// Extensions for SCP-127. +/// +public static partial class ItemExtensions +{ + extension(Scp127Firearm item) + { + /// + /// Modifies the tier of this . + /// + /// The tier. + /// The modified . + public Scp127Firearm WithTier(Scp127Tier tier) + { + item.Tier = tier; + return item; + } + + /// + /// Modifies the experience of this . + /// + /// The experience. + /// The modified . + public Scp127Firearm WithExperience(float experience) + { + item.Experience = experience; + return item; + } + } +} \ No newline at end of file diff --git a/SecretAPI/Extensions/Items/ItemExtensions.Scp1509.cs b/SecretAPI/Extensions/Items/ItemExtensions.Scp1509.cs new file mode 100644 index 0000000..d78780a --- /dev/null +++ b/SecretAPI/Extensions/Items/ItemExtensions.Scp1509.cs @@ -0,0 +1,67 @@ +namespace SecretAPI.Extensions.Items; + +using LabApi.Features.Wrappers; + +/// +/// Extensions for SCP-1509. +/// +public static partial class ItemExtensions +{ + extension(Scp1509Item item) + { + /// + /// Modifies the shield regen rate of this . + /// + /// The rate. + /// The modified . + public Scp1509Item WithShieldRegenRate(float rate) + { + item.ShieldRegenRate = rate; + return item; + } + + /// + /// Modifies the shield decay rate of this . + /// + /// The rate. + /// The modified . + public Scp1509Item WithShieldDecayRate(float rate) + { + item.ShieldDecayRate = rate; + return item; + } + + /// + /// Modifies the unequip decay delay of this . + /// + /// The time to start decaying. + /// The modified . + public Scp1509Item WithUnequipDecayDelay(float time) + { + item.UnequipDecayDelay = time; + return item; + } + + /// + /// Modifies the revive cooldown of this . + /// + /// The cooldown. + /// The modified . + public Scp1509Item WithReviveCooldown(double cooldown) + { + item.ReviveCooldown = cooldown; + return item; + } + + /// + /// Modifies the equipped HS of this . + /// + /// The hume shield. + /// The modified . + public Scp1509Item WithEquippedHumeShield(float hs) + { + item.EquippedHS = hs; + return item; + } + } +} \ No newline at end of file diff --git a/SecretAPI/Extensions/Items/ItemExtensions.cs b/SecretAPI/Extensions/Items/ItemExtensions.cs new file mode 100644 index 0000000..296443c --- /dev/null +++ b/SecretAPI/Extensions/Items/ItemExtensions.cs @@ -0,0 +1,35 @@ +namespace SecretAPI.Extensions.Items; + +using LabApi.Features.Wrappers; + +/// +/// Extensions for items. +/// +public static partial class ItemExtensions +{ + extension(Item item) + { + /// + /// Change this into a different item type, useful for the other extension methods that can be used. + /// + /// The item type you want to change type to. + /// The changed item type. + public T As() + where T : Item + { + return (T)item; + } + } + + /// + /// Modifies the battery percentage of this . + /// + /// The . + /// The percentage. + /// The modified . + public static RadioItem WithBatteryPercent(this RadioItem item, byte battery) + { + item.BatteryPercent = battery; + return item; + } +} \ No newline at end of file From 630652c2689aaf9b8858ff05f6f5a28ccdc6a4a6 Mon Sep 17 00:00:00 2001 From: Lumi Date: Mon, 4 May 2026 11:06:15 +0100 Subject: [PATCH 5/6] feat: pickup extensions --- .../Pickups/PickupExtensions.Grenades.cs | 86 +++++++++++++++++++ .../Pickups/PickupExtensions.Jailbird.cs | 46 ++++++++++ .../Pickups/PickupExtensions.MicroHID.cs | 46 ++++++++++ .../Pickups/PickupExtensions.Radio.cs | 46 ++++++++++ .../Extensions/Pickups/PickupExtensions.cs | 75 ++++++++++++++++ 5 files changed, 299 insertions(+) create mode 100644 SecretAPI/Extensions/Pickups/PickupExtensions.Grenades.cs create mode 100644 SecretAPI/Extensions/Pickups/PickupExtensions.Jailbird.cs create mode 100644 SecretAPI/Extensions/Pickups/PickupExtensions.MicroHID.cs create mode 100644 SecretAPI/Extensions/Pickups/PickupExtensions.Radio.cs create mode 100644 SecretAPI/Extensions/Pickups/PickupExtensions.cs diff --git a/SecretAPI/Extensions/Pickups/PickupExtensions.Grenades.cs b/SecretAPI/Extensions/Pickups/PickupExtensions.Grenades.cs new file mode 100644 index 0000000..152b6fa --- /dev/null +++ b/SecretAPI/Extensions/Pickups/PickupExtensions.Grenades.cs @@ -0,0 +1,86 @@ +namespace SecretAPI.Extensions.Pickups; + +using LabApi.Features.Wrappers; +using UnityEngine; + +/// +/// Extensions for grenade projectiles. +/// +public static partial class PickupExtensions +{ + extension(T pickup) + where T : TimedGrenadeProjectile + { + /// + /// Modifies the remaining time of this . + /// + /// The time. + /// The modified . + public T WithRemainingTime(double time) + { + pickup.RemainingTime = time; + return pickup; + } + } + + extension(ExplosiveGrenadeProjectile pickup) + { + /// + /// Modifies the max explosion radius of this . + /// + /// The radius. + /// The modified . + public ExplosiveGrenadeProjectile WithMaxRadius(float radius) + { + pickup.MaxRadius = radius; + return pickup; + } + + /// + /// Modifies the scp damage multiplier of this . + /// + /// The multiplier. + /// The modified . + public ExplosiveGrenadeProjectile WithScpDamageMultiplier(float multiplier) + { + pickup.ScpDamageMultiplier = multiplier; + return pickup; + } + } + + /// + /// Modifies the flash time of this . + /// + /// The flashbang. + /// The time. + /// The modified . + public static FlashbangProjectile WithBlindTime(this FlashbangProjectile pickup, float time) + { + pickup.BaseBlindTime = time; + return pickup; + } + + /// + /// Modifies the velocity of this . + /// + /// The SCP-018 instance. + /// The velocity. + /// The modified . + public static Scp018Projectile WithVelocity(this Scp018Projectile pickup, Vector3 velocity) + { + pickup.Velocity = velocity; + return pickup; + } + + /// + /// Modifies the lockdown duration of this . + /// + /// The SCP-2176 instance. + /// The duration. + /// The modified . + public static Scp2176Projectile WithLockdownDuration(this Scp2176Projectile pickup, float duration) + { + pickup.LockdownDuration = duration; + return pickup; + } +} \ No newline at end of file diff --git a/SecretAPI/Extensions/Pickups/PickupExtensions.Jailbird.cs b/SecretAPI/Extensions/Pickups/PickupExtensions.Jailbird.cs new file mode 100644 index 0000000..8f1aad2 --- /dev/null +++ b/SecretAPI/Extensions/Pickups/PickupExtensions.Jailbird.cs @@ -0,0 +1,46 @@ +namespace SecretAPI.Extensions.Pickups; + +using InventorySystem.Items.Jailbird; +using JailbirdPickup = LabApi.Features.Wrappers.JailbirdPickup; + +/// +/// Extensions for jailbirds. +/// +public static partial class PickupExtensions +{ + extension(JailbirdPickup pickup) + { + /// + /// Modifies the total damage dealt of this . + /// + /// The damage. + /// The modified . + public JailbirdPickup WithTotalDamageDealt(float damage) + { + pickup.TotalDamageDealt += damage; + return pickup; + } + + /// + /// Modifies the total charges performed of this . + /// + /// The charges. + /// The modified . + public JailbirdPickup WithTotalChargesPerformed(int charges) + { + pickup.TotalChargesPerformed += charges; + return pickup; + } + + /// + /// Modifies the wear state of this . + /// + /// The state. + /// The modified . + public JailbirdPickup WithWearState(JailbirdWearState state) + { + pickup.WearState = state; + return pickup; + } + } +} \ No newline at end of file diff --git a/SecretAPI/Extensions/Pickups/PickupExtensions.MicroHID.cs b/SecretAPI/Extensions/Pickups/PickupExtensions.MicroHID.cs new file mode 100644 index 0000000..c749688 --- /dev/null +++ b/SecretAPI/Extensions/Pickups/PickupExtensions.MicroHID.cs @@ -0,0 +1,46 @@ +namespace SecretAPI.Extensions.Pickups; + +using InventorySystem.Items.MicroHID.Modules; +using LabApi.Features.Wrappers; + +/// +/// Extensions for Micro H.I.D. +/// +public static partial class PickupExtensions +{ + extension(MicroHIDPickup pickup) + { + /// + /// Modify the energy of this . + /// + /// The energy. + /// The modified . + public MicroHIDPickup WithEnergy(float energy) + { + pickup.Energy = energy; + return pickup; + } + + /// + /// Modify the phase of this . + /// + /// The phase. + /// The modified . + public MicroHIDPickup WithPhase(MicroHidPhase phase) + { + pickup.Phase = phase; + return pickup; + } + + /// + /// Modify the firing mode of this . + /// + /// The firing mode. + /// The modified . + public MicroHIDPickup WithFiringMode(MicroHidFiringMode mode) + { + pickup.FiringMode = mode; + return pickup; + } + } +} \ No newline at end of file diff --git a/SecretAPI/Extensions/Pickups/PickupExtensions.Radio.cs b/SecretAPI/Extensions/Pickups/PickupExtensions.Radio.cs new file mode 100644 index 0000000..f45b142 --- /dev/null +++ b/SecretAPI/Extensions/Pickups/PickupExtensions.Radio.cs @@ -0,0 +1,46 @@ +namespace SecretAPI.Extensions.Pickups; + +using InventorySystem.Items.Radio; +using RadioPickup = LabApi.Features.Wrappers.RadioPickup; + +/// +/// Extensions for radios. +/// +public static partial class PickupExtensions +{ + extension(RadioPickup pickup) + { + /// + /// Modifies the enabled state of this . + /// + /// The enabled state. + /// The modified . + public RadioPickup WithEnabledState(bool enabled) + { + pickup.IsEnabled = enabled; + return pickup; + } + + /// + /// Modifies the range level of this . + /// + /// The range. + /// The modified . + public RadioPickup WithRangeLevel(RadioMessages.RadioRangeLevel range) + { + pickup.RangeLevel = range; + return pickup; + } + + /// + /// Modifies the battery of this . + /// + /// The battery. + /// The modified . + public RadioPickup WithBattery(float battery) + { + pickup.Battery = battery; + return pickup; + } + } +} \ No newline at end of file diff --git a/SecretAPI/Extensions/Pickups/PickupExtensions.cs b/SecretAPI/Extensions/Pickups/PickupExtensions.cs new file mode 100644 index 0000000..07f260e --- /dev/null +++ b/SecretAPI/Extensions/Pickups/PickupExtensions.cs @@ -0,0 +1,75 @@ +namespace SecretAPI.Extensions.Pickups; + +using InventorySystem.Items.Usables.Scp330; +using LabApi.Features.Wrappers; +using Scp330Pickup = LabApi.Features.Wrappers.Scp330Pickup; + +/// +/// Extensions for pickups. +/// +public static partial class PickupExtensions +{ + extension(T pickup) + where T : Pickup + { + /// + /// Modifies the weight of this . + /// + /// The weight. + /// The modified . + public T WithWeight(float weight) + { + pickup.Weight = weight; + return pickup; + } + + /// + /// Modifies the locked state of this . + /// + /// The lock state. + /// The modified . + public T WithLockedState(bool locked) + { + pickup.IsLocked = locked; + return pickup; + } + } + + extension(Pickup pickup) + { + /// + /// Change this into a different pickup type, useful for the other extension methods that can be used. + /// + /// The pickup type you want to change type to. + /// The changed pickup type. + public T As() + where T : Pickup + { + return (T)pickup; + } + } + + /// + /// Modifies the ammo in this . + /// + /// The pickup. + /// The ammo. + /// The modified . + public static AmmoPickup WithAmmo(this AmmoPickup pickup, ushort ammo) + { + pickup.Ammo = ammo; + return pickup; + } + + /// + /// Modifies the exposed candy in this . + /// + /// The pickup. + /// The candy kind. + /// The modified . + public static Scp330Pickup WithExposedCandy(this Scp330Pickup pickup, CandyKindID kind) + { + pickup.ExposedCandy = kind; + return pickup; + } +} \ No newline at end of file From 486cc452c4537378453f22a42837a453562207dd Mon Sep 17 00:00:00 2001 From: Eve <85962933+obvEve@users.noreply.github.com> Date: Mon, 4 May 2026 17:59:58 +0200 Subject: [PATCH 6/6] Remove .As, replaced with Cast and CastTypeSafely --- SecretAPI/Extensions/Items/ItemExtensions.cs | 14 ------------ .../Extensions/Pickups/PickupExtensions.cs | 14 ------------ SecretAPI/Extensions/ReflectionExtensions.cs | 22 +++++++++++++++++++ 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/SecretAPI/Extensions/Items/ItemExtensions.cs b/SecretAPI/Extensions/Items/ItemExtensions.cs index 296443c..ac671c9 100644 --- a/SecretAPI/Extensions/Items/ItemExtensions.cs +++ b/SecretAPI/Extensions/Items/ItemExtensions.cs @@ -7,20 +7,6 @@ namespace SecretAPI.Extensions.Items; /// public static partial class ItemExtensions { - extension(Item item) - { - /// - /// Change this into a different item type, useful for the other extension methods that can be used. - /// - /// The item type you want to change type to. - /// The changed item type. - public T As() - where T : Item - { - return (T)item; - } - } - /// /// Modifies the battery percentage of this . /// diff --git a/SecretAPI/Extensions/Pickups/PickupExtensions.cs b/SecretAPI/Extensions/Pickups/PickupExtensions.cs index 07f260e..0d530b3 100644 --- a/SecretAPI/Extensions/Pickups/PickupExtensions.cs +++ b/SecretAPI/Extensions/Pickups/PickupExtensions.cs @@ -35,20 +35,6 @@ public T WithLockedState(bool locked) } } - extension(Pickup pickup) - { - /// - /// Change this into a different pickup type, useful for the other extension methods that can be used. - /// - /// The pickup type you want to change type to. - /// The changed pickup type. - public T As() - where T : Pickup - { - return (T)pickup; - } - } - /// /// Modifies the ammo in this . /// diff --git a/SecretAPI/Extensions/ReflectionExtensions.cs b/SecretAPI/Extensions/ReflectionExtensions.cs index 32767cf..340cf68 100644 --- a/SecretAPI/Extensions/ReflectionExtensions.cs +++ b/SecretAPI/Extensions/ReflectionExtensions.cs @@ -11,6 +11,28 @@ /// public static class ReflectionExtensions { + /// + /// Casts an object into . + /// This will throw an exception if is not of type . + /// + /// The source object to cast from. + /// The new type to cast to. + /// The source after being cast to T. + public static T Cast(this object source) + where T : class => (T)source; + + /// + /// Casts an object of to . + /// This will require to be derived from . + /// + /// The source to cast from. + /// The original type. + /// The type to cast to. + /// The source after being cast to . + public static T2 CastTypeSafely(this T1 source) + where T1 : class + where T2 : T1 => (T2)source; + /// /// Gets the long name of a function. ///