Extracts magic strings from Tag calls (#36305)

* Extracts magic strings from Tag calls

When #36281 gets merged, the `TagSystem` methods will all give warnings. Let's fix those warnings before they even happen!

* Adds missing libraries

* Remove not yet implemented TagSystem changes

* Fix tag spelling error

Genuinely surprised there was only 1!

* Styling and proper type changes

* Styling

Co-authored-by: Tayrtahn <tayrtahn@gmail.com>

---------

Co-authored-by: Tayrtahn <tayrtahn@gmail.com>
This commit is contained in:
J
2025-04-05 00:20:19 +00:00
committed by GitHub
parent e58ab56e42
commit af9526197a
36 changed files with 156 additions and 51 deletions

View File

@@ -23,6 +23,8 @@ public abstract class SharedChameleonClothingSystem : EntitySystem
[Dependency] private readonly TagSystem _tag = default!;
[Dependency] protected readonly SharedUserInterfaceSystem UI = default!;
private static readonly ProtoId<TagPrototype> WhitelistChameleonTag = "WhitelistChameleon";
public override void Initialize()
{
base.Initialize();
@@ -124,7 +126,7 @@ public abstract class SharedChameleonClothingSystem : EntitySystem
return false;
// check if it is marked as valid chameleon target
if (!proto.TryGetComponent(out TagComponent? tag, _factory) || !_tag.HasTag(tag, "WhitelistChameleon"))
if (!proto.TryGetComponent(out TagComponent? tag, _factory) || !_tag.HasTag(tag, WhitelistChameleonTag))
return false;
if (requiredTag != null && !_tag.HasTag(tag, requiredTag))

View File

@@ -1,7 +1,8 @@
using Content.Shared.Maps;
using Content.Shared.Maps;
using Content.Shared.Tag;
using JetBrains.Annotations;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
namespace Content.Shared.Construction.Conditions
{
@@ -9,6 +10,8 @@ namespace Content.Shared.Construction.Conditions
[DataDefinition]
public sealed partial class NoWindowsInTile : IConstructionCondition
{
private static readonly ProtoId<TagPrototype> WindowTag = "Window";
public bool Condition(EntityUid user, EntityCoordinates location, Direction direction)
{
var entManager = IoCManager.Resolve<IEntityManager>();
@@ -17,7 +20,7 @@ namespace Content.Shared.Construction.Conditions
foreach (var entity in location.GetEntitiesInTile(LookupFlags.Static))
{
if (tagSystem.HasTag(entity, "Window"))
if (tagSystem.HasTag(entity, WindowTag))
return false;
}

View File

@@ -6,6 +6,7 @@ using JetBrains.Annotations;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Shared.Construction.Conditions
@@ -14,6 +15,8 @@ namespace Content.Shared.Construction.Conditions
[DataDefinition]
public sealed partial class WallmountCondition : IConstructionCondition
{
private static readonly ProtoId<TagPrototype> WallTag = "Wall";
public bool Condition(EntityUid user, EntityCoordinates location, Direction direction)
{
var entManager = IoCManager.Resolve<IEntityManager>();
@@ -42,7 +45,7 @@ namespace Content.Shared.Construction.Conditions
var tagSystem = entManager.System<TagSystem>();
var userToObjRaycastResults = physics.IntersectRayWithPredicate(entManager.GetComponent<TransformComponent>(user).MapID, rUserToObj, maxLength: length,
predicate: (e) => !tagSystem.HasTag(e, "Wall"));
predicate: (e) => !tagSystem.HasTag(e, WallTag));
var targetWall = userToObjRaycastResults.FirstOrNull();
@@ -53,7 +56,7 @@ namespace Content.Shared.Construction.Conditions
// check that we didn't try to build wallmount that facing another adjacent wall
var rAdjWall = new CollisionRay(objWorldPosition, directionWithOffset.Normalized(), (int) CollisionGroup.Impassable);
var adjWallRaycastResults = physics.IntersectRayWithPredicate(entManager.GetComponent<TransformComponent>(user).MapID, rAdjWall, maxLength: 0.5f,
predicate: e => e == targetWall.Value.HitEntity || !tagSystem.HasTag(e, "Wall"));
predicate: e => e == targetWall.Value.HitEntity || !tagSystem.HasTag(e, WallTag));
return !adjWallRaycastResults.Any();
}

View File

@@ -12,6 +12,7 @@ using Content.Shared.Tag;
using Content.Shared.Verbs;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Containers;
using Robust.Shared.Prototypes;
namespace Content.Shared.Delivery;
@@ -30,6 +31,9 @@ public abstract class SharedDeliverySystem : EntitySystem
[Dependency] private readonly SharedHandsSystem _hands = default!;
[Dependency] private readonly NameModifierSystem _nameModifier = default!;
private static readonly ProtoId<TagPrototype> TrashTag = "Trash";
private static readonly ProtoId<TagPrototype> RecyclableTag = "Recyclable";
public override void Initialize()
{
base.Initialize();
@@ -129,7 +133,7 @@ public abstract class SharedDeliverySystem : EntitySystem
ent.Comp.IsOpened = true;
_appearance.SetData(ent, DeliveryVisuals.IsTrash, ent.Comp.IsOpened);
_tag.AddTags(ent, "Trash", "Recyclable");
_tag.AddTags(ent, TrashTag, RecyclableTag);
EnsureComp<SpaceGarbageComponent>(ent);
RemComp<StealTargetComponent>(ent); // opened mail should not count for the objective

View File

@@ -5,6 +5,7 @@ using Content.Shared.Damage;
using Content.Shared.Hands.Components;
using Content.Shared.Tag;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
@@ -23,6 +24,8 @@ public abstract partial class SharedDoAfterSystem : EntitySystem
/// </summary>
private static readonly TimeSpan ExcessTime = TimeSpan.FromSeconds(0.5f);
private static readonly ProtoId<TagPrototype> InstantDoAftersTag = "InstantDoAfters";
public override void Initialize()
{
base.Initialize();
@@ -233,7 +236,7 @@ public abstract partial class SharedDoAfterSystem : EntitySystem
// TODO DO AFTER
// Why does this tag exist? Just make this a bool on the component?
if (args.Delay <= TimeSpan.Zero || _tag.HasTag(args.User, "InstantDoAfters"))
if (args.Delay <= TimeSpan.Zero || _tag.HasTag(args.User, InstantDoAftersTag))
{
RaiseDoAfterEvents(doAfter, comp);
// We don't store instant do-afters. This is just a lazy way of hiding them from client-side visuals.

View File

@@ -18,6 +18,7 @@ using Robust.Shared.Network;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Shared.Follower;
@@ -32,6 +33,8 @@ public sealed class FollowerSystem : EntitySystem
[Dependency] private readonly INetManager _netMan = default!;
[Dependency] private readonly ISharedAdminManager _adminManager = default!;
private static readonly ProtoId<TagPrototype> ForceableFollowTag = "ForceableFollow";
public override void Initialize()
{
base.Initialize();
@@ -106,7 +109,7 @@ public sealed class FollowerSystem : EntitySystem
ev.Verbs.Add(verb);
}
if (_tagSystem.HasTag(ev.Target, "ForceableFollow"))
if (_tagSystem.HasTag(ev.Target, ForceableFollowTag))
{
if (!ev.CanAccess || !ev.CanInteract)
return;

View File

@@ -6,12 +6,16 @@ using Content.Shared.Inventory.VirtualItem;
using Content.Shared.Tag;
using Robust.Shared.Containers;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
namespace Content.Shared.Hands.EntitySystems;
public abstract partial class SharedHandsSystem
{
[Dependency] private readonly TagSystem _tagSystem = default!;
private static readonly ProtoId<TagPrototype> BypassDropChecksTag = "BypassDropChecks";
private void InitializeDrop()
{
SubscribeLocalEvent<HandsComponent, EntRemovedFromContainerMessage>(HandleEntityRemoved);
@@ -37,7 +41,7 @@ public abstract partial class SharedHandsSystem
private bool ShouldIgnoreRestrictions(EntityUid user)
{
//Checks if the Entity is something that shouldn't care about drop distance or walls ie Aghost
return !_tagSystem.HasTag(user, "BypassDropChecks");
return !_tagSystem.HasTag(user, BypassDropChecksTag);
}
/// <summary>

View File

@@ -7,6 +7,7 @@ using Content.Shared.Tag;
using JetBrains.Annotations;
using Robust.Shared.Containers;
using Robust.Shared.Network;
using Robust.Shared.Prototypes;
using System.Linq;
namespace Content.Shared.Implants;
@@ -21,6 +22,9 @@ public abstract class SharedSubdermalImplantSystem : EntitySystem
public const string BaseStorageId = "storagebase";
private static readonly ProtoId<TagPrototype> MicroBombTag = "MicroBomb";
private static readonly ProtoId<TagPrototype> MacroBombTag = "MacroBomb";
public override void Initialize()
{
SubscribeLocalEvent<SubdermalImplantComponent, EntGotInsertedIntoContainerMessage>(OnInsert);
@@ -43,11 +47,11 @@ public abstract class SharedSubdermalImplantSystem : EntitySystem
}
//replace micro bomb with macro bomb
if (_container.TryGetContainer(component.ImplantedEntity.Value, ImplanterComponent.ImplantSlotId, out var implantContainer) && _tag.HasTag(uid, "MacroBomb"))
if (_container.TryGetContainer(component.ImplantedEntity.Value, ImplanterComponent.ImplantSlotId, out var implantContainer) && _tag.HasTag(uid, MacroBombTag))
{
foreach (var implant in implantContainer.ContainedEntities)
{
if (_tag.HasTag(implant, "MicroBomb"))
if (_tag.HasTag(implant, MicroBombTag))
{
_container.Remove(implant, implantContainer);
QueueDel(implant);

View File

@@ -37,6 +37,7 @@ using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
@@ -87,6 +88,8 @@ namespace Content.Shared.Interaction
public const float MaxRaycastRange = 100f;
public const string RateLimitKey = "Interaction";
private static readonly ProtoId<TagPrototype> BypassInteractionRangeChecksTag = "BypassInteractionRangeChecks";
public delegate bool Ignored(EntityUid entity);
public override void Initialize()
@@ -318,7 +321,7 @@ namespace Content.Shared.Interaction
{
// This is for Admin/mapping convenience. If ever there are other ghosts that can still interact, this check
// might need to be more selective.
return !_tagSystem.HasTag(user, "BypassInteractionRangeChecks");
return !_tagSystem.HasTag(user, BypassInteractionRangeChecksTag);
}
/// <summary>

View File

@@ -65,6 +65,8 @@ public abstract class SharedMagicSystem : EntitySystem
[Dependency] private readonly SharedMindSystem _mind = default!;
[Dependency] private readonly SharedStunSystem _stun = default!;
private static readonly ProtoId<TagPrototype> InvalidForGlobalSpawnSpellTag = "InvalidForGlobalSpawnSpell";
public override void Initialize()
{
base.Initialize();
@@ -484,7 +486,7 @@ public abstract class SharedMagicSystem : EntitySystem
var ent = human.Comp.OwnedEntity.Value;
if (_tag.HasTag(ent, "InvalidForGlobalSpawnSpell"))
if (_tag.HasTag(ent, InvalidForGlobalSpawnSpellTag))
continue;
var mapCoords = _transform.GetMapCoordinates(ent);

View File

@@ -20,6 +20,7 @@ using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Controllers;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using PullableComponent = Content.Shared.Movement.Pulling.Components.PullableComponent;
@@ -59,6 +60,8 @@ public abstract partial class SharedMoverController : VirtualController
protected EntityQuery<FootstepModifierComponent> FootstepModifierQuery;
protected EntityQuery<MapGridComponent> MapGridQuery;
private static readonly ProtoId<TagPrototype> FootstepSoundTag = "FootstepSound";
/// <summary>
/// <see cref="CCVars.StopSpeed"/>
/// </summary>
@@ -431,7 +434,7 @@ public abstract partial class SharedMoverController : VirtualController
{
sound = null;
if (!CanSound() || !_tags.HasTag(uid, "FootstepSound"))
if (!CanSound() || !_tags.HasTag(uid, FootstepSoundTag))
return false;
var coordinates = xform.Coordinates;

View File

@@ -9,6 +9,7 @@ using Content.Shared.Tag;
using Robust.Shared.Player;
using Robust.Shared.Audio.Systems;
using static Content.Shared.Paper.PaperComponent;
using Robust.Shared.Prototypes;
namespace Content.Shared.Paper;
@@ -23,6 +24,9 @@ public sealed class PaperSystem : EntitySystem
[Dependency] private readonly MetaDataSystem _metaSystem = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
private static readonly ProtoId<TagPrototype> WriteIgnoreStampsTag = "WriteIgnoreStamps";
private static readonly ProtoId<TagPrototype> WriteTag = "Write";
public override void Initialize()
{
base.Initialize();
@@ -100,8 +104,8 @@ public sealed class PaperSystem : EntitySystem
private void OnInteractUsing(Entity<PaperComponent> entity, ref InteractUsingEvent args)
{
// only allow editing if there are no stamps or when using a cyberpen
var editable = entity.Comp.StampedBy.Count == 0 || _tagSystem.HasTag(args.Used, "WriteIgnoreStamps");
if (_tagSystem.HasTag(args.Used, "Write"))
var editable = entity.Comp.StampedBy.Count == 0 || _tagSystem.HasTag(args.Used, WriteIgnoreStampsTag);
if (_tagSystem.HasTag(args.Used, WriteTag))
{
if (editable)
{

View File

@@ -51,6 +51,7 @@ public class RCDSystem : EntitySystem
private readonly EntProtoId _instantConstructionFx = "EffectRCDConstruct0";
private readonly ProtoId<RCDPrototype> _deconstructTileProto = "DeconstructTile";
private readonly ProtoId<RCDPrototype> _deconstructLatticeProto = "DeconstructLattice";
private static readonly ProtoId<TagPrototype> CatwalkTag = "Catwalk";
private HashSet<EntityUid> _intersectingEntities = new();
@@ -411,7 +412,7 @@ public class RCDSystem : EntitySystem
if (isWindow && HasComp<SharedCanBuildWindowOnTopComponent>(ent))
continue;
if (isCatwalk && _tags.HasTag(ent, "Catwalk"))
if (isCatwalk && _tags.HasTag(ent, CatwalkTag))
{
if (popMsgs)
_popup.PopupClient(Loc.GetString("rcd-component-cannot-build-on-occupied-tile-message"), uid, user);