Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 11 additions & 30 deletions Content.Shared/Clothing/Components/ClothingComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ namespace Content.Shared.Clothing.Components;
/// <summary>
/// This handles entities which can be equipped.
/// </summary>
[NetworkedComponent]
[RegisterComponent]
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]
[Access(typeof(ClothingSystem), typeof(InventorySystem))]
public sealed partial class ClothingComponent : Component
{
[DataField("clothingVisuals")]
[DataField]
public Dictionary<string, List<PrototypeLayerData>> ClothingVisuals = new();

/// <summary>
Expand All @@ -25,8 +24,7 @@ public sealed partial class ClothingComponent : Component
[DataField]
public string? MappedLayer;

[ViewVariables(VVAccess.ReadWrite)]
[DataField("quickEquip")]
[DataField]
public bool QuickEquip = true;

/// <summary>
Expand All @@ -36,34 +34,28 @@ public sealed partial class ClothingComponent : Component
/// <remarks>
/// Note that this may be a combination of different slot flags, not a singular bit.
/// </remarks>
[ViewVariables(VVAccess.ReadWrite)]
[DataField(required: true)]
[Access(typeof(ClothingSystem), typeof(InventorySystem), Other = AccessPermissions.ReadExecute)]
public SlotFlags Slots = SlotFlags.NONE;

[ViewVariables(VVAccess.ReadWrite)]
[DataField("equipSound")]
[DataField]
public SoundSpecifier? EquipSound;

[ViewVariables(VVAccess.ReadWrite)]
[DataField("unequipSound")]
[DataField]
public SoundSpecifier? UnequipSound;

[Access(typeof(ClothingSystem))]
[ViewVariables(VVAccess.ReadWrite)]
[DataField("equippedPrefix")]
[DataField, AutoNetworkedField]
public string? EquippedPrefix;

/// <summary>
/// Allows the equipped state to be directly overwritten.
/// useful when prototyping INNERCLOTHING items into OUTERCLOTHING items without duplicating/modifying RSIs etc.
/// </summary>
[Access(typeof(ClothingSystem))]
[ViewVariables(VVAccess.ReadWrite)]
[DataField("equippedState")]
[DataField, AutoNetworkedField]
public string? EquippedState;

[ViewVariables(VVAccess.ReadWrite)]
[DataField("sprite")]
public string? RsiPath;

Expand All @@ -72,7 +64,7 @@ public sealed partial class ClothingComponent : Component
/// Note that this being non-null does not mean the clothing is considered "worn" or "equipped" unless the slot
/// satisfies the <see cref="Slots"/> flags.
/// </summary>
[DataField]
[DataField, AutoNetworkedField]
public string? InSlot;
// TODO CLOTHING
// Maybe keep this null unless its in a valid slot?
Expand All @@ -82,16 +74,16 @@ public sealed partial class ClothingComponent : Component
/// <summary>
/// Slot flags of the slot the clothing is currently in. See also <see cref="InSlot"/>.
/// </summary>
[DataField]
[DataField, AutoNetworkedField]
public SlotFlags? InSlotFlag;
// TODO CLOTHING
// Maybe keep this null unless its in a valid slot?
// And when doing this, combine InSlot and InSlotFlag, as it'd be a breaking change for downstreams anyway

[DataField, ViewVariables(VVAccess.ReadWrite)]
[DataField]
public TimeSpan EquipDelay = TimeSpan.Zero;

[DataField, ViewVariables(VVAccess.ReadWrite)]
[DataField]
public TimeSpan UnequipDelay = TimeSpan.Zero;

/// <summary>
Expand All @@ -102,17 +94,6 @@ public sealed partial class ClothingComponent : Component
public TimeSpan StripDelay = TimeSpan.Zero;
}

[Serializable, NetSerializable]
public sealed class ClothingComponentState : ComponentState
{
public string? EquippedPrefix;

public ClothingComponentState(string? equippedPrefix)
{
EquippedPrefix = equippedPrefix;
}
}

public enum ClothingMask : byte
{
NoMask = 0,
Expand Down
17 changes: 5 additions & 12 deletions Content.Shared/Clothing/EntitySystems/ClothingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public override void Initialize()
base.Initialize();

SubscribeLocalEvent<ClothingComponent, UseInHandEvent>(OnUseInHand);
SubscribeLocalEvent<ClothingComponent, ComponentGetState>(OnGetState);
SubscribeLocalEvent<ClothingComponent, ComponentHandleState>(OnHandleState);
SubscribeLocalEvent<ClothingComponent, AfterAutoHandleStateEvent>(AfterAutoHandleState);
SubscribeLocalEvent<ClothingComponent, GotEquippedEvent>(OnGotEquipped);
SubscribeLocalEvent<ClothingComponent, GotUnequippedEvent>(OnGotUnequipped);

Expand Down Expand Up @@ -89,6 +88,7 @@ protected virtual void OnGotEquipped(EntityUid uid, ClothingComponent component,
{
component.InSlot = args.Slot;
component.InSlotFlag = args.SlotFlags;
Dirty(uid, component);

if ((component.Slots & args.SlotFlags) == SlotFlags.NONE)
return;
Expand All @@ -113,19 +113,12 @@ protected virtual void OnGotUnequipped(EntityUid uid, ClothingComponent componen

component.InSlot = null;
component.InSlotFlag = null;
Dirty(uid, component);
}

private void OnGetState(EntityUid uid, ClothingComponent component, ref ComponentGetState args)
private void AfterAutoHandleState(Entity<ClothingComponent> ent, ref AfterAutoHandleStateEvent args)
{
args.State = new ClothingComponentState(component.EquippedPrefix);
}

private void OnHandleState(EntityUid uid, ClothingComponent component, ref ComponentHandleState args)
{
if (args.Current is not ClothingComponentState state)
return;

SetEquippedPrefix(uid, state.EquippedPrefix, component);
_itemSys.VisualsChanged(ent.Owner);
}

private void OnEquipDoAfter(Entity<ClothingComponent> ent, ref ClothingEquipDoAfterEvent args)
Expand Down
6 changes: 3 additions & 3 deletions Content.Shared/Clothing/EntitySystems/MaskSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ private void OnGotUnequipped(EntityUid uid, MaskComponent mask, GotUnequippedEve
private void ToggleMaskComponents(EntityUid uid, MaskComponent mask, EntityUid wearer, string? equippedPrefix = null, bool isEquip = false)
{
Dirty(uid, mask);
if (mask.ToggleActionEntity is {} action)
if (mask.ToggleActionEntity is { } action)
_actionSystem.SetToggled(action, mask.IsToggled);

var maskEv = new ItemMaskToggledEvent((wearer, mask), wearer);
var maskEv = new ItemMaskToggledEvent((uid, mask), wearer);
RaiseLocalEvent(uid, ref maskEv);

var wearerEv = new WearerMaskToggledEvent((wearer, mask));
var wearerEv = new WearerMaskToggledEvent((uid, mask));
RaiseLocalEvent(wearer, ref wearerEv);
}

Expand Down
Loading