2021-02-22 19:18:30 -07:00
|
|
|
#nullable enable
|
2021-03-05 01:08:38 +01:00
|
|
|
using System;
|
2020-09-13 14:23:52 +02:00
|
|
|
using Content.Shared.GameObjects.Components.Atmos;
|
2020-08-30 18:13:15 -06:00
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
using Robust.Client.GameObjects;
|
2020-10-18 04:13:06 -06:00
|
|
|
using Robust.Client.Graphics;
|
|
|
|
|
using Robust.Client.ResourceManagement;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2020-10-18 04:13:06 -06:00
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
using Robust.Shared.Log;
|
2021-01-19 07:26:16 -06:00
|
|
|
using Robust.Shared.Serialization;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2020-08-30 18:13:15 -06:00
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
namespace Content.Client.GameObjects.Components.Atmos.Piping
|
2020-08-30 18:13:15 -06:00
|
|
|
{
|
2021-02-22 19:18:30 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the state of the sprite based on what shape of pipe it is.
|
|
|
|
|
/// </summary>
|
2020-08-30 18:13:15 -06:00
|
|
|
[UsedImplicitly]
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataDefinition]
|
|
|
|
|
public class PipeVisualizer : AppearanceVisualizer, ISerializationHooks
|
2020-08-30 18:13:15 -06:00
|
|
|
{
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("rsi")] private string _rsiString = "Constructible/Atmos/pipe.rsi";
|
2021-02-22 19:18:30 -07:00
|
|
|
private RSI? _pipeRSI;
|
2020-10-18 04:13:06 -06:00
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
void ISerializationHooks.AfterDeserialization()
|
2020-10-18 04:13:06 -06:00
|
|
|
{
|
2021-03-05 01:08:38 +01:00
|
|
|
var rsiPath = SharedSpriteComponent.TextureRoot / _rsiString;
|
2021-02-22 19:18:30 -07:00
|
|
|
var resourceCache = IoCManager.Resolve<IResourceCache>();
|
2021-03-05 01:08:38 +01:00
|
|
|
|
|
|
|
|
if (resourceCache.TryGetResource(rsiPath, out RSIResource? rsi))
|
|
|
|
|
{
|
2021-02-22 19:18:30 -07:00
|
|
|
_pipeRSI = rsi.RSI;
|
2021-03-05 01:08:38 +01:00
|
|
|
}
|
2020-10-18 04:13:06 -06:00
|
|
|
}
|
|
|
|
|
|
2020-10-08 09:53:56 -06:00
|
|
|
public override void InitializeEntity(IEntity entity)
|
2020-08-30 18:13:15 -06:00
|
|
|
{
|
2020-10-08 09:53:56 -06:00
|
|
|
base.InitializeEntity(entity);
|
2021-02-22 19:18:30 -07:00
|
|
|
if (!entity.TryGetComponent<ISpriteComponent>(out var sprite)) return;
|
2020-10-08 09:53:56 -06:00
|
|
|
sprite.LayerMapReserveBlank(Layer.PipeBase);
|
|
|
|
|
var pipeBaseLayer = sprite.LayerMapGet(Layer.PipeBase);
|
2021-02-22 19:18:30 -07:00
|
|
|
|
|
|
|
|
if (_pipeRSI != null)
|
|
|
|
|
sprite.LayerSetRSI(pipeBaseLayer, _pipeRSI);
|
|
|
|
|
|
2020-10-08 09:53:56 -06:00
|
|
|
sprite.LayerSetVisible(pipeBaseLayer, true);
|
2020-08-30 18:13:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnChangeData(AppearanceComponent component)
|
|
|
|
|
{
|
|
|
|
|
base.OnChangeData(component);
|
2021-02-22 19:18:30 -07:00
|
|
|
if (!component.Owner.TryGetComponent<ISpriteComponent>(out var sprite)) return;
|
2020-10-08 09:53:56 -06:00
|
|
|
if (!component.TryGetData(PipeVisuals.VisualState, out PipeVisualState pipeVisualState)) return;
|
|
|
|
|
var pipeBase = sprite.LayerMapGet(Layer.PipeBase);
|
|
|
|
|
var pipeBaseStateId = GetPipeBaseStateId(pipeVisualState);
|
|
|
|
|
sprite.LayerSetState(pipeBase, pipeBaseStateId);
|
|
|
|
|
}
|
2020-08-30 18:13:15 -06:00
|
|
|
|
2020-10-08 09:53:56 -06:00
|
|
|
private string GetPipeBaseStateId(PipeVisualState pipeVisualState)
|
|
|
|
|
{
|
|
|
|
|
var stateId = "pipe";
|
2021-02-22 19:18:30 -07:00
|
|
|
stateId += pipeVisualState.PipeShape.ToString();
|
2020-10-08 09:53:56 -06:00
|
|
|
return stateId;
|
|
|
|
|
}
|
2020-08-30 18:13:15 -06:00
|
|
|
|
2020-12-04 11:57:33 +01:00
|
|
|
private enum Layer : byte
|
2020-10-08 09:53:56 -06:00
|
|
|
{
|
|
|
|
|
PipeBase,
|
2020-08-30 18:13:15 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|