Skip to content

Commit

Permalink
Add methods to get entity sprite position
Browse files Browse the repository at this point in the history
No easy way to get this in world-terms and I want a control to track it.
  • Loading branch information
metalgearsloth committed Aug 22, 2024
1 parent f03c006 commit ee5c535
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Robust.Client/GameObjects/EntitySystems/SpriteSystem.Helpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.Numerics;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;

namespace Robust.Client.GameObjects;

public sealed partial class SpriteSystem
{
/// <summary>
/// Gets an entity's sprite position in world terms.
/// </summary>
public Vector2 GetSpriteWorldPosition(Entity<SpriteComponent?, TransformComponent?> entity)
{
if (!Resolve(entity, ref entity.Comp2))
return Vector2.Zero;

var (worldPos, worldRot) = _xforms.GetWorldPositionRotation(entity.Owner);

if (!Resolve(entity, ref entity.Comp1, false))
{
return worldPos;
}

if (entity.Comp1.NoRotation)
{
return worldPos + entity.Comp1.Offset;
}

return worldPos + worldRot.RotateVec(entity.Comp1.Rotation.RotateVec(entity.Comp1.Offset));
}

/// <summary>
/// Gets an entity's sprite position in screen coordinates.
/// </summary>
public ScreenCoordinates GetSpriteScreenCoordinates(Entity<SpriteComponent?, TransformComponent?> entity)
{
if (!Resolve(entity, ref entity.Comp2))
return ScreenCoordinates.Invalid;

var spriteCoords = GetSpriteWorldPosition(entity);
return _eye.MapToScreen(new MapCoordinates(spriteCoords, entity.Comp2.MapID));
}
}
2 changes: 2 additions & 0 deletions Robust.Client/GameObjects/EntitySystems/SpriteSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ namespace Robust.Client.GameObjects
public sealed partial class SpriteSystem : EntitySystem
{
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IEyeManager _eye = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly IResourceCache _resourceCache = default!;
[Dependency] private readonly ILogManager _logManager = default!;
[Dependency] private readonly SharedTransformSystem _xforms = default!;

private readonly Queue<SpriteComponent> _inertUpdateQueue = new();

Expand Down

0 comments on commit ee5c535

Please sign in to comment.