forked from space-wizards/RobustToolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add methods to get entity sprite position
No easy way to get this in world-terms and I want a control to track it.
- Loading branch information
1 parent
f03c006
commit ee5c535
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
Robust.Client/GameObjects/EntitySystems/SpriteSystem.Helpers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters