SharedItemComponent (#3513)
* StorableComponent refactor * ItemComponent refactor * conflict fixes * removes redundant null check * removes redundant item throwing code * fix conflicts * ExplosionLaunchedComponent Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -1,19 +1,23 @@
|
||||
using Content.Client.GameObjects.Components.HUD.Inventory;
|
||||
#nullable enable
|
||||
using Content.Client.GameObjects.Components.HUD.Inventory;
|
||||
using Content.Client.GameObjects.Components.Items;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Inventory;
|
||||
using Content.Shared.GameObjects.Components.Items;
|
||||
using Content.Shared.GameObjects.Components.Storage;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Clothing
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(SharedItemComponent))]
|
||||
[ComponentReference(typeof(ItemComponent))]
|
||||
[ComponentReference(typeof(IItemComponent))]
|
||||
public class ClothingComponent : ItemComponent
|
||||
{
|
||||
[DataField("femaleMask")]
|
||||
@@ -64,17 +68,9 @@ namespace Content.Client.GameObjects.Components.Clothing
|
||||
public (RSI rsi, RSI.StateId stateId)? GetEquippedStateInfo(EquipmentSlotDefines.SlotFlags slot, string? speciesId=null)
|
||||
{
|
||||
if (RsiPath == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var rsi = GetRSI();
|
||||
|
||||
if (rsi == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var rsi = IoCManager.Resolve<IResourceCache>().GetResource<RSIResource>(SharedSpriteComponent.TextureRoot / RsiPath).RSI;
|
||||
var prefix = ClothingEquippedPrefix ?? EquippedPrefix;
|
||||
var stateId = prefix != null ? $"{prefix}-equipped-{slot}" : $"equipped-{slot}";
|
||||
if (speciesId != null)
|
||||
|
||||
@@ -4,7 +4,9 @@ using System.Linq;
|
||||
using Content.Client.Animations;
|
||||
using Content.Client.UserInterface;
|
||||
using Content.Shared.GameObjects.Components.Items;
|
||||
using Content.Shared.GameObjects.Components.Storage;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Network;
|
||||
@@ -161,20 +163,26 @@ namespace Content.Client.GameObjects.Components.Items
|
||||
return;
|
||||
}
|
||||
|
||||
if (!entity.TryGetComponent(out ItemComponent? item)) return;
|
||||
if (!entity.TryGetComponent(out SharedItemComponent? item))
|
||||
return;
|
||||
|
||||
var maybeInHands = item.GetInHandStateInfo(hand.Location);
|
||||
|
||||
if (!maybeInHands.HasValue)
|
||||
if (item.RsiPath == null)
|
||||
{
|
||||
_sprite.LayerSetVisible($"hand-{name}", false);
|
||||
}
|
||||
else
|
||||
{
|
||||
var (rsi, state, color) = maybeInHands.Value;
|
||||
var rsi = IoCManager.Resolve<IResourceCache>().GetResource<RSIResource>(SharedSpriteComponent.TextureRoot / item.RsiPath).RSI;
|
||||
|
||||
var handName = hand.Location.ToString().ToLowerInvariant();
|
||||
var prefix = item.EquippedPrefix;
|
||||
var state = prefix != null ? $"{prefix}-inhand-{handName}" : $"inhand-{handName}";
|
||||
|
||||
var color = item.Color;
|
||||
|
||||
_sprite.LayerSetColor($"hand-{name}", color);
|
||||
_sprite.LayerSetVisible($"hand-{name}", true);
|
||||
_sprite.LayerSetState($"hand-{name}", state, rsi);
|
||||
_sprite.LayerSetState($"hand-{name}", state, rsi);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,102 +1,26 @@
|
||||
using Content.Client.GameObjects.Components.Disposal;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Items;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.ResourceManagement;
|
||||
#nullable enable
|
||||
using Content.Shared.GameObjects.Components.Storage;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Items
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IItemComponent))]
|
||||
public class ItemComponent : Component, IItemComponent, IDraggable
|
||||
[ComponentReference(typeof(SharedItemComponent))]
|
||||
public class ItemComponent : SharedItemComponent
|
||||
{
|
||||
[Dependency] private readonly IResourceCache _resourceCache = default!;
|
||||
|
||||
public override string Name => "Item";
|
||||
public override uint? NetID => ContentNetIDs.ITEM;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("sprite")]
|
||||
protected ResourcePath? RsiPath;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("color")]
|
||||
protected Color Color = Color.White;
|
||||
|
||||
[DataField("HeldPrefix")]
|
||||
private string? _equippedPrefix;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public string? EquippedPrefix
|
||||
public override bool TryPutInHand(IEntity user)
|
||||
{
|
||||
get => _equippedPrefix;
|
||||
set
|
||||
{
|
||||
_equippedPrefix = value;
|
||||
|
||||
if (!Owner.TryGetContainer(out var container))
|
||||
return;
|
||||
|
||||
if (container.Owner.TryGetComponent(out HandsComponent? hands))
|
||||
hands.RefreshInHands();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public (RSI rsi, RSI.StateId stateId, Color color)? GetInHandStateInfo(HandLocation hand)
|
||||
protected override void OnEquippedPrefixChange()
|
||||
{
|
||||
var rsi = GetRSI();
|
||||
|
||||
if (rsi == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var handName = hand.ToString().ToLowerInvariant();
|
||||
var stateId = EquippedPrefix != null ? $"{EquippedPrefix}-inhand-{handName}" : $"inhand-{handName}";
|
||||
|
||||
if (rsi.TryGetState(stateId, out _))
|
||||
{
|
||||
return (rsi, stateId, Color);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected RSI? GetRSI()
|
||||
{
|
||||
if (RsiPath == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return _resourceCache.GetResource<RSIResource>(SharedSpriteComponent.TextureRoot / RsiPath).RSI;
|
||||
}
|
||||
|
||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||
{
|
||||
if (curState is not ItemComponentState state)
|
||||
if (!Owner.TryGetContainer(out var container))
|
||||
return;
|
||||
|
||||
EquippedPrefix = state.EquippedPrefix;
|
||||
}
|
||||
|
||||
bool IDraggable.CanDrop(CanDropEventArgs args)
|
||||
{
|
||||
return args.Target.HasComponent<DisposalUnitComponent>();
|
||||
}
|
||||
|
||||
bool IDraggable.Drop(DragDropEventArgs args)
|
||||
{
|
||||
// TODO: Shared item class
|
||||
return false;
|
||||
if (container.Owner.TryGetComponent(out HandsComponent? hands))
|
||||
hands.RefreshInHands();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
using Content.Shared.GameObjects.Components.Storage;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Storage
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(SharedStorableComponent))]
|
||||
public class StorableComponent : SharedStorableComponent
|
||||
{
|
||||
private int _size;
|
||||
|
||||
public override int Size
|
||||
{
|
||||
get => _size;
|
||||
set
|
||||
{
|
||||
if (_size == value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_size = value;
|
||||
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||
{
|
||||
base.HandleComponentState(curState, nextState);
|
||||
|
||||
if (curState is not StorableComponentState state)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_size = state.Size;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -252,6 +252,7 @@ namespace Content.Client
|
||||
"RandomSpawner",
|
||||
"SpawnAfterInteract",
|
||||
"DisassembleOnActivate",
|
||||
"ExplosionLaunched",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user