Re-organize all projects (#4166)

This commit is contained in:
DrSmugleaf
2021-06-09 22:19:39 +02:00
committed by GitHub
parent 9f50e4061b
commit ff1a2d97ea
1773 changed files with 5258 additions and 5508 deletions

View File

@@ -0,0 +1,103 @@
#nullable enable
using Content.Shared.Actions.Behaviors;
using Content.Shared.Module;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Shared.Actions.Prototypes
{
/// <summary>
/// An action which is granted directly to an entity (such as an innate ability
/// or skill).
/// </summary>
[Prototype("action")]
[DataDefinition]
public class ActionPrototype : BaseActionPrototype, ISerializationHooks
{
/// <summary>
/// Type of action, no 2 action prototypes should have the same one.
/// </summary>
[DataField("actionType", required: true)]
public ActionType ActionType { get; set; }
[DataField("behavior", serverOnly: true)]
private IActionBehavior? Behavior { get; set; }
/// <summary>
/// The IInstantAction that should be invoked when performing this
/// action. Null if this is not an Instant ActionBehaviorType.
/// Will be null on client side if the behavior is not in Content.Client.
/// </summary>
public IInstantAction InstantAction { get; private set; } = default!;
/// <summary>
/// The IToggleAction that should be invoked when performing this
/// action. Null if this is not a Toggle ActionBehaviorType.
/// Will be null on client side if the behavior is not in Content.Client.
/// </summary>
public IToggleAction ToggleAction { get; private set; } = default!;
/// <summary>
/// The ITargetEntityAction that should be invoked when performing this
/// action. Null if this is not a TargetEntity ActionBehaviorType.
/// Will be null on client side if the behavior is not in Content.Client.
/// </summary>
public ITargetEntityAction TargetEntityAction { get; private set; } = default!;
/// <summary>
/// The ITargetPointAction that should be invoked when performing this
/// action. Null if this is not a TargetPoint ActionBehaviorType.
/// Will be null on client side if the behavior is not in Content.Client.
/// </summary>
public ITargetPointAction TargetPointAction { get; private set; } = default!;
public override string ID => ActionType.ToString();
void ISerializationHooks.AfterDeserialization()
{
base.AfterDeserialization();
if (ActionType == ActionType.Error)
{
Logger.ErrorS("action", "missing or invalid actionType for action with name {0}", Name);
}
if (IoCManager.Resolve<IModuleManager>().IsClientModule) return;
switch (Behavior)
{
case null:
BehaviorType = BehaviorType.None;
Logger.ErrorS("action", "missing or invalid behavior for action with name {0}", Name);
break;
case IInstantAction instantAction:
ValidateBehaviorType(BehaviorType.Instant, typeof(IInstantAction));
BehaviorType = BehaviorType.Instant;
InstantAction = instantAction;
break;
case IToggleAction toggleAction:
ValidateBehaviorType(BehaviorType.Toggle, typeof(IToggleAction));
BehaviorType = BehaviorType.Toggle;
ToggleAction = toggleAction;
break;
case ITargetEntityAction targetEntity:
ValidateBehaviorType(BehaviorType.TargetEntity, typeof(ITargetEntityAction));
BehaviorType = BehaviorType.TargetEntity;
TargetEntityAction = targetEntity;
break;
case ITargetPointAction targetPointAction:
ValidateBehaviorType(BehaviorType.TargetPoint, typeof(ITargetPointAction));
BehaviorType = BehaviorType.TargetPoint;
TargetPointAction = targetPointAction;
break;
default:
BehaviorType = BehaviorType.None;
Logger.ErrorS("action", "unrecognized behavior type for action with name {0}", Name);
break;
}
}
}
}

View File

@@ -0,0 +1,171 @@
#nullable enable
using System;
using System.Collections.Generic;
using Robust.Shared.Log;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
namespace Content.Shared.Actions.Prototypes
{
/// <summary>
/// Base class for action prototypes.
/// </summary>
[ImplicitDataDefinitionForInheritors]
public abstract class BaseActionPrototype : IPrototype, ISerializationHooks
{
public abstract string ID { get; }
/// <summary>
/// Icon representing this action in the UI.
/// </summary>
[ViewVariables]
[DataField("icon")]
public SpriteSpecifier Icon { get; } = SpriteSpecifier.Invalid;
/// <summary>
/// For toggle actions only, icon to show when toggled on. If omitted,
/// the action will simply be highlighted when turned on.
/// </summary>
[ViewVariables]
[DataField("iconOn")]
public SpriteSpecifier IconOn { get; } = SpriteSpecifier.Invalid;
/// <summary>
/// Name to show in UI. Accepts formatting.
/// </summary>
[DataField("name")]
public FormattedMessage Name { get; private set; } = new();
/// <summary>
/// Description to show in UI. Accepts formatting.
/// </summary>
[DataField("description")]
public FormattedMessage Description { get; } = new();
/// <summary>
/// Requirements message to show in UI. Accepts formatting, but generally should be avoided
/// so the requirements message isn't too prominent in the tooltip.
/// </summary>
[DataField("requires")]
public string Requires { get; } = string.Empty;
/// <summary>
/// The type of behavior this action has. This is valid clientside and serverside.
/// </summary>
[DataField("behaviorType")]
public BehaviorType BehaviorType { get; protected set; } = BehaviorType.None;
/// <summary>
/// For targetpoint or targetentity actions, if this is true the action will remain
/// selected after it is used, so it can be continuously re-used. If this is false,
/// the action will be deselected after one use.
/// </summary>
[DataField("repeat")]
public bool Repeat { get; }
/// <summary>
/// For TargetEntity/TargetPoint actions, should the action be de-selected if currently selected (choosing a target)
/// when it goes on cooldown. Defaults to false.
/// </summary>
[DataField("deselectOnCooldown")]
public bool DeselectOnCooldown { get; }
/// <summary>
/// For TargetEntity actions, should the action be de-selected if the user doesn't click an entity when
/// selecting a target. Defaults to false.
/// </summary>
[DataField("deselectWhenEntityNotClicked")]
public bool DeselectWhenEntityNotClicked { get; }
[DataField("filters")] private List<string> _filters = new();
/// <summary>
/// Filters that can be used to filter this item in action menu.
/// </summary>
public IEnumerable<string> Filters => _filters;
[DataField("keywords")] private List<string> _keywords = new();
/// <summary>
/// Keywords that can be used to search this item in action menu.
/// </summary>
public IEnumerable<string> Keywords => _keywords;
/// <summary>
/// True if this is an action that requires selecting a target
/// </summary>
public bool IsTargetAction =>
BehaviorType == BehaviorType.TargetEntity || BehaviorType == BehaviorType.TargetPoint;
public virtual void AfterDeserialization()
{
Name = new FormattedMessage();
Name.AddText(ID);
if (BehaviorType == BehaviorType.None)
{
Logger.ErrorS("action", "Missing behaviorType for action with name {0}", Name);
}
if (BehaviorType != BehaviorType.Toggle && IconOn != SpriteSpecifier.Invalid)
{
Logger.ErrorS("action", "for action {0}, iconOn was specified but behavior" +
" type was {1}. iconOn is only supported for Toggle behavior type.", Name);
}
if (Repeat && BehaviorType != BehaviorType.TargetEntity && BehaviorType != BehaviorType.TargetPoint)
{
Logger.ErrorS("action", " action named {0} used repeat: true, but this is only supported for" +
" TargetEntity and TargetPoint behaviorType and its behaviorType is {1}",
Name, BehaviorType);
}
}
protected void ValidateBehaviorType(BehaviorType expected, Type actualInterface)
{
if (BehaviorType != expected)
{
Logger.ErrorS("action", "for action named {0}, behavior implements " +
"{1}, so behaviorType should be {2} but was {3}", Name, actualInterface.Name, expected, BehaviorType);
}
}
}
/// <summary>
/// The behavior / logic of the action. Each of these corresponds to a particular IActionBehavior
/// (for actions) or IItemActionBehavior (for item actions)
/// interface. Corresponds to action.behaviorType in YAML
/// </summary>
public enum BehaviorType
{
/// <summary>
/// Action doesn't do anything.
/// </summary>
None,
/// <summary>
/// IInstantAction/IInstantItemAction. Action which does something immediately when used and has
/// no target.
/// </summary>
Instant,
/// <summary>
/// IToggleAction/IToggleItemAction Action which can be toggled on and off
/// </summary>
Toggle,
/// <summary>
/// ITargetEntityAction/ITargetEntityItemAction. Action which is used on a targeted entity.
/// </summary>
TargetEntity,
/// <summary>
/// ITargetPointAction/ITargetPointItemAction. Action which requires the user to select a target point, which
/// does not necessarily have an entity on it.
/// </summary>
TargetPoint
}
}

View File

@@ -0,0 +1,126 @@
#nullable enable
using Content.Shared.Actions.Behaviors;
using Content.Shared.Actions.Behaviors.Item;
using Content.Shared.Module;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Shared.Actions.Prototypes
{
/// <summary>
/// An action which is granted to an entity via an item (such as toggling a flashlight).
/// </summary>
[Prototype("itemAction")]
[DataDefinition]
public class ItemActionPrototype : BaseActionPrototype, ISerializationHooks
{
/// <summary>
/// Type of item action, no 2 itemAction prototypes should have the same one.
/// </summary>
[DataField("actionType")]
public ItemActionType ActionType { get; private set; } = ItemActionType.Error;
/// <see cref="ItemActionIconStyle"/>
[DataField("iconStyle")]
public ItemActionIconStyle IconStyle { get; private set; } = ItemActionIconStyle.BigItem;
/// <summary>
/// The IInstantItemAction that should be invoked when performing this
/// action. Null if this is not an Instant ActionBehaviorType.
/// Will be null on client side if the behavior is not in Content.Client.
/// </summary>
public IInstantItemAction InstantAction { get; private set; } = default!;
/// <summary>
/// The IToggleItemAction that should be invoked when performing this
/// action. Null if this is not a Toggle ActionBehaviorType.
/// Will be null on client side if the behavior is not in Content.Client.
/// </summary>
public IToggleItemAction ToggleAction { get; private set; } = default!;
/// <summary>
/// The ITargetEntityItemAction that should be invoked when performing this
/// action. Null if this is not a TargetEntity ActionBehaviorType.
/// Will be null on client side if the behavior is not in Content.Client.
/// </summary>
public ITargetEntityItemAction TargetEntityAction { get; private set; } = default!;
/// <summary>
/// The ITargetPointItemAction that should be invoked when performing this
/// action. Null if this is not a TargetPoint ActionBehaviorType.
/// Will be null on client side if the behavior is not in Content.Client.
/// </summary>
public ITargetPointItemAction TargetPointAction { get; private set; } = default!;
[DataField("behavior", readOnly: true, serverOnly: true)]
public IItemActionBehavior? ItemActionBehavior { get; private set; }
public override string ID => ActionType.ToString();
public override void AfterDeserialization()
{
base.AfterDeserialization();
if (ActionType == ItemActionType.Error)
{
Logger.ErrorS("action", "missing or invalid actionType for action with name {0}", Name);
}
// TODO: Split this class into server/client after RobustToolbox#1405
if (IoCManager.Resolve<IModuleManager>().IsClientModule) return;
switch (ItemActionBehavior)
{
case null:
BehaviorType = BehaviorType.None;
Logger.ErrorS("action", "missing or invalid behavior for action with name {0}", Name);
break;
case IInstantItemAction instantAction:
ValidateBehaviorType(BehaviorType.Instant, typeof(IInstantItemAction));
BehaviorType = BehaviorType.Instant;
InstantAction = instantAction;
break;
case IToggleItemAction toggleAction:
ValidateBehaviorType(BehaviorType.Toggle, typeof(IToggleItemAction));
BehaviorType = BehaviorType.Toggle;
ToggleAction = toggleAction;
break;
case ITargetEntityItemAction targetEntity:
ValidateBehaviorType(BehaviorType.TargetEntity, typeof(ITargetEntityItemAction));
BehaviorType = BehaviorType.TargetEntity;
TargetEntityAction = targetEntity;
break;
case ITargetPointItemAction targetPointAction:
ValidateBehaviorType(BehaviorType.TargetPoint, typeof(ITargetPointItemAction));
BehaviorType = BehaviorType.TargetPoint;
TargetPointAction = targetPointAction;
break;
default:
BehaviorType = BehaviorType.None;
Logger.ErrorS("action", "unrecognized behavior type for action with name {0}", Name);
break;
}
}
}
/// <summary>
/// Determines how the action icon appears in the hotbar for item actions.
/// </summary>
public enum ItemActionIconStyle : byte
{
/// <summary>
/// The default - the item icon will be big with a small action icon in the corner
/// </summary>
BigItem,
/// <summary>
/// The action icon will be big with a small item icon in the corner
/// </summary>
BigAction,
/// <summary>
/// BigAction but no item icon will be shown in the corner.
/// </summary>
NoItem
}
}