mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 18:31:17 +03:00
* Refactor DeviceNetwork * Singleton * NetworkPayloads refactor * Reorganize DeviceNetworkSystem * Surveillance cameras * Fix code * Fix build * Fix test fail by rewriting entire singleton logic * Properly predict examine * Update DeviceNetworkSystem.API.cs * Update EntityTest.cs * Update DeviceNetworkSystem.cs * Alright I'll do this expensive check fine * Fix disposals debug assert * Implement device network static events support * Use frozen dictionaries for performance * Update SharedDeviceNetworkSystem.Payloads.cs * Parallel payload handling support * Fix some spagetti-code * Optimize NetworkPayload cancellation * Parallel payloads are now cancellable * Fix screens * Fix robotics console * Allow new methods for shared * Mail fix * Turret fix * Fix network system method usage + signal and borg fix * finally fix atmos devices OH MY GOOOD * Remove stupid parallelism from fax * Fix surveiollance cameras * Working on a single thing for 2 days straight award * Fix the test? * Update units.yml * Add IDevice interface because why not * Add more device network suffixes * Fix camera router failing test * yaml linter peak * Improve docs for DeviceNetworkHandlers * fix build * Update CartridgeLoaderSystem.Relay.cs * Remove parallel system and EntitySystem post init * Add more docs and also events * Remove unnecessary caching * Update DevicePayloadComponentSystem.cs * Back to entity events * Implement DeviceData * Remove serializable from payloads * Update DeviceData.cs * Add a prototype for a singleton * Fix tests * Fix air alarms * Update DeviceNetworkSystem.cs * Fix cameras * Make camera router event-less * Fix atmos sync payloads, add more docs * Remove singleton + instant packets * oops remove public access * Fix tests? * Why the hell overload effect makes puddle sparks * Apparently it was redundant * Update gates.yml * Finish documentation * Review * Mark relay properties as obsolete * Struct payloads support (#blazinglyfastmemorysafe) * Update DeviceNetworkTest.cs * Make device structs stuff better * Move address prefix to DeviceNetworkComponent * Locale fixes * Fix tests * Doesn't know boolean logic award * Update AtmosAlarmableSystem.cs * Fix address predicted examine * Partial fix to air alarmables * Fix deployable turrets UI * Fix firelocks, maybe * Apparently Activatable UI was enough lol * Fix surveillance cameras * Rename `QueuePacket` into `SendPacket` * Simplify DeviceData as much as possible * Update DeviceData.cs * Update FaxMachineComponent.cs * Remove DeviceData because its stupid * Update ScreenSystem.cs * Fix build (camera map broken still) * Fix map * fix usings * Review changes * Build fix
146 lines
4.9 KiB
C#
146 lines
4.9 KiB
C#
using Content.Shared.Configurable;
|
|
using Content.Shared.DeviceNetwork.Components;
|
|
using Content.Shared.DeviceNetwork.Events;
|
|
using Content.Shared.DeviceNetwork.Systems;
|
|
using Content.Shared.Disposal.Components;
|
|
using Content.Shared.Disposal.Unit;
|
|
using Content.Shared.Interaction;
|
|
using Robust.Shared.Player;
|
|
|
|
namespace Content.Shared.Disposal.Mailing;
|
|
|
|
public abstract partial class SharedMailingUnitSystem : EntitySystem
|
|
{
|
|
[Dependency] private SharedDeviceNetworkSystem _deviceNetwork = default!;
|
|
[Dependency] private SharedUserInterfaceSystem _userInterface = default!;
|
|
|
|
private const string MailTag = "mail";
|
|
private const string TagConfigurationKey = "tag";
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<MailingUnitComponent, ComponentInit>(OnComponentInit);
|
|
SubscribeLocalEvent<MailingUnitComponent, BeforeDisposalFlushEvent>(OnBeforeFlush);
|
|
SubscribeLocalEvent<MailingUnitComponent, ConfigurationUpdatedEvent>(OnConfigurationUpdated);
|
|
SubscribeLocalEvent<MailingUnitComponent, ActivateInWorldEvent>(HandleActivate, before: new[] { typeof(SharedDisposalUnitSystem) });
|
|
SubscribeLocalEvent<MailingUnitComponent, TargetSelectedMessage>(OnTargetSelected);
|
|
}
|
|
|
|
private void OnComponentInit(Entity<MailingUnitComponent> ent, ref ComponentInit args)
|
|
{
|
|
UpdateTargetList(ent);
|
|
}
|
|
|
|
[SubscribeLocalEvent]
|
|
private void OnRequestTag(Entity<MailingUnitComponent> ent, ref DeviceNetworkPacketEvent<MailRequestTagPayload> args)
|
|
{
|
|
if (ent.Comp.Tag == null)
|
|
return;
|
|
|
|
var tagPayload = new MailTagPayload
|
|
{
|
|
Tag = ent.Comp.Tag,
|
|
};
|
|
|
|
_deviceNetwork.SendPacket(ent.Owner, args.SenderAddress, ref tagPayload, args.Frequency);
|
|
}
|
|
|
|
[SubscribeLocalEvent]
|
|
private void OnTag(Entity<MailingUnitComponent> ent, ref DeviceNetworkPacketEvent<MailTagPayload> args)
|
|
{
|
|
ent.Comp.TargetList.Add(args.Data.Tag);
|
|
Dirty(ent);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Prevents the unit from flushing if no target is selected
|
|
/// </summary>
|
|
private void OnBeforeFlush(Entity<MailingUnitComponent> ent, ref BeforeDisposalFlushEvent args)
|
|
{
|
|
if (string.IsNullOrEmpty(ent.Comp.Target))
|
|
{
|
|
args.Cancel();
|
|
return;
|
|
}
|
|
|
|
Dirty(ent);
|
|
args.Tags.Add(MailTag);
|
|
args.Tags.Add(ent.Comp.Target);
|
|
|
|
BroadcastSentMessage(ent);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Broadcast that a mail was sent including the src and target tags
|
|
/// </summary>
|
|
private void BroadcastSentMessage(Entity<MailingUnitComponent> ent, DeviceNetworkComponent? device = null)
|
|
{
|
|
if (string.IsNullOrEmpty(ent.Comp.Tag) || string.IsNullOrEmpty(ent.Comp.Target) || !Resolve(ent, ref device))
|
|
return;
|
|
|
|
var payload = new MailSendPayload
|
|
{
|
|
Tag = ent.Comp.Tag,
|
|
Target = ent.Comp.Target,
|
|
};
|
|
|
|
_deviceNetwork.SendPacket((ent.Owner, device), null, ref payload);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Clears the units target list and broadcasts a <see cref="MailRequestTagPayload"/>.
|
|
/// The target list will then get populated with <see cref="MailTagPayload"/> responses from all active mailing units on the same grid
|
|
/// </summary>
|
|
private void UpdateTargetList(Entity<MailingUnitComponent> ent, DeviceNetworkComponent? device = null)
|
|
{
|
|
if (!Resolve(ent, ref device, false))
|
|
return;
|
|
|
|
var payload = new MailRequestTagPayload();
|
|
ent.Comp.TargetList.Clear();
|
|
_deviceNetwork.SendPacket((ent.Owner, device), null, ref payload);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets called when the units tag got updated
|
|
/// </summary>
|
|
private void OnConfigurationUpdated(Entity<MailingUnitComponent> ent, ref ConfigurationUpdatedEvent args)
|
|
{
|
|
var configuration = args.Configuration.Config;
|
|
if (!configuration.ContainsKey(TagConfigurationKey) || configuration[TagConfigurationKey] == string.Empty)
|
|
{
|
|
ent.Comp.Tag = null;
|
|
return;
|
|
}
|
|
|
|
ent.Comp.Tag = configuration[TagConfigurationKey];
|
|
Dirty(ent);
|
|
}
|
|
|
|
private void HandleActivate(Entity<MailingUnitComponent> ent, ref ActivateInWorldEvent args)
|
|
{
|
|
if (args.Handled || !args.Complex)
|
|
return;
|
|
|
|
if (!TryComp(args.User, out ActorComponent? actor))
|
|
return;
|
|
|
|
args.Handled = true;
|
|
UpdateTargetList(ent);
|
|
|
|
_userInterface.OpenUi(ent.Owner, MailingUnitUiKey.Key, actor.PlayerSession);
|
|
}
|
|
|
|
private void OnTargetSelected(Entity<MailingUnitComponent> ent, ref TargetSelectedMessage args)
|
|
{
|
|
ent.Comp.Target = args.Target;
|
|
Dirty(ent);
|
|
|
|
if (_userInterface.TryGetOpenUi(ent.Owner, MailingUnitUiKey.Key, out var bui))
|
|
{
|
|
bui.Update<MailingUnitBoundUserInterfaceState>();
|
|
}
|
|
}
|
|
}
|