Make OffsetRsiDir() and GetDir() public (#2434)

This commit is contained in:
Leon Friedrich
2022-01-31 21:22:56 +13:00
committed by GitHub
parent 53c7ec8ddc
commit f13f9dc5cd
2 changed files with 62 additions and 72 deletions

View File

@@ -1477,30 +1477,6 @@ namespace Robust.Client.GameObjects
}
}
private RSI.State.Direction GetDir(RSI.State.DirectionType rsiDirectionType, Angle worldRotation)
{
var dir = rsiDirectionType switch
{
RSI.State.DirectionType.Dir1 => Direction.South,
RSI.State.DirectionType.Dir4 => worldRotation.GetCardinalDir(),
RSI.State.DirectionType.Dir8 => worldRotation.GetDir(),
_ => throw new ArgumentException($"Unknown RSI DirectionType: {rsiDirectionType}.", nameof(rsiDirectionType))
};
return dir switch
{
Direction.North => RSI.State.Direction.North,
Direction.South => RSI.State.Direction.South,
Direction.East => RSI.State.Direction.East,
Direction.West => RSI.State.Direction.West,
Direction.SouthEast => RSI.State.Direction.SouthEast,
Direction.SouthWest => RSI.State.Direction.SouthWest,
Direction.NorthEast => RSI.State.Direction.NorthEast,
Direction.NorthWest => RSI.State.Direction.NorthWest,
_ => throw new ArgumentOutOfRangeException(nameof(dir), dir, null)
};
}
private void QueueUpdateIsInert()
{
// Look this was an easy way to get bounds checks for layer updates.
@@ -1550,58 +1526,13 @@ namespace Robust.Client.GameObjects
return rsi["error"];
}
private static RSI.State.Direction OffsetRsiDir(RSI.State.Direction dir, DirectionOffset offset)
{
// There is probably a better way to do this.
// Eh.
switch (offset)
{
case DirectionOffset.None:
return dir;
case DirectionOffset.Clockwise:
return dir switch
{
RSI.State.Direction.North => RSI.State.Direction.East,
RSI.State.Direction.East => RSI.State.Direction.South,
RSI.State.Direction.South => RSI.State.Direction.West,
RSI.State.Direction.West => RSI.State.Direction.North,
_ => throw new NotImplementedException()
};
case DirectionOffset.CounterClockwise:
return dir switch
{
RSI.State.Direction.North => RSI.State.Direction.West,
RSI.State.Direction.East => RSI.State.Direction.North,
RSI.State.Direction.South => RSI.State.Direction.East,
RSI.State.Direction.West => RSI.State.Direction.South,
_ => throw new NotImplementedException()
};
case DirectionOffset.Flip:
switch (dir)
{
case RSI.State.Direction.North:
return RSI.State.Direction.South;
case RSI.State.Direction.East:
return RSI.State.Direction.West;
case RSI.State.Direction.South:
return RSI.State.Direction.North;
case RSI.State.Direction.West:
return RSI.State.Direction.East;
default:
throw new NotImplementedException();
}
default:
throw new NotImplementedException();
}
}
public string GetDebugString()
{
var builder = new StringBuilder();
builder.AppendFormat(
"vis/depth/scl/rot/ofs/col/norot/override/dir: {0}/{1}/{2}/{3}/{4}/{5}/{6}/{8}/{7}\n",
Visible, DrawDepth, Scale, Rotation, Offset,
Color, NoRotation, GetDir(RSI.State.DirectionType.Dir8, entities.GetComponent<TransformComponent>(Owner).WorldRotation),
Color, NoRotation, entities.GetComponent<TransformComponent>(Owner).WorldRotation.ToRsiDirection(RSI.State.DirectionType.Dir8),
DirectionOverride
);
@@ -1842,10 +1773,10 @@ namespace Robust.Client.GameObjects
}
else
{
dir = _parent.GetDir(state.Directions, worldRotation);
dir = worldRotation.ToRsiDirection(state.Directions);
}
return OffsetRsiDir(dir, DirOffset);
return dir.OffsetRsiDir(DirOffset);
}
}

View File

@@ -1,6 +1,7 @@
using System;
using Robust.Client.Graphics;
using Robust.Shared.Maths;
using static Robust.Client.GameObjects.SpriteComponent;
using RSIDirection = Robust.Client.Graphics.RSI.State.Direction;
namespace Robust.Client.Utility
@@ -109,5 +110,63 @@ namespace Robust.Client.Utility
{
return (Direction)(((int)dir + 1) % 8);
}
public static RSIDirection ToRsiDirection(this Angle angle, RSI.State.DirectionType type)
{
return type switch
{
RSI.State.DirectionType.Dir1 => RSIDirection.South,
RSI.State.DirectionType.Dir4 or RSI.State.DirectionType.Dir8 => angle.GetDir().Convert(type),
_ => throw new ArgumentOutOfRangeException($"Unknown rsi direction type: {type}.", nameof(type))
};
}
public static RSIDirection OffsetRsiDir(this RSIDirection dir, DirectionOffset offset)
{
// There is probably a better way to do this.
// Eh.
//
// Maybe convert RSI direction to a direction and use the much more elegant solution in `TurnCw()` functions?
// but that conversion would probably be slower than this, even though its a mess to read.
switch (offset)
{
case DirectionOffset.None:
return dir;
case DirectionOffset.Clockwise:
return dir switch
{
RSIDirection.North => RSIDirection.East,
RSIDirection.East => RSIDirection.South,
RSIDirection.South => RSIDirection.West,
RSIDirection.West => RSIDirection.North,
_ => throw new NotImplementedException()
};
case DirectionOffset.CounterClockwise:
return dir switch
{
RSIDirection.North => RSIDirection.West,
RSIDirection.East => RSIDirection.North,
RSIDirection.South => RSIDirection.East,
RSIDirection.West => RSIDirection.South,
_ => throw new NotImplementedException()
};
case DirectionOffset.Flip:
switch (dir)
{
case RSIDirection.North:
return RSIDirection.South;
case RSIDirection.East:
return RSIDirection.West;
case RSIDirection.South:
return RSIDirection.North;
case RSIDirection.West:
return RSIDirection.East;
default:
throw new NotImplementedException();
}
default:
throw new NotImplementedException();
}
}
}
}