Skip to content

Commit

Permalink
Resolve 'TransformComponent.MapPosition' is obsolete in content (#2…
Browse files Browse the repository at this point in the history
…7939)

* Resolve `'TransformComponent.MapPosition' is obsolete: 'Use TransformSystem.GetMapCoordinates'` in content

* build?
  • Loading branch information
mirrorcult authored May 12, 2024
1 parent 8938e1d commit 855234a
Show file tree
Hide file tree
Showing 59 changed files with 152 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using JetBrains.Annotations;
using Robust.Client.AutoGenerated;
using Robust.Client.Console;
using Robust.Client.GameObjects;
using Robust.Client.Player;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
Expand All @@ -22,7 +23,7 @@ public sealed partial class SpawnExplosionWindow : DefaultWindow
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IEntityManager _entMan = default!;

private readonly SharedTransformSystem _transform = default!;

private readonly SpawnExplosionEui _eui;
private List<MapId> _mapData = new();
Expand All @@ -37,6 +38,7 @@ public SpawnExplosionWindow(SpawnExplosionEui eui)
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_transform = _entMan.System<TransformSystem>();
_eui = eui;

ExplosionOption.OnItemSelected += ExplosionSelected;
Expand Down Expand Up @@ -104,7 +106,7 @@ private void SetLocation()

_pausePreview = true;
MapOptions.Select(_mapData.IndexOf(transform.MapID));
(MapX.Value, MapY.Value) = transform.MapPosition.Position;
(MapX.Value, MapY.Value) = _transform.GetMapCoordinates(_playerManager.LocalEntity!.Value, xform: transform).Position;
_pausePreview = false;

UpdatePreview();
Expand Down
5 changes: 4 additions & 1 deletion Content.Client/GPS/UI/HandheldGpsStatusControl.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Content.Client.GPS.Components;
using Content.Client.Message;
using Content.Client.Stylesheets;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Timing;
Expand All @@ -13,11 +14,13 @@ public sealed class HandheldGpsStatusControl : Control
private readonly RichTextLabel _label;
private float _updateDif;
private readonly IEntityManager _entMan;
private readonly SharedTransformSystem _transform;

