Pipe prototypes (#2124)

* Pipe prototypes

* PipeDirection setter

* IRotatableNode

* NodeContainer passes rotation events to its nodes

* Removes duplicate pipe prototypes that are rotations of each other

* PipeDirectionHelpers

* PipeNode rotation

* icon removal

* Pipe icons

* Icon fix

* Fixes pipe sprites and icons

Co-authored-by: py01 <pyronetics01@gmail.com>
This commit is contained in:
py01
2020-10-08 09:53:56 -06:00
committed by GitHub
parent 621a39016f
commit 970f3bc82f
47 changed files with 278 additions and 296 deletions

View File

@@ -2,67 +2,44 @@
using Content.Shared.GameObjects.Components.Atmos;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Interfaces.GameObjects.Components;
using Robust.Client.Interfaces.ResourceManagement;
using Robust.Client.ResourceManagement;
using Robust.Shared.GameObjects.Components.Renderable;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Utility;
using YamlDotNet.RepresentationModel;
using Robust.Shared.Interfaces.GameObjects;
namespace Content.Client.GameObjects.Components.Atmos
{
[UsedImplicitly]
public class PipeVisualizer : AppearanceVisualizer
{
private RSI _pipeRSI;
public override void LoadData(YamlMappingNode node)
public override void InitializeEntity(IEntity entity)
{
base.LoadData(node);
var rsiString = node.GetNode("pipeRSI").ToString();
var rsiPath = SharedSpriteComponent.TextureRoot / rsiString;
try
{
var resourceCache = IoCManager.Resolve<IResourceCache>();
var resource = resourceCache.GetResource<RSIResource>(rsiPath);
_pipeRSI = resource.RSI;
}
catch (Exception e)
{
Logger.ErrorS("go.pipevisualizer", "Unable to load RSI '{0}'. Trace:\n{1}", rsiPath, e);
}
base.InitializeEntity(entity);
if (!entity.TryGetComponent(out ISpriteComponent sprite)) return;
sprite.LayerMapReserveBlank(Layer.PipeBase);
var pipeBaseLayer = sprite.LayerMapGet(Layer.PipeBase);
sprite.LayerSetVisible(pipeBaseLayer, true);
}
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);
if (!component.Owner.TryGetComponent(out ISpriteComponent sprite)) return;
if (!component.TryGetData(PipeVisuals.VisualState, out PipeVisualState pipeVisualState)) return;
var pipeBase = sprite.LayerMapGet(Layer.PipeBase);
var pipeBaseStateId = GetPipeBaseStateId(pipeVisualState);
sprite.LayerSetState(pipeBase, pipeBaseStateId);
}
if (!component.Owner.TryGetComponent(out ISpriteComponent sprite))
{
return;
}
if (!component.TryGetData(PipeVisuals.VisualState, out PipeVisualStateSet pipeVisualStateSet))
{
return;
}
for (var i = 0; i < pipeVisualStateSet.PipeVisualStates.Length; i++)
{
var pipeVisualState = pipeVisualStateSet.PipeVisualStates[i];
var rsiState = "pipe";
rsiState += pipeVisualState.PipeDirection.ToString();
rsiState += ((int) pipeVisualState.ConduitLayer).ToString();
private string GetPipeBaseStateId(PipeVisualState pipeVisualState)
{
var stateId = "pipe";
stateId += pipeVisualState.PipeDirection.PipeDirectionToPipeShape().ToString();
stateId += (int) pipeVisualState.ConduitLayer;
return stateId;
}
var pipeLayerKey = "pipeLayer" + i.ToString();
sprite.LayerMapReserveBlank(pipeLayerKey);
var currentPipeLayer = sprite.LayerMapGet(pipeLayerKey);
sprite.LayerSetRSI(currentPipeLayer, _pipeRSI);
sprite.LayerSetState(currentPipeLayer, rsiState);
sprite.LayerSetVisible(currentPipeLayer, true);
}
private enum Layer
{
PipeBase,
}
}
}

View File

@@ -1,6 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Transform;
using Robust.Shared.Maths;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
@@ -31,6 +34,8 @@ namespace Content.Server.GameObjects.Components.NodeContainer
{
node.Initialize(Owner);
}
Owner.EntityManager.EventBus.SubscribeEvent<RotateEvent>(EventSource.Local, this, RotateEvent);
}
protected override void Startup()
@@ -50,5 +55,16 @@ namespace Content.Server.GameObjects.Components.NodeContainer
}
base.OnRemove();
}
private void RotateEvent(RotateEvent ev)
{
if (ev.Sender != Owner || ev.NewRotation == ev.OldRotation)
return;
foreach (var rotatableNode in Nodes.OfType<IRotatableNode>())
{
rotatableNode.RotateEvent(ev);
}
}
}
}

View File

@@ -0,0 +1,16 @@
using Robust.Shared.GameObjects.Components.Transform;
namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
{
/// <summary>
/// A <see cref="Node"/> that implements this will have its <see cref="RotateEvent(RotateEvent)"/> called when its
/// <see cref="NodeContainerComponent"/> is rotated.
/// </summary>
public interface IRotatableNode
{
/// <summary>
/// Rotates this <see cref="Node"/>.
/// </summary>
void RotateEvent(RotateEvent ev);
}
}

View File

@@ -106,6 +106,14 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
_needsGroup = true;
}
protected void RefreshNodeGroup()
{
NodeGroup.RemoveNode(this);
ClearNodeGroup();
TryAssignGroupIfNeeded();
CombineGroupWithReachable();
}
/// <summary>
/// How this node will attempt to find other reachable <see cref="Node"/>s to group with.
/// Returns a set of <see cref="Node"/>s to consider grouping with. Should not return this current <see cref="Node"/>.

View File

@@ -18,10 +18,10 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
/// Connects with other <see cref="PipeNode"/>s whose <see cref="PipeNode.PipeDirection"/>
/// correctly correspond.
/// </summary>
public class PipeNode : Node, IGasMixtureHolder
public class PipeNode : Node, IGasMixtureHolder, IRotatableNode
{
[ViewVariables]
public PipeDirection PipeDirection => _pipeDirection;
public PipeDirection PipeDirection { get => _pipeDirection; set => SetPipeDirection(value); }
private PipeDirection _pipeDirection;
/// <summary>
@@ -64,8 +64,6 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
private AppearanceComponent _appearance;
private PipeVisualState PipeVisualState => new PipeVisualState(PipeDirection, ConduitLayer);
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
@@ -94,22 +92,40 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
_needsPipeNet = true;
}
void IRotatableNode.RotateEvent(RotateEvent ev)
{
var diff = ev.NewRotation - ev.OldRotation;
var newPipeDir = PipeDirection.None;
for (var i = 0; i < PipeDirectionHelpers.PipeDirections; i++)
{
var pipeDirection = (PipeDirection) (1 << i);
if (!PipeDirection.HasFlag(pipeDirection)) continue;
var angle = pipeDirection.ToAngle();
angle += diff;
newPipeDir |= angle.GetCardinalDir().ToPipeDirection();
}
PipeDirection = newPipeDir;
}
protected override IEnumerable<Node> GetReachableNodes()
{
foreach (CardinalDirection direction in Enum.GetValues(typeof(CardinalDirection)))
for (var i = 0; i < PipeDirectionHelpers.PipeDirections; i++)
{
PipeDirectionFromCardinal(direction, out var ownNeededConnection, out var theirNeededConnection);
if ((_pipeDirection & ownNeededConnection) == PipeDirection.None)
var pipeDirection = (PipeDirection) (1 << i);
var ownNeededConnection = pipeDirection;
var theirNeededConnection = ownNeededConnection.GetOpposite();
if (!_pipeDirection.HasFlag(ownNeededConnection))
{
continue;
}
var pipeNodesInDirection = Owner.GetComponent<SnapGridComponent>()
.GetInDir((Direction) direction)
.GetInDir(pipeDirection.ToDirection())
.Select(entity => entity.TryGetComponent<NodeContainerComponent>(out var container) ? container : null)
.Where(container => container != null)
.SelectMany(container => container.Nodes)
.OfType<PipeNode>()
.Where(pipeNode => (pipeNode._pipeDirection & theirNeededConnection) != PipeDirection.None);
.Where(pipeNode => pipeNode._pipeDirection.HasFlag(theirNeededConnection));
foreach (var pipeNode in pipeNodesInDirection)
{
yield return pipeNode;
@@ -117,47 +133,16 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
}
}
private void PipeDirectionFromCardinal(CardinalDirection direction, out PipeDirection sameDir, out PipeDirection oppDir)
{
switch (direction)
{
case CardinalDirection.North:
sameDir = PipeDirection.North;
oppDir = PipeDirection.South;
break;
case CardinalDirection.South:
sameDir = PipeDirection.South;
oppDir = PipeDirection.North;
break;
case CardinalDirection.East:
sameDir = PipeDirection.East;
oppDir = PipeDirection.West;
break;
case CardinalDirection.West:
sameDir = PipeDirection.West;
oppDir = PipeDirection.East;
break;
default:
throw new ArgumentException("Invalid Direction.");
}
}
private void UpdateAppearance()
{
var pipeVisualStates = Owner.GetComponent<NodeContainerComponent>()
.Nodes
.OfType<PipeNode>()
.Select(pipeNode => pipeNode.PipeVisualState)
.ToArray();
_appearance?.SetData(PipeVisuals.VisualState, new PipeVisualStateSet(pipeVisualStates));
_appearance?.SetData(PipeVisuals.VisualState, new PipeVisualState(PipeDirection, ConduitLayer));
}
private enum CardinalDirection
private void SetPipeDirection(PipeDirection pipeDirection)
{
North = Direction.North,
South = Direction.South,
East = Direction.East,
West = Direction.West,
_pipeDirection = pipeDirection;
RefreshNodeGroup();
UpdateAppearance();
}
}
}

