Skip to content

Commit

Permalink
Apis rework (#2660)
Browse files Browse the repository at this point in the history
* `[Exiled::Core]` `Assets` and `Fragments` (#2568)

* Core's assets have been implemented:

- Added new classes and attributes for improved entity management.
- Added AssetFragment, EClass, EntityAsset, and related attributes.
- Any types implementing IAssetFragment can be used to generate a fragment or an EntityAsset.
- Began adding EProperty attributes to classes which are supposed to be used to generate fragments and assets.

* Implemented `EProperty` for Items

* ?.

* Minor changes to `EConfig`. Added an `EClass`.
Converted `Effect` class to struct.

* Added `Generator` `EClass`

* Fix hint's `EClass`

* Added more `EClass`'es

* Fixed `AssetFragment::GenerateAsset` generating assets from types which are not marked as `EClass`.

* Fixed `State` compare by ref instead of value

* Minor fixes

* All `EClass`'es

* Fix warnings

* Fix docs

* Revert CustomHealthStat.cs

* Fix build error

* fix conflict?

* fix typo

* fix removals

* fix lag & log spam

* Changes & null fix

* [Core API] Fix null & invalid cast (#2650)

---------

Co-authored-by: Nameless <85962933+Misfiy@users.noreply.github.com>

* Revert "Merge remote-tracking branch 'origin/dev' into apis-rework"

This reverts commit 08e279f, reversing
changes made to 1b8d3a5.

* Exiled9  (#2641)

* Changes

* that

---------

Co-authored-by: Yamato <66829532+louis1706@users.noreply.github.com>

* Moved modified code. (#2656)

---------

Co-authored-by: Nameless <85962933+Misfiy@users.noreply.github.com>
Co-authored-by: Yamato <66829532+louis1706@users.noreply.github.com>
Co-authored-by: Alex Rouse <123724383+ALEXWARELLC@users.noreply.github.com>
  • Loading branch information
4 people authored Jul 1, 2024
1 parent 4845e73 commit 6798314
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Exiled.CustomModules/API/Extensions/ItemExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// -----------------------------------------------------------------------
// <copyright file="ItemExtensions.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.CustomModules.API.Extensions
{
using Exiled.API.Features.Items;
using Exiled.CustomModules.API.Features.CustomItems;

/// <summary>
/// A set of extensions for <see cref="Item"/>.
/// </summary>
public static class ItemExtensions
{
/// <inheritdoc cref="CustomItem.Get(Item)"/>
public static CustomItem Get(this Item item) => CustomItem.Get(item);

/// <inheritdoc cref="CustomItem.TryGet(Item, out CustomItem)"/>
public static bool TryGet(this Item item, out CustomItem customItem) => CustomItem.TryGet(item, out customItem);
}
}
24 changes: 24 additions & 0 deletions Exiled.CustomModules/API/Extensions/PickupExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// -----------------------------------------------------------------------
// <copyright file="PickupExtensions.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.CustomModules.API.Extensions
{
using Exiled.API.Features.Pickups;
using Exiled.CustomModules.API.Features.CustomItems;

/// <summary>
/// A set of extensions for <see cref="Pickup"/>.
/// </summary>
public static class PickupExtensions
{
/// <inheritdoc cref="CustomItem.Get(Pickup)"/>
public static CustomItem Get(this Pickup pickup) => CustomItem.Get(pickup);

/// <inheritdoc cref="CustomItem.TryGet(Pickup, out CustomItem)"/>
public static bool TryGet(this Pickup pickup, out CustomItem item) => CustomItem.TryGet(pickup, out item);
}
}
59 changes: 59 additions & 0 deletions Exiled.CustomModules/API/Extensions/PlayerExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// -----------------------------------------------------------------------
// <copyright file="PlayerExtensions.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.CustomModules.API.Extensions
{
using System;

using Exiled.API.Features;
using Exiled.CustomModules.API.Features;
using Exiled.CustomModules.API.Features.CustomItems;
using Exiled.CustomModules.API.Features.CustomRoles;

/// <summary>
/// A set of extensions for <see cref="Player"/>.
/// </summary>
public static class PlayerExtensions
{
/// <inheritdoc cref="CustomRole.Get(Pawn)"/>
public static CustomRole Get(this Player player) => CustomRole.Get(player.Cast<Pawn>());

/// <inheritdoc cref="CustomRole.Spawn(Pawn, CustomRole, bool)"/>
public static bool Spawn(this Player player, CustomRole customRole, bool shouldKeepPosition = false) => CustomRole.Spawn(player.Cast<Pawn>(), customRole, shouldKeepPosition);

/// <inheritdoc cref="CustomRole.Spawn{T}(Pawn)"/>
public static bool Spawn<T>(this Player player)
where T : CustomRole => CustomRole.Spawn<T>(player.Cast<Pawn>());

/// <inheritdoc cref="CustomRole.Spawn(Pawn, string, bool)"/>
public static bool Spawn(this Player player, string name, bool shouldKeepPosition = false) => CustomRole.Spawn(player.Cast<Pawn>(), name, shouldKeepPosition);

/// <inheritdoc cref="CustomRole.Spawn(Pawn, uint, bool)"/>
public static bool Spawn(this Player player, uint id, bool shouldKeepPosition = false) => CustomRole.Spawn(player.Cast<Pawn>(), id, shouldKeepPosition);

/// <inheritdoc cref="CustomRole.TrySpawn(Pawn, CustomRole)"/>
public static bool TrySpawn(this Player player, CustomRole customRole) => CustomRole.TrySpawn(player.Cast<Pawn>(), customRole);

/// <inheritdoc cref="CustomRole.TrySpawn(Pawn, string)"/>
public static bool TrySpawn(this Player player, string name) => CustomRole.TrySpawn(player.Cast<Pawn>(), name);

/// <inheritdoc cref="CustomRole.TrySpawn(Pawn, uint)"/>
public static bool TrySpawn(this Player player, uint id) => CustomRole.TrySpawn(player.Cast<Pawn>(), id);

/// <inheritdoc cref="CustomRole.TryGet(Pawn, out CustomRole)"/>
public static bool TryGet(this Player player, out CustomRole customRole) => CustomRole.TryGet(player.Cast<Pawn>(), out customRole);

/// <inheritdoc cref="CustomItem.TryGive(Player, string, bool)"/>
public static bool TryGive(this Player player, string name, bool displayMessage = true) => CustomItem.TryGive(player, name, displayMessage);

/// <inheritdoc cref="CustomItem.TryGive(Player, uint, bool)"/>
public static bool TryGive(this Player player, uint id, bool displayMessage = true) => CustomItem.TryGive(player, id, displayMessage);

/// <inheritdoc cref="CustomItem.TryGive(Player, Type, bool)"/>
public static bool TryGive(this Player player, Type type, bool displayMessage) => CustomItem.TryGive(player, type, displayMessage);
}
}
15 changes: 15 additions & 0 deletions Exiled.CustomModules/API/Features/CustomRoles/CustomRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,21 @@ public static bool Spawn(Pawn player, string name, bool shouldKeepPosition = fal
return true;
}

/// <summary>
/// Spawns the specified player with the custom role identified by the provided type.
/// </summary>
/// <typeparam name="T">The type of custom role to be added.</typeparam>
/// <param name="player">The <see cref="Pawn"/> to be spawned.</param>
/// <returns>
/// <see langword="true"/> if the player was spawned with the custom role successfully; otherwise, <see langword="false"/>.
/// </returns>
/// <remarks>
/// This method add the custom role of type <typeparamref name="T"/> assigned to the specified player.
/// If the addition operation fails, the method returns <see langword="false"/>.
/// </remarks>
public static bool Spawn<T>(Pawn player)
where T : CustomRole => TryGet(typeof(T), out CustomRole customRole) && customRole.Spawn(player);

/// <summary>
/// Removes the custom role from the specified player.
/// </summary>
Expand Down

0 comments on commit 6798314

Please sign in to comment.