public HandheldGpsStatusControl(Entity<HandheldGPSComponent> parent)
{
_parent = parent;
_entMan = IoCManager.Resolve<IEntityManager>();
_transform = _entMan.System<TransformSystem>();
_label = new RichTextLabel { StyleClasses = { StyleNano.StyleClassItemStatus } };
AddChild(_label);
UpdateGpsDetails();
Expand All @@ -41,7 +44,7 @@ private void UpdateGpsDetails()
var posText = "Error";
if (_entMan.TryGetComponent(_parent, out TransformComponent? transComp))
{
var pos = transComp.MapPosition;
var pos = _transform.GetMapCoordinates(_parent.Owner, xform: transComp);
var x = (int) pos.X;
var y = (int) pos.Y;
posText = $"({x}, {y})";
Expand Down
3 changes: 2 additions & 1 deletion Content.Client/MouseRotator/MouseRotatorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.Player;
using Robust.Client.Replays.Loading;
using Robust.Shared.Map;
using Robust.Shared.Timing;

Expand Down Expand Up @@ -37,7 +38,7 @@ public override void Update(float frameTime)
if (mapPos.MapId == MapId.Nullspace)
return;

var angle = (mapPos.Position - xform.MapPosition.Position).ToWorldAngle();
var angle = (mapPos.Position - _transform.GetMapCoordinates(player.Value, xform: xform).Position).ToWorldAngle();

var curRot = _transform.GetWorldRotation(xform);

Expand Down
9 changes: 7 additions & 2 deletions Content.Client/Radiation/Overlays/RadiationPulseOverlay.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Numerics;
using Content.Shared.Radiation.Components;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Shared.Enums;
using Robust.Shared.Graphics;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;

Expand All @@ -14,6 +16,7 @@ public sealed class RadiationPulseOverlay : Overlay
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
private TransformSystem? _transform;

private const float MaxDist = 15.0f;

Expand Down Expand Up @@ -72,6 +75,8 @@ protected override void Draw(in OverlayDrawArgs args)
//Queries all pulses on the map and either adds or removes them from the list of rendered pulses based on whether they should be drawn (in range? on the same z-level/map? pulse entity still exists?)
private void RadiationQuery(IEye? currentEye)
{
_transform ??= _entityManager.System<TransformSystem>();

if (currentEye == null)
{
_pulses.Clear();
Expand All @@ -91,7 +96,7 @@ private void RadiationQuery(IEye? currentEye)
(
_baseShader.Duplicate(),
new RadiationShaderInstance(
_entityManager.GetComponent<TransformComponent>(pulseEntity).MapPosition,
_transform.GetMapCoordinates(pulseEntity),
pulse.VisualRange,
pulse.StartTime,
pulse.VisualDuration
Expand All @@ -109,7 +114,7 @@ private void RadiationQuery(IEye? currentEye)
_entityManager.TryGetComponent(pulseEntity, out RadiationPulseComponent? pulse))
{
var shaderInstance = _pulses[pulseEntity];
shaderInstance.instance.CurrentMapCoords = _entityManager.GetComponent<TransformComponent>(pulseEntity).MapPosition;
shaderInstance.instance.CurrentMapCoords = _transform.GetMapCoordinates(pulseEntity);
shaderInstance.instance.Range = pulse.VisualRange;
} else {
_pulses[pulseEntity].shd.Dispose();
Expand Down
4 changes: 3 additions & 1 deletion Content.Client/Sprite/SpriteFadeSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Robust.Client.GameObjects;
using Robust.Client.Player;
using Robust.Client.State;
using Robust.Shared.Physics;

namespace Content.Client.Sprite;

Expand All @@ -15,6 +16,7 @@ public sealed class SpriteFadeSystem : EntitySystem

[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IStateManager _stateManager = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;

private readonly HashSet<FadingSpriteComponent> _comps = new();

Expand Down Expand Up @@ -48,7 +50,7 @@ _stateManager.CurrentState is GameplayState state &&
spriteQuery.TryGetComponent(player, out var playerSprite))
{
var fadeQuery = GetEntityQuery<SpriteFadeComponent>();
var mapPos = playerXform.MapPosition;
var mapPos = _transform.GetMapCoordinates(_playerManager.LocalEntity!.Value, xform: playerXform);

// Also want to handle large entities even if they may not be clickable.
foreach (var ent in state.GetClickableEntities(mapPos))
Expand Down
5 changes: 3 additions & 2 deletions Content.Client/Tabletop/TabletopSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ private void StopDragging(bool broadcast = true)
// Set the dragging player on the component to noone
if (broadcast && _draggedEntity != null && EntityManager.HasComponent<TabletopDraggableComponent>(_draggedEntity.Value))
{
RaisePredictiveEvent(new TabletopMoveEvent(GetNetEntity(_draggedEntity.Value), Transform(_draggedEntity.Value).MapPosition, GetNetEntity(_table!.Value)));
RaisePredictiveEvent(new TabletopMoveEvent(GetNetEntity(_draggedEntity.Value), Transforms.GetMapCoordinates(_draggedEntity.Value), GetNetEntity(_table!.Value)));
RaisePredictiveEvent(new TabletopDraggingPlayerChangedEvent(GetNetEntity(_draggedEntity.Value), false));
}

Expand All @@ -277,7 +277,8 @@ private static MapCoordinates ClampPositionToViewport(MapCoordinates coordinates
if (coordinates == MapCoordinates.Nullspace) return MapCoordinates.Nullspace;

var eye = viewport.Eye;
if (eye == null) return MapCoordinates.Nullspace;
if (eye == null)
return MapCoordinates.Nullspace;

var size = (Vector2) viewport.ViewportSize / EyeManager.PixelsPerMeter; // Convert to tiles instead of pixels
var eyePosition = eye.Position.Position;
Expand Down
5 changes: 3 additions & 2 deletions Content.Client/UserInterface/Systems/Chat/ChatUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public sealed class ChatUIController : UIController
[UISystemDependency] private readonly GhostSystem? _ghost = default;
[UISystemDependency] private readonly TypingIndicatorSystem? _typingIndicator = default;
[UISystemDependency] private readonly ChatSystem? _chatSys = default;
[UISystemDependency] private readonly TransformSystem? _transform = default;

[ValidatePrototypeId<ColorPalettePrototype>]
private const string ChatNamePalette = "ChatNames";
Expand Down Expand Up @@ -625,7 +626,7 @@ private void UpdateQueuedSpeechBubbles(FrameEventArgs delta)
var predicate = static (EntityUid uid, (EntityUid compOwner, EntityUid? attachedEntity) data)
=> uid == data.compOwner || uid == data.attachedEntity;
var playerPos = player != null
? EntityManager.GetComponent<TransformComponent>(player.Value).MapPosition
? _transform?.GetMapCoordinates(player.Value) ?? MapCoordinates.Nullspace
: MapCoordinates.Nullspace;

var occluded = player != null && _examine.IsOccluded(player.Value);
Expand All @@ -644,7 +645,7 @@ private void UpdateQueuedSpeechBubbles(FrameEventArgs delta)
continue;
}

var otherPos = EntityManager.GetComponent<TransformComponent>(ent).MapPosition;
var otherPos = _transform?.GetMapCoordinates(ent) ?? MapCoordinates.Nullspace;

if (occluded && !_examine.InRangeUnOccluded(
playerPos,
Expand Down
5 changes: 3 additions & 2 deletions Content.Client/Verbs/VerbSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public sealed class VerbSystem : SharedVerbSystem
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly ExamineSystem _examine = default!;
[Dependency] private readonly TagSystem _tagSystem = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly IStateManager _stateManager = default!;
[Dependency] private readonly EntityLookupSystem _entityLookup = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
Expand Down Expand Up @@ -141,15 +142,15 @@ public bool TryGetEntityMenuEntities(MapCoordinates targetPos, [NotNullWhen(true
if ((visibility & MenuVisibility.NoFov) == 0)
{
var xformQuery = GetEntityQuery<TransformComponent>();
var playerPos = xformQuery.GetComponent(player.Value).MapPosition;
var playerPos = _transform.GetMapCoordinates(player.Value, xform: xformQuery.GetComponent(player.Value));

for (var i = entities.Count - 1; i >= 0; i--)
{
var entity = entities[i];

if (!_examine.InRangeUnOccluded(
playerPos,
xformQuery.GetComponent(entity).MapPosition,
_transform.GetMapCoordinates(entity, xform: xformQuery.GetComponent(entity)),
ExamineSystemShared.ExamineRange,
null))
{
Expand Down
6 changes: 4 additions & 2 deletions Content.Client/Weapons/Melee/MeleeArcOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ public sealed class MeleeArcOverlay : Overlay
private readonly IPlayerManager _playerManager;
private readonly MeleeWeaponSystem _melee;
private readonly SharedCombatModeSystem _combatMode;
private readonly SharedTransformSystem _transform = default!;

public override OverlaySpace Space => OverlaySpace.WorldSpaceBelowFOV;

public MeleeArcOverlay(IEntityManager entManager, IEyeManager eyeManager, IInputManager inputManager, IPlayerManager playerManager, MeleeWeaponSystem melee, SharedCombatModeSystem combatMode)
public MeleeArcOverlay(IEntityManager entManager, IEyeManager eyeManager, IInputManager inputManager, IPlayerManager playerManager, MeleeWeaponSystem melee, SharedCombatModeSystem combatMode, SharedTransformSystem transform)
{
_entManager = entManager;
_eyeManager = eyeManager;
_inputManager = inputManager;
_playerManager = playerManager;
_melee = melee;
_combatMode = combatMode;
_transform = transform;
}

protected override void Draw(in OverlayDrawArgs args)
Expand All @@ -52,7 +54,7 @@ protected override void Draw(in OverlayDrawArgs args)
if (mapPos.MapId != args.MapId)
return;

var playerPos = xform.MapPosition;
var playerPos = _transform.GetMapCoordinates(player.Value, xform: xform);

if (mapPos.MapId != playerPos.MapId)
return;
Expand Down
3 changes: 2 additions & 1 deletion Content.Client/Weapons/Melee/MeleeSpreadCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)
collection.Resolve<IInputManager>(),
collection.Resolve<IPlayerManager>(),
sysManager.GetEntitySystem<MeleeWeaponSystem>(),
sysManager.GetEntitySystem<SharedCombatModeSystem>()));
sysManager.GetEntitySystem<SharedCombatModeSystem>(),
sysManager.GetEntitySystem<SharedTransformSystem>()));
}
}
2 changes: 1 addition & 1 deletion Content.Client/Weapons/Melee/MeleeWeaponSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public override void Update(float frameTime)
// Light attack
if (useDown == BoundKeyState.Down)
{
var attackerPos = Transform(entity).MapPosition;
var attackerPos = TransformSystem.GetMapCoordinates(entity);

if (mousePos.MapId != attackerPos.MapId ||
(attackerPos.Position - mousePos.Position).Length() > weapon.Range)
Expand Down
6 changes: 4 additions & 2 deletions Content.Client/Weapons/Ranged/GunSpreadOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ public sealed class GunSpreadOverlay : Overlay
private readonly IInputManager _input;
private readonly IPlayerManager _player;
private readonly GunSystem _guns;
private readonly SharedTransformSystem _transform;

public GunSpreadOverlay(IEntityManager entManager, IEyeManager eyeManager, IGameTiming timing, IInputManager input, IPlayerManager player, GunSystem system)
public GunSpreadOverlay(IEntityManager entManager, IEyeManager eyeManager, IGameTiming timing, IInputManager input, IPlayerManager player, GunSystem system, SharedTransformSystem transform)
{
_entManager = entManager;
_eye = eyeManager;
_input = input;
_timing = timing;
_player = player;
_guns = system;
_transform = transform;
}

protected override void Draw(in OverlayDrawArgs args)
Expand All @@ -41,7 +43,7 @@ protected override void Draw(in OverlayDrawArgs args)
return;
}

var mapPos = xform.MapPosition;
var mapPos = _transform.GetMapCoordinates(player.Value, xform: xform);

if (mapPos.MapId == MapId.Nullspace)
return;
Expand Down
3 changes: 2 additions & 1 deletion Content.Client/Weapons/Ranged/Systems/GunSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public bool SpreadOverlay
Timing,
_inputManager,
_player,
this));
this,
TransformSystem));
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion Content.IntegrationTests/Tests/Doors/AirlockTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ await server.WaitPost(() =>
// Sloth: Okay I'm sorry but I hate having to rewrite tests for every refactor
// If you see this yell at me in discord so I can continue to pretend this didn't happen.
// REMINDER THAT I STILL HAVE TO FIX THIS TEST EVERY OTHER PHYSICS PR
// Assert.That(AirlockPhysicsDummy.Transform.MapPosition.X, Is.GreaterThan(AirlockPhysicsDummyStartingX));
// _transform.GetMapCoordinates(UID HERE, xform: Assert.That(AirlockPhysicsDummy.Transform).X, Is.GreaterThan(AirlockPhysicsDummyStartingX));

// Blocked by the airlock
await server.WaitAssertion(() =>
Expand Down
4 changes: 3 additions & 1 deletion Content.IntegrationTests/Tests/Hands/HandTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Linq;
using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems;
using Robust.Server.GameObjects;
using Robust.Server.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
Expand All @@ -24,6 +25,7 @@ public async Task TestPickupDrop()
var playerMan = server.ResolveDependency<IPlayerManager>();
var mapMan = server.ResolveDependency<IMapManager>();
var sys = entMan.System<SharedHandsSystem>();
var tSys = entMan.System<TransformSystem>();

var data = await pair.CreateTestMap();
await pair.RunTicksSync(5);
Expand All @@ -35,7 +37,7 @@ await server.WaitPost(() =>
{
player = playerMan.Sessions.First().AttachedEntity!.Value;
var xform = entMan.GetComponent<TransformComponent>(player);
item = entMan.SpawnEntity("Crowbar", xform.MapPosition);
item = entMan.SpawnEntity("Crowbar", tSys.GetMapCoordinates(player, xform: xform));
hands = entMan.GetComponent<HandsComponent>(player);
sys.TryPickup(player, item, hands.ActiveHand!);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Numerics;
using Content.Shared.Interaction;
using Robust.Server.GameObjects;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
Expand Down Expand Up @@ -32,6 +33,7 @@ public async Task EntityEntityTest()
var sEntities = server.ResolveDependency<IEntityManager>();
var mapManager = server.ResolveDependency<IMapManager>();
var conSystem = sEntities.EntitySysManager.GetEntitySystem<SharedContainerSystem>();
var tSystem = sEntities.EntitySysManager.GetEntitySystem<TransformSystem>();

EntityUid origin = default;
EntityUid other = default;
Expand All @@ -45,7 +47,7 @@ await server.WaitAssertion(() =>
origin = sEntities.SpawnEntity(HumanId, coordinates);
other = sEntities.SpawnEntity(HumanId, coordinates);
conSystem.EnsureContainer<Container>(other, "InRangeUnobstructedTestOtherContainer");
mapCoordinates = sEntities.GetComponent<TransformComponent>(other).MapPosition;
mapCoordinates = tSystem.GetMapCoordinates(other);
});

await server.WaitIdleAsync();
Expand Down
3 changes: 2 additions & 1 deletion Content.Server/Administration/Commands/ExplosionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Robust.Shared.Prototypes;
using System.Linq;
using System.Numerics;
using Robust.Server.GameObjects;

namespace Content.Server.Administration.Commands;

Expand Down Expand Up @@ -105,7 +106,7 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)
if (args.Length > 4)
coords = new MapCoordinates(new Vector2(x, y), xform.MapID);
else
coords = xform.MapPosition;
coords = entMan.System<TransformSystem>().GetMapCoordinates(shell.Player.AttachedEntity.Value, xform: xform);
}

ExplosionPrototype? type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private void AddSmiteVerbs(GetVerbsEvent<Verb> args)
Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/smite.svg.192dpi.png")),
Act = () =>
{
var coords = Transform(args.Target).MapPosition;
var coords = _transformSystem.GetMapCoordinates(args.Target);
Timer.Spawn(_gameTiming.TickPeriod,
() => _explosionSystem.QueueExplosion(coords, ExplosionSystem.DefaultExplosionPrototypeId,
4, 1, 2, maxTileBreak: 0), // it gibs, damage doesn't need to be high.
Expand Down
Loading

0 comments on commit 855234a

Please sign in to comment.