View File

@@ -1,4 +1,5 @@
using System;
using Robust.Shared.Maths;
using Robust.Shared.Serialization;
namespace Content.Shared.GameObjects.Components.Atmos
@@ -9,17 +10,6 @@ namespace Content.Shared.GameObjects.Components.Atmos
VisualState
}
[Serializable, NetSerializable]
public class PipeVisualStateSet
{
public readonly PipeVisualState[] PipeVisualStates;
public PipeVisualStateSet(PipeVisualState[] pipeVisualStates)
{
PipeVisualStates = pipeVisualStates;
}
}
[Serializable, NetSerializable]
public class PipeVisualState
{
@@ -65,10 +55,94 @@ namespace Content.Shared.GameObjects.Components.Atmos
All = -1,
}
public enum PipeShape
{
Straight,
Bend,
TJunction,
Fourway
}
public enum ConduitLayer
{
One = 1,
Two = 2,
Three = 3,
}
public static class PipeDirectionHelpers
{
public const int PipeDirections = 4;
public static Angle ToAngle(this PipeDirection pipeDirection)
{
return pipeDirection switch
{
PipeDirection.East => Angle.FromDegrees(0),
PipeDirection.North => Angle.FromDegrees(90),
PipeDirection.West => Angle.FromDegrees(180),
PipeDirection.South => Angle.FromDegrees(270),
_ => throw new ArgumentOutOfRangeException(nameof(pipeDirection), $"{pipeDirection} does not have an associated angle."),
};
}
public static PipeDirection ToPipeDirection(this Direction direction)
{
return direction switch
{
Direction.North => PipeDirection.North,
Direction.South => PipeDirection.South,
Direction.East => PipeDirection.East,
Direction.West => PipeDirection.West,
_ => throw new ArgumentOutOfRangeException(nameof(direction)),
};
}
public static Direction ToDirection(this PipeDirection pipeDirection)
{
return pipeDirection switch
{
PipeDirection.North => Direction.North,
PipeDirection.South => Direction.South,
PipeDirection.East => Direction.East,
PipeDirection.West => Direction.West,
_ => throw new ArgumentOutOfRangeException(nameof(pipeDirection)),
};
}
public static PipeDirection GetOpposite(this PipeDirection pipeDirection)
{
return pipeDirection switch
{
PipeDirection.North => PipeDirection.South,
PipeDirection.South => PipeDirection.North,
PipeDirection.East => PipeDirection.West,
PipeDirection.West => PipeDirection.East,
_ => throw new ArgumentOutOfRangeException(nameof(pipeDirection)),
};
}
public static PipeShape PipeDirectionToPipeShape(this PipeDirection pipeDirection)
{
return pipeDirection switch
{
PipeDirection.Lateral => PipeShape.Straight,
PipeDirection.Longitudinal => PipeShape.Straight,
PipeDirection.NEBend => PipeShape.Bend,
PipeDirection.NWBend => PipeShape.Bend,
PipeDirection.SEBend => PipeShape.Bend,
PipeDirection.SWBend => PipeShape.Bend,
PipeDirection.TNorth => PipeShape.TJunction,
PipeDirection.TSouth => PipeShape.TJunction,
PipeDirection.TEast => PipeShape.TJunction,
PipeDirection.TWest => PipeShape.TJunction,
PipeDirection.Fourway => PipeShape.Fourway,
_ => throw new ArgumentOutOfRangeException(nameof(pipeDirection)),
};
}
}
}

