Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Breaking] AdminToys:Create structure #14

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions EXILED/Exiled.API/Features/Toys/Light.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ public bool ShadowEmission
set => Base.NetworkLightShadows = value;
}

/// <summary>
/// Creates a new <see cref="Light"/>.
/// </summary>
/// <param name="spawn">Whether the <see cref="Light"/> should be initially spawned.</param>
/// <returns>The new <see cref="Light"/>.</returns>
public static Light Create(bool spawn = true)
=> Create(Vector3.zero, Vector3.zero, Vector3.one, spawn);

/// <summary>
/// Creates a new <see cref="Light"/>.
/// </summary>
Expand All @@ -81,31 +89,31 @@ public bool ShadowEmission
/// <param name="scale">The scale of the <see cref="Light"/>.</param>
/// <param name="spawn">Whether the <see cref="Light"/> should be initially spawned.</param>
/// <returns>The new <see cref="Light"/>.</returns>
public static Light Create(Vector3? position = null, Vector3? rotation = null, Vector3? scale = null, bool spawn = true)
=> Create(position, rotation, scale, spawn, null);
public static Light Create(Vector3 position, Vector3 rotation, Vector3 scale, bool spawn = true)
=> Create(position, rotation, scale, Color.gray, spawn);

/// <summary>
/// Creates a new <see cref="Light"/>.
/// </summary>
/// <param name="position">The position of the <see cref="Light"/>.</param>
/// <param name="rotation">The rotation of the <see cref="Light"/>.</param>
/// <param name="scale">The scale of the <see cref="Light"/>.</param>
/// <param name="spawn">Whether the <see cref="Light"/> should be initially spawned.</param>
/// <param name="color">The color of the <see cref="Light"/>.</param>
/// <param name="spawn">Whether the <see cref="Light"/> should be initially spawned.</param>
/// <returns>The new <see cref="Light"/>.</returns>
public static Light Create(Vector3? position /*= null*/, Vector3? rotation /*= null*/, Vector3? scale /*= null*/, bool spawn /*= true*/, Color? color /*= null*/)
public static Light Create(Vector3 position, Vector3 rotation, Vector3 scale, Color color, bool spawn)
{
Light light = new(UnityEngine.Object.Instantiate(ToysHelper.LightBaseObject));

light.Position = position ?? Vector3.zero;
light.Rotation = Quaternion.Euler(rotation ?? Vector3.zero);
light.Scale = scale ?? Vector3.one;
light.Position = position;
light.Rotation = Quaternion.Euler(rotation);
light.Scale = scale;

light.Color = color;

if (spawn)
light.Spawn();

light.Color = color ?? Color.gray;

return light;
}

Expand Down
108 changes: 45 additions & 63 deletions EXILED/Exiled.API/Features/Toys/Primitive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ public PrimitiveFlags Flags
set => Base.NetworkPrimitiveFlags = value;
}

/// <summary>
/// Creates a new <see cref="Primitive"/>.
/// </summary>
/// <param name="primitiveType">The type of primitive to spawn.</param>
/// <param name="spawn">Whether or not the <see cref="Primitive"/> should be initially spawned.</param>
/// <returns>The new <see cref="Primitive"/>.</returns>
public static Primitive Create(PrimitiveType primitiveType, bool spawn = true)
=> Create(primitiveType, Vector3.zero, Vector3.zero, Vector3.one, spawn);

/// <summary>
/// Creates a new <see cref="Primitive"/>.
/// </summary>
Expand All @@ -89,45 +98,32 @@ public PrimitiveFlags Flags
/// <param name="scale">The scale of the <see cref="Primitive"/>.</param>
/// <param name="spawn">Whether or not the <see cref="Primitive"/> should be initially spawned.</param>
/// <returns>The new <see cref="Primitive"/>.</returns>
public static Primitive Create(Vector3? position = null, Vector3? rotation = null, Vector3? scale = null, bool spawn = true)
=> Create(position, rotation, scale, spawn, null);
public static Primitive Create(Vector3 position, Vector3 rotation, Vector3 scale, bool spawn = true)
=> Create(position, rotation, scale, Color.gray, spawn);

