From 4720353fa2f15e4e8472b873fabdc60ffdc640c9 Mon Sep 17 00:00:00 2001 From: DamianX Date: Wed, 6 Nov 2019 17:22:26 +0100 Subject: [PATCH] Basic rotatable component (#416) * Basic rotatable component * Added counter-clockwise verb * RegisterIgnore --- Content.Client/EntryPoint.cs | 1 + .../Components/RotatableComponent.cs | 74 +++++++++++++++++++ .../Entities/buildings/furniture.yml | 2 + .../Entities/buildings/vending_machines.yml | 3 + 4 files changed, 80 insertions(+) create mode 100644 Content.Server/GameObjects/Components/RotatableComponent.cs diff --git a/Content.Client/EntryPoint.cs b/Content.Client/EntryPoint.cs index 23be4fd207..3acda3a4fb 100644 --- a/Content.Client/EntryPoint.cs +++ b/Content.Client/EntryPoint.cs @@ -111,6 +111,7 @@ namespace Content.Client "MedicalScanner", "WirePlacer", "Species", + "Rotatable", }; foreach (var ignoreName in registerIgnore) diff --git a/Content.Server/GameObjects/Components/RotatableComponent.cs b/Content.Server/GameObjects/Components/RotatableComponent.cs new file mode 100644 index 0000000000..5150f9ad8a --- /dev/null +++ b/Content.Server/GameObjects/Components/RotatableComponent.cs @@ -0,0 +1,74 @@ +using Content.Server.Interfaces; +using Content.Shared.GameObjects; +using Robust.Server.GameObjects; +using Robust.Shared.GameObjects; +using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.IoC; +using Robust.Shared.Localization; +using Robust.Shared.Maths; + +namespace Content.Server.GameObjects.Components +{ + [RegisterComponent] + public class RotatableComponent : Component + { +#pragma warning disable 649 + [Dependency] private readonly IServerNotifyManager _notifyManager; + [Dependency] private readonly ILocalizationManager _localizationManager; +#pragma warning restore 649 + public override string Name => "Rotatable"; + + private void TryRotate(IEntity user, Angle angle) + { + if (Owner.TryGetComponent(out PhysicsComponent physics)) + { + if (physics.Anchored) + { + _notifyManager.PopupMessage(Owner.Transform.GridPosition, user, _localizationManager.GetString("It's stuck.")); + return; + } + } + + Owner.Transform.LocalRotation += angle; + } + + [Verb] + public sealed class RotateVerb : Verb + { + protected override string GetText(IEntity user, RotatableComponent component) + { + return "Rotate clockwise"; + } + + protected override VerbVisibility GetVisibility(IEntity user, RotatableComponent component) + { + return VerbVisibility.Visible; + } + + protected override void Activate(IEntity user, RotatableComponent component) + { + component.TryRotate(user, Angle.FromDegrees(90)); + } + } + + [Verb] + public sealed class RotateCounterVerb : Verb + { + protected override string GetText(IEntity user, RotatableComponent component) + { + return "Rotate counter-clockwise"; + } + + protected override VerbVisibility GetVisibility(IEntity user, RotatableComponent component) + { + return VerbVisibility.Visible; + } + + protected override void Activate(IEntity user, RotatableComponent component) + { + component.TryRotate(user, Angle.FromDegrees(-90)); + } + } + + } +} diff --git a/Resources/Prototypes/Entities/buildings/furniture.yml b/Resources/Prototypes/Entities/buildings/furniture.yml index dac90cd29c..1415d4f688 100644 --- a/Resources/Prototypes/Entities/buildings/furniture.yml +++ b/Resources/Prototypes/Entities/buildings/furniture.yml @@ -16,6 +16,7 @@ name: White Office Chair id: chairOfficeLight components: + - type: Rotatable - type: Clickable - type: Collidable - type: Sprite @@ -29,6 +30,7 @@ name: Dark Office Chair id: chairOfficeDark components: + - type: Rotatable - type: Clickable - type: Collidable - type: Sprite diff --git a/Resources/Prototypes/Entities/buildings/vending_machines.yml b/Resources/Prototypes/Entities/buildings/vending_machines.yml index 97ca099aaf..7fdeef1614 100644 --- a/Resources/Prototypes/Entities/buildings/vending_machines.yml +++ b/Resources/Prototypes/Entities/buildings/vending_machines.yml @@ -2,6 +2,9 @@ id: VendingMachine name: vending machine components: + - type: Physics + Anchored: true + - type: Rotatable - type: Clickable - type: Sprite sprite: Buildings/VendingMachines/empty.rsi