CatStation/Content.Shared/DeviceLinking/Systems/SharedRandomGateSystem.cs
Pieter-Jan Briers 5168b5f3d4
IoC source gen compatibility (#43863)
* IoC source gen compatibility

Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter.

* Missed a spot
2026-05-09 03:29:58 +00:00

35 lines
1.2 KiB
C#

using Content.Shared.DeviceLinking.Components;
using Content.Shared.UserInterface;
namespace Content.Shared.DeviceLinking.Systems;
public abstract partial class SharedRandomGateSystem : EntitySystem
{
[Dependency] private SharedUserInterfaceSystem _ui = default!;
public override void Initialize()
{
SubscribeLocalEvent<RandomGateComponent, AfterActivatableUIOpenEvent>(OnAfterActivatableUIOpen);
SubscribeLocalEvent<RandomGateComponent, RandomGateProbabilityChangedMessage>(OnProbabilityChanged);
}
private void OnAfterActivatableUIOpen(Entity<RandomGateComponent> ent, ref AfterActivatableUIOpenEvent args)
{
UpdateUI(ent);
}
private void OnProbabilityChanged(Entity<RandomGateComponent> ent, ref RandomGateProbabilityChangedMessage args)
{
ent.Comp.SuccessProbability = Math.Clamp(args.Probability, 0f, 100f) / 100f;
Dirty(ent);
UpdateUI(ent);
}
private void UpdateUI(Entity<RandomGateComponent> ent)
{
if (!_ui.HasUi(ent.Owner, RandomGateUiKey.Key))
return;
_ui.SetUiState(ent.Owner, RandomGateUiKey.Key, new RandomGateBoundUserInterfaceState(ent.Comp.SuccessProbability));
}
}