/// <summary>
/// Creates a new <see cref="Primitive"/>.
/// </summary>
/// <param name="primitiveType">The type of primitive to spawn.</param>
/// <param name="position">The position of the <see cref="Primitive"/>.</param>
/// <param name="rotation">The rotation of the <see cref="Primitive"/>.</param>
/// <param name="scale">The scale of the <see cref="Primitive"/>.</param>
/// <param name="color">The color of the <see cref="Primitive"/>.</param>
/// <param name="spawn">Whether or not the <see cref="Primitive"/> should be initially spawned.</param>
/// <returns>The new <see cref="Primitive"/>.</returns>
public static Primitive Create(PrimitiveType primitiveType = PrimitiveType.Sphere, Vector3? position = null, Vector3? rotation = null, Vector3? scale = null, bool spawn = true)
=> Create(primitiveType, position, rotation, scale, spawn, null);
public static Primitive Create(Vector3 position, Vector3 rotation, Vector3 scale, Color color, bool spawn = true)
=> Create(PrimitiveType.Sphere, position, rotation, scale, color, spawn);

/// <summary>
/// Creates a new <see cref="Primitive"/>.
/// </summary>
/// <param name="primitiveType">The type of primitive to spawn.</param>
/// <param name="position">The position of the <see cref="Primitive"/>.</param>
/// <param name="rotation">The rotation of the <see cref="Primitive"/>.</param>
/// <param name="scale">The scale of the <see cref="Primitive"/>.</param>
/// <param name="spawn">Whether or not the <see cref="Primitive"/> should be initially spawned.</param>
/// <param name="color">The color of the <see cref="Primitive"/>.</param>
/// <returns>The new <see cref="Primitive"/>.</returns>
public static Primitive Create(Vector3? position /*= null*/, Vector3? rotation /*= null*/, Vector3? scale /*= null*/, bool spawn /*= true*/, Color? color /*= null*/)
{
Primitive primitive = new(Object.Instantiate(ToysHelper.PrimitiveBaseObject));

primitive.Position = position ?? Vector3.zero;
primitive.Rotation = Quaternion.Euler(rotation ?? Vector3.zero);
primitive.Scale = scale ?? Vector3.one;

if (spawn)
primitive.Spawn();

primitive.Color = color ?? Color.gray;

return primitive;
}
public static Primitive Create(PrimitiveType primitiveType, Vector3 position, Vector3 rotation, Vector3 scale, bool spawn = true)
=> Create(primitiveType, position, rotation, scale, Color.gray, spawn);

