2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Solar.Components;
|
2021-11-23 18:19:08 +00:00
|
|
|
using Content.Server.UserInterface;
|
|
|
|
|
using Content.Shared.Solar;
|
2020-06-02 12:32:18 +01:00
|
|
|
using JetBrains.Annotations;
|
2023-07-08 09:02:17 -07:00
|
|
|
using Robust.Server.GameObjects;
|
2020-06-02 12:32:18 +01:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Solar.EntitySystems
|
2020-06-02 12:32:18 +01:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Responsible for updating solar control consoles.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[UsedImplicitly]
|
2020-08-13 22:17:12 +10:00
|
|
|
internal sealed class PowerSolarControlConsoleSystem : EntitySystem
|
2020-06-02 12:32:18 +01:00
|
|
|
{
|
2023-07-08 09:02:17 -07:00
|
|
|
[Dependency] private readonly PowerSolarSystem _powerSolarSystem = default!;
|
|
|
|
|
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
|
2021-11-23 18:19:08 +00:00
|
|
|
|
2020-06-02 12:32:18 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Timer used to avoid updating the UI state every frame (which would be overkill)
|
|
|
|
|
/// </summary>
|
2020-08-13 22:17:12 +10:00
|
|
|
private float _updateTimer;
|
2020-06-02 12:32:18 +01:00
|
|
|
|
2021-11-23 18:19:08 +00:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2021-11-24 20:51:43 +00:00
|
|
|
SubscribeLocalEvent<SolarControlConsoleComponent, SolarControlConsoleAdjustMessage>(OnUIMessage);
|
2021-11-23 18:19:08 +00:00
|
|
|
}
|
|
|
|
|
|
2020-06-02 12:32:18 +01:00
|
|
|
public override void Update(float frameTime)
|
|
|
|
|
{
|
2020-08-13 22:17:12 +10:00
|
|
|
_updateTimer += frameTime;
|
|
|
|
|
if (_updateTimer >= 1)
|
2020-06-02 12:32:18 +01:00
|
|
|
{
|
2020-08-13 22:17:12 +10:00
|
|
|
_updateTimer -= 1;
|
2021-11-23 18:19:08 +00:00
|
|
|
var state = new SolarControlConsoleBoundInterfaceState(_powerSolarSystem.TargetPanelRotation, _powerSolarSystem.TargetPanelVelocity, _powerSolarSystem.TotalPanelPower, _powerSolarSystem.TowardsSun);
|
2023-09-11 21:20:46 +10:00
|
|
|
var query = EntityQueryEnumerator<SolarControlConsoleComponent, UserInterfaceComponent>();
|
2023-07-08 09:02:17 -07:00
|
|
|
while (query.MoveNext(out var uid, out var _, out var uiComp))
|
2020-06-02 12:32:18 +01:00
|
|
|
{
|
2023-07-08 09:02:17 -07:00
|
|
|
_uiSystem.TrySetUiState(uid, SolarControlConsoleUiKey.Key, state, ui: uiComp);
|
2020-06-02 12:32:18 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-23 18:19:08 +00:00
|
|
|
|
2021-11-24 20:51:43 +00:00
|
|
|
private void OnUIMessage(EntityUid uid, SolarControlConsoleComponent component, SolarControlConsoleAdjustMessage msg)
|
2021-11-23 18:19:08 +00:00
|
|
|
{
|
2021-11-24 20:51:43 +00:00
|
|
|
if (double.IsFinite(msg.Rotation))
|
2021-11-23 18:19:08 +00:00
|
|
|
{
|
2021-11-24 20:51:43 +00:00
|
|
|
_powerSolarSystem.TargetPanelRotation = msg.Rotation.Reduced();
|
|
|
|
|
}
|
|
|
|
|
if (double.IsFinite(msg.AngularVelocity))
|
|
|
|
|
{
|
|
|
|
|
var degrees = msg.AngularVelocity.Degrees;
|
|
|
|
|
degrees = Math.Clamp(degrees, -PowerSolarSystem.MaxPanelVelocityDegrees, PowerSolarSystem.MaxPanelVelocityDegrees);
|
|
|
|
|
_powerSolarSystem.TargetPanelVelocity = Angle.FromDegrees(degrees);
|
2021-11-23 18:19:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-02 12:32:18 +01:00
|
|
|
}
|
|
|
|
|
}
|