Pipe Sprites & Visualizer (#1954)

* Pipe sprites

* pipe copyright

* SharedPipeComponent

* Pipe Visualizer draft

* missing longitudinal pipe sprites

* expanded rsi states

* pipe prototype fixes

* Fixed pipe visualizer

* ConduitLayer enum

* PipeVisualizer update

* halfpipe sprites

* yaml unneeded proto removal

* PipeVisualizer uses its own RSI

* Removes unused field from PipeVisualizer

Co-authored-by: py01 <pyronetics01@gmail.com>
This commit is contained in:
py01
2020-08-30 18:13:15 -06:00
committed by GitHub
parent b83c8126d7
commit 68ec6e6be5
43 changed files with 371 additions and 40 deletions

View File

@@ -0,0 +1,69 @@
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 System;
using System.Collections.Generic;
using YamlDotNet.RepresentationModel;
namespace Content.Client.GameObjects.Components.Atmos
{
[UsedImplicitly]
public class PipeVisualizer : AppearanceVisualizer
{
private RSI _pipeRSI;
public override void LoadData(YamlMappingNode node)
{
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);
}
}
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);
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();
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);
}
}
}
}

View File

@@ -1,6 +1,7 @@
using Content.Server.Atmos;
using Content.Server.GameObjects.Components.NodeContainer;
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
using Content.Shared.GameObjects.Components.Atmos;
using Robust.Shared.Log;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;

View File

@@ -1,7 +1,8 @@
using Content.Server.Atmos;
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
using Content.Server.Interfaces;
using Content.Shared.Atmos;
using Content.Shared.GameObjects.Components.Atmos;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects.Components.Transform;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Maths;
@@ -23,6 +24,12 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
public PipeDirection PipeDirection => _pipeDirection;
private PipeDirection _pipeDirection;
/// <summary>
/// Controls what visuals are applied in <see cref="PipeVisualizer"/>.
/// </summary>
public ConduitLayer ConduitLayer => _conduitLayer;
private ConduitLayer _conduitLayer;
[ViewVariables]
private IPipeNet _pipeNet = PipeNet.NullNet;
@@ -55,17 +62,24 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
[ViewVariables]
public float Volume { get; private set; }
private AppearanceComponent _appearance;
private PipeVisualState PipeVisualState => new PipeVisualState(PipeDirection, ConduitLayer);
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref _pipeDirection, "pipeDirection", PipeDirection.None);
serializer.DataField(this, x => Volume, "volume", 10);
serializer.DataField(ref _conduitLayer, "conduitLayer", ConduitLayer.Two);
}
public override void Initialize(IEntity owner)
{
base.Initialize(owner);
LocalAir = new GasMixture(Volume);
Owner.TryGetComponent(out _appearance);
UpdateAppearance();
}
public void JoinPipeNet(IPipeNet pipeNet)
@@ -128,6 +142,16 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
}
}
private void UpdateAppearance()
{
var pipeVisualStates = Owner.GetComponent<NodeContainerComponent>()
.Nodes
.OfType<PipeNode>()
.Select(pipeNode => pipeNode.PipeVisualState)
.ToArray();
_appearance?.SetData(PipeVisuals.VisualState, new PipeVisualStateSet(pipeVisualStates));
}
private enum CardinalDirection
{
North = Direction.North,
@@ -136,36 +160,4 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
West = Direction.West,
}
}
public enum PipeDirection
{
None = 0,
//Half of a pipe in a direction
North = 1 << 0,
South = 1 << 1,
West = 1 << 2,
East = 1 << 3,
//Straight pipes
Longitudinal = North | South,
Lateral = West | East,
//Bends
NWBend = North | West,
NEBend = North | East,
SWBend = South | West,
SEBend = South | East,
//T-Junctions
TNorth = North | Lateral,
TSouth = South | Lateral,
TWest = West | Longitudinal,
TEast = East | Longitudinal,
//Four way
FourWay = North | South | East | West,
All = -1,
}
}

View File

@@ -0,0 +1,74 @@
using Robust.Shared.Serialization;
using System;
namespace Content.Shared.GameObjects.Components.Atmos
{
[Serializable, NetSerializable]
public enum PipeVisuals
{
VisualState
}
[Serializable, NetSerializable]
public class PipeVisualStateSet
{
public readonly PipeVisualState[] PipeVisualStates;
public PipeVisualStateSet(PipeVisualState[] pipeVisualStates)
{
PipeVisualStates = pipeVisualStates;
}
}
[Serializable, NetSerializable]
public class PipeVisualState
{
public readonly PipeDirection PipeDirection;
public readonly ConduitLayer ConduitLayer;
public PipeVisualState(PipeDirection pipeDirection, ConduitLayer conduitLayer)
{
PipeDirection = pipeDirection;
ConduitLayer = conduitLayer;
}
}
public enum PipeDirection
{
None = 0,
//Half of a pipe in a direction
North = 1 << 0,
South = 1 << 1,
West = 1 << 2,
East = 1 << 3,
//Straight pipes
Longitudinal = North | South,
Lateral = West | East,
//Bends
NWBend = North | West,
NEBend = North | East,
SWBend = South | West,
SEBend = South | East,
//T-Junctions
TNorth = North | Lateral,
TSouth = South | Lateral,
TWest = West | Longitudinal,
TEast = East | Longitudinal,
//Four way
Fourway = North | South | East | West,
All = -1,
}
public enum ConduitLayer
{
One = 1,
Two = 2,
Three = 3,
}
}

View File

@@ -12,32 +12,31 @@
- type: Icon
texture: Constructible/Power/eightdirwire.png
- type: Sprite
sprite: Constructible/Power/hv_cable.rsi
- type: Destructible
thresholdvalue: 100
- type: Appearance
visuals:
- type: PipeVisualizer
pipeRSI: Constructible/Atmos/pipe.rsi
- type: entity
parent: PipeBase
id: FourwayPipe
name: Fourway Pipe
components:
- type: Sprite
state: hvcable_15
- type: NodeContainer
nodes:
- !type:PipeNode
nodeGroupID: Pipe
pipeDirection: FourWay
pipeDirection: Fourway
- type: entity
parent: PipeBase
id: LongitudinalPipe
name: Longitudinal Pipe
components:
- type: Sprite
state: hvcable_3
- type: NodeContainer
nodes:
- !type:PipeNode
nodeGroupID: Pipe
pipeDirection: Longitudinal
pipeDirection: Longitudinal

View File

@@ -0,0 +1,196 @@
{
"version":1,
"size":{
"x":32,
"y":32
},
"license":"CC-BY-SA-3.0",
"copyright":"Taken from https://github.com/tgstation/tgstation at commit 57cd1d59ca019dd0e7811ac451f295f818e573da",
"states":[
{
"name":"pipeEast2",
"directions":1,
"delays":[ [ 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":"pipeFourway2",
"directions":1,
"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 ] ]
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 556 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 538 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 545 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 273 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 278 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 278 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 321 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 265 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 317 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 347 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 324 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 229 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 233 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 276 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 267 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 309 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 278 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 450 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 450 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 433 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 474 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 447 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 427 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 398 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 416 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 426 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 449 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 471 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 479 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 236 B