Clothing/item ECS & cleanup (#9706)
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
using Content.Shared.Clothing.EntitySystems;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.Sound;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Clothing.Components;
|
||||
|
||||
/// <summary>
|
||||
/// This handles entities which can be equipped.
|
||||
/// </summary>
|
||||
[NetworkedComponent]
|
||||
public abstract class SharedClothingComponent : Component
|
||||
{
|
||||
[DataField("clothingVisuals")]
|
||||
public Dictionary<string, List<SharedSpriteComponent.PrototypeLayerData>> ClothingVisuals = new();
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("quickEquip")]
|
||||
public bool QuickEquip = true;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("slots", required: true)]
|
||||
public SlotFlags Slots = SlotFlags.NONE;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("equipSound")]
|
||||
public SoundSpecifier? EquipSound;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("unequipSound")]
|
||||
public SoundSpecifier? UnequipSound;
|
||||
|
||||
[Access(typeof(ClothingSystem))]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("equippedPrefix")]
|
||||
public string? EquippedPrefix;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("sprite")]
|
||||
public string? RsiPath;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class ClothingComponentState : ComponentState
|
||||
{
|
||||
public string? EquippedPrefix;
|
||||
|
||||
public ClothingComponentState(string? equippedPrefix)
|
||||
{
|
||||
EquippedPrefix = equippedPrefix;
|
||||
}
|
||||
}
|
||||
39
Content.Shared/Clothing/EntitySystems/ClothingSystem.cs
Normal file
39
Content.Shared/Clothing/EntitySystems/ClothingSystem.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using Content.Shared.Clothing.Components;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Clothing.EntitySystems;
|
||||
|
||||
public sealed class ClothingSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SharedClothingComponent, ComponentGetState>(OnGetState);
|
||||
SubscribeLocalEvent<SharedClothingComponent, ComponentHandleState>(OnHandleState);
|
||||
}
|
||||
|
||||
private void OnGetState(EntityUid uid, SharedClothingComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new ClothingComponentState(component.EquippedPrefix);
|
||||
}
|
||||
|
||||
private void OnHandleState(EntityUid uid, SharedClothingComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is ClothingComponentState state)
|
||||
component.EquippedPrefix = state.EquippedPrefix;
|
||||
}
|
||||
|
||||
#region Public API
|
||||
|
||||
public void SetEquippedPrefix(EntityUid uid, string? prefix, SharedClothingComponent? clothing = null)
|
||||
{
|
||||
if (!Resolve(uid, ref clothing))
|
||||
return;
|
||||
|
||||
clothing.EquippedPrefix = prefix;
|
||||
Dirty(clothing);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.Clothing.EntitySystems;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Slippery;
|
||||
@@ -13,6 +14,8 @@ public abstract class SharedMagbootsSystem : EntitySystem
|
||||
[Dependency] private readonly SharedActionsSystem _sharedActions = default!;
|
||||
[Dependency] private readonly ClothingSpeedModifierSystem _clothingSpeedModifier = default!;
|
||||
[Dependency] private readonly InventorySystem _inventory = default!;
|
||||
[Dependency] private readonly SharedItemSystem _item = default!;
|
||||
[Dependency] private readonly ClothingSystem _clothing = default!;
|
||||
[Dependency] private readonly SharedContainerSystem _sharedContainer = default!;
|
||||
|
||||
public override void Initialize()
|
||||
@@ -37,8 +40,11 @@ public abstract class SharedMagbootsSystem : EntitySystem
|
||||
_inventory.TryGetSlotEntity(container.Owner, "shoes", out var entityUid) && entityUid == component.Owner)
|
||||
UpdateMagbootEffects(container.Owner, uid, true, component);
|
||||
|
||||
if (TryComp<SharedItemComponent>(uid, out var item))
|
||||
item.EquippedPrefix = component.On ? "on" : null;
|
||||
if (TryComp<ItemComponent>(uid, out var item))
|
||||
{
|
||||
_item.SetHeldPrefix(uid, component.On ? "on" : null, item);
|
||||
_clothing.SetEquippedPrefix(uid, component.On ? "on" : null);
|
||||
}
|
||||
|
||||
if (TryComp(uid, out AppearanceComponent? appearance))
|
||||
appearance.SetData(ToggleVisuals.Toggled, component.On);
|
||||
|
||||
Reference in New Issue
Block a user