Pipe visualizers (#3042)

* modifies pipe sprites to look not connected

* pipe connector sprites

* PipeConnectorVisualizer

* Remove pipe visualizer

* Revert "Remove pipe visualizer"

This reverts commit dc8da93f99f20aa55247c6a94d26c7a75a3d1782.

* PipeDirection can be set with the sprite updating correctly

* fixes meta files

* removes unused vent/scrubber directions

* OnConnectedDirectionsNeedsUpdating

* comments + OnConnectedDirectionsNeedsUpdating gets called

* fix connecteddirections bug

* Combines ConnectedDirections sent to visualizer

* fixes unconnected pipe sprites

* Adds PipeConnectorVisualizer to other piping entities

* code cleanup

* Fixed bug with ConnectedDirections not being set correctly

* diff fix

* rotation simplification

* Improves rsi serialization

* enable nullable

* wip

* visualizer cleanup

* nullable cleanup

Co-authored-by: py01 <pyronetics01@gmail.com>
This commit is contained in:
collinlunn
2021-02-22 19:18:30 -07:00
committed by GitHub
parent 6a79782fc0
commit 112f7d8346
26 changed files with 343 additions and 74 deletions

View File

@@ -1,4 +1,4 @@
using System;
#nullable enable
using Content.Shared.GameObjects.Components.Atmos;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
@@ -12,47 +12,44 @@ using YamlDotNet.RepresentationModel;
namespace Content.Client.GameObjects.Components.Atmos
{
/// <summary>
/// Sets the state of the sprite based on what shape of pipe it is.
/// </summary>
[UsedImplicitly]
public class PipeVisualizer : AppearanceVisualizer
{
private string _rsiString;
private RSI _pipeRSI;
private RSI? _pipeRSI;
public override void LoadData(YamlMappingNode node)
{
base.LoadData(node);
var serializer = YamlObjectSerializer.NewReader(node);
serializer.DataField(ref _rsiString, "rsiString", "Constructible/Atmos/pipe.rsi");
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.ventvisualizer", "Unable to load RSI '{0}'. Trace:\n{1}", rsiPath, e);
}
var rsiString = SharedSpriteComponent.TextureRoot / serializer.ReadDataField("rsi", "Constructible/Atmos/pipe.rsi");
var resourceCache = IoCManager.Resolve<IResourceCache>();
if (resourceCache.TryGetResource(rsiString, out RSIResource? rsi))
_pipeRSI = rsi.RSI;
else
Logger.Error($"{nameof(PipeVisualizer)} could not load to load RSI {rsiString}.");
}
public override void InitializeEntity(IEntity entity)
{
base.InitializeEntity(entity);
if (!entity.TryGetComponent(out ISpriteComponent sprite)) return;
if (!entity.TryGetComponent<ISpriteComponent>(out var sprite)) return;
sprite.LayerMapReserveBlank(Layer.PipeBase);
var pipeBaseLayer = sprite.LayerMapGet(Layer.PipeBase);
sprite.LayerSetRSI(pipeBaseLayer, _pipeRSI);
if (_pipeRSI != null)
sprite.LayerSetRSI(pipeBaseLayer, _pipeRSI);
sprite.LayerSetVisible(pipeBaseLayer, true);
}
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);
if (!component.Owner.TryGetComponent(out ISpriteComponent sprite)) return;
if (!component.Owner.TryGetComponent<ISpriteComponent>(out var sprite)) return;
if (!component.TryGetData(PipeVisuals.VisualState, out PipeVisualState pipeVisualState)) return;
var pipeBase = sprite.LayerMapGet(Layer.PipeBase);
var pipeBaseStateId = GetPipeBaseStateId(pipeVisualState);
@@ -62,7 +59,7 @@ namespace Content.Client.GameObjects.Components.Atmos
private string GetPipeBaseStateId(PipeVisualState pipeVisualState)
{
var stateId = "pipe";
stateId += pipeVisualState.PipeDirection.PipeDirectionToPipeShape().ToString();
stateId += pipeVisualState.PipeShape.ToString();
return stateId;
}