Files
tbd-station-14/Content.Server/Solar/Components/SolarControlConsoleComponent.cs
Acruid 15fb554c28 Engine Entity Anchoring Changes (#4195)
* Converted all SnapGridPositionChangedEvent subscriptions to AnchorStateChangedEvent.

* Fixes power tests with new anchored requirements.

* Moved AnchorableComponent into construction.
AnchorableComponent now uses Transform.Anchored.

* Fixed bug with nodes, power works again.

* Adds lifetime stages to Component.

* Update Engine to v0.4.70.
2021-06-19 19:41:26 -07:00

54 lines
1.9 KiB
C#

#nullable enable
using Content.Shared.Solar;
using Content.Server.Solar.EntitySystems;
using Content.Server.GameObjects.Components;
using Content.Server.GameObjects.EntitySystems;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.ViewVariables;
namespace Content.Server.Solar.Components
{
[RegisterComponent]
[ComponentReference(typeof(BaseComputerUserInterfaceComponent))]
public class SolarControlConsoleComponent : BaseComputerUserInterfaceComponent
{
public override string Name => "SolarControlConsole";
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
private PowerSolarSystem _powerSolarSystem = default!;
public SolarControlConsoleComponent() : base(SolarControlConsoleUiKey.Key) { }
protected override void Initialize()
{
base.Initialize();
_powerSolarSystem = _entitySystemManager.GetEntitySystem<PowerSolarSystem>();
}
public void UpdateUIState()
{
UserInterface?.SetState(new SolarControlConsoleBoundInterfaceState(_powerSolarSystem.TargetPanelRotation, _powerSolarSystem.TargetPanelVelocity, _powerSolarSystem.TotalPanelPower, _powerSolarSystem.TowardsSun));
}
protected override void OnReceiveUserInterfaceMessage(ServerBoundUserInterfaceMessage obj)
{
switch (obj.Message)
{
case SolarControlConsoleAdjustMessage msg:
if (double.IsFinite(msg.Rotation))
{
_powerSolarSystem.TargetPanelRotation = msg.Rotation.Reduced();
}
if (double.IsFinite(msg.AngularVelocity))
{
_powerSolarSystem.TargetPanelVelocity = msg.AngularVelocity.Reduced();
}
break;
}
}
}
}