CatStation/Content.Server/Power/Generator/PowerSwitchableSystem.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

76 lines
2.6 KiB
C#

using Content.Server.NodeContainer.EntitySystems;
using Content.Server.Popups;
using Content.Server.Power.Components;
using Content.Server.Power.Nodes;
using Content.Shared.NodeContainer;
using Content.Shared.Power;
using Content.Shared.Power.Generator;
using Content.Shared.Timing;
using Robust.Shared.Audio.Systems;
namespace Content.Server.Power.Generator;
/// <summary>
/// Implements server logic for power-switchable devices.
/// </summary>
/// <seealso cref="PowerSwitchableComponent"/>
/// <seealso cref="PortableGeneratorSystem"/>
/// <seealso cref="GeneratorSystem"/>
public sealed partial class PowerSwitchableSystem : SharedPowerSwitchableSystem
{
[Dependency] private NodeGroupSystem _nodeGroup = default!;
[Dependency] private PopupSystem _popup = default!;
[Dependency] private SharedAudioSystem _audio = default!;
[Dependency] private UseDelaySystem _useDelay = default!;
// TODO: Prediction
/// <inheritdoc/>
public override void Cycle(EntityUid uid, EntityUid user, PowerSwitchableComponent? comp = null)
{
if (!Resolve(uid, ref comp))
return;
// no sound spamming
if (!TryComp(uid, out UseDelayComponent? useDelay) || _useDelay.IsDelayed((uid, useDelay)))
return;
comp.ActiveIndex = NextIndex(uid, comp);
Dirty(uid, comp);
var voltage = GetVoltage(uid, comp);
if (TryComp<PowerSupplierComponent>(uid, out var supplier))
{
// convert to nodegroupid (goofy server Voltage enum is just alias for it)
switch (voltage)
{
case SwitchableVoltage.HV:
supplier.Voltage = Voltage.High;
break;
case SwitchableVoltage.MV:
supplier.Voltage = Voltage.Medium;
break;
case SwitchableVoltage.LV:
supplier.Voltage = Voltage.Apc;
break;
}
}
// Switching around the voltage on the power supplier is "enough",
// but we also want to disconnect the cable nodes so it doesn't show up in power monitors etc.
var nodeContainer = Comp<NodeContainerComponent>(uid);
foreach (var cable in comp.Cables)
{
var node = (CableDeviceNode) nodeContainer.Nodes[cable.Node];
node.Enabled = cable.Voltage == voltage;
_nodeGroup.QueueReflood(node);
}
var popup = Loc.GetString(comp.SwitchText, ("voltage", VoltageString(voltage)));
_popup.PopupEntity(popup, uid, user);
_audio.PlayPvs(comp.SwitchSound, uid);
_useDelay.TryResetDelay((uid, useDelay));
}
}