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

@@ -50,6 +50,9 @@ public sealed class PlantHolderSystem : EntitySystem
public const float HydroponicsSpeedMultiplier = 1f;
public const float HydroponicsConsumptionMultiplier = 2f;
private static readonly ProtoId<TagPrototype> HoeTag = "Hoe";
private static readonly ProtoId<TagPrototype> PlantSampleTakerTag = "PlantSampleTaker";
public override void Initialize()
{
base.Initialize();
@@ -203,7 +206,7 @@ public sealed class PlantHolderSystem : EntitySystem
return;
}
if (_tagSystem.HasTag(args.Used, "Hoe"))
if (_tagSystem.HasTag(args.Used, HoeTag))
{
args.Handled = true;
if (component.WeedLevel > 0)
@@ -243,7 +246,7 @@ public sealed class PlantHolderSystem : EntitySystem
return;
}
if (_tagSystem.HasTag(args.Used, "PlantSampleTaker"))
if (_tagSystem.HasTag(args.Used, PlantSampleTakerTag))
{
args.Handled = true;
if (component.Seed == null)

View File

@@ -14,6 +14,7 @@ using Content.Shared.Mobs.Systems;
using Content.Shared.Popups;
using Content.Shared.Tag;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
namespace Content.Server.Chat;
@@ -27,6 +28,8 @@ public sealed class SuicideSystem : EntitySystem
[Dependency] private readonly GhostSystem _ghostSystem = default!;
[Dependency] private readonly SharedSuicideSystem _suicide = default!;
private static readonly ProtoId<TagPrototype> CannotSuicideTag = "CannotSuicide";
public override void Initialize()
{
base.Initialize();
@@ -60,7 +63,7 @@ public sealed class SuicideSystem : EntitySystem
// Suicide is considered a fail if the user wasn't able to ghost
// Suiciding with the CannotSuicide tag will ghost the player but not kill the body
if (!suicideGhostEvent.Handled || _tagSystem.HasTag(victim, "CannotSuicide"))
if (!suicideGhostEvent.Handled || _tagSystem.HasTag(victim, CannotSuicideTag))
return false;
var suicideEvent = new SuicideEvent(victim);
@@ -95,7 +98,7 @@ public sealed class SuicideSystem : EntitySystem
// CannotSuicide tag will allow the user to ghost, but also return to their mind
// This is kind of weird, not sure what it applies to?
if (_tagSystem.HasTag(victim, "CannotSuicide"))
if (_tagSystem.HasTag(victim, CannotSuicideTag))
args.CanReturnToBody = true;
if (_ghostSystem.OnGhostAttempt(victim.Comp.Mind.Value, args.CanReturnToBody, mind: mindComponent))

View File

@@ -9,6 +9,7 @@ using Content.Shared.Projectiles;
using Content.Shared.Tag;
using Content.Shared.Weapons.Melee.Events;
using Robust.Shared.Collections;
using Robust.Shared.Prototypes;
namespace Content.Server.Chemistry.EntitySystems;
@@ -24,6 +25,8 @@ public sealed class SolutionInjectOnCollideSystem : EntitySystem
[Dependency] private readonly SharedSolutionContainerSystem _solutionContainer = default!;
[Dependency] private readonly TagSystem _tag = default!;
private static readonly ProtoId<TagPrototype> HardsuitTag = "Hardsuit";
public override void Initialize()
{
base.Initialize();
@@ -93,7 +96,7 @@ public sealed class SolutionInjectOnCollideSystem : EntitySystem
// Yuck, this is way to hardcodey for my tastes
// TODO blocking injection with a hardsuit should probably done with a cancellable event or something
if (!injector.Comp.PierceArmor && _inventory.TryGetSlotEntity(target, "outerClothing", out var suit) && _tag.HasTag(suit.Value, "Hardsuit"))
if (!injector.Comp.PierceArmor && _inventory.TryGetSlotEntity(target, "outerClothing", out var suit) && _tag.HasTag(suit.Value, HardsuitTag))
{
// Only show popup to attacker
if (source != null)

View File

@@ -5,6 +5,7 @@ using Content.Shared.Construction;
using Content.Shared.Tag;
using Robust.Shared.Console;
using Robust.Shared.Map.Components;
using Robust.Shared.Prototypes;
namespace Content.Server.Construction.Commands;
@@ -13,6 +14,10 @@ public sealed class FixRotationsCommand : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entManager = default!;
private static readonly ProtoId<TagPrototype> ForceFixRotationsTag = "ForceFixRotations";
private static readonly ProtoId<TagPrototype> ForceNoFixRotationsTag = "ForceNoFixRotations";
private static readonly ProtoId<TagPrototype> DiagonalTag = "Diagonal";
// ReSharper disable once StringLiteralTypo
public string Command => "fixrotations";
public string Description => "Sets the rotation of all occluders, low walls and windows to south.";
@@ -86,11 +91,11 @@ public sealed class FixRotationsCommand : IConsoleCommand
// cables
valid |= _entManager.HasComponent<CableComponent>(child);
// anything else that might need this forced
valid |= tagSystem.HasTag(child, "ForceFixRotations");
valid |= tagSystem.HasTag(child, ForceFixRotationsTag);
// override
valid &= !tagSystem.HasTag(child, "ForceNoFixRotations");
valid &= !tagSystem.HasTag(child, ForceNoFixRotationsTag);
// remove diagonal entities as well
valid &= !tagSystem.HasTag(child, "Diagonal");
valid &= !tagSystem.HasTag(child, DiagonalTag);
if (!valid)
continue;

View File

@@ -62,6 +62,8 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
[ValidatePrototypeId<DamageTypePrototype>]
private const string DamageType = "Shock";
private static readonly ProtoId<TagPrototype> WindowTag = "Window";
// Multiply and shift the log scale for shock damage.
private const float RecursiveDamageMultiplier = 0.75f;
private const float RecursiveTimeMultiplier = 0.8f;
@@ -139,7 +141,7 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
{
foreach (var entity in _entityLookup.GetLocalEntitiesIntersecting(tileRef.Value, flags: LookupFlags.StaticSundries))
{
if (_tag.HasTag(entity, "Window"))
if (_tag.HasTag(entity, WindowTag))
return false;
}
}

View File

@@ -21,6 +21,7 @@ using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Random;
using InventoryComponent = Content.Shared.Inventory.InventoryComponent;
using Robust.Shared.Prototypes;
namespace Content.Server.Flash
{
@@ -39,6 +40,8 @@ namespace Content.Server.Flash
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly StatusEffectsSystem _statusEffectsSystem = default!;
private static readonly ProtoId<TagPrototype> TrashTag = "Trash";
public override void Initialize()
{
base.Initialize();
@@ -94,7 +97,7 @@ namespace Content.Server.Flash
if (_charges.IsEmpty(uid, charges))
{
_appearance.SetData(uid, FlashVisuals.Burnt, true);
_tag.AddTag(uid, "Trash");
_tag.AddTag(uid, TrashTag);
_popup.PopupEntity(Loc.GetString("flash-component-becomes-empty"), user);
}

View File

@@ -16,6 +16,7 @@ using Robust.Shared.Audio;
using Robust.Shared.Player;
using Robust.Shared.Timing;
using Content.Server.Chemistry.Containers.EntitySystems;
using Robust.Shared.Prototypes;
// todo: remove this stinky LINQy
namespace Content.Server.Forensics
@@ -33,6 +34,8 @@ namespace Content.Server.Forensics
[Dependency] private readonly ForensicsSystem _forensicsSystem = default!;
[Dependency] private readonly TagSystem _tag = default!;
private static readonly ProtoId<TagPrototype> DNASolutionScannableTag = "DNASolutionScannable";
public override void Initialize()
{
base.Initialize();
@@ -86,7 +89,7 @@ namespace Content.Server.Forensics
scanner.Residues = forensics.Residues.ToList();
}
if (_tag.HasTag(args.Args.Target.Value, "DNASolutionScannable"))
if (_tag.HasTag(args.Args.Target.Value, DNASolutionScannableTag))
{
scanner.SolutionDNAs = _forensicsSystem.GetSolutionsDNA(args.Args.Target.Value);
} else

View File

@@ -9,6 +9,7 @@ using Content.Shared.Mobs.Systems;
using Content.Shared.Survivor.Components;
using Content.Shared.Tag;
using Robust.Server.GameObjects;
using Robust.Shared.Prototypes;
namespace Content.Server.GameTicking.Rules;
@@ -22,6 +23,8 @@ public sealed class SurvivorRuleSystem : GameRuleSystem<SurvivorRuleComponent>
[Dependency] private readonly TagSystem _tag = default!;
[Dependency] private readonly MobStateSystem _mobState = default!;
private static readonly ProtoId<TagPrototype> InvalidForSurvivorAntagTag = "InvalidForSurvivorAntag";
public override void Initialize()
{
base.Initialize();
@@ -44,7 +47,7 @@ public sealed class SurvivorRuleSystem : GameRuleSystem<SurvivorRuleComponent>
var mind = humanMind.Owner;
var ent = humanMind.Comp.OwnedEntity.Value;
if (HasComp<SurvivorComponent>(mind) || _tag.HasTag(mind, "InvalidForSurvivorAntag"))
if (HasComp<SurvivorComponent>(mind) || _tag.HasTag(mind, InvalidForSurvivorAntagTag))
continue;
EnsureComp<SurvivorComponent>(mind);

View File

@@ -72,6 +72,8 @@ namespace Content.Server.Ghost
private EntityQuery<GhostComponent> _ghostQuery;
private EntityQuery<PhysicsComponent> _physicsQuery;
private static readonly ProtoId<TagPrototype> AllowGhostShownByEventTag = "AllowGhostShownByEvent";
public override void Initialize()
{
base.Initialize();
@@ -403,7 +405,7 @@ namespace Content.Server.Ghost
var entityQuery = EntityQueryEnumerator<GhostComponent, VisibilityComponent>();
while (entityQuery.MoveNext(out var uid, out var _, out var vis))
{
if (!_tag.HasTag(uid, "AllowGhostShownByEvent"))
if (!_tag.HasTag(uid, AllowGhostShownByEventTag))
continue;
if (visible)

View File

@@ -73,6 +73,9 @@ namespace Content.Server.Kitchen.EntitySystems
[ValidatePrototypeId<EntityPrototype>]
private const string MalfunctionSpark = "Spark";
private static readonly ProtoId<TagPrototype> MetalTag = "Metal";
private static readonly ProtoId<TagPrototype> PlasticTag = "Plastic";
public override void Initialize()
{
base.Initialize();
@@ -550,12 +553,12 @@ namespace Content.Server.Kitchen.EntitySystems
return;
}
if (_tag.HasTag(item, "Metal"))
if (_tag.HasTag(item, MetalTag))
{
malfunctioning = true;
}
if (_tag.HasTag(item, "Plastic"))
if (_tag.HasTag(item, PlasticTag))
{
var junk = Spawn(component.BadRecipeEntityId, Transform(uid).Coordinates);
_container.Insert(junk, component.Storage);

View File

@@ -10,6 +10,7 @@ using Content.Shared.Verbs;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Server.Light.EntitySystems
@@ -24,6 +25,8 @@ namespace Content.Server.Light.EntitySystems
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly MetaDataSystem _metaData = default!;
private static readonly ProtoId<TagPrototype> TrashTag = "Trash";
public override void Initialize()
{
base.Initialize();
@@ -69,7 +72,7 @@ namespace Content.Server.Light.EntitySystems
_metaData.SetEntityName(ent, Loc.GetString(component.SpentName), meta);
_metaData.SetEntityDescription(ent, Loc.GetString(component.SpentDesc), meta);
_tagSystem.AddTag(ent, "Trash");
_tagSystem.AddTag(ent, TrashTag);
UpdateSounds(ent);
UpdateVisualizer(ent);

View File

@@ -16,6 +16,8 @@ public sealed class MagicSystem : SharedMagicSystem
[Dependency] private readonly TagSystem _tag = default!;
[Dependency] private readonly SharedMindSystem _mind = default!;
private static readonly ProtoId<TagPrototype> InvalidForSurvivorAntagTag = "InvalidForSurvivorAntag";
public override void Initialize()
{
base.Initialize();
@@ -48,8 +50,8 @@ public sealed class MagicSystem : SharedMagicSystem
if (!ev.MakeSurvivorAntagonist)
return;
if (_mind.TryGetMind(ev.Performer, out var mind, out _) && !_tag.HasTag(mind, "InvalidForSurvivorAntag"))
_tag.AddTag(mind, "InvalidForSurvivorAntag");
if (_mind.TryGetMind(ev.Performer, out var mind, out _) && !_tag.HasTag(mind, InvalidForSurvivorAntagTag))
_tag.AddTag(mind, InvalidForSurvivorAntagTag);
EntProtoId survivorRule = "Survivor";

View File

@@ -11,6 +11,7 @@ using Content.Shared.MagicMirror;
using Content.Shared.Popups;
using Content.Shared.Tag;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Prototypes;
namespace Content.Server.MagicMirror;
@@ -27,6 +28,8 @@ public sealed class MagicMirrorSystem : SharedMagicMirrorSystem
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly TagSystem _tagSystem = default!;
private static readonly ProtoId<TagPrototype> HidesHairTag = "HidesHair";
public override void Initialize()
{
base.Initialize();
@@ -391,7 +394,7 @@ public sealed class MagicMirrorSystem : SharedMagicMirrorSystem
var slots = _inventory.GetSlotEnumerator((target, inventoryComp), SlotFlags.WITHOUT_POCKET);
while (slots.MoveNext(out var slot))
{
if (slot.ContainedEntity != null && _tagSystem.HasTag(slot.ContainedEntity.Value, "HidesHair"))
if (slot.ContainedEntity != null && _tagSystem.HasTag(slot.ContainedEntity.Value, HidesHairTag))
{
return true;
}

View File

@@ -3,6 +3,7 @@ using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Components.SolutionManager;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Tag;
using Robust.Shared.Prototypes;
namespace Content.Server.Nutrition.EntitySystems
{
@@ -11,6 +12,8 @@ namespace Content.Server.Nutrition.EntitySystems
[Dependency] private readonly SharedSolutionContainerSystem _solutionContainerSystem = default!;
[Dependency] private readonly TagSystem _tagSystem = default!;
private static readonly ProtoId<TagPrototype> TrashTag = "Trash";
public override void Initialize()
{
base.Initialize();
@@ -41,11 +44,11 @@ namespace Content.Server.Nutrition.EntitySystems
{
if (solution.Volume <= 0)
{
_tagSystem.AddTag(entity.Owner, "Trash");
_tagSystem.AddTag(entity.Owner, TrashTag);
return;
}
if (_tagSystem.HasTag(entity.Owner, "Trash"))
_tagSystem.RemoveTag(entity.Owner, "Trash");
_tagSystem.RemoveTag(entity.Owner, TrashTag);
}
}
}

View File

@@ -11,6 +11,7 @@ using Robust.Shared.Serialization.Manager;
using Robust.Shared.Utility;
using System.Linq;
using Robust.Server.GameObjects;
using Robust.Shared.Prototypes;
namespace Content.Server.Payload.EntitySystems;
@@ -23,6 +24,8 @@ public sealed class PayloadSystem : EntitySystem
[Dependency] private readonly IComponentFactory _componentFactory = default!;
[Dependency] private readonly ISerializationManager _serializationManager = default!;
private static readonly ProtoId<TagPrototype> PayloadTag = "Payload";
public override void Initialize()
{
base.Initialize();
@@ -44,7 +47,7 @@ public sealed class PayloadSystem : EntitySystem
{
foreach (var entity in container.ContainedEntities)
{
if (_tagSystem.HasTag(entity, "Payload"))
if (_tagSystem.HasTag(entity, PayloadTag))
yield return entity;
}
}
@@ -71,7 +74,7 @@ public sealed class PayloadSystem : EntitySystem
return;
// Ensure we don't enter a trigger-loop
DebugTools.Assert(!_tagSystem.HasTag(uid, "Payload"));
DebugTools.Assert(!_tagSystem.HasTag(uid, PayloadTag));
RaiseLocalEvent(parent, args, false);
}

View File

@@ -1,8 +1,10 @@
using System.Numerics;
using Content.Shared.Procedural;
using Content.Shared.Tag;
using Robust.Shared.Collections;
using Robust.Shared.Map.Components;
using Robust.Shared.Physics.Components;
using Robust.Shared.Prototypes;
namespace Content.Server.Procedural.DungeonJob;
@@ -12,13 +14,15 @@ public sealed partial class DungeonJob
* Run after the main dungeon generation
*/
private static readonly ProtoId<TagPrototype> WallTag = "Wall";
private bool HasWall(Vector2i tile)
{
var anchored = _maps.GetAnchoredEntitiesEnumerator(_gridUid, _grid, tile);
while (anchored.MoveNext(out var uid))
{
if (_tags.HasTag(uid.Value, "Wall"))
if (_tags.HasTag(uid.Value, WallTag))
return true;
}

View File

@@ -29,6 +29,7 @@ using Robust.Shared.Physics.Components;
using Robust.Shared.Utility;
using Robust.Shared.Map.Components;
using Content.Shared.Whitelist;
using Robust.Shared.Prototypes;
namespace Content.Server.Revenant.EntitySystems;
@@ -44,6 +45,8 @@ public sealed partial class RevenantSystem
[Dependency] private readonly SharedTransformSystem _transformSystem = default!;
[Dependency] private readonly SharedMapSystem _mapSystem = default!;
private static readonly ProtoId<TagPrototype> WindowTag = "Window";
private void InitializeAbilities()
{
SubscribeLocalEvent<RevenantComponent, UserActivateInWorldEvent>(OnInteract);
@@ -253,7 +256,7 @@ public sealed partial class RevenantSystem
foreach (var ent in lookup)
{
//break windows
if (tags.HasComponent(ent) && _tag.HasTag(ent, "Window"))
if (tags.HasComponent(ent) && _tag.HasTag(ent, WindowTag))
{
//hardcoded damage specifiers til i die.
var dspec = new DamageSpecifier();

View File

@@ -21,6 +21,7 @@ using Robust.Shared.GameStates;
using Robust.Shared.Map;
using Robust.Shared.Utility;
using Content.Shared.UserInterface;
using Robust.Shared.Prototypes;
namespace Content.Server.Shuttles.Systems;
@@ -43,6 +44,8 @@ public sealed partial class ShuttleConsoleSystem : SharedShuttleConsoleSystem
private readonly HashSet<Entity<ShuttleConsoleComponent>> _consoles = new();
private static readonly ProtoId<TagPrototype> CanPilotTag = "CanPilot";
public override void Initialize()
{
base.Initialize();
@@ -168,7 +171,7 @@ public sealed partial class ShuttleConsoleSystem : SharedShuttleConsoleSystem
private bool TryPilot(EntityUid user, EntityUid uid)
{
if (!_tags.HasTag(user, "CanPilot") ||
if (!_tags.HasTag(user, CanPilotTag) ||
!TryComp<ShuttleConsoleComponent>(uid, out var component) ||
!this.IsPowered(uid, EntityManager) ||
!Transform(uid).Anchored ||

View File

@@ -14,6 +14,7 @@ using Robust.Shared.Map.Components;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Events;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
namespace Content.Server.Singularity.EntitySystems;
@@ -36,6 +37,8 @@ public sealed class EventHorizonSystem : SharedEventHorizonSystem
[Dependency] private readonly TagSystem _tagSystem = default!;
#endregion Dependencies
private static readonly ProtoId<TagPrototype> HighRiskItemTag = "HighRiskItem";
private EntityQuery<PhysicsComponent> _physicsQuery;
public override void Initialize()
@@ -127,7 +130,7 @@ public sealed class EventHorizonSystem : SharedEventHorizonSystem
return;
if (HasComp<MindContainerComponent>(morsel)
|| _tagSystem.HasTag(morsel, "HighRiskItem")
|| _tagSystem.HasTag(morsel, HighRiskItemTag)
|| HasComp<ContainmentFieldGeneratorComponent>(morsel))
{
_adminLogger.Add(LogType.EntityDelete, LogImpact.High, $"{ToPrettyString(morsel):player} entered the event horizon of {ToPrettyString(hungry)} and was deleted");

View File

@@ -8,6 +8,7 @@ using Content.Shared.Interaction.Components;
using Content.Shared.Storage;
using Content.Shared.Tag;
using Robust.Shared.Network;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
namespace Content.Server.Tools.Innate;
@@ -22,6 +23,8 @@ public sealed class InnateToolSystem : EntitySystem
[Dependency] private readonly SharedHandsSystem _sharedHandsSystem = default!;
[Dependency] private readonly TagSystem _tagSystem = default!;
private static readonly ProtoId<TagPrototype> InnateDontDeleteTag = "InnateDontDelete";
public override void Initialize()
{
base.Initialize();
@@ -76,7 +79,7 @@ public sealed class InnateToolSystem : EntitySystem
{
foreach (var tool in component.ToolUids)
{
if (_tagSystem.HasTag(tool, "InnateDontDelete"))
if (_tagSystem.HasTag(tool, InnateDontDeleteTag))
{
RemComp<UnremoveableComponent>(tool);
}

View File

@@ -36,6 +36,7 @@ using Content.Shared.Traits.Assorted;
using Robust.Shared.Audio.Systems;
using Content.Shared.Ghost.Roles.Components;
using Content.Shared.Tag;
using Robust.Shared.Prototypes;
namespace Content.Server.Zombies;
@@ -61,6 +62,8 @@ public sealed partial class ZombieSystem
[Dependency] private readonly TagSystem _tag = default!;
[Dependency] private readonly NameModifierSystem _nameMod = default!;
private static readonly ProtoId<TagPrototype> InvalidForGlobalSpawnSpellTag = "InvalidForGlobalSpawnSpell";
/// <summary>
/// Handles an entity turning into a zombie when they die or go into crit
/// </summary>
@@ -290,6 +293,6 @@ public sealed partial class ZombieSystem
//Need to prevent them from getting an item, they have no hands.
// Also prevents them from becoming a Survivor. They're undead.
_tag.AddTag(target, "InvalidForGlobalSpawnSpell");
_tag.AddTag(target, InvalidForGlobalSpawnSpellTag);
}
}