add button to print logprobe logs (#32255)
* add EntityName at the bottom of LogProbe * pass User into CartridgeMessageEvent * add button to print logprobe logs --------- Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
@@ -1,25 +1,40 @@
|
||||
using Content.Shared.Access.Components;
|
||||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.CartridgeLoader;
|
||||
using Content.Shared.CartridgeLoader.Cartridges;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Hands.EntitySystems;
|
||||
using Content.Shared.Labels.EntitySystems;
|
||||
using Content.Shared.Paper;
|
||||
using Content.Shared.Popups;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
using System.Text;
|
||||
|
||||
namespace Content.Server.CartridgeLoader.Cartridges;
|
||||
|
||||
public sealed class LogProbeCartridgeSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly CartridgeLoaderSystem _cartridge = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly CartridgeLoaderSystem? _cartridgeLoaderSystem = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
|
||||
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedHandsSystem _hands = default!;
|
||||
[Dependency] private readonly SharedLabelSystem _label = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||
[Dependency] private readonly PaperSystem _paper = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<LogProbeCartridgeComponent, CartridgeUiReadyEvent>(OnUiReady);
|
||||
SubscribeLocalEvent<LogProbeCartridgeComponent, CartridgeAfterInteractEvent>(AfterInteract);
|
||||
SubscribeLocalEvent<LogProbeCartridgeComponent, CartridgeMessageEvent>(OnMessage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -37,9 +52,10 @@ public sealed class LogProbeCartridgeSystem : EntitySystem
|
||||
return;
|
||||
|
||||
//Play scanning sound with slightly randomized pitch
|
||||
_audioSystem.PlayEntity(ent.Comp.SoundScan, args.InteractEvent.User, target, AudioHelpers.WithVariation(0.25f, _random));
|
||||
_popupSystem.PopupCursor(Loc.GetString("log-probe-scan", ("device", target)), args.InteractEvent.User);
|
||||
_audio.PlayEntity(ent.Comp.SoundScan, args.InteractEvent.User, target, AudioHelpers.WithVariation(0.25f, _random));
|
||||
_popup.PopupCursor(Loc.GetString("log-probe-scan", ("device", target)), args.InteractEvent.User);
|
||||
|
||||
ent.Comp.EntityName = Name(target);
|
||||
ent.Comp.PulledAccessLogs.Clear();
|
||||
|
||||
foreach (var accessRecord in accessReaderComponent.AccessLog)
|
||||
@@ -52,6 +68,9 @@ public sealed class LogProbeCartridgeSystem : EntitySystem
|
||||
ent.Comp.PulledAccessLogs.Add(log);
|
||||
}
|
||||
|
||||
// Reverse the list so the oldest is at the bottom
|
||||
ent.Comp.PulledAccessLogs.Reverse();
|
||||
|
||||
UpdateUiState(ent, args.Loader);
|
||||
}
|
||||
|
||||
@@ -63,9 +82,49 @@ public sealed class LogProbeCartridgeSystem : EntitySystem
|
||||
UpdateUiState(ent, args.Loader);
|
||||
}
|
||||
|
||||
private void OnMessage(Entity<LogProbeCartridgeComponent> ent, ref CartridgeMessageEvent args)
|
||||
{
|
||||
if (args is LogProbePrintMessage cast)
|
||||
PrintLogs(ent, cast.User);
|
||||
}
|
||||
|
||||
private void PrintLogs(Entity<LogProbeCartridgeComponent> ent, EntityUid user)
|
||||
{
|
||||
if (string.IsNullOrEmpty(ent.Comp.EntityName))
|
||||
return;
|
||||
|
||||
if (_timing.CurTime < ent.Comp.NextPrintAllowed)
|
||||
return;
|
||||
|
||||
ent.Comp.NextPrintAllowed = _timing.CurTime + ent.Comp.PrintCooldown;
|
||||
|
||||
var paper = Spawn(ent.Comp.PaperPrototype, _transform.GetMapCoordinates(user));
|
||||
_label.Label(paper, ent.Comp.EntityName); // label it for easy identification
|
||||
|
||||
_audio.PlayEntity(ent.Comp.PrintSound, user, paper);
|
||||
_hands.PickupOrDrop(user, paper, checkActionBlocker: false);
|
||||
|
||||
// generate the actual printout text
|
||||
var builder = new StringBuilder();
|
||||
builder.AppendLine(Loc.GetString("log-probe-printout-device", ("name", ent.Comp.EntityName)));
|
||||
builder.AppendLine(Loc.GetString("log-probe-printout-header"));
|
||||
var number = 1;
|
||||
foreach (var log in ent.Comp.PulledAccessLogs)
|
||||
{
|
||||
var time = TimeSpan.FromSeconds(Math.Truncate(log.Time.TotalSeconds)).ToString();
|
||||
builder.AppendLine(Loc.GetString("log-probe-printout-entry", ("number", number), ("time", time), ("accessor", log.Accessor)));
|
||||
number++;
|
||||
}
|
||||
|
||||
var paperComp = Comp<PaperComponent>(paper);
|
||||
_paper.SetContent((paper, paperComp), builder.ToString());
|
||||
|
||||
_adminLogger.Add(LogType.EntitySpawn, LogImpact.Low, $"{ToPrettyString(user):user} printed out LogProbe logs ({paper}) of {ent.Comp.EntityName}");
|
||||
}
|
||||
|
||||
private void UpdateUiState(Entity<LogProbeCartridgeComponent> ent, EntityUid loaderUid)
|
||||
{
|
||||
var state = new LogProbeUiState(ent.Comp.PulledAccessLogs);
|
||||
_cartridgeLoaderSystem?.UpdateCartridgeUiState(loaderUid, state);
|
||||
var state = new LogProbeUiState(ent.Comp.EntityName, ent.Comp.PulledAccessLogs);
|
||||
_cartridge.UpdateCartridgeUiState(loaderUid, state);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user