using System;
using JetBrains.Annotations;
using Robust.Shared.Interfaces.GameObjects;
namespace Content.Shared.GameObjects.Verbs
{
///
/// A verb is an action in the right click menu of an entity.
///
///
/// To add a verb to an entity, define it as a nested class inside the owning component,
/// and mark it with
///
[UsedImplicitly]
public abstract class Verb : VerbBase
{
///
/// Gets the visible verb data for the user.
///
///
/// Implementations should write into to return their data.
///
/// The entity of the user opening this menu.
/// The component instance for which this verb is being loaded.
/// The data that must be filled into.
protected abstract void GetData(IEntity user, IComponent component, VerbData data);
///
/// Invoked when this verb is activated from the right click menu.
///
/// The entity of the user opening this menu.
/// The component instance for which this verb is being loaded.
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;
}
}
///
///
/// Sub class of that works on a specific type of component,
/// to reduce casting boiler plate for implementations.
///
/// The type of component that this verb will run on.
public abstract class Verb : Verb where T : IComponent
{
///
/// Gets the visible verb data for the user.
///
///
/// Implementations should write into to return their data.
///
/// The entity of the user opening this menu.
/// The component instance for which this verb is being loaded.
/// The data that must be filled into.
protected abstract void GetData(IEntity user, T component, VerbData data);
///
/// Invoked when this verb is activated from the right click menu.
///
/// The entity of the user opening this menu.
/// The component instance for which this verb is being loaded.
protected abstract void Activate(IEntity user, T component);
protected sealed override void GetData(IEntity user, IComponent component, VerbData data)
{
GetData(user, (T) component, data);
}
///
public sealed override void Activate(IEntity user, IComponent component)
{
Activate(user, (T) component);
}
}
///
/// This attribute should be used on implementations nested inside component classes,
/// so that they're automatically detected.
///
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
[MeansImplicitUse]
public sealed class VerbAttribute : Attribute
{
}
}