From 70d2c7dba0d5ca8190942ede8b312ded9e0a9a2c Mon Sep 17 00:00:00 2001 From: Nagel Date: Tue, 1 Oct 2024 15:07:28 -0300 Subject: [PATCH] =?UTF-8?q?adaptando=20RotatableSystem.cs=20pras=20fun?= =?UTF-8?q?=C3=A7=C3=B5es=20de=20rotacionar=20n=C3=A3o=20precisarem=20cham?= =?UTF-8?q?ar=20SharedInterectionSystem=20que=20n=C3=A3o=20est=C3=A3o=20pr?= =?UTF-8?q?esentes=20no=20EE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Content.Server/Rotatable/RotatableSystem.cs | 74 +++++++++------------ 1 file changed, 30 insertions(+), 44 deletions(-) diff --git a/Content.Server/Rotatable/RotatableSystem.cs b/Content.Server/Rotatable/RotatableSystem.cs index 63b5e44c3d27..551027c17f38 100644 --- a/Content.Server/Rotatable/RotatableSystem.cs +++ b/Content.Server/Rotatable/RotatableSystem.cs @@ -1,15 +1,15 @@ using Content.Server.Popups; -using Content.Shared.ActionBlocker; -using Content.Shared.Input; -using Content.Shared.Interaction; +using Content.Shared.Popups; using Content.Shared.Rotatable; using Content.Shared.Verbs; -using Robust.Shared.Input.Binding; -using Robust.Shared.Map; -using Robust.Shared.Player; using Robust.Shared.Physics; using Robust.Shared.Physics.Components; using Robust.Shared.Utility; +using Robust.Shared.Map; +using Content.Shared.Input; +using Content.Shared.ActionBlocker; +using Robust.Shared.Input.Binding; +using Robust.Shared.Player; namespace Content.Server.Rotatable { @@ -20,7 +20,6 @@ public sealed class RotatableSystem : EntitySystem { [Dependency] private readonly PopupSystem _popup = default!; [Dependency] private readonly ActionBlockerSystem _actionBlocker = default!; - [Dependency] private readonly SharedInteractionSystem _interaction = default!; public override void Initialize() { @@ -39,16 +38,12 @@ private void AddFlipVerb(EntityUid uid, FlippableComponent component, GetVerbsEv if (!args.CanAccess || !args.CanInteract) return; - // Check if the object is anchored. - if (EntityManager.TryGetComponent(uid, out PhysicsComponent? physics) && physics.BodyType == BodyType.Static) - return; - Verb verb = new() { - Act = () => Flip(uid, component), + 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")), + Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/flip.svg.192dpi.png")), Priority = -3, // show flip last DoContactInteraction = true }; @@ -59,63 +54,47 @@ private void AddRotateVerbs(EntityUid uid, RotatableComponent component, GetVerb { if (!args.CanAccess || !args.CanInteract - || Transform(uid).NoLocalRotation) // Good ol prototype inheritance, eh? + || Transform(uid).NoLocalRotation) 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() + Verb resetRotation = new () { DoContactInteraction = true, Act = () => EntityManager.GetComponent(uid).LocalRotation = Angle.Zero, Category = VerbCategory.Rotate, - Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/refresh.svg.192dpi.png")), + Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/refresh.svg.192dpi.png")), Text = "Reset", - Priority = -2, // show CCW, then CW, then reset + Priority = -2, CloseMenu = false, }; args.Verbs.Add(resetRotation); - // rotate clockwise Verb rotateCW = new() { Act = () => EntityManager.GetComponent(uid).LocalRotation -= component.Increment, Category = VerbCategory.Rotate, - Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/rotate_cw.svg.192dpi.png")), + Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/rotate_cw.svg.192dpi.png")), Priority = -1, - CloseMenu = false, // allow for easy double rotations. + CloseMenu = false, }; args.Verbs.Add(rotateCW); - // rotate counter-clockwise Verb rotateCCW = new() { Act = () => EntityManager.GetComponent(uid).LocalRotation += component.Increment, Category = VerbCategory.Rotate, - Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/rotate_ccw.svg.192dpi.png")), + Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/rotate_ccw.svg.192dpi.png")), Priority = 0, - CloseMenu = false, // allow for easy double rotations. + CloseMenu = false, }; args.Verbs.Add(rotateCCW); } - /// - /// Replace a flippable entity with it's flipped / mirror-symmetric entity. - /// - public void Flip(EntityUid uid, FlippableComponent component) - { - var oldTransform = EntityManager.GetComponent(uid); - var entity = EntityManager.SpawnEntity(component.MirrorEntity, oldTransform.Coordinates); - var newTransform = EntityManager.GetComponent(entity); - newTransform.LocalRotation = oldTransform.LocalRotation; - newTransform.Anchored = false; - EntityManager.DeleteEntity(uid); - } - public bool HandleRotateObjectClockwise(ICommonSession? playerSession, EntityCoordinates coordinates, EntityUid entity) { if (playerSession?.AttachedEntity is not { Valid: true } player || !Exists(player)) @@ -124,10 +103,9 @@ public bool HandleRotateObjectClockwise(ICommonSession? playerSession, EntityCoo if (!TryComp(entity, out var rotatableComp)) return false; - if (!_actionBlocker.CanInteract(player, entity) || !_interaction.InRangeAndAccessible(player, entity)) + if (!_actionBlocker.CanInteract(player, entity)) return false; - // Check if the object is anchored, and whether we are still allowed to rotate it. if (!rotatableComp.RotateWhileAnchored && EntityManager.TryGetComponent(entity, out PhysicsComponent? physics) && physics.BodyType == BodyType.Static) { @@ -147,10 +125,9 @@ public bool HandleRotateObjectCounterclockwise(ICommonSession? playerSession, En if (!TryComp(entity, out var rotatableComp)) return false; - if (!_actionBlocker.CanInteract(player, entity) || !_interaction.InRangeAndAccessible(player, entity)) + if (!_actionBlocker.CanInteract(player, entity)) return false; - // Check if the object is anchored, and whether we are still allowed to rotate it. if (!rotatableComp.RotateWhileAnchored && EntityManager.TryGetComponent(entity, out PhysicsComponent? physics) && physics.BodyType == BodyType.Static) { @@ -170,18 +147,27 @@ public bool HandleFlipObject(ICommonSession? playerSession, EntityCoordinates co if (!TryComp(entity, out var flippableComp)) return false; - if (!_actionBlocker.CanInteract(player, entity) || !_interaction.InRangeAndAccessible(player, entity)) + if (!_actionBlocker.CanInteract(player, entity)) return false; - // Check if the object is anchored. if (EntityManager.TryGetComponent(entity, out PhysicsComponent? physics) && physics.BodyType == BodyType.Static) { _popup.PopupEntity(Loc.GetString("flippable-component-try-flip-is-stuck"), entity, player); return false; } - Flip(entity, flippableComp); + TryFlip(entity, flippableComp, player); return true; } + + public void TryFlip(EntityUid uid, FlippableComponent component, EntityUid user) + { + var oldTransform = EntityManager.GetComponent(uid); + var entity = EntityManager.SpawnEntity(component.MirrorEntity, oldTransform.Coordinates); + var newTransform = EntityManager.GetComponent(entity); + newTransform.LocalRotation = oldTransform.LocalRotation; + newTransform.Anchored = false; + EntityManager.DeleteEntity(uid); + } } }