/// <summary>
/// Creates a new <see cref="Primitive"/>.
Expand All @@ -136,25 +132,11 @@ public static Primitive Create(Vector3? position /*= null*/, Vector3? rotation /
/// <param name="position">The position of the <see cref="Primitive"/>.</param>
/// <param name="rotation">The rotation of the <see cref="Primitive"/>.</param>
/// <param name="scale">The scale of the <see cref="Primitive"/>.</param>
/// <param name="spawn">Whether or not the <see cref="Primitive"/> should be initially spawned.</param>
/// <param name="color">The color of the <see cref="Primitive"/>.</param>
/// <param name="spawn">Whether or not the <see cref="Primitive"/> should be initially spawned.</param>
/// <returns>The new <see cref="Primitive"/>.</returns>
public static Primitive Create(PrimitiveType primitiveType /*= PrimitiveType.Sphere*/, Vector3? position /*= null*/, Vector3? rotation /*= null*/, Vector3? scale /*= null*/, bool spawn /*= true*/, Color? color /*= null*/)
{
Primitive primitive = new(Object.Instantiate(ToysHelper.PrimitiveBaseObject));

primitive.Position = position ?? Vector3.zero;
primitive.Rotation = Quaternion.Euler(rotation ?? Vector3.zero);
primitive.Scale = scale ?? Vector3.one;

if (spawn)
primitive.Spawn();

primitive.Base.NetworkPrimitiveType = primitiveType;
primitive.Color = color ?? Color.gray;

return primitive;
}
public static Primitive Create(PrimitiveType primitiveType, Vector3 position, Vector3 rotation, Vector3 scale, Color color, bool spawn = true)
=> Create(primitiveType, ~PrimitiveFlags.None, position, rotation, scale, color, spawn);

/// <summary>
/// Creates a new <see cref="Primitive"/>.
Expand All @@ -164,24 +146,40 @@ public static Primitive Create(PrimitiveType primitiveType /*= PrimitiveType.Sph
/// <param name="position">The position of the <see cref="Primitive"/>.</param>
/// <param name="rotation">The rotation of the <see cref="Primitive"/>.</param>
/// <param name="scale">The scale of the <see cref="Primitive"/>.</param>
/// <param name="color">The color of the <see cref="Primitive"/>.</param>
/// <param name="spawn">Whether or not the <see cref="Primitive"/> should be initially spawned.</param>
/// <returns>The new <see cref="Primitive"/>.</returns>
public static Primitive Create(PrimitiveType primitiveType, PrimitiveFlags flags, Vector3 position, Vector3 rotation, Vector3 scale, Color color, bool spawn)
=> Create(primitiveType, flags, position, rotation, scale, color, false, spawn);

/// <summary>
/// Creates a new <see cref="Primitive"/>.
/// </summary>
/// <param name="primitiveType">The type of primitive to spawn.</param>
/// <param name="flags">The primitive flags.</param>
/// <param name="position">The position of the <see cref="Primitive"/>.</param>
/// <param name="rotation">The rotation of the <see cref="Primitive"/>.</param>
/// <param name="scale">The scale of the <see cref="Primitive"/>.</param>
/// <param name="color">The color of the <see cref="Primitive"/>.</param>
/// <param name="isStatic">Whether or not the <see cref="Primitive"/> should dynamically update.</param>
/// <param name="spawn">Whether or not the <see cref="Primitive"/> should be initially spawned.</param>
/// <returns>The new <see cref="Primitive"/>.</returns>
public static Primitive Create(PrimitiveType primitiveType /*= PrimitiveType.Sphere*/, PrimitiveFlags flags, Vector3? position /*= null*/, Vector3? rotation /*= null*/, Vector3? scale /*= null*/, bool spawn /*= true*/, Color? color /*= null*/)
public static Primitive Create(PrimitiveType primitiveType, PrimitiveFlags flags, Vector3 position, Vector3 rotation, Vector3 scale, Color color, bool isStatic, bool spawn)
{
Primitive primitive = new(Object.Instantiate(ToysHelper.PrimitiveBaseObject));

primitive.Position = position ?? Vector3.zero;
primitive.Rotation = Quaternion.Euler(rotation ?? Vector3.zero);
primitive.Scale = scale ?? Vector3.one;
primitive.Position = position;
primitive.Rotation = Quaternion.Euler(rotation);
primitive.Scale = scale;

primitive.Flags = flags;
primitive.IsStatic = isStatic;
primitive.Type = primitiveType;
primitive.Color = color;

if (spawn)
primitive.Spawn();

primitive.Base.NetworkPrimitiveType = primitiveType;
primitive.Color = color ?? Color.gray;

return primitive;
}

Expand All @@ -190,24 +188,8 @@ public static Primitive Create(PrimitiveType primitiveType /*= PrimitiveType.Sph
/// </summary>
/// <param name="primitiveSettings">The settings of the <see cref="Primitive"/>.</param>
/// <returns>The new <see cref="Primitive"/>.</returns>
public static Primitive Create(PrimitiveSettings primitiveSettings)
{
Primitive primitive = new(Object.Instantiate(ToysHelper.PrimitiveBaseObject));

primitive.Position = primitiveSettings.Position;
primitive.Rotation = Quaternion.Euler(primitiveSettings.Rotation);
primitive.Scale = primitiveSettings.Scale;
primitive.Flags = primitiveSettings.Flags;

if (primitiveSettings.Spawn)
primitive.Spawn();

primitive.Base.NetworkPrimitiveType = primitiveSettings.PrimitiveType;
primitive.Color = primitiveSettings.Color;
primitive.IsStatic = primitiveSettings.IsStatic;

return primitive;
}
public static Primitive Create(PrimitiveSettings primitiveSettings) =>
Create(primitiveSettings.PrimitiveType, primitiveSettings.Flags, primitiveSettings.Position, primitiveSettings.Rotation, primitiveSettings.Scale, primitiveSettings.Color, primitiveSettings.IsStatic, primitiveSettings.Spawn);

/// <summary>
/// Gets the <see cref="Primitive"/> belonging to the <see cref="PrimitiveObjectToy"/>.
Expand Down
49 changes: 25 additions & 24 deletions EXILED/Exiled.API/Features/Toys/ShootingTargetToy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ public class ShootingTargetToy : AdminToy, IWrapper<ShootingTarget>
{ "binaryTargetPrefab", ShootingTargetType.Binary },
};

private static readonly Dictionary<ShootingTargetType, ShootingTarget> TypeToPrefabs = new()
{
{ ShootingTargetType.ClassD, ToysHelper.DboyShootingTargetObject },
{ ShootingTargetType.Binary, ToysHelper.BinaryShootingTargetObject },
{ ShootingTargetType.Sport, ToysHelper.SportShootingTargetObject },
{ ShootingTargetType.Unknown, ToysHelper.SportShootingTargetObject },
};

/// <summary>
/// Initializes a new instance of the <see cref="ShootingTargetToy"/> class.
/// </summary>
Expand Down Expand Up @@ -148,6 +156,15 @@ public bool IsSynced
/// </summary>
public ShootingTargetType Type { get; }

/// <summary>
/// Creates a new <see cref="ShootingTargetToy"/>.
/// </summary>
/// <param name="type">The <see cref="ShootingTargetType"/> of the <see cref="ShootingTargetToy"/>.</param>
/// <param name="spawn">Whether the <see cref="ShootingTargetToy"/> should be initially spawned.</param>
/// <returns>The new <see cref="ShootingTargetToy"/>.</returns>
public static ShootingTargetToy Create(ShootingTargetType type, bool spawn = true) =>
Create(type, Vector3.zero, Vector3.zero, Vector3.one, spawn);

/// <summary>
/// Creates a new <see cref="ShootingTargetToy"/>.
/// </summary>
Expand All @@ -157,34 +174,18 @@ public bool IsSynced
/// <param name="scale">The scale of the <see cref="ShootingTargetToy"/>.</param>
/// <param name="spawn">Whether the <see cref="ShootingTargetToy"/> should be initially spawned.</param>
/// <returns>The new <see cref="ShootingTargetToy"/>.</returns>
public static ShootingTargetToy Create(ShootingTargetType type, Vector3? position = null, Vector3? rotation = null, Vector3? scale = null, bool spawn = true)
public static ShootingTargetToy Create(ShootingTargetType type, Vector3 position, Vector3 rotation, Vector3 scale, bool spawn = true)
{
ShootingTargetToy shootingTargetToy;

switch (type)
if (!TypeToPrefabs.TryGetValue(type, out ShootingTarget shootingTargetBase))
{
case ShootingTargetType.ClassD:
{
shootingTargetToy = new ShootingTargetToy(Object.Instantiate(ToysHelper.DboyShootingTargetObject));
break;
}

case ShootingTargetType.Binary:
{
shootingTargetToy = new ShootingTargetToy(Object.Instantiate(ToysHelper.BinaryShootingTargetObject));
break;
}

default:
{
shootingTargetToy = new ShootingTargetToy(Object.Instantiate(ToysHelper.SportShootingTargetObject));
break;
}
shootingTargetBase = TypeToPrefabs[ShootingTargetType.Unknown];
}

shootingTargetToy.Position = position ?? Vector3.zero;
shootingTargetToy.Rotation = Quaternion.Euler(rotation ?? Vector3.zero);
shootingTargetToy.Scale = scale ?? Vector3.one;
ShootingTargetToy shootingTargetToy = new ShootingTargetToy(shootingTargetBase);

shootingTargetToy.Position = position;
shootingTargetToy.Rotation = Quaternion.Euler(rotation);
shootingTargetToy.Scale = scale;

if (spawn)
shootingTargetToy.Spawn();
Expand Down
2 changes: 1 addition & 1 deletion EXILED/Exiled.API/Structs/PrimitiveSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public PrimitiveSettings(PrimitiveType primitiveType, PrimitiveFlags primitiveFl
public Vector3 Scale { get; }

/// <summary>
/// Gets a value indicating whether or not the primitive should be spawned.
/// Gets a value indicating whether or not the primitive should dynamically update.
/// </summary>
public bool IsStatic { get; }

Expand Down