Fix rotated pipe connection visuals (#6756)

This commit is contained in:
Leon Friedrich
2022-02-18 10:31:11 +13:00
committed by GitHub
parent 4567b4f597
commit 3ba55d0798
9 changed files with 23 additions and 18 deletions

View File

@@ -37,8 +37,9 @@ public sealed class AtmosPipeAppearanceSystem : EntitySystem
sprite.LayerMapReserveBlank(layerKey); sprite.LayerMapReserveBlank(layerKey);
var layer = sprite.LayerMapGet(layerKey); var layer = sprite.LayerMapGet(layerKey);
sprite.LayerSetRSI(layer, rsi.RSI); sprite.LayerSetRSI(layer, rsi.RSI);
var layerState = component.BaseState + (PipeDirection) layerKey; var layerState = component.State;
sprite.LayerSetState(layer, layerState); sprite.LayerSetState(layer, layerState);
sprite.LayerSetDirOffset(layer, ToOffset(layerKey));
} }
} }
@@ -50,11 +51,12 @@ public sealed class AtmosPipeAppearanceSystem : EntitySystem
if (!args.Component.TryGetData(PipeColorVisuals.Color, out Color color)) if (!args.Component.TryGetData(PipeColorVisuals.Color, out Color color))
color = Color.White; color = Color.White;
if (!args.Component.TryGetData(PipeVisuals.VisualState, out PipeDirection connectedDirections)) if (!args.Component.TryGetData(PipeVisuals.VisualState, out PipeDirection worldConnectedDirections))
return; return;
var rotation = Transform(uid).LocalRotation; // transform connected directions to local-coordinates
var connectedDirections = worldConnectedDirections.RotatePipeDirection(-Transform(uid).LocalRotation);
foreach (PipeConnectionLayer layerKey in Enum.GetValues(typeof(PipeConnectionLayer))) foreach (PipeConnectionLayer layerKey in Enum.GetValues(typeof(PipeConnectionLayer)))
{ {
if (!sprite.LayerMapTryGet(layerKey, out var key)) if (!sprite.LayerMapTryGet(layerKey, out var key))
@@ -68,11 +70,21 @@ public sealed class AtmosPipeAppearanceSystem : EntitySystem
if (!visible) continue; if (!visible) continue;
layer.Rotation = -rotation;
layer.Color = color; layer.Color = color;
} }
} }
private SpriteComponent.DirectionOffset ToOffset(PipeConnectionLayer layer)
{
return layer switch
{
PipeConnectionLayer.NorthConnection => SpriteComponent.DirectionOffset.Flip,
PipeConnectionLayer.EastConnection => SpriteComponent.DirectionOffset.CounterClockwise,
PipeConnectionLayer.WestConnection => SpriteComponent.DirectionOffset.Clockwise,
_ => SpriteComponent.DirectionOffset.None,
};
}
private enum PipeConnectionLayer : byte private enum PipeConnectionLayer : byte
{ {
NorthConnection = PipeDirection.North, NorthConnection = PipeDirection.North,

View File

@@ -7,5 +7,5 @@ public sealed class PipeAppearanceComponent : Component
public string RsiPath = "Structures/Piping/Atmospherics/pipe.rsi"; public string RsiPath = "Structures/Piping/Atmospherics/pipe.rsi";
[DataField("baseState")] [DataField("baseState")]
public string BaseState = "pipeConnector"; public string State = "pipeConnector";
} }

View File

@@ -20,23 +20,16 @@
"directions":4 "directions":4
}, },
{ {
"name":"pipeFourway", "name": "pipeFourway",
"directions":4
}, },
{ {
"name":"pipeStraight", "name":"pipeStraight",
"directions":4 "directions":4
}, },
{ {
"name":"pipeConnectorSouth", "name":"pipeConnector",
}, "directions":4
{
"name":"pipeConnectorNorth",
},
{
"name":"pipeConnectorEast",
},
{
"name":"pipeConnectorWest",
} }
] ]
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB