Files
tbd-station-14/Content.Client/GameObjects/Components/Atmos/PipeVisualizer.cs
py01 178931e54b Pump visuals (#1960)
* Pipe sprites

* pipe copyright

* SharedPipeComponent

* Pipe Visualizer draft

* missing longitudinal pipe sprites

* expanded rsi states

* pipe prototype fixes

* Fixed pipe visualizer

* PressurePump and VolumePump

* VolumePump fix

* PressurePump fix

* Shared pump

# Conflicts:
#	Content.Server/GameObjects/Components/Atmos/Piping/Pumps/BasePumpComponent.cs
#	Content.Server/GameObjects/Components/NodeContainer/Nodes/PipeNode.cs

* PumpVisualizer Draft

* ConduitLayer enum

* PipeVisualizer update

* halfpipe sprites

* pumpvisualizer simplification

* yaml unneeded proto removal

* pump visualizer draft 2

* Pump overlays

* pump rsi name

* merge fix

* PumpVisuals ConduitLayer

* merge fix

Co-authored-by: py01 <pyronetics01@gmail.com>
2020-08-31 12:33:05 +02:00

69 lines
2.4 KiB
C#

using Content.Shared.GameObjects.Components.Atmos;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Client.Interfaces.GameObjects.Components;
using Robust.Client.Graphics;
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 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);
}
}
}
}