View File

@@ -1,6 +1,8 @@
- type: entity
abstract: true
id: PipeBase
name: Pipe
description: Holds gas.
placement:
mode: SnapgridCenter
components:
@@ -9,38 +11,64 @@
- type: Collidable
- type: SnapGrid
offset: Center
- type: Sprite
- type: Destructible
thresholdvalue: 100
- type: Sprite
sprite: Constructible/Atmos/pipe.rsi
- type: Appearance
visuals:
- type: PipeVisualizer
pipeRSI: Constructible/Atmos/pipe.rsi
- type: Icon
sprite: Constructible/Atmos/pipe.rsi
- type: entity
parent: PipeBase
id: FourwayPipe
name: Fourway Pipe
id: PipeStraight
suffix: Straight
components:
- type: NodeContainer
nodes:
- !type:PipeNode
nodeGroupID: Pipe
pipeDirection: Lateral
- type: Icon
sprite: Constructible/Atmos/pipe.rsi
state: pipeFourway2
state: pipeStraight2
- type: entity
parent: PipeBase
id: PipeBend
suffix: Bend
components:
- type: NodeContainer
nodes:
- !type:PipeNode
nodeGroupID: Pipe
pipeDirection: SEBend
- type: Icon
state: pipeBend2
- type: entity
parent: PipeBase
id: PipeTJunction
suffix: TJunction
components:
- type: NodeContainer
nodes:
- !type:PipeNode
nodeGroupID: Pipe
pipeDirection: TEast
- type: Icon
state: pipeTJunction2
- type: entity
parent: PipeBase
id: PipeFourway
suffix: Fourway
components:
- type: NodeContainer
nodes:
- !type:PipeNode
nodeGroupID: Pipe
pipeDirection: Fourway
- type: entity
parent: PipeBase
id: LongitudinalPipe
name: Longitudinal Pipe
components:
- type: Icon
sprite: Constructible/Atmos/pipe.rsi
state: pipeLongitudinal2
- type: NodeContainer
nodes:
- !type:PipeNode
nodeGroupID: Pipe
pipeDirection: Longitudinal
state: pipeFourway2

View File

@@ -8,189 +8,67 @@
"copyright":"Taken from https://github.com/tgstation/tgstation at commit 57cd1d59ca019dd0e7811ac451f295f818e573da",
"states":[
{
"name":"pipeEast2",
"directions":1,
"delays":[ [ 1.0 ] ]
"name":"pipeTJunction2",
"directions":4,
"delays":[
[
1.0
],
[
1.0
],
[
1.0
],
[
1.0
]
]
},
{
"name":"pipeNorth2",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeSouth2",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeWest2",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeFourway1",
"directions":1,
"delays":[ [ 1.0 ] ]
"name":"pipeBend2",
"directions":4,
"delays":[
[
1.0
],
[
1.0
],
[
1.0
],
[
1.0
]
]
},
{
"name":"pipeFourway2",
"directions":1,
"delays":[ [ 1.0 ] ]
"delays":[
[
1.0
]
]
},
{
"name":"pipeFourway3",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeLateral1",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeLateral2",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeLateral3",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeLongitudinal1",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeLongitudinal2",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeLongitudinal3",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeNEBend1",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeNEBend2",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeNEBend3",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeNWBend1",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeNWBend2",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeNWBend3",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeSEBend1",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeSEBend2",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeSEBend3",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeSWBend1",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeSWBend2",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeSWBend3",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeTEast1",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeTEast2",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeTEast3",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeTNorth1",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeTNorth2",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeTNorth3",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeTSouth1",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeTSouth2",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeTSouth3",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeTWest1",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeTWest2",
"directions":1,
"delays":[ [ 1.0 ] ]
},
{
"name":"pipeTWest3",
"directions":1,
"delays":[ [ 1.0 ] ]
"name":"pipeStraight2",
"directions":4,
"delays":[
[
1.0
],
[
1.0
],
[
1.0
],
[
1.0
]
]
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 854 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 217 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 556 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 545 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 273 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 278 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 278 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 329 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 321 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 265 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 255 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 317 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 347 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 324 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 229 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 233 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 264 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 276 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 267 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 292 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 309 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 278 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 643 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 450 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 450 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 433 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 474 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 447 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 427 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 398 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 416 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 426 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 449 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 471 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 479 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 236 B