Forbid string literals for SharedToolSystem methods (#38250)
* Forbid string literals for ToolSystem methods * Cleanup violations * Sort usings
This commit is contained in:
@@ -5,29 +5,31 @@ using Content.Server.DeviceNetwork.Systems;
|
||||
using Content.Server.Popups;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Tools;
|
||||
using Content.Shared.UserInterface;
|
||||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.DeviceNetwork;
|
||||
using Content.Shared.DeviceNetwork.Components;
|
||||
using Content.Shared.DeviceNetwork.Events;
|
||||
using Content.Shared.Emag.Systems;
|
||||
using Content.Shared.Fax;
|
||||
using Content.Shared.Fax.Systems;
|
||||
using Content.Shared.Fax.Components;
|
||||
using Content.Shared.Fax.Systems;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Labels.Components;
|
||||
using Content.Shared.Labels.EntitySystems;
|
||||
using Content.Shared.Mobs.Components;
|
||||
using Content.Shared.NameModifier.Components;
|
||||
using Content.Shared.Paper;
|
||||
using Content.Shared.Power;
|
||||
using Content.Shared.Tools;
|
||||
using Content.Shared.UserInterface;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Player;
|
||||
using Content.Shared.NameModifier.Components;
|
||||
using Content.Shared.Power;
|
||||
using Content.Shared.DeviceNetwork.Components;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.Fax;
|
||||
|
||||
@@ -50,6 +52,8 @@ public sealed class FaxSystem : EntitySystem
|
||||
[Dependency] private readonly FaxecuteSystem _faxecute = default!;
|
||||
[Dependency] private readonly EmagSystem _emag = default!;
|
||||
|
||||
private static readonly ProtoId<ToolQualityPrototype> ScrewingQuality = "Screwing";
|
||||
|
||||
private const string PaperSlotId = "Paper";
|
||||
|
||||
public override void Initialize()
|
||||
@@ -209,7 +213,7 @@ public sealed class FaxSystem : EntitySystem
|
||||
{
|
||||
if (args.Handled ||
|
||||
!TryComp<ActorComponent>(args.User, out var actor) ||
|
||||
!_toolSystem.HasQuality(args.Used, "Screwing")) // Screwing because Pulsing already used by device linking
|
||||
!_toolSystem.HasQuality(args.Used, ScrewingQuality)) // Screwing because Pulsing already used by device linking
|
||||
return;
|
||||
|
||||
_quickDialog.OpenDialog(actor.PlayerSession,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Server.Body.Systems;
|
||||
using Content.Server.Mech.Components;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Power.EntitySystems;
|
||||
@@ -13,16 +14,17 @@ using Content.Shared.Mech.Components;
|
||||
using Content.Shared.Mech.EntitySystems;
|
||||
using Content.Shared.Movement.Events;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Tools;
|
||||
using Content.Shared.Tools.Components;
|
||||
using Content.Shared.Verbs;
|
||||
using Content.Shared.Wires;
|
||||
using Content.Server.Body.Systems;
|
||||
using Content.Shared.Tools.Systems;
|
||||
using Content.Shared.Verbs;
|
||||
using Content.Shared.Whitelist;
|
||||
using Content.Shared.Wires;
|
||||
using Robust.Server.Containers;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Player;
|
||||
using Content.Shared.Whitelist;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.Mech.Systems;
|
||||
|
||||
@@ -40,6 +42,8 @@ public sealed partial class MechSystem : SharedMechSystem
|
||||
[Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
|
||||
[Dependency] private readonly SharedToolSystem _toolSystem = default!;
|
||||
|
||||
private static readonly ProtoId<ToolQualityPrototype> PryingQuality = "Prying";
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -91,7 +95,7 @@ public sealed partial class MechSystem : SharedMechSystem
|
||||
return;
|
||||
}
|
||||
|
||||
if (_toolSystem.HasQuality(args.Used, "Prying") && component.BatterySlot.ContainedEntity != null)
|
||||
if (_toolSystem.HasQuality(args.Used, PryingQuality) && component.BatterySlot.ContainedEntity != null)
|
||||
{
|
||||
var doAfterEventArgs = new DoAfterArgs(EntityManager, args.User, component.BatteryRemovalDelay,
|
||||
new RemoveBatteryEvent(), uid, target: uid, used: args.Target)
|
||||
|
||||
@@ -9,12 +9,11 @@ using Content.Server.NodeContainer.EntitySystems;
|
||||
using Content.Server.NodeContainer.NodeGroups;
|
||||
using Content.Server.NodeContainer.Nodes;
|
||||
using Content.Server.Temperature.Components;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.UserInterface;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.Components.SolutionManager;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Climbing.Systems;
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
using Content.Shared.Database;
|
||||
@@ -26,11 +25,14 @@ using Content.Shared.Interaction;
|
||||
using Content.Shared.Medical.Cryogenics;
|
||||
using Content.Shared.MedicalScanner;
|
||||
using Content.Shared.Power;
|
||||
using Content.Shared.Tools;
|
||||
using Content.Shared.Tools.Systems;
|
||||
using Content.Shared.UserInterface;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Timing;
|
||||
using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
|
||||
|
||||
namespace Content.Server.Medical;
|
||||
|
||||
@@ -51,6 +53,8 @@ public sealed partial class CryoPodSystem : SharedCryoPodSystem
|
||||
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
||||
[Dependency] private readonly NodeContainerSystem _nodeContainer = default!;
|
||||
|
||||
private static readonly ProtoId<ToolQualityPrototype> PryingQuality = "Prying";
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -211,7 +215,7 @@ public sealed partial class CryoPodSystem : SharedCryoPodSystem
|
||||
if (args.Handled || !entity.Comp.Locked || entity.Comp.BodyContainer.ContainedEntity == null)
|
||||
return;
|
||||
|
||||
args.Handled = _toolSystem.UseTool(args.Used, args.User, entity.Owner, entity.Comp.PryDelay, "Prying", new CryoPodPryFinished());
|
||||
args.Handled = _toolSystem.UseTool(args.Used, args.User, entity.Owner, entity.Comp.PryDelay, PryingQuality, new CryoPodPryFinished());
|
||||
}
|
||||
|
||||
private void OnExamined(Entity<CryoPodComponent> entity, ref ExaminedEvent args)
|
||||
|
||||
@@ -10,6 +10,7 @@ using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Power;
|
||||
using Content.Shared.Tools;
|
||||
using Content.Shared.Tools.Components;
|
||||
using Content.Shared.Wires;
|
||||
using Robust.Server.GameObjects;
|
||||
@@ -29,6 +30,9 @@ public sealed class WiresSystem : SharedWiresSystem
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly ConstructionSystem _construction = default!;
|
||||
|
||||
private static readonly ProtoId<ToolQualityPrototype> CuttingQuality = "Cutting";
|
||||
private static readonly ProtoId<ToolQualityPrototype> PulsingQuality = "Pulsing";
|
||||
|
||||
// This is where all the wire layouts are stored.
|
||||
[ViewVariables] private readonly Dictionary<string, WireLayout> _layouts = new();
|
||||
|
||||
@@ -443,8 +447,8 @@ public sealed class WiresSystem : SharedWiresSystem
|
||||
if (!IsPanelOpen(uid))
|
||||
return;
|
||||
|
||||
if (Tool.HasQuality(args.Used, "Cutting", tool) ||
|
||||
Tool.HasQuality(args.Used, "Pulsing", tool))
|
||||
if (Tool.HasQuality(args.Used, CuttingQuality, tool) ||
|
||||
Tool.HasQuality(args.Used, PulsingQuality, tool))
|
||||
{
|
||||
if (TryComp(args.User, out ActorComponent? actor))
|
||||
{
|
||||
@@ -623,7 +627,7 @@ public sealed class WiresSystem : SharedWiresSystem
|
||||
switch (action)
|
||||
{
|
||||
case WiresAction.Cut:
|
||||
if (!Tool.HasQuality(toolEntity, "Cutting", tool))
|
||||
if (!Tool.HasQuality(toolEntity, CuttingQuality, tool))
|
||||
{
|
||||
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-wirecutters"), user);
|
||||
return;
|
||||
@@ -637,7 +641,7 @@ public sealed class WiresSystem : SharedWiresSystem
|
||||
|
||||
break;
|
||||
case WiresAction.Mend:
|
||||
if (!Tool.HasQuality(toolEntity, "Cutting", tool))
|
||||
if (!Tool.HasQuality(toolEntity, CuttingQuality, tool))
|
||||
{
|
||||
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-wirecutters"), user);
|
||||
return;
|
||||
@@ -651,7 +655,7 @@ public sealed class WiresSystem : SharedWiresSystem
|
||||
|
||||
break;
|
||||
case WiresAction.Pulse:
|
||||
if (!Tool.HasQuality(toolEntity, "Pulsing", tool))
|
||||
if (!Tool.HasQuality(toolEntity, PulsingQuality, tool))
|
||||
{
|
||||
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-multitool"), user);
|
||||
return;
|
||||
@@ -710,7 +714,7 @@ public sealed class WiresSystem : SharedWiresSystem
|
||||
switch (action)
|
||||
{
|
||||
case WiresAction.Cut:
|
||||
if (!Tool.HasQuality(toolEntity, "Cutting", tool))
|
||||
if (!Tool.HasQuality(toolEntity, CuttingQuality, tool))
|
||||
{
|
||||
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-wirecutters"), user);
|
||||
break;
|
||||
@@ -731,7 +735,7 @@ public sealed class WiresSystem : SharedWiresSystem
|
||||
UpdateUserInterface(used);
|
||||
break;
|
||||
case WiresAction.Mend:
|
||||
if (!Tool.HasQuality(toolEntity, "Cutting", tool))
|
||||
if (!Tool.HasQuality(toolEntity, CuttingQuality, tool))
|
||||
{
|
||||
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-wirecutters"), user);
|
||||
break;
|
||||
@@ -752,7 +756,7 @@ public sealed class WiresSystem : SharedWiresSystem
|
||||
UpdateUserInterface(used);
|
||||
break;
|
||||
case WiresAction.Pulse:
|
||||
if (!Tool.HasQuality(toolEntity, "Pulsing", tool))
|
||||
if (!Tool.HasQuality(toolEntity, PulsingQuality, tool))
|
||||
{
|
||||
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-multitool"), user);
|
||||
break;
|
||||
|
||||
@@ -115,7 +115,7 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
EntityUid user,
|
||||
EntityUid? target,
|
||||
float doAfterDelay,
|
||||
IEnumerable<string> toolQualitiesNeeded,
|
||||
[ForbidLiteral] IEnumerable<string> toolQualitiesNeeded,
|
||||
DoAfterEvent doAfterEv,
|
||||
float fuel = 0,
|
||||
ToolComponent? toolComponent = null)
|
||||
@@ -153,7 +153,7 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
EntityUid user,
|
||||
EntityUid? target,
|
||||
TimeSpan delay,
|
||||
IEnumerable<string> toolQualitiesNeeded,
|
||||
[ForbidLiteral] IEnumerable<string> toolQualitiesNeeded,
|
||||
DoAfterEvent doAfterEv,
|
||||
out DoAfterId? id,
|
||||
float fuel = 0,
|
||||
@@ -200,7 +200,7 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
EntityUid user,
|
||||
EntityUid? target,
|
||||
float doAfterDelay,
|
||||
string toolQualityNeeded,
|
||||
[ForbidLiteral] string toolQualityNeeded,
|
||||
DoAfterEvent doAfterEv,
|
||||
float fuel = 0,
|
||||
ToolComponent? toolComponent = null)
|
||||
@@ -219,7 +219,7 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
/// <summary>
|
||||
/// Whether a tool entity has the specified quality or not.
|
||||
/// </summary>
|
||||
public bool HasQuality(EntityUid uid, string quality, ToolComponent? tool = null)
|
||||
public bool HasQuality(EntityUid uid, [ForbidLiteral] string quality, ToolComponent? tool = null)
|
||||
{
|
||||
return Resolve(uid, ref tool, false) && tool.Qualities.Contains(quality);
|
||||
}
|
||||
@@ -228,7 +228,7 @@ public abstract partial class SharedToolSystem : EntitySystem
|
||||
/// Whether a tool entity has all specified qualities or not.
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public bool HasAllQualities(EntityUid uid, IEnumerable<string> qualities, ToolComponent? tool = null)
|
||||
public bool HasAllQualities(EntityUid uid, [ForbidLiteral] IEnumerable<string> qualities, ToolComponent? tool = null)
|
||||
{
|
||||
return Resolve(uid, ref tool, false) && tool.Qualities.ContainsAll(qualities);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user