LocalRotation normalize + obsolete setter (#125)

This commit is contained in:
metalgearsloth
2026-06-21 16:08:30 +10:00
committed by GitHub
parent 3c77bfde67
commit e568c7ba78
4 changed files with 49 additions and 4 deletions
@@ -45,7 +45,7 @@ public abstract partial class SharedTransformSystem
var oldRot = xform._localRotation;
var oldMap = xform.MapUid;
xform._localPosition = tilePos + newGrid.TileSizeHalfVector;
xform._localRotation += rotation;
xform._localRotation = NormalizeRotation(xform._localRotation + rotation);
var meta = MetaData(uid);
SetGridId((uid, xform, meta), newGridUid);
@@ -437,6 +437,11 @@ public abstract partial class SharedTransformSystem
#region Local Rotation
internal static Angle NormalizeRotation(Angle rotation)
{
return rotation.Reduced();
}
public void SetLocalRotationNoLerp(EntityUid uid, Angle value, TransformComponent? xform = null)
{
if (!XformQuery.Resolve(uid, ref xform))
@@ -457,6 +462,27 @@ public abstract partial class SharedTransformSystem
#endregion
#region No Local Rotation
public void SetNoLocalRotation(EntityUid uid, bool value, TransformComponent? xform = null)
{
if (!XformQuery.Resolve(uid, ref xform))
return;
SetNoLocalRotation((uid, xform), value);
}
public void SetNoLocalRotation(Entity<TransformComponent> entity, bool value)
{
if (value)
SetLocalRotation(entity.Owner, Angle.Zero, entity.Comp);
entity.Comp._noLocalRotation = value;
Dirty(entity);
}
#endregion
#region Coordinates
public void SetCoordinates(EntityUid uid, EntityCoordinates value)
@@ -519,7 +545,7 @@ public abstract partial class SharedTransformSystem
xform._localPosition = value.Position;
if (rotation != null && !xform.NoLocalRotation)
xform._localRotation = rotation.Value;
xform._localRotation = NormalizeRotation(rotation.Value);
DebugTools.Assert(!xform.NoLocalRotation || xform.LocalRotation == 0);
@@ -621,7 +647,7 @@ public abstract partial class SharedTransformSystem
{
// preserve world rotation
if (rotation == null && oldParent != null && newParent != null && !xform.NoLocalRotation)
xform._localRotation += GetWorldRotation(oldParent) - GetWorldRotation(newParent);
xform._localRotation = NormalizeRotation(xform._localRotation + GetWorldRotation(oldParent) - GetWorldRotation(newParent));
DebugTools.Assert(!xform.NoLocalRotation || xform.LocalRotation == 0);
}
@@ -1277,7 +1303,7 @@ public abstract partial class SharedTransformSystem
xform._localPosition = pos;
if (!xform.NoLocalRotation)
xform._localRotation = rot;
xform._localRotation = NormalizeRotation(rot);
DebugTools.Assert(!xform.NoLocalRotation || xform.LocalRotation == 0);