Files
tbd-station-14/Content.Server/GameObjects/Components/Rotatable/RotatableComponent.cs
Acruid ca4fd649fe Massive Namespace Cleanup (#3120)
* Engine namespace changes.

* Automated remove redundant using statements.

* Simplified Graphics namespace.

* Apparently the container system stores full type names in the map file.😞 This updates those names.

* API Changes to LocalizationManager.LoadCulture.

* Update submodule to v0.3.2
2021-02-11 01:13:03 -08:00

89 lines
3.2 KiB
C#

using Content.Shared.GameObjects.EntitySystems.ActionBlocker;
using Content.Shared.GameObjects.Verbs;
using Content.Shared.Interfaces;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Rotatable
{
[RegisterComponent]
public class RotatableComponent : Component
{
public override string Name => "Rotatable";
/// <summary>
/// If true, this entity can be rotated even while anchored.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public bool RotateWhileAnchored { get; private set; }
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(this, x => x.RotateWhileAnchored, "rotateWhileAnchored", false);
}
private void TryRotate(IEntity user, Angle angle)
{
if (!RotateWhileAnchored && Owner.TryGetComponent(out IPhysicsComponent physics))
{
if (physics.Anchored)
{
Owner.PopupMessage(user, Loc.GetString("It's stuck."));
return;
}
}
Owner.Transform.LocalRotation += angle;
}
[Verb]
public sealed class RotateVerb : Verb<RotatableComponent>
{
protected override void GetData(IEntity user, RotatableComponent component, VerbData data)
{
if (!ActionBlockerSystem.CanInteract(user) || (!component.RotateWhileAnchored && component.Owner.TryGetComponent(out IPhysicsComponent physics) && physics.Anchored))
{
data.Visibility = VerbVisibility.Invisible;
return;
}
data.CategoryData = VerbCategories.Rotate;
data.Text = Loc.GetString("Rotate clockwise");
data.IconTexture = "/Textures/Interface/VerbIcons/rotate_cw.svg.96dpi.png";
}
protected override void Activate(IEntity user, RotatableComponent component)
{
component.TryRotate(user, Angle.FromDegrees(-90));
}
}
[Verb]
public sealed class RotateCounterVerb : Verb<RotatableComponent>
{
protected override void GetData(IEntity user, RotatableComponent component, VerbData data)
{
if (!ActionBlockerSystem.CanInteract(user) || (!component.RotateWhileAnchored && component.Owner.TryGetComponent(out IPhysicsComponent physics) && physics.Anchored))
{
data.Visibility = VerbVisibility.Invisible;
return;
}
data.CategoryData = VerbCategories.Rotate;
data.Text = Loc.GetString("Rotate counter-clockwise");
data.IconTexture = "/Textures/Interface/VerbIcons/rotate_ccw.svg.96dpi.png";
}
protected override void Activate(IEntity user, RotatableComponent component)
{
component.TryRotate(user, Angle.FromDegrees(90));
}
}
}
}