CatStation/Content.Shared/CartridgeLoader/CartridgeLoaderSystem.Relay.cs
pathetic meowmeow 09fb1b923f
Predict CartridgeLoader (#40302)
* Move CartridgeLoader to shared

* get containered bozo

* the dirtening

* mass shared the cartridges

* predict keb cartridges

* no overpopups

* the tidying continues

* review

* aaaaaa

* fix UI flickers

* dependency me

* mimed

* refactor: removed unused usings, dots at the end of old xml-doc,  additional in line-breaks

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
Co-authored-by: Fildrance <fildrance@gmail.com>
2026-07-05 14:13:20 +00:00

64 lines
2 KiB
C#

using Content.Shared.DeviceNetwork.Events;
using Content.Shared.Interaction;
namespace Content.Shared.CartridgeLoader;
public sealed partial class CartridgeLoaderSystem
{
private void InitializeRelay()
{
SubscribeLocalEvent<CartridgeLoaderComponent, AfterInteractEvent>(RelayEvent);
SubscribeLocalEvent<CartridgeLoaderComponent, InteractUsingEvent>(RelayEvent);
SubscribeLocalEvent<CartridgeLoaderComponent, DeviceNetworkPacketEvent>(RelayEvent);
}
private void RefRelayEvent<T>(EntityUid uid, CartridgeLoaderComponent component, ref T args) where T : struct
{
RefRelayEvent((uid, component), ref args);
}
private void RelayEvent<T>(EntityUid uid, CartridgeLoaderComponent component, T args) where T : class
{
RelayEvent((uid, component), args);
}
public void RefRelayEvent<T>(Entity<CartridgeLoaderComponent> ent, ref T args, bool foregroundOnly = false) where T : struct
{
var ev = new CartridgeRelayedEvent<T>(ent, args);
if (foregroundOnly)
{
if (ent.Comp.ActiveProgram is { } foreground)
RaiseLocalEvent(foreground, ref ev);
args = ev.Args;
return;
}
foreach (var program in GetAllPrograms(ent))
{
RaiseLocalEvent(program, ref ev);
}
args = ev.Args;
}
public void RelayEvent<T>(Entity<CartridgeLoaderComponent> ent, T args, bool foregroundOnly = false) where T : class
{
var ev = new CartridgeRelayedEvent<T>(ent, args);
if (foregroundOnly)
{
if (ent.Comp.ActiveProgram is { } foreground)
RaiseLocalEvent(foreground, ref ev);
return;
}
foreach (var program in GetAllPrograms(ent))
{
RaiseLocalEvent(program, ref ev);
}
}
}
/// <summary>
/// Event wrapper for relayed events.
/// </summary>
[ByRefEvent]
public record struct CartridgeRelayedEvent<TEvent>(Entity<CartridgeLoaderComponent> Loader, TEvent Args);