Files
tbd-station-14/Content.Server/Solar/Components/SolarControlConsoleComponent.cs
20kdc a2f5c953dc Refactoring of solar control console (#4072)
* Refactor/fix client-side of solar control computer (introduce ComputerBoundUserInterface & fix bugs)

* Refactor server side of solar control computer (introduce BaseComputerUserInterfaceComponent)

* If you can't interact, then messages to computers are blocked.

* Add 'not powered' messages, migrate activation logic partially to an EntitySystem

* Move solar control console to a XAML UI

* Remove useless comment on UserInterfaceKey

* BaseComputerUserInterfaceComponent: Remove EnsureComponent<PowerReceiver>, it's not necessary

* Fix solar panel occlusion check direction

* Solar Control Console refactors/etc. : Handle namespace renames
2021-06-17 00:49:02 +10: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) { }
public 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;
}
}
}
}