Layering for atmospheric pipes (#36124)
Co-authored-by: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com> Co-authored-by: Kevin Zheng <kevinz5000@gmail.com>
This commit is contained in:
56
Content.Client/Atmos/EntitySystems/AtmosPipeLayersSystem.cs
Normal file
56
Content.Client/Atmos/EntitySystems/AtmosPipeLayersSystem.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using Content.Shared.Atmos.Components;
|
||||
using Content.Shared.Atmos.EntitySystems;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Shared.Reflection;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations;
|
||||
using Robust.Shared.Utility;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Content.Client.Atmos.EntitySystems;
|
||||
|
||||
/// <summary>
|
||||
/// The system responsible for updating the appearance of layered gas pipe
|
||||
/// </summary>
|
||||
public sealed partial class AtmosPipeLayersSystem : SharedAtmosPipeLayersSystem
|
||||
{
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
[Dependency] private readonly IReflectionManager _reflection = default!;
|
||||
[Dependency] private readonly IResourceCache _resourceCache = default!;
|
||||
[Dependency] private readonly SpriteSystem _sprite = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<AtmosPipeLayersComponent, AppearanceChangeEvent>(OnAppearanceChange);
|
||||
}
|
||||
|
||||
private void OnAppearanceChange(Entity<AtmosPipeLayersComponent> ent, ref AppearanceChangeEvent ev)
|
||||
{
|
||||
if (!TryComp<SpriteComponent>(ent, out var sprite))
|
||||
return;
|
||||
|
||||
if (_appearance.TryGetData<string>(ent, AtmosPipeLayerVisuals.Sprite, out var spriteRsi) &&
|
||||
_resourceCache.TryGetResource(SpriteSpecifierSerializer.TextureRoot / spriteRsi, out RSIResource? resource))
|
||||
{
|
||||
_sprite.SetBaseRsi((ent, sprite), resource.RSI);
|
||||
}
|
||||
|
||||
if (_appearance.TryGetData<Dictionary<string, string>>(ent, AtmosPipeLayerVisuals.SpriteLayers, out var pipeState))
|
||||
{
|
||||
foreach (var (layerKey, rsiPath) in pipeState)
|
||||
{
|
||||
if (TryParseKey(layerKey, out var @enum))
|
||||
_sprite.LayerSetRsi((ent, sprite), @enum, new ResPath(rsiPath));
|
||||
else
|
||||
_sprite.LayerSetRsi((ent, sprite), layerKey, new ResPath(rsiPath));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryParseKey(string keyString, [NotNullWhen(true)] out Enum? @enum)
|
||||
{
|
||||
return _reflection.TryParseEnumReference(keyString, out @enum);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user