Files
tbd-station-14/Content.Shared/Actions/ActionPrototype.cs
Visne 9b94d5c195 Added nullable to most Content.Shared files (#3238)
* 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>
2021-02-27 14:12:09 +11:00

102 lines
4.4 KiB
C#

#nullable enable
using Content.Shared.Interfaces;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using YamlDotNet.RepresentationModel;
using Robust.Shared.Log;
namespace Content.Shared.Actions
{
/// <summary>
/// An action which is granted directly to an entity (such as an innate ability
/// or skill).
/// </summary>
[Prototype("action")]
public class ActionPrototype : BaseActionPrototype
{
/// <summary>
/// Type of action, no 2 action prototypes should have the same one.
/// </summary>
public ActionType ActionType { get; private 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 void LoadFrom(YamlMappingNode mapping)
{
base.LoadFrom(mapping);
var serializer = YamlObjectSerializer.NewReader(mapping);
serializer.DataField(this, x => x.ActionType, "actionType", ActionType.Error);
if (ActionType == ActionType.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;
IActionBehavior? behavior = null;
serializer.DataField(ref behavior, "behavior", null);
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;
}
}
}
}