Fix item/clothing visual & networking bugs (#10116)

This commit is contained in:
Leon Friedrich
2022-07-29 13:02:09 +12:00
committed by GitHub
parent e22679501c
commit d279f6172a
16 changed files with 278 additions and 239 deletions

View File

@@ -1,4 +1,4 @@
using Content.Shared.Clothing.EntitySystems;
using Content.Shared.Clothing.EntitySystems;
using Content.Shared.Inventory;
using Content.Shared.Sound;
using Robust.Shared.GameStates;
@@ -10,9 +10,11 @@ namespace Content.Shared.Clothing.Components;
/// This handles entities which can be equipped.
/// </summary>
[NetworkedComponent]
[Access(typeof(ClothingSystem), typeof(InventorySystem))]
public abstract class SharedClothingComponent : Component
{
[DataField("clothingVisuals")]
[Access(typeof(ClothingSystem), typeof(InventorySystem), Other = AccessPermissions.ReadExecute)] // TODO remove execute permissions.
public Dictionary<string, List<SharedSpriteComponent.PrototypeLayerData>> ClothingVisuals = new();
[ViewVariables(VVAccess.ReadWrite)]
@@ -21,6 +23,7 @@ public abstract class SharedClothingComponent : Component
[ViewVariables(VVAccess.ReadWrite)]
[DataField("slots", required: true)]
[Access(typeof(ClothingSystem), typeof(InventorySystem), Other = AccessPermissions.ReadExecute)]
public SlotFlags Slots = SlotFlags.NONE;
[ViewVariables(VVAccess.ReadWrite)]

View File

@@ -1,10 +1,14 @@
using Content.Shared.Clothing.Components;
using Content.Shared.Clothing.Components;
using Content.Shared.Inventory;
using Content.Shared.Item;
using Robust.Shared.GameStates;
namespace Content.Shared.Clothing.EntitySystems;
public sealed class ClothingSystem : EntitySystem
{
[Dependency] private readonly SharedItemSystem _itemSys = default!;
public override void Initialize()
{
base.Initialize();
@@ -21,17 +25,30 @@ public sealed class ClothingSystem : EntitySystem
private void OnHandleState(EntityUid uid, SharedClothingComponent component, ref ComponentHandleState args)
{
if (args.Current is ClothingComponentState state)
component.EquippedPrefix = state.EquippedPrefix;
SetEquippedPrefix(uid, state.EquippedPrefix, component);
}
#region Public API
public void SetEquippedPrefix(EntityUid uid, string? prefix, SharedClothingComponent? clothing = null)
{
if (!Resolve(uid, ref clothing))
if (!Resolve(uid, ref clothing, false))
return;
if (clothing.EquippedPrefix == prefix)
return;
clothing.EquippedPrefix = prefix;
_itemSys.VisualsChanged(uid);
Dirty(clothing);
}
public void SetSlots(EntityUid uid, SlotFlags slots, SharedClothingComponent? clothing = null)
{
if (!Resolve(uid, ref clothing))
return;
clothing.Slots = slots;
Dirty(clothing);
}