Fix monkey jumpsuits (#17410)

This commit is contained in:
Leon Friedrich
2023-06-19 05:23:04 +12:00
committed by GitHub
parent 4f8ea0c19b
commit cc81a7511b

View File

@@ -12,12 +12,15 @@ using Robust.Client.GameObjects;
using Robust.Client.Graphics; using Robust.Client.Graphics;
using Robust.Client.ResourceManagement; using Robust.Client.ResourceManagement;
using Robust.Shared.Serialization.TypeSerializers.Implementations; using Robust.Shared.Serialization.TypeSerializers.Implementations;
using Robust.Shared.Utility;
using static Robust.Client.GameObjects.SpriteComponent; using static Robust.Client.GameObjects.SpriteComponent;
namespace Content.Client.Clothing; namespace Content.Client.Clothing;
public sealed class ClientClothingSystem : ClothingSystem public sealed class ClientClothingSystem : ClothingSystem
{ {
public const string Jumpsuit = "jumpsuit";
/// <summary> /// <summary>
/// This is a shitty hotfix written by me (Paul) to save me from renaming all files. /// This is a shitty hotfix written by me (Paul) to save me from renaming all files.
/// For some context, im currently refactoring inventory. Part of that is slots not being indexed by a massive enum anymore, but by strings. /// For some context, im currently refactoring inventory. Part of that is slots not being indexed by a massive enum anymore, but by strings.
@@ -30,7 +33,7 @@ public sealed class ClientClothingSystem : ClothingSystem
{"ears", "EARS"}, {"ears", "EARS"},
{"mask", "MASK"}, {"mask", "MASK"},
{"outerClothing", "OUTERCLOTHING"}, {"outerClothing", "OUTERCLOTHING"},
{"jumpsuit", "INNERCLOTHING"}, {Jumpsuit, "INNERCLOTHING"},
{"neck", "NECK"}, {"neck", "NECK"},
{"back", "BACKPACK"}, {"back", "BACKPACK"},
{"belt", "BELT"}, {"belt", "BELT"},
@@ -60,15 +63,22 @@ public sealed class ClientClothingSystem : ClothingSystem
private void OnAppearanceUpdate(EntityUid uid, InventoryComponent component, ref AppearanceChangeEvent args) private void OnAppearanceUpdate(EntityUid uid, InventoryComponent component, ref AppearanceChangeEvent args)
{ {
// May need to update jumpsuit stencils if the sex changed. Also required to properly set the stencil on init // May need to update jumpsuit stencils if the sex changed. Also required to properly set the stencil on init
// This is when sex is first loaded from the profile. if (args.Sprite == null)
if (!TryComp(uid, out SpriteComponent? sprite) ||
!TryComp(uid, out HumanoidAppearanceComponent? humanoid) ||
!_inventorySystem.TryGetSlotEntity(uid, "jumpsuit", out var suit, component) ||
!TryComp(suit, out ClothingComponent? clothing))
return; return;
SetGenderedMask(sprite, humanoid, clothing); if (_inventorySystem.TryGetSlotEntity(uid, Jumpsuit, out var suit, component)
&& TryComp(suit, out ClothingComponent? clothing))
{
SetGenderedMask(uid, args.Sprite, clothing);
return;
}
// No clothing equipped -> make sure the layer is hidden, though this should already be handled by on-unequip.
if (args.Sprite.LayerMapTryGet(HumanoidVisualLayers.StencilMask, out var layer))
{
DebugTools.Assert(!args.Sprite[layer].Visible);
args.Sprite.LayerSetVisible(layer, false);
}
} }
private void OnGetVisuals(EntityUid uid, ClothingComponent item, GetEquipmentVisualsEvent args) private void OnGetVisuals(EntityUid uid, ClothingComponent item, GetEquipmentVisualsEvent args)
@@ -168,7 +178,15 @@ public sealed class ClientClothingSystem : ClothingSystem
private void OnDidUnequip(EntityUid uid, SpriteComponent component, DidUnequipEvent args) private void OnDidUnequip(EntityUid uid, SpriteComponent component, DidUnequipEvent args)
{ {
if (!TryComp(uid, out InventoryComponent? inventory) || !TryComp(uid, out InventorySlotsComponent? inventorySlots)) // Hide jumpsuit mask layer.
if (args.Slot == Jumpsuit
&& TryComp(uid, out SpriteComponent? sprite)
&& sprite.LayerMapTryGet(HumanoidVisualLayers.StencilMask, out var maskLayer))
{
sprite.LayerSetVisible(maskLayer, false);
}
if (!TryComp(uid, out InventorySlotsComponent? inventorySlots))
return; return;
if (!inventorySlots.VisualLayerKeys.TryGetValue(args.Slot, out var revealedLayers)) if (!inventorySlots.VisualLayerKeys.TryGetValue(args.Slot, out var revealedLayers))
@@ -214,13 +232,8 @@ public sealed class ClientClothingSystem : ClothingSystem
return; return;
} }
if (slot == "jumpsuit") if (slot == Jumpsuit)
{ SetGenderedMask(equipee, sprite, clothingComponent);
if (!TryComp(equipee, out HumanoidAppearanceComponent? humanoid))
return;
SetGenderedMask(sprite, humanoid, clothingComponent);
}
if (!_inventorySystem.TryGetSlot(equipee, slot, out var slotDef, inventory)) if (!_inventorySystem.TryGetSlot(equipee, slot, out var slotDef, inventory))
return; return;
@@ -287,7 +300,8 @@ public sealed class ClientClothingSystem : ClothingSystem
// Another "temporary" fix for clothing stencil masks. // Another "temporary" fix for clothing stencil masks.
// Sprite layer redactor when // Sprite layer redactor when
if (slot == "jumpsuit") // Sprite "redactor" just a week away.
if (slot == Jumpsuit)
layerData.Shader ??= "StencilDraw"; layerData.Shader ??= "StencilDraw";
sprite.LayerSetData(index, layerData); sprite.LayerSetData(index, layerData);
@@ -304,15 +318,15 @@ public sealed class ClientClothingSystem : ClothingSystem
/// <param name="sprite">Sprite to modify</param> /// <param name="sprite">Sprite to modify</param>
/// <param name="humanoid">Humanoid, to get gender from</param> /// <param name="humanoid">Humanoid, to get gender from</param>
/// <param name="clothing">Clothing component, to get mask sprite type</param> /// <param name="clothing">Clothing component, to get mask sprite type</param>
private static void SetGenderedMask(SpriteComponent sprite, HumanoidAppearanceComponent humanoid, ClothingComponent clothing) private void SetGenderedMask(EntityUid uid, SpriteComponent sprite, ClothingComponent clothing)
{ {
if (!sprite.LayerMapTryGet(HumanoidVisualLayers.StencilMask, out var layer)) if (!sprite.LayerMapTryGet(HumanoidVisualLayers.StencilMask, out var layer))
return; return;
ClothingMask? mask = null; ClothingMask mask;
var prefix = ""; string prefix;
switch (humanoid.Sex) switch (CompOrNull<HumanoidAppearanceComponent>(uid)?.Sex)
{ {
case Sex.Male: case Sex.Male:
mask = clothing.MaleMask; mask = clothing.MaleMask;
@@ -322,14 +336,12 @@ public sealed class ClientClothingSystem : ClothingSystem
mask = clothing.FemaleMask; mask = clothing.FemaleMask;
prefix = "female_"; prefix = "female_";
break; break;
case Sex.Unsexed: default:
mask = clothing.UnisexMask; mask = clothing.UnisexMask;
prefix = "unisex_"; prefix = "unisex_";
break; break;
} }
if (mask != null)
{
sprite.LayerSetState(layer, mask switch sprite.LayerSetState(layer, mask switch
{ {
ClothingMask.NoMask => $"{prefix}none", ClothingMask.NoMask => $"{prefix}none",
@@ -338,7 +350,4 @@ public sealed class ClientClothingSystem : ClothingSystem
}); });
sprite.LayerSetVisible(layer, true); sprite.LayerSetVisible(layer, true);
} }
else
sprite.LayerSetVisible(layer, false);
}
} }