* Add nullable to some Content.Shared files. * Use [NotNullWhen(true)] * Undo adding now redundant !'s * Forgot one * Add a ton more nullable * You can guess * Fix some issues * It actually compiles now * Auto stash before merge of "null2" and "origin/master" * I lied * enable annotations -> enable * Revert ActionBlockerSystem.cs to original * Fix ActionBlockerSystem.cs * More nullable * Undo some added exclamation marks * Fix issues * Update Content.Shared/Maps/ContentTileDefinition.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Resolve some issues * Remove unused method * Fix more issues * Fix more issues * Fix more issues * Fix more issues * Fix issue, rollback SharedGhostComponent.cs * Update submodule * Fix issue, invert some if-statements to reduce nesting * Revert RobustToolbox * FIx things broken by merge * Some fixes - Replaced with string.Empty - Remove some exclamation marks - Revert file * Some fixes * Trivial #nullable enable * Fix null ables Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
92 lines
3.7 KiB
C#
92 lines
3.7 KiB
C#
#nullable enable
|
|
using System;
|
|
using JetBrains.Annotations;
|
|
using Robust.Shared.GameObjects;
|
|
|
|
namespace Content.Shared.GameObjects.Verbs
|
|
{
|
|
/// <summary>
|
|
/// A verb is an action in the right click menu of an entity.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// To add a verb to an entity, define it as a nested class inside the owning component,
|
|
/// and mark it with <see cref="VerbAttribute"/>
|
|
/// </remarks>
|
|
[UsedImplicitly]
|
|
public abstract class Verb : VerbBase
|
|
{
|
|
/// <summary>
|
|
/// Gets the visible verb data for the user.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Implementations should write into <paramref name="data"/> to return their data.
|
|
/// </remarks>
|
|
/// <param name="user">The entity of the user opening this menu.</param>
|
|
/// <param name="component">The component instance for which this verb is being loaded.</param>
|
|
/// <param name="data">The data that must be filled into.</param>
|
|
protected abstract void GetData(IEntity user, IComponent component, VerbData data);
|
|
|
|
/// <summary>
|
|
/// Invoked when this verb is activated from the right click menu.
|
|
/// </summary>
|
|
/// <param name="user">The entity of the user opening this menu.</param>
|
|
/// <param name="component">The component instance for which this verb is being loaded.</param>
|
|
public abstract void Activate(IEntity user, IComponent component);
|
|
|
|
public VerbData GetData(IEntity user, IComponent component)
|
|
{
|
|
var data = new VerbData();
|
|
GetData(user, component, data);
|
|
return data;
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
/// <summary>
|
|
/// Sub class of <see cref="T:Content.Shared.GameObjects.Verbs.Verb" /> that works on a specific type of component,
|
|
/// to reduce casting boiler plate for implementations.
|
|
/// </summary>
|
|
/// <typeparam name="T">The type of component that this verb will run on.</typeparam>
|
|
public abstract class Verb<T> : Verb where T : IComponent
|
|
{
|
|
/// <summary>
|
|
/// Gets the visible verb data for the user.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Implementations should write into <paramref name="data"/> to return their data.
|
|
/// </remarks>
|
|
/// <param name="user">The entity of the user opening this menu.</param>
|
|
/// <param name="component">The component instance for which this verb is being loaded.</param>
|
|
/// <param name="data">The data that must be filled into.</param>
|
|
protected abstract void GetData(IEntity user, T component, VerbData data);
|
|
|
|
/// <summary>
|
|
/// Invoked when this verb is activated from the right click menu.
|
|
/// </summary>
|
|
/// <param name="user">The entity of the user opening this menu.</param>
|
|
/// <param name="component">The component instance for which this verb is being loaded.</param>
|
|
protected abstract void Activate(IEntity user, T component);
|
|
|
|
protected sealed override void GetData(IEntity user, IComponent component, VerbData data)
|
|
{
|
|
GetData(user, (T) component, data);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public sealed override void Activate(IEntity user, IComponent component)
|
|
{
|
|
Activate(user, (T) component);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// This attribute should be used on <see cref="Verb"/> implementations nested inside component classes,
|
|
/// so that they're automatically detected.
|
|
/// </summary>
|
|
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
|
|
[MeansImplicitUse]
|
|
public sealed class VerbAttribute : Attribute
|
|
{
|
|
}
|
|
}
|