Files
tbd-station-14/Content.Server/Rotatable/RotatableSystem.cs
TemporalOroboros f284b43ff6 Fixes obsolete Transform warnings in Content. (#25256)
* Fix TransformComponent.MapPosition warnings in Content.Client

* Fix TransformComponent.MapPosition warnings in Content.IntegrationTests

* Fix TransformComponent.MapPosition warnings in Content.Shared

* Fix TransformComponent.MapPosition warnings in Content.Server

* Fix TransformComponent.WorldPosition warnings in Content.Shared

* Fix TransformComponent.WorldPosition warnings in Content.Client
Excepts ClickableComponent b/c that needs to be ECS'd entirely later

* Fix TransformComponent.WorldPosition warnings in Content.Server

* Fix TransformComponent.WorldRotation warnings in Content.*

* Fix TransformComponent.MapPosition warnings I missed

* Fix TransformComponent.WorldMatrix warnings in Content.*

* Fix TransformComponent.InvWorldMatrix warnings in Content.*

* Fix TransformComponent.GetWorldPositionRotationMatrixWithInv warnings in Content.*

* Fix TransformComponent.GetWorldPositionRotationMatrix warnings in Content.*

* Fix TransformComponent.GetWorldPositionRotation warnings in Content.*

* Fix TransformComponent.Anchored.set warnings in Content.*

* Fix TransformComponent.Coordinates.set warnings in Content.*

* Fix TransformComponent.LocalPosition.set warnings in Content.*

* Fix TransformComponent.AttachToGridOrMap warnings in Content.*

* Fix TransformComponent.AttachParent warnings in Content.*

* Preempt TransformComponent.LocalRotation.set warnings in Content.Shared

* Preempt TransformComponent.LocalRotation.set warnings in Content.Client

* Preempt TransformComponent.LocalRotation.set warnings in Content.IntegrationTests

* Preempt TransformComponent.LocalRotation.set warnings in Content.Server

* Fix/Preempt the remaining obsolete TransformComponent properties/methods in Content.*

* ECS ClickableComponent

* Fix obsolete SharedTransformSystem methods in Content.*

* Fix ExplosionOverlay `SharedTransformSystem` dependency

* Maybe fix null eye position breaking tests

* MGS requested changes
2024-02-27 12:06:20 +11:00

119 lines
4.8 KiB
C#

using Content.Server.Popups;
using Content.Shared.Popups;
using Content.Shared.Rotatable;
using Content.Shared.Verbs;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Utility;
namespace Content.Server.Rotatable
{
/// <summary>
/// Handles verbs for the <see cref="RotatableComponent"/> and <see cref="FlippableComponent"/> components.
/// </summary>
public sealed class RotatableSystem : EntitySystem
{
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly SharedTransformSystem _xformSystem = default!;
public override void Initialize()
{
SubscribeLocalEvent<FlippableComponent, GetVerbsEvent<Verb>>(AddFlipVerb);
SubscribeLocalEvent<RotatableComponent, GetVerbsEvent<Verb>>(AddRotateVerbs);
}
private void AddFlipVerb(EntityUid uid, FlippableComponent component, GetVerbsEvent<Verb> args)
{
if (!args.CanAccess || !args.CanInteract)
return;
Verb verb = new()
{
Act = () => TryFlip(uid, component, args.User),
Text = Loc.GetString("flippable-verb-get-data-text"),
Category = VerbCategory.Rotate,
Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/flip.svg.192dpi.png")),
Priority = -3, // show flip last
DoContactInteraction = true
};
args.Verbs.Add(verb);
}
private void AddRotateVerbs(EntityUid uid, RotatableComponent component, GetVerbsEvent<Verb> args)
{
if (!args.CanAccess
|| !args.CanInteract
|| Transform(uid).NoLocalRotation) // Good ol prototype inheritance, eh?
return;
// Check if the object is anchored, and whether we are still allowed to rotate it.
if (!component.RotateWhileAnchored &&
EntityManager.TryGetComponent(uid, out PhysicsComponent? physics) &&
physics.BodyType == BodyType.Static)
return;
Verb resetRotation = new ()
{
DoContactInteraction = true,
Act = () => _xformSystem.SetLocalRotation(uid, Angle.Zero),
Category = VerbCategory.Rotate,
Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/refresh.svg.192dpi.png")),
Text = "Reset",
Priority = -2, // show CCW, then CW, then reset
CloseMenu = false,
};
args.Verbs.Add(resetRotation);
// rotate clockwise
Verb rotateCW = new()
{
Act = () =>
{
var xform = Transform(uid);
_xformSystem.SetLocalRotation(uid, xform.LocalRotation - component.Increment, xform);
},
Category = VerbCategory.Rotate,
Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/rotate_cw.svg.192dpi.png")),
Priority = -1,
CloseMenu = false, // allow for easy double rotations.
};
args.Verbs.Add(rotateCW);
// rotate counter-clockwise
Verb rotateCCW = new()
{
Act = () =>
{
var xform = Transform(uid);
_xformSystem.SetLocalRotation(uid, xform.LocalRotation + component.Increment, xform);
},
Category = VerbCategory.Rotate,
Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/rotate_ccw.svg.192dpi.png")),
Priority = 0,
CloseMenu = false, // allow for easy double rotations.
};
args.Verbs.Add(rotateCCW);
}
/// <summary>
/// Replace a flippable entity with it's flipped / mirror-symmetric entity.
/// </summary>
public void TryFlip(EntityUid uid, FlippableComponent component, EntityUid user)
{
if (EntityManager.TryGetComponent(uid, out PhysicsComponent? physics) &&
physics.BodyType == BodyType.Static)
{
_popup.PopupEntity(Loc.GetString("flippable-component-try-flip-is-stuck"), uid, user);
return;
}
var oldTransform = EntityManager.GetComponent<TransformComponent>(uid);
var entity = EntityManager.SpawnEntity(component.MirrorEntity, oldTransform.Coordinates);
var newTransform = EntityManager.GetComponent<TransformComponent>(entity);
_xformSystem.SetLocalRotation(entity, oldTransform.LocalRotation, newTransform);
_xformSystem.Unanchor(entity, newTransform);
EntityManager.DeleteEntity(uid);
}
}
}