using Content.Shared.Interaction; namespace Content.Shared.CartridgeLoader; public sealed partial class CartridgeLoaderSystem { private void InitializeRelay() { SubscribeLocalEvent(RelayEvent); SubscribeLocalEvent(RelayEvent); } private void RefRelayEvent(EntityUid uid, CartridgeLoaderComponent component, ref T args) where T : struct { RefRelayEvent((uid, component), ref args); } private void RelayEvent(EntityUid uid, CartridgeLoaderComponent component, T args) where T : class { RelayEvent((uid, component), args); } public void RefRelayEvent(Entity ent, ref T args, bool foregroundOnly = false) where T : struct { var ev = new CartridgeRelayedEvent(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(Entity ent, T args, bool foregroundOnly = false) where T : class { var ev = new CartridgeRelayedEvent(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); } } } /// /// Event wrapper for relayed events. /// [ByRefEvent] public record struct CartridgeRelayedEvent(Entity Loader, TEvent Args);