Makes Eyepatches Flippable (#26277)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using Content.Client.Inventory;
|
||||
using Content.Shared.Clothing;
|
||||
using Content.Shared.Clothing.Components;
|
||||
@@ -113,6 +114,7 @@ public sealed class ClientClothingSystem : ClothingSystem
|
||||
i++;
|
||||
}
|
||||
|
||||
item.MappedLayer = key;
|
||||
args.Layers.Add((key, layer));
|
||||
}
|
||||
}
|
||||
@@ -153,13 +155,9 @@ public sealed class ClientClothingSystem : ClothingSystem
|
||||
|
||||
// species specific
|
||||
if (speciesId != null && rsi.TryGetState($"{state}-{speciesId}", out _))
|
||||
{
|
||||
state = $"{state}-{speciesId}";
|
||||
}
|
||||
else if (!rsi.TryGetState(state, out _))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var layer = new PrototypeLayerData();
|
||||
layer.RsiPath = rsi.Path.ToString();
|
||||
@@ -287,6 +285,8 @@ public sealed class ClientClothingSystem : ClothingSystem
|
||||
|
||||
if (layerData.Color != null)
|
||||
sprite.LayerSetColor(key, layerData.Color.Value);
|
||||
if (layerData.Scale != null)
|
||||
sprite.LayerSetScale(key, layerData.Scale.Value);
|
||||
}
|
||||
else
|
||||
index = sprite.LayerMapReserveBlank(key);
|
||||
|
||||
48
Content.Client/Clothing/FlippableClothingVisualizerSystem.cs
Normal file
48
Content.Client/Clothing/FlippableClothingVisualizerSystem.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using Content.Shared.Clothing;
|
||||
using Content.Shared.Clothing.Components;
|
||||
using Content.Shared.Clothing.EntitySystems;
|
||||
using Content.Shared.Foldable;
|
||||
using Content.Shared.Item;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
namespace Content.Client.Clothing;
|
||||
|
||||
public sealed class FlippableClothingVisualizerSystem : VisualizerSystem<FlippableClothingVisualsComponent>
|
||||
{
|
||||
[Dependency] private readonly SharedItemSystem _itemSys = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<FlippableClothingVisualsComponent, GetEquipmentVisualsEvent>(OnGetVisuals, after: [typeof(ClothingSystem)]);
|
||||
SubscribeLocalEvent<FlippableClothingVisualsComponent, FoldedEvent>(OnFolded);
|
||||
}
|
||||
|
||||
private void OnFolded(Entity<FlippableClothingVisualsComponent> ent, ref FoldedEvent args)
|
||||
{
|
||||
_itemSys.VisualsChanged(ent);
|
||||
}
|
||||
|
||||
private void OnGetVisuals(Entity<FlippableClothingVisualsComponent> ent, ref GetEquipmentVisualsEvent args)
|
||||
{
|
||||
if (!TryComp(ent, out SpriteComponent? sprite) ||
|
||||
!TryComp(ent, out ClothingComponent? clothing))
|
||||
return;
|
||||
|
||||
if (clothing.MappedLayer == null ||
|
||||
!AppearanceSystem.TryGetData<bool>(ent, FoldableSystem.FoldedVisuals.State, out var folding) ||
|
||||
!sprite.LayerMapTryGet(folding ? ent.Comp.FoldingLayer : ent.Comp.UnfoldingLayer, out var idx))
|
||||
return;
|
||||
|
||||
// add each layer to the visuals
|
||||
var spriteLayer = sprite[idx];
|
||||
foreach (var layer in args.Layers)
|
||||
{
|
||||
if (layer.Item1 != clothing.MappedLayer)
|
||||
continue;
|
||||
|
||||
layer.Item2.Scale = spriteLayer.Scale;
|
||||
}
|
||||
}
|
||||
}
|
||||
16
Content.Client/Clothing/FlippableClothingVisualsComponent.cs
Normal file
16
Content.Client/Clothing/FlippableClothingVisualsComponent.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace Content.Client.Clothing;
|
||||
|
||||
/// <summary>
|
||||
/// Communicates folded layers data (currently only Scale to handle flipping)
|
||||
/// to the wearer clothing sprite layer
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[Access(typeof(FlippableClothingVisualizerSystem))]
|
||||
public sealed partial class FlippableClothingVisualsComponent : Component
|
||||
{
|
||||
[DataField]
|
||||
public string FoldingLayer = "foldedLayer";
|
||||
|
||||
[DataField]
|
||||
public string UnfoldingLayer = "unfoldedLayer";
|
||||
}
|
||||
Reference in New Issue
Block a user