Fix female clothing mask (#12217)

Co-authored-by: ElectroJr <leonsfriedrich@gmail.com>
This commit is contained in:
Rane
2022-10-30 20:06:16 -04:00
committed by GitHub
parent e0ac3307bb
commit 16e1b9e349
4 changed files with 52 additions and 25 deletions

View File

@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Client.Inventory;
using Content.Client.Humanoid;
using Content.Shared.Clothing;
using Content.Shared.Clothing.Components;
using Content.Shared.Clothing.EntitySystems;
@@ -42,8 +42,9 @@ public sealed class ClientClothingSystem : ClothingSystem
{"pocket2", "POCKET2"},
};
[Dependency] private IResourceCache _cache = default!;
[Dependency] private InventorySystem _inventorySystem = default!;
[Dependency] private readonly IResourceCache _cache = default!;
[Dependency] private readonly InventorySystem _inventorySystem = default!;
[Dependency] private readonly AppearanceSystem _appearance = default!;
public override void Initialize()
{
@@ -53,6 +54,33 @@ public sealed class ClientClothingSystem : ClothingSystem
SubscribeLocalEvent<ClientInventoryComponent, VisualsChangedEvent>(OnVisualsChanged);
SubscribeLocalEvent<SpriteComponent, DidUnequipEvent>(OnDidUnequip);
SubscribeLocalEvent<ClientInventoryComponent, AppearanceChangeEvent>(OnAppearanceUpdate);
}
private void OnAppearanceUpdate(EntityUid uid, ClientInventoryComponent component, ref AppearanceChangeEvent args)
{
// May need to update jumpsuit stencils if the sex changed. Also required to properly set the stencil on init
// when sex is first loaded from the profile.
if (!TryComp(uid, out SpriteComponent? sprite) || !sprite.LayerMapTryGet(HumanoidVisualLayers.StencilMask, out var layer))
return;
if (!args.AppearanceData.TryGetValue(HumanoidVisualizerKey.Key, out object? obj)
|| obj is not HumanoidVisualizerData data
|| data.Sex != Sex.Female
|| !_inventorySystem.TryGetSlotEntity(uid, "jumpsuit", out var suit, component)
|| !TryComp(suit, out ClothingComponent? clothing))
{
sprite.LayerSetVisible(layer, false);
return;
}
sprite.LayerSetState(layer, clothing.FemaleMask switch
{
FemaleClothingMask.NoMask => "female_none",
FemaleClothingMask.UniformTop => "female_top",
_ => "female_full",
});
sprite.LayerSetVisible(layer, true);
}
private void OnGetVisuals(EntityUid uid, ClothingComponent item, GetEquipmentVisualsEvent args)
@@ -188,14 +216,22 @@ public sealed class ClientClothingSystem : ClothingSystem
if(!Resolve(equipee, ref inventory, ref sprite) || !Resolve(equipment, ref clothingComponent, false))
return;
if (slot == "jumpsuit" && sprite.LayerMapTryGet(HumanoidVisualLayers.StencilMask, out _))
if (slot == "jumpsuit" && sprite.LayerMapTryGet(HumanoidVisualLayers.StencilMask, out var suitLayer))
{
sprite.LayerSetState(HumanoidVisualLayers.StencilMask, clothingComponent.FemaleMask switch
if (_appearance.TryGetData(equipee, HumanoidVisualizerKey.Key, out object? obj)
&& obj is HumanoidVisualizerData data
&& data.Sex == Sex.Female)
{
FemaleClothingMask.NoMask => "female_none",
FemaleClothingMask.UniformTop => "female_top",
_ => "female_full",
});
sprite.LayerSetState(suitLayer, clothingComponent.FemaleMask switch
{
FemaleClothingMask.NoMask => "female_none",
FemaleClothingMask.UniformTop => "female_top",
_ => "female_full",
});
sprite.LayerSetVisible(suitLayer, true);
}
else
sprite.LayerSetVisible(suitLayer, false);
}
if (!_inventorySystem.TryGetSlot(equipee, slot, out var slotDef, inventory))