* Add test that puts all components on an entity and checks for no exceptions Also fix all the exceptions that happened because of this * Add comments to the test * Fix nullable errors * Fix more nullable errors * More nullable error fixes * Unignore basic actor component * Fix more nullable errors * NULLABLE ERROR * Add string interpolation * Merge if checks * Remove redundant pragma warning disable 649 * Address reviews * Remove null wrappers around TryGetComponent * Merge conflict fixes * APC battery component error fix * Fix power test * Fix atmos mapgrid usages
84 lines
3.0 KiB
C#
84 lines
3.0 KiB
C#
#nullable enable
|
|
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
|
|
using Content.Server.GameObjects.EntitySystems;
|
|
using Content.Shared.GameObjects.Components.Power;
|
|
using Content.Shared.Interfaces.GameObjects.Components;
|
|
using Robust.Server.GameObjects.Components.UserInterface;
|
|
using Robust.Server.Interfaces.GameObjects;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Interfaces.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
namespace Content.Server.GameObjects.Components.Power.PowerNetComponents
|
|
{
|
|
[RegisterComponent]
|
|
[ComponentReference(typeof(IActivate))]
|
|
public class SolarControlConsoleComponent : SharedSolarControlConsoleComponent, IActivate
|
|
{
|
|
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
|
|
|
|
private PowerSolarSystem _powerSolarSystem = default!;
|
|
private bool Powered => !Owner.TryGetComponent(out PowerReceiverComponent? receiver) || receiver.Powered;
|
|
|
|
[ViewVariables]
|
|
private BoundUserInterface? UserInterface =>
|
|
Owner.TryGetComponent(out ServerUserInterfaceComponent? ui) &&
|
|
ui.TryGetBoundUserInterface(SolarControlConsoleUiKey.Key, out var boundUi)
|
|
? boundUi
|
|
: null;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
if (UserInterface != null)
|
|
{
|
|
UserInterface.OnReceiveMessage += UserInterfaceOnReceiveMessage;
|
|
}
|
|
|
|
Owner.EnsureComponent<PowerReceiverComponent>();
|
|
_powerSolarSystem = _entitySystemManager.GetEntitySystem<PowerSolarSystem>();
|
|
}
|
|
|
|
public void UpdateUIState()
|
|
{
|
|
UserInterface?.SetState(new SolarControlConsoleBoundInterfaceState(_powerSolarSystem.TargetPanelRotation, _powerSolarSystem.TargetPanelVelocity, _powerSolarSystem.TotalPanelPower, _powerSolarSystem.TowardsSun));
|
|
}
|
|
|
|
private void UserInterfaceOnReceiveMessage(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;
|
|
}
|
|
}
|
|
|
|
void IActivate.Activate(ActivateEventArgs eventArgs)
|
|
{
|
|
if (!eventArgs.User.TryGetComponent(out IActorComponent? actor))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!Powered)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// always update the UI immediately before opening, just in case
|
|
UpdateUIState();
|
|
UserInterface?.Open(actor.playerSession);
|
|
}
|
|
}
|
